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 
25 #include "naoqi_broker.h"
26 
27 #include <alcommon/albrokermanager.h>
28 #include <alcore/alerror.h>
29 #include <sys/wait.h>
30 
31 #include <cerrno>
32 #include <csignal>
33 #include <unistd.h>
34 
35 using namespace fawkes;
36 
37 /** @class NaoQiBrokerThread "broker_thread.h"
38  * NaoQi Broker Thread.
39  * This thread maintains a NaoQi broker which can be used by other
40  * threads and is provided via the NaoQiAspect.
41  *
42  * @author Tim Niemueller
43  */
44 
45 /** Constructor. */
47 : Thread("NaoQiBrokerThread", Thread::OPMODE_WAITFORWAKEUP),
48  AspectProviderAspect("NaoQiAspect", &naoqi_aspect_inifin_)
49 {
50 }
51 
52 /** Destructor. */
54 {
55 }
56 
57 void
59 {
60  if (fawkes::naoqi::broker) {
61  broker_ = fawkes::naoqi::broker;
62  logger->log_debug(name(), "Using NaoQi Module broker");
63  } else {
64  throw Exception("NaoQi broker not set, embedding of NaoQi "
65  "not implemented, yet");
66  }
67 
68  /*
69  std::vector<AL::ALModuleInfo>::iterator m;
70  AL::ALPtr<std::vector<AL::ALModuleInfo> >
71  modules(new std::vector<AL::ALModuleInfo>);
72 
73  broker_->getModuleList(modules);
74  for (m = modules->begin(); m != modules->end(); ++m) {
75  printf("Module: %s @ %s:%i\n", m->name.c_str(), m->ip.c_str(), m->port);
76  }
77 
78  modules->clear();
79  broker_->getGlobalModuleList(modules);
80  for (m = modules->begin(); m != modules->end(); ++m) {
81  printf("Global Module: %s @ %s:%i\n", m->name.c_str(), m->ip.c_str(), m->port);
82  }
83  */
84 
85  naoqi_aspect_inifin_.set_naoqi_broker(broker_);
86 }
87 
88 void
90 {
91  broker_.reset();
92  naoqi_aspect_inifin_.set_naoqi_broker(broker_);
93 }
94 
95 void
97 {
98 }
Fawkes library namespace.
virtual void finalize()
Finalize the thread.
NaoQiBrokerThread()
Constructor.
Thread class encapsulation of pthreads.
Definition: thread.h:45
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
virtual void loop()
Code to execute in the thread.
Base class for exceptions in Fawkes.
Definition: exception.h:35
const char * name() const
Get name of thread.
Definition: thread.h:100
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.