2 * jsonserver.c: A plugin for the Video Disk Recorder
4 * See the README file for copyright information and how to reach the author.
8 #include <vdr/plugin.h>
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";
18 class cPluginJsonserver : public cPlugin {
20 // Add any member variables or functions you may need here.
21 struct mg_context *mg;
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);
46 cPluginJsonserver::cPluginJsonserver(void)
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!
53 if (log) log->init(Log::DEBUG, "/tmp/jsonserver.log");
56 cPluginJsonserver::~cPluginJsonserver()
58 // Clean up after yourself!
63 const char *cPluginJsonserver::CommandLineHelp(void)
65 // Return a string that describes all known command line options.
69 bool cPluginJsonserver::ProcessArgs(int argc, char *argv[])
71 // Implement command line argument processing here if applicable.
75 bool cPluginJsonserver::Initialize(void)
77 // Initialize any background activities the plugin shall perform.
81 bool cPluginJsonserver::Start(void)
83 // Start any background activities the plugin shall perform.
85 // Make Mongoose options
86 const char *options[] =
88 "document_root", "/home/chris/dvb/vdr-1.7.32/PLUGINS/src/jsonserver/docroot",
89 "listening_ports", "8005",
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;
99 mg = mg_start(&callbacks, NULL, options);
100 log->log("JSONServer", Log::INFO, "Mongoose started");
104 void cPluginJsonserver::Stop(void)
106 // Stop any background activities the plugin is performing.
110 void cPluginJsonserver::Housekeeping(void)
112 // Perform any cleanup or other regular tasks.
115 void cPluginJsonserver::MainThreadHook(void)
117 // Perform actions in the context of the main program thread.
118 // WARNING: Use with great care - see PLUGINS.html!
121 cString cPluginJsonserver::Active(void)
123 // Return a message string if shutdown should be postponed
127 time_t cPluginJsonserver::WakeupTime(void)
129 // Return custom wakeup time for shutdown script
133 cOsdObject *cPluginJsonserver::MainMenuAction(void)
135 // Perform the action when selected from the main VDR menu.
139 cMenuSetupPage *cPluginJsonserver::SetupMenu(void)
141 // Return a setup menu in case the plugin supports one.
145 bool cPluginJsonserver::SetupParse(const char *Name, const char *Value)
147 // Parse your own setup parameters and store their values.
151 bool cPluginJsonserver::Service(const char *Id, void *Data)
153 // Handle custom service requests from other plugins
157 const char **cPluginJsonserver::SVDRPHelpPages(void)
159 // Return help text for SVDRP commands this plugin implements
163 cString cPluginJsonserver::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
165 // Process SVDRP commands this plugin implements
169 VDRPLUGINCREATOR(cPluginJsonserver); // Don't touch this!