]> git.vomp.tv Git - vompclient.git/blob - inputman.cc
Rename TCP class to TCPOld
[vompclient.git] / inputman.cc
1 /*
2     Copyright 2020 Chris Tallon; 2012 Marten Richter
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, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "log.h"
21 #include "wremoteconfig.h"
22 #include "wtabbar.h"
23 #ifdef VOMP_PLATFORM_RASPBERRY
24 #include "inputlinux.h"
25 #include "inputcec.h"
26 #endif
27 #include "inputudp.h"
28 #ifdef WIN32
29 #include "inputwin.h"
30 #endif
31 #include "i18n.h"
32 #include "input.h"
33
34 #include "inputman.h"
35
36 InputMan* InputMan::instance = NULL;
37
38 InputMan::InputMan()
39 {
40   instance = this;
41 }
42
43 InputMan::~InputMan()
44 {
45   instance = NULL;
46 }
47
48 InputMan* InputMan::getInstance()
49 {
50   return instance;
51 }
52
53 bool InputMan::init()
54 {
55         bool i1{}, i2{}, i3{}, i4{};
56
57 #ifdef VOMP_PLATFORM_RASPBERRY
58   inputLinux = new InputLinux();
59   i1 = inputLinux->init();
60   if (!i1) { delete inputLinux; inputLinux = NULL; }
61
62   // FIXME enable modules by new config system
63
64 //  inputCEC = new InputCEC();
65 //  i2 = inputCEC->init();
66 //  if (!i2) { delete inputCEC; inputCEC = NULL; }
67 #endif
68
69   inputUDP = new InputUDP();
70   i3 = inputUDP->init();
71   if (!i3) { delete inputUDP; inputUDP = NULL; }
72
73 #ifdef WIN32
74   inputWin = new InputWin();
75   i4 = inputWin->init();
76   if (!i4) { delete inputWin; inputWin = NULL; }
77 #endif
78
79   if (!i1 && !i2 && !i3 && !i4)
80   {
81     Log::getInstance()->log("InputMan", Log::CRIT, "InputMan could not init any input module");
82     return false;
83   }
84
85   initted = true;
86   return true;
87 }
88
89 bool InputMan::start()
90 {
91   Log::getInstance()->log("InputMan", Log::DEBUG, "Start");
92
93   bool i1{}, i3{};
94
95 #ifdef VOMP_PLATFORM_RASPBERRY
96   if (inputLinux)
97   {
98     i1 = inputLinux->start();
99   }
100 #endif
101
102   if (inputUDP)
103   {
104     i3 = inputUDP->start();
105   }
106
107   return i1;
108 }
109
110 void InputMan::stop()
111 {
112   Log::getInstance()->log("InputMan", Log::DEBUG, "Stop called");
113
114 #ifdef VOMP_PLATFORM_RASPBERRY
115   if (inputLinux) inputLinux->stop();
116 #endif
117   if (inputUDP) inputUDP->stop();
118 }
119
120 void InputMan::shutdown()
121 {
122   Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start");
123
124 #ifdef VOMP_PLATFORM_RASPBERRY
125
126   if (inputLinux)
127   {
128     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - Linux");
129     inputLinux->stop();
130     inputLinux->shutdown();
131     delete inputLinux;
132     inputLinux = NULL;
133   }
134
135   if (inputCEC)
136   {
137     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - CEC");
138     inputCEC->shutdown();
139     delete inputCEC;
140     inputCEC = NULL;
141   }
142
143 #endif
144
145   if (inputUDP)
146   {
147     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - UDP");
148     inputUDP->stop();
149     inputUDP->shutdown();
150     delete inputUDP;
151     inputUDP = NULL;
152   }
153
154   initted = false;
155 }
156
157 bool InputMan::mayHaveFewButtons()
158 {
159   // 052 returned true if remotelinux was in effect - linux or CEC. What was it for?
160
161   if (inputLinux || inputCEC) return true;
162   return false;
163 }
164
165 bool InputMan::handlesVolume()
166 {
167 #ifdef VOMP_PLATFORM_RASPBERRY
168   if (!inputCEC) return false;
169   return inputCEC->handlesVolume();
170 #else
171   return false;
172 #endif
173 }
174
175 void InputMan::volumeUp()
176 {
177 #ifdef VOMP_PLATFORM_RASPBERRY
178         if (inputCEC) inputCEC->volumeUp();
179 #endif
180 }
181
182 void InputMan::volumeDown()
183 {
184 #ifdef VOMP_PLATFORM_RASPBERRY
185         if (inputCEC) inputCEC->volumeDown();
186 #endif
187 }
188
189 void InputMan::volumeMute()
190 {
191 #ifdef VOMP_PLATFORM_RASPBERRY
192   if (inputCEC) inputCEC->volumeMute();
193 #endif
194 }
195
196 void InputMan::changePowerState(bool powerOn)
197 {
198 #ifdef VOMP_PLATFORM_RASPBERRY
199   if (inputCEC) inputCEC->changePowerState(powerOn);
200 #endif
201 }
202
203 bool InputMan::addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane)
204 {
205 #ifdef VOMP_PLATFORM_RASPBERRY
206   if (inputLinux) inputLinux->addOptionsToPanes(panenumber, options, pane);
207   if (inputCEC) inputCEC->addOptionsToPanes(panenumber, options, pane);
208 #endif
209
210   return true; // FIXME
211 }
212
213 bool InputMan::addOptionPagesToWTB(WTabBar *wtb)
214 {
215   WRemoteConfig* wrc = new WRemoteConfig();
216   wtb->addTab(tr("Remote Control"), wrc);
217
218   return true; // FIXME
219 }
220
221 bool InputMan::loadOptionsFromServer(VDR* vdr)
222 {
223 #ifdef VOMP_PLATFORM_RASPBERRY
224   if (inputLinux) inputLinux->loadOptionsFromServer(vdr);
225   if (inputCEC) inputCEC->loadOptionsFromServer(vdr);
226 #endif
227
228   return true; // FIXME
229 }
230
231 bool InputMan::saveOptionstoServer()
232 {
233 #ifdef VOMP_PLATFORM_RASPBERRY
234   if (inputLinux) inputLinux->saveOptionstoServer();
235   if (inputCEC) inputCEC->saveOptionstoServer();
236 #endif
237   return true; // FIXME
238 }
239
240 const char* InputMan::getVompKeyName(UCHAR number)
241 {
242   switch (number)
243   {
244     case Input::VOLUMEUP:
245       return tr("Volume Up");
246     case Input::VOLUMEDOWN:
247       return tr("Volume Down");
248     case Input::CHANNELUP:
249       return tr("Channel up");
250     case Input::CHANNELDOWN:
251       return tr("Channel down");
252     case Input::ZERO:
253       return "0";
254     case Input::ONE:
255       return "1";
256     case Input::TWO:
257       return "2";
258     case Input::THREE:
259       return "3";
260     case Input::FOUR:
261       return "4";
262     case Input::FIVE:
263       return "5";
264     case Input::SIX:
265       return "6";
266     case Input::SEVEN:
267       return "7";
268     case Input::EIGHT:
269       return "8";
270     case Input::NINE:
271       return "9";
272     case Input::POWER:
273       return tr("Power");
274     case Input::GO:
275       return tr("Go");
276     case Input::BACK:
277       return tr("Back");
278     case Input::MENU:
279       return tr("Menu");
280     case Input::RED:
281       return tr("Red");
282     case Input::GREEN:
283       return tr("Green");
284     case Input::YELLOW:
285       return tr("Yellow");
286     case Input::BLUE:
287       return tr("Blue");
288     case Input::MUTE:
289       return tr("Mute");
290     case Input::RADIO:
291       return tr("Radio");
292     case Input::REVERSE:
293       return tr("Reverse");
294     case Input::PLAY:
295       return tr("Play");
296     case Input::FORWARD:
297       return tr("Forward");
298     case Input::RECORD:
299       return tr("Record");
300     case Input::STOP:
301       return tr("Stop");
302     case Input::PAUSE:
303       return tr("Pause");
304     case Input::SKIPBACK:
305       return tr("Skip back");
306     case Input::SKIPFORWARD:
307       return tr("Skip forward");
308     case Input::OK:
309       return tr("Ok");
310     case Input::FULL:
311       return tr("Fullscreen");
312     case Input::TV:
313       return tr("TV");
314     case Input::VIDEOS:
315       return tr("Videos");
316     case Input::MUSIC:
317       return tr("Music");
318     case Input::PICTURES:
319       return tr("Pictures");
320     case Input::GUIDE:
321       return tr("Guide");
322     case Input::UP:
323       return tr("Up");
324     case Input::DOWN:
325       return tr("Down");
326     case Input::LEFT:
327       return tr("Left");
328     case Input::RIGHT:
329       return tr("Right");
330     case Input::PREVCHANNEL:
331       return tr("Previous Channel");
332     case Input::STAR:
333       return tr("Star");
334     case Input::HASH:
335       return tr("Hash");
336     case Input::PLAYPAUSE:
337        return tr("Play/Pause");
338
339     default:
340       return NULL;
341   }
342 }
343
344 std::string InputMan::getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey)
345 {
346   // Go through each active Input class and get the hardware key name for vompKey
347
348   // which doesn't make any sense
349
350   std::string keyNames;
351
352 #ifdef VOMP_PLATFORM_RASPBERRY
353   if (inputLinux)
354   {
355     std::string k = inputLinux->getHardCodedHardwareKeyNamesForVompKey(vompKey);
356     if (k.size()) keyNames += k;
357   }
358
359   if (inputCEC)
360   {
361     std::string k = inputCEC->getHardCodedHardwareKeyNamesForVompKey(vompKey);
362     if (k.size()) { keyNames += ", "; keyNames += k; }
363   }
364 #endif
365
366   if (inputUDP)
367   {
368     std::string k = inputUDP->getHardCodedHardwareKeyNamesForVompKey(vompKey);
369     if (k.size()) { keyNames += ", "; keyNames += k; }
370   }
371
372   return keyNames;
373 }
374
375 std::string InputMan::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
376 {
377   std::string keyNames;
378
379 #ifdef VOMP_PLATFORM_RASPBERRY
380   if (inputLinux)
381   {
382     std::string k = inputLinux->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
383     if (k.size()) keyNames += k;
384   }
385
386   if (inputCEC)
387   {
388     std::string k = inputCEC->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
389     if (k.size()) { keyNames += ", "; keyNames += k; }
390   }
391 #endif
392
393   if (inputUDP)
394   {
395     std::string k = inputUDP->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
396     if (k.size()) { keyNames += ", "; keyNames += k; }
397   }
398
399   return keyNames;
400 }
401
402 void InputMan::ResetToDefault()
403 {
404 #ifdef VOMP_PLATFORM_RASPBERRY
405
406   if (inputLinux) inputLinux->ResetToDefault();
407
408   if (inputCEC) inputCEC->ResetToDefault();
409
410 #endif
411
412   if (inputUDP) inputUDP->ResetToDefault();
413 }
414
415 void InputMan::EnterLearningMode(UCHAR vompKey)
416 {
417 #ifdef VOMP_PLATFORM_RASPBERRY
418   if (inputLinux) inputLinux->EnterLearningMode(vompKey);
419
420 //  if (inputCEC) inputCEC->EnterLearningMode();  FIXME - is there any such thing?
421 #endif
422 }
423
424 void InputMan::cancelLearnMode()
425 {
426 #ifdef VOMP_PLATFORM_RASPBERRY
427   if (inputLinux) inputLinux->cancelLearnMode();
428   if (inputCEC) inputCEC->cancelLearnMode();
429 #endif
430   if (inputUDP) inputUDP->cancelLearnMode();
431 }