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