Fawkes API  Fawkes Development Version
broker_thread.cpp
1 
2 /***************************************************************************
3  * broker_thread.cpp - NaoQi broker providing Thread
4  *
5  * Created: Thu May 12 19:03:40 2011
6  * Copyright 2006-2011 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "broker_thread.h"
24 #include "naoqi_broker.h"
25 
26 #include <cerrno>
27 #include <csignal>
28 #include <unistd.h>
29 #include <sys/wait.h>
30 
31 #include <alcommon/albrokermanager.h>
32 #include <alcore/alerror.h>
33 
34 using namespace fawkes;
35 
36 /** @class NaoQiBrokerThread "broker_thread.h"
37  * NaoQi Broker Thread.
38  * This thread maintains a NaoQi broker which can be used by other
39  * threads and is provided via the NaoQiAspect.
40  *
41  * @author Tim Niemueller
42  */
43 
44 /** Constructor. */
46  : Thread("NaoQiBrokerThread", Thread::OPMODE_WAITFORWAKEUP),
47  AspectProviderAspect("NaoQiAspect", &__naoqi_aspect_inifin)
48 {
49 }
50 
51 
52 /** Destructor. */
54 {
55 }
56 
57 
58 void
60 {
61  if (fawkes::naoqi::broker) {
62  __broker = fawkes::naoqi::broker;
63  logger->log_debug(name(), "Using NaoQi Module broker");
64  } else {
65  throw Exception("NaoQi broker not set, embedding of NaoQi "
66  "not implemented, yet");
67  }
68 
69  /*
70  std::vector<AL::ALModuleInfo>::iterator m;
71  AL::ALPtr<std::vector<AL::ALModuleInfo> >
72  modules(new std::vector<AL::ALModuleInfo>);
73 
74  __broker->getModuleList(modules);
75  for (m = modules->begin(); m != modules->end(); ++m) {
76  printf("Module: %s @ %s:%i\n", m->name.c_str(), m->ip.c_str(), m->port);
77  }
78 
79  modules->clear();
80  __broker->getGlobalModuleList(modules);
81  for (m = modules->begin(); m != modules->end(); ++m) {
82  printf("Global Module: %s @ %s:%i\n", m->name.c_str(), m->ip.c_str(), m->port);
83  }
84  */
85 
86  __naoqi_aspect_inifin.set_naoqi_broker(__broker);
87 }
88 
89 
90 void
92 {
93  __broker.reset();
94  __naoqi_aspect_inifin.set_naoqi_broker(__broker);
95 }
96 
97 
98 void
100 {
101 }
Fawkes library namespace.
virtual void finalize()
Finalize the thread.
NaoQiBrokerThread()
Constructor.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:44
virtual void loop()
Code to execute in the thread.
Base class for exceptions in Fawkes.
Definition: exception.h:36
const char * name() const
Get name of thread.
Definition: thread.h:95
Thread aspect provide a new aspect.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
void set_naoqi_broker(AL::ALPtr< AL::ALBroker > naoqi_broker)
Set the NaoQi broker to use for aspect initialization.
virtual ~NaoQiBrokerThread()
Destructor.
virtual void init()
Initialize the thread.