![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A DTMF sequence editor and player for HAM radio equipment command & control.
KeyboardManager/kbd_mgr/KeyboardStateHandler.h@0:1324e7d9d471, 2011-03-07 (annotated)
- Committer:
- osmeest
- Date:
- Mon Mar 07 22:51:19 2011 +0000
- Revision:
- 0:1324e7d9d471
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
osmeest | 0:1324e7d9d471 | 1 | #ifndef KEYBOARD_STATE_HANDLER_H_ |
osmeest | 0:1324e7d9d471 | 2 | #define KEYBOARD_STATE_HANDLER_H_ |
osmeest | 0:1324e7d9d471 | 3 | |
osmeest | 0:1324e7d9d471 | 4 | #include "kbd_mgr/KeyboardState.h" |
osmeest | 0:1324e7d9d471 | 5 | |
osmeest | 0:1324e7d9d471 | 6 | namespace kbd_mgr { |
osmeest | 0:1324e7d9d471 | 7 | |
osmeest | 0:1324e7d9d471 | 8 | /** |
osmeest | 0:1324e7d9d471 | 9 | * @brief Interface used to report a keyboard state. |
osmeest | 0:1324e7d9d471 | 10 | */ |
osmeest | 0:1324e7d9d471 | 11 | class KeyboardStateHandler { |
osmeest | 0:1324e7d9d471 | 12 | public: |
osmeest | 0:1324e7d9d471 | 13 | virtual void handleState(const KeyboardState &newState) = 0; |
osmeest | 0:1324e7d9d471 | 14 | virtual ~KeyboardStateHandler() { } |
osmeest | 0:1324e7d9d471 | 15 | }; |
osmeest | 0:1324e7d9d471 | 16 | |
osmeest | 0:1324e7d9d471 | 17 | template <class T> |
osmeest | 0:1324e7d9d471 | 18 | class MemberKeyboardStateHandler : public KeyboardStateHandler { |
osmeest | 0:1324e7d9d471 | 19 | public: |
osmeest | 0:1324e7d9d471 | 20 | typedef void (T::*MemberFunction)(const KeyboardState &); |
osmeest | 0:1324e7d9d471 | 21 | |
osmeest | 0:1324e7d9d471 | 22 | MemberKeyboardStateHandler(T *obj, MemberFunction fn) : |
osmeest | 0:1324e7d9d471 | 23 | object(obj), func(fn) |
osmeest | 0:1324e7d9d471 | 24 | { } |
osmeest | 0:1324e7d9d471 | 25 | |
osmeest | 0:1324e7d9d471 | 26 | virtual void handleState(const KeyboardState &newState) { |
osmeest | 0:1324e7d9d471 | 27 | (object->*func)(newState); |
osmeest | 0:1324e7d9d471 | 28 | } |
osmeest | 0:1324e7d9d471 | 29 | |
osmeest | 0:1324e7d9d471 | 30 | private: |
osmeest | 0:1324e7d9d471 | 31 | T *object; |
osmeest | 0:1324e7d9d471 | 32 | MemberFunction func; |
osmeest | 0:1324e7d9d471 | 33 | }; |
osmeest | 0:1324e7d9d471 | 34 | |
osmeest | 0:1324e7d9d471 | 35 | class FunctionKeyboardStateHandler : public KeyboardStateHandler { |
osmeest | 0:1324e7d9d471 | 36 | public: |
osmeest | 0:1324e7d9d471 | 37 | typedef void (*HandlerFunction)(const KeyboardState &); |
osmeest | 0:1324e7d9d471 | 38 | |
osmeest | 0:1324e7d9d471 | 39 | FunctionKeyboardStateHandler(HandlerFunction fn) : |
osmeest | 0:1324e7d9d471 | 40 | func(fn) |
osmeest | 0:1324e7d9d471 | 41 | { } |
osmeest | 0:1324e7d9d471 | 42 | |
osmeest | 0:1324e7d9d471 | 43 | virtual void handleState(const KeyboardState &newState) { |
osmeest | 0:1324e7d9d471 | 44 | func(newState); |
osmeest | 0:1324e7d9d471 | 45 | } |
osmeest | 0:1324e7d9d471 | 46 | |
osmeest | 0:1324e7d9d471 | 47 | private: |
osmeest | 0:1324e7d9d471 | 48 | HandlerFunction func; |
osmeest | 0:1324e7d9d471 | 49 | }; |
osmeest | 0:1324e7d9d471 | 50 | |
osmeest | 0:1324e7d9d471 | 51 | } // kbd_mgr |
osmeest | 0:1324e7d9d471 | 52 | |
osmeest | 0:1324e7d9d471 | 53 | #endif // KEYBOARD_STATE_HANDLER_H_ |