]> git.vomp.tv Git - vompserver.git/blob - vompserver.c
Fix for moving recordings
[vompserver.git] / vompserver.c
1 /*
2     Copyright 2004-2005 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 "mvpclient.h"
29
30 static const char *VERSION        = "0.2.7";
31 static const char *DESCRIPTION    = "VDR on MVP plugin by Chris Tallon";
32
33 #ifndef VOMPSTANDALONE
34 class cPluginVompserver : public cPlugin
35 {
36 public:
37   cPluginVompserver(void);
38   virtual ~cPluginVompserver();
39   virtual const char *Version(void) { return VERSION; }
40   virtual const char *Description(void) { return DESCRIPTION; }
41   virtual const char *CommandLineHelp(void);
42   virtual bool ProcessArgs(int argc, char *argv[]);
43   virtual bool Initialize(void);
44   virtual bool Start(void);
45   virtual bool SetupParse(const char *Name, const char *Value);
46 #if VDRVERSNUM > 10300
47   virtual cString Active(void);
48 #endif
49
50 private:
51
52   MVPServer mvpserver;
53   char* configDir;
54 };
55
56 cPluginVompserver::cPluginVompserver(void)
57 {
58   // Initialize any member variables here.
59   // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
60   // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
61
62   configDir = NULL;
63 }
64
65 bool cPluginVompserver::Start(void)
66 {
67   // Start any background activities the plugin shall perform.
68   
69   if (!configDir)
70   {
71     const char* vdrret = cPlugin::ConfigDirectory("vompserver");
72     if (!vdrret)
73     {
74       dsyslog("VOMP: Could not get config dir from VDR");
75       return false;
76     }
77     configDir = new char[strlen(vdrret)+1];
78     strcpy(configDir, vdrret);
79   }
80   
81   int success = mvpserver.run(configDir);
82   if (success) return true;
83   else return false;
84 }
85
86 cPluginVompserver::~cPluginVompserver()
87 {
88   // Clean up after yourself!
89   mvpserver.stop();
90   if (configDir) delete[] configDir;
91 }
92
93 const char *cPluginVompserver::CommandLineHelp(void)
94 {
95   // Return a string that describes all known command line options.
96
97   return "  -c dir    config path relative to VDR plugins config path\n";
98 }
99
100 bool cPluginVompserver::ProcessArgs(int argc, char *argv[])
101 {
102   // Implement command line argument processing here if applicable.
103
104   int c;
105   while ((c = getopt(argc, argv, "c:")) != -1)
106   {
107     if (c == 'c')
108     {
109       const char* vdrret = cPlugin::ConfigDirectory(optarg);
110       if (!vdrret)
111       {
112         dsyslog("VOMP: Could not get config dir from VDR");
113         return false;
114       }
115     
116       configDir = new char[strlen(vdrret)+1];
117       strcpy(configDir, vdrret);
118     }
119     else
120     {
121       return false;
122     }
123   }
124
125   return true;
126 }
127
128 bool cPluginVompserver::Initialize(void)
129 {
130   // Initialize any background activities the plugin shall perform.
131   return true;
132 }
133
134 bool cPluginVompserver::SetupParse(const char *Name, const char *Value)
135 {
136   // Parse your own setup parameters and store their values.
137   return false;
138 }
139
140 #if VDRVERSNUM > 10300
141
142 cString cPluginVompserver::Active(void)
143 {
144   if(MVPClient::getNrClients() != 0) return tr("VOMP client(s) connected");
145   return NULL;
146 }
147
148 #endif
149
150 VDRPLUGINCREATOR(cPluginVompserver); // Don't touch this!
151
152 #else //VOMPSTANDALONE
153
154 int main(int argc, char **argv) {
155   char *cdir=".";
156     if (argc > 1) {
157       cdir=argv[1];
158     }
159   std::cout << "Vompserver starting Version " << VERSION << " " << DESCRIPTION << std::endl;
160   MVPServer server;
161   if ( server.run(cdir) != 1) {
162         std::cerr << "unable to start vompserver" << std::endl;
163         return 1;
164     }
165   while (1) sleep(1);
166   return 0;
167 }
168
169 #endif //VOMPSTANDALONE