Skip to content

Commit

Permalink
fix DDS deactivation if no 'dds' key in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Dec 26, 2023
1 parent 3252b30 commit 5710317
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 7 additions & 9 deletions src/dds/rsdds-device-factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,21 @@ static std::mutex domain_context_by_id_mutex;
rsdds_device_factory::rsdds_device_factory( std::shared_ptr< context > const & ctx, callback && cb )
: super( ctx )
{
nlohmann::json const & dds_settings = rsutils::json::nested( ctx->get_settings(), std::string( "dds", 3 ) );
if( dds_settings.is_object() && rsutils::json::get( dds_settings, std::string( "enabled", 7 ), true ) )
rsutils::json::nested dds_settings( ctx->get_settings(), std::string( "dds", 3 ) );
if( dds_settings.is_object() && dds_settings.find( std::string( "enabled", 7 ) ).default_value( true ) )
{
auto domain_id = rsutils::json::get< realdds::dds_domain_id >( dds_settings, std::string( "domain", 6 ), 0 );
std::string participant_name = rsutils::json::get< std::string >( dds_settings,
std::string( "participant", 11 ),
rsutils::os::executable_name() );
auto domain_id = dds_settings.find( std::string( "domain", 6 ) ).default_value< realdds::dds_domain_id >( 0 );
auto participant_name_j = dds_settings.find( std::string( "participant", 11 ) );
auto participant_name = participant_name_j.default_value( rsutils::os::executable_name() );

std::lock_guard< std::mutex > lock( domain_context_by_id_mutex );
auto & domain = domain_context_by_id[domain_id];
_participant = domain.participant.instance();
if( ! _participant->is_valid() )
{
_participant->init( domain_id, participant_name, std::move( dds_settings ) );
_participant->init( domain_id, participant_name, dds_settings.default_object() );
}
else if( rsutils::json::has_value( dds_settings, std::string( "participant", 11 ) )
&& participant_name != _participant->name() )
else if( participant_name_j.exists() && participant_name != _participant->name() )
{
throw std::runtime_error( rsutils::string::from()
<< "A DDS participant '" << _participant->name() << "' already exists in domain "
Expand Down
9 changes: 6 additions & 3 deletions third-party/realdds/src/dds-participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,12 @@ void dds_participant::init( dds_domain_id domain_id, std::string const & partici
"failed creating participant " + participant_name + " on domain id " + std::to_string( domain_id ) );
}

if( ! settings.is_object() )
DDS_THROW( runtime_error, "provided settings are invalid" );
_settings = settings;
if( settings.is_object() )
_settings = settings;
else if( settings.is_null() )
_settings = nlohmann::json::object();
else
DDS_THROW( runtime_error, "provided settings are invalid: " << settings );

LOG_DEBUG( "participant '" << participant_name << "' (" << realdds::print_guid( guid() ) << ") is up on domain "
<< domain_id << " with settings: " << _settings.dump( 4 ) );
Expand Down

0 comments on commit 5710317

Please sign in to comment.