diff --git a/src/device.cpp b/src/device.cpp index 99e3ee47419..dc7bdf33377 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -31,52 +31,14 @@ librealsense::find_profile( rs2_stream stream, int index, std::vector< stream_in } -device::device( std::shared_ptr< const device_info > const & dev_info, - bool device_changed_notifications ) +device::device( std::shared_ptr< const device_info > const & dev_info ) : _dev_info( dev_info ) - , _is_valid( true ) - , _is_alive( std::make_shared< bool >( true ) ) , _profiles_tags( [this]() { return get_profiles_tags(); } ) { - if( device_changed_notifications ) - { - std::weak_ptr< bool > weak = _is_alive; - auto cb = new devices_changed_callback_internal([this, weak](rs2_device_list* removed, rs2_device_list* added) - { - // The callback can be called from one thread while the object is being destroyed by another. - // Check if members can still be accessed. - auto alive = weak.lock(); - if( ! alive || ! *alive ) - return; - - // Update is_valid variable when device is invalid - std::lock_guard lock(_device_changed_mtx); - for (auto& dev_info : removed->list) - { - if( dev_info.info->is_same_as( _dev_info ) ) - { - _is_valid = false; - return; - } - } - }); - - _device_changed_callback_id - = get_context()->register_internal_device_callback( { cb, - []( rs2_devices_changed_callback * p ) - { - p->release(); - } } ); - } } device::~device() { - *_is_alive = false; - - if( _device_changed_callback_id ) - get_context()->unregister_internal_device_callback( _device_changed_callback_id ); - _sensors.clear(); } diff --git a/src/device.h b/src/device.h index c2f538d22d2..9415e0ace70 100644 --- a/src/device.h +++ b/src/device.h @@ -54,8 +54,7 @@ class device bool is_valid() const override { - std::lock_guard lock(_device_changed_mtx); - return _is_valid; + return _dev_info->is_alive(); } void tag_profiles(stream_profiles profiles) const override; @@ -66,8 +65,6 @@ class device virtual void stop_activity() const; - bool device_changed_notifications_on() const { return _device_changed_callback_id; } - format_conversion get_format_conversion() const; protected: @@ -76,19 +73,15 @@ class device void register_stream_to_extrinsic_group(const stream_interface& stream, uint32_t groupd_index); std::vector map_supported_color_formats(rs2_format source_format); - explicit device( std::shared_ptr< const device_info > const &, bool device_changed_notifications = true ); + explicit device( std::shared_ptr< const device_info > const & ); std::map>> _extrinsics; private: std::vector> _sensors; std::shared_ptr< const device_info > _dev_info; - bool _is_valid; mutable std::mutex _device_changed_mtx; - uint64_t _device_changed_callback_id = 0; rsutils::lazy< std::vector< tagged_profile > > _profiles_tags; - - std::shared_ptr< bool > _is_alive; // Ensures object can be accessed }; diff --git a/src/ds/d400/d400-factory.cpp b/src/ds/d400/d400-factory.cpp index e2c4227a141..272e07a52fa 100644 --- a/src/ds/d400/d400-factory.cpp +++ b/src/ds/d400/d400-factory.cpp @@ -41,9 +41,9 @@ namespace librealsense public firmware_logger_device { public: - rs400_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs400_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_nonmonochrome( dev_info ) , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) @@ -80,9 +80,9 @@ namespace librealsense public firmware_logger_device { public: - rs405u_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device(dev_info, register_device_notifications), - ds_device( dev_info, register_device_notifications ), + rs405u_device( std::shared_ptr< const d400_info > const & dev_info ) + : device(dev_info), + ds_device( dev_info ), ds5u_device(dev_info), ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), firmware_logger_device(dev_info, d400_device::_hw_monitor, @@ -131,9 +131,9 @@ namespace librealsense public firmware_logger_device { public: - rs410_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs410_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_nonmonochrome( dev_info ) , d400_active( dev_info ) @@ -170,9 +170,9 @@ namespace librealsense public firmware_logger_device { public: - rs415_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs415_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_nonmonochrome( dev_info ) , d400_active( dev_info ) @@ -211,9 +211,9 @@ namespace librealsense public firmware_logger_device { public: - rs416_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs416_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_nonmonochrome( dev_info ) , d400_active( dev_info ) @@ -265,9 +265,9 @@ namespace librealsense { public: - rs416_rgb_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs416_rgb_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_nonmonochrome( dev_info ) , d400_active( dev_info ) @@ -319,9 +319,9 @@ namespace librealsense public firmware_logger_device { public: - rs420_mm_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs420_mm_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_motion( dev_info ) , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) @@ -367,9 +367,9 @@ namespace librealsense public firmware_logger_device { public: - rs420_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs420_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) , firmware_logger_device( @@ -405,9 +405,9 @@ namespace librealsense public firmware_logger_device { public: - rs430_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs430_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_active( dev_info ) , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) @@ -444,9 +444,9 @@ namespace librealsense public firmware_logger_device { public: - rs430i_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs430i_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_active( dev_info ) , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) @@ -488,9 +488,9 @@ namespace librealsense public firmware_logger_device { public: - rs430_mm_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs430_mm_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_active( dev_info ) , d400_motion( dev_info ) @@ -539,9 +539,9 @@ namespace librealsense public firmware_logger_device { public: - rs435_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs435_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_active( dev_info ) , d400_color( dev_info ) @@ -581,9 +581,9 @@ namespace librealsense public firmware_logger_device { public: - rs457_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs457_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_active( dev_info ) , d400_color( dev_info ) @@ -615,9 +615,9 @@ namespace librealsense public firmware_logger_device { public: - rs430_rgb_mm_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs430_rgb_mm_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_active( dev_info ) , d400_color( dev_info ) @@ -658,9 +658,9 @@ namespace librealsense public firmware_logger_device { public: - rs435i_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs435i_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_active( dev_info ) , d400_color( dev_info ) @@ -876,9 +876,9 @@ namespace librealsense public firmware_logger_device { public: - rs465_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs465_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_active( dev_info ) , d400_color( dev_info ) @@ -917,9 +917,9 @@ namespace librealsense public firmware_logger_device { public: - rs400_imu_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs400_imu_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_motion( dev_info ) , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) @@ -947,9 +947,9 @@ namespace librealsense public firmware_logger_device { public: - rs405_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs405_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_color( dev_info ) , d400_nonmonochrome( dev_info ) @@ -1034,9 +1034,9 @@ namespace librealsense public d400_thermal_tracking { public: - rs455_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) - : device( dev_info, register_device_notifications ) - , ds_device( dev_info, register_device_notifications ) + rs455_device( std::shared_ptr< const d400_info > const & dev_info ) + : device( dev_info ) + , ds_device( dev_info ) , d400_device( dev_info ) , d400_nonmonochrome( dev_info ) , d400_active( dev_info ) @@ -1085,52 +1085,51 @@ namespace librealsense throw std::runtime_error("Depth Camera not found!"); auto const dev_info = std::dynamic_pointer_cast< const d400_info >( shared_from_this() ); - bool const register_device_notifications = true; auto pid = _group.uvc_devices.front().pid; switch(pid) { case RS400_PID: - return std::make_shared< rs400_device >( dev_info, register_device_notifications ); + return std::make_shared< rs400_device >( dev_info ); case RS405U_PID: - return std::make_shared< rs405u_device >( dev_info, register_device_notifications ); + return std::make_shared< rs405u_device >( dev_info ); case RS410_PID: case RS460_PID: - return std::make_shared< rs410_device >( dev_info, register_device_notifications ); + return std::make_shared< rs410_device >( dev_info ); case RS415_PID: - return std::make_shared< rs415_device >( dev_info, register_device_notifications ); + return std::make_shared< rs415_device >( dev_info ); case RS416_PID: - return std::make_shared< rs416_device >( dev_info, register_device_notifications ); + return std::make_shared< rs416_device >( dev_info ); case RS416_RGB_PID: - return std::make_shared< rs416_rgb_device >( dev_info, register_device_notifications ); + return std::make_shared< rs416_rgb_device >( dev_info ); case RS420_PID: - return std::make_shared< rs420_device >( dev_info, register_device_notifications ); + return std::make_shared< rs420_device >( dev_info ); case RS420_MM_PID: - return std::make_shared< rs420_mm_device >( dev_info, register_device_notifications ); + return std::make_shared< rs420_mm_device >( dev_info ); case RS430_PID: - return std::make_shared< rs430_device >( dev_info, register_device_notifications ); + return std::make_shared< rs430_device >( dev_info ); case RS430I_PID: - return std::make_shared< rs430i_device >( dev_info, register_device_notifications ); + return std::make_shared< rs430i_device >( dev_info ); case RS430_MM_PID: - return std::make_shared< rs430_mm_device >( dev_info, register_device_notifications ); + return std::make_shared< rs430_mm_device >( dev_info ); case RS430_MM_RGB_PID: - return std::make_shared< rs430_rgb_mm_device >( dev_info, register_device_notifications ); + return std::make_shared< rs430_rgb_mm_device >( dev_info ); case RS435_RGB_PID: - return std::make_shared< rs435_device >( dev_info, register_device_notifications ); + return std::make_shared< rs435_device >( dev_info ); case RS435I_PID: - return std::make_shared< rs435i_device >( dev_info, register_device_notifications ); + return std::make_shared< rs435i_device >( dev_info ); case RS465_PID: - return std::make_shared< rs465_device >( dev_info, register_device_notifications ); + return std::make_shared< rs465_device >( dev_info ); case RS_USB2_PID: - return std::make_shared< rs410_device >( dev_info, register_device_notifications ); + return std::make_shared< rs410_device >( dev_info ); case RS400_IMU_PID: - return std::make_shared< rs400_imu_device >( dev_info, register_device_notifications ); + return std::make_shared< rs400_imu_device >( dev_info ); case RS405_PID: - return std::make_shared< rs405_device >( dev_info, register_device_notifications ); + return std::make_shared< rs405_device >( dev_info ); case RS455_PID: - return std::make_shared< rs455_device >( dev_info, register_device_notifications ); + return std::make_shared< rs455_device >( dev_info ); case RS457_PID: - return std::make_shared< rs457_device >( dev_info, register_device_notifications ); + return std::make_shared< rs457_device >( dev_info ); default: throw std::runtime_error( rsutils::string::from() << "Unsupported RS400 model! 0x" << std::hex << std::setw( 4 ) << std::setfill( '0' ) << (int)pid ); diff --git a/src/ds/ds-device-common.cpp b/src/ds/ds-device-common.cpp index 333a980b3ff..ba89b4c5109 100644 --- a/src/ds/ds-device-common.cpp +++ b/src/ds/ds-device-common.cpp @@ -92,8 +92,7 @@ namespace librealsense this_thread::sleep_for( milliseconds( DELAY_FOR_RETRIES ) ); } - if (_owner->device_changed_notifications_on()) - LOG_WARNING("Timeout waiting for device disconnect after DFU command!"); + LOG_WARNING("Timeout waiting for device disconnect after DFU command!"); } catch (std::exception& e) { diff --git a/src/ds/ds-device.h b/src/ds/ds-device.h index 3e970e5f473..6e609cacb93 100644 --- a/src/ds/ds-device.h +++ b/src/ds/ds-device.h @@ -16,8 +16,8 @@ class ds_device : public virtual device typedef device super; protected: - ds_device( std::shared_ptr< const device_info > const & dev_info, bool device_changed_notifications = true ) - : super( dev_info, device_changed_notifications ) + ds_device( std::shared_ptr< const device_info > const & dev_info ) + : super( dev_info ) { } diff --git a/src/platform-camera.cpp b/src/platform-camera.cpp index a3c0d26d526..3ed0300bd7a 100644 --- a/src/platform-camera.cpp +++ b/src/platform-camera.cpp @@ -62,9 +62,8 @@ class platform_camera_sensor : public synthetic_sensor platform_camera::platform_camera( std::shared_ptr< const device_info > const & dev_info, - const std::vector< platform::uvc_device_info > & uvc_infos, - bool register_device_notifications ) - : device( dev_info, register_device_notifications ) + const std::vector< platform::uvc_device_info > & uvc_infos ) + : device( dev_info ) { std::vector< std::shared_ptr< platform::uvc_device > > devs; for( auto && info : uvc_infos ) diff --git a/src/platform-camera.h b/src/platform-camera.h index e6ed8e88857..37d8d49e0e7 100644 --- a/src/platform-camera.h +++ b/src/platform-camera.h @@ -14,8 +14,7 @@ class platform_camera : public device { public: platform_camera( std::shared_ptr< const device_info > const & dev_info, - const std::vector< platform::uvc_device_info > & uvc_infos, - bool register_device_notifications ); + const std::vector< platform::uvc_device_info > & uvc_infos ); virtual rs2_intrinsics get_intrinsics( unsigned int, const stream_profile & ) const { return rs2_intrinsics{}; } @@ -34,10 +33,8 @@ class platform_camera_info : public platform::platform_device_info std::shared_ptr< device_interface > create_device() override { - bool const register_device_notifications = true; return std::make_shared< platform_camera >( shared_from_this(), - get_group().uvc_devices, - register_device_notifications ); + get_group().uvc_devices ); } static std::vector< std::shared_ptr< platform_camera_info > > diff --git a/src/software-device.cpp b/src/software-device.cpp index cb68e1ad2b2..29bf5727e88 100644 --- a/src/software-device.cpp +++ b/src/software-device.cpp @@ -17,7 +17,7 @@ using rsutils::deferred; namespace librealsense { software_device::software_device( std::shared_ptr< const device_info > const & dev_info ) - : device( dev_info, false ) + : device( dev_info ) { }