00001 // Copyright [2015] Takashi Ogura<t.ogura@gmail.com> 00002 00003 #include "cv_camera/driver.h" 00004 00005 #include <nodelet/nodelet.h> 00006 #include <boost/thread.hpp> 00007 00008 namespace cv_camera 00009 { 00010 00014 class CvCameraNodelet : public nodelet::Nodelet 00015 { 00016 public: 00017 CvCameraNodelet() : 00018 is_running_(false) 00019 {} 00020 ~CvCameraNodelet() 00021 { 00022 if (is_running_) 00023 { 00024 is_running_ = false; 00025 thread_->join(); 00026 } 00027 } 00028 00029 private: 00033 virtual void onInit() 00034 { 00035 driver_.reset(new Driver(getPrivateNodeHandle(), 00036 getPrivateNodeHandle())); 00037 try 00038 { 00039 driver_->setup(); 00040 is_running_ = true; 00041 thread_ = boost::shared_ptr<boost::thread> 00042 (new boost::thread(boost::bind(&CvCameraNodelet::main, this))); 00043 } 00044 catch(cv_camera::DeviceError& e) 00045 { 00046 NODELET_ERROR_STREAM("failed to open device... do nothing: " << e.what()); 00047 } 00048 } 00049 00053 void main() 00054 { 00055 while (is_running_) 00056 { 00057 driver_->proceed(); 00058 } 00059 } 00060 00064 bool is_running_; 00065 00069 boost::shared_ptr<Driver> driver_; 00070 00074 boost::shared_ptr<boost::thread> thread_; 00075 }; 00076 00077 } // end namespace cv_camera 00078 00079 #include <pluginlib/class_list_macros.h> 00080 PLUGINLIB_DECLARE_CLASS(cv_camera, CvCameraNodelet, cv_camera::CvCameraNodelet, nodelet::Nodelet);