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