c39aaa1bc307d9f43ac8f8daf9ee1442ced62e11
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>
Stefan Schuermans clarified operator connecti...

Stefan Schuermans authored 12 years ago

11) #include <vector>
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

12) 
13) #include "Directory.h"
14) #include "File.h"
15) #include "IoCallee.h"
Stefan Schuermans implemented extension confi...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

44)   /// map from line number to connection
45)   typedef std::map<unsigned int, OpConn *> LineConnMap;
46) 
47)   /// map from connection to line number
48)   typedef std::map<OpConn *, unsigned int> ConnLineMap;
49) 
Stefan Schuermans clarified operator connecti...

Stefan Schuermans authored 12 years ago

50)   /// type for command buffer (command sent before line connected)
51)   typedef std::vector<std::string> CmdBuf;
52) 
53)   /// type for command buffer map (line to command buffer)
54)   typedef std::map<unsigned int, CmdBuf> CmdBufMap;
55) 
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

56) public:
57)   /**
58)    * @brief constructor
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

60)    * @param[in] mgrs managers
61)    * @param[in] dirBase base directory
62)    */
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

94)   /**
95)    * @brief key command received on operator connection
96)    * @param[in] pConn operator connection object
97)    * @param[in] key key that was pressed
98)    */
99)   virtual void opConnRecvKey(OpConn *pConn, char key);
100) 
101)   /**
102)    * @brief play command received on operator connection
103)    * @param[in] pConn operator connection object
104)    * @param[in] sound name of sound to play
105)    */
106)   virtual void opConnRecvPlay(OpConn *pConn, const std::string &sound);
107) 
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

108)   /**
109)    * @brief operator connection is closed
110)    * @param[in] pConn operator connection object
Stefan Schuermans clarified operator connecti...

Stefan Schuermans authored 12 years ago

111)    *
112)    * The connection may not be used for sending any more in this callback.
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

113)    */
114)   virtual void opConnClose(OpConn *pConn);
115) 
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

116) protected:
117)   /// (re-)read server address
118)   void readServer();
119) 
120)   /// create socket and bind it
121)   void createSock();
122) 
123)   /// destroy socket
124)   void destroySock();
125) 
126)   /// register with server
127)   void sendRegister();
128) 
129)   /// send heartbeat to server
130)   void sendHeartbeat();
131) 
Stefan Schuermans accepting EBIP calls works now

Stefan Schuermans authored 12 years ago

132)   /**
133)    * @brief send accept message
134)    * @param[in] line number of line accept on
135)    */
136)   void sendAccept(unsigned int line);
137) 
Stefan Schuermans implemented play and key me...

Stefan Schuermans authored 12 years ago

138)   /**
139)    * @brief send play message
140)    * @param[in] line number of line to request play on
141)    * @param[in] sound name of sound to request
142)    */
143)   void sendPlay(unsigned int line, const std::string &sound);
144) 
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

145)   /**
146)    * @brief send hangup message
147)    * @param[in] line number of line to hangup
148)    */
149)   void sendHangup(unsigned int line);
150) 
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

151)   /**
Stefan Schuermans clarified operator connecti...

Stefan Schuermans authored 12 years ago

152)    * @brief send message buffered to server
153)    * @param[in] line number of line to hangup
154)    * @param[in] msg message to send
155)    */
156)   void sendBuf(unsigned int line, const std::string &msg);
157) 
158)   /**
159)    * @brief send message to server now
160)    * @param[in] line number of line to hangup
161)    * @param[in] msg message to send
162)    */
163)   void sendNow(unsigned int line, const std::string &msg);
164) 
165)   /**
166)    * @brief send message to socket
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

167)    * @param[in] msg message to send
168)    */
Stefan Schuermans clarified operator connecti...

Stefan Schuermans authored 12 years ago

169)   void sendSock(const std::string &msg);
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

170) 
171)   /// receive data from socket
172)   void receiveFromSock();
173) 
Stefan Schuermans implemented extension confi...

Stefan Schuermans authored 12 years ago

174)   /**
175)    * @brief process message from server
176)    * @param[in] msg message from server
177)    */
178)   void serverMsg(const std::string &msg);
179) 
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

180)   /**
181)    * @brief process incoming call
182)    * @param[in] line number of phone line
183)    * @param[in] extension extenstion called (i.e. phone number)
184)    */
185)   void incomingCall(unsigned int line, const std::string &extension);
186) 
Stefan Schuermans clarified operator connecti...

Stefan Schuermans authored 12 years ago

187)   /**
188)    * @brief phone line connected
189)    * @param[in] line number of phone line
190)    */
191)   void connected(unsigned int line);
192) 
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

193)   /**
194)    * @brief hangup on phone line
195)    * @param[in] line number of phone line
196)    */
197)   void hangup(unsigned int line);
198) 
199)   /**
200)    * @brief key pressed on phone line
201)    * @param[in] line number of phone line
202)    * @param[in] key key that has been pressed
203)    */
204)   void keyPressed(unsigned int line, char key);
205) 
Stefan Schuermans implemented play and key me...

Stefan Schuermans authored 12 years ago

206)   /**
207)    * @brief get phone line number from operator connection
208)    * @param[in] pConn operator connection object
209)    * @param[out] line phone line number
210)    * @return if phone line was found
211)    */
212)   bool conn2line(OpConn *pConn, unsigned int &line) const;
213) 
214)   /**
215)    * @brief get operator connection from phone line number
216)    * @param[in] line phone line number
217)    * @param[out] pConn operator connection object
218)    * @return if phone line was found
219)    */
220)   bool line2conn(unsigned int line, OpConn *&pConn) const;
221) 
Stefan Schuermans begin of phone connector

Stefan Schuermans authored 12 years ago

222)   /// update time callback
223)   void updateTimeCallback();
224) 
225) protected:
226)   static const Time m_serverTimeout;
227)   static const Time m_heartbeatInterval;
228) 
229) protected:
Stefan Schuermans implemented extension confi...

Stefan Schuermans authored 12 years ago

230)   AddrFile       m_fileBind;       ///< bind address file
231)   AddrFile       m_fileServer;     ///< server address file
232)   ExtListTracker m_extListTracker; ///< extension tracker
233)   SOCK           *m_pSock;         ///< socket to use for sending messages
234)   Time           m_timeRegister;   ///< time to re-register
235)   Time           m_timeHeartbeat;  ///< time to send next heartbeat
236)   ExtMap         m_extMap;         ///< map of extensions to call
Stefan Schuermans phone connector module basi...

Stefan Schuermans authored 12 years ago

237)   LineConnMap    m_lineConnMap;    ///< map from line number to connection
238)   ConnLineMap    m_connLineMap;    ///< map from connection to line number
Stefan Schuermans clarified operator connecti...

Stefan Schuermans authored 12 years ago

239)   CmdBufMap      m_cmdBufMap;      ///< commands to send after line connected