Skip to content

Commit

Permalink
Add Receiver Monitor method handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-r-thorpe committed Jun 11, 2024
1 parent e970fa6 commit 667ea4f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Development/nmos-cpp-node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int main(int argc, char* argv[])
.on_request_authorization_code(nmos::experimental::make_request_authorization_code_handler(gate)); // may be omitted, only required for OAuth client which is using the Authorization Code Flow to obtain the access token
}

nmos::experimental::control_protocol_state control_protocol_state(node_implementation.control_protocol_property_changed);
nmos::experimental::control_protocol_state control_protocol_state(node_implementation.get_lost_packet_method_handler, node_implementation.get_late_packet_method_handler, node_implementation.reset_packet_counters_method_handler, node_implementation.control_protocol_property_changed);
if (0 <= nmos::fields::control_protocol_ws_port(node_model.settings))
{
node_implementation
Expand Down
6 changes: 3 additions & 3 deletions Development/nmos/control_protocol_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,19 +627,19 @@ namespace nmos
}

// NcReceiverMonitor methods
web::json::value get_lost_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, get_control_protocol_class_descriptor_handler, get_control_protocol_datatype_descriptor_handler, control_protocol_property_changed_handler, slog::base_gate&)
web::json::value get_lost_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&)
{
// this will need to be defined in a user defined handler
return details::make_nc_method_result({ nc_method_status::ok });
}

web::json::value get_late_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, get_control_protocol_class_descriptor_handler, get_control_protocol_datatype_descriptor_handler, control_protocol_property_changed_handler, slog::base_gate&)
web::json::value get_late_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&)
{
// this will need to be defined in a user defined handler
return details::make_nc_method_result({ nc_method_status::ok });
}

web::json::value reset_packet_counters(nmos::resources&, const nmos::resource&, const web::json::value&, bool, get_control_protocol_class_descriptor_handler, get_control_protocol_datatype_descriptor_handler, control_protocol_property_changed_handler, slog::base_gate&)
web::json::value reset_packet_counters(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&)
{
// this will need to be defined in a user defined handler
return details::make_nc_method_result({ nc_method_status::ok });
Expand Down
6 changes: 3 additions & 3 deletions Development/nmos/control_protocol_methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ namespace nmos

// NcReceiverMonitor methods implementation
// Gets the lost packets
web::json::value get_lost_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, get_control_protocol_class_descriptor_handler, get_control_protocol_datatype_descriptor_handler, control_protocol_property_changed_handler, slog::base_gate&);
web::json::value get_lost_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&);
// Gets the late packets
web::json::value get_late_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, get_control_protocol_class_descriptor_handler, get_control_protocol_datatype_descriptor_handler, control_protocol_property_changed_handler, slog::base_gate&);
web::json::value get_late_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&);
// Resets the packet counters
web::json::value reset_packet_counters(nmos::resources&, const nmos::resource&, const web::json::value&, bool, get_control_protocol_class_descriptor_handler, get_control_protocol_datatype_descriptor_handler, control_protocol_property_changed_handler, slog::base_gate&);
web::json::value reset_packet_counters(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&);
}

#endif
29 changes: 25 additions & 4 deletions Development/nmos/control_protocol_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,30 @@ namespace nmos
return get_datatype(resources, resource, arguments, is_deprecated, get_control_protocol_datatype_descriptor, gate);
};
}
nmos::experimental::control_protocol_method_handler make_nc_get_lost_packets(experimental::control_protocol_method_handler get_lost_packet_method_handler)
{
return [get_lost_packet_method_handler](nmos::resources& resources, const nmos::resource& resource, const web::json::value& arguments, bool is_deprecated, slog::base_gate& gate)
{
return get_lost_packet_method_handler(resources, resource, arguments, is_deprecated, gate);
};
}
nmos::experimental::control_protocol_method_handler make_nc_get_late_packets(experimental::control_protocol_method_handler get_late_packet_method_handler)
{
return [get_late_packet_method_handler](nmos::resources& resources, const nmos::resource& resource, const web::json::value& arguments, bool is_deprecated, slog::base_gate& gate)
{
return get_late_packet_method_handler(resources, resource, arguments, is_deprecated, gate);
};
}
nmos::experimental::control_protocol_method_handler make_nc_reset_packet_counters(experimental::control_protocol_method_handler reset_packet_counters_method_handler)
{
return [reset_packet_counters_method_handler](nmos::resources& resources, const nmos::resource& resource, const web::json::value& arguments, bool is_deprecated, slog::base_gate& gate)
{
return reset_packet_counters_method_handler(resources, resource, arguments, is_deprecated, gate);
};
}
}

