7 #include <lib/base/ebase.h>
8 #include <libsig_comp.h>
18 * \brief A remote control.
20 * Handles one remote control. Gets codes from a \ref eRCDriver. Produces events in \ref eRCInput.
22 class eRCDevice: public Object
30 * \brief Constructs a new remote control.
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.
35 eRCDevice(std::string id, eRCDriver *input);
38 * \brief Handles a device specific code.
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
44 virtual void handleCode(long code)=0;
46 * \brief Get user readable description.
47 * \result The description.
49 virtual const char *getDescription() const=0;
50 const std::string getIdentifier() const { return id; }
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.
56 virtual void setExclusive(bool b) { };
60 * Receives codes from one or more remote controls.
62 class eRCDriver: public Object
65 std::list<eRCDevice*> listeners;
70 * \brief Constructs a driver.
72 * \param input The RCInput to bind this driver to.
74 eRCDriver(eRCInput *input);
76 * \brief Get pointer to key-consumer.
78 eRCInput *getInput() const { return input; }
80 * \brief Adds a code lister
82 void addCodeListener(eRCDevice *dev)
84 listeners.push_back(dev);
86 void removeCodeListener(eRCDevice *dev)
88 listeners.remove(dev);
92 void enable(int en) { enabled=en; }
93 virtual void setExclusive(bool) { }
96 class eRCShortDriver: public eRCDriver
100 ePtr<eSocketNotifier> sn;
101 void keyPressed(int);
103 eRCShortDriver(const char *filename);
107 class eRCInputEventDriver: public eRCDriver
111 ePtr<eSocketNotifier> sn;
112 void keyPressed(int);
114 std::string getDeviceName();
115 eRCInputEventDriver(const char *filename);
116 ~eRCInputEventDriver();
117 void setExclusive(bool b); // in exclusive mode data is not carried to console device
126 eRCKey(eRCDevice *producer, int code, int flags):
127 producer(producer), code(code), flags(flags)
132 /* there are not really flags.. */
141 bool operator<(const eRCKey &r) const
143 if (r.producer == producer)
151 } else if (r.code < code)
155 } else if (r.producer < producer)
169 void set(int delay, int repeat);
170 int rdelay, // keypress delay after first keypress to begin of repeat (in ms)
171 rrate; // repeat rate (in ms)
176 class eRCInput: public Object
179 static eRCInput *instance;
189 bool operator()(const std::string &a, const std::string &b) const
195 std::map<std::string,eRCDevice*,lstr> devices;
197 Signal1<void, const eRCKey&> keyEvent;
204 /* This is only relevant for "keyboard"-styled input devices,
205 i.e. not plain remote controls. It's up to the input device
206 driver to decide wheter an input device is a keyboard or
209 kmNone will ignore all Ascii Characters sent from the
210 keyboard/console driver, only give normal keycodes to the
213 kmAscii will filter out all keys which produce ascii characters,
214 and send them instead. Note that Modifiers like shift will still
215 be send. Control keys which produce escape codes are send using
218 kmAll will ignore all keycodes, and send everything as ascii,
219 including escape codes. Pretty much useless, since you should
220 lock the console and pass this as the console fd for making the
224 void keyPressed(const eRCKey &key)
226 /*emit*/ keyEvent(key);
229 void addDevice(const std::string &id, eRCDevice *dev);
230 void removeDevice(const std::string &id);
231 eRCDevice *getDevice(const std::string &id);
232 std::map<std::string,eRCDevice*,lstr> &getDevices();
236 enum { kmNone, kmAscii, kmAll };
237 void setKeyboardMode(int mode) { keyboardMode = mode; }
238 int getKeyboardMode() { return keyboardMode; }
239 static eRCInput *getInstance() { return instance; }
242 int islocked() { return locked; }