forked from flensrocker/vdr-plugin-dbus2vdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epg.c
80 lines (66 loc) · 2.03 KB
/
epg.c
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
#include "epg.h"
#include "common.h"
#include "helper.h"
#include <vdr/epg.h>
cDBusMessageEPG::cDBusMessageEPG(cDBusMessageEPG::eAction action, DBusConnection* conn, DBusMessage* msg)
:cDBusMessage(conn, msg)
,_action(action)
{
}
cDBusMessageEPG::~cDBusMessageEPG(void)
{
}
void cDBusMessageEPG::Process(void)
{
switch (_action) {
case dmePutFile:
PutFile();
break;
}
}
void cDBusMessageEPG::PutFile(void)
{
const char *filename = NULL;
DBusMessageIter args;
if (!dbus_message_iter_init(_msg, &args))
esyslog("dbus2vdr: %s.PutFile: message misses an argument for the filename", DBUS_VDR_EPG_INTERFACE);
else {
if (cDBusHelper::GetNextArg(args, DBUS_TYPE_STRING, &filename) < 0)
esyslog("dbus2vdr: %s.SVDRPCommand: 'filename' argument is not a string", DBUS_VDR_EPG_INTERFACE);
}
if (filename != NULL) {
FILE *f = fopen(filename, "r");
if (f) {
cString message = cString::sprintf("start reading epg data from %s", filename);
cDBusHelper::SendReply(_conn, _msg, 0, *message);
if (cSchedules::Read(f))
cSchedules::Cleanup(true);
fclose(f);
}
else {
esyslog("dbus2vdr: %s.PutFile: error opening %s", DBUS_VDR_EPG_INTERFACE, filename);
cString message = cString::sprintf("error opening %s", filename);
cDBusHelper::SendReply(_conn, _msg, -2, *message);
}
}
else
cDBusHelper::SendReply(_conn, _msg, -1, "no filename");
}
cDBusDispatcherEPG::cDBusDispatcherEPG(void)
:cDBusMessageDispatcher(DBUS_VDR_EPG_INTERFACE)
{
}
cDBusDispatcherEPG::~cDBusDispatcherEPG(void)
{
}
cDBusMessage *cDBusDispatcherEPG::CreateMessage(DBusConnection* conn, DBusMessage* msg)
{
if ((conn == NULL) || (msg == NULL))
return NULL;
const char *object = dbus_message_get_path(msg);
if ((object == NULL) || (strcmp(object, "/EPG") != 0))
return NULL;
if (dbus_message_is_method_call(msg, DBUS_VDR_EPG_INTERFACE, "PutFile"))
return new cDBusMessageEPG(cDBusMessageEPG::dmePutFile, conn, msg);
return NULL;
}