3fc21e2edcd508f41a1891b542b0154556f4b6ae
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

1) /* Blinker
2)    Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org>
3)    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4)    a blinkenarea.org project */
5) 
6) #ifndef BLINKER_PHONE_H
7) #define BLINKER_PHONE_H
8) 
Stefan Schuermans implemented extension confi...

Stefan Schuermans authored 12 years ago

9) #include <map>
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

10) #include <string>
11) 
12) #include "Directory.h"
13) #include "File.h"
14) #include "IoCallee.h"
Stefan Schuermans implemented extension confi...

Stefan Schuermans authored 12 years ago

15) #include "ListTracker.h"
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

16) #include "Mgrs.h"
17) #include "Module.h"
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

18) #include "OpConn.h"
19) #include "OpConnIf.h"
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

20) #include "SettingFile.h"
21) #include "Time.h"
22) #include "TimeCallee.h"
23) 
24) namespace Blinker {
25) 
26) /// phone connector (using EBIP)
27) template<typename ADDR, typename SOCK>
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

28) class Phone: public IoCallee, public Module, public OpConnIf, public TimeCallee
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

29) {
30) protected:
31)   /// type for address setting file
32)   typedef SettingFile<ADDR> AddrFile;
33) 
Stefan Schuermans implemented extension confi...

Stefan Schuermans authored 12 years ago

34)   /// extension to be called
35)   class Extension;
36) 
37)   /// extension list tracker
38)   typedef ListTracker<Phone, Extension, Directory> ExtListTracker;
39) 
40)   /// map of extensions to call (extension name  -> module name)
41)   typedef std::map<std::string, std::string> ExtMap;
42) 
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

43)   /// map from line number to connection
44)   typedef std::map<unsigned int, OpConn *> LineConnMap;
45) 
46)   /// map from connection to line number
47)   typedef std::map<OpConn *, unsigned int> ConnLineMap;
48) 
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

49) public:
50)   /**
51)    * @brief constructor
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

52)    * @param[in] name module name
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

53)    * @param[in] mgrs managers
54)    * @param[in] dirBase base directory
55)    */
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

56)   Phone(const std::string &name, Mgrs &mgrs, const Directory &dirBase);
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

57) 
58)   /// virtual destructor
59)   virtual ~Phone();
60) 
61) private:
62)   /// copy constructor disabled
63)   Phone(const Phone &that);
64) 
65)   /// assignment operator disabled
66)   const Phone & operator=(const Phone &that);
67) 
68) public:
69)   /// check for update of configuration
70)   virtual void updateConfig();
71) 
72)   /// callback when requested time reached
73)   virtual void timeCall();
74) 
75)   /**
76)    * @brief callback when I/O object is readable
77)    * @param[in] io I/O object that is readable
78)    */
79)   virtual void ioReadCall(Io *io);
80) 
81)   /**
82)    * @brief callback when I/O object is writable
83)    * @param[in] io I/O object that is writable
84)    */
85)   virtual void ioWriteCall(Io *io);
86) 
Stefan Schuermans implemented play and key me...

Stefan Schuermans authored 12 years ago

87)   /**
88)    * @brief key command received on operator connection
89)    * @param[in] pConn operator connection object
90)    * @param[in] key key that was pressed
91)    */
92)   virtual void opConnRecvKey(OpConn *pConn, char key);
93) 
94)   /**
95)    * @brief play command received on operator connection
96)    * @param[in] pConn operator connection object
97)    * @param[in] sound name of sound to play
98)    */
99)   virtual void opConnRecvPlay(OpConn *pConn, const std::string &sound);
100) 
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

101)   /**
102)    * @brief operator connection is closed
103)    * @param[in] pConn operator connection object
104)    */
105)   virtual void opConnClose(OpConn *pConn);
106) 
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

107) protected:
108)   /// (re-)read server address
109)   void readServer();
110) 
111)   /// create socket and bind it
112)   void createSock();
113) 
114)   /// destroy socket
115)   void destroySock();
116) 
117)   /// register with server
118)   void sendRegister();
119) 
120)   /// send heartbeat to server
121)   void sendHeartbeat();
122) 
Stefan Schuermans accepting EBIP calls works now

Stefan Schuermans authored 12 years ago

123)   /**
124)    * @brief send accept message
125)    * @param[in] line number of line accept on
126)    */
127)   void sendAccept(unsigned int line);
128) 
Stefan Schuermans implemented play and key me...

Stefan Schuermans authored 12 years ago

129)   /**
130)    * @brief send play message
131)    * @param[in] line number of line to request play on
132)    * @param[in] sound name of sound to request
133)    */
134)   void sendPlay(unsigned int line, const std::string &sound);
135) 
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

136)   /**
137)    * @brief send hangup message
138)    * @param[in] line number of line to hangup
139)    */
140)   void sendHangup(unsigned int line);
141) 
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

142)   /**
143)    * @brief send message to server
144)    * @param[in] msg message to send
145)    */
146)   void send(const std::string &msg);
147) 
148)   /// receive data from socket
149)   void receiveFromSock();
150) 
Stefan Schuermans implemented extension confi...

Stefan Schuermans authored 12 years ago

151)   /**
152)    * @brief process message from server
153)    * @param[in] msg message from server
154)    */
155)   void serverMsg(const std::string &msg);
156) 
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

157)   /**
158)    * @brief process incoming call
159)    * @param[in] line number of phone line
160)    * @param[in] extension extenstion called (i.e. phone number)
161)    */
162)   void incomingCall(unsigned int line, const std::string &extension);
163) 
164)   /**
165)    * @brief hangup on phone line
166)    * @param[in] line number of phone line
167)    */
168)   void hangup(unsigned int line);
169) 
170)   /**
171)    * @brief key pressed on phone line
172)    * @param[in] line number of phone line
173)    * @param[in] key key that has been pressed
174)    */
175)   void keyPressed(unsigned int line, char key);
176) 
Stefan Schuermans implemented play and key me...

Stefan Schuermans authored 12 years ago

177)   /**
178)    * @brief get phone line number from operator connection
179)    * @param[in] pConn operator connection object
180)    * @param[out] line phone line number
181)    * @return if phone line was found
182)    */
183)   bool conn2line(OpConn *pConn, unsigned int &line) const;
184) 
185)   /**
186)    * @brief get operator connection from phone line number
187)    * @param[in] line phone line number
188)    * @param[out] pConn operator connection object
189)    * @return if phone line was found
190)    */
191)   bool line2conn(unsigned int line, OpConn *&pConn) const;
192) 
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

193)   /// update time callback
194)   void updateTimeCallback();
195) 
196) protected:
197)   static const Time m_serverTimeout;
198)   static const Time m_heartbeatInterval;
199) 
200) protected:
Stefan Schuermans implemented extension confi...

Stefan Schuermans authored 12 years ago

201)   AddrFile       m_fileBind;       ///< bind address file
202)   AddrFile       m_fileServer;     ///< server address file
203)   ExtListTracker m_extListTracker; ///< extension tracker
204)   SOCK           *m_pSock;         ///< socket to use for sending messages
205)   Time           m_timeRegister;   ///< time to re-register
206)   Time           m_timeHeartbeat;  ///< time to send next heartbeat
207)   ExtMap         m_extMap;         ///< map of extensions to call
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

208)   LineConnMap    m_lineConnMap;    ///< map from line number to connection
209)   ConnLineMap    m_connLineMap;    ///< map from connection to line number