]> git.vomp.tv Git - vompclient.git/blob - inputman.cc
Log conversion
[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 "config.h"
21 #include "log.h"
22 #include "wremoteconfig.h"
23 #include "wtabbar.h"
24 #ifdef VOMP_PLATFORM_RASPBERRY
25 #include "inputlinux.h"
26 #include "inputcec.h"
27 #endif
28 #include "inputudp.h"
29 #include "inputlirc.h"
30 #ifdef WIN32
31 #include "inputwin.h"
32 #endif
33 #include "i18n.h"
34 #include "input.h"
35
36 #include "inputman.h"
37
38 static const char* TAG = "InputMan";
39
40 InputMan* InputMan::instance = NULL;
41
42 InputMan::InputMan()
43 {
44   instance = this;
45 }
46
47 InputMan::~InputMan()
48 {
49   instance = NULL;
50 }
51
52 InputMan* InputMan::getInstance()
53 {
54   return instance;
55 }
56
57 bool InputMan::init()
58 {
59   bool ret;
60   bool oneOK{};
61
62 #ifdef VOMP_PLATFORM_RASPBERRY
63   inputLinux = new InputLinux();
64   ret = inputLinux->init();
65   if (ret)
66     oneOK = true;
67   else
68     { delete inputLinux; inputLinux = NULL; }
69
70   bool cecEnabled = true;
71   Config::getInstance()->getBool("input", "mod_cec_enabled", cecEnabled);
72   if (cecEnabled)
73   {
74     inputCEC = new InputCEC();
75     ret = inputCEC->init();
76     if (ret)
77       oneOK = true;
78     else
79       { delete inputCEC; inputCEC = NULL; }
80   }
81 #endif
82
83   bool udpEnabled = true;
84   Config::getInstance()->getBool("input", "mod_udp_enabled", udpEnabled);
85   if (udpEnabled)
86   {
87     inputUDP = new InputUDP();
88     ret = inputUDP->init();
89     if (ret)
90       oneOK = true;
91     else
92       { delete inputUDP; inputUDP = NULL; }
93   }
94
95   bool lircEnabled = false;
96   Config::getInstance()->getBool("input", "mod_lirc_enabled", lircEnabled);
97   if (lircEnabled)
98   {
99     inputLirc = new InputLIRC();
100     ret = inputLirc->init();
101     if (ret)
102       oneOK = true;
103     else
104       { delete inputLirc; inputLirc = NULL; }
105   }
106
107 #ifdef WIN32
108   inputWin = new InputWin();
109   ret = inputWin->init();
110   if (ret)
111     oneOK = true;
112   else
113     { delete inputWin; inputWin = NULL; }
114 #endif
115
116   if (!oneOK)
117   {
118     LogNT::getInstance()->crit(TAG, "InputMan could not init any input module");
119     return false;
120   }
121
122   initted = true;
123   return true;
124 }
125
126 bool InputMan::start()
127 {
128   LogNT::getInstance()->debug(TAG, "Start");
129
130   bool oneOK{};
131
132 #ifdef VOMP_PLATFORM_RASPBERRY
133   if (inputLinux && inputLinux->start()) oneOK = true;
134 #endif
135
136   if (inputUDP && inputUDP->start()) oneOK = true;
137
138   if (inputLirc)
139   {
140     std::string lircIP;
141     bool checkA = Config::getInstance()->getString("input", "lirc_ip", lircIP);
142     int lircPort = 8765;
143     bool checkB = Config::getInstance()->getInt("input", "lirc_port", lircPort);
144
145     if (!checkA || !checkB)
146     {
147       delete inputLirc;
148       inputLirc = NULL;
149     }
150     else
151     {
152       if (inputLirc->start(lircIP, lircPort))
153       {
154         oneOK = true;
155       }
156       else
157       {
158         delete inputLirc;
159         inputLirc = NULL;
160       }
161     }
162   }
163
164   if (!oneOK)
165     LogNT::getInstance()->crit(TAG, "InputMan could not start any input module");
166
167   return oneOK;
168 }
169
170 void InputMan::stop()
171 {
172   LogNT::getInstance()->debug(TAG, "Stop called");
173
174 #ifdef VOMP_PLATFORM_RASPBERRY
175   if (inputLinux) inputLinux->stop();
176 #endif
177   if (inputUDP) inputUDP->stop();
178   if (inputLirc) inputLirc->stop();
179 }
180
181 void InputMan::shutdown()
182 {
183   LogNT::getInstance()->debug(TAG, "Shutdown start");
184
185 #ifdef VOMP_PLATFORM_RASPBERRY
186
187   if (inputLinux)
188   {
189     LogNT::getInstance()->debug(TAG, "Shutdown start - Linux");
190     inputLinux->stop();
191     inputLinux->shutdown();
192     delete inputLinux;
193     inputLinux = NULL;
194   }
195
196   if (inputCEC)
197   {
198     LogNT::getInstance()->debug(TAG, "Shutdown start - CEC");
199     inputCEC->shutdown();
200     delete inputCEC;
201     inputCEC = NULL;
202   }
203
204 #endif
205
206   if (inputUDP)
207   {
208     LogNT::getInstance()->debug(TAG, "Shutdown start - UDP");
209     inputUDP->stop();
210     inputUDP->shutdown();
211     delete inputUDP;
212     inputUDP = NULL;
213   }
214
215   if (inputLirc)
216   {
217     LogNT::getInstance()->debug(TAG, "Shutdown start - LIRC");
218     inputLirc->stop();
219     inputLirc->shutdown();
220     delete inputLirc;
221     inputLirc = NULL;
222   }
223
224   initted = false;
225 }
226
227 bool InputMan::mayHaveFewButtons()
228 {
229   // 052 returned true if remotelinux was in effect - linux or CEC. What was it for?
230
231   if (inputLinux || inputCEC) return true;
232   return false;
233 }
234
235 bool InputMan::handlesVolume()
236 {
237 #ifdef VOMP_PLATFORM_RASPBERRY
238   if (!inputCEC) return false;
239   return inputCEC->handlesVolume();
240 #else
241   return false;
242 #endif
243 }
244
245 void InputMan::volumeUp()
246 {
247 #ifdef VOMP_PLATFORM_RASPBERRY
248         if (inputCEC) inputCEC->volumeUp();
249 #endif
250 }
251
252 void InputMan::volumeDown()
253 {
254 #ifdef VOMP_PLATFORM_RASPBERRY
255         if (inputCEC) inputCEC->volumeDown();
256 #endif
257 }
258
259 void InputMan::volumeMute()
260 {
261 #ifdef VOMP_PLATFORM_RASPBERRY
262   if (inputCEC) inputCEC->volumeMute();
263 #endif
264 }
265
266 void InputMan::changePowerState(bool powerOn)
267 {
268 #ifdef VOMP_PLATFORM_RASPBERRY
269   if (inputCEC) inputCEC->changePowerState(powerOn);
270 #endif
271 }
272
273 bool InputMan::addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane)
274 {
275 #ifdef VOMP_PLATFORM_RASPBERRY
276   if (inputLinux) inputLinux->addOptionsToPanes(panenumber, options, pane);
277   if (inputCEC) inputCEC->addOptionsToPanes(panenumber, options, pane);
278 #endif
279
280   return true; // FIXME
281 }
282
283 bool InputMan::addOptionPagesToWTB(WTabBar *wtb)
284 {
285   WRemoteConfig* wrc = new WRemoteConfig();
286   wtb->addTab(tr("Remote Control"), wrc);
287
288   return true; // FIXME
289 }
290
291 bool InputMan::loadOptionsFromServer(VDR* vdr)
292 {
293 #ifdef VOMP_PLATFORM_RASPBERRY
294   if (inputLinux) inputLinux->loadOptionsFromServer(vdr);
295   if (inputCEC) inputCEC->loadOptionsFromServer(vdr);
296 #endif
297
298   return true; // FIXME
299 }
300
301 bool InputMan::saveOptionstoServer()
302 {
303 #ifdef VOMP_PLATFORM_RASPBERRY
304   if (inputLinux) inputLinux->saveOptionstoServer();
305   if (inputCEC) inputCEC->saveOptionstoServer();
306 #endif
307   return true; // FIXME
308 }
309
310 const char* InputMan::getVompKeyName(UCHAR number)
311 {
312   switch (number)
313   {
314     case Input::VOLUMEUP:
315       return tr("Volume Up");
316     case Input::VOLUMEDOWN:
317       return tr("Volume Down");
318     case Input::CHANNELUP:
319       return tr("Channel up");
320     case Input::CHANNELDOWN:
321       return tr("Channel down");
322     case Input::ZERO:
323       return "0";
324     case Input::ONE:
325       return "1";
326     case Input::TWO:
327       return "2";
328     case Input::THREE:
329       return "3";
330     case Input::FOUR:
331       return "4";
332     case Input::FIVE:
333       return "5";
334     case Input::SIX:
335       return "6";
336     case Input::SEVEN:
337       return "7";
338     case Input::EIGHT:
339       return "8";
340     case Input::NINE:
341       return "9";
342     case Input::POWER:
343       return tr("Power");
344     case Input::GO:
345       return tr("Go");
346     case Input::BACK:
347       return tr("Back");
348     case Input::MENU:
349       return tr("Menu");
350     case Input::RED:
351       return tr("Red");
352     case Input::GREEN:
353       return tr("Green");
354     case Input::YELLOW:
355       return tr("Yellow");
356     case Input::BLUE:
357       return tr("Blue");
358     case Input::MUTE:
359       return tr("Mute");
360     case Input::RADIO:
361       return tr("Radio");
362     case Input::REVERSE:
363       return tr("Reverse");
364     case Input::PLAY:
365       return tr("Play");
366     case Input::FORWARD:
367       return tr("Forward");
368     case Input::RECORD:
369       return tr("Record");
370     case Input::STOP:
371       return tr("Stop");
372     case Input::PAUSE:
373       return tr("Pause");
374     case Input::SKIPBACK:
375       return tr("Skip back");
376     case Input::SKIPFORWARD:
377       return tr("Skip forward");
378     case Input::OK:
379       return tr("Ok");
380     case Input::FULL:
381       return tr("Fullscreen");
382     case Input::TV:
383       return tr("TV");
384     case Input::VIDEOS:
385       return tr("Videos");
386     case Input::MUSIC:
387       return tr("Music");
388     case Input::PICTURES:
389       return tr("Pictures");
390     case Input::GUIDE:
391       return tr("Guide");
392     case Input::UP:
393       return tr("Up");
394     case Input::DOWN:
395       return tr("Down");
396     case Input::LEFT:
397       return tr("Left");
398     case Input::RIGHT:
399       return tr("Right");
400     case Input::PREVCHANNEL:
401       return tr("Previous Channel");
402     case Input::STAR:
403       return tr("Star");
404     case Input::HASH:
405       return tr("Hash");
406     case Input::PLAYPAUSE:
407        return tr("Play/Pause");
408
409     default:
410       return NULL;
411   }
412 }
413
414 const UCHAR InputMan::getVompKeyNumber(const char* vompKeyName)
415 {
416   if      (!strcmp(vompKeyName, "VOLUMEUP")) return Input::VOLUMEUP;
417   else if (!strcmp(vompKeyName, "VOLUMEDOWN")) return Input::VOLUMEDOWN;
418   else if (!strcmp(vompKeyName, "CHANNELUP")) return Input::CHANNELUP;
419   else if (!strcmp(vompKeyName, "CHANNELDOWN")) return Input::CHANNELDOWN;
420   else if (!strcmp(vompKeyName, "ZERO")) return Input::ZERO;
421   else if (!strcmp(vompKeyName, "ONE")) return Input::ONE;
422   else if (!strcmp(vompKeyName, "TWO")) return Input::TWO;
423   else if (!strcmp(vompKeyName, "THREE")) return Input::THREE;
424   else if (!strcmp(vompKeyName, "FOUR")) return Input::FOUR;
425   else if (!strcmp(vompKeyName, "FIVE")) return Input::FIVE;
426   else if (!strcmp(vompKeyName, "SIX")) return Input::SIX;
427   else if (!strcmp(vompKeyName, "SEVEN")) return Input::SEVEN;
428   else if (!strcmp(vompKeyName, "EIGHT")) return Input::EIGHT;
429   else if (!strcmp(vompKeyName, "NINE")) return Input::NINE;
430   else if (!strcmp(vompKeyName, "POWER")) return Input::POWER;
431   else if (!strcmp(vompKeyName, "GO")) return Input::GO;
432   else if (!strcmp(vompKeyName, "BACK")) return Input::BACK;
433   else if (!strcmp(vompKeyName, "MENU")) return Input::MENU;
434   else if (!strcmp(vompKeyName, "RED")) return Input::RED;
435   else if (!strcmp(vompKeyName, "GREEN")) return Input::GREEN;
436   else if (!strcmp(vompKeyName, "YELLOW")) return Input::YELLOW;
437   else if (!strcmp(vompKeyName, "BLUE")) return Input::BLUE;
438   else if (!strcmp(vompKeyName, "MUTE")) return Input::MUTE;
439   else if (!strcmp(vompKeyName, "RADIO")) return Input::RADIO;
440   else if (!strcmp(vompKeyName, "REVERSE")) return Input::REVERSE;
441   else if (!strcmp(vompKeyName, "PLAY")) return Input::PLAY;
442   else if (!strcmp(vompKeyName, "FORWARD")) return Input::FORWARD;
443   else if (!strcmp(vompKeyName, "RECORD")) return Input::RECORD;
444   else if (!strcmp(vompKeyName, "STOP")) return Input::STOP;
445   else if (!strcmp(vompKeyName, "PAUSE")) return Input::PAUSE;
446   else if (!strcmp(vompKeyName, "SKIPBACK")) return Input::SKIPBACK;
447   else if (!strcmp(vompKeyName, "SKIPFORWARD")) return Input::SKIPFORWARD;
448   else if (!strcmp(vompKeyName, "OK")) return Input::OK;
449   else if (!strcmp(vompKeyName, "FULL")) return Input::FULL;
450   else if (!strcmp(vompKeyName, "TV")) return Input::TV;
451   else if (!strcmp(vompKeyName, "VIDEOS")) return Input::VIDEOS;
452   else if (!strcmp(vompKeyName, "MUSIC")) return Input::MUSIC;
453   else if (!strcmp(vompKeyName, "PICTURES")) return Input::PICTURES;
454   else if (!strcmp(vompKeyName, "GUIDE")) return Input::GUIDE;
455   else if (!strcmp(vompKeyName, "UP")) return Input::UP;
456   else if (!strcmp(vompKeyName, "DOWN")) return Input::DOWN;
457   else if (!strcmp(vompKeyName, "LEFT")) return Input::LEFT;
458   else if (!strcmp(vompKeyName, "RIGHT")) return Input::RIGHT;
459   else if (!strcmp(vompKeyName, "PREVCHANNEL")) return Input::PREVCHANNEL;
460   else if (!strcmp(vompKeyName, "STAR")) return Input::STAR;
461   else if (!strcmp(vompKeyName, "HASH")) return Input::HASH;
462   else if (!strcmp(vompKeyName, "PLAYPAUSE")) return Input::PLAYPAUSE;
463   else if (!strcmp(vompKeyName, "POWERON")) return Input::POWERON;
464   else if (!strcmp(vompKeyName, "POWEROFF")) return Input::POWEROFF;
465   else return Input::NA_UNKNOWN;
466 }
467
468 std::string InputMan::getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey)
469 {
470   // Go through each active Input class and get the hardware key name for vompKey
471
472   // which doesn't make any sense
473
474   std::string keyNames;
475
476 #ifdef VOMP_PLATFORM_RASPBERRY
477   if (inputLinux)
478   {
479     std::string k = inputLinux->getHardCodedHardwareKeyNamesForVompKey(vompKey);
480     if (k.size()) keyNames += k;
481   }
482
483   if (inputCEC)
484   {
485     std::string k = inputCEC->getHardCodedHardwareKeyNamesForVompKey(vompKey);
486     if (k.size()) { keyNames += ", "; keyNames += k; }
487   }
488 #endif
489
490   if (inputUDP)
491   {
492     std::string k = inputUDP->getHardCodedHardwareKeyNamesForVompKey(vompKey);
493     if (k.size()) { keyNames += ", "; keyNames += k; }
494   }
495
496   return keyNames;
497 }
498
499 std::string InputMan::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
500 {
501   std::string keyNames;
502
503 #ifdef VOMP_PLATFORM_RASPBERRY
504   if (inputLinux)
505   {
506     std::string k = inputLinux->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
507     if (k.size()) keyNames += k;
508   }
509
510   if (inputCEC)
511   {
512     std::string k = inputCEC->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
513     if (k.size()) { keyNames += ", "; keyNames += k; }
514   }
515 #endif
516
517   if (inputUDP)
518   {
519     std::string k = inputUDP->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
520     if (k.size()) { keyNames += ", "; keyNames += k; }
521   }
522
523   return keyNames;
524 }
525
526 void InputMan::ResetToDefault()
527 {
528 #ifdef VOMP_PLATFORM_RASPBERRY
529
530   if (inputLinux) inputLinux->ResetToDefault();
531
532   if (inputCEC) inputCEC->ResetToDefault();
533
534 #endif
535
536   if (inputUDP) inputUDP->ResetToDefault();
537 }
538
539 void InputMan::EnterLearningMode(UCHAR vompKey)
540 {
541 #ifdef VOMP_PLATFORM_RASPBERRY
542   if (inputLinux) inputLinux->EnterLearningMode(vompKey);
543
544 //  if (inputCEC) inputCEC->EnterLearningMode();  FIXME - is there any such thing?
545 #endif
546 }
547
548 void InputMan::cancelLearnMode()
549 {
550 #ifdef VOMP_PLATFORM_RASPBERRY
551   if (inputLinux) inputLinux->cancelLearnMode();
552   if (inputCEC) inputCEC->cancelLearnMode();
553 #endif
554   if (inputUDP) inputUDP->cancelLearnMode();
555 }