forked from northern-bites/nao-man
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manmodule.cpp
288 lines (229 loc) · 7.46 KB
/
manmodule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/**
* \mainpage
* \section Author
* @author NorthernBites
*
* \section Copyright
* Version : $Id$
*
* \section Description
*
* This file was generated by Aldebaran Robotics ModuleGenerator
*/
//NB NOTE: This file contains the interface to Man used for Naoqi
// See webotsmodule.cpp for the Webots interface.
#ifndef _WIN32
#include <signal.h>
#endif
#include "altypes.h"
#include "alxplatform.h"
#include "manmodule.h"
#include "alptr.h"
#include "albroker.h"
#include "almodule.h"
#include "albrokermanager.h"
#include "alerror.h"
//NBites includes
#include "alproxy.h"
#ifdef USE_DCM
# if defined USE_DCM && defined MAN_IS_REMOTE
# error "DCM not compatible with remote!!!"
# endif
#include "TMan.h"
#include "NaoEnactor.h"
typedef NaoEnactor EnactorT;
typedef TMan ALMan;
#else
#include "TTMan.h"
#include "ALEnactor.h"
typedef ALEnactor EnactorT;
typedef TTMan ALMan;
#endif
#include "ALTranscriber.h"
#include "ALImageTranscriber.h"
#include "NaoLights.h"
#include "almodule.h"
#include "alsentinelproxy.h"
using namespace std;
using namespace AL;
using boost::shared_ptr;
static shared_ptr<ALMan> man;
static shared_ptr<Sensors> sensors;
static shared_ptr<Synchro> synchro;
static shared_ptr<ALTranscriber> transcriber;
static shared_ptr<ALImageTranscriber> imageTranscriber;
static shared_ptr<EnactorT> enactor;
static shared_ptr<Lights> lights;
void ALCreateMan( ALPtr<ALBroker> broker){
try{
ALSentinelProxy sentinel(broker);
sentinel.enableDefaultActionSimpleClick(false);
sentinel.enableDefaultActionDoubleClick(false);
sentinel.enableDefaultActionTripleClick(false);
}catch(ALError &e){
cout << "Failed to access the ALSentinel: "<<e.toString()<<endl;
}
synchro = shared_ptr<Synchro>(new Synchro());
sensors = shared_ptr<Sensors>(new Sensors);
transcriber = shared_ptr<ALTranscriber>(new ALTranscriber(broker,sensors));
imageTranscriber =
shared_ptr<ALImageTranscriber>
(new ALImageTranscriber(synchro, sensors, broker));
#ifdef USE_DCM
enactor = shared_ptr<EnactorT>(new EnactorT(sensors,
transcriber,broker));
#else
enactor = shared_ptr<EnactorT>(new EnactorT(sensors,synchro,
transcriber,broker));
#endif
lights = shared_ptr<Lights>(new NaoLights(broker));
//setLedsProxy(AL::ALPtr<AL::ALLedsProxy>(new AL::ALLedsProxy(broker)));
man = boost::shared_ptr<ALMan> (new ALMan(sensors,
transcriber,
imageTranscriber,
enactor,
synchro,
lights));
man->startSubThreads();
}
void ALDestroyMan(){
man->stopSubThreads();
}
#ifndef MAN_IS_REMOTE
#ifdef _WIN32
#define ALCALL __declspec(dllexport)
#else
#define ALCALL
#endif
#ifdef __cplusplus
extern "C"
{
#endif
ALCALL int _createModule( ALPtr<ALBroker> pBroker )
{
#ifdef REDIRECT_C_STDERR
// Redirect stderr to stdout
FILE *_syderr = stderr;
#ifndef __APPLE__
stderr = stdout;
#endif
#endif
// init broker with the main broker inctance
// from the parent executable
ALBrokerManager::setInstance(pBroker->fBrokerManager.lock());
ALBrokerManager::getInstance()->addBroker(pBroker);
// create modules instance
//<OGETINSTANCE> don't remove this comment
//</OGETINSTANCE> don't remove this comment
//NBites code
ALCreateMan(pBroker);
//man = boost::shared_ptr<Man>(new Man(pBroker,"Man"));
//man->manStart();
return 0;
}
ALCALL int _closeModule( )
{
// Delete module instance
//<OKILLINSTANCE> don't remove this comment
//ALPtr<ALProxy>
// man = pBroker->getProxy("Man");
ALDestroyMan();
//</OKILLINSTANCE> don't remove this comment
return 0;
}
# ifdef __cplusplus
}
# endif
#else//MAN_IS_REMOTE
void _terminationHandler( int signum )
{
//ALPtr<ALProxy> man = pBroker->getProxy("Man");
if (signum == SIGINT) {
// no direct exit, main thread will exit when finished
cerr << "Exiting Man via thread stop." << endl;
ALDestroyMan();
}
else {
cerr << "Emergency stop -- exiting immediately" << endl;
// fault, exit immediately
::exit(1);
}
ALBrokerManager::getInstance()->killAllBroker();
ALBrokerManager::kill();
exit(0);
}
int usage( char* progName )
{
std::cout << progName <<", a remote module of naoqi !" << std::endl
<< "USAGE :" << std::endl
<< "-b\t<ip> : binding ip of the server. Default is 127.0.0.1" << std::endl
<< "-p\t<port> : binding port of the server. Default is 9559" << std::endl
<< "-pip\t<ip> : ip of the parent broker. Default is 127.0.0.1" << std::endl
<< "-pport\t<ip> : port of the parent broker. Default is 9559" << std::endl
<< "-h\t: Display this help\n" << std::endl;
return 0;
}
int main( int argc, char *argv[] )
{
#ifdef REDIRECT_C_STDERR
// Redirect stderr to stdout
FILE *_syderr = stderr;
stderr = stdout;
#endif
std::cout << "..::: starting MANMODULE revision " << MANMODULE_VERSION_REVISION << " :::.." << std::endl;
std::cout << "Copyright (c) 2007, Aldebaran-robotics" << std::endl << std::endl;
int i = 1;
std::string brokerName = "manmodule";
std::string brokerIP = "0.0.0.0";
int brokerPort = 0 ;
// Default parent broker IP
std::string parentBrokerIP = "127.0.0.1";
// Default parent broker port
int parentBrokerPort = kBrokerPort;
// checking options
while( i < argc ) {
if ( argv[i][0] != '-' ) return usage( argv[0] );
else if ( std::string( argv[i] ) == "-b" ) brokerIP = std::string( argv[++i] );
else if ( std::string( argv[i] ) == "-p" ) brokerPort = atoi( argv[++i] );
else if ( std::string( argv[i] ) == "-pip" ) parentBrokerIP = std::string( argv[++i] );
else if ( std::string( argv[i] ) == "-pport" ) parentBrokerPort = atoi( argv[++i] );
else if ( std::string( argv[i] ) == "-h" ) return usage( argv[0] );
i++;
}
// If server port is not set
if ( !brokerPort )
brokerPort = FindFreePort( brokerIP );
std::cout << "Try to connect to parent Broker at ip :" << parentBrokerIP
<< " and port : " << parentBrokerPort << std::endl;
std::cout << "Start the server bind on this ip : " << brokerIP
<< " and port : " << brokerPort << std::endl;
// Starting Broker
ALPtr<ALBroker> pBroker = ALBroker::createBroker(brokerName, brokerIP, brokerPort, parentBrokerIP, parentBrokerPort);
pBroker->setBrokerManagerInstance(ALBrokerManager::getInstance());
//<OGETINSTANCE> don't remove this comment
//ALPtr<Man> manptr = ALModule::createModule<Man>(pBroker,"Man" );
//</OGETINSTANCE> don't remove this comment
#ifndef _WIN32
struct sigaction new_action;
/* Set up the structure to specify the new action. */
new_action.sa_handler = _terminationHandler;
sigemptyset( &new_action.sa_mask );
new_action.sa_flags = 0;
sigaction( SIGINT, &new_action, NULL );
#endif
//man = boost::shared_ptr<Man>(new Man(pBroker,"Man"));
ALCreateMan(pBroker);
//man->getTrigger()->await_off();
// // Not sure what the purpose of this modulegenerator code is: //EDIT -JS
pBroker.reset(); // because of while( 1 ), broker counted by brokermanager
while( 1)
{
SleepMs( 100 );
}
cout << "Main method finished" <<endl;
#ifdef _WIN32
_terminationHandler( 0 );
#endif
exit( 0 );
}
#endif//MAN_IS_REMOTE