storage: add struct StoragePlugin and a plugin registry

This commit is contained in:
Max Kellermann
2014-02-05 19:23:02 +01:00
parent be081929f4
commit a0088ccce1
9 changed files with 177 additions and 6 deletions

View File

@@ -19,6 +19,7 @@
#include "config.h"
#include "LocalStorage.hxx"
#include "storage/StoragePlugin.hxx"
#include "storage/StorageInterface.hxx"
#include "storage/FileInfo.hxx"
#include "util/Error.hxx"
@@ -210,3 +211,8 @@ CreateLocalStorage(Path base_fs)
{
return new LocalStorage(base_fs);
}
const StoragePlugin local_storage_plugin = {
"local",
nullptr,
};

View File

@@ -23,9 +23,12 @@
#include "check.h"
#include "Compiler.h"
struct StoragePlugin;
class Storage;
class Path;
extern const StoragePlugin local_storage_plugin;
gcc_malloc gcc_nonnull_all
Storage *
CreateLocalStorage(Path base_fs);

View File

@@ -19,6 +19,7 @@
#include "config.h"
#include "SmbclientStorage.hxx"
#include "storage/StoragePlugin.hxx"
#include "storage/StorageInterface.hxx"
#include "storage/FileInfo.hxx"
#include "lib/smbclient/Init.hxx"
@@ -178,9 +179,12 @@ SmbclientDirectoryReader::GetInfo(gcc_unused bool follow, FileInfo &info,
return ::GetInfo(path.c_str(), info, error);
}
Storage *
CreateSmbclientStorage(const char *base, Error &error)
static Storage *
CreateSmbclientStorageURI(const char *base, Error &error)
{
if (memcmp(base, "smb://", 6) != 0)
return nullptr;
if (!SmbclientInit(error))
return nullptr;
@@ -200,3 +204,8 @@ CreateSmbclientStorage(const char *base, Error &error)
return new SmbclientStorage(base, ctx2);
}
const StoragePlugin smbclient_storage_plugin = {
"smbclient",
CreateSmbclientStorageURI,
};

View File

@@ -22,10 +22,8 @@
#include "check.h"
class Error;
class Storage;
struct StoragePlugin;
Storage *
CreateSmbclientStorage(const char *base, Error &error);
extern const StoragePlugin smbclient_storage_plugin;
#endif