db/Interface: add attribute "plugin"
The new method IsPlugin() replaces the "is_simple" flag.
This commit is contained in:
parent
ae594ad92c
commit
85b8675e7a
|
@ -166,11 +166,10 @@ InitStorage(Error &error)
|
||||||
static bool
|
static bool
|
||||||
glue_db_init_and_load(void)
|
glue_db_init_and_load(void)
|
||||||
{
|
{
|
||||||
bool is_simple;
|
|
||||||
Error error;
|
Error error;
|
||||||
instance->database =
|
instance->database =
|
||||||
CreateConfiguredDatabase(*instance->event_loop, *instance,
|
CreateConfiguredDatabase(*instance->event_loop, *instance,
|
||||||
is_simple, error);
|
error);
|
||||||
if (instance->database == nullptr) {
|
if (instance->database == nullptr) {
|
||||||
if (error.IsDefined())
|
if (error.IsDefined())
|
||||||
FatalError(error);
|
FatalError(error);
|
||||||
|
@ -193,7 +192,7 @@ glue_db_init_and_load(void)
|
||||||
if (!instance->database->Open(error))
|
if (!instance->database->Open(error))
|
||||||
FatalError(error);
|
FatalError(error);
|
||||||
|
|
||||||
if (!is_simple)
|
if (!instance->database->IsPlugin(simple_db_plugin))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
SimpleDatabase &db = *(SimpleDatabase *)instance->database;
|
SimpleDatabase &db = *(SimpleDatabase *)instance->database;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
Database *
|
Database *
|
||||||
CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
|
CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
|
||||||
bool &is_simple_r, Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
const struct config_param *param = config_get_param(CONF_DATABASE);
|
const struct config_param *param = config_get_param(CONF_DATABASE);
|
||||||
const struct config_param *path = config_get_param(CONF_DB_FILE);
|
const struct config_param *path = config_get_param(CONF_DB_FILE);
|
||||||
|
@ -53,7 +53,7 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
Database *db = DatabaseGlobalInit(loop, listener, *param,
|
Database *db = DatabaseGlobalInit(loop, listener, *param,
|
||||||
is_simple_r, error);
|
error);
|
||||||
delete allocated;
|
delete allocated;
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,6 @@ class Error;
|
||||||
*/
|
*/
|
||||||
Database *
|
Database *
|
||||||
CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
|
CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
|
||||||
bool &is_simple_r, Error &error);
|
Error &error);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,11 +29,10 @@
|
||||||
|
|
||||||
Database *
|
Database *
|
||||||
DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
|
DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
|
||||||
const config_param ¶m, bool &is_simple, Error &error)
|
const config_param ¶m, Error &error)
|
||||||
{
|
{
|
||||||
const char *plugin_name =
|
const char *plugin_name =
|
||||||
param.GetBlockValue("plugin", "simple");
|
param.GetBlockValue("plugin", "simple");
|
||||||
is_simple = strcmp(plugin_name, "simple") == 0;
|
|
||||||
|
|
||||||
const DatabasePlugin *plugin = GetDatabasePluginByName(plugin_name);
|
const DatabasePlugin *plugin = GetDatabasePluginByName(plugin_name);
|
||||||
if (plugin == nullptr) {
|
if (plugin == nullptr) {
|
||||||
|
|
|
@ -32,11 +32,9 @@ class Error;
|
||||||
* Initialize the database library.
|
* Initialize the database library.
|
||||||
*
|
*
|
||||||
* @param param the database configuration block
|
* @param param the database configuration block
|
||||||
* @param is_simple returns whether this is the "simple" database
|
|
||||||
* plugin
|
|
||||||
*/
|
*/
|
||||||
Database *
|
Database *
|
||||||
DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
|
DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
|
||||||
const config_param ¶m, bool &is_simple, Error &error);
|
const config_param ¶m, Error &error);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,18 +26,32 @@
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
struct DatabasePlugin;
|
||||||
struct DatabaseStats;
|
struct DatabaseStats;
|
||||||
struct DatabaseSelection;
|
struct DatabaseSelection;
|
||||||
struct LightSong;
|
struct LightSong;
|
||||||
class Error;
|
class Error;
|
||||||
|
|
||||||
class Database {
|
class Database {
|
||||||
|
const DatabasePlugin &plugin;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Database(const DatabasePlugin &_plugin)
|
||||||
|
:plugin(_plugin) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free instance data.
|
* Free instance data.
|
||||||
*/
|
*/
|
||||||
virtual ~Database() {}
|
virtual ~Database() {}
|
||||||
|
|
||||||
|
const DatabasePlugin &GetPlugin() const {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsPlugin(const DatabasePlugin &other) const {
|
||||||
|
return &plugin == &other;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the database. Read it into memory if applicable.
|
* Open the database. Read it into memory if applicable.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
LazyDatabase::LazyDatabase(Database *_db)
|
||||||
|
:Database(_db->GetPlugin()), db(_db), open(false) {}
|
||||||
|
|
||||||
LazyDatabase::~LazyDatabase()
|
LazyDatabase::~LazyDatabase()
|
||||||
{
|
{
|
||||||
assert(!open);
|
assert(!open);
|
||||||
|
|
|
@ -35,8 +35,7 @@ class LazyDatabase final : public Database {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
gcc_nonnull_all
|
gcc_nonnull_all
|
||||||
LazyDatabase(Database *_db)
|
LazyDatabase(Database *_db);
|
||||||
:db(_db), open(false) {}
|
|
||||||
|
|
||||||
virtual ~LazyDatabase();
|
virtual ~LazyDatabase();
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,8 @@ class ProxyDatabase final : public Database, SocketMonitor, IdleMonitor {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener)
|
ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener)
|
||||||
:SocketMonitor(_loop), IdleMonitor(_loop),
|
:Database(proxy_db_plugin),
|
||||||
|
SocketMonitor(_loop), IdleMonitor(_loop),
|
||||||
listener(_listener) {}
|
listener(_listener) {}
|
||||||
|
|
||||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||||
|
|
|
@ -40,6 +40,10 @@
|
||||||
|
|
||||||
static constexpr Domain simple_db_domain("simple_db");
|
static constexpr Domain simple_db_domain("simple_db");
|
||||||
|
|
||||||
|
inline SimpleDatabase::SimpleDatabase()
|
||||||
|
:Database(simple_db_plugin),
|
||||||
|
path(AllocatedPath::Null()) {}
|
||||||
|
|
||||||
Database *
|
Database *
|
||||||
SimpleDatabase::Create(gcc_unused EventLoop &loop,
|
SimpleDatabase::Create(gcc_unused EventLoop &loop,
|
||||||
gcc_unused DatabaseListener &listener,
|
gcc_unused DatabaseListener &listener,
|
||||||
|
|
|
@ -50,8 +50,7 @@ class SimpleDatabase : public Database {
|
||||||
mutable unsigned borrowed_song_count;
|
mutable unsigned borrowed_song_count;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SimpleDatabase()
|
SimpleDatabase();
|
||||||
:path(AllocatedPath::Null()) {}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
gcc_pure
|
gcc_pure
|
||||||
|
|
|
@ -75,6 +75,8 @@ class UpnpDatabase : public Database {
|
||||||
UPnPDeviceDirectory *discovery;
|
UPnPDeviceDirectory *discovery;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
UpnpDatabase():Database(upnp_db_plugin) {}
|
||||||
|
|
||||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||||
const config_param ¶m,
|
const config_param ¶m,
|
||||||
Error &error);
|
Error &error);
|
||||||
|
|
Loading…
Reference in New Issue