client.cpp
Go to the documentation of this file.
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-client.hh"
00010 
00011 namespace visp_tracker
00012 {
00013   class TrackerClientNodelet : public nodelet::Nodelet
00014   {
00015   public:
00016     TrackerClientNodelet ()
00017       : nodelet::Nodelet (),
00018         exiting_ (false),
00019         trackerClient_ (),
00020         thread_ ()
00021     {}
00022 
00023     ~TrackerClientNodelet ()
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       trackerClient_.reset ();
00031     }
00032 
00033     void spin ()
00034     {
00035       trackerClient_ = boost::shared_ptr<visp_tracker::TrackerClient>
00036         (new visp_tracker::TrackerClient
00037          (getMTNodeHandle (),
00038           getMTPrivateNodeHandle (),
00039           exiting_, 5u));
00040       if (ros::ok () && !exiting_)
00041         trackerClient_->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 (&TrackerClientNodelet::spin, this));
00050     }
00051   private:
00052     volatile bool exiting_;
00053     boost::shared_ptr<visp_tracker::TrackerClient> trackerClient_;
00054     boost::shared_ptr<boost::thread> thread_;
00055   };
00056 
00057 } // end of namespace visp_tracker.
00058 
00059 PLUGINLIB_DECLARE_CLASS(visp_tracker, TrackerClient,
00060                         visp_tracker::TrackerClientNodelet, nodelet::Nodelet);


visp_tracker
Author(s): Thomas Moulard
autogenerated on Mon Oct 6 2014 08:40:35