]> git.vomp.tv Git - jsonserver.git/blob - vdrclient.h
JSON: Switch from StyledWriter to StreamWriterBuilder
[jsonserver.git] / vdrclient.h
1 #ifndef VDRCLIENT_H
2 #define VDRCLIENT_H
3
4 #include <sstream>
5
6 #include <jsoncpp/json/json.h>
7
8 // Log docs: https://github.com/gabime/spdlog
9 #include <spdlog/spdlog.h>
10 namespace spd = spdlog;
11
12 // Config docs: http://www.hyperrealm.com/libconfig/libconfig_manual.html#The-C_002b_002b-API
13 #include <libconfig.h++>
14
15 class cEvent;
16 class cTimer;
17 class cChannels;
18 class cSchedules;
19 class cTimers;
20 class cRecordings;
21
22 class VDRClient
23 {
24   typedef std::map<std::string, std::string> PFMap;
25
26   public:
27     VDRClient(const std::string& configDir);
28     ~VDRClient();
29
30     bool process(std::string& request, PFMap& postFields, std::stringstream* returnData);
31
32   private:
33     const std::string& configDir;
34
35     std::shared_ptr<spd::logger> logger;
36     bool gettime(PFMap& postFields, Json::Value& returnJSON);
37     bool diskstats(PFMap& postFields, Json::Value& returnJSON);
38     bool channellist(PFMap& postFields, Json::Value& returnJSON);
39     bool reclist(PFMap& postFields, Json::Value& returnJSON);
40     bool timerlist(PFMap& postFields, Json::Value& returnJSON);
41     bool epgdownload(PFMap& postFields, Json::Value& returnJSON);
42     bool tunersstatus(PFMap& postFields, Json::Value& returnJSON);
43     bool epgfilterget(PFMap& postFields, Json::Value& js);
44
45     bool channelschedule(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
46     bool getscheduleevent(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
47     bool epgsearch(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
48     bool epgsearchsame(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
49     bool epgsearchotherhalf(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
50     bool timerset(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
51     bool recinfo(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
52     bool recstop(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
53     bool recdel(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
54     bool recrename(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
55     bool recmove(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
56     bool timersetactive(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
57     bool timerdel(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
58     bool timerisrecording(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
59     bool recresetresume(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
60     bool timeredit(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
61     bool epgfilteradd(PFMap& postFields, Json::Value& returnJSON); // throws BadParamException
62     bool epgfilterdel(PFMap& postFields, Json::Value& js); // throws BadParamException
63
64     cTimer* findTimer(cTimers* Timers,
65                       const char* rChannelID, const char* rName, const char* rStartTime, const char* rStopTime, const char* rWeekDays);
66     const cTimer* findTimer(const cTimers* Timers,
67                       const char* rChannelID, const char* rName, const char* rStartTime, const char* rStopTime, const char* rWeekDays);
68     cTimer* findTimer2(cTimers* Timers,
69                        const char* rName, const char* rActive, const char* rChannelID, const char* rDay, const char* rWeekDays, const char* rStartTime, const char* rStopTime, const char* rPriority, const char* rLifetime);
70     const cEvent* getEvent(const cChannels* Channels, const cSchedules* Schedules,
71                            Json::Value& js, int channelNumber, int eventID, int aroundTime);
72
73     int getVarInt(PFMap& postFields, const char* paramName); // THROWS
74     std::string getVarString(PFMap& postFields, const char* paramName, bool emptyOk = false); // THROWS
75
76     bool loadEpgFilter(libconfig::Config& epgFilter);
77     bool saveEpgFilter(libconfig::Config& epgFilter);
78
79     class BadParamException : public std::exception
80     {
81     public:
82       const char* param;
83       BadParamException(const char* _param) { param = _param; }
84       /*
85       virtual const char* what() const throw()
86       {
87         return "Mine!!";
88       }
89       */
90     };
91
92     std::shared_ptr<Json::StreamWriter> jsonwriter;
93 };
94
95 #endif