]> git.vomp.tv Git - vompserver.git/blob - vompserver.c
Add forgotten vdrcommand.h changes
[vompserver.git] / vompserver.c
1 /*
2  *    Copyright 2004-2013 Chris Tallon
3  * 
4  *    This file is part of VOMP.
5  * 
6  *    VOMP is free software; you can redistribute it and/or modify
7  *    it under the terms of the GNU General Public License as published by
8  *    the Free Software Foundation; either version 2 of the License, or
9  *    (at your option) any later version.
10  * 
11  *    VOMP is distributed in the hope that it will be useful,
12  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *    GNU General Public License for more details.
15  * 
16  *    You should have received a copy of the GNU General Public License
17  *    along with VOMP; if not, write to the Free Software
18  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20
21 #ifndef VOMPSTANDALONE
22 #include <vdr/plugin.h>
23 #endif
24 #include <iostream>
25 #include <getopt.h>
26
27 #include "mvpserver.h"
28 //#include "vompclient.h"
29
30 static const char *VERSION        = "0.4.1";
31 static const char *DESCRIPTION    = "Vompserver plugin by Chris Tallon";
32 static const char *MAINMENUENTRY  = "Vompserver";
33
34 #ifndef VOMPSTANDALONE
35
36 class cPluginVompserver : public cPlugin {
37 private:
38   MVPServer mvpserver;
39   char* configDir;
40 public:
41   cPluginVompserver(void);
42   virtual ~cPluginVompserver();
43   virtual const char *Version(void) { return VERSION; }
44   virtual const char *Description(void) { return DESCRIPTION; }
45   virtual const char *CommandLineHelp(void);
46   virtual bool ProcessArgs(int argc, char *argv[]);
47   virtual bool Initialize(void);
48   virtual bool Start(void);
49   virtual void Stop(void);
50   virtual void Housekeeping(void);
51   virtual void MainThreadHook(void);
52   virtual cString Active(void);
53   virtual time_t WakeupTime(void);
54   virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; }
55   virtual cOsdObject *MainMenuAction(void);
56   virtual cMenuSetupPage *SetupMenu(void);
57   virtual bool SetupParse(const char *Name, const char *Value);
58   virtual bool Service(const char *Id, void *Data = NULL);
59   virtual const char **SVDRPHelpPages(void);
60   virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
61   };
62
63 cPluginVompserver::cPluginVompserver(void)
64 {
65   // Initialize any member variables here.
66   // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
67   // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
68   
69   configDir = NULL;
70 }
71
72 cPluginVompserver::~cPluginVompserver()
73 {
74   // Clean up after yourself!
75   mvpserver.stop();
76   if (configDir) delete[] configDir;  
77 }
78
79 const char *cPluginVompserver::CommandLineHelp(void)
80 {
81   // Return a string that describes all known command line options.
82   return "  -c dir    config path relative to VDR plugins config path\n";
83 }
84
85 bool cPluginVompserver::ProcessArgs(int argc, char *argv[])
86 {
87   // Implement command line argument processing here if applicable.
88   
89   int c;
90   while ((c = getopt(argc, argv, "c:")) != -1)
91   {
92     if (c == 'c')
93     {
94       const char* vdrdeveldevelret = cPlugin::ConfigDirectory(optarg);
95       if (!vdrdeveldevelret)
96       {
97         dsyslog("VOMP: Could not get config dir from VDR");
98         return false;
99       }
100       
101       configDir = new char[strlen(vdrdeveldevelret)+1];
102       strcpy(configDir, vdrdeveldevelret);
103     }
104     else
105     {
106       return false;
107     }
108   }
109   
110   return true;
111 }
112
113 bool cPluginVompserver::Initialize(void)
114 {
115   // Initialize any background activities the plugin shall perform.
116   return true;
117 }
118
119 bool cPluginVompserver::Start(void)
120 {
121   // Start any background activities the plugin shall perform.
122   
123   if (!configDir)
124   {
125     const char* vdrdeveldevelret = cPlugin::ConfigDirectory("vompserver");
126     if (!vdrdeveldevelret)
127     {
128       dsyslog("VOMP: Could not get config dir from VDR");
129       return false;
130     }
131     configDir = new char[strlen(vdrdeveldevelret)+1];
132     strcpy(configDir, vdrdeveldevelret);
133   }
134   
135   int success = mvpserver.run(configDir);
136   if (success) return true;
137   else return false;
138 }
139
140 void cPluginVompserver::Stop(void)
141 {
142   // Stop any background activities the plugin is performing.
143 }
144
145 void cPluginVompserver::Housekeeping(void)
146 {
147   // Perform any cleanup or other regular tasks.
148 }
149
150 void cPluginVompserver::MainThreadHook(void)
151 {
152   // Perform actions in the context of the main program thread.
153   // WARNING: Use with great care - see PLUGINS.html!
154 }
155
156 cString cPluginVompserver::Active(void)
157 {
158   // Return a message string if shutdown should be postponed
159   if(VompClient::getNrClients() != 0) return tr("VOMP client(s) connected");
160   return NULL;
161 }
162
163 time_t cPluginVompserver::WakeupTime(void)
164 {
165   // Return custom wakeup time for shutdown script
166   return 0;
167 }
168
169 cOsdObject *cPluginVompserver::MainMenuAction(void)
170 {
171   // Perform the action when selected from the main VDR menu.
172   return NULL;
173 }
174
175 cMenuSetupPage *cPluginVompserver::SetupMenu(void)
176 {
177   // Return a setup menu in case the plugin supports one.
178   return NULL;
179 }
180
181 bool cPluginVompserver::SetupParse(const char *Name, const char *Value)
182 {
183   // Parse your own setup parameters and store their values.
184   return false;
185 }
186
187 bool cPluginVompserver::Service(const char *Id, void *Data)
188 {
189   // Handle custom service requests from other plugins
190   return false;
191 }
192
193 const char **cPluginVompserver::SVDRPHelpPages(void)
194 {
195   // Return help text for SVDRP commands this plugin implements
196   return NULL;
197 }
198
199 cString cPluginVompserver::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
200 {
201   // Process SVDRP commands this plugin implements
202   return NULL;
203 }
204
205 VDRPLUGINCREATOR(cPluginVompserver); // Don't touch this!
206
207
208 #else //VOMPSTANDALONE
209
210 int main(int argc, char **argv) {
211   char *cdir=".";
212   if (argc > 1) {
213     cdir=argv[1];
214   }
215   std::cout << "Vompserver starting Version " << VERSION << " " << DESCRIPTION << std::endl;
216   MVPServer server;
217   if ( server.run(cdir) != 1) {
218     std::cerr << "unable to start vompserver" << std::endl;
219     return 1;
220   }
221   while (1) sleep(1);
222   return 0;
223 }
224
225 #endif //VOMPSTANDALONE