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: */
static int SendEvent(const MythUtilCommandLineParser &cmdline)
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
#define GENERIC_EXIT_CONNECT_ERROR
Can't connect to master backend.
Definition: exitcodes.h:20
static int ScanVideos(const MythUtilCommandLineParser &)
void registerBackendUtils(UtilMap &utilMap)
bool ConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void SendMessage(const QString &message)
static int RawSendEvent(const QStringList &eventStringList)
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
QMap< QString, UtilFunc > UtilMap
Definition: mythutil.h:16
static int ParseVideoFilename(const MythUtilCommandLineParser &cmdline)
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
static QString FilenameToMeta(const QString &file_name, int position)
MythCommFlagCommandLineParser cmdline
static void RescheduleMatch(uint recordid, uint sourceid, uint mplexid, const QDateTime &maxstarttime, const QString &why)
static int SendSystemEvent(const MythUtilCommandLineParser &cmdline)
QStringList toStringList(const QString &key, const QString &sep="") const
Returns stored QVariant as a QStringList, falling to default if not provided.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
static int Reschedule(const MythUtilCommandLineParser &)
#define GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:15
QString GetHostName(void)
static int ClearSettingsCache(const MythUtilCommandLineParser &)