Main: move part of the shutdown code to Instance methods
This commit is contained in:
parent
c1221c5c87
commit
52da387a1d
|
@ -114,6 +114,9 @@ struct Instance final
|
||||||
gcc_pure
|
gcc_pure
|
||||||
Partition *FindPartition(const char *name) noexcept;
|
Partition *FindPartition(const char *name) noexcept;
|
||||||
|
|
||||||
|
void BeginShutdownPartitions() noexcept;
|
||||||
|
void FinishShutdownPartitions() noexcept;
|
||||||
|
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
/**
|
/**
|
||||||
* Returns the global #Database instance. May return nullptr
|
* Returns the global #Database instance. May return nullptr
|
||||||
|
@ -132,6 +135,10 @@ struct Instance final
|
||||||
const Database &GetDatabaseOrThrow() const;
|
const Database &GetDatabaseOrThrow() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void BeginShutdownUpdate() noexcept;
|
||||||
|
void FinishShutdownUpdate() noexcept;
|
||||||
|
void ShutdownDatabase() noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
void OnDatabaseModified() override;
|
void OnDatabaseModified() override;
|
||||||
|
|
73
src/Main.cxx
73
src/Main.cxx
|
@ -405,6 +405,53 @@ initialize_decoder_and_player(const ReplayGainConfig &replay_gain_config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
Instance::BeginShutdownUpdate() noexcept
|
||||||
|
{
|
||||||
|
#ifdef ENABLE_DATABASE
|
||||||
|
#ifdef ENABLE_INOTIFY
|
||||||
|
mpd_inotify_finish();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (update != nullptr)
|
||||||
|
update->CancelAllAsync();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
Instance::FinishShutdownUpdate() noexcept
|
||||||
|
{
|
||||||
|
#ifdef ENABLE_DATABASE
|
||||||
|
delete update;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
Instance::ShutdownDatabase() noexcept
|
||||||
|
{
|
||||||
|
#ifdef ENABLE_DATABASE
|
||||||
|
if (instance->database != nullptr) {
|
||||||
|
instance->database->Close();
|
||||||
|
delete instance->database;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete instance->storage;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
Instance::BeginShutdownPartitions() noexcept
|
||||||
|
{
|
||||||
|
for (auto &partition : partitions)
|
||||||
|
partition.pc.Kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
Instance::FinishShutdownPartitions() noexcept
|
||||||
|
{
|
||||||
|
partitions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Instance::OnIdle(unsigned flags)
|
Instance::OnIdle(unsigned flags)
|
||||||
{
|
{
|
||||||
|
@ -643,22 +690,14 @@ try {
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
|
|
||||||
#ifdef ENABLE_DATABASE
|
instance->BeginShutdownUpdate();
|
||||||
#ifdef ENABLE_INOTIFY
|
|
||||||
mpd_inotify_finish();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (instance->update != nullptr)
|
|
||||||
instance->update->CancelAllAsync();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (instance->state_file != nullptr) {
|
if (instance->state_file != nullptr) {
|
||||||
instance->state_file->Write();
|
instance->state_file->Write();
|
||||||
delete instance->state_file;
|
delete instance->state_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &partition : instance->partitions)
|
instance->BeginShutdownPartitions();
|
||||||
partition.pc.Kill();
|
|
||||||
|
|
||||||
ZeroconfDeinit();
|
ZeroconfDeinit();
|
||||||
listen_global_finish();
|
listen_global_finish();
|
||||||
|
@ -671,16 +710,8 @@ try {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_DATABASE
|
instance->FinishShutdownUpdate();
|
||||||
delete instance->update;
|
instance->ShutdownDatabase();
|
||||||
|
|
||||||
if (instance->database != nullptr) {
|
|
||||||
instance->database->Close();
|
|
||||||
delete instance->database;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete instance->storage;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ENABLE_SQLITE
|
#ifdef ENABLE_SQLITE
|
||||||
sticker_global_finish();
|
sticker_global_finish();
|
||||||
|
@ -695,7 +726,7 @@ try {
|
||||||
|
|
||||||
DeinitFS();
|
DeinitFS();
|
||||||
|
|
||||||
instance->partitions.clear();
|
instance->FinishShutdownPartitions();
|
||||||
command_finish();
|
command_finish();
|
||||||
decoder_plugin_deinit_all();
|
decoder_plugin_deinit_all();
|
||||||
#ifdef ENABLE_ARCHIVE
|
#ifdef ENABLE_ARCHIVE
|
||||||
|
|
Loading…
Reference in New Issue