]> git.vomp.tv Git - jsonserver.git/blob - jsonserver.c
Initial import
[jsonserver.git] / jsonserver.c
1 /*
2  * jsonserver.c: A plugin for the Video Disk Recorder
3  *
4  * See the README file for copyright information and how to reach the author.
5  *
6  */
7
8 #include <vdr/plugin.h>
9
10 #include "mongoose.h"
11 #include "handler.h"
12 #include "log.h"
13
14 static const char *VERSION        = "0.0.1";
15 static const char *DESCRIPTION    = "JSON data server plugin for VDR";
16 static const char *MAINMENUENTRY  = "Jsonserver";
17
18 class cPluginJsonserver : public cPlugin {
19 private:
20   // Add any member variables or functions you may need here.
21   struct mg_context *mg;
22   Log* log;  
23 public:
24   cPluginJsonserver(void);
25   virtual ~cPluginJsonserver();
26   virtual const char *Version(void) { return VERSION; }
27   virtual const char *Description(void) { return DESCRIPTION; }
28   virtual const char *CommandLineHelp(void);
29   virtual bool ProcessArgs(int argc, char *argv[]);
30   virtual bool Initialize(void);
31   virtual bool Start(void);
32   virtual void Stop(void);
33   virtual void Housekeeping(void);
34   virtual void MainThreadHook(void);
35   virtual cString Active(void);
36   virtual time_t WakeupTime(void);
37   virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; }
38   virtual cOsdObject *MainMenuAction(void);
39   virtual cMenuSetupPage *SetupMenu(void);
40   virtual bool SetupParse(const char *Name, const char *Value);
41   virtual bool Service(const char *Id, void *Data = NULL);
42   virtual const char **SVDRPHelpPages(void);
43   virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
44   };
45
46 cPluginJsonserver::cPluginJsonserver(void)
47 {
48   // Initialize any member variables here.
49   // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
50   // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
51
52   log = new Log();
53   if (log) log->init(Log::DEBUG, "/tmp/jsonserver.log");
54 }
55
56 cPluginJsonserver::~cPluginJsonserver()
57 {
58   // Clean up after yourself!
59   delete log;
60   log = NULL;
61 }
62
63 const char *cPluginJsonserver::CommandLineHelp(void)
64 {
65   // Return a string that describes all known command line options.
66   return NULL;
67 }
68
69 bool cPluginJsonserver::ProcessArgs(int argc, char *argv[])
70 {
71   // Implement command line argument processing here if applicable.
72   return true;
73 }
74
75 bool cPluginJsonserver::Initialize(void)
76 {
77   // Initialize any background activities the plugin shall perform.
78   return true;
79 }
80
81 bool cPluginJsonserver::Start(void)
82 {
83   // Start any background activities the plugin shall perform.
84
85   // Make Mongoose options
86   const char *options[] =
87   {
88     "document_root", "/home/chris/dvb/vdr-1.7.32/PLUGINS/src/jsonserver/docroot",
89     "listening_ports", "8005",
90     "num_threads", "5",
91     NULL
92   };
93
94   // Prepare callbacks structure. We have only one callback, the rest are NULL.
95   struct mg_callbacks callbacks;
96   memset(&callbacks, 0, sizeof(callbacks));
97   callbacks.begin_request = jsonserver_request_handler;
98   
99   mg = mg_start(&callbacks, NULL, options);
100   log->log("JSONServer", Log::INFO, "Mongoose started");
101   return true;
102 }
103
104 void cPluginJsonserver::Stop(void)
105 {
106   // Stop any background activities the plugin is performing.
107   mg_stop(mg);
108 }
109
110 void cPluginJsonserver::Housekeeping(void)
111 {
112   // Perform any cleanup or other regular tasks.
113 }
114
115 void cPluginJsonserver::MainThreadHook(void)
116 {
117   // Perform actions in the context of the main program thread.
118   // WARNING: Use with great care - see PLUGINS.html!
119 }
120
121 cString cPluginJsonserver::Active(void)
122 {
123   // Return a message string if shutdown should be postponed
124   return NULL;
125 }
126
127 time_t cPluginJsonserver::WakeupTime(void)
128 {
129   // Return custom wakeup time for shutdown script
130   return 0;
131 }
132
133 cOsdObject *cPluginJsonserver::MainMenuAction(void)
134 {
135   // Perform the action when selected from the main VDR menu.
136   return NULL;
137 }
138
139 cMenuSetupPage *cPluginJsonserver::SetupMenu(void)
140 {
141   // Return a setup menu in case the plugin supports one.
142   return NULL;
143 }
144
145 bool cPluginJsonserver::SetupParse(const char *Name, const char *Value)
146 {
147   // Parse your own setup parameters and store their values.
148   return false;
149 }
150
151 bool cPluginJsonserver::Service(const char *Id, void *Data)
152 {
153   // Handle custom service requests from other plugins
154   return false;
155 }
156
157 const char **cPluginJsonserver::SVDRPHelpPages(void)
158 {
159   // Return help text for SVDRP commands this plugin implements
160   return NULL;
161 }
162
163 cString cPluginJsonserver::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
164 {
165   // Process SVDRP commands this plugin implements
166   return NULL;
167 }
168
169 VDRPLUGINCREATOR(cPluginJsonserver); // Don't touch this!