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() : is_running_(false) 00018 { 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>(new boost::thread(boost::bind(&CvCameraNodelet::main, this))); 00042 } 00043 catch (cv_camera::DeviceError &e) 00044 { 00045 NODELET_ERROR_STREAM("failed to open device... do nothing: " << e.what()); 00046 } 00047 } 00048 00052 void main() 00053 { 00054 while (is_running_) 00055 { 00056 driver_->proceed(); 00057 } 00058 } 00059 00063 bool is_running_; 00064 00068 boost::shared_ptr<Driver> driver_; 00069 00073 boost::shared_ptr<boost::thread> thread_; 00074 }; 00075 00076 } // end namespace cv_camera 00077 00078 #include <pluginlib/class_list_macros.h> 00079 PLUGINLIB_EXPORT_CLASS(cv_camera::CvCameraNodelet, nodelet::Nodelet)