SensorManager.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 /*
00018  * Desc: Class to manager all sensors
00019  * Author: Nate Koenig
00020  * Date: 18 Dec 2009
00021  */
00022 
00023 #ifndef SENSORMANAGER_HH
00024 #define SENSORMANAGER_HH
00025 
00026 #include <list>
00027 #include <boost/thread.hpp>
00028 
00029 #include "common/SingletonT.hh"
00030 #include "sensors/SensorTypes.hh"
00031 #include "sdf/sdf.h"
00032 
00033 namespace gazebo
00034 {
00035   namespace sensors
00036   {
00039  
00041     class SensorManager : public SingletonT<SensorManager>
00042     {
00044       public: SensorManager();
00045 
00047       public: virtual ~SensorManager();
00048 
00050       public: void Update(bool force=false);
00051 
00053       public: void Init();
00054 
00056       public: void Run();
00057 
00059       public: void Stop();
00060 
00062       public: void Fini();
00063 
00065       public: std::string LoadSensor(sdf::ElementPtr _elem,
00066                                      const std::string &_parentName);
00067 
00069       public: SensorPtr GetSensor(const std::string &_name);
00070 
00072       public: void RemoveSensor(const std::string &_name);
00073 
00075       public: void RemoveSensors();
00076 
00078       private: void RunLoop();
00079 
00080       private: bool stop;
00081       private: bool initialized;
00082       private: boost::thread *runThread;
00083       private: boost::recursive_mutex *mutex;
00084 
00085       private: std::list<SensorPtr > sensors;
00086 
00087       private: friend class SingletonT<SensorManager>;
00088 
00089       private: std::list<SensorPtr > initSensors;
00090     };
00092   }
00093 }
00094 #endif