From 25be8d7436dac020b5b10b6bd8a2245f82ff39cc Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 21 Aug 2020 13:07:26 +0200 Subject: [PATCH] Added AddSensor method to Manager Signed-off-by: ahcorde --- include/ignition/sensors/Manager.hh | 7 +++++++ include/ignition/sensors/SensorFactory.hh | 1 - src/Manager.cc | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/ignition/sensors/Manager.hh b/include/ignition/sensors/Manager.hh index 01b8fa50..d5a4bc72 100644 --- a/include/ignition/sensors/Manager.hh +++ b/include/ignition/sensors/Manager.hh @@ -153,6 +153,13 @@ namespace ignition /// is returned on erro. public: ignition::sensors::SensorId CreateSensor(sdf::ElementPtr _sdf); + /// \brief Add a sensor from a sensor instance. + /// \sa Sensor() + /// \param[in] _sensor pointer to the sensor + /// \return A sensor id that refers to the created sensor. NO_SENSOR + /// is returned on error. + public: ignition::sensors::SensorId AddSensor(std::unique_ptr _sensor); + /// \brief Create a sensor from SDF without a known sensor type. /// /// This creates sensors by looking at the given sdf element. diff --git a/include/ignition/sensors/SensorFactory.hh b/include/ignition/sensors/SensorFactory.hh index cb5f234d..be5d6dfc 100644 --- a/include/ignition/sensors/SensorFactory.hh +++ b/include/ignition/sensors/SensorFactory.hh @@ -24,7 +24,6 @@ #include #include -#include #include #include diff --git a/src/Manager.cc b/src/Manager.cc index 4105fb9a..e102de33 100644 --- a/src/Manager.cc +++ b/src/Manager.cc @@ -100,6 +100,16 @@ void Manager::RunOnce(const ignition::common::Time &_time, bool _force) } } +///////////////////////////////////////////////// +ignition::sensors::SensorId Manager::AddSensor(std::unique_ptr _sensor) +{ + if (!_sensor) + return NO_SENSOR; + SensorId id = _sensor->Id(); + this->dataPtr->sensors[id] = std::move(_sensor); + return id; +} + ///////////////////////////////////////////////// ignition::sensors::SensorId Manager::CreateSensor(const sdf::Sensor &_sdf) {