|
1 | 1 | #include "nmos/control_protocol_state.h"
|
2 | 2 |
|
| 3 | +#include "cpprest/http_utils.h" |
3 | 4 | #include "nmos/control_protocol_methods.h"
|
4 | 5 | #include "nmos/control_protocol_resource.h"
|
5 | 6 |
|
@@ -178,30 +179,69 @@ namespace nmos
|
178 | 179 | return get_datatype(resources, resource, arguments, is_deprecated, get_control_protocol_datatype_descriptor, gate);
|
179 | 180 | };
|
180 | 181 | }
|
181 |
| - nmos::experimental::control_protocol_method_handler make_nc_get_lost_packets(experimental::control_protocol_method_handler get_lost_packet_method_handler) |
| 182 | + nmos::experimental::control_protocol_method_handler make_nc_get_lost_packet_counters_handler(get_lost_packet_counters_handler get_lost_packet_counters) |
182 | 183 | {
|
183 |
| - 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) |
| 184 | + return [get_lost_packet_counters](nmos::resources& resources, const nmos::resource& resource, const web::json::value& arguments, bool is_deprecated, slog::base_gate& gate) |
184 | 185 | {
|
185 |
| - return get_lost_packet_method_handler(resources, resource, arguments, is_deprecated, gate); |
| 186 | + // Delegate to user defined handler |
| 187 | + auto result = nmos::details::make_nc_method_result_error({ nmos::nc_method_status::method_not_implemented }, U("not implemented")); |
| 188 | + |
| 189 | + if (get_lost_packet_counters) |
| 190 | + { |
| 191 | + result = get_lost_packet_counters(); |
| 192 | + |
| 193 | + const auto& status = nmos::fields::nc::status(result); |
| 194 | + if (!web::http::is_error_status_code((web::http::status_code)status) && is_deprecated) |
| 195 | + { |
| 196 | + return nmos::details::make_nc_method_result({ nmos::nc_method_status::method_deprecated }, nmos::fields::nc::value(result)); |
| 197 | + } |
| 198 | + } |
| 199 | + return result; |
186 | 200 | };
|
187 | 201 | }
|
188 |
| - nmos::experimental::control_protocol_method_handler make_nc_get_late_packets(experimental::control_protocol_method_handler get_late_packet_method_handler) |
| 202 | + nmos::experimental::control_protocol_method_handler make_nc_get_late_packet_counters_handler(get_late_packet_counters_handler get_late_packet_counters) |
189 | 203 | {
|
190 |
| - 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) |
| 204 | + return [get_late_packet_counters](nmos::resources& resources, const nmos::resource& resource, const web::json::value& arguments, bool is_deprecated, slog::base_gate& gate) |
191 | 205 | {
|
192 |
| - return get_late_packet_method_handler(resources, resource, arguments, is_deprecated, gate); |
| 206 | + // Delegate to user defined handler |
| 207 | + auto result = nmos::details::make_nc_method_result_error({ nmos::nc_method_status::method_not_implemented }, U("not implemented")); |
| 208 | + |
| 209 | + if (get_late_packet_counters) |
| 210 | + { |
| 211 | + result = get_late_packet_counters(); |
| 212 | + |
| 213 | + const auto& status = nmos::fields::nc::status(result); |
| 214 | + if (!web::http::is_error_status_code((web::http::status_code)status) && is_deprecated) |
| 215 | + { |
| 216 | + return nmos::details::make_nc_method_result({ nmos::nc_method_status::method_deprecated }, nmos::fields::nc::value(result)); |
| 217 | + } |
| 218 | + } |
| 219 | + return result; |
193 | 220 | };
|
194 | 221 | }
|
195 |
| - nmos::experimental::control_protocol_method_handler make_nc_reset_packet_counters(experimental::control_protocol_method_handler reset_packet_counters_method_handler) |
| 222 | + nmos::experimental::control_protocol_method_handler make_nc_reset_packet_counters_handler(reset_packet_counters_handler reset_packet_counters) |
196 | 223 | {
|
197 |
| - 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) |
| 224 | + return [reset_packet_counters](nmos::resources& resources, const nmos::resource& resource, const web::json::value& arguments, bool is_deprecated, slog::base_gate& gate) |
198 | 225 | {
|
199 |
| - return reset_packet_counters_method_handler(resources, resource, arguments, is_deprecated, gate); |
| 226 | + // Delegate to user defined handler |
| 227 | + auto result = nmos::details::make_nc_method_result_error({ nmos::nc_method_status::method_not_implemented }, U("not implemented")); |
| 228 | + |
| 229 | + if (reset_packet_counters) |
| 230 | + { |
| 231 | + result = reset_packet_counters(); |
| 232 | + |
| 233 | + const auto& status = nmos::fields::nc::status(result); |
| 234 | + if (!web::http::is_error_status_code((web::http::status_code)status) && is_deprecated) |
| 235 | + { |
| 236 | + return nmos::details::make_nc_method_result({ nmos::nc_method_status::method_deprecated }, nmos::fields::nc::value(result)); |
| 237 | + } |
| 238 | + } |
| 239 | + return result; |
200 | 240 | };
|
201 | 241 | }
|
202 | 242 | }
|
203 | 243 |
|
204 |
| - 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) |
| 244 | + control_protocol_state::control_protocol_state(get_lost_packet_counters_handler get_lost_packet_counters, get_late_packet_counters_handler get_late_packet_counters, reset_packet_counters_handler reset_packet_counters, control_protocol_property_changed_handler property_changed) |
205 | 245 | {
|
206 | 246 | using web::json::value;
|
207 | 247 |
|
@@ -336,9 +376,9 @@ namespace nmos
|
336 | 376 | to_methods_vector(make_nc_receiver_monitor_methods(),
|
337 | 377 | {
|
338 | 378 | // link NcReceiverMonitor method_ids with method functions
|
339 |
| - { nc_receiver_monitor_get_lost_packets_method_id, details::make_nc_get_lost_packets(get_lost_packet_method_handler)}, |
340 |
| - { nc_receiver_monitor_get_late_packets_method_id, details::make_nc_get_late_packets(get_late_packet_method_handler)}, |
341 |
| - { nc_receiver_monitor_reset_packet_counters_method_id, details::make_nc_reset_packet_counters(reset_packet_couter_method_handler)} |
| 379 | + { nc_receiver_monitor_get_lost_packet_counters_method_id, details::make_nc_get_lost_packet_counters_handler(get_lost_packet_counters)}, |
| 380 | + { nc_receiver_monitor_get_late_packet_counters_method_id, details::make_nc_get_late_packet_counters_handler(get_late_packet_counters)}, |
| 381 | + { nc_receiver_monitor_reset_packet_counters_method_id, details::make_nc_reset_packet_counters_handler(reset_packet_counters)} |
342 | 382 | }),
|
343 | 383 | // NcReceiverMonitor events
|
344 | 384 | to_vector(make_nc_receiver_monitor_events())) }
|
@@ -424,7 +464,8 @@ namespace nmos
|
424 | 464 | { U("NcLinkStatus"), {make_nc_link_status_datatype() } },
|
425 | 465 | { U("NcSynchronizationStatus"), {make_nc_synchronization_status_datatype() } },
|
426 | 466 | { U("NcStreamStatus"), {make_nc_stream_status_datatype() } },
|
427 |
| - { U("NcMethodResultCounter"), {make_nc_method_result_counter_datatype() } } |
| 467 | + { U("NcPacketCounter"), {make_nc_packet_counter_datatype() } }, |
| 468 | + { U("NcMethodResultCounters"), {make_nc_method_result_counters_datatype() } } |
428 | 469 | };
|
429 | 470 | }
|
430 | 471 |
|
|
0 commit comments