Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MythContext refactoring #671

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft

Conversation

ulmus-scott
Copy link
Contributor

I had planned to do more, but I got fed up with the use of global state and Singletons, so this is all I have done for now.

Checklist

These details do not need to be exposed in the header
since MythContextPrivate is already a QObject.
Convert it to a nested private class and rename
MythContext::d to m_impl.
It was only used once by a line from commit
0d4ef8e

Use MythContext::Impl's own members and methods instead of redirecting
back to them through MythContext.
Whether to show the prompt was never determined at runtime
and in one case was forced regardless of whether or not a
temporary window already existed (which would have prevented
the prompt from showing as it would return early from
TempMainWindow()).
and directly access the MythDB singleton.

This should help reasoning about further changes.
…calls

The only functional difference is that m_dbParams::m_localEnabled
is now conditionally set before the first
`gCoreContext->GetDB()->SetDatabaseParams(m_dbParams);` call.

This doesn't matter since it was set before the second SetDatabaseParams()
call, likely via ResetDatabase().  Also, DatabaseParams::m_localEnabled
is practically unused.

This split is to enable refactoring out the DatabaseSettingsCache into
its own class by reducing LoadDatabaseSettings() to its core functionality.
This is necessary to enable loading the cache in its constructor before
the MythCoreContext constructor has finished, i.e. while gCoreContext is
nullptr.
…ingleton

This should allow moving the DatabaseSettingsCache to MythDB since
save can now be called at any time.
These are only used in mythtv/programs and occasionally in mythtv/libs,
so this can be a private header.
The current QT5_MIN_VERSION_STR is 5.15.2.
and move its use in *.h to *.cpp files.

git grep -l mythcorecontext.h > mythcorecontext.txt; git grep -l -E "gCoreContext|MythCoreContext" -- ':!*/i18n/*' > gCoreContext.txt; git diff --no-index -U0 mythcorecontext.txt gCoreContext.txt

git grep -l mythcorecontext.h -- *.h
A few remain in programs.
It was never set nor reset and would thus not work as intended.
It was only used twice and I will replace one of those uses shortly.
This is to simplify moving the cache to MythDB.

DatabaseParamsCache::SaveDatabaseParams(): inline ResetDatabase(), removing the
duplicate call to MythDB::SetDatabaseParams().
If the string is already empty then clearing it does nothing
and the DatabaseParams are already equal.
GetMythDB() will always return a valid pointer to the global MythDB instance.

Some of the functions previously did not update the DatabaseParams in MythDB;
however, this shouldn't make a difference since only libmyth/mythcontext.cpp
ever called MythDB::SetDatabaseParams().

gContext is now unused in the libraries and can be removed.
After much investigation, I discovered that the popup the hack is supposed to be
preventing has not existed since it was replaced with a notification in 2013 in
7dcf2a5
Convert it into an instance so the destructor is called automatically.

mythtv-setup:
SetupMenuCallback() does not use the data pointer, so feed it with nullptr.

mythfrontend:
TVMenuCallback() also does not use the data pointer, so feed it with nullptr.

mythbackend:
httpconfig.cpp: The only HttpConfig is created in MediaServer::Init() which is
only called in run_backend() after the MythContext is created in main(), so that
check was always false.

V2Myth::s_WebOnlyStartup: I would have prefered to avoid global state and pass
it as a parameter to V2Myth() via run_backend() and run_setup_webserver() but
the entire class is already static.

V2Myth is a better place for WebOnlyStartup since that is the only place it is
used.

CleanupGuards:
Move the CleanupGuard instance after the MythContext, so it is destroyed first.
~MythCoreContextPrivate() calls MThread::Cleanup() which wants all threads to
already be destroyed.  Move DestroyMythMainWindow() into ~MythContext() so the
static MythUDP instance destroys its thread.

ReferenceCounter::PrintDebug(): remove extraneous ui include and move into
~MythContext() so it is called after all objects should be destroyed.
I would have preferred to make it into an instance within MythContext, but
libmythtv/tv_play.cpp uses SignalHandler::IsExiting(), which seems like a hack.
From:
MythTV@f9a46e0

If _WIN32 is defined, the SignalHandler will only create its initial strings.

mythfrontend's extra signal handlers are triggered externally and are from:
MythTV@4b67e3e
MythTV@2aa4aa5
…mythlogging.h"'

git grep -l mythlogging.h > mythlogging.txt; git grep -l -w -E "LOG|VERBOSE_" -- mythplugins mythtv/libs mythtv/programs > LOG.txt; git diff --no-index -U0 mythlogging.txt LOG.txt

git grep -l mythlogging.h -- *.h

Only header in mythplugins is a header only file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant