/
backendutils.cpp
88 lines (75 loc) · 2.73 KB
/
backendutils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// libmyth* headers
#include "exitcodes.h"
#include "mythcorecontext.h"
#include "mythlogging.h"
#include "remoteutil.h"
#include "scheduledrecording.h"
// local headers
#include "backendutils.h"
static int RawSendEvent(const QStringList &eventStringList)
{
if (eventStringList.isEmpty() || eventStringList[0].isEmpty())
return GENERIC_EXIT_INVALID_CMDLINE;
if (gCoreContext->ConnectToMasterServer(false, false))
{
QStringList message("MESSAGE");
message << eventStringList;
gCoreContext->SendReceiveStringList(message);
return GENERIC_EXIT_OK;
}
return GENERIC_EXIT_CONNECT_ERROR;
}
static int ClearSettingsCache(const MythUtilCommandLineParser &cmdline)
{
if (gCoreContext->ConnectToMasterServer(false, false))
{
gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
LOG(VB_GENERAL, LOG_INFO, "Sent CLEAR_SETTINGS_CACHE message");
return GENERIC_EXIT_OK;
}
LOG(VB_GENERAL, LOG_ERR, "Unable to connect to backend, settings "
"cache will not be cleared.");
return GENERIC_EXIT_CONNECT_ERROR;
}
static int SendEvent(const MythUtilCommandLineParser &cmdline)
{
return RawSendEvent(cmdline.toStringList("event"));
}
static int SendSystemEvent(const MythUtilCommandLineParser &cmdline)
{
return RawSendEvent(QStringList(QString("SYSTEM_EVENT %1 SENDER %2")
.arg(cmdline.toString("systemevent"))
.arg(gCoreContext->GetHostName())));
}
static int Reschedule(const MythUtilCommandLineParser &cmdline)
{
if (gCoreContext->ConnectToMasterServer(false, false))
{
ScheduledRecording::RescheduleMatch(0, 0, 0, QDateTime(),
"MythUtilCommand");
LOG(VB_GENERAL, LOG_INFO, "Reschedule command sent to master");
return GENERIC_EXIT_OK;
}
LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for reschedule");
return GENERIC_EXIT_CONNECT_ERROR;
}
static int ScanVideos(const MythUtilCommandLineParser &cmdline)
{
if (gCoreContext->ConnectToMasterServer(false, false))
{
gCoreContext->SendReceiveStringList(QStringList() << "SCAN_VIDEOS");
LOG(VB_GENERAL, LOG_INFO, "Requested video scan");
return GENERIC_EXIT_OK;
}
LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master for video scan");
return GENERIC_EXIT_CONNECT_ERROR;
}
void registerBackendUtils(UtilMap &utilMap)
{
utilMap["clearcache"] = &ClearSettingsCache;
utilMap["event"] = &SendEvent;
utilMap["resched"] = &Reschedule;
utilMap["scanvideos"] = &ScanVideos;
utilMap["systemevent"] = &SendSystemEvent;
}
/* vim: set expandtab tabstop=4 shiftwidth=4: */