MythTV  master
mythtv/programs/mythutil/main.cpp
Go to the documentation of this file.
1 // Qt includes
2 #ifndef _WIN32
3 #include <QCoreApplication>
4 #else
5 #include <QApplication>
6 #endif
7 
8 // libmyth* includes
9 #include "mythconfig.h"
10 #include "exitcodes.h"
11 #include "mythcontext.h"
12 #include "mythversion.h"
13 #include "loggingserver.h"
14 #include "mythlogging.h"
15 
16 // Local includes
17 #include "mythutil.h"
18 #include "commandlineparser.h"
19 #include "backendutils.h"
20 #include "eitutils.h"
21 #include "fileutils.h"
22 #include "mpegutils.h"
23 #include "jobutils.h"
24 #include "markuputils.h"
25 #include "messageutils.h"
26 #include "musicmetautils.h"
27 #include "recordingutils.h"
28 #include "signalhandling.h"
29 
30 
31 int main(int argc, char *argv[])
32 {
34  if (!cmdline.Parse(argc, argv))
35  {
38  }
39 
40  // default to quiet operation for pidcounter and pidfilter
41  QString defaultVerbose = "general";
42  LogLevel_t defaultLevel = LOG_INFO;
43  if (cmdline.toBool("pidcounter") || cmdline.toBool("pidfilter"))
44  {
45  if (!cmdline.toBool("verbose"))
46  {
47  verboseString = defaultVerbose = "";
48  verboseMask = 0;
49  }
50  if (!cmdline.toBool("loglevel"))
51  logLevel = defaultLevel = LOG_ERR;
52  }
53 
54 
55  if (cmdline.toBool("showhelp"))
56  {
58  return GENERIC_EXIT_OK;
59  }
60 
61  if (cmdline.toBool("showversion"))
62  {
64  return GENERIC_EXIT_OK;
65  }
66 
67 #ifndef _WIN32
68  QCoreApplication a(argc, argv);
69 #else
70  // MINGW application needs a window to receive messages
71  // such as socket notifications :[
72  QApplication a(argc, argv);
73 #endif
74 
75  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHUTIL);
76 
77  int retval = cmdline.ConfigureLogging(defaultVerbose);
78  if (retval != GENERIC_EXIT_OK)
79  return retval;
80 
81  if (!cmdline.toBool("loglevel"))
82  logLevel = defaultLevel;
83 
84 #ifndef _WIN32
85  QList<int> signallist;
86  signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT << SIGBUS << SIGFPE
87  << SIGILL;
88 #if ! CONFIG_DARWIN
89  signallist << SIGRTMIN;
90 #endif
91  SignalHandler::Init(signallist);
93 #endif
94 
96  if (!gContext->Init(false))
97  {
98  LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting.");
100  }
101 
103 
104  UtilMap utilMap;
105 
106  registerBackendUtils(utilMap);
107  registerEITUtils(utilMap);
108  registerFileUtils(utilMap);
109  registerMPEGUtils(utilMap);
110  registerJobUtils(utilMap);
111  registerMarkupUtils(utilMap);
112  registerMessageUtils(utilMap);
113  registerMusicUtils(utilMap);
114  registerRecordingUtils(utilMap);
115 
116  bool cmdFound = false;
117  int cmdResult = GENERIC_EXIT_OK;
118  UtilMap::iterator i;
119  for (i = utilMap.begin(); i != utilMap.end(); ++i)
120  {
121  if (cmdline.toBool(i.key()))
122  {
123  cmdResult = (i.value())(cmdline);
124  cmdFound = true;
125  break;
126  }
127  }
128 
129  if(!cmdFound)
130  {
131  cmdline.PrintHelp();
132  cmdResult = GENERIC_EXIT_INVALID_CMDLINE;
133  }
134 
135  delete gContext;
136 
138 
139  return cmdResult;
140 }
141 
142 /* vim: set expandtab tabstop=4 shiftwidth=4: */
Startup context for MythTV.
Definition: mythcontext.h:42
int main(int argc, char *argv[])
void registerMPEGUtils(UtilMap &utilMap)
Definition: mpegutils.cpp:848
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
static void PrintVersion(void)
Print application version information.
void registerMarkupUtils(UtilMap &utilMap)
void PrintHelp(void) const
Print command line option help.
void registerBackendUtils(UtilMap &utilMap)
void registerMusicUtils(UtilMap &utilMap)
static void Init(QList< int > &signallist, QObject *parent=nullptr)
uint64_t verboseMask
Definition: logging.cpp:107
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:62
void ApplySettingsOverride(void)
Apply all overrides to the global context.
QMap< QString, UtilFunc > UtilMap
Definition: mythutil.h:15
void registerEITUtils(UtilMap &utilMap)
Definition: eitutils.cpp:137
void registerRecordingUtils(UtilMap &utilMap)
void registerMessageUtils(UtilMap &utilMap)
static void Done(void)
static void SetHandler(int signum, SigHandlerFunc handler)
MythCommFlagCommandLineParser cmdline
void registerJobUtils(UtilMap &utilMap)
Definition: jobutils.cpp:71
#define MYTH_APPNAME_MYTHUTIL
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
LogLevel_t logLevel
Definition: logging.cpp:95
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
#define SIGHUP
Definition: compat.h:213
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:16
void registerFileUtils(UtilMap &utilMap)
Definition: fileutils.cpp:144
bool Init(const bool gui=true, const bool promptForBackend=false, const bool disableAutoDiscovery=false, const bool ignoreDB=false)
#define GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:13
#define GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:15
int ConfigureLogging(const QString &mask="general", unsigned int progress=0)
Read in logging options and initialize the logging interface.
QString verboseString
Definition: logging.cpp:108