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
14
15// local headers
16#include "backendutils.h"
17
18static 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
33static 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
59static 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
73static int ScanImages(const MythUtilCommandLineParser &/*cmdline*/)
74{
75 if (gCoreContext->ConnectToMasterServer(false, false))
76 {
77 gCoreContext->SendReceiveStringList(QStringList() << "IMAGE_SCAN");
78 LOG(VB_GENERAL, LOG_INFO, "Requested image scan");
79 return GENERIC_EXIT_OK;
80 }
81
82 LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for iamge scan");
84}
85
86static int ScanVideos(const MythUtilCommandLineParser &/*cmdline*/)
87{
88 if (gCoreContext->ConnectToMasterServer(false, false))
89 {
90 gCoreContext->SendReceiveStringList(QStringList() << "SCAN_VIDEOS");
91 LOG(VB_GENERAL, LOG_INFO, "Requested video scan");
92 return GENERIC_EXIT_OK;
93 }
94
95 LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for video scan");
97}
98
100{
101 QString filename = cmdline.toString("parsevideo");
102 cout << "Title: " << VideoMetadata::FilenameToMeta(filename, 1)
103 .toLocal8Bit().constData() << endl
104 << "Season: " << VideoMetadata::FilenameToMeta(filename, 2)
105 .toLocal8Bit().constData() << endl
106 << "Episode: " << VideoMetadata::FilenameToMeta(filename, 3)
107 .toLocal8Bit().constData() << endl
108 << "Subtitle: " << VideoMetadata::FilenameToMeta(filename, 4)
109 .toLocal8Bit().constData() << endl;
110
111 return GENERIC_EXIT_OK;
112}
113
115{
116 utilMap["clearcache"] = &ClearSettingsCache;
117 utilMap["event"] = &SendEvent;
118 utilMap["resched"] = &Reschedule;
119 utilMap["scanimages"] = &ScanImages;
120 utilMap["scanvideos"] = &ScanVideos;
121 utilMap["systemevent"] = &SendSystemEvent;
122 utilMap["parsevideo"] = &ParseVideoFilename;
123}
124
125/* 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
MythCommFlagCommandLineParser cmdline
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