BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
69ac12f
Branches
Tags
master
Blinker
src
noarch
Phone.h
make modules know their name
Stefan Schuermans
commited
69ac12f
at 2011-12-22 19:41:00
Phone.h
Blame
History
Raw
/* Blinker Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html a blinkenarea.org project */ #ifndef BLINKER_PHONE_H #define BLINKER_PHONE_H #include <map> #include <string> #include "Directory.h" #include "File.h" #include "IoCallee.h" #include "ListTracker.h" #include "Mgrs.h" #include "Module.h" #include "OpConn.h" #include "OpConnIf.h" #include "SettingFile.h" #include "Time.h" #include "TimeCallee.h" namespace Blinker { /// phone connector (using EBIP) template<typename ADDR, typename SOCK> class Phone: public IoCallee, public Module, public OpConnIf, public TimeCallee { protected: /// type for address setting file typedef SettingFile<ADDR> AddrFile; /// extension to be called class Extension; /// extension list tracker typedef ListTracker<Phone, Extension, Directory> ExtListTracker; /// map of extensions to call (extension name -> module name) typedef std::map<std::string, std::string> ExtMap; /// map from line number to connection typedef std::map<unsigned int, OpConn *> LineConnMap; /// map from connection to line number typedef std::map<OpConn *, unsigned int> ConnLineMap; public: /** * @brief constructor * @param[in] name module name * @param[in] mgrs managers * @param[in] dirBase base directory */ Phone(const std::string &name, Mgrs &mgrs, const Directory &dirBase); /// virtual destructor virtual ~Phone(); private: /// copy constructor disabled Phone(const Phone &that); /// assignment operator disabled const Phone & operator=(const Phone &that); public: /// check for update of configuration virtual void updateConfig(); /// callback when requested time reached virtual void timeCall(); /** * @brief callback when I/O object is readable * @param[in] io I/O object that is readable */ virtual void ioReadCall(Io *io); /** * @brief callback when I/O object is writable * @param[in] io I/O object that is writable */ virtual void ioWriteCall(Io *io); /** * @brief operator connection is closed * @param[in] pConn operator connection object */ virtual void opConnClose(OpConn *pConn); protected: /// (re-)read server address void readServer(); /// create socket and bind it void createSock(); /// destroy socket void destroySock(); /// register with server void sendRegister(); /// send heartbeat to server void sendHeartbeat(); /** * @brief send hangup message * @param[in] line number of line to hangup */ void sendHangup(unsigned int line); /** * @brief send message to server * @param[in] msg message to send */ void send(const std::string &msg); /// receive data from socket void receiveFromSock(); /** * @brief process message from server * @param[in] msg message from server */ void serverMsg(const std::string &msg); /** * @brief process incoming call * @param[in] line number of phone line * @param[in] extension extenstion called (i.e. phone number) */ void incomingCall(unsigned int line, const std::string &extension); /** * @brief hangup on phone line * @param[in] line number of phone line */ void hangup(unsigned int line); /** * @brief key pressed on phone line * @param[in] line number of phone line * @param[in] key key that has been pressed */ void keyPressed(unsigned int line, char key); /// update time callback void updateTimeCallback(); protected: static const Time m_serverTimeout; static const Time m_heartbeatInterval; protected: AddrFile m_fileBind; ///< bind address file AddrFile m_fileServer; ///< server address file ExtListTracker m_extListTracker; ///< extension tracker SOCK *m_pSock; ///< socket to use for sending messages Time m_timeRegister; ///< time to re-register Time m_timeHeartbeat; ///< time to send next heartbeat ExtMap m_extMap; ///< map of extensions to call LineConnMap m_lineConnMap; ///< map from line number to connection ConnLineMap m_connLineMap; ///< map from connection to line number }; // class Phone } // namespace Blinker #endif // #ifndef BLINKER_PHONE_H