StoragePlugin: pass EventLoop to constructor
This commit is contained in:
parent
1aac0b10c9
commit
3d2558bde6
@ -1589,11 +1589,15 @@ endif
|
||||
test_run_storage_LDADD = \
|
||||
$(STORAGE_LIBS) \
|
||||
$(FS_LIBS) \
|
||||
libevent.a \
|
||||
libthread.a \
|
||||
libsystem.a \
|
||||
libutil.a \
|
||||
$(GLIB_LIBS)
|
||||
test_run_storage_SOURCES = \
|
||||
src/Log.cxx src/LogBackend.cxx \
|
||||
src/IOThread.cxx \
|
||||
test/ScopeIOThread.hxx \
|
||||
test/run_storage.cxx
|
||||
|
||||
endif
|
||||
|
@ -166,7 +166,7 @@ glue_mapper_init(Error &error)
|
||||
static bool
|
||||
InitStorage(Error &error)
|
||||
{
|
||||
Storage *storage = CreateConfiguredStorage(error);
|
||||
Storage *storage = CreateConfiguredStorage(io_thread_get(), error);
|
||||
if (storage == nullptr)
|
||||
return !error.IsDefined();
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "db/plugins/simple/SimpleDatabasePlugin.hxx"
|
||||
#include "db/update/Service.hxx"
|
||||
#include "TimePrint.hxx"
|
||||
#include "IOThread.hxx"
|
||||
#include "Idle.hxx"
|
||||
|
||||
#include <inttypes.h> /* for PRIu64 */
|
||||
@ -121,7 +122,7 @@ CommandResult
|
||||
handle_listfiles_storage(Client &client, const char *uri)
|
||||
{
|
||||
Error error;
|
||||
Storage *storage = CreateStorageURI(uri, error);
|
||||
Storage *storage = CreateStorageURI(io_thread_get(), uri, error);
|
||||
if (storage == nullptr) {
|
||||
if (error.IsDefined())
|
||||
return print_error(client, error);
|
||||
@ -217,7 +218,8 @@ handle_mount(Client &client, gcc_unused unsigned argc, char *argv[])
|
||||
}
|
||||
|
||||
Error error;
|
||||
Storage *storage = CreateStorageURI(remote_uri, error);
|
||||
Storage *storage = CreateStorageURI(io_thread_get(), remote_uri,
|
||||
error);
|
||||
if (storage == nullptr) {
|
||||
if (error.IsDefined())
|
||||
return print_error(client, error);
|
||||
|
@ -31,9 +31,10 @@
|
||||
#include <assert.h>
|
||||
|
||||
static Storage *
|
||||
CreateConfiguredStorageUri(const char *uri, Error &error)
|
||||
CreateConfiguredStorageUri(EventLoop &event_loop, const char *uri,
|
||||
Error &error)
|
||||
{
|
||||
Storage *storage = CreateStorageURI(uri, error);
|
||||
Storage *storage = CreateStorageURI(event_loop, uri, error);
|
||||
if (storage == nullptr && !error.IsDefined())
|
||||
error.Format(config_domain,
|
||||
"Unrecognized storage URI: %s", uri);
|
||||
@ -63,13 +64,13 @@ CreateConfiguredStorageLocal(Error &error)
|
||||
}
|
||||
|
||||
Storage *
|
||||
CreateConfiguredStorage(Error &error)
|
||||
CreateConfiguredStorage(EventLoop &event_loop, Error &error)
|
||||
{
|
||||
assert(!error.IsDefined());
|
||||
|
||||
auto uri = config_get_string(CONF_MUSIC_DIR, nullptr);
|
||||
if (uri != nullptr && uri_has_scheme(uri))
|
||||
return CreateConfiguredStorageUri(uri, error);
|
||||
return CreateConfiguredStorageUri(event_loop, uri, error);
|
||||
|
||||
return CreateConfiguredStorageLocal(error);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
class Error;
|
||||
class Storage;
|
||||
class EventLoop;
|
||||
|
||||
/**
|
||||
* Read storage configuration settings and create a #Storage instance
|
||||
@ -32,7 +33,7 @@ class Storage;
|
||||
* (no #Error set in that case).
|
||||
*/
|
||||
Storage *
|
||||
CreateConfiguredStorage(Error &error);
|
||||
CreateConfiguredStorage(EventLoop &event_loop, Error &error);
|
||||
|
||||
/**
|
||||
* Returns true if there is configuration for a #Storage instance.
|
||||
|
@ -52,7 +52,7 @@ GetStoragePluginByName(const char *name)
|
||||
}
|
||||
|
||||
Storage *
|
||||
CreateStorageURI(const char *uri, Error &error)
|
||||
CreateStorageURI(EventLoop &event_loop, const char *uri, Error &error)
|
||||
{
|
||||
assert(!error.IsDefined());
|
||||
|
||||
@ -62,7 +62,7 @@ CreateStorageURI(const char *uri, Error &error)
|
||||
if (plugin.create_uri == nullptr)
|
||||
continue;
|
||||
|
||||
Storage *storage = plugin.create_uri(uri, error);
|
||||
Storage *storage = plugin.create_uri(event_loop, uri, error);
|
||||
if (storage != nullptr || error.IsDefined())
|
||||
return storage;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
struct StoragePlugin;
|
||||
class Storage;
|
||||
class Error;
|
||||
class EventLoop;
|
||||
|
||||
/**
|
||||
* nullptr terminated list of all storage plugins which were enabled at
|
||||
@ -39,6 +40,6 @@ GetStoragePluginByName(const char *name);
|
||||
|
||||
gcc_nonnull_all gcc_malloc
|
||||
Storage *
|
||||
CreateStorageURI(const char *uri, Error &error);
|
||||
CreateStorageURI(EventLoop &event_loop, const char *uri, Error &error);
|
||||
|
||||
#endif
|
||||
|
@ -24,11 +24,13 @@
|
||||
|
||||
class Error;
|
||||
class Storage;
|
||||
class EventLoop;
|
||||
|
||||
struct StoragePlugin {
|
||||
const char *name;
|
||||
|
||||
Storage *(*create_uri)(const char *uri, Error &error);
|
||||
Storage *(*create_uri)(EventLoop &event_loop, const char *uri,
|
||||
Error &error);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -203,7 +203,8 @@ NfsStorage::OpenDirectory(const char *uri_utf8, Error &error)
|
||||
}
|
||||
|
||||
static Storage *
|
||||
CreateNfsStorageURI(const char *base, Error &error)
|
||||
CreateNfsStorageURI(gcc_unused EventLoop &event_loop, const char *base,
|
||||
Error &error)
|
||||
{
|
||||
if (memcmp(base, "nfs://", 6) != 0)
|
||||
return nullptr;
|
||||
|
@ -180,7 +180,8 @@ SmbclientDirectoryReader::GetInfo(gcc_unused bool follow, FileInfo &info,
|
||||
}
|
||||
|
||||
static Storage *
|
||||
CreateSmbclientStorageURI(const char *base, Error &error)
|
||||
CreateSmbclientStorageURI(gcc_unused EventLoop &event_loop, const char *base,
|
||||
Error &error)
|
||||
{
|
||||
if (memcmp(base, "smb://", 6) != 0)
|
||||
return nullptr;
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "ScopeIOThread.hxx"
|
||||
#include "storage/Registry.hxx"
|
||||
#include "storage/StorageInterface.hxx"
|
||||
#include "storage/FileInfo.hxx"
|
||||
@ -38,7 +39,7 @@ static Storage *
|
||||
MakeStorage(const char *uri)
|
||||
{
|
||||
Error error;
|
||||
Storage *storage = CreateStorageURI(uri, error);
|
||||
Storage *storage = CreateStorageURI(io_thread_get(), uri, error);
|
||||
if (storage == nullptr) {
|
||||
fprintf(stderr, "%s\n", error.GetMessage());
|
||||
exit(EXIT_FAILURE);
|
||||
@ -112,6 +113,8 @@ main(int argc, char **argv)
|
||||
const char *const command = argv[1];
|
||||
const char *const storage_uri = argv[2];
|
||||
|
||||
const ScopeIOThread io_thread;
|
||||
|
||||
if (strcmp(command, "ls") == 0) {
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "Usage: run_storage ls URI PATH\n");
|
||||
|
Loading…
Reference in New Issue
Block a user