Fawkes API  Fawkes Development Version
ros_inifin.cpp
00001 
00002 /***************************************************************************
00003  *  ros_inifin.cpp - Fawkes ROSAspect initializer/finalizer
00004  *
00005  *  Created: Thu May 05 16:03:34 2011
00006  *  Copyright  2006-2011  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <plugins/ros/aspect/ros_inifin.h>
00025 #include <core/threading/thread_finalizer.h>
00026 #include <ros/node_handle.h>
00027 
00028 namespace fawkes {
00029 #if 0 /* just to make Emacs auto-indent happy */
00030 }
00031 #endif
00032 
00033 /** @class ROSAspectIniFin <plugins/ros/aspect/ros_inifin.h>
00034  * ROSAspect initializer/finalizer.
00035  * This initializer/finalizer will provide the ROS node handle to
00036  * threads with the ROSAspect.
00037  * @author Tim Niemueller
00038  */
00039 
00040 /** Constructor. */
00041 ROSAspectIniFin::ROSAspectIniFin()
00042   : AspectIniFin("ROSAspect")
00043 {
00044 }
00045 
00046 void
00047 ROSAspectIniFin::init(Thread *thread)
00048 {
00049   ROSAspect *ros_thread;
00050   ros_thread = dynamic_cast<ROSAspect *>(thread);
00051   if (ros_thread == NULL) {
00052     throw CannotInitializeThreadException("Thread '%s' claims to have the "
00053                                           "ROSAspect, but RTTI says it "
00054                                           "has not. ", thread->name());
00055   }
00056   if (! __rosnode) {
00057     throw CannotInitializeThreadException("ROS node handle has not been set.");
00058   }
00059 
00060   ros_thread->init_ROSAspect(__rosnode);
00061 }
00062 
00063 void
00064 ROSAspectIniFin::finalize(Thread *thread)
00065 {
00066   ROSAspect *ros_thread;
00067   ros_thread = dynamic_cast<ROSAspect *>(thread);
00068   if (ros_thread == NULL) {
00069     throw CannotFinalizeThreadException("Thread '%s' claims to have the "
00070                                         "ROSAspect, but RTTI says it "
00071                                         "has not. ", thread->name());
00072   }
00073   ros_thread->finalize_ROSAspect();
00074 }
00075 
00076 
00077 /** Set the ROS node handle to use for aspect initialization.
00078  * @param rosnode ROS node handle to pass to threads with ROSAspect.
00079  */
00080 void
00081 ROSAspectIniFin::set_rosnode(LockPtr<ros::NodeHandle> rosnode)
00082 {
00083   __rosnode = rosnode;
00084 }
00085 
00086 } // end namespace fawkes