MythTV  master
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
RecordingExtender Class Reference

#include <recordingextender.h>

Inheritance diagram for RecordingExtender:
Inheritance graph
[legend]
Collaboration diagram for RecordingExtender:
Collaboration graph
[legend]

Public Member Functions

void run (void) override
 The main execution loop for the Recording Extender. More...
 
 ~RecordingExtender () override
 
- Public Member Functions inherited from MThread
 MThread (const QString &objectName)
 Standard constructor. More...
 
 MThread (const QString &objectName, QRunnable *runnable)
 Use this constructor if you want the default run() method to run the QRunnable's run() method instead of entering the Qt event loop. More...
 
virtual ~MThread ()
 
 MThread (const MThread &)=delete
 
MThreadoperator= (const MThread &)=delete
 
void RunProlog (void)
 Sets up a thread, call this if you reimplement run(). More...
 
void RunEpilog (void)
 Cleans up a thread's resources, call this if you reimplement run(). More...
 
QThread * qthread (void)
 Returns the thread, this will always return the same pointer no matter how often you restart the thread. More...
 
void setObjectName (const QString &name)
 
QString objectName (void) const
 
void setPriority (QThread::Priority priority)
 
QThread::Priority priority (void) const
 
bool isFinished (void) const
 
bool isRunning (void) const
 
void setStackSize (uint stackSize)
 
uint stackSize (void) const
 
void exit (int retcode=0)
 Use this to exit from the thread if you are using a Qt event loop. More...
 
void start (QThread::Priority p=QThread::InheritPriority)
 Tell MThread to start running the thread in the near future. More...
 
void terminate (void)
 Kill a thread unsafely. More...
 
void quit (void)
 calls exit(0) More...
 
bool wait (std::chrono::milliseconds time=std::chrono::milliseconds::max())
 Wait for the MThread to exit, with a maximum timeout. More...
 

Static Public Member Functions

static void create (Scheduler *scheduler, RecordingInfo &ri)
 Create an instance of the RecordingExtender if necessary, and add this recording to the list of new recordings. More...
 
static void nameCleanup (const SportInfo &info, QString &name1, QString &name2)
 Clean up two team names for comparison against the ESPN API. More...
 
- Static Public Member Functions inherited from MThread
static void ThreadSetup (const QString &name)
 This is to be called on startup in those few threads that haven't been ported to MThread. More...
 
static void ThreadCleanup (void)
 This is to be called on exit in those few threads that haven't been ported to MThread. More...
 
static void Cleanup (void)
 This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total for all the threads to exit. More...
 
static void GetAllThreadNames (QStringList &list)
 
static void GetAllRunningThreadNames (QStringList &list)
 

Private Member Functions

 RecordingExtender ()
 
void addNewRecording (int recordedID)
 Add an item to the list of new recordings. More...
 
bool findKnownSport (const QString &_title, AutoExtendType type, SportInfoList &info) const
 Retrieve the db record for a sporting event on a specific provider. More...
 
virtual RecExtDataSourcecreateDataSource (AutoExtendType type)
 Create a RecExtDataSource object for the specified service. More...
 
void extendRecording (const RecordingInfo *ri, RecordingRule *rr, const ActiveGame &game)
 Extend the current recording by XX minutes. More...
 
void processNewRecordings ()
 Process the list of newly started sports recordings. More...
 
void processActiveRecordings ()
 Process the currently active sports recordings. More...
 
void checkDone ()
 Is there any remaining work? Check for both newly created recording and for active recordings. More...
 
void expireOverrides ()
 Delete the list of the override rules that have been created by this instance of RecordingExtender. More...
 

Static Private Member Functions

static void clearDownloadedInfo ()
 Clear all downloaded info. More...
 
static bool parseProgramInfo (const QString &subtitle, const QString &description, QString &team1, QString &team2)
 Parse a RecordingInfo to find the team names. More...
 
static QString ruleIdAsString (const RecordingRule *rr)
 Quick helper function for printing recording rule numbers. More...
 
static void finishRecording (const RecordingInfo *ri, RecordingRule *rr, const ActiveGame &game)
 Stop the current recording early. More...
 
