Olivier Smeesters / Mbed 2 deprecated DtmfKit

Dependencies:   mbed ExtTextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers KeyboardStateEventServer.h Source File

KeyboardStateEventServer.h

00001 #ifndef KEYBOARD_STATE_EVENT_SERVER_H_
00002 #define KEYBOARD_STATE_EVENT_SERVER_H_
00003 
00004 #include "kbd_mgr/KeyboardEventServer.h"
00005 #include "kbd_mgr/KeyboardStateHandler.h"
00006 
00007 namespace kbd_mgr {
00008 
00009 /**
00010  * @brief A keyboard state handler that reports only state changes.
00011  */    
00012 class KeyboardStateEventServer : public KeyboardEventServer<KeyboardStateHandler> {
00013 public:
00014     /**
00015      * @brief Attaches the monitor to a function.
00016      * @param fn       Event handler called to report keyboard state change.
00017      */
00018     void attach(FunctionKeyboardStateHandler::HandlerFunction fn) {
00019         setHandler(new FunctionKeyboardStateHandler(fn));
00020     }
00021     
00022     /**
00023      * @brief Attaches the monitor to a method of an object.
00024      * @param obj      Event handler object
00025      * @param fn       Event handler method called to report keyboard state after each complete scan.
00026      */
00027     template <class T>
00028     void attach(T *obj, typename MemberKeyboardStateHandler<T>::MemberFunction fn) {
00029         setHandler(new MemberKeyboardStateHandler<T>(obj, fn));
00030     }
00031     
00032     using  KeyboardEventServer<KeyboardStateHandler>::attach;
00033     
00034     void invokeHandler(const KeyboardState &state) {
00035         if (this->hasHandler()) {
00036             this->handler()->handleState(state);
00037         }
00038     }
00039 };
00040 
00041 } // kbd_mgr
00042 
00043 #endif // KEYBOARD_STATE_EVENT_SERVER_H_