db/Plugin: migrate from class Error to C++ exceptions
This commit is contained in:
parent
7e5ce623fe
commit
dea46e8d5a
@ -39,5 +39,5 @@ DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return plugin->create(loop, listener, block, error);
|
||||
return plugin->create(loop, listener, block);
|
||||
}
|
||||
|
@ -27,7 +27,6 @@
|
||||
#define MPD_DATABASE_PLUGIN_HXX
|
||||
|
||||
struct ConfigBlock;
|
||||
class Error;
|
||||
class EventLoop;
|
||||
class DatabaseListener;
|
||||
class Database;
|
||||
@ -45,10 +44,11 @@ struct DatabasePlugin {
|
||||
|
||||
/**
|
||||
* Allocates and configures a database.
|
||||
*
|
||||
* Throws #std::runtime_error on error.
|
||||
*/
|
||||
Database *(*create)(EventLoop &loop, DatabaseListener &listener,
|
||||
const ConfigBlock &block,
|
||||
Error &error);
|
||||
const ConfigBlock &block);
|
||||
|
||||
constexpr bool RequireStorage() const {
|
||||
return flags & FLAG_REQUIRE_STORAGE;
|
||||
|
@ -82,9 +82,9 @@ public:
|
||||
class ProxyDatabase final : public Database, SocketMonitor, IdleMonitor {
|
||||
DatabaseListener &listener;
|
||||
|
||||
std::string host;
|
||||
unsigned port;
|
||||
bool keepalive;
|
||||
const std::string host;
|
||||
const unsigned port;
|
||||
const bool keepalive;
|
||||
|
||||
struct mpd_connection *connection;
|
||||
|
||||
@ -104,14 +104,11 @@ class ProxyDatabase final : public Database, SocketMonitor, IdleMonitor {
|
||||
bool is_idle;
|
||||
|
||||
public:
|
||||
ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener)
|
||||
:Database(proxy_db_plugin),
|
||||
SocketMonitor(_loop), IdleMonitor(_loop),
|
||||
listener(_listener) {}
|
||||
ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener,
|
||||
const ConfigBlock &block);
|
||||
|
||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||
const ConfigBlock &block,
|
||||
Error &error);
|
||||
const ConfigBlock &block);
|
||||
|
||||
virtual void Open() override;
|
||||
virtual void Close() override;
|
||||
@ -141,8 +138,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
bool Configure(const ConfigBlock &block, Error &error);
|
||||
|
||||
void Connect();
|
||||
void CheckConnection();
|
||||
void EnsureConnected();
|
||||
@ -338,27 +333,22 @@ SendConstraints(mpd_connection *connection, const DatabaseSelection &selection)
|
||||
return true;
|
||||
}
|
||||
|
||||
Database *
|
||||
ProxyDatabase::Create(EventLoop &loop, DatabaseListener &listener,
|
||||
const ConfigBlock &block, Error &error)
|
||||
ProxyDatabase::ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener,
|
||||
const ConfigBlock &block)
|
||||
:Database(proxy_db_plugin),
|
||||
SocketMonitor(_loop), IdleMonitor(_loop),
|
||||
listener(_listener),
|
||||
host(block.GetBlockValue("host", "")),
|
||||
port(block.GetBlockValue("port", 0u)),
|
||||
keepalive(block.GetBlockValue("keepalive", false))
|
||||
{
|
||||
ProxyDatabase *db = new ProxyDatabase(loop, listener);
|
||||
if (!db->Configure(block, error)) {
|
||||
delete db;
|
||||
db = nullptr;
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
bool
|
||||
ProxyDatabase::Configure(const ConfigBlock &block, gcc_unused Error &error)
|
||||
Database *
|
||||
ProxyDatabase::Create(EventLoop &loop, DatabaseListener &listener,
|
||||
const ConfigBlock &block)
|
||||
{
|
||||
host = block.GetBlockValue("host", "");
|
||||
port = block.GetBlockValue("port", 0u);
|
||||
keepalive = block.GetBlockValue("keepalive", false);
|
||||
|
||||
return true;
|
||||
return new ProxyDatabase(loop, listener, block);
|
||||
}
|
||||
|
||||
void
|
||||
@ -395,6 +385,9 @@ ProxyDatabase::Connect()
|
||||
|
||||
#if LIBMPDCLIENT_CHECK_VERSION(2, 10, 0)
|
||||
mpd_connection_set_keepalive(connection, keepalive);
|
||||
#else
|
||||
// suppress -Wunused-private-field
|
||||
(void)keepalive;
|
||||
#endif
|
||||
|
||||
idle_received = unsigned(-1);
|
||||
|
@ -84,7 +84,7 @@ inline SimpleDatabase::SimpleDatabase(AllocatedPath &&_path,
|
||||
Database *
|
||||
SimpleDatabase::Create(gcc_unused EventLoop &loop,
|
||||
gcc_unused DatabaseListener &listener,
|
||||
const ConfigBlock &block, Error &)
|
||||
const ConfigBlock &block)
|
||||
{
|
||||
return new SimpleDatabase(block);
|
||||
}
|
||||
|
@ -73,8 +73,7 @@ class SimpleDatabase : public Database {
|
||||
|
||||
public:
|
||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||
const ConfigBlock &block,
|
||||
Error &error);
|
||||
const ConfigBlock &block);
|
||||
|
||||
gcc_pure
|
||||
Directory &GetRoot() {
|
||||
|
@ -77,8 +77,7 @@ public:
|
||||
UpnpDatabase():Database(upnp_db_plugin) {}
|
||||
|
||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||
const ConfigBlock &block,
|
||||
Error &error);
|
||||
const ConfigBlock &block);
|
||||
|
||||
virtual void Open() override;
|
||||
virtual void Close() override;
|
||||
@ -103,9 +102,6 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool Configure(const ConfigBlock &block, Error &error);
|
||||
|
||||
private:
|
||||
bool VisitServer(const ContentDirectoryService &server,
|
||||
const std::list<std::string> &vpath,
|
||||
@ -150,21 +146,9 @@ private:
|
||||
Database *
|
||||
UpnpDatabase::Create(gcc_unused EventLoop &loop,
|
||||
gcc_unused DatabaseListener &listener,
|
||||
const ConfigBlock &block, Error &error)
|
||||
const ConfigBlock &)
|
||||
{
|
||||
UpnpDatabase *db = new UpnpDatabase();
|
||||
if (!db->Configure(block, error)) {
|
||||
delete db;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
inline bool
|
||||
UpnpDatabase::Configure(const ConfigBlock &, Error &)
|
||||
{
|
||||
return true;
|
||||
return new UpnpDatabase();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -127,13 +127,7 @@ try {
|
||||
if (path != nullptr)
|
||||
block.AddBlockParam("path", path->value.c_str(), path->line);
|
||||
|
||||
Database *db = plugin->create(event_loop, database_listener,
|
||||
block, error);
|
||||
|
||||
if (db == nullptr) {
|
||||
cerr << error.GetMessage() << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
Database *db = plugin->create(event_loop, database_listener, block);
|
||||
|
||||
AtScopeExit(db) { delete db; };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user