control_protocol_state::control_protocol_state(control_protocol_property_changed_handler property_changed)
control_protocol_state::control_protocol_state(experimental::control_protocol_method_handler get_lost_packet_method_handler, experimental::control_protocol_method_handler get_late_packet_method_handler, experimental::control_protocol_method_handler reset_packet_couter_method_handler, control_protocol_property_changed_handler property_changed)
{
using web::json::value;

Expand Down Expand Up @@ -315,9 +336,9 @@ namespace nmos
to_methods_vector(make_nc_receiver_monitor_methods(),
{
// link NcReceiverMonitor method_ids with method functions
{ nc_receiver_monitor_get_lost_packets_method_id, get_lost_packets },
{ nc_receiver_monitor_get_late_packets_method_id, get_late_packets },
{ nc_receiver_monitor_reset_packet_counters_method_id, reset_packet_counters }
{ nc_receiver_monitor_get_lost_packets_method_id, details::make_nc_get_lost_packets(get_lost_packet_method_handler)},
{ nc_receiver_monitor_get_late_packets_method_id, details::make_nc_get_late_packets(get_late_packet_method_handler)},
{ nc_receiver_monitor_reset_packet_counters_method_id, details::make_nc_reset_packet_counters(reset_packet_couter_method_handler)}
}),
// NcReceiverMonitor events
to_vector(make_nc_receiver_monitor_events())) }
Expand Down
2 changes: 1 addition & 1 deletion Development/nmos/control_protocol_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace nmos
nmos::read_lock read_lock() const { return nmos::read_lock{ mutex }; }
nmos::write_lock write_lock() const { return nmos::write_lock{ mutex }; }

control_protocol_state(control_protocol_property_changed_handler property_changed);
control_protocol_state(experimental::control_protocol_method_handler get_lost_packet_method_handler = nullptr, experimental::control_protocol_method_handler get_late_packet_method_handler = nullptr, experimental::control_protocol_method_handler reset_packet_couter_method_handler = nullptr, control_protocol_property_changed_handler property_changed = nullptr);

// insert control class descriptor, false if class descriptor already inserted
bool insert(const experimental::control_class_descriptor& control_class_descriptor);
Expand Down
4 changes: 2 additions & 2 deletions Development/nmos/test/control_protocol_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ BST_TEST_CASE(testFindProperty)
const auto invalid_property_id = nmos::nc_property_id(1000, 1000);
const auto invalid_class_id = nmos::nc_class_id({ 1000, 1000 });

nmos::experimental::control_protocol_state control_protocol_state(nullptr);
nmos::experimental::control_protocol_state control_protocol_state;
auto get_control_protocol_class_descriptor = nmos::make_get_control_protocol_class_descriptor_handler(control_protocol_state);

{
Expand Down Expand Up @@ -773,7 +773,7 @@ BST_TEST_CASE(testConstraints)
const auto struct_datatype = nmos::details::make_nc_datatype_descriptor_struct(U("struct datatype"), U("structDatatype"), fields, value::null()); // no datatype constraints for struct datatype

// setup datatypes in control_protocol_state
nmos::experimental::control_protocol_state control_protocol_state(nullptr);
nmos::experimental::control_protocol_state control_protocol_state;
control_protocol_state.insert(nmos::experimental::datatype_descriptor{ no_constraints_int16_datatype });
control_protocol_state.insert(nmos::experimental::datatype_descriptor{ no_constraints_int32_datatype });
control_protocol_state.insert(nmos::experimental::datatype_descriptor{ no_constraints_int64_datatype });
Expand Down

0 comments on commit 667ea4f

Please sign in to comment.