forked from yavdr/vdr-plugin-restfulapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timers.h
134 lines (123 loc) · 3.91 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
#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 <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);
};
typedef cxxtools::http::CachedService<TimersResponder> TimersService;
struct SerTimer
{
cxxtools::String Id;
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;
};
void operator<<= (cxxtools::SerializationInfo& si, const SerTimer& t);
class TimerList : public BaseList
{
protected:
StreamExtension *s;
int total;
public:
TimerList(std::ostream* _out);
~TimerList();
virtual void init() { };
virtual void addTimer(cTimer* timer) { };
virtual void finish() { };
virtual void setTotal(int _total) { total = _total; }
};
class HtmlTimerList : TimerList
{
public:
HtmlTimerList(std::ostream* _out) : TimerList(_out) { };
~HtmlTimerList() { };
virtual void init();
virtual void addTimer(cTimer* timer);
virtual void finish();
};
class JsonTimerList : TimerList
{
private:
std::vector < struct SerTimer > serTimers;
public:
JsonTimerList(std::ostream* _out) : TimerList(_out) { };
~JsonTimerList() { };
virtual void addTimer(cTimer* timer);
virtual void finish();
};
class XmlTimerList : TimerList
{
public:
XmlTimerList(std::ostream* _out) : TimerList(_out) { };
~XmlTimerList() { };
virtual void init();
virtual void addTimer(cTimer* timer);
virtual void finish();
};
class TimerValues
{
private:
std::stack<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);
cChannel* ConvertChannel(std::string v);
cTimer* ConvertTimer(std::string v);
};