summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Instance.cxx2
-rw-r--r--src/Instance.hxx6
-rw-r--r--src/Main.cxx7
-rw-r--r--src/StateFile.cxx2
-rw-r--r--src/Stats.cxx2
-rw-r--r--src/command/OtherCommands.cxx2
-rw-r--r--src/command/StorageCommands.cxx4
-rw-r--r--src/storage/StorageState.cxx2
8 files changed, 13 insertions, 14 deletions
diff --git a/src/Instance.cxx b/src/Instance.cxx
index af3d01456..c2032aa7c 100644
--- a/src/Instance.cxx
+++ b/src/Instance.cxx
@@ -58,7 +58,7 @@ Instance::~Instance() noexcept
if (database != nullptr) {
database->Close();
- delete database;
+ database.reset();
}
delete storage;
diff --git a/src/Instance.hxx b/src/Instance.hxx
index 23a3c52b9..5aa2209d9 100644
--- a/src/Instance.hxx
+++ b/src/Instance.hxx
@@ -41,7 +41,7 @@ class NeighborGlue;
#ifdef ENABLE_DATABASE
#include "db/DatabaseListener.hxx"
-class Database;
+#include "db/Ptr.hxx"
class Storage;
class UpdateService;
#endif
@@ -104,7 +104,7 @@ struct Instance final
#endif
#ifdef ENABLE_DATABASE
- Database *database;
+ DatabasePtr database;
/**
* This is really a #CompositeStorage. To avoid heavy include
@@ -155,7 +155,7 @@ struct Instance final
* music_directory was configured).
*/
Database *GetDatabase() {
- return database;
+ return database.get();
}
/**
diff --git a/src/Main.cxx b/src/Main.cxx
index 89b6eaf8f..87bda1734 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -188,7 +188,7 @@ glue_db_init_and_load(const ConfigData &config)
instance->database =
CreateConfiguredDatabase(config, instance->event_loop,
instance->io_thread.GetEventLoop(),
- *instance).release();
+ *instance);
if (instance->database == nullptr)
return true;
@@ -196,8 +196,7 @@ glue_db_init_and_load(const ConfigData &config)
InitStorage(config, instance->io_thread.GetEventLoop());
if (instance->storage == nullptr) {
- delete instance->database;
- instance->database = nullptr;
+ instance->database.reset();
LogDefault(config_domain,
"Found database setting without "
"music_directory - disabling database");
@@ -216,7 +215,7 @@ glue_db_init_and_load(const ConfigData &config)
std::throw_with_nested(std::runtime_error("Failed to open database plugin"));
}
- auto *db = dynamic_cast<SimpleDatabase *>(instance->database);
+ auto *db = dynamic_cast<SimpleDatabase *>(instance->database.get());
if (db == nullptr)
return true;
diff --git a/src/StateFile.cxx b/src/StateFile.cxx
index 4dd4d449b..b8ad82e01 100644
--- a/src/StateFile.cxx
+++ b/src/StateFile.cxx
@@ -119,7 +119,7 @@ try {
TextFile file(config.path);
#ifdef ENABLE_DATABASE
- const SongLoader song_loader(partition.instance.database,
+ const SongLoader song_loader(partition.instance.GetDatabase(),
partition.instance.storage);
#else
const SongLoader song_loader(nullptr, nullptr);
diff --git a/src/Stats.cxx b/src/Stats.cxx
index a9b8619fe..b8773d6f0 100644
--- a/src/Stats.cxx
+++ b/src/Stats.cxx
@@ -124,7 +124,7 @@ stats_print(Response &r, const Partition &partition)
std::lround(partition.pc.GetTotalPlayTime().count()));
#ifdef ENABLE_DATABASE
- const Database *db = partition.instance.database;
+ const Database *db = partition.instance.GetDatabase();
if (db != nullptr)
db_stats_print(r, *db);
#endif
diff --git a/src/command/OtherCommands.cxx b/src/command/OtherCommands.cxx
index 00f895956..5228868d9 100644
--- a/src/command/OtherCommands.cxx
+++ b/src/command/OtherCommands.cxx
@@ -294,7 +294,7 @@ handle_update(Client &client, Request args, Response &r, bool discard)
if (update != nullptr)
return handle_update(r, *update, path, discard);
- Database *db = client.GetInstance().database;
+ Database *db = client.GetInstance().GetDatabase();
if (db != nullptr)
return handle_update(r, *db, path, discard);
#else
diff --git a/src/command/StorageCommands.cxx b/src/command/StorageCommands.cxx
index ef779a318..2333eca4a 100644
--- a/src/command/StorageCommands.cxx
+++ b/src/command/StorageCommands.cxx
@@ -209,7 +209,7 @@ handle_mount(Client &client, Request args, Response &r)
instance.EmitIdle(IDLE_MOUNT);
#ifdef ENABLE_DATABASE
- if (auto *db = dynamic_cast<SimpleDatabase *>(instance.database)) {
+ if (auto *db = dynamic_cast<SimpleDatabase *>(instance.GetDatabase())) {
try {
db->Mount(local_uri, remote_uri);
} catch (...) {
@@ -253,7 +253,7 @@ handle_unmount(Client &client, Request args, Response &r)
destroy here */
instance.update->CancelMount(local_uri);
- if (auto *db = dynamic_cast<SimpleDatabase *>(instance.database)) {
+ if (auto *db = dynamic_cast<SimpleDatabase *>(instance.GetDatabase())) {
if (db->Unmount(local_uri))
// TODO: call Instance::OnDatabaseModified()?
instance.EmitIdle(IDLE_DATABASE);
diff --git a/src/storage/StorageState.cxx b/src/storage/StorageState.cxx
index 5cf2f4428..eea57fa26 100644
--- a/src/storage/StorageState.cxx
+++ b/src/storage/StorageState.cxx
@@ -106,7 +106,7 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
return true;
}
- if (auto *db = dynamic_cast<SimpleDatabase *>(instance.database)) {
+ if (auto *db = dynamic_cast<SimpleDatabase *>(instance.GetDatabase())) {
try {
db->Mount(uri.c_str(), url.c_str());
} catch (...) {