From addf90283196e8156873695c477a3626cdd6d98c Mon Sep 17 00:00:00 2001 From: Joao Figueiredo Date: Tue, 10 Sep 2024 08:32:16 +0000 Subject: [PATCH] Remove receivers and senders demo --- cpp/demos/ossrf-nmos-api/main.cpp | 17 ++++++++++++-- .../lib/include/ossrf/nmos/api/nmos_client.h | 4 ++++ .../ossrf_nmos_api/lib/src/nmos_client.cpp | 22 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/cpp/demos/ossrf-nmos-api/main.cpp b/cpp/demos/ossrf-nmos-api/main.cpp index fee6649..137c915 100644 --- a/cpp/demos/ossrf-nmos-api/main.cpp +++ b/cpp/demos/ossrf-nmos-api/main.cpp @@ -51,6 +51,7 @@ namespace ossrf::gst::plugins::gst_sender_plugin_uptr gst_sender_uptr_2 = nullptr; ossrf::gst::plugins::gst_receiver_plugin_uptr gst_receiver_uptr = nullptr; + std::string receiver_info_config; auto receivers_it = app_configuration.find("receivers"); if(receivers_it != app_configuration.end()) { @@ -74,9 +75,10 @@ namespace }; BST_CHECK(nmos_client->add_receiver(device_id, (*it).dump(), receiver_activation_callback)); + receiver_info_config = (*it).dump(); } } - + std::string sender_info_config; auto senders_it = app_configuration.find("senders"); if(senders_it != app_configuration.end()) { @@ -87,6 +89,7 @@ namespace if(i == 1) { BST_CHECK_ASSIGN(gst_sender_uptr, ossrf::gst::plugins::create_gst_sender_plugin((*it).dump(), 25)); + sender_info_config = (*it).dump(); } else if(i == 2) { @@ -97,10 +100,20 @@ namespace } } - fmt::print("\n >>> Press a key to stop <<< \n"); + fmt::print("\n >>> Press a key to stop sender <<< \n"); char c; std::cin >> c; + BST_CHECK(nmos_client->remove_sender(device_id, sender_info_config)); + + fmt::print("\n >>> Press a key to stop receiver<<< \n"); + std::cin >> c; + + BST_CHECK(nmos_client->remove_receiver(device_id, receiver_info_config)); + + fmt::print("\n >>> Press a key to stop <<< \n"); + std::cin >> c; + BST_CHECK(nmos_client->remove_resource(device_id, nmos::types::device)); fmt::print("\n >>> Stopped <<< \n"); diff --git a/cpp/libs/ossrf_nmos_api/lib/include/ossrf/nmos/api/nmos_client.h b/cpp/libs/ossrf_nmos_api/lib/include/ossrf/nmos/api/nmos_client.h index 37c2e8e..7e7fecf 100644 --- a/cpp/libs/ossrf_nmos_api/lib/include/ossrf/nmos/api/nmos_client.h +++ b/cpp/libs/ossrf_nmos_api/lib/include/ossrf/nmos/api/nmos_client.h @@ -39,6 +39,10 @@ namespace ossrf bisect::maybe_ok add_sender(const std::string& device_id, const std::string& config, bisect::nmoscpp::sender_activation_callback_t callback) noexcept; + bisect::maybe_ok remove_receiver(const std::string& device_id, const std::string& config) noexcept; + + bisect::maybe_ok remove_sender(const std::string& device_id, const std::string& config) noexcept; + bisect::maybe_ok remove_resource(const std::string& id, const nmos::type& type) noexcept; private: diff --git a/cpp/libs/ossrf_nmos_api/lib/src/nmos_client.cpp b/cpp/libs/ossrf_nmos_api/lib/src/nmos_client.cpp index 3bf9fe4..bf60fde 100644 --- a/cpp/libs/ossrf_nmos_api/lib/src/nmos_client.cpp +++ b/cpp/libs/ossrf_nmos_api/lib/src/nmos_client.cpp @@ -107,6 +107,28 @@ maybe_ok nmos_client_t::add_sender(const std::string& device_id, const std::stri return {}; } +maybe_ok nmos_client_t::remove_receiver(const std::string& device_id, const std::string& config) noexcept +{ + BST_ASSIGN_MUT(receiver_config, nmos_receiver_from_json(json::parse(config))); + + BST_CHECK(remove_resource(receiver_config.id, nmos::types::receiver)); + BST_CHECK(update_device_sub_resources(impl_->context_, device_id)); + + return {}; +} + +maybe_ok nmos_client_t::remove_sender(const std::string& device_id, const std::string& config) noexcept +{ + BST_ASSIGN_MUT(sender_config, nmos_sender_from_json(json::parse(config))); + + BST_CHECK(remove_resource(sender_config.id, nmos::types::sender)); + BST_CHECK(remove_resource(sender_config.source.id, nmos::types::source)); + BST_CHECK(remove_resource(sender_config.flow.id, nmos::types::flow)); + BST_CHECK(update_device_sub_resources(impl_->context_, device_id)); + + return {}; +} + maybe_ok nmos_client_t::remove_resource(const std::string& id, const nmos::type& type) noexcept { BST_CHECK(impl_->context_->nmos().remove_resource(id, type));