Stefan Schuermans commited on 2011-12-22 21:03:22
Showing 7 changed files, with 210 additions and 14 deletions.
... | ... |
@@ -27,6 +27,26 @@ OpConn::~OpConn() |
27 | 27 |
// might be explicitly deconstructed by remote side |
28 | 28 |
} |
29 | 29 |
|
30 |
+/** |
|
31 |
+ * @brief send key command |
|
32 |
+ * @param[in] key key that was pressed |
|
33 |
+ */ |
|
34 |
+void OpConn::sendKey(char key) |
|
35 |
+{ |
|
36 |
+ if (m_pRemote) |
|
37 |
+ m_pRemote->m_pConnIf->opConnRecvKey(m_pRemote, key); |
|
38 |
+} |
|
39 |
+ |
|
40 |
+/** |
|
41 |
+ * @brief send play command |
|
42 |
+ * @param[in] sound name of sound to play |
|
43 |
+ */ |
|
44 |
+void OpConn::sendPlay(const std::string &sound) |
|
45 |
+{ |
|
46 |
+ if (m_pRemote) |
|
47 |
+ m_pRemote->m_pConnIf->opConnRecvPlay(m_pRemote, sound); |
|
48 |
+} |
|
49 |
+ |
|
30 | 50 |
/// close connection |
31 | 51 |
void OpConn::close() |
32 | 52 |
{ |
... | ... |
@@ -34,6 +34,18 @@ private: |
34 | 34 |
const OpConn & operator=(const OpConn &that); |
35 | 35 |
|
36 | 36 |
public: |
37 |
+ /** |
|
38 |
+ * @brief send key command |
|
39 |
+ * @param[in] key key that was pressed |
|
40 |
+ */ |
|
41 |
+ void sendKey(char key); |
|
42 |
+ |
|
43 |
+ /** |
|
44 |
+ * @brief send play command |
|
45 |
+ * @param[in] sound name of sound to play |
|
46 |
+ */ |
|
47 |
+ void sendPlay(const std::string &sound); |
|
48 |
+ |
|
37 | 49 |
/// close connection |
38 | 50 |
void close(); |
39 | 51 |
|
... | ... |
@@ -23,6 +23,20 @@ public: |
23 | 23 |
virtual ~OpConnIf(); |
24 | 24 |
|
25 | 25 |
public: |
26 |
+ /** |
|
27 |
+ * @brief key command received on operator connection |
|
28 |
+ * @param[in] pConn operator connection object |
|
29 |
+ * @param[in] key key that was pressed |
|
30 |
+ */ |
|
31 |
+ virtual void opConnRecvKey(OpConn *pConn, char key) = 0; |
|
32 |
+ |
|
33 |
+ /** |
|
34 |
+ * @brief play command received on operator connection |
|
35 |
+ * @param[in] pConn operator connection object |
|
36 |
+ * @param[in] sound name of sound to play |
|
37 |
+ */ |
|
38 |
+ virtual void opConnRecvPlay(OpConn *pConn, const std::string &sound) = 0; |
|
39 |
+ |
|
26 | 40 |
/** |
27 | 41 |
* @brief operator connection is closed |
28 | 42 |
* @param[in] pConn operator connection object |
... | ... |
@@ -65,6 +65,34 @@ void OpPrinter::newOpConn(const std::string &name, OpConn *pConn) |
65 | 65 |
(void)name; // unused |
66 | 66 |
} |
67 | 67 |
|
68 |
+/** |
|
69 |
+ * @brief key command received on operator connection |
|
70 |
+ * @param[in] pConn operator connection object |
|
71 |
+ * @param[in] key key that was pressed |
|
72 |
+ */ |
|
73 |
+void OpPrinter::opConnRecvKey(OpConn *pConn, char key) |
|
74 |
+{ |
|
75 |
+ std::cout << "key \"" << key << "\" on connection " << pConn << std::endl; |
|
76 |
+ |
|
77 |
+ // reply to some keys with play command for sounds |
|
78 |
+ switch (key) { |
|
79 |
+ case '7': pConn->sendPlay("ueber_7_bruecken"); break; |
|
80 |
+ case '9': pConn->sendPlay("99_luftballons"); break; |
|
81 |
+ } |
|
82 |
+} |
|
83 |
+ |
|
84 |
+/** |
|
85 |
+ * @brief play command received on operator connection |
|
86 |
+ * @param[in] pConn operator connection object |
|
87 |
+ * @param[in] sound name of sound to play |
|
88 |
+ */ |
|
89 |
+void OpPrinter::opConnRecvPlay(OpConn *pConn, const std::string &sound) |
|
90 |
+{ |
|
91 |
+ // this interface is usually not called for incoming connections |
|
92 |
+ std::cout << "play sound \"" << sound << "\" on connection " << pConn |
|
93 |
+ << std::endl; |
|
94 |
+} |
|
95 |
+ |
|
68 | 96 |
/** |
69 | 97 |
* @brief operator connection is closed |
70 | 98 |
* @param[in] pConn operator connection object |
... | ... |
@@ -58,6 +58,20 @@ public: |
58 | 58 |
*/ |
59 | 59 |
virtual void newOpConn(const std::string &name, OpConn *pConn); |
60 | 60 |
|
61 |
+ /** |
|
62 |
+ * @brief key command received on operator connection |
|
63 |
+ * @param[in] pConn operator connection object |
|
64 |
+ * @param[in] key key that was pressed |
|
65 |
+ */ |
|
66 |
+ virtual void opConnRecvKey(OpConn *pConn, char key); |
|
67 |
+ |
|
68 |
+ /** |
|
69 |
+ * @brief play command received on operator connection |
|
70 |
+ * @param[in] pConn operator connection object |
|
71 |
+ * @param[in] sound name of sound to play |
|
72 |
+ */ |
|
73 |
+ virtual void opConnRecvPlay(OpConn *pConn, const std::string &sound); |
|
74 |
+ |
|
61 | 75 |
/** |
62 | 76 |
* @brief operator connection is closed |
63 | 77 |
* @param[in] pConn operator connection object |
... | ... |
@@ -84,6 +84,20 @@ public: |
84 | 84 |
*/ |
85 | 85 |
virtual void ioWriteCall(Io *io); |
86 | 86 |
|
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 |
+ |
|
87 | 101 |
/** |
88 | 102 |
* @brief operator connection is closed |
89 | 103 |
* @param[in] pConn operator connection object |
... | ... |
@@ -112,6 +126,13 @@ protected: |
112 | 126 |
*/ |
113 | 127 |
void sendAccept(unsigned int line); |
114 | 128 |
|
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 |
+ |
|
115 | 136 |
/** |
116 | 137 |
* @brief send hangup message |
117 | 138 |
* @param[in] line number of line to hangup |
... | ... |
@@ -153,6 +174,22 @@ protected: |
153 | 174 |
*/ |
154 | 175 |
void keyPressed(unsigned int line, char key); |
155 | 176 |
|
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 |
+ |
|
156 | 193 |
/// update time callback |
157 | 194 |
void updateTimeCallback(); |
158 | 195 |
|
... | ... |
@@ -131,6 +131,36 @@ void Phone<ADDR, SOCK>::ioWriteCall(Io *io) |
131 | 131 |
(void)io; // unused |
132 | 132 |
} |
133 | 133 |
|
134 |
+/** |
|
135 |
+ * @brief key command received on operator connection |
|
136 |
+ * @param[in] pConn operator connection object |
|
137 |
+ * @param[in] key key that was pressed |
|
138 |
+ */ |
|
139 |
+template<typename ADDR, typename SOCK> |
|
140 |
+void Phone<ADDR, SOCK>::opConnRecvKey(OpConn *pConn, char key) |
|
141 |
+{ |
|
142 |
+ // the key command does not make sense in this direction, ignore it |
|
143 |
+ (void)pConn; // unused |
|
144 |
+ (void)key; // unused |
|
145 |
+} |
|
146 |
+ |
|
147 |
+/** |
|
148 |
+ * @brief play command received on operator connection |
|
149 |
+ * @param[in] pConn operator connection object |
|
150 |
+ * @param[in] sound name of sound to play |
|
151 |
+ */ |
|
152 |
+template<typename ADDR, typename SOCK> |
|
153 |
+void Phone<ADDR, SOCK>::opConnRecvPlay(OpConn *pConn, const std::string &sound) |
|
154 |
+{ |
|
155 |
+ // get phone line of connection |
|
156 |
+ unsigned int line; |
|
157 |
+ if (!conn2line(pConn, line)) |
|
158 |
+ return; |
|
159 |
+ |
|
160 |
+ // send play message |
|
161 |
+ sendPlay(line, sound); |
|
162 |
+} |
|
163 |
+ |
|
134 | 164 |
/** |
135 | 165 |
* @brief operator connection is closed |
136 | 166 |
* @param[in] pConn operator connection object |
... | ... |
@@ -139,16 +169,15 @@ template<typename ADDR, typename SOCK> |
139 | 169 |
void Phone<ADDR, SOCK>::opConnClose(OpConn *pConn) |
140 | 170 |
{ |
141 | 171 |
// get phone line of connection |
142 |
- ConnLineMap::iterator itConn = m_connLineMap.find(pConn); |
|
143 |
- if (itConn == m_connLineMap.end()) |
|
172 |
+ unsigned int line; |
|
173 |
+ if (!conn2line(pConn, line)) |
|
144 | 174 |
return; |
145 |
- unsigned int line = itConn->second; |
|
146 | 175 |
|
147 | 176 |
// send hangup message |
148 | 177 |
sendHangup(line); |
149 | 178 |
|
150 | 179 |
// remove connection from maps |
151 |
- m_connLineMap.erase(itConn); |
|
180 |
+ m_connLineMap.erase(pConn); |
|
152 | 181 |
m_lineConnMap.erase(line); |
153 | 182 |
} |
154 | 183 |
|
... | ... |
@@ -232,6 +261,19 @@ void Phone<ADDR, SOCK>::sendHeartbeat() |
232 | 261 |
updateTimeCallback(); |
233 | 262 |
} |
234 | 263 |
|
264 |
+/** |
|
265 |
+ * @brief send play message |
|
266 |
+ * @param[in] line number of line to request play on |
|
267 |
+ * @param[in] sound name of sound to request |
|
268 |
+ */ |
|
269 |
+template<typename ADDR, typename SOCK> |
|
270 |
+void Phone<ADDR, SOCK>::sendPlay(unsigned int line, const std::string &sound) |
|
271 |
+{ |
|
272 |
+ std::stringstream strm; |
|
273 |
+ strm << line << ":playbackground:" << sound; |
|
274 |
+ send(strm.str()); |
|
275 |
+} |
|
276 |
+ |
|
235 | 277 |
/** |
236 | 278 |
* @brief send hangup message |
237 | 279 |
* @param[in] line number of line to hangup |
... | ... |
@@ -374,16 +416,15 @@ template<typename ADDR, typename SOCK> |
374 | 416 |
void Phone<ADDR, SOCK>::hangup(unsigned int line) |
375 | 417 |
{ |
376 | 418 |
// get connection |
377 |
- LineConnMap::iterator itLine = m_lineConnMap.find(line); |
|
378 |
- if (itLine == m_lineConnMap.end()) |
|
419 |
+ OpConn *pConn; |
|
420 |
+ if (!line2conn(line, pConn)) |
|
379 | 421 |
return; // no connection on this line |
380 |
- OpConn *pConn = itLine->second; |
|
381 | 422 |
|
382 | 423 |
// close connection |
383 | 424 |
pConn->close(); |
384 | 425 |
|
385 | 426 |
// remove connection from maps |
386 |
- m_lineConnMap.erase(itLine); |
|
427 |
+ m_lineConnMap.erase(line); |
|
387 | 428 |
m_connLineMap.erase(pConn); |
388 | 429 |
} |
389 | 430 |
|
... | ... |
@@ -396,14 +437,44 @@ template<typename ADDR, typename SOCK> |
396 | 437 |
void Phone<ADDR, SOCK>::keyPressed(unsigned int line, char key) |
397 | 438 |
{ |
398 | 439 |
// get connection |
399 |
- LineConnMap::iterator itLine = m_lineConnMap.find(line); |
|
400 |
- if (itLine == m_lineConnMap.end()) |
|
440 |
+ OpConn *pConn; |
|
441 |
+ if (!line2conn(line, pConn)) |
|
401 | 442 |
return; // no connection on this line |
402 |
- OpConn *pConn = itLine->second; |
|
403 | 443 |
|
404 |
- // TODO |
|
405 |
- (void)pConn; |
|
406 |
- (void)key; |
|
444 |
+ // send key press event over connection |
|
445 |
+ pConn->sendKey(key); |
|
446 |
+} |
|
447 |
+ |
|
448 |
+/** |
|
449 |
+ * @brief get phone line number from operator connection |
|
450 |
+ * @param[in] pConn operator connection object |
|
451 |
+ * @param[out] line phone line number |
|
452 |
+ * @return if phone line was found |
|
453 |
+ */ |
|
454 |
+template<typename ADDR, typename SOCK> |
|
455 |
+bool Phone<ADDR, SOCK>::conn2line(OpConn *pConn, unsigned int &line) const |
|
456 |
+{ |
|
457 |
+ ConnLineMap::const_iterator itConn = m_connLineMap.find(pConn); |
|
458 |
+ if (itConn == m_connLineMap.end()) |
|
459 |
+ return false; |
|
460 |
+ line = itConn->second; |
|
461 |
+ return true; |
|
462 |
+} |
|
463 |
+ |
|
464 |
+/** |
|
465 |
+ * @brief get operator connection from phone line number |
|
466 |
+ * @param[in] line phone line number |
|
467 |
+ * @param[out] pConn operator connection object |
|
468 |
+ * @return if phone line was found |
|
469 |
+ */ |
|
470 |
+template<typename ADDR, typename SOCK> |
|
471 |
+bool Phone<ADDR, SOCK>::line2conn(unsigned int line, OpConn *&pConn) const |
|
472 |
+{ |
|
473 |
+ LineConnMap::const_iterator itLine = m_lineConnMap.find(line); |
|
474 |
+ if (itLine == m_lineConnMap.end()) |
|
475 |
+ return false; |
|
476 |
+ pConn = itLine->second; |
|
477 |
+ return true; |
|
407 | 478 |
} |
408 | 479 |
|
409 | 480 |
/// update time callback |
410 | 481 |