Skip to content

Commit

Permalink
Make Sender validator of streamcompatibility_behaviour_thread customi…
Browse files Browse the repository at this point in the history
…zable
  • Loading branch information
N-Nagorny committed Oct 3, 2022
1 parent ceedd93 commit e2dd598
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
9 changes: 8 additions & 1 deletion Development/nmos-cpp-node/node_implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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());
}
3 changes: 2 additions & 1 deletion Development/nmos/node_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions Development/nmos/node_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)); }
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions Development/nmos/streamcompatibility_behaviour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -179,7 +179,10 @@ namespace nmos
auto& transport_file = nmos::fields::endpoint_transportfile(connection_sender->data);

slog::log<slog::severities::info>(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)
Expand Down
21 changes: 20 additions & 1 deletion Development/nmos/streamcompatibility_behaviour.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
#ifndef NMOS_FLOWCOMPATIBILITY_BEHAVIOUR_H
#define NMOS_FLOWCOMPATIBILITY_BEHAVIOUR_H

#include <functional>

#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<nmos::sender_state(const web::json::value& transport_file, const web::json::value& flow, const web::json::value& source, const web::json::array& constraint_sets)> 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);
}
}

Expand Down

0 comments on commit e2dd598

Please sign in to comment.