]> git.vomp.tv Git - vompclient.git/blob - inputman.h
Message queue fix for VVideoRec
[vompclient.git] / inputman.h
1 /*
2     Copyright 2020 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, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifndef INPUTMAN_H
21 #define INPUTMAN_H
22
23 /*
24 The plan:
25
26 The old design had an abstract Remote class with a single Remote* (RemoteWin, RemoteLinux, RemoteLirc)
27 instantiating.
28
29 The new design is:
30
31 A single RemoteMan object will look after several Input devices. RemoteMan will have getInstance().
32
33 An abstract Input class (old Remote) defines common stuff about input devices.
34
35 Many Input* objects may exist at the same time. They will be:
36
37 InputLinux
38 InputCEC
39 InputUDP
40 InputWin
41 InputLirc
42
43 Obviously Linux and Win won't be active simultaneously. UDP will roll in the UDP button receiver
44 into this input system.
45
46 The old design grew out of the fact the main thread waited on Remote::getButtonPress. Now the main
47 thread waits on the MessageQueue. The input system should be separate, run in its own threads and
48 should insert messages to the queue on input.
49
50 Benefits:
51
52 It would be nice if the input system could boot up in its own time, not delaying the rest of the
53 program, but this may not be achievable.
54
55 In the future it will be possible to implement hot plugging of USB input devices. (Currently vomp
56 only uses what is present at vomp-startup).
57
58 The CEC code can be removed from InputLinux. Under the new design they are nothing to do with
59 each other.
60
61 Direct Lirc input is now brought back, via TCP or unix domain socket.
62
63 Input objects can be easily and individually enabled / disabled.
64
65 New types of input can be implemented much easier.
66
67 For now, two decisions to make things a bit easier:
68
69 1. InputMan will hardcode knowledge about the Input types with hard pointers to each. In future
70    perhaps this will change to a dynamic list of Input objects where InputMan refers to them
71    through the Input interface only.
72
73 2. InputLinux will continue to represent all devices found in /dev/input. If there is a good
74    reason in future then this should switch to several InputLinux objects representing one
75    device each.
76
77 */
78
79 #include <string>
80
81 #include "defines.h"
82 #include "abstractoption.h"
83
84 class InputLinux;
85 class InputCEC;
86 class InputWin;
87 class InputUDP;
88 class InputLIRC;
89
90 class InputMan: public AbstractOption
91 {
92   public:
93     InputMan();
94     virtual ~InputMan();
95     static InputMan* getInstance();
96
97     bool init();
98     void shutdown();
99
100     bool start(); // MessageQueue should be ready before this is called
101     void stop(); // Nothing should be sent to MQ after this
102
103         InputWin* getInputWin() { return inputWin; };
104
105     bool mayHaveFewButtons();
106
107     bool handlesVolume(); // Returns true if we have an InputCEC willing to handle volume
108     void volumeUp();
109     void volumeDown();
110     void volumeMute();
111     void changePowerState(bool powerOn);
112
113     // Abstract Option interface
114     bool addOptionPagesToWTB(WTabBar* wtb);
115     bool addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane);
116     bool loadOptionsFromServer(VDR*);
117     bool saveOptionstoServer();
118
119     static const char* getVompKeyName(UCHAR vompKey);
120     static UCHAR getVompKeyNumber(const char* vompKeyName);
121
122
123     std::string getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey);
124     std::string getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey);
125
126     void EnterLearningMode(UCHAR vompKey);
127     void cancelLearnMode();
128     void ResetToDefault();
129
130   private:
131     static InputMan* instance;
132
133     InputLinux* inputLinux{};
134     InputCEC* inputCEC{};
135     InputWin* inputWin{};
136     InputUDP* inputUDP{};
137     InputLIRC* inputLirc{};
138
139     bool initted{};
140 };
141
142 #endif
143
144 // TODO idea:
145 // don't have Input inherit AbstractOption, just individual inputs. Then one day could test with
146 // dynamic_cast whether to call the AO IF stuff on them
147 // could also have a CEC IF and do the same?