$search
00001 #include <boost/bind.hpp> 00002 #include <boost/make_shared.hpp> 00003 #include <boost/shared_ptr.hpp> 00004 #include <boost/thread.hpp> 00005 00006 #include <nodelet/nodelet.h> 00007 #include <pluginlib/class_list_macros.h> 00008 00009 #include "tracker-viewer.hh" 00010 00011 namespace visp_tracker 00012 { 00013 class TrackerViewerNodelet : public nodelet::Nodelet 00014 { 00015 public: 00016 TrackerViewerNodelet () 00017 : nodelet::Nodelet (), 00018 exiting_ (false), 00019 trackerViewer_ (), 00020 thread_ () 00021 {} 00022 00023 ~TrackerViewerNodelet () 00024 { 00025 exiting_ = true; 00026 if (thread_) 00027 if (!thread_->timed_join (boost::posix_time::seconds (2))) 00028 NODELET_WARN ("failed to join thread but continuing anyway"); 00029 thread_.reset (); 00030 trackerViewer_.reset (); 00031 } 00032 00033 void spin () 00034 { 00035 trackerViewer_ = boost::shared_ptr<visp_tracker::TrackerViewer> 00036 (new visp_tracker::TrackerViewer 00037 (getMTNodeHandle (), 00038 getMTPrivateNodeHandle (), 00039 exiting_, 5u)); 00040 while (ros::ok () && !exiting_) 00041 trackerViewer_->spin (); 00042 } 00043 00044 virtual void onInit () 00045 { 00046 NODELET_DEBUG ("Initializing nodelet..."); 00047 exiting_ = false; 00048 thread_ = boost::make_shared<boost::thread> 00049 (boost::bind (&TrackerViewerNodelet::spin, this)); 00050 } 00051 private: 00052 volatile bool exiting_; 00053 boost::shared_ptr<visp_tracker::TrackerViewer> trackerViewer_; 00054 boost::shared_ptr<boost::thread> thread_; 00055 }; 00056 00057 } // end of namespace visp_tracker. 00058 00059 PLUGINLIB_DECLARE_CLASS(visp_tracker, TrackerViewer, 00060 visp_tracker::TrackerViewerNodelet, nodelet::Nodelet);