Stefan Schuermans commited on 2011-12-23 13:37:28
Showing 3 changed files, with 31 additions and 2 deletions.
| ... | ... |
@@ -9,7 +9,9 @@ |
| 9 | 9 |
purposes. |
| 10 | 10 |
It accepts all incoming operator connections and prints events received |
| 11 | 11 |
to standard output. |
| 12 |
- It also replies with a sound play request to the key events 7 and 9. |
|
| 12 |
+ It also replies with a sound play request on connection and in |
|
| 13 |
+ response to the key events <code>7</code> and <code>9</code>. |
|
| 14 |
+ Key event <code>#</code> closes the connection. |
|
| 13 | 15 |
</p> |
| 14 | 16 |
<h2>Configuration</h2> |
| 15 | 17 |
<p> |
| ... | ... |
@@ -6,6 +6,7 @@ |
| 6 | 6 |
#include <iostream> |
| 7 | 7 |
#include <string> |
| 8 | 8 |
|
| 9 |
+#include "CallMgr.h" |
|
| 9 | 10 |
#include "Directory.h" |
| 10 | 11 |
#include "File.h" |
| 11 | 12 |
#include "Mgrs.h" |
| ... | ... |
@@ -15,6 +16,8 @@ |
| 15 | 16 |
#include "OpMgr.h" |
| 16 | 17 |
#include "OpPrinter.h" |
| 17 | 18 |
#include "OpReqIf.h" |
| 19 |
+#include "Time.h" |
|
| 20 |
+#include "TimeCallee.h" |
|
| 18 | 21 |
|
| 19 | 22 |
namespace Blinker {
|
| 20 | 23 |
|
| ... | ... |
@@ -52,6 +55,16 @@ void OpPrinter::updateConfig() |
| 52 | 55 |
// nothing to do here for this module |
| 53 | 56 |
} |
| 54 | 57 |
|
| 58 |
+/// callback when requested time reached |
|
| 59 |
+void OpPrinter::timeCall() |
|
| 60 |
+{
|
|
| 61 |
+ while (!m_sendPlay.empty()) {
|
|
| 62 |
+ OpConns::iterator it = m_sendPlay.begin(); |
|
| 63 |
+ (*it)->sendPlay("opprinter");
|
|
| 64 |
+ m_sendPlay.erase(it); |
|
| 65 |
+ } |
|
| 66 |
+} |
|
| 67 |
+ |
|
| 55 | 68 |
/** |
| 56 | 69 |
* @brief check if accepting new operator connction is possible |
| 57 | 70 |
* @param[in] name operator interface name |
| ... | ... |
@@ -74,6 +87,8 @@ void OpPrinter::newOpConn(const std::string &name, OpConn *pConn) |
| 74 | 87 |
{
|
| 75 | 88 |
m_opConns.insert(pConn); |
| 76 | 89 |
std::cout << "new connection " << pConn << std::endl; |
| 90 |
+ m_sendPlay.insert(pConn); // schedule sending play command |
|
| 91 |
+ m_mgrs.m_callMgr.requestTimeCall(this, Time::now()); |
|
| 77 | 92 |
(void)name; // unused |
| 78 | 93 |
} |
| 79 | 94 |
|
| ... | ... |
@@ -90,6 +105,12 @@ void OpPrinter::opConnRecvKey(OpConn *pConn, char key) |
| 90 | 105 |
switch (key) {
|
| 91 | 106 |
case '7': pConn->sendPlay("ueber_7_bruecken"); break;
|
| 92 | 107 |
case '9': pConn->sendPlay("99_luftballons"); break;
|
| 108 |
+ case '#': |
|
| 109 |
+ std::cout << "closing connection " << pConn << std::endl; |
|
| 110 |
+ pConn->close(); |
|
| 111 |
+ m_opConns.erase(pConn); |
|
| 112 |
+ m_sendPlay.erase(pConn); // could be in there, better be on safe side |
|
| 113 |
+ break; |
|
| 93 | 114 |
} |
| 94 | 115 |
} |
| 95 | 116 |
|
| ... | ... |
@@ -115,6 +136,7 @@ void OpPrinter::opConnClose(OpConn *pConn) |
| 115 | 136 |
{
|
| 116 | 137 |
std::cout << "connection " << pConn << " closed" << std::endl; |
| 117 | 138 |
m_opConns.erase(pConn); |
| 139 |
+ m_sendPlay.erase(pConn); // could be in there, better be on safe side |
|
| 118 | 140 |
} |
| 119 | 141 |
|
| 120 | 142 |
} // namespace Blinker |
| ... | ... |
@@ -16,11 +16,12 @@ |
| 16 | 16 |
#include "OpConn.h" |
| 17 | 17 |
#include "OpConnIf.h" |
| 18 | 18 |
#include "OpReqIf.h" |
| 19 |
+#include "TimeCallee.h" |
|
| 19 | 20 |
|
| 20 | 21 |
namespace Blinker {
|
| 21 | 22 |
|
| 22 | 23 |
/// a operator connection printer |
| 23 |
-class OpPrinter: public Module, public OpReqIf |
|
| 24 |
+class OpPrinter: public Module, public OpReqIf, public TimeCallee |
|
| 24 | 25 |
{
|
| 25 | 26 |
public: |
| 26 | 27 |
/// type for set of open operator connections |
| ... | ... |
@@ -49,6 +50,9 @@ public: |
| 49 | 50 |
/// check for update of configuration |
| 50 | 51 |
virtual void updateConfig(); |
| 51 | 52 |
|
| 53 |
+ /// callback when requested time reached |
|
| 54 |
+ virtual void timeCall(); |
|
| 55 |
+ |
|
| 52 | 56 |
/** |
| 53 | 57 |
* @brief check if accepting new operator connction is possible |
| 54 | 58 |
* @param[in] name operator interface name |
| ... | ... |
@@ -89,6 +93,7 @@ public: |
| 89 | 93 |
|
| 90 | 94 |
protected: |
| 91 | 95 |
OpConns m_opConns; ///< open operator connections |
| 96 |
+ OpConns m_sendPlay; ///< connections to send play request on |
|
| 92 | 97 |
}; // class OpPrinter |
| 93 | 98 |
|
| 94 | 99 |
} // namespace Blinker |
| 95 | 100 |