Fawkes API Fawkes Development Version
ros_inifin.cpp
1
2/***************************************************************************
3 * ros_inifin.cpp - Fawkes ROSAspect initializer/finalizer
4 *
5 * Created: Thu May 05 16:03:34 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 <core/threading/thread_finalizer.h>
25#include <plugins/ros/aspect/ros_inifin.h>
26#include <ros/node_handle.h>
27
28namespace fawkes {
29
30/** @class ROSAspectIniFin <plugins/ros/aspect/ros_inifin.h>
31 * ROSAspect initializer/finalizer.
32 * This initializer/finalizer will provide the ROS node handle to
33 * threads with the ROSAspect.
34 * @author Tim Niemueller
35 */
36
37/** Constructor. */
39{
40}
41
42void
44{
45 ROSAspect *ros_thread;
46 ros_thread = dynamic_cast<ROSAspect *>(thread);
47 if (ros_thread == NULL) {
48 throw CannotInitializeThreadException("Thread '%s' claims to have the "
49 "ROSAspect, but RTTI says it "
50 "has not. ",
51 thread->name());
52 }
53 if (!rosnode_) {
54 throw CannotInitializeThreadException("ROS node handle has not been set.");
55 }
56
57 ros_thread->init_ROSAspect(rosnode_);
58}
59
60void
62{
63 ROSAspect *ros_thread;
64 ros_thread = dynamic_cast<ROSAspect *>(thread);
65 if (ros_thread == NULL) {
66 throw CannotFinalizeThreadException("Thread '%s' claims to have the "
67 "ROSAspect, but RTTI says it "
68 "has not. ",
69 thread->name());
70 }
71 ros_thread->finalize_ROSAspect();
72}
73
74/** Set the ROS node handle to use for aspect initialization.
75 * @param rosnode ROS node handle to pass to threads with ROSAspect.
76 */
77void
79{
80 rosnode_ = rosnode;
81}
82
83} // end namespace fawkes
Aspect initializer/finalizer base class.
Definition: inifin.h:34
Thread cannot be finalized.
virtual void finalize(Thread *thread)
Finalize thread.
Definition: ros_inifin.cpp:61
void set_rosnode(LockPtr< ros::NodeHandle > rosnode)
Set the ROS node handle to use for aspect initialization.
Definition: ros_inifin.cpp:78
ROSAspectIniFin()
Constructor.
Definition: ros_inifin.cpp:38
virtual void init(Thread *thread)
Initialize thread.
Definition: ros_inifin.cpp:43
Thread aspect to get access to a ROS node handle.
Definition: ros.h:39
Thread class encapsulation of pthreads.
Definition: thread.h:46
const char * name() const
Get name of thread.
Definition: thread.h:100
Fawkes library namespace.