db/simple: throw C++ exception on init error
This commit is contained in:
parent
e17805f208
commit
7e5ce623fe
src/db/plugins/simple
@ -51,14 +51,20 @@
|
|||||||
|
|
||||||
static constexpr Domain simple_db_domain("simple_db");
|
static constexpr Domain simple_db_domain("simple_db");
|
||||||
|
|
||||||
inline SimpleDatabase::SimpleDatabase()
|
inline SimpleDatabase::SimpleDatabase(const ConfigBlock &block)
|
||||||
:Database(simple_db_plugin),
|
:Database(simple_db_plugin),
|
||||||
path(AllocatedPath::Null()),
|
path(block.GetPath("path")),
|
||||||
#ifdef ENABLE_ZLIB
|
#ifdef ENABLE_ZLIB
|
||||||
compress(true),
|
compress(block.GetBlockValue("compress", true)),
|
||||||
#endif
|
#endif
|
||||||
cache_path(AllocatedPath::Null()),
|
cache_path(block.GetPath("cache_directory")),
|
||||||
prefixed_light_song(nullptr) {}
|
prefixed_light_song(nullptr)
|
||||||
|
{
|
||||||
|
if (path.IsNull())
|
||||||
|
throw std::runtime_error("No \"path\" parameter specified");
|
||||||
|
|
||||||
|
path_utf8 = path.ToUTF8();
|
||||||
|
}
|
||||||
|
|
||||||
inline SimpleDatabase::SimpleDatabase(AllocatedPath &&_path,
|
inline SimpleDatabase::SimpleDatabase(AllocatedPath &&_path,
|
||||||
#ifndef ENABLE_ZLIB
|
#ifndef ENABLE_ZLIB
|
||||||
@ -80,25 +86,7 @@ SimpleDatabase::Create(gcc_unused EventLoop &loop,
|
|||||||
gcc_unused DatabaseListener &listener,
|
gcc_unused DatabaseListener &listener,
|
||||||
const ConfigBlock &block, Error &)
|
const ConfigBlock &block, Error &)
|
||||||
{
|
{
|
||||||
SimpleDatabase *db = new SimpleDatabase();
|
return new SimpleDatabase(block);
|
||||||
db->Configure(block);
|
|
||||||
return db;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SimpleDatabase::Configure(const ConfigBlock &block)
|
|
||||||
{
|
|
||||||
path = block.GetPath("path");
|
|
||||||
if (path.IsNull())
|
|
||||||
throw std::runtime_error("No \"path\" parameter specified");
|
|
||||||
|
|
||||||
path_utf8 = path.ToUTF8();
|
|
||||||
|
|
||||||
cache_path = block.GetPath("cache_directory");
|
|
||||||
|
|
||||||
#ifdef ENABLE_ZLIB
|
|
||||||
compress = block.GetBlockValue("compress", compress);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -67,7 +67,7 @@ class SimpleDatabase : public Database {
|
|||||||
mutable unsigned borrowed_song_count;
|
mutable unsigned borrowed_song_count;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SimpleDatabase();
|
SimpleDatabase(const ConfigBlock &block);
|
||||||
|
|
||||||
SimpleDatabase(AllocatedPath &&_path, bool _compress);
|
SimpleDatabase(AllocatedPath &&_path, bool _compress);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user