forked from yavdr/vdr-plugin-restfulapi
-
Notifications
You must be signed in to change notification settings - Fork 3
/
serverthread.cpp
110 lines (96 loc) · 4.1 KB
/
serverthread.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* serverthread.cpp: JSONAPI plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include "serverthread.h"
void cServerThread::Initialize()
{
active = false;
listenIp = Settings::get()->Ip();
listenPort = Settings::get()->Port();
isyslog("create server");
server = new cxxtools::http::Server(loop, listenIp, listenPort);
}
void cServerThread::Stop() {
active = false;
loop.exit();
int now = time(NULL);
esyslog("restfulapi: will end server thread: /%i/", now);
usleep(100000);//100ms//sleep(1);
delete server;
}
cServerThread::~cServerThread()
{
Cancel(0);
}
void cServerThread::Action(void)
{
active = true;
AudioService audioService;
ChannelsService channelsService;
EventsService eventsService;
InfoService infoService;
OsdService osdService;
RecordingsService recordingsService;
RemoteService remoteService;
SearchTimersService searchTimersService;
TimersService timersService;
RestfulServices* services = RestfulServices::get();
RestfulService* audio = new RestfulService("/audio", true, 1);
RestfulService* channels = new RestfulService("/channels", true, 1);
RestfulService* channelGroups = new RestfulService("/channels/groups", true, 1, channels);
RestfulService* channelImage = new RestfulService("/channels/image", true, 1, channels);
RestfulService* events = new RestfulService("/events", true, 1);
RestfulService* eventsImage = new RestfulService("/events/image", true, 1, events);
RestfulService* eventsSearch = new RestfulService("/events/search", false, 1, events);
RestfulService* info = new RestfulService("/info", true, 1);
RestfulService* osd = new RestfulService("/osd", true, 1);
RestfulService* recordings = new RestfulService("/recordings", true, 1);
RestfulService* recordingsCut = new RestfulService("/recordings/cut", true, 1, recordings);
RestfulService* recordingsMarks = new RestfulService("/recordings/marks", true, 1, recordings);
RestfulService* recordingsPlay = new RestfulService("/recordings/play", true, 2, recordings);
RestfulService* recordingsRewind = new RestfulService("/recordings/rewind", true, 1, recordings);
RestfulService* recordingsDelete = new RestfulService("/recordings/delete", true, 1, recordings);
RestfulService* recordingsMove = new RestfulService("/recordings/move", true, 1, recordings);
RestfulService* remote = new RestfulService("/remote", true, 1);
RestfulService* searchtimers = new RestfulService("/searchtimers", false, 1);
RestfulService* timers = new RestfulService("/timers", true, 1);
services->appendService(audio);
services->appendService(channels);
services->appendService(channelGroups);
services->appendService(channelImage);
services->appendService(events);
services->appendService(eventsImage);
services->appendService(eventsSearch);
services->appendService(info);
services->appendService(osd);
services->appendService(recordings);
services->appendService(recordingsCut);
services->appendService(recordingsMarks);
services->appendService(recordingsPlay);
services->appendService(recordingsRewind);
services->appendService(recordingsDelete);
services->appendService(recordingsMove);
services->appendService(remote);
services->appendService(searchtimers);
services->appendService(timers);
server->addService(*audio->Regex(), audioService);
server->addService(*channels->Regex(), channelsService);
server->addService(*events->Regex(), eventsService);
server->addService(*info->Regex(), infoService);
server->addService(*osd->Regex(), osdService);
server->addService(*recordings->Regex(), recordingsService);
server->addService(*remote->Regex(), remoteService);
server->addService(*searchtimers->Regex(), searchTimersService);
server->addService(*timers->Regex(), timersService);
try {
loop.run();
} catch ( const std::exception& e) {
esyslog("restfulapi: starting services failed: /%s/", e.what());
}
int now = time(NULL);
esyslog("restfulapi: server thread end: /%i/", now);
dsyslog("restfulapi: server thread ended (pid=%d)", getpid());
}