diff --git a/src/core/options-container.cpp b/src/core/options-container.cpp index 3058e15810..f38ece59d1 100644 --- a/src/core/options-container.cpp +++ b/src/core/options-container.cpp @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2023 Intel Corporation. All Rights Reserved. +// Copyright(c) 2023-4 Intel Corporation. All Rights Reserved. #include "options-container.h" #include "enum-helpers.h" @@ -12,8 +12,8 @@ namespace librealsense { const option & options_container::get_option( rs2_option id ) const { - auto it = _options.find( id ); - if( it == _options.end() ) + auto it = _options_by_id.find( id ); + if( it == _options_by_id.end() ) { throw invalid_value_exception( rsutils::string::from() << "option '" << get_option_name( id ) << "' not supported" ); @@ -27,17 +27,47 @@ void options_container::update( std::shared_ptr< extension_snapshot > ext ) auto ctr = As< options_container >( ext ); if( ! ctr ) return; - for( auto && opt : ctr->_options ) + for( auto id : ctr->_ordered_options ) { - _options[opt.first] = opt.second; + auto & opt = _options_by_id[id]; + if( ! opt ) + _ordered_options.push_back( id ); + opt = ctr->_options_by_id[id]; } } +void options_container::register_option( rs2_option id, std::shared_ptr< option > option ) +{ + auto & opt = _options_by_id[id]; + if( ! opt ) + _ordered_options.push_back( id ); + opt = option; + _recording_function( *this ); +} + + +void options_container::unregister_option( rs2_option id ) +{ + for( auto it = _ordered_options.begin(); it != _ordered_options.end(); ++it ) + { + if( *it == id ) + { + _ordered_options.erase( it ); + break; + } + } + _options_by_id.erase( id ); +} + + std::vector< rs2_option > options_container::get_supported_options() const { + // Return options ordered by their ID values! This means custom options will be first! + // Kept for backwards compatibility with existing devices; software sensors will return the _ordered_options + std::vector< rs2_option > options; - for( auto option : _options ) + for( auto option : _options_by_id ) options.push_back( option.first ); return options; diff --git a/src/core/options-container.h b/src/core/options-container.h index fb7f7e8f2f..8ddd80ec85 100644 --- a/src/core/options-container.h +++ b/src/core/options-container.h @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2015 Intel Corporation. All Rights Reserved. +// Copyright(c) 2015-24 Intel Corporation. All Rights Reserved. #pragma once #include "options-interface.h" @@ -24,8 +24,9 @@ class LRS_EXTENSION_API options_container : public virtual options_interface, pu public: bool supports_option(rs2_option id) const override { - auto it = _options.find(id); - if (it == _options.end()) return false; + auto it = _options_by_id.find( id ); + if( it == _options_by_id.end() ) + return false; return it->second->is_enabled(); } @@ -41,22 +42,16 @@ class LRS_EXTENSION_API options_container : public virtual options_interface, pu return (const_cast(this)->get_option_handler(id)); } - std::shared_ptr