Ignition Sensors

API Reference

6.0.1
Manager.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_SENSORS_MANAGER_HH_
18 #define IGNITION_SENSORS_MANAGER_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <utility>
23 #include <type_traits>
24 #include <vector>
25 #include <sdf/sdf.hh>
26 #include <ignition/common/SuppressWarning.hh>
27 #include <ignition/common/Console.hh>
28 #include <ignition/sensors/config.hh>
29 #include <ignition/sensors/Export.hh>
32 
33 namespace ignition
34 {
35  namespace sensors
36  {
37  // Inline bracket to help doxygen filtering.
38  inline namespace IGNITION_SENSORS_VERSION_NAMESPACE {
39  // Forward declarations
40  class ManagerPrivate;
41 
53  class IGNITION_SENSORS_VISIBLE Manager
54  {
56  public: Manager();
57 
59  public: virtual ~Manager();
60 
63  public: bool Init();
64 
73  public: template<typename SensorType, typename SdfType>
74  SensorType *CreateSensor(SdfType _sdf)
75  {
76  SensorFactory sensorFactory;
77  auto sensor = sensorFactory.CreateSensor<SensorType>(_sdf);
78  if (nullptr == sensor)
79  {
80  ignerr << "Failed to create sensor." << std::endl;
81  return nullptr;
82  }
83  auto result = sensor.get();
84  if (NO_SENSOR == this->AddSensor(std::move(sensor)))
85  {
86  ignerr << "Failed to add sensor." << std::endl;
87  return nullptr;
88  }
89  return result;
90  }
91 
100  public: ignition::sensors::SensorId IGN_DEPRECATED(6) CreateSensor(
101  sdf::ElementPtr _sdf);
102 
111  public: ignition::sensors::SensorId IGN_DEPRECATED(6) CreateSensor(
112  const sdf::Sensor &_sdf);
113 
119  public: SensorId AddSensor(std::unique_ptr<Sensor> _sensor);
120 
126 
130  public: bool Remove(const ignition::sensors::SensorId _id);
131 
136  public: void RunOnce(const std::chrono::steady_clock::duration &_time,
137  bool _force = false);
138 
140  public: void IGN_DEPRECATED(6) AddPluginPaths(const std::string &_path);
141 
142  IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
144  private: std::unique_ptr<ManagerPrivate> dataPtr;
145  IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
146  };
147  }
148  }
149 }
150 
151 #endif
SensorType * CreateSensor(SdfType _sdf)
Create a sensor from an SDF ovject with a known sensor type.
Definition: Manager.hh:74
T endl(T... args)
A factory class for creating sensors This class instantiates sensor objects based on the sensor type ...
Definition: SensorFactory.hh:72
a base sensor class
Definition: Sensor.hh:59
STL class.
Loads and runs sensors.
Definition: Manager.hh:53
std::unique_ptr< SensorType > CreateSensor(const sdf::Sensor &_sdf)
Create a sensor from a SDF DOM object with a known sensor type.
Definition: SensorFactory.hh:86
const SensorId NO_SENSOR
Definition: Sensor.hh:49
T move(T... args)
STL class.
Definition: AirPressureSensor.hh:31