Olivier Smeesters
/
DtmfKit
A DTMF sequence editor and player for HAM radio equipment command & control.
Diff: system.hpp
- Revision:
- 0:1324e7d9d471
diff -r 000000000000 -r 1324e7d9d471 system.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/system.hpp Mon Mar 07 22:51:19 2011 +0000 @@ -0,0 +1,60 @@ +#ifndef _SYSTEM_HPP +#define _SYSTEM_HPP + +#include "key_handler.hpp" +#include <string> + +class State; +class DisplayManager; +class KeyboardManager; +class DtmfGenerator; + + +class System : public KeyHandler { +public: + enum StateId { + Init, Edit, Command, Sending, + NumStates + }; + + System(DisplayManager *display, KeyboardManager *keyboard, DtmfGenerator *dtmf); + + DisplayManager *display() { return this->display_; } + KeyboardManager *keyboard() { return this->keyboard_; } + DtmfGenerator *dtmf() { return this->dtmf_; } + + void registerState(StateId id, State *state); + void unregisterState(State *state); + + void setState(StateId newState); + State * state() const { return this->state_; } + + void insertSymbol(char ch); + void deleteCurrentSymbol(); + void clearText(); + const std::string &text() const { return this->text_; } + std::size_t text_size() const { return this->len_; } + + void moveCursorTo(int pos); + void moveCursorBy(int delta); + std::size_t cursor() const { return this->pos_; } + + // KeyHandler implementation + virtual void handleKey(char ch); + +private: + void setCursorPosition(int pos); + + DisplayManager *display_; + KeyboardManager *keyboard_; + DtmfGenerator *dtmf_; + + State *state_; + State *states_[NumStates]; + + std::string text_; + std::size_t len_; + std::size_t pos_; +}; + +#endif