dont show the infobar when close the last open screen
[enigma2.git] / lib / driver / rc.h
1 #ifndef __rc_h
2 #define __rc_h
3
4 #include <list>
5 #include <map>
6
7 #include <lib/base/ebase.h>
8 #include <libsig_comp.h>
9 #include <string>
10
11 class eRCInput;
12 class eRCDriver;
13 class eRCKey;
14
15 #ifndef SWIG
16
17 /**
18  * \brief A remote control.
19  *
20  * Handles one remote control. Gets codes from a \ref eRCDriver. Produces events in \ref eRCInput.
21  */
22 class eRCDevice: public Object
23 {
24 protected:
25         eRCInput *input;
26         eRCDriver *driver;
27         std::string id;
28 public:
29         /**
30          * \brief Constructs a new remote control.
31          *
32          * \param id The identifier of the RC, for use in settings.
33          * \param input The \ref eRCDriver where this remote gets its codes from.
34          */
35         eRCDevice(std::string id, eRCDriver *input);
36         ~eRCDevice();
37         /**
38          * \brief Handles a device specific code.
39          *
40          * Generates events in \ref eRCInput. code is highly device- and driver dependant.
41          * For Example, it might be 16bit codes with one bit make/break or special codes
42          * for repeat.
43          */
44         virtual void handleCode(int code)=0;
45         /**
46          * \brief Get user readable description.
47          * \result The description.
48          */
49         virtual const char *getDescription() const=0;
50         const std::string getIdentifier() const { return id; }
51         /**
52          * \brief Get a description for a specific key.
53          * \param key The key to get the description for.
54          * \result User readable description of given key.
55          */
56 };
57
58 /**
59  * Receives codes from one or more remote controls.
60  */
61 class eRCDriver: public Object
62 {
63 protected:
64         std::list<eRCDevice*> listeners;
65         eRCInput *input;
66         int enabled;
67 public:
68         /**
69          * \brief Constructs a driver.
70          *
71          * \param input The RCInput to bind this driver to.
72          */
73         eRCDriver(eRCInput *input);
74         /**
75          * \brief Get pointer to key-consumer.
76          */
77         eRCInput *getInput() const { return input; }
78         /**
79          * \brief Adds a code lister
80          */
81         void addCodeListener(eRCDevice *dev)
82         {
83                 listeners.push_back(dev);
84         }
85         void removeCodeListener(eRCDevice *dev)
86         {
87                 listeners.remove(dev);
88         }
89         ~eRCDriver();
90         
91         void enable(int en) { enabled=en; }
92 };
93
94 class eRCShortDriver: public eRCDriver
95 {
96 protected:
97         int handle;
98         eSocketNotifier *sn;
99         void keyPressed(int);
100 public:
101         eRCShortDriver(const char *filename);
102         ~eRCShortDriver();
103 };
104
105 class eRCInputEventDriver: public eRCDriver
106 {
107 protected:
108         int handle;
109         eSocketNotifier *sn;
110         void keyPressed(int);
111 public:
112         std::string getDeviceName();
113         eRCInputEventDriver(const char *filename);
114         ~eRCInputEventDriver();
115 };
116
117 class eRCKey
118 {
119 public:
120         eRCDevice *producer;
121         int code, flags;
122
123         eRCKey(eRCDevice *producer, int code, int flags): 
124                 producer(producer), code(code), flags(flags)
125         {
126         }
127         enum
128         {
129                 flagBreak=1,
130                 flagRepeat=2,
131                 flagAscii=4
132         };
133         
134         bool operator<(const eRCKey &r) const
135         {
136                 if (r.producer == producer)
137                 {
138                         if (r.code == code)
139                         {
140                                 if (r.flags < flags)
141                                         return 1;
142                                 else
143                                         return 0;
144                         } else if (r.code < code)
145                                 return 1;
146                         else
147                                 return 0;
148                 } else if (r.producer < producer)
149                         return 1;
150                 else
151                         return 0;
152         }
153 };
154
155 class eRCConfig
156 {
157 public:
158         eRCConfig();
159         ~eRCConfig();
160         void reload();
161         void save();
162         void set(int delay, int repeat);
163         int rdelay, // keypress delay after first keypress to begin of repeat (in ms)
164                 rrate;          // repeat rate (in ms)
165 };
166
167 #endif
168
169 class eRCInput: public Object
170 {
171         int locked;     
172         int handle;
173         static eRCInput *instance;
174         int keyboardMode;
175 #ifdef SWIG
176         eRCInput();
177         ~eRCInput();
178 public:
179 #else
180 public:
181         struct lstr
182         {
183                 bool operator()(const std::string &a, const std::string &b) const
184                 {
185                         return a<b;
186                 }
187         };
188 protected:
189         std::map<std::string,eRCDevice*,lstr> devices;
190 public:
191         Signal1<void, const eRCKey&> keyEvent;
192         eRCInput();
193         ~eRCInput();
194
195         void close();
196         bool open();
197
198         void setFile(int handle);
199
200         /* This is only relevant for "keyboard"-styled input devices,
201            i.e. not plain remote controls. It's up to the input device
202            driver to decide wheter an input device is a keyboard or
203            not.
204            
205            kmNone will ignore all Ascii Characters sent from the 
206            keyboard/console driver, only give normal keycodes to the
207            application.
208            
209            kmAscii will filter out all keys which produce ascii characters,
210            and send them instead. Note that Modifiers like shift will still
211            be send. Control keys which produce escape codes are send using
212            normal keycodes. 
213            
214            kmAll will ignore all keycodes, and send everything as ascii,
215            including escape codes. Pretty much useless, since you should
216            lock the console and pass this as the console fd for making the
217            tc* stuff working.
218         */
219
220         void keyPressed(const eRCKey &key)
221         {
222                 /*emit*/ keyEvent(key);
223         }
224         
225         void addDevice(const std::string &id, eRCDevice *dev);
226         void removeDevice(const std::string &id);
227         eRCDevice *getDevice(const std::string &id);
228         std::map<std::string,eRCDevice*,lstr> &getDevices();
229
230         eRCConfig config;
231 #endif
232         enum { kmNone, kmAscii, kmAll };
233         void setKeyboardMode(int mode) { keyboardMode = mode; }
234         int  getKeyboardMode() { return keyboardMode; }
235         static eRCInput *getInstance() { return instance; }
236         int lock();
237         void unlock();
238         int islocked() { return locked; }
239 };
240
241 #endif