MythTV master
backendutils.cpp
Go to the documentation of this file.
1
2// C++ includes
3#include <iostream> // for std::cout
4
5// MythTV
11
12// local headers
13#include "backendutils.h"
14
15static int RawSendEvent(const QStringList &eventStringList)
16{
17 if (eventStringList.isEmpty() || eventStringList[0].isEmpty())
19
20 if (gCoreContext->ConnectToMasterServer(false, false))
21 {
22 QStringList message("MESSAGE");
23 message << eventStringList;
25 return GENERIC_EXIT_OK;
26 }
28}
29
30static int ClearSettingsCache(const MythUtilCommandLineParser &/*cmdline*/)
31{
32 if (gCoreContext->ConnectToMasterServer(false, false))
33 {
34 gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
35 LOG(VB_GENERAL, LOG_INFO, "Sent CLEAR_SETTINGS_CACHE message");
36 return GENERIC_EXIT_OK;
37 }
38
39 LOG(VB_GENERAL, LOG_ERR, "Unable to connect to backend, settings "
40 "cache will not be cleared.");
42}
43
45{
46 return RawSendEvent(cmdline.toStringList("event"));
47}
48
50{
51 return RawSendEvent(QStringList(QString("SYSTEM_EVENT %1 SENDER %2")
52 .arg(cmdline.toString("systemevent"),
54}
55
56static int Reschedule(const MythUtilCommandLineParser &/*cmdline*/)
57{
58 if (gCoreContext->ConnectToMasterServer(false, false))
59 {
60 ScheduledRecording::RescheduleMatch(0, 0, 0, QDateTime(),
61 "MythUtilCommand");
62 LOG(VB_GENERAL, LOG_INFO, "Reschedule command sent to master");
63 return GENERIC_EXIT_OK;
64 }
65
66 LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for reschedule");
68}
69
70static int ScanImages(const MythUtilCommandLineParser &/*cmdline*/)
71{
72 if (gCoreContext->ConnectToMasterServer(false, false))
73 {
74 gCoreContext->SendReceiveStringList(QStringList() << "IMAGE_SCAN");
75 LOG(VB_GENERAL, LOG_INFO, "Requested image scan");
76 return GENERIC_EXIT_OK;
77 }
78
79 LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for iamge scan");
81}
82
83static int ScanVideos(const MythUtilCommandLineParser &/*cmdline*/)
84{
85 if (gCoreContext->ConnectToMasterServer(false, false))
86 {
87 gCoreContext->SendReceiveStringList(QStringList() << "SCAN_VIDEOS");
88 LOG(VB_GENERAL, LOG_INFO, "Requested video scan");
89 return GENERIC_EXIT_OK;
90 }
91
92 LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for video scan");
94}
95
97{
98 QString filename = cmdline.toString("parsevideo");
99 std::cout << "Title: " << VideoMetadata::FilenameToMeta(filename, 1)
100 .toLocal8Bit().constData() << '\n'
101 << "Season: " << VideoMetadata::FilenameToMeta(filename, 2)
102 .toLocal8Bit().constData() << '\n'
103 << "Episode: " << VideoMetadata::FilenameToMeta(filename, 3)
104 .toLocal8Bit().constData() << '\n'
105 << "Subtitle: " << VideoMetadata::FilenameToMeta(filename, 4)
106 .toLocal8Bit().constData() << '\n';
107
108 return GENERIC_EXIT_OK;
109}
110
112{
113 utilMap["clearcache"] = &ClearSettingsCache;
114 utilMap["event"] = &SendEvent;
115 utilMap["resched"] = &Reschedule;
116 utilMap["scanimages"] = &ScanImages;
117 utilMap["scanvideos"] = &ScanVideos;
118 utilMap["systemevent"] = &SendSystemEvent;
119 utilMap["parsevideo"] = &ParseVideoFilename;
120}
121
122/* 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