static void unchangedRecording (const RecordingInfo *ri, RecordingRule *rr, const ActiveGame &game)
 Log that this recording hasn't changed. More...
 
static void nameCleanup (const SportInfo &info, QString &name)
 Clean up a single team name for comparison against the ESPN API. More...
 

Private Attributes

bool m_running {true}
 Whether the RecordingExtender process is running. More...
 
Schedulerm_scheduler {nullptr}
 Pointer to the scheduler. More...
 
QMutex m_newRecordingsLock
 New recordings are added by the scheduler process and removed by this process. More...
 
QList< int > m_newRecordings
 Newly started recordings to process. More...
 
QList< ActiveGamem_activeGames
 Currently ongoing games to track. More...
 
QList< int > m_overrideRules
 Recordings that have had an override rule creates. More...
 
uint m_forcedYearforTesting {0}
 Testing data. More...
 

Static Private Attributes

static RecordingExtenders_singleton {nullptr}
 The single instance of a RecordingExtender. More...
 
static QMutex s_createLock {}
 Interlock the scheduler thread crating this process, and this process determining whether it should continue running. More...
 

Friends

class TestRecordingExtender
 

Additional Inherited Members

- Protected Member Functions inherited from MThread
int exec (void)
 Enters the qt event loop. call exit or quit to exit thread. More...
 
- Static Protected Member Functions inherited from MThread
static void setTerminationEnabled (bool enabled=true)
 
static void usleep (std::chrono::microseconds time)
 
template<typename R , typename P >
static std::enable_if_t< std::chrono::treat_as_floating_point< R >::value, void > usleep (std::chrono::duration< R, P > time)
 
- Protected Attributes inherited from MThread
MThreadInternalm_thread {nullptr}
 
QRunnable * m_runnable {nullptr}
 
bool m_prologExecuted {true}
 
bool m_epilogExecuted {true}
 

Detailed Description

Definition at line 307 of file recordingextender.h.

Constructor & Destructor Documentation

◆ ~RecordingExtender()

RecordingExtender::~RecordingExtender ( )
override

Definition at line 1065 of file recordingextender.cpp.

◆ RecordingExtender()

RecordingExtender::RecordingExtender ( )
inlineprivate

Definition at line 319 of file recordingextender.h.

Referenced by create().

Member Function Documentation

◆ create()

void RecordingExtender::create ( Scheduler scheduler,
RecordingInfo ri 
)
static

Create an instance of the RecordingExtender if necessary, and add this recording to the list of new recordings.

This function is called by the scheduler for all new recordings, but only does anything if the recording is marked to be auto extended.

Note
This function runs on the scheduler thread. It defers all work to the Recording Extender thread.
Parameters
schedulerA pointer to the scheduler object.
riThe recording that just started.

Definition at line 1080 of file recordingextender.cpp.

Referenced by Scheduler::HandleRecording().

◆ run()

void RecordingExtender::run ( void  )
overridevirtual

The main execution loop for the Recording Extender.

Reimplemented from MThread.

Definition at line 1681 of file recordingextender.cpp.

◆ nameCleanup() [1/2]

void RecordingExtender::nameCleanup ( const SportInfo info,
QString &  name1,
QString &  name2 
)
static

Clean up two team names for comparison against the ESPN API.

See also
RecordingExtender::nameCleanup(const SportInfo& info, QString& name)
Parameters
[in]infoA data structure defining the current sport.
[in,out]name1The first sports team name to clean up.
[in,out]name2The second sports team name to clean up.

Definition at line 1352 of file recordingextender.cpp.

Referenced by RecExtEspnDataPage::findGameInfo(), RecExtMlbDataPage::parseGameObject(), and processNewRecordings().

◆ addNewRecording()

void RecordingExtender::addNewRecording ( int  recordedID)
private

Add an item to the list of new recordings.

Handles locking of the new recordings list.

Parameters
recordedIDThe recording ID of the recording that just started.

Definition at line 1109 of file recordingextender.cpp.

Referenced by create().

◆ findKnownSport()

bool RecordingExtender::findKnownSport ( const QString &  _title,
AutoExtendType  type,
SportInfoList infoList 
) const
private

