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 // libmythbase
8 #include "exitcodes.h"
9 #include "mythcorecontext.h"
10 #include "mythlogging.h"
11 
12 // libmyth
13 #include "remoteutil.h"
14 
15 // libmythtv
16 #include "scheduledrecording.h"
17 
18 // libmythmetadata
19 #include "videometadata.h"
20 
21 // local headers
22 #include "backendutils.h"
23 
24 static int RawSendEvent(const QStringList &eventStringList)
25 {
26  if (eventStringList.isEmpty() || eventStringList[0].isEmpty())
28 
29  if (gCoreContext->ConnectToMasterServer(false, false))
30  {
31  QStringList message("MESSAGE");
32  message << eventStringList;
34  return GENERIC_EXIT_OK;
35  }
37 }
38 
39 static int ClearSettingsCache(const MythUtilCommandLineParser &/*cmdline*/)
40 {
41  if (gCoreContext->ConnectToMasterServer(false, false))
42  {
43  gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
44  LOG(VB_GENERAL, LOG_INFO, "Sent CLEAR_SETTINGS_CACHE message");
45  return GENERIC_EXIT_OK;
46  }
47 
48  LOG(VB_GENERAL, LOG_ERR, "Unable to connect to backend, settings "
49  "cache will not be cleared.");
51 }
52 
54 {
55  return RawSendEvent(cmdline.toStringList("event"));
56 }
57 
59 {
60  return RawSendEvent(QStringList(QString("SYSTEM_EVENT %1 SENDER %2")
61  .arg(cmdline.toString("systemevent"))
62  .arg(gCoreContext->GetHostName())));
63 }
64 
65 static int Reschedule(const MythUtilCommandLineParser &/*cmdline*/)
66 {
67  if (gCoreContext->ConnectToMasterServer(false, false))
68  {
69  ScheduledRecording::RescheduleMatch(0, 0, 0, QDateTime(),
70  "MythUtilCommand");
71  LOG(VB_GENERAL, LOG_INFO, "Reschedule command sent to master");
72  return GENERIC_EXIT_OK;
73  }
74 
75  LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for reschedule");
77 }
78 
79 static int ScanVideos(const MythUtilCommandLineParser &/*cmdline*/)
80 {
81  if (gCoreContext->ConnectToMasterServer(false, false))
82  {
83  gCoreContext->SendReceiveStringList(QStringList() << "SCAN_VIDEOS");
84  LOG(VB_GENERAL, LOG_INFO, "Requested video scan");
85  return GENERIC_EXIT_OK;
86  }
87 
88  LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for video scan");
90 }
91 
93 {
94  QString filename = cmdline.toString("parsevideo");
95  cout << "Title: " << VideoMetadata::FilenameToMeta(filename, 1)
96  .toLocal8Bit().constData() << endl
97  << "Season: " << VideoMetadata::FilenameToMeta(filename, 2)
98  .toLocal8Bit().constData() << endl
99  << "Episode: " << VideoMetadata::FilenameToMeta(filename, 3)
100  .toLocal8Bit().constData() << endl
101  << "Subtitle: " << VideoMetadata::FilenameToMeta(filename, 4)
102  .toLocal8Bit().constData() << endl;
103 
104  return GENERIC_EXIT_OK;
105 }
106 
108 {
109  utilMap["clearcache"] = &ClearSettingsCache;
110  utilMap["event"] = &SendEvent;
111  utilMap["resched"] = &Reschedule;
112  utilMap["scanvideos"] = &ScanVideos;
113  utilMap["systemevent"] = &SendSystemEvent;
114  utilMap["parsevideo"] = &ParseVideoFilename;
115 }
116 
117 /* vim: set expandtab tabstop=4 shiftwidth=4: */
MythCoreContext::SendMessage
void SendMessage(const QString &message)
Definition: mythcorecontext.cpp:1524
registerBackendUtils
void registerBackendUtils(UtilMap &utilMap)
Definition: backendutils.cpp:107
GENERIC_EXIT_OK
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
VideoMetadata::FilenameToMeta
static QString FilenameToMeta(const QString &file_name, int position)
Definition: videometadata.cpp:1072
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:1377
MythCoreContext::ConnectToMasterServer
bool ConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
Definition: mythcorecontext.cpp:374
ParseVideoFilename
static int ParseVideoFilename(const MythUtilCommandLineParser &cmdline)
Definition: backendutils.cpp:92
arg
arg(title).arg(filename).arg(doDelete))
backendutils.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
GENERIC_EXIT_INVALID_CMDLINE
#define GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:15
MythUtilCommandLineParser
Definition: mythutil/commandlineparser.h:9
remoteutil.h
RawSendEvent
static int RawSendEvent(const QStringList &eventStringList)
Definition: backendutils.cpp:24
SendSystemEvent
static int SendSystemEvent(const MythUtilCommandLineParser &cmdline)
Definition: backendutils.cpp:58
SendEvent
static int SendEvent(const MythUtilCommandLineParser &cmdline)
Definition: backendutils.cpp:53
mythlogging.h
ScanVideos
static int ScanVideos(const MythUtilCommandLineParser &)
Definition: backendutils.cpp:79
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:634
scheduledrecording.h
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythtv/programs/mythcommflag/main.cpp:77
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:2094
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:2125
ClearSettingsCache
static int ClearSettingsCache(const MythUtilCommandLineParser &)
Definition: backendutils.cpp:39
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:856
Reschedule
static int Reschedule(const MythUtilCommandLineParser &)
Definition: backendutils.cpp:65
GENERIC_EXIT_CONNECT_ERROR
#define GENERIC_EXIT_CONNECT_ERROR
Can't connect to master backend.
Definition: exitcodes.h:20
exitcodes.h
ScheduledRecording::RescheduleMatch
static void RescheduleMatch(uint recordid, uint sourceid, uint mplexid, const QDateTime &maxstarttime, const QString &why)
Definition: scheduledrecording.h:17