From 2c8a94bd355d6a6a828f2885b393a748c77408f4 Mon Sep 17 00:00:00 2001 From: N-Nagorny Date: Wed, 6 Jul 2022 14:15:43 +0300 Subject: [PATCH] Make Sender validator of streamcompatibility_behaviour_thread customizable --- .../nmos-cpp-node/node_implementation.cpp | 9 +++++++- Development/nmos/node_server.cpp | 3 ++- Development/nmos/node_server.h | 3 +++ .../nmos/streamcompatibility_behaviour.cpp | 7 +++++-- .../nmos/streamcompatibility_behaviour.h | 21 ++++++++++++++++++- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Development/nmos-cpp-node/node_implementation.cpp b/Development/nmos-cpp-node/node_implementation.cpp index a46276ed0..2a29db3d2 100644 --- a/Development/nmos-cpp-node/node_implementation.cpp +++ b/Development/nmos-cpp-node/node_implementation.cpp @@ -1338,6 +1338,12 @@ nmos::experimental::details::streamcompatibility_active_constraints_put_handler }; } +nmos::experimental::details::streamcompatibility_sender_validator make_node_implementation_sender_validator() +{ + // this example uses the default sender validator explicitly + return &nmos::experimental::validate_sender_resources; +} + namespace impl { nmos::interlace_mode get_interlace_mode(const nmos::settings& settings) @@ -1459,5 +1465,6 @@ nmos::experimental::node_implementation make_node_implementation(nmos::node_mode .on_base_edid_changed(make_node_implementation_streamcompatibility_base_edid_put_handler(gate)) .on_base_edid_deleted(make_node_implementation_streamcompatibility_base_edid_delete_handler(gate)) .on_set_effective_edid(make_node_implementation_effective_edid_setter(model.streamcompatibility_resources, gate)) - .on_active_constraints_changed(make_node_implementation_active_constraints_handler(gate)); + .on_active_constraints_changed(make_node_implementation_active_constraints_handler(gate)) + .on_validate_sender_against_active_constraints(make_node_implementation_sender_validator()); } diff --git a/Development/nmos/node_server.cpp b/Development/nmos/node_server.cpp index d897f5a5b..29ffaef43 100644 --- a/Development/nmos/node_server.cpp +++ b/Development/nmos/node_server.cpp @@ -104,13 +104,14 @@ namespace nmos auto set_transportfile = node_implementation.set_transportfile; auto connection_activated = node_implementation.connection_activated; auto channelmapping_activated = node_implementation.channelmapping_activated; + auto validate_sender = node_implementation.validate_sender; node_server.thread_functions.assign({ [&, load_ca_certificates, registration_changed] { nmos::node_behaviour_thread(node_model, load_ca_certificates, registration_changed, gate); }, [&] { nmos::send_events_ws_messages_thread(events_ws_listener, node_model, events_ws_api.second, gate); }, [&] { nmos::erase_expired_events_resources_thread(node_model, gate); }, [&, resolve_auto, set_transportfile, connection_activated] { nmos::connection_activation_thread(node_model, resolve_auto, set_transportfile, connection_activated, gate); }, [&, channelmapping_activated] { nmos::channelmapping_activation_thread(node_model, channelmapping_activated, gate); }, - [&] { nmos::experimental::streamcompatibility_behaviour_thread(node_model, gate); } + [&, validate_sender] { nmos::experimental::streamcompatibility_behaviour_thread(node_model, validate_sender, gate); } }); auto system_changed = node_implementation.system_changed; diff --git a/Development/nmos/node_server.h b/Development/nmos/node_server.h index d6f211042..1235a6373 100644 --- a/Development/nmos/node_server.h +++ b/Development/nmos/node_server.h @@ -7,6 +7,7 @@ #include "nmos/connection_api.h" #include "nmos/connection_activation.h" #include "nmos/streamcompatibility_api.h" +#include "nmos/streamcompatibility_behaviour.h" #include "nmos/node_behaviour.h" #include "nmos/node_system_behaviour.h" @@ -59,6 +60,7 @@ namespace nmos node_implementation& on_base_edid_deleted(nmos::experimental::details::streamcompatibility_base_edid_delete_handler base_edid_deleted) { this->base_edid_deleted = std::move(base_edid_deleted); return *this; } node_implementation& on_set_effective_edid(nmos::experimental::details::streamcompatibility_effective_edid_setter set_effective_edid) { this->set_effective_edid = std::move(set_effective_edid); return *this; } node_implementation& on_active_constraints_changed(nmos::experimental::details::streamcompatibility_active_constraints_put_handler active_constraints_changed) { this->active_constraints_changed = std::move(active_constraints_changed); return *this; } + node_implementation& on_validate_sender_against_active_constraints(nmos::experimental::details::streamcompatibility_sender_validator validate_sender) { this->validate_sender = std::move(validate_sender); return *this; } // deprecated, use on_validate_connection_resource_patch node_implementation& on_validate_merged(nmos::details::connection_resource_patch_validator validate_merged) { return on_validate_connection_resource_patch(std::move(validate_merged)); } @@ -91,6 +93,7 @@ namespace nmos nmos::experimental::details::streamcompatibility_base_edid_delete_handler base_edid_deleted; nmos::experimental::details::streamcompatibility_effective_edid_setter set_effective_edid; nmos::experimental::details::streamcompatibility_active_constraints_put_handler active_constraints_changed; + nmos::experimental::details::streamcompatibility_sender_validator validate_sender; }; // Construct a server instance for an NMOS Node, implementing the IS-04 Node API, IS-05 Connection API, IS-07 Events API diff --git a/Development/nmos/streamcompatibility_behaviour.cpp b/Development/nmos/streamcompatibility_behaviour.cpp index fa99d7e5e..a2e99ae80 100644 --- a/Development/nmos/streamcompatibility_behaviour.cpp +++ b/Development/nmos/streamcompatibility_behaviour.cpp @@ -117,7 +117,7 @@ namespace nmos return receiver_state; } - void streamcompatibility_behaviour_thread(nmos::node_model& model, slog::base_gate& gate) + void streamcompatibility_behaviour_thread(nmos::node_model& model, details::streamcompatibility_sender_validator validate_sender, slog::base_gate& gate) { using web::json::value; using web::json::value_of; @@ -179,7 +179,10 @@ namespace nmos auto& transport_file = nmos::fields::endpoint_transportfile(connection_sender->data); slog::log(gate, SLOG_FLF) << "Sender " << sender_id << " is being validated with its Flow, Source and transport file"; - sender_state = validate_sender_resources(transport_file, flow->data, source->data, constraint_sets); + if (validate_sender) + { + sender_state = validate_sender(transport_file, flow->data, source->data, constraint_sets); + } } if (nmos::fields::state(nmos::fields::status(streamcompatibility_sender->data)) != sender_state.name) diff --git a/Development/nmos/streamcompatibility_behaviour.h b/Development/nmos/streamcompatibility_behaviour.h index 498a0a569..75c83e4db 100644 --- a/Development/nmos/streamcompatibility_behaviour.h +++ b/Development/nmos/streamcompatibility_behaviour.h @@ -1,18 +1,37 @@ #ifndef NMOS_FLOWCOMPATIBILITY_BEHAVIOUR_H #define NMOS_FLOWCOMPATIBILITY_BEHAVIOUR_H +#include + +#include "nmos/streamcompatibility_state.h" + namespace slog { class base_gate; } +namespace web +{ + namespace json + { + class value; + class array; + } +} + namespace nmos { struct node_model; namespace experimental { - void streamcompatibility_behaviour_thread(nmos::node_model& model, slog::base_gate& gate); + namespace details + { + typedef std::function streamcompatibility_sender_validator; + } + + nmos::sender_state validate_sender_resources(const web::json::value& transport_file, const web::json::value& flow, const web::json::value& source, const web::json::array& constraint_sets); + void streamcompatibility_behaviour_thread(nmos::node_model& model, details::streamcompatibility_sender_validator validate_sender, slog::base_gate& gate); } }