MythTV master
mythjobqueue.cpp
Go to the documentation of this file.
1// C/C++
2#include <cmath>
3#include <csignal>
4#include <cstdio>
5#include <cstdlib>
6#include <fcntl.h>
7#include <fstream>
8#include <iostream>
9#include <string>
10#include <sys/stat.h>
11#include <sys/types.h>
12#include <unistd.h>
13
14// Qt
15#include <QCoreApplication>
16#include <QDir>
17#include <QFileInfo>
18#include <QString>
19#include <QtGlobal>
20
21// MythTV
22#include "libmyth/mythcontext.h"
23#include "libmythbase/mythconfig.h"
24#include "libmythbase/compat.h"
32#include "libmythbase/mythversion.h"
33#include "libmythtv/jobqueue.h"
35
36// MythJobQueue
38
39#define LOC QString("MythJobQueue: ")
40#define LOC_WARN QString("MythJobQueue, Warning: ")
41#define LOC_ERR QString("MythJobQueue, Error: ")
42
43JobQueue *jobqueue = nullptr;
44
45int main(int argc, char *argv[])
46{
48 if (!cmdline.Parse(argc, argv))
49 {
52 }
53
54 if (cmdline.toBool("showhelp"))
55 {
57 return GENERIC_EXIT_OK;
58 }
59
60 if (cmdline.toBool("showversion"))
61 {
63 return GENERIC_EXIT_OK;
64 }
65
66 QCoreApplication a(argc, argv);
67 QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHJOBQUEUE);
68
69 int retval = cmdline.Daemonize();
70 if (retval != GENERIC_EXIT_OK)
71 return retval;
72
73 bool daemonize = cmdline.toBool("daemon");
74 QString mask("general");
75 retval = cmdline.ConfigureLogging(mask, daemonize);
76 if (retval != GENERIC_EXIT_OK)
77 return retval;
78
79 MythContext context {MYTH_BINARY_VERSION};
80 if (!context.Init(false))
81 {
82 LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to init MythContext, exiting.");
84 }
85
87
89 {
90 LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect to master server");
92 }
93
94 jobqueue = new JobQueue(false);
95
96 auto *sysEventHandler = new MythSystemEventHandler();
97
98 auto *housekeeping = new HouseKeeper();
99#ifdef Q_OS_LINUX
100 #ifdef CONFIG_BINDINGS_PYTHON
101 housekeeping->RegisterTask(new HardwareProfileTask());
102 #endif
103#endif
104 housekeeping->Start();
105
106 int exitCode = QCoreApplication::exec();
107
108 delete sysEventHandler;
109
110 return exitCode ? exitCode : GENERIC_EXIT_OK;
111}
112
113/* vim: set expandtab tabstop=4 shiftwidth=4: */
Manages registered HouseKeeperTasks and queues tasks for operation.
Definition: housekeeper.h:155
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
void ApplySettingsOverride(void)
Apply all overrides to the global context.
int Daemonize(void) const
Fork application into background, and detatch from terminal.
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
static void PrintVersion(void)
Print application version information.
void PrintHelp(void) const
Print command line option help.
Startup context for MythTV.
Definition: mythcontext.h:20
bool ConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
Handles incoming MythSystemEvent messages.
@ GENERIC_EXIT_CONNECT_ERROR
Can't connect to master backend.
Definition: exitcodes.h:23
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:16
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:18
static constexpr const char * MYTH_APPNAME_MYTHJOBQUEUE
Definition: mythappname.h:5
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
int main(int argc, char *argv[])
#define LOC
JobQueue * jobqueue
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythCommFlagCommandLineParser cmdline