[mythtv] RFC: Refactoring and code standards

Scott T scott.the.elm at gmail.com
Wed Sep 8 01:29:44 UTC 2021

On 9/6/21 4:48 AM, Stuart Auchterlonie wrote:
> Can you share your thoughts on what you are looking to achieve here?
> Having just pulled the startup sequence apart, i agree it's not the
> prettiest thing, and there is likely to be room for improvement. 

When I was looking at the code to figure out a bug I found (fix: 
https://github.com/MythTV/mythtv/pull/385 ; 
https://github.com/MythTV/mythtv/pull/369 (changes in 385 now); 
https://forum.mythtv.org/viewtopic.php?f=36&t=4470&start=45#p22285), I 
noticed the code in mythcontext was messy and not very readable.

My goal is to make the code more readable (some work, subject to changes 
and rebasing, is on my fork https://github.com/ulmus-scott/mythtv ).  
Much work remains, e.g. merging the anemic MythContextSlotHandler into 
MythContextPrivate, separating the settings caches into their own 
classes, some old cache format code to remove, some hacks to test.

I was originally only looking at MythContext, but I got distracted by 
the unnecessary shim duplication of MythDB’s methods in 
MythCoreContext.  I was also thinking of making the MythDB instance a 
global variable, but thinking on it some more, it would probably be 
better to make it a member of MythCoreContext (still exposing it via the 
global GetMythDB() ), since trying to access it uninitialized doesn’t 
make any sense.

Communicating between MythCoreContext and MythContext via QObjects and 
QEvents, seems, at the very least, hack-y, if not breaking 
encapsulation.  I’m thinking of renaming MythContext to MythGUIContext, 
as seems to have been the intent, and make it a subclass of 
MythCoreContext, overriding the CLI superclass methods with the subclass 
GUI counterparts.

To investigate:
Does MythCoreContext need to be a QObject?  The TVPlayback signals 
(without having looked at them) seem out of scope for MythCoreContext 
(frontend only? And thus GUI only?).

Beyond current scope of work:
cleanup in MythMainWindow (similarly quasi-global as MythDB) (seems to 
also be MythCoreContext’s GUIObject)

Improve logging with __FILE__, __LINE__, and __func__.  Readability: 
define masks with bit shifting.  Add a mask for fonts to enable 
disabling output (debug produces lots of extraneous font messages).


More information about the mythtv-dev mailing list