Skip to content

Commit

Permalink
merge CleanupGuard into MythContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ulmus-scott committed Dec 2, 2024
1 parent a212a84 commit a57d74a
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 39 deletions.
5 changes: 5 additions & 0 deletions mythtv/libs/libmyth/mythcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,11 @@ bool MythContext::Init(const bool gui,

MythContext::~MythContext()
{
if (m_cleanup != nullptr)
{
m_cleanup();
}

if (m_impl->m_gui)
{
DestroyMythMainWindow();
Expand Down
8 changes: 8 additions & 0 deletions mythtv/libs/libmyth/mythcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class MPUBLIC MythContext
bool disableAutoDiscovery = false,
bool ignoreDB = false);

using CleanupFunction = void (*)();
void setCleanup(CleanupFunction cleanup) { m_cleanup = cleanup; }

bool saveSettingsCache();

void SetDisableEventPopup(bool check);
Expand All @@ -37,6 +40,11 @@ class MPUBLIC MythContext
class Impl;
Impl *m_impl {nullptr}; ///< PIMPL idiom
QString m_appBinaryVersion;
/**
This is used to destroy global state before main() returns. It is called
first before anything else is done in ~MythContext() if it is not nullptr.
*/
CleanupFunction m_cleanup {nullptr};
};

#endif
Expand Down
2 changes: 0 additions & 2 deletions mythtv/libs/libmythbase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ set(LIBMYTHBASE_HEADERS

set(LIBMYTHBASE_HEADERS_NOT_INSTALLED
mythbinaryplist.h
cleanupguard.h
configuration.h
housekeeper.h
logging.h
Expand Down Expand Up @@ -146,7 +145,6 @@ add_library(
${LIBMYTHBASE_HEADERS}
${LIBMYTHBASE_HEADERS_NOT_INSTALLED}
${LIBMYTHBASE_HTTP_HEADERS}
cleanupguard.cpp
configuration.cpp
dbcheckcommon.cpp
dbutil.cpp
Expand Down
11 changes: 0 additions & 11 deletions mythtv/libs/libmythbase/cleanupguard.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions mythtv/libs/libmythbase/cleanupguard.h

This file was deleted.

4 changes: 2 additions & 2 deletions mythtv/libs/libmythbase/libmythbase.pro
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ HEADERS += mythsystemlegacy.h mythtypes.h
HEADERS += threadedfilewriter.h mythsingledownload.h
HEADERS += ternarycompare.h
HEADERS += mythsession.h
HEADERS += cleanupguard.h portchecker.h
HEADERS += portchecker.h
HEADERS += mythsorthelper.h mythdbcheck.h
HEADERS += mythpower.h
HEADERS += configuration.h
Expand Down Expand Up @@ -76,7 +76,7 @@ SOURCES += mythrandom.cpp
SOURCES += stringutil.cpp
SOURCES += threadedfilewriter.cpp mythsingledownload.cpp
SOURCES += mythsession.cpp
SOURCES += cleanupguard.cpp portchecker.cpp
SOURCES += portchecker.cpp
SOURCES += mythsorthelper.cpp dbcheckcommon.cpp
SOURCES += mythpower.cpp
SOURCES += configuration.cpp
Expand Down
3 changes: 1 addition & 2 deletions mythtv/programs/mythbackend/mythbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

// MythTV
#include "libmyth/mythcontext.h"
#include "libmythbase/cleanupguard.h"
#include "libmythbase/compat.h"
#include "libmythbase/configuration.h"
#include "libmythbase/exitcodes.h"
Expand Down Expand Up @@ -156,7 +155,7 @@ int main(int argc, char **argv)
LOG(VB_GENERAL, LOG_CRIT, "Failed to init MythContext.");
return GENERIC_EXIT_NO_MYTHCONTEXT;
}
CleanupGuard callCleanup(cleanup);
context.setCleanup(cleanup);

MythTranslation::load("mythfrontend");

Expand Down
3 changes: 1 addition & 2 deletions mythtv/programs/mythfrontend/mythfrontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "libmyth/mythcontext.h"
#include "libmyth/mythmediamonitor.h"
#include "libmyth/standardsettings.h"
#include "libmythbase/cleanupguard.h"
#include "libmythbase/compat.h" // For SIG* on MinGW
#include "libmythbase/exitcodes.h"
#include "libmythbase/hardwareprofile.h"
Expand Down Expand Up @@ -2024,7 +2023,7 @@ Q_DECL_EXPORT int main(int argc, char **argv)
gCoreContext->SetExiting(true);
return GENERIC_EXIT_NO_MYTHCONTEXT;
}
CleanupGuard callCleanup(cleanup);
context.setCleanup(cleanup);

SignalHandler::SetHandler(SIGUSR1, handleSIGUSR1);
SignalHandler::SetHandler(SIGUSR2, handleSIGUSR2);
Expand Down

0 comments on commit a57d74a

Please sign in to comment.