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