Fawkes API  Fawkes Development Version
naoqi_inifin.cpp
1 
2 /***************************************************************************
3  * naoqi_inifin.cpp - Fawkes NaoQiAspect initializer/finalizer
4  *
5  * Created: Thu May 12 15:54:02 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. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <plugins/nao/aspect/naoqi_inifin.h>
25 #include <core/threading/thread_finalizer.h>
26 
27 namespace fawkes {
28 #if 0 /* just to make Emacs auto-indent happy */
29 }
30 #endif
31 
32 /** @class NaoQiAspectIniFin <plugins/nao/aspect/naoqi_inifin.h>
33  * NaoQiAspect initializer/finalizer.
34  * This initializer/finalizer will provide the NaoQi broker to threads
35  * with the NaoQiAspect.
36  * @author Tim Niemueller
37  */
38 
39 /** Constructor. */
41  : AspectIniFin("NaoQiAspect")
42 {
43 }
44 
45 void
47 {
48  NaoQiAspect *naoqi_thread;
49  naoqi_thread = dynamic_cast<NaoQiAspect *>(thread);
50  if (naoqi_thread == NULL) {
51  throw CannotInitializeThreadException("Thread '%s' claims to have the "
52  "NaoQiAspect, but RTTI says it "
53  "has not. ", thread->name());
54  }
55  if (! __naoqi_broker) {
56  throw CannotInitializeThreadException("NaoQi broker has not been set.");
57  }
58 
59  naoqi_thread->init_NaoQiAspect(__naoqi_broker);
60 }
61 
62 void
64 {
65 }
66 
67 
68 /** Set the NaoQi broker to use for aspect initialization.
69  * @param naoqi_broker NaoQi broker to pass to threads with NaoQiAspect.
70  */
71 void
72 NaoQiAspectIniFin::set_naoqi_broker(AL::ALPtr<AL::ALBroker> naoqi_broker)
73 {
74  __naoqi_broker = naoqi_broker;
75 }
76 
77 } // end namespace fawkes
virtual void init(Thread *thread)
Initialize thread.
NaoQiAspectIniFin()
Constructor.
Fawkes library namespace.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Thread cannot be initialized.
const char * name() const
Get name of thread.
Definition: thread.h:95
Thread aspect to get access to NaoQi broker.
Definition: naoqi.h:36
virtual void finalize(Thread *thread)
Finalize thread.
void set_naoqi_broker(AL::ALPtr< AL::ALBroker > naoqi_broker)
Set the NaoQi broker to use for aspect initialization.
Aspect initializer/finalizer base class.
Definition: inifin.h:36