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/compat.h"
31#include "libmythbase/mythversion.h"
32#include "libmythtv/jobqueue.h"
34
35// MythJobQueue
37
38#define LOC QString("MythJobQueue: ")
39#define LOC_WARN QString("MythJobQueue, Warning: ")
40#define LOC_ERR QString("MythJobQueue, Error: ")
41
42JobQueue *jobqueue = nullptr;
43
44int main(int argc, char *argv[])
45{
47 if (!cmdline.Parse(argc, argv))
48 {
51 }
52
53 if (cmdline.toBool("showhelp"))
54 {
56 return GENERIC_EXIT_OK;
57 }
58
59 if (cmdline.toBool("showversion"))
60 {
62 return GENERIC_EXIT_OK;
63 }
64
65 QCoreApplication a(argc, argv);
66 QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHJOBQUEUE);
67
68 int retval = cmdline.Daemonize();
69 if (retval != GENERIC_EXIT_OK)
70 return retval;
71
72 bool daemonize = cmdline.toBool("daemon");
73 QString mask("general");
74 retval = cmdline.ConfigureLogging(mask, daemonize);
75 if (retval != GENERIC_EXIT_OK)
76 return retval;
77
78 MythContext context {MYTH_BINARY_VERSION};
79 if (!context.Init(false))
80 {
81 LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to init MythContext, exiting.");
83 }
84
86
88 {
89 LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect to master server");
91 }
92
93 jobqueue = new JobQueue(false);
94
95 auto *sysEventHandler = new MythSystemEventHandler();
96
97 auto *housekeeping = new HouseKeeper();
98#ifdef __linux__
99 #ifdef CONFIG_BINDINGS_PYTHON
100 housekeeping->RegisterTask(new HardwareProfileTask());
101 #endif
102#endif
103 housekeeping->Start();
104
105 int exitCode = QCoreApplication::exec();
106
107 delete sysEventHandler;
108
109 return exitCode ? exitCode : GENERIC_EXIT_OK;
110}
111
112/* vim: set expandtab tabstop=4 shiftwidth=4: */
Manages registered HouseKeeperTasks and queues tasks for operation.
Definition: housekeeper.h:150
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