Retrieve the db record for a sporting event on a specific provider.

This function handles regex matching between program listings and database entries.

If the title contains a year (i.e. four consecutive digits) then the year must be this year in order to match. Handling the year this way simplifies all the regular expressions, eliminating the need for each one to allow for a starting or ending year.

Parameters
titleThe program title of the sporting event. I.E. "MLB Baseball", "2021 World Series", or "Superbowl LVI".
typeAn identifier for the service used to check the game status.
infoListIf the function returns true, this contains a list of the databases record for the specified sporting event and provider. Unchanged otherwise. Everything other than FIFA Soccer Qualification Matches will likely return a single entry.
Returns
true if the title matches a known sport.

Definition at line 1155 of file recordingextender.cpp.

Referenced by processNewRecordings().

◆ clearDownloadedInfo()

void RecordingExtender::clearDownloadedInfo ( )
staticprivate

Clear all downloaded info.

Definition at line 1211 of file recordingextender.cpp.

Referenced by run(), and ~RecordingExtender().

◆ createDataSource()

RecExtDataSource * RecordingExtender::createDataSource ( AutoExtendType  type)
privatevirtual

Create a RecExtDataSource object for the specified service.

This will never produce the base class object, but will only produce one of the subclass objects.

Parameters
[in]parentA pointer to the RecordingExtender object that created this data source.
[in]typeAn identifier for the service used to check the game status.

Definition at line 1123 of file recordingextender.cpp.

Referenced by processActiveRecordings(), and processNewRecordings().

◆ parseProgramInfo()

bool RecordingExtender::parseProgramInfo ( const QString &  subtitle,
const QString &  description,
QString &  team1,
QString &  team2 
)
staticprivate

Parse a RecordingInfo to find the team names.

Depending on the guide data source, this can be found either in the subtitle or in the description field.

Parameters
[in]riThe RecordingInfo to parse.
[out]team1The name of the first team.
[out]team2The name of the second team.
Returns
true if the team names could be determined.

Definition at line 1250 of file recordingextender.cpp.

Referenced by processNewRecordings().

◆ ruleIdAsString()

QString RecordingExtender::ruleIdAsString ( const RecordingRule rr)
staticprivate

Quick helper function for printing recording rule numbers.

If there is a parent rule this prints two numbers, otherwise it prints one.

Parameters
[in]rrThe recording rule to print.
Returns
a string representing this rule.

Definition at line 1268 of file recordingextender.cpp.

Referenced by extendRecording(), finishRecording(), and unchangedRecording().

◆ finishRecording()

void RecordingExtender::finishRecording ( const RecordingInfo ri,
RecordingRule rr,
const ActiveGame game 
)
staticprivate

Stop the current recording early.

The main idea behind having this function is to catch games that are called on account of rain, etc, and not record whatever random programming the network shows after the game is postponed.

Parameters
riA pointer to the RecordingInfo for the recording to be extended.
rrA pointer to the RecordingRule for the recording to be extended.
gameA reference to the current sporting event.

Definition at line 1369 of file recordingextender.cpp.

Referenced by processActiveRecordings().

◆ extendRecording()

void RecordingExtender::extendRecording ( const RecordingInfo ri,
RecordingRule rr,
const ActiveGame game 
)
private

Extend the current recording by XX minutes.

The first time this is done it creates a new override recording.

Parameters
riA pointer to the RecordingInfo for the recording to be extended.
rrA pointer to the RecordingRule for the recording to be extended.
gameA reference to the current sporting event.

Definition at line 1391 of file recordingextender.cpp.

Referenced by processActiveRecordings().

◆ unchangedRecording()

void RecordingExtender::unchangedRecording ( const RecordingInfo ri,
RecordingRule rr,
const ActiveGame game 
)
staticprivate

Log that this recording hasn't changed.

Parameters
riA pointer to the RecordingInfo for the recording to be extended.
rrA pointer to the RecordingRule for the recording to be extended.
gameA reference to the current sporting event.

Definition at line 1451 of file recordingextender.cpp.

Referenced by processActiveRecordings().

