Fawkes API  Fawkes Development Version
gazebo_inifin.cpp
1 
2 /***************************************************************************
3  * gazebo_inifin.cpp - Fawkes GazeboAspect initializer/finalizer
4  *
5  * Created: Fri Aug 24 09:26:04 2012
6  * Author Bastian Klingen, Frederik Zwilling (2013)
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/gazebo/aspect/gazebo_inifin.h>
25 #include <core/threading/thread_finalizer.h>
26 #include <stdio.h>
27 
28 namespace fawkes {
29 #if 0 /* just to make Emacs auto-indent happy */
30 }
31 #endif
32 
33 /** @class GazeboAspectIniFin <plugins/gazebo/aspect/gazebo_inifin.h>
34  * GazeboAspect initializer/finalizer.
35  * This initializer/finalizer will provide the Gazebo node handle to
36  * threads with the GazeboAspect.
37  * @author Bastian Klingen, Frederik Zwilling
38  */
39 
40 /** Constructor. */
42  : AspectIniFin("GazeboAspect")
43 {
44 }
45 
46 /** Initialize
47  * @param thread thread
48  */
49 void
51 {
52  GazeboAspect *gazebo_thread;
53  gazebo_thread = dynamic_cast<GazeboAspect *>(thread);
54  if (gazebo_thread == NULL) {
55  throw CannotInitializeThreadException("Thread '%s' claims to have the "
56  "GazeboAspect, but RTTI says it "
57  "has not. ", thread->name());
58  }
59  if (! __gazebonode) {
60  throw CannotInitializeThreadException("Gazebo node handle has not been set.");
61  }
62 
63  gazebo_thread->init_GazeboAspect(__gazebonode, __gazebo_world_node);
64 }
65 
66 /** Finalize
67  * @param thread thread
68  */
69 void
71 {
72  GazeboAspect *gazebo_thread;
73  gazebo_thread = dynamic_cast<GazeboAspect *>(thread);
74  if (gazebo_thread == NULL) {
75  throw CannotFinalizeThreadException("Thread '%s' claims to have the "
76  "GazeboAspect, but RTTI says it "
77  "has not. ", thread->name());
78  }
79  gazebo_thread->finalize_GazeboAspect();
80 }
81 
82 
83 /** Set the Gazebo node handle to use for aspect initialization.
84  * (used for robot specific communication)
85  * @param gazebonode Gazebo node handle to pass to threads with GazeboAspect.
86  */
87 void
88 GazeboAspectIniFin::set_gazebonode(gazebo::transport::NodePtr gazebonode)
89 {
90  __gazebonode = gazebonode;
91 }
92 /** Set the Gazebo node handle to use for aspect initialization.
93  * (used for robot independent or world changing communication)
94  * @param gazebo_world_node Gazebo node handle to pass to threads with GazeboAspect.
95  */
96 void
97 GazeboAspectIniFin::set_gazebo_world_node(gazebo::transport::NodePtr gazebo_world_node)
98 {
99  __gazebo_world_node = gazebo_world_node;
100 }
101 
102 } // end namespace fawkes
Fawkes library namespace.
Thread aspect to get access to a Gazebo node handle.
Definition: gazebo.h:37
Thread class encapsulation of pthreads.
Definition: thread.h:42
GazeboAspectIniFin()
Constructor.
virtual void finalize(Thread *thread)
Finalize.
Thread cannot be initialized.
const char * name() const
Get name of thread.
Definition: thread.h:95
Thread cannot be finalized.
void set_gazebonode(gazebo::transport::NodePtr gazebonode)
Set the Gazebo node handle to use for aspect initialization.
virtual void init(Thread *thread)
Initialize.
void set_gazebo_world_node(gazebo::transport::NodePtr gazebo_world_node)
Set the Gazebo node handle to use for aspect initialization.
Aspect initializer/finalizer base class.
Definition: inifin.h:36