![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A DTMF sequence editor and player for HAM radio equipment command & control.
KeyboardManager/kbd_mgr/KeyboardStateEventServer.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_EVENT_SERVER_H_ |
osmeest | 0:1324e7d9d471 | 2 | #define KEYBOARD_STATE_EVENT_SERVER_H_ |
osmeest | 0:1324e7d9d471 | 3 | |
osmeest | 0:1324e7d9d471 | 4 | #include "kbd_mgr/KeyboardEventServer.h" |
osmeest | 0:1324e7d9d471 | 5 | #include "kbd_mgr/KeyboardStateHandler.h" |
osmeest | 0:1324e7d9d471 | 6 | |
osmeest | 0:1324e7d9d471 | 7 | namespace kbd_mgr { |
osmeest | 0:1324e7d9d471 | 8 | |
osmeest | 0:1324e7d9d471 | 9 | /** |
osmeest | 0:1324e7d9d471 | 10 | * @brief A keyboard state handler that reports only state changes. |
osmeest | 0:1324e7d9d471 | 11 | */ |
osmeest | 0:1324e7d9d471 | 12 | class KeyboardStateEventServer : public KeyboardEventServer<KeyboardStateHandler> { |
osmeest | 0:1324e7d9d471 | 13 | public: |
osmeest | 0:1324e7d9d471 | 14 | /** |
osmeest | 0:1324e7d9d471 | 15 | * @brief Attaches the monitor to a function. |
osmeest | 0:1324e7d9d471 | 16 | * @param fn Event handler called to report keyboard state change. |
osmeest | 0:1324e7d9d471 | 17 | */ |
osmeest | 0:1324e7d9d471 | 18 | void attach(FunctionKeyboardStateHandler::HandlerFunction fn) { |
osmeest | 0:1324e7d9d471 | 19 | setHandler(new FunctionKeyboardStateHandler(fn)); |
osmeest | 0:1324e7d9d471 | 20 | } |
osmeest | 0:1324e7d9d471 | 21 | |
osmeest | 0:1324e7d9d471 | 22 | /** |
osmeest | 0:1324e7d9d471 | 23 | * @brief Attaches the monitor to a method of an object. |
osmeest | 0:1324e7d9d471 | 24 | * @param obj Event handler object |
osmeest | 0:1324e7d9d471 | 25 | * @param fn Event handler method called to report keyboard state after each complete scan. |
osmeest | 0:1324e7d9d471 | 26 | */ |
osmeest | 0:1324e7d9d471 | 27 | template <class T> |
osmeest | 0:1324e7d9d471 | 28 | void attach(T *obj, typename MemberKeyboardStateHandler<T>::MemberFunction fn) { |
osmeest | 0:1324e7d9d471 | 29 | setHandler(new MemberKeyboardStateHandler<T>(obj, fn)); |
osmeest | 0:1324e7d9d471 | 30 | } |
osmeest | 0:1324e7d9d471 | 31 | |
osmeest | 0:1324e7d9d471 | 32 | using KeyboardEventServer<KeyboardStateHandler>::attach; |
osmeest | 0:1324e7d9d471 | 33 | |
osmeest | 0:1324e7d9d471 | 34 | void invokeHandler(const KeyboardState &state) { |
osmeest | 0:1324e7d9d471 | 35 | if (this->hasHandler()) { |
osmeest | 0:1324e7d9d471 | 36 | this->handler()->handleState(state); |
osmeest | 0:1324e7d9d471 | 37 | } |
osmeest | 0:1324e7d9d471 | 38 | } |
osmeest | 0:1324e7d9d471 | 39 | }; |
osmeest | 0:1324e7d9d471 | 40 | |
osmeest | 0:1324e7d9d471 | 41 | } // kbd_mgr |
osmeest | 0:1324e7d9d471 | 42 | |
osmeest | 0:1324e7d9d471 | 43 | #endif // KEYBOARD_STATE_EVENT_SERVER_H_ |