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 <core/threading/thread_finalizer.h>
25 #include <plugins/gazebo/aspect/gazebo_inifin.h>
26 
27 #include <stdio.h>
28 
29 namespace fawkes {
30 
31 /** @class GazeboAspectIniFin <plugins/gazebo/aspect/gazebo_inifin.h>
32  * GazeboAspect initializer/finalizer.
33  * This initializer/finalizer will provide the Gazebo node handle to
34  * threads with the GazeboAspect.
35  * @author Bastian Klingen, Frederik Zwilling
36  */
37 
38 /** Constructor. */
39 GazeboAspectIniFin::GazeboAspectIniFin() : AspectIniFin("GazeboAspect")
40 {
41 }
42 
43 /** Initialize
44  * @param thread thread
45  */
46 void
48 {
49  GazeboAspect *gazebo_thread;
50  gazebo_thread = dynamic_cast<GazeboAspect *>(thread);
51  if (gazebo_thread == NULL) {
52  throw CannotInitializeThreadException("Thread '%s' claims to have the "
53  "GazeboAspect, but RTTI says it "
54  "has not. ",
55  thread->name());
56  }
57  if (!gazebonode_) {
58  throw CannotInitializeThreadException("Gazebo node handle has not been set.");
59  }
60 
61  gazebo_thread->init_GazeboAspect(gazebonode_, gazebo_world_node_);
62 }
63 
64 /** Finalize
65  * @param thread thread
66  */
67 void
68 GazeboAspectIniFin::finalize(Thread *thread)
69 {
70  GazeboAspect *gazebo_thread;
71  gazebo_thread = dynamic_cast<GazeboAspect *>(thread);
72  if (gazebo_thread == NULL) {
73  throw CannotFinalizeThreadException("Thread '%s' claims to have the "
74  "GazeboAspect, but RTTI says it "
75  "has not. ",
76  thread->name());
77  }
78  gazebo_thread->finalize_GazeboAspect();
79 }
80 
81 /** Set the Gazebo node handle to use for aspect initialization.
82  * (used for robot specific communication)
83  * @param gazebonode Gazebo node handle to pass to threads with GazeboAspect.
84  */
85 void
86 GazeboAspectIniFin::set_gazebonode(gazebo::transport::NodePtr gazebonode)
87 {
88  gazebonode_ = gazebonode;
89 }
90 /** Set the Gazebo node handle to use for aspect initialization.
91  * (used for robot independent or world changing communication)
92  * @param gazebo_world_node Gazebo node handle to pass to threads with GazeboAspect.
93  */
94 void
95 GazeboAspectIniFin::set_gazebo_world_node(gazebo::transport::NodePtr gazebo_world_node)
96 {
97  gazebo_world_node_ = gazebo_world_node;
98 }
99 
100 } // end namespace fawkes
fawkes::GazeboAspect
Definition: gazebo.h:40
fawkes::GazeboAspectIniFin::set_gazebonode
void set_gazebonode(gazebo::transport::NodePtr gazebonode)
Set the Gazebo node handle to use for aspect initialization.
Definition: gazebo_inifin.cpp:90
fawkes::CannotInitializeThreadException
Definition: thread_initializer.h:37
fawkes::Thread::name
const char * name() const
Definition: thread.h:99
fawkes::GazeboAspectIniFin::set_gazebo_world_node
void set_gazebo_world_node(gazebo::transport::NodePtr gazebo_world_node)
Set the Gazebo node handle to use for aspect initialization.
Definition: gazebo_inifin.cpp:99
fawkes::GazeboAspectIniFin::init
virtual void init(Thread *thread)
Initialize.
Definition: gazebo_inifin.cpp:51
fawkes
fawkes::Thread
Definition: thread.h:44
fawkes::GazeboAspectIniFin::finalize
virtual void finalize(Thread *thread)
Finalize.
Definition: gazebo_inifin.cpp:72
fawkes::CannotFinalizeThreadException
Definition: thread_finalizer.h:37
fawkes::GazeboAspectIniFin::GazeboAspectIniFin
GazeboAspectIniFin()
Constructor.
Definition: gazebo_inifin.cpp:43