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 eb7e47c commit 1ae51b4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 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
36 changes: 0 additions & 36 deletions cpp/libs/ossrf_nmos_api/lib/src/context/resource_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,39 +104,3 @@ std::vector<std::string> resource_map_t::get_receiver_ids() const

return ids;
}

std::vector<std::string> resource_map_t::get_sender_ids() const
{
std::vector<std::string> ids;
lock_t lock(mutex_);
for(const auto& [id, resources] : map_)
{
for(const auto& resource : resources)
{
if(resource->get_resource_type() == nmos::types::sender)
{
ids.push_back(id);
}
}
}

return ids;
}

std::vector<std::string> resource_map_t::get_receiver_ids() const
{
std::vector<std::string> ids;
lock_t lock(mutex_);
for(const auto& [id, resources] : map_)
{
for(const auto& resource : resources)
{
if(resource->get_resource_type() == nmos::types::receiver)
{
ids.push_back(id);
}
}
}

return ids;
}
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 1ae51b4

Please sign in to comment.