◆ processNewRecordings()

void RecordingExtender::processNewRecordings ( )
private

Process the list of newly started sports recordings.

Create an ActiveGame structure for this recording, and determine the URL to get data for this particular game.

Definition at line 1472 of file recordingextender.cpp.

Referenced by run().

◆ processActiveRecordings()

void RecordingExtender::processActiveRecordings ( )
private

Process the currently active sports recordings.

Query provider for current game status. If the game finished early, stop it. If the game is still going and the recording is about to end, extend the recording. get data for this particular game.

Definition at line 1573 of file recordingextender.cpp.

Referenced by run().

◆ checkDone()

void RecordingExtender::checkDone ( )
private

Is there any remaining work? Check for both newly created recording and for active recordings.

Definition at line 1660 of file recordingextender.cpp.

Referenced by run().

◆ nameCleanup() [2/2]

void RecordingExtender::nameCleanup ( const SportInfo info,
QString &  name 
)
staticprivate

Clean up a single team name for comparison against the ESPN API.

This means normalizing the Unicode, removing any diacritical marks, and removing any extraneous white space. For soccer, however, it also means removing a bunch of common sets of initials like "FC (Football Club)", "SC (Sports Club)", etc. that don't appear in the ESPN API.

Parameters
[in]infoA data structure defining the current sport.
[in,out]nameThe sports team name to clean up.

Definition at line 1284 of file recordingextender.cpp.

◆ expireOverrides()

void RecordingExtender::expireOverrides ( )
private

Delete the list of the override rules that have been created by this instance of RecordingExtender.

No need to delete the actual rules, as they'll be cleaned up by the housekeeping code.

Definition at line 1464 of file recordingextender.cpp.

Referenced by run().

Friends And Related Function Documentation

◆ TestRecordingExtender

friend class TestRecordingExtender
friend

Definition at line 309 of file recordingextender.h.

Member Data Documentation

◆ s_singleton

RecordingExtender * RecordingExtender::s_singleton {nullptr}
staticprivate

The single instance of a RecordingExtender.

Definition at line 346 of file recordingextender.h.

Referenced by checkDone(), and create().

◆ s_createLock

QMutex RecordingExtender::s_createLock {}
staticprivate

Interlock the scheduler thread crating this process, and this process determining whether it should continue running.

RecordingExtender ///.

Definition at line 349 of file recordingextender.h.

Referenced by checkDone(), and create().

◆ m_running

bool RecordingExtender::m_running {true}
private

Whether the RecordingExtender process is running.

Definition at line 351 of file recordingextender.h.

Referenced by checkDone(), and run().

◆ m_scheduler

Scheduler* RecordingExtender::m_scheduler {nullptr}
private

Pointer to the scheduler.

Needed to retrieve the scheduler's view of ongoing recordings.

Definition at line 354 of file recordingextender.h.

Referenced by create(), processActiveRecordings(), and processNewRecordings().

◆ m_newRecordingsLock

QMutex RecordingExtender::m_newRecordingsLock
private

New recordings are added by the scheduler process and removed by this process.

Definition at line 357 of file recordingextender.h.

Referenced by addNewRecording(), checkDone(), and processNewRecordings().

◆ m_newRecordings

QList<int> RecordingExtender::m_newRecordings
private

Newly started recordings to process.

Definition at line 359 of file recordingextender.h.

Referenced by addNewRecording(), checkDone(), and processNewRecordings().

◆ m_activeGames

QList<ActiveGame> RecordingExtender::m_activeGames
private

Currently ongoing games to track.

Definition at line 361 of file recordingextender.h.

Referenced by checkDone(), processActiveRecordings(), and processNewRecordings().

◆ m_overrideRules

QList<int> RecordingExtender::m_overrideRules
private

Recordings that have had an override rule creates.

Definition at line 363 of file recordingextender.h.

Referenced by checkDone(), expireOverrides(), and extendRecording().

◆ m_forcedYearforTesting

uint RecordingExtender::m_forcedYearforTesting {0}
private

Testing data.

Definition at line 366 of file recordingextender.h.

Referenced by findKnownSport().


The documentation for this class was generated from the following files: