00001 #include "cv_camera/driver.h" 00002 00003 #include <nodelet/nodelet.h> 00004 #include <boost/thread.hpp> 00005 00006 namespace cv_camera 00007 { 00008 00012 class CvCameraNodelet : public nodelet::Nodelet 00013 { 00014 public: 00015 CvCameraNodelet() : 00016 is_running_(false) 00017 { 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 driver_->setup(); 00039 is_running_ = true; 00040 thread_ = boost::shared_ptr<boost::thread> 00041 (new boost::thread(boost::bind(&CvCameraNodelet::main, this))); 00042 } catch(cv_camera::DeviceError& e) { 00043 NODELET_ERROR_STREAM("failed to open device... do nothing: " << e.what()); 00044 } 00045 } 00046 00050 void main() 00051 { 00052 while(is_running_) 00053 { 00054 driver_->proceed(); 00055 } 00056 } 00057 00061 bool is_running_; 00062 00066 boost::shared_ptr<Driver> driver_; 00067 00071 boost::shared_ptr<boost::thread> thread_; 00072 00073 }; 00074 00075 } // end namespace cv_camera 00076 00077 #include <pluginlib/class_list_macros.h> 00078 PLUGINLIB_DECLARE_CLASS(cv_camera, CvCameraNodelet, cv_camera::CvCameraNodelet, nodelet::Nodelet);