b6b2996b76e1b0f0e403b4be40430a445bc0873c
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

1) /* Blinker
Stefan Schuermans update copyright years

Stefan Schuermans authored 10 years ago

2)    Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org>
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

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) 
Stefan Schuermans OpPrinter: play sound on co...

Stefan Schuermans authored 12 years ago

9) #include "CallMgr.h"
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

10) #include "Directory.h"
11) #include "File.h"
12) #include "Mgrs.h"
13) #include "Module.h"
14) #include "OpConn.h"
15) #include "OpConnIf.h"
16) #include "OpMgr.h"
17) #include "OpPrinter.h"
18) #include "OpReqIf.h"
Stefan Schuermans OpPrinter: play sound on co...

Stefan Schuermans authored 12 years ago

19) #include "Time.h"
20) #include "TimeCallee.h"
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

21) 
22) namespace Blinker {
23) 
24) /**
25)  * @brief constructor
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

27)  * @param[in] mgrs managers
28)  * @param[in] dirBase base directory
29)  */
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

30) OpPrinter::OpPrinter(const std::string &name, Mgrs &mgrs,
31)                      const Directory &dirBase):
32)   Module(name, mgrs, dirBase)
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

36) }
37) 
38) /// virtual destructor
39) OpPrinter::~OpPrinter()
40) {
Stefan Schuermans fix operator connection pri...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

43) 
44)   // close open operator connections
45)   while (!m_opConns.empty()) {
46)     OpConns::iterator itOpConn = m_opConns.begin();
47)     (*itOpConn)->close();
48)     m_opConns.erase(itOpConn);
49)   }
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

50) }
51) 
52) /// check for update of configuration
53) void OpPrinter::updateConfig()
54) {
55)   // nothing to do here for this module
56) }
57) 
Stefan Schuermans OpPrinter: play sound on co...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

68) /**
69)  * @brief check if accepting new operator connction is possible
70)  * @param[in] name operator interface name
71)  * @return if accepting new connection is possible
72)  */
73) bool OpPrinter::acceptNewOpConn(const std::string &name)
74) {
75)   return true; // accept all connections
76)   (void)name; // unused
77) }
78) 
79) /**
80)  * @brief new operator connection
81)  * @param[in] name operator interface name
82)  * @param[in] pConn operator connection object
Stefan Schuermans clarified operator connecti...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

89)   std::cout << "new connection " << pConn << std::endl;
Stefan Schuermans OpPrinter: play sound on co...

Stefan Schuermans authored 12 years ago

90)   m_sendPlay.insert(pConn); // schedule sending play command
91)   m_mgrs.m_callMgr.requestTimeCall(this, Time::now());
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

92)   (void)name; // unused
93) }
94) 
Stefan Schuermans implemented play and key me...

Stefan Schuermans authored 12 years ago

95) /**
96)  * @brief key command received on operator connection
97)  * @param[in] pConn operator connection object
98)  * @param[in] key key that was pressed
99)  */
100) void OpPrinter::opConnRecvKey(OpConn *pConn, char key)
101) {
102)   std::cout << "key \"" << key << "\" on connection " << pConn << std::endl;
103) 
104)   // reply to some keys with play command for sounds
105)   switch (key) {
106)     case '7': pConn->sendPlay("ueber_7_bruecken"); break;
107)     case '9': pConn->sendPlay("99_luftballons"); break;
Stefan Schuermans OpPrinter: play sound on co...

Stefan Schuermans authored 12 years ago

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;
Stefan Schuermans implemented play and key me...

Stefan Schuermans authored 12 years ago

114)   }
115) }
116) 
117) /**
118)  * @brief play command received on operator connection
119)  * @param[in] pConn operator connection object
120)  * @param[in] sound name of sound to play
121)  */
122) void OpPrinter::opConnRecvPlay(OpConn *pConn, const std::string &sound)
123) {
124)   // this interface is usually not called for incoming connections
125)   std::cout << "play sound \"" << sound << "\" on connection " << pConn
126)             << std::endl;
127) }
128) 
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

129) /**
130)  * @brief operator connection is closed
131)  * @param[in] pConn operator connection object
Stefan Schuermans clarified operator connecti...

Stefan Schuermans authored 12 years ago

132)  *
133)  * The connection may not be used for sending any more in this callback.
Stefan Schuermans implement operator connecti...

Stefan Schuermans authored 12 years ago

134)  */
135) void OpPrinter::opConnClose(OpConn *pConn)
136) {
137)   std::cout << "connection " << pConn << " closed" << std::endl;
Stefan Schuermans fix operator connection pri...

Stefan Schuermans authored 12 years ago

138)   m_opConns.erase(pConn);
Stefan Schuermans OpPrinter: play sound on co...

Stefan Schuermans authored 12 years ago

139)   m_sendPlay.erase(pConn); // could be in there, better be on safe side