nodelet.cpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*********************************************************************
00004 * Software License Agreement (BSD License)
00005 *
00006 *  Copyright (c) 2010 Jack O'Quin
00007 *  All rights reserved.
00008 *
00009 *  Redistribution and use in source and binary forms, with or without
00010 *  modification, are permitted provided that the following conditions
00011 *  are met:
00012 *
00013 *   * Redistributions of source code must retain the above copyright
00014 *     notice, this list of conditions and the following disclaimer.
00015 *   * Redistributions in binary form must reproduce the above
00016 *     copyright notice, this list of conditions and the following
00017 *     disclaimer in the documentation and/or other materials provided
00018 *     with the distribution.
00019 *   * Neither the name of the author nor other contributors may be
00020 *     used to endorse or promote products derived from this software
00021 *     without specific prior written permission.
00022 *
00023 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034 *  POSSIBILITY OF SUCH DAMAGE.
00035 *********************************************************************/
00036 
00037 #include <signal.h>
00038 
00039 #include <boost/thread.hpp>
00040 
00041 #include <ros/ros.h>
00042 #include <pluginlib/class_list_macros.h>
00043 #include <nodelet/nodelet.h>
00044 
00045 #include "driver1394.h"
00046 
00054 class Camera1394Nodelet: public nodelet::Nodelet
00055 {
00056 public:
00057   Camera1394Nodelet():
00058     running_(false)
00059   {}
00060 
00061   ~Camera1394Nodelet()
00062   {
00063     if (running_)
00064       {
00065         NODELET_INFO("shutting down driver thread");
00066         running_ = false;
00067         deviceThread_->join();
00068         NODELET_INFO("driver thread stopped");
00069       }
00070     dvr_->shutdown();
00071   }
00072 
00073 private:
00074   virtual void onInit();
00075   virtual void devicePoll();
00076 
00077   volatile bool running_;               
00078   boost::shared_ptr<camera1394_driver::Camera1394Driver> dvr_;
00079   boost::shared_ptr<boost::thread> deviceThread_;
00080 };
00081 
00086 void Camera1394Nodelet::onInit()
00087 {
00088   ros::NodeHandle priv_nh(getPrivateNodeHandle());
00089   ros::NodeHandle node(getNodeHandle());
00090   ros::NodeHandle camera_nh(node, "camera");
00091   dvr_.reset(new camera1394_driver::Camera1394Driver(priv_nh, camera_nh));
00092   dvr_->setup();
00093 
00094   // spawn device thread
00095   running_ = true;
00096   deviceThread_ = boost::shared_ptr< boost::thread >
00097     (new boost::thread(boost::bind(&Camera1394Nodelet::devicePoll, this)));
00098 }
00099 
00101 void Camera1394Nodelet::devicePoll()
00102 {
00103   while (running_)
00104     {
00105       dvr_->poll();
00106     }
00107 }
00108 
00109 // Register this plugin with pluginlib.  Names must match nodelet_velodyne.xml.
00110 //
00111 // parameters are: package, class name, class type, base class type
00112 PLUGINLIB_DECLARE_CLASS(camera1394, driver,
00113                         Camera1394Nodelet, nodelet::Nodelet);


camera1394
Author(s): Jack O'Quin, Ken Tossell, Patrick Beeson, Nate Koenig, Andrew Howard, Damien Douxchamps, Dan Dennedy
autogenerated on Sat Dec 28 2013 16:50:11