Stefan Schuermans commited on 2011-12-22 21:22:09
Showing 2 changed files, with 19 additions and 0 deletions.
... | ... |
@@ -28,13 +28,22 @@ OpPrinter::OpPrinter(const std::string &name, Mgrs &mgrs, |
28 | 28 |
const Directory &dirBase): |
29 | 29 |
Module(name, mgrs, dirBase) |
30 | 30 |
{ |
31 |
+ // open operator connection interface |
|
31 | 32 |
m_mgrs.m_opMgr.open(m_name, this); |
32 | 33 |
} |
33 | 34 |
|
34 | 35 |
/// virtual destructor |
35 | 36 |
OpPrinter::~OpPrinter() |
36 | 37 |
{ |
38 |
+ // close operator connection interface |
|
37 | 39 |
m_mgrs.m_opMgr.close(m_name); |
40 |
+ |
|
41 |
+ // close open operator connections |
|
42 |
+ while (!m_opConns.empty()) { |
|
43 |
+ OpConns::iterator itOpConn = m_opConns.begin(); |
|
44 |
+ (*itOpConn)->close(); |
|
45 |
+ m_opConns.erase(itOpConn); |
|
46 |
+ } |
|
38 | 47 |
} |
39 | 48 |
|
40 | 49 |
/// check for update of configuration |
... | ... |
@@ -61,6 +70,7 @@ bool OpPrinter::acceptNewOpConn(const std::string &name) |
61 | 70 |
*/ |
62 | 71 |
void OpPrinter::newOpConn(const std::string &name, OpConn *pConn) |
63 | 72 |
{ |
73 |
+ m_opConns.insert(pConn); |
|
64 | 74 |
std::cout << "new connection " << pConn << std::endl; |
65 | 75 |
(void)name; // unused |
66 | 76 |
} |
... | ... |
@@ -100,6 +110,7 @@ void OpPrinter::opConnRecvPlay(OpConn *pConn, const std::string &sound) |
100 | 110 |
void OpPrinter::opConnClose(OpConn *pConn) |
101 | 111 |
{ |
102 | 112 |
std::cout << "connection " << pConn << " closed" << std::endl; |
113 |
+ m_opConns.erase(pConn); |
|
103 | 114 |
} |
104 | 115 |
|
105 | 116 |
} // namespace Blinker |
... | ... |
@@ -6,6 +6,7 @@ |
6 | 6 |
#ifndef BLINKER_OPPRINTER_H |
7 | 7 |
#define BLINKER_OPPRINTER_H |
8 | 8 |
|
9 |
+#include <set> |
|
9 | 10 |
#include <string> |
10 | 11 |
|
11 | 12 |
#include "Directory.h" |
... | ... |
@@ -21,6 +22,10 @@ namespace Blinker { |
21 | 22 |
/// a operator connection printer |
22 | 23 |
class OpPrinter: public Module, public OpReqIf |
23 | 24 |
{ |
25 |
+public: |
|
26 |
+ /// type for set of open operator connections |
|
27 |
+ typedef std::set<OpConn *> OpConns; |
|
28 |
+ |
|
24 | 29 |
public: |
25 | 30 |
/** |
26 | 31 |
* @brief constructor |
... | ... |
@@ -77,6 +82,9 @@ public: |
77 | 82 |
* @param[in] pConn operator connection object |
78 | 83 |
*/ |
79 | 84 |
virtual void opConnClose(OpConn *pConn); |
85 |
+ |
|
86 |
+protected: |
|
87 |
+ OpConns m_opConns; ///< open operator connections |
|
80 | 88 |
}; // class OpPrinter |
81 | 89 |
|
82 | 90 |
} // namespace Blinker |
83 | 91 |