]> git.vomp.tv Git - vompserver.git/blob - vompserver.c
15 years that line of code has been waiting to crash
[vompserver.git] / vompserver.c
1 /*
2  *    Copyright 2004-2019 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.5.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
80 const char *cPluginVompserver::CommandLineHelp(void)
81 {
82   // Return a string that describes all known command line options.
83   return "  -c dir    config path relative to VDR plugins config path\n";
84 }
85
86 bool cPluginVompserver::ProcessArgs(int argc, char *argv[])
87 {
88   // Implement command line argument processing here if applicable.
89   
90   int c;
91   while ((c = getopt(argc, argv, "c:")) != -1)
92   {
93     if (c == 'c')
94     {
95       const char* vdrret = cPlugin::ConfigDirectory(optarg);
96       if (!vdrret)
97       {
98         dsyslog("VOMP: Could not get config dir from VDR");
99         return false;
100       }
101       
102       configDir = new char[strlen(vdrret)+1];
103       strcpy(configDir, vdrret);
104     }
105     else
106     {
107       return false;
108     }
109   }
110   
111   return true;
112 }
113
114 bool cPluginVompserver::Initialize(void)
115 {
116   // Initialize any background activities the plugin shall perform.
117   return true;
118 }
119
120 bool cPluginVompserver::Start(void)
121 {
122   // Start any background activities the plugin shall perform.
123   
124   if (!configDir)
125   {
126     const char* vdrret = cPlugin::ConfigDirectory("vompserver");
127     if (!vdrret)
128     {
129       dsyslog("VOMP: Could not get config dir from VDR");
130       return false;
131     }
132     configDir = new char[strlen(vdrret)+1];
133     strcpy(configDir, vdrret);
134   }
135   
136   int success = mvpserver.run(configDir);
137   if (success) return true;
138   else return false;
139 }
140
141 void cPluginVompserver::Stop(void)
142 {
143   // Stop any background activities the plugin is performing.
144 }
145
146 void cPluginVompserver::Housekeeping(void)
147 {
148   // Perform any cleanup or other regular tasks.
149 }
150
151 void cPluginVompserver::MainThreadHook(void)
152 {
153   // Perform actions in the context of the main program thread.
154   // WARNING: Use with great care - see PLUGINS.html!
155 }
156
157 cString cPluginVompserver::Active(void)
158 {
159   // Return a message string if shutdown should be postponed
160   if(VompClient::getNrClients() != 0) return tr("VOMP client(s) connected");
161   return NULL;
162 }
163
164 time_t cPluginVompserver::WakeupTime(void)
165 {
166   // Return custom wakeup time for shutdown script
167   return 0;
168 }
169
170 cOsdObject *cPluginVompserver::MainMenuAction(void)
171 {
172   // Perform the action when selected from the main VDR menu.
173   return NULL;
174 }
175
176 cMenuSetupPage *cPluginVompserver::SetupMenu(void)
177 {
178   // Return a setup menu in case the plugin supports one.
179   return NULL;
180 }
181
182 bool cPluginVompserver::SetupParse(const char *Name, const char *Value)
183 {
184   // Parse your own setup parameters and store their values.
185   return false;
186 }
187
188 bool cPluginVompserver::Service(const char *Id, void *Data)
189 {
190   // Handle custom service requests from other plugins
191   return false;
192 }
193
194 const char **cPluginVompserver::SVDRPHelpPages(void)
195 {
196   // Return help text for SVDRP commands this plugin implements
197   return NULL;
198 }
199
200 cString cPluginVompserver::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
201 {
202   // Process SVDRP commands this plugin implements
203   return NULL;
204 }
205
206 VDRPLUGINCREATOR(cPluginVompserver); // Don't touch this!
207
208
209 #else //VOMPSTANDALONE
210
211 int main(int argc, char **argv) {
212   char *cdir=".";
213   if (argc > 1) {
214     cdir=argv[1];
215   }
216   std::cout << "Vompserver starting Version " << VERSION << " " << DESCRIPTION << std::endl;
217   MVPServer server;
218   if ( server.run(cdir) != 1) {
219     std::cerr << "unable to start vompserver" << std::endl;
220     return 1;
221   }
222   while (1) sleep(1);
223   return 0;
224 }
225
226 #endif //VOMPSTANDALONE