c39aaa1bc307d9f43ac8f8daf9ee1442ced62e11
Stefan Schuermans implement operator connecti...

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) #include <iostream>
7) #include <string>
8) 
9) #include "Directory.h"
10) #include "File.h"
11) #include "Mgrs.h"
12) #include "Module.h"
13) #include "OpConn.h"
14) #include "OpConnIf.h"
15) #include "OpMgr.h"
16) #include "OpPrinter.h"
17) #include "OpReqIf.h"
18) 
19) namespace Blinker {
20) 
21) /**
22)  * @brief constructor
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

23)  * @param[in] name module name
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

24)  * @param[in] mgrs managers
25)  * @param[in] dirBase base directory
26)  */
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

27) OpPrinter::OpPrinter(const std::string &name, Mgrs &mgrs,
28)                      const Directory &dirBase):
29)   Module(name, mgrs, dirBase)
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

30) {
Stefan Schuermans fix operator connection pri...

Stefan Schuermans authored 12 years ago

31)   // open operator connection interface
Stefan Schuermans accepting EBIP calls works now

Stefan Schuermans authored 12 years ago

32)   m_mgrs.m_opMgr.open(m_name, this);
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

33) }
34) 
35) /// virtual destructor
36) OpPrinter::~OpPrinter()
37) {
Stefan Schuermans fix operator connection pri...

Stefan Schuermans authored 12 years ago

38)   // close operator connection interface
Stefan Schuermans accepting EBIP calls works now

Stefan Schuermans authored 12 years ago

39)   m_mgrs.m_opMgr.close(m_name);
Stefan Schuermans fix operator connection pri...

Stefan Schuermans authored 12 years ago

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)   }
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

47) }
48) 
49) /// check for update of configuration
50) void OpPrinter::updateConfig()
51) {
52)   // nothing to do here for this module
53) }
54) 
55) /**
56)  * @brief check if accepting new operator connction is possible
57)  * @param[in] name operator interface name
58)  * @return if accepting new connection is possible
59)  */
60) bool OpPrinter::acceptNewOpConn(const std::string &name)
61) {
62)   return true; // accept all connections
63)   (void)name; // unused
64) }
65) 
66) /**
67)  * @brief new operator connection
68)  * @param[in] name operator interface name
69)  * @param[in] pConn operator connection object
Stefan Schuermans clarified operator connecti...

Stefan Schuermans authored 12 years ago

70)  *
71)  * The new connection may not yet be used for sending inside this callback.
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

72)  */
73) void OpPrinter::newOpConn(const std::string &name, OpConn *pConn)
74) {
Stefan Schuermans fix operator connection pri...

Stefan Schuermans authored 12 years ago

75)   m_opConns.insert(pConn);
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

76)   std::cout << "new connection " << pConn << std::endl;
77)   (void)name; // unused
78) }
79) 
Stefan Schuermans implemented play and key me...

Stefan Schuermans authored 12 years ago

80) /**
81)  * @brief key command received on operator connection
82)  * @param[in] pConn operator connection object
83)  * @param[in] key key that was pressed
84)  */
85) void OpPrinter::opConnRecvKey(OpConn *pConn, char key)
86) {
87)   std::cout << "key \"" << key << "\" on connection " << pConn << std::endl;
88) 
89)   // reply to some keys with play command for sounds
90)   switch (key) {
91)     case '7': pConn->sendPlay("ueber_7_bruecken"); break;
92)     case '9': pConn->sendPlay("99_luftballons"); break;
93)   }
94) }
95) 
96) /**
97)  * @brief play command received on operator connection
98)  * @param[in] pConn operator connection object
99)  * @param[in] sound name of sound to play
100)  */
101) void OpPrinter::opConnRecvPlay(OpConn *pConn, const std::string &sound)
102) {
103)   // this interface is usually not called for incoming connections
104)   std::cout << "play sound \"" << sound << "\" on connection " << pConn
105)             << std::endl;
106) }
107) 
Stefan Schuermans implement operator connecti...

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 implement operator connecti...

Stefan Schuermans authored 12 years ago

113)  */
114) void OpPrinter::opConnClose(OpConn *pConn)
115) {
116)   std::cout << "connection " << pConn << " closed" << std::endl;
Stefan Schuermans fix operator connection pri...

Stefan Schuermans authored 12 years ago

117)   m_opConns.erase(pConn);