From ed3f507e272296723ec5d24b84d9a8eb1f2d6f22 Mon Sep 17 00:00:00 2001 From: Tamir Date: Mon, 4 Dec 2023 11:40:11 +0200 Subject: [PATCH 1/3] shared_ptr added --- src/ds/d400/d400-device.cpp | 6 ++++-- src/ds/ds-active-common.cpp | 2 +- src/ds/ds-options.cpp | 26 ++++++++++++++++++++------ src/ds/ds-options.h | 4 ++-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/ds/d400/d400-device.cpp b/src/ds/d400/d400-device.cpp index 4a6f1b2f63..dd8c5b9c95 100644 --- a/src/ds/d400/d400-device.cpp +++ b/src/ds/d400/d400-device.cpp @@ -584,6 +584,8 @@ namespace librealsense auto& depth_sensor = get_depth_sensor(); auto& raw_depth_sensor = get_raw_depth_sensor(); + //_raw_depth_sensor2 = dynamic_cast<>.get_raw_sensor(); + using namespace platform; // minimal firmware version in which hdr feature is supported @@ -681,7 +683,7 @@ namespace librealsense "Generate trigger from the camera to external device once per frame")); depth_sensor.register_option(RS2_OPTION_ASIC_TEMPERATURE, - std::make_shared(raw_depth_sensor, + std::make_shared(std::make_shared(raw_depth_sensor), RS2_OPTION_ASIC_TEMPERATURE)); // D457 dev - get_xu fails for D457 - error polling id not defined @@ -1298,7 +1300,7 @@ namespace librealsense std::vector{0.f, 2.f}, 1.f)); depth_ep.register_option(RS2_OPTION_PROJECTOR_TEMPERATURE, - std::make_shared(depth_ep, + std::make_shared(std::make_shared(depth_ep), RS2_OPTION_PROJECTOR_TEMPERATURE)); } } diff --git a/src/ds/ds-active-common.cpp b/src/ds/ds-active-common.cpp index 94a6707942..d9828bdace 100644 --- a/src/ds/ds-active-common.cpp +++ b/src/ds/ds-active-common.cpp @@ -73,7 +73,7 @@ namespace librealsense else { _depth_ep.register_option(RS2_OPTION_PROJECTOR_TEMPERATURE, - std::make_shared(_raw_depth_ep, + std::make_shared(std::make_shared(_raw_depth_ep), RS2_OPTION_PROJECTOR_TEMPERATURE)); } } diff --git a/src/ds/ds-options.cpp b/src/ds/ds-options.cpp index d70ef6c354..4472798d1b 100644 --- a/src/ds/ds-options.cpp +++ b/src/ds/ds-options.cpp @@ -4,6 +4,8 @@ #include "ds-options.h" #include +#include + namespace librealsense @@ -53,7 +55,11 @@ namespace librealsense }; #pragma pack(pop) - auto temperature_data = static_cast(_ep.invoke_powered( + auto strong_ep = _ep.lock(); + if (!strong_ep) + throw invalid_value_exception(rsutils::string::from() << "EP is not exists"); + + auto temperature_data = static_cast(strong_ep->invoke_powered( [this](platform::uvc_device& dev) { temperature temp{}; @@ -82,11 +88,11 @@ namespace librealsense is_valid_field = &temperature::is_projector_valid; break; default: - throw invalid_value_exception(rsutils::string::from() << _ep.get_option_name(_option) << " is not temperature option!"); + throw invalid_value_exception(rsutils::string::from() << strong_ep->get_option_name(_option) << " is not temperature option!"); } if (0 == temperature_data.*is_valid_field) - LOG_ERROR(_ep.get_option_name(_option) << " value is not valid!"); + LOG_ERROR(strong_ep->get_option_name(_option) << " value is not valid!"); return temperature_data.*field; } @@ -98,11 +104,19 @@ namespace librealsense bool asic_and_projector_temperature_options::is_enabled() const { - return _ep.is_streaming(); + auto strong_ep = _ep.lock(); + if (!strong_ep) + throw invalid_value_exception(rsutils::string::from() << "Can not retriev temperature as no valid EP"); + + return strong_ep->is_streaming(); } const char* asic_and_projector_temperature_options::get_description() const { + auto strong_ep = _ep.lock(); + if (! strong_ep) + throw invalid_value_exception(rsutils::string::from() << "EP is not exists"); + switch (_option) { case RS2_OPTION_ASIC_TEMPERATURE: @@ -110,11 +124,11 @@ namespace librealsense case RS2_OPTION_PROJECTOR_TEMPERATURE: return "Current Projector Temperature (degree celsius)"; default: - throw invalid_value_exception(rsutils::string::from() << _ep.get_option_name(_option) << " is not temperature option!"); + throw invalid_value_exception(rsutils::string::from() << strong_ep->get_option_name(_option) << " is not temperature option!"); } } - asic_and_projector_temperature_options::asic_and_projector_temperature_options(uvc_sensor& ep, rs2_option opt) + asic_and_projector_temperature_options::asic_and_projector_temperature_options(std::shared_ptr ep, rs2_option opt) : _option(opt), _ep(ep) {} diff --git a/src/ds/ds-options.h b/src/ds/ds-options.h index f09591203f..9c10ac4988 100644 --- a/src/ds/ds-options.h +++ b/src/ds/ds-options.h @@ -31,10 +31,10 @@ namespace librealsense const char* get_description() const override; - explicit asic_and_projector_temperature_options(uvc_sensor& ep, rs2_option opt); + explicit asic_and_projector_temperature_options(std::shared_ptr ep, rs2_option opt); private: - uvc_sensor& _ep; + std::weak_ptr _ep; rs2_option _option; }; From 88c0fbd1f157ef46b9dcb455a88601eda2a3dc7d Mon Sep 17 00:00:00 2001 From: Tamir Date: Mon, 4 Dec 2023 14:22:05 +0200 Subject: [PATCH 2/3] dynamic pointer cast added --- src/ds/d400/d400-device.cpp | 4 ++-- src/ds/ds-active-common.cpp | 2 +- src/ds/ds-options.cpp | 4 ++-- src/ds/ds-options.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ds/d400/d400-device.cpp b/src/ds/d400/d400-device.cpp index dd8c5b9c95..c7a4a89b1e 100644 --- a/src/ds/d400/d400-device.cpp +++ b/src/ds/d400/d400-device.cpp @@ -683,7 +683,7 @@ namespace librealsense "Generate trigger from the camera to external device once per frame")); depth_sensor.register_option(RS2_OPTION_ASIC_TEMPERATURE, - std::make_shared(std::make_shared(raw_depth_sensor), + std::make_shared(std::dynamic_pointer_cast(raw_depth_sensor.shared_from_this()), RS2_OPTION_ASIC_TEMPERATURE)); // D457 dev - get_xu fails for D457 - error polling id not defined @@ -1300,7 +1300,7 @@ namespace librealsense std::vector{0.f, 2.f}, 1.f)); depth_ep.register_option(RS2_OPTION_PROJECTOR_TEMPERATURE, - std::make_shared(std::make_shared(depth_ep), + std::make_shared(std::dynamic_pointer_cast(depth_ep.shared_from_this()), RS2_OPTION_PROJECTOR_TEMPERATURE)); } } diff --git a/src/ds/ds-active-common.cpp b/src/ds/ds-active-common.cpp index d9828bdace..6fbef2747d 100644 --- a/src/ds/ds-active-common.cpp +++ b/src/ds/ds-active-common.cpp @@ -73,7 +73,7 @@ namespace librealsense else { _depth_ep.register_option(RS2_OPTION_PROJECTOR_TEMPERATURE, - std::make_shared(std::make_shared(_raw_depth_ep), + std::make_shared(std::dynamic_pointer_cast(_raw_depth_ep.shared_from_this()), RS2_OPTION_PROJECTOR_TEMPERATURE)); } } diff --git a/src/ds/ds-options.cpp b/src/ds/ds-options.cpp index 4472798d1b..3c379f95cf 100644 --- a/src/ds/ds-options.cpp +++ b/src/ds/ds-options.cpp @@ -128,8 +128,8 @@ namespace librealsense } } - asic_and_projector_temperature_options::asic_and_projector_temperature_options(std::shared_ptr ep, rs2_option opt) - : _option(opt), _ep(ep) + asic_and_projector_temperature_options::asic_and_projector_temperature_options(std::shared_ptr && ep, rs2_option opt) + : _option(opt), _ep(std::move(ep)) {} float motion_module_temperature_option::query() const diff --git a/src/ds/ds-options.h b/src/ds/ds-options.h index 9c10ac4988..b599cba1ec 100644 --- a/src/ds/ds-options.h +++ b/src/ds/ds-options.h @@ -31,7 +31,7 @@ namespace librealsense const char* get_description() const override; - explicit asic_and_projector_temperature_options(std::shared_ptr ep, rs2_option opt); + explicit asic_and_projector_temperature_options(std::shared_ptr && ep, rs2_option opt); private: std::weak_ptr _ep; From 6f3169ebe9b67618eaa28a9bae3586623eeb1ae5 Mon Sep 17 00:00:00 2001 From: Tamir Date: Thu, 7 Dec 2023 10:18:58 +0200 Subject: [PATCH 3/3] Small fixes Checking dynamic casts Exception type changed --- src/ds/d400/d400-device.cpp | 14 ++++++++++---- src/ds/ds-active-common.cpp | 6 +++++- src/ds/ds-options.cpp | 6 +++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/ds/d400/d400-device.cpp b/src/ds/d400/d400-device.cpp index c7a4a89b1e..3ed6f3fc5b 100644 --- a/src/ds/d400/d400-device.cpp +++ b/src/ds/d400/d400-device.cpp @@ -584,8 +584,6 @@ namespace librealsense auto& depth_sensor = get_depth_sensor(); auto& raw_depth_sensor = get_raw_depth_sensor(); - //_raw_depth_sensor2 = dynamic_cast<>.get_raw_sensor(); - using namespace platform; // minimal firmware version in which hdr feature is supported @@ -682,8 +680,12 @@ namespace librealsense std::make_shared>(raw_depth_sensor, depth_xu, DS5_EXT_TRIGGER, "Generate trigger from the camera to external device once per frame")); + auto uvc_s = std::dynamic_pointer_cast(raw_depth_sensor.shared_from_this()); + if (!uvc_s) + throw std::runtime_error("Sensor base is not uvc sensor"); + depth_sensor.register_option(RS2_OPTION_ASIC_TEMPERATURE, - std::make_shared(std::dynamic_pointer_cast(raw_depth_sensor.shared_from_this()), + std::make_shared(std::move(uvc_s), RS2_OPTION_ASIC_TEMPERATURE)); // D457 dev - get_xu fails for D457 - error polling id not defined @@ -1299,8 +1301,12 @@ namespace librealsense emitter_enabled, std::vector{0.f, 2.f}, 1.f)); + auto uvc_s = std::dynamic_pointer_cast(depth_ep.shared_from_this()); + if (!uvc_s) + throw std::runtime_error("Sensor base is not uvc sensor"); + depth_ep.register_option(RS2_OPTION_PROJECTOR_TEMPERATURE, - std::make_shared(std::dynamic_pointer_cast(depth_ep.shared_from_this()), + std::make_shared(std::move(uvc_s), RS2_OPTION_PROJECTOR_TEMPERATURE)); } } diff --git a/src/ds/ds-active-common.cpp b/src/ds/ds-active-common.cpp index 6fbef2747d..26517e1485 100644 --- a/src/ds/ds-active-common.cpp +++ b/src/ds/ds-active-common.cpp @@ -72,8 +72,12 @@ namespace librealsense } else { + auto uvc_s = std::dynamic_pointer_cast(_raw_depth_ep.shared_from_this()); + if (!uvc_s) + throw std::runtime_error("Sensor base is not uvc sensor"); + _depth_ep.register_option(RS2_OPTION_PROJECTOR_TEMPERATURE, - std::make_shared(std::dynamic_pointer_cast(_raw_depth_ep.shared_from_this()), + std::make_shared(std::move(uvc_s), RS2_OPTION_PROJECTOR_TEMPERATURE)); } } diff --git a/src/ds/ds-options.cpp b/src/ds/ds-options.cpp index 3c379f95cf..39f0c6056c 100644 --- a/src/ds/ds-options.cpp +++ b/src/ds/ds-options.cpp @@ -57,7 +57,7 @@ namespace librealsense auto strong_ep = _ep.lock(); if (!strong_ep) - throw invalid_value_exception(rsutils::string::from() << "EP is not exists"); + throw camera_disconnected_exception("asic and proj temperatures cannot access the sensor"); auto temperature_data = static_cast(strong_ep->invoke_powered( [this](platform::uvc_device& dev) @@ -106,7 +106,7 @@ namespace librealsense { auto strong_ep = _ep.lock(); if (!strong_ep) - throw invalid_value_exception(rsutils::string::from() << "Can not retriev temperature as no valid EP"); + throw camera_disconnected_exception("asic and proj temperatures cannot access the sensor"); return strong_ep->is_streaming(); } @@ -115,7 +115,7 @@ namespace librealsense { auto strong_ep = _ep.lock(); if (! strong_ep) - throw invalid_value_exception(rsutils::string::from() << "EP is not exists"); + throw camera_disconnected_exception("asic and proj temperatures cannot access the sensor"); switch (_option) {