Skip to content

Commit

Permalink
Remove receivers and senders demo
Browse files Browse the repository at this point in the history
  • Loading branch information
joaofigueiredobisect committed Sep 10, 2024
1 parent 1bfba3a commit addf902
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cpp/demos/ossrf-nmos-api/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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())
{
Expand All @@ -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)
{
Expand All @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions cpp/libs/ossrf_nmos_api/lib/src/nmos_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit addf902

Please sign in to comment.