9 #include <lib/base/ebase.h>
10 #include <lib/base/estring.h>
11 #include <libsig_comp.h>
12 #include <linux/input.h>
13 #include <lib/driver/input_fake.h>
19 // the offset of plain ascii codes coming out of the console (only when in keyboard mode)
20 #define KEY_ASCII 0x1000
23 * \brief A remote control.
25 * Handles one remote control. Gets codes from a \ref eRCDriver. Produces events in \ref eRCInput.
27 class eRCDevice
: public Object
35 * \brief Constructs a new remote control.
37 * \param id The identifier of the RC, for use in settings.
38 * \param input The \ref eRCDriver where this remote gets its codes from.
40 eRCDevice(const eString
&id
, eRCDriver
*input
);
43 * \brief Handles a device specific code.
45 * Generates events in \ref eRCInput. code is highly device- and driver dependant.
46 * For Example, it might be 16bit codes with one bit make/break or special codes
49 virtual void handleCode(int code
)=0;
51 * \brief Get user readable description.
52 * \result The description.
54 virtual const char *getDescription() const=0;
56 * \brief Get a description for a specific key.
57 * \param key The key to get the description for.
58 * \result User readable description of given key.
60 const eString
getIdentifier() const { return id
; }
62 * \brief Get the identifier for this device.
63 * \result User readable identifier of device.
65 virtual const char *getKeyDescription(const eRCKey
&key
) const=0;
67 * \brief Get an input device keycode.
69 * \param key The key to get the input code for.
70 * \result The Linux input device keycode
72 virtual int getKeyCompatibleCode(const eRCKey
&key
) const;
73 const eRCDriver
*getDriver() { return driver
; }
77 * Receives codes from one or more remote controls.
79 class eRCDriver
: public Object
82 std::list
<eRCDevice
*> listeners
;
87 * \brief Constructs a driver.
89 * \param input The RCInput to bind this driver to.
91 eRCDriver(eRCInput
*input
);
93 * \brief Get pointer to key-consumer.
95 eRCInput
*getInput() const { return input
; }
97 * \brief Adds a code lister
99 void addCodeListener(eRCDevice
*dev
)
101 listeners
.push_back(dev
);
103 void removeCodeListener(eRCDevice
*dev
)
105 listeners
.remove(dev
);
109 void enable(int en
) { enabled
=en
; }
111 virtual void flushBuffer() const {};
112 virtual void lock() const {};
113 virtual void unlock() const {};
116 #if HAVE_DVB_API_VERSION < 3
117 class eRCShortDriver
: public eRCDriver
122 void keyPressed(int);
124 eRCShortDriver(const char *filename
);
126 void flushBuffer() const
130 while ( ::read(handle
, &buf
, 2) == 2 );
145 class eRCInputEventDriver
: public eRCDriver
150 void keyPressed(int);
152 eString
getDeviceName();
153 eRCInputEventDriver(const char *filename
);
154 ~eRCInputEventDriver();
155 void flushBuffer() const
157 struct input_event ev
;
159 while ( ::read(handle
, &ev
, sizeof(struct input_event
)) == sizeof(struct input_event
) );
180 eRCKey(eRCDevice
*producer
, int code
, int flags
, eString picture
=""):
181 producer(producer
), code(code
), flags(flags
), picture(picture
)
190 bool operator<(const eRCKey
&r
) const
192 if (producer
> r
.producer
)
194 if (producer
< r
.producer
)
218 void set(int delay
, int repeat
);
219 int rdelay
, // keypress delay after first keypress to begin of repeat (in ms)
220 rrate
; // repeat rate (in ms)
223 class eRCInput
: public Object
227 static eRCInput
*instance
;
232 bool operator()(const eString
&a
, const eString
&b
) const
239 std::map
<eString
,eRCDevice
*,lstr
> devices
;
241 Signal1
<void, const eRCKey
&> keyEvent
;
247 int islocked() { return locked
; }
251 void setFile(int handle
);
254 /* This is only relevant for "keyboard"-styled input devices,
255 i.e. not plain remote controls. It's up to the input device
256 driver to decide wheter an input device is a keyboard or
259 kmNone will ignore all Ascii Characters sent from the
260 keyboard/console driver, only give normal keycodes to the
263 kmAscii will filter out all keys which produce ascii characters,
264 and send them instead. Note that Modifiers like shift will still
265 be send. Control keys which produce escape codes are send using
268 kmAll will ignore all keycodes, and send everything as ascii,
269 including escape codes. Pretty much useless, since you should
270 lock the console and pass this as the console fd for making the
274 enum { kmNone
, kmAscii
, kmAll
};
275 void setKeyboardMode(int mode
);
276 int getKeyboardMode() { return keyboardMode
; }
277 void loadKeyboardMapping();
279 void keyPressed(const eRCKey
&key
)
281 /*emit*/ keyEvent(key
);
284 void addDevice(const eString
&, eRCDevice
*dev
);
285 void removeDevice(const eString
&id
);
286 eRCDevice
*getDevice(const eString
&id
);
287 std::map
<eString
,eRCDevice
*,lstr
> &getDevices();
289 static eRCInput
*getInstance() { return instance
; }