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