MythTV  master
backendutils.cpp
Go to the documentation of this file.
1 
2 // C++ includes
3 #include <iostream> // for cout
4 using std::cout;
5 using std::endl;
6 
7 // MythTV
11 #include "libmythbase/remoteutil.h"
14 
15 // local headers
16 #include "backendutils.h"
17 
18 static int RawSendEvent(const QStringList &eventStringList)
19 {
20  if (eventStringList.isEmpty() || eventStringList[0].isEmpty())
22 
23  if (gCoreContext->ConnectToMasterServer(false, false))
24  {
25  QStringList message("MESSAGE");
26  message << eventStringList;
28  return GENERIC_EXIT_OK;
29  }
31 }
32 
33 static int ClearSettingsCache(const MythUtilCommandLineParser &/*cmdline*/)
34 {
35  if (gCoreContext->ConnectToMasterServer(false, false))
36  {
37  gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
38  LOG(VB_GENERAL, LOG_INFO, "Sent CLEAR_SETTINGS_CACHE message");
39  return GENERIC_EXIT_OK;
40  }
41 
42  LOG(VB_GENERAL, LOG_ERR, "Unable to connect to backend, settings "
43  "cache will not be cleared.");
45 }
46 
48 {
49  return RawSendEvent(cmdline.toStringList("event"));
50 }
51 
53 {
54  return RawSendEvent(QStringList(QString("SYSTEM_EVENT %1 SENDER %2")
55  .arg(cmdline.toString("systemevent"),
57 }
58 
59 static int Reschedule(const MythUtilCommandLineParser &/*cmdline*/)
60 {
61  if (gCoreContext->ConnectToMasterServer(false, false))
62  {
63  ScheduledRecording::RescheduleMatch(0, 0, 0, QDateTime(),
64  "MythUtilCommand");
65  LOG(VB_GENERAL, LOG_INFO, "Reschedule command sent to master");
66  return GENERIC_EXIT_OK;
67  }
68 
69  LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for reschedule");
71 }
72 
73 static int ScanVideos(const MythUtilCommandLineParser &/*cmdline*/)
74 {
75  if (gCoreContext->ConnectToMasterServer(false, false))
76  {
77  gCoreContext->SendReceiveStringList(QStringList() << "SCAN_VIDEOS");
78  LOG(VB_GENERAL, LOG_INFO, "Requested video scan");
79  return GENERIC_EXIT_OK;
80  }
81 
82  LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for video scan");
84 }
85 
87 {
88  QString filename = cmdline.toString("parsevideo");
89  cout << "Title: " << VideoMetadata::FilenameToMeta(filename, 1)
90  .toLocal8Bit().constData() << endl
91  << "Season: " << VideoMetadata::FilenameToMeta(filename, 2)
92  .toLocal8Bit().constData() << endl
93  << "Episode: " << VideoMetadata::FilenameToMeta(filename, 3)
94  .toLocal8Bit().constData() << endl
95  << "Subtitle: " << VideoMetadata::FilenameToMeta(filename, 4)
96  .toLocal8Bit().constData() << endl;
97 
98  return GENERIC_EXIT_OK;
99 }
100 
102 {
103  utilMap["clearcache"] = &ClearSettingsCache;
104  utilMap["event"] = &SendEvent;
105  utilMap["resched"] = &Reschedule;
106  utilMap["scanvideos"] = &ScanVideos;
107  utilMap["systemevent"] = &SendSystemEvent;
108  utilMap["parsevideo"] = &ParseVideoFilename;
109 }
110 
111 /* vim: set expandtab tabstop=4 shiftwidth=4: */
MythCoreContext::SendMessage
void SendMessage(const QString &message)
Definition: mythcorecontext.cpp:1525
registerBackendUtils
void registerBackendUtils(UtilMap &utilMap)
Definition: backendutils.cpp:101
VideoMetadata::FilenameToMeta
static QString FilenameToMeta(const QString &file_name, int position)
Definition: videometadata.cpp:1137
videometadata.h
MythCoreContext::SendReceiveStringList
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
Definition: mythcorecontext.cpp:1379
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythcommflag.cpp:72
MythCoreContext::ConnectToMasterServer
bool ConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
Definition: mythcorecontext.cpp:357
ParseVideoFilename
static int ParseVideoFilename(const MythUtilCommandLineParser &cmdline)
Definition: backendutils.cpp:86
backendutils.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythUtilCommandLineParser
Definition: mythutil_commandlineparser.h:8
remoteutil.h
RawSendEvent
static int RawSendEvent(const QStringList &eventStringList)
Definition: backendutils.cpp:18
SendSystemEvent
static int SendSystemEvent(const MythUtilCommandLineParser &cmdline)
Definition: backendutils.cpp:52
SendEvent
static int SendEvent(const MythUtilCommandLineParser &cmdline)
Definition: backendutils.cpp:47
GENERIC_EXIT_INVALID_CMDLINE
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:18
mythlogging.h
GENERIC_EXIT_OK
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
ScanVideos
static int ScanVideos(const MythUtilCommandLineParser &)
Definition: backendutils.cpp:73
GENERIC_EXIT_CONNECT_ERROR
@ GENERIC_EXIT_CONNECT_ERROR
Can't connect to master backend.
Definition: exitcodes.h:23
scheduledrecording.h
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
UtilMap
QMap< QString, UtilFunc > UtilMap
Definition: mythutil.h:15
MythCommandLineParser::toString
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2354
mythcorecontext.h
MythCommandLineParser::toStringList
QStringList toStringList(const QString &key, const QString &sep="") const
Returns stored QVariant as a QStringList, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2385
ClearSettingsCache
static int ClearSettingsCache(const MythUtilCommandLineParser &)
Definition: backendutils.cpp:33
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:842
Reschedule
static int Reschedule(const MythUtilCommandLineParser &)
Definition: backendutils.cpp:59
exitcodes.h
build_compdb.filename
filename
Definition: build_compdb.py:21
ScheduledRecording::RescheduleMatch
static void RescheduleMatch(uint recordid, uint sourceid, uint mplexid, const QDateTime &maxstarttime, const QString &why)
Definition: scheduledrecording.h:17