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
29namespace 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. */
40{
41}
42
43/** Initialize
44 * @param thread thread
45 */
46void
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 */
67void
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 */
85void
86GazeboAspectIniFin::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 */
94void
95GazeboAspectIniFin::set_gazebo_world_node(gazebo::transport::NodePtr gazebo_world_node)
96{
97 gazebo_world_node_ = gazebo_world_node;
98}
99
100} // end namespace fawkes
Aspect initializer/finalizer base class.
Definition: inifin.h:34
Thread cannot be finalized.
void set_gazebonode(gazebo::transport::NodePtr gazebonode)
Set the Gazebo node handle to use for aspect initialization.
GazeboAspectIniFin()
Constructor.
virtual void init(Thread *thread)
Initialize.
virtual void finalize(Thread *thread)
Finalize.
void set_gazebo_world_node(gazebo::transport::NodePtr gazebo_world_node)
Set the Gazebo node handle to use for aspect initialization.
Thread aspect to get access to a Gazebo node handle.
Definition: gazebo.h:37
Thread class encapsulation of pthreads.
Definition: thread.h:46
const char * name() const
Get name of thread.
Definition: thread.h:100
Fawkes library namespace.