-
Notifications
You must be signed in to change notification settings - Fork 21
/
timers.h
191 lines (174 loc) · 5.59 KB
/
timers.h
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <vdr/channels.h>
#include <vdr/timers.h>
#include <vdr/epg.h>
#include <vdr/menu.h>
#include <cxxtools/http/request.h>
#include <cxxtools/http/reply.h>
#include <cxxtools/http/responder.h>
#include <cxxtools/query_params.h>
#include <cxxtools/arg.h>
#include <cxxtools/jsonserializer.h>
#include <cxxtools/regex.h>
#include <cxxtools/serializationinfo.h>
#include <cxxtools/utf8codec.h>
#include <iostream>
#include <sstream>
#include <stack>
#include <queue>
#include <time.h>
#include "tools.h"
class TimersResponder : public cxxtools::http::Responder
{
public:
explicit TimersResponder(cxxtools::http::Service& service)
: cxxtools::http::Responder(service)
{ }
virtual void reply(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
void createOrUpdateTimer(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply, bool update);
void deleteTimer(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
void showTimers(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
void replyCreatedId(cTimer* timer, cxxtools::http::Request& request, cxxtools::http::Reply& reply, std::ostream& out);
void replyBulkdelete(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
};
typedef cxxtools::http::CachedService<TimersResponder> TimersService;
struct SerTimer
{
cxxtools::String Id;
int Index;
int Flags;
int Start;
cxxtools::String StartTimeStamp;
int Stop;
cxxtools::String StopTimeStamp;
int Priority;
int Lifetime;
int EventID;
cxxtools::String WeekDays;
cxxtools::String Day;
cxxtools::String Channel;
bool IsRecording;
bool IsPending;
bool IsActive;
cxxtools::String FileName;
cxxtools::String ChannelName;
cxxtools::String Aux;
};
void operator<<= (cxxtools::SerializationInfo& si, const SerTimer& t);
class TimerList : public BaseList
{
protected:
StreamExtension *s;
int total;
public:
explicit TimerList(std::ostream* _out);
virtual ~TimerList();
virtual void init() { };
virtual void addTimer(const cTimer* timer) { };
virtual void finish() { };
virtual void setTotal(int _total) { total = _total; }
};
class HtmlTimerList : TimerList
{
public:
explicit HtmlTimerList(std::ostream* _out) : TimerList(_out) { };
~HtmlTimerList() { };
virtual void init();
virtual void addTimer(const cTimer* timer);
virtual void finish();
};
class JsonTimerList : TimerList
{
private:
std::vector < struct SerTimer > serTimers;
public:
explicit JsonTimerList(std::ostream* _out) : TimerList(_out) { };
~JsonTimerList() { };
virtual void addTimer(const cTimer* timer);
virtual void finish();
};
class XmlTimerList : TimerList
{
public:
explicit XmlTimerList(std::ostream* _out) : TimerList(_out) { };
~XmlTimerList() { };
virtual void init();
virtual void addTimer(const cTimer* timer);
virtual void finish();
};
struct SerBulkDeleted {
cxxtools::String id;
bool deleted;
};
void operator<<= (cxxtools::SerializationInfo& si, const SerBulkDeleted& t);
class TimerDeletedList : public BaseList
{
protected:
StreamExtension *s;
int total;
public:
explicit TimerDeletedList(std::ostream* _out);
virtual ~TimerDeletedList();
virtual void init() { };
virtual void addDeleted(SerBulkDeleted &timer) { };
virtual void finish() { };
virtual void setTotal(int _total) { total = _total; }
};
class HtmlTimerDeletedList : TimerDeletedList
{
public:
explicit HtmlTimerDeletedList(std::ostream* _out) : TimerDeletedList(_out) { };
~HtmlTimerDeletedList() { };
virtual void init();
virtual void addDeleted(SerBulkDeleted &timer);
virtual void finish();
};
class JsonTimerDeletedList : TimerDeletedList
{
private:
std::vector < struct SerBulkDeleted > serDeleted;
public:
explicit JsonTimerDeletedList(std::ostream* _out) : TimerDeletedList(_out) { };
~JsonTimerDeletedList() { };
virtual void addDeleted(SerBulkDeleted &timer);
virtual void finish();
};
class XmlTimerDeletedList : TimerDeletedList
{
public:
explicit XmlTimerDeletedList(std::ostream* _out) : TimerDeletedList(_out) { };
~XmlTimerDeletedList() { };
virtual void init();
virtual void addDeleted(SerBulkDeleted &timer);
virtual void finish();
};
class TimerValues
{
private:
std::queue<int> ConvertToBinary(int v);
public:
TimerValues() { };
~TimerValues() { };
bool IsDayValid(std::string v);
bool IsFlagsValid(int v);
bool IsFileValid(std::string v);
bool IsLifetimeValid(int v);
bool IsPriorityValid(int v);
bool IsStopValid(int v);
bool IsStartValid(int v);
bool IsWeekdaysValid(std::string v);
int ConvertFlags(std::string v);
cEvent* ConvertEvent(std::string event_id, cChannel* channel);
std::string ConvertFile(std::string v); // replaces : with | - required by parsing method of VDR
std::string ConvertAux(std::string v); // replaces : with | - required by parsing method of VDR
int ConvertLifetime(std::string v);
int ConvertPriority(std::string v);
int ConvertStop(std::string v);
int ConvertStart(std::string v);
std::string ConvertDay(std::string v); // appends 0 to day/month because vdr requires two digits
std::string ConvertDay(time_t v);
std::string ConvertWeekdays(int v);
int ConvertWeekdays(std::string v);
const cChannel* ConvertChannel(std::string v);
cTimer* ConvertTimer(std::string v);
std::string GetStartStopTimestamp(const cTimer* timer, bool stopTime = false);
};