Skip to content

Commit e978104

Browse files
authored
Enhance Monitor Status callback to include monitor information (#486)
* Enhance the Monitor Status callback to include monitor information associated with specific network interfaces * Fix control_protocol_utils_test usng the updated Status Monitor's callback
1 parent 8e2e17f commit e978104

4 files changed

Lines changed: 30 additions & 24 deletions

File tree

Development/nmos-cpp-node/node_implementation.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,11 +2121,13 @@ nmos::control_protocol_property_changed_handler make_node_implementation_control
21212121
};
21222122
}
21232123

2124-
// Example Control Protocol WebSocket API Receiver Status Monitor callback to get network interface controller lost packet counters
2125-
nmos::get_packet_counters_handler make_node_implementation_get_lost_packet_counters_handler()
2124+
// Example Control Protocol WebSocket API Receiver/Sender Status Monitor callback to get network interface controller lost packet counters
2125+
nmos::get_packet_counters_handler make_node_implementation_get_lost_packet_counters_handler(slog::base_gate& gate)
21262126
{
2127-
return []()
2127+
return [&gate](const nmos::resource& resource)
21282128
{
2129+
slog::log<slog::severities::info>(gate, SLOG_FLF) << nmos::stash_category(impl::categories::node_implementation) << "Lost package counters of " << nmos::fields::nc::role(resource.data);
2130+
21292131
return boost::copy_range<std::vector<nmos::nc::counter>>(impl::nic_packet_counters | boost::adaptors::transformed([](const impl::nic_packet_counter& counter)
21302132
{
21312133
return nmos::nc::counter{ counter.lost_packet_counter.name, counter.lost_packet_counter.value, counter.lost_packet_counter.description };
@@ -2134,22 +2136,26 @@ nmos::get_packet_counters_handler make_node_implementation_get_lost_packet_count
21342136
}
21352137

21362138
// Example Control Protocol WebSocket API Receiver Status Monitor callback to get network interface controller late packet counters
2137-
nmos::get_packet_counters_handler make_node_implementation_get_late_packet_counters_handler()
2139+
nmos::get_packet_counters_handler make_node_implementation_get_late_packet_counters_handler(slog::base_gate& gate)
21382140
{
2139-
return []()
2141+
return [&gate](const nmos::resource& resource)
21402142
{
2143+
slog::log<slog::severities::info>(gate, SLOG_FLF) << nmos::stash_category(impl::categories::node_implementation) << "Late package counters of " << nmos::fields::nc::role(resource.data);
2144+
21412145
return boost::copy_range<std::vector<nmos::nc::counter>>(impl::nic_packet_counters | boost::adaptors::transformed([](const impl::nic_packet_counter& counter)
21422146
{
21432147
return nmos::nc::counter{ counter.late_packet_counter.name, counter.late_packet_counter.value, counter.late_packet_counter.description };
21442148
}));
21452149
};
21462150
}
21472151

2148-
// Example Control Protocol WebSocket API Receiver Status Monitor callback to reset network interface controller packet counters
2149-
nmos::reset_monitor_handler make_node_implementation_reset_monitor_handler()
2152+
// Example Control Protocol WebSocket API Receiver/Sender Status Monitor callback to reset network interface controller packet counters
2153+
nmos::reset_monitor_handler make_node_implementation_reset_monitor_handler(slog::base_gate& gate)
21502154
{
2151-
return []()
2155+
return [&gate](const nmos::resource& resource)
21522156
{
2157+
slog::log<slog::severities::info>(gate, SLOG_FLF) << nmos::stash_category(impl::categories::node_implementation) << "Reset package counters of " << nmos::fields::nc::role(resource.data);
2158+
21532159
for (auto& counter : impl::nic_packet_counters)
21542160
{
21552161
counter.lost_packet_counter.value = 0;
@@ -2394,7 +2400,7 @@ nmos::experimental::node_implementation make_node_implementation(nmos::node_mode
23942400
.on_get_read_only_modification_allow_list(make_get_read_only_modification_allow_list_handler(gate)) // may be omitted if either IS-14 not required, or IS-14 Rebuild functionality not required
23952401
.on_remove_device_model_object(make_remove_device_model_object_handler()) // may be omitted if either IS-14 not required, or IS-14 Rebuild functionality not required
23962402
.on_create_device_model_object(make_create_device_model_object_handler(gate)) // may be omitted if either IS-14 not required, or IS-14 Rebuild functionality not required
2397-
.on_get_lost_packet_counters(make_node_implementation_get_lost_packet_counters_handler()) // may be omitted if IS-12/BCP-008-1 not required
2398-
.on_get_late_packet_counters(make_node_implementation_get_late_packet_counters_handler()) // may be omitted if IS-12/BCP-008-1 not required
2399-
.on_reset_monitor(make_node_implementation_reset_monitor_handler()); // may be omitted if IS-12/BCP-008-1 not required
2403+
.on_get_lost_packet_counters(make_node_implementation_get_lost_packet_counters_handler(gate)) // may be omitted if IS-12/BCP-008-1 not required
2404+
.on_get_late_packet_counters(make_node_implementation_get_late_packet_counters_handler(gate)) // may be omitted if IS-12/BCP-008-1 not required
2405+
.on_reset_monitor(make_node_implementation_reset_monitor_handler(gate)); // may be omitted if IS-12/BCP-008-1 not required
24002406
}

Development/nmos/control_protocol_handlers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ namespace nmos
5757
: name(name), value(value), description(description) {}
5858
};
5959
}
60-
typedef std::function<std::vector<nc::counter>(void)> get_packet_counters_handler;
61-
typedef std::function<void(void)> reset_monitor_handler;
60+
typedef std::function<std::vector<nc::counter>(const nmos::resource&)> get_packet_counters_handler;
61+
typedef std::function<void(const nmos::resource&)> reset_monitor_handler;
6262

6363
namespace experimental
6464
{

Development/nmos/control_protocol_methods.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,17 +677,17 @@ namespace nmos
677677
return details::make_method_result_error({nc_method_status::parameter_error}, U("name not found"));
678678
}
679679

680-
// NcReceiverMonitor methods implementation
680+
// NcReceiverMonitor and NcSenderMonitor methods implementation
681681
namespace details
682682
{
683-
web::json::value get_packet_counters(bool is_deprecated, get_packet_counters_handler get_packet_counters)
683+
web::json::value get_packet_counters(const nmos::resource& resource, bool is_deprecated, get_packet_counters_handler get_packet_counters)
684684
{
685685
using web::json::value;
686686
using web::json::value_from_elements;
687687

688688
if (get_packet_counters)
689689
{
690-
const auto counters = get_packet_counters();
690+
const auto counters = get_packet_counters(resource);
691691
auto nc_counter_sequence = value_from_elements(counters | boost::adaptors::transformed([](const nc::counter& counter)
692692
{
693693
return web::json::value_of({
@@ -705,19 +705,19 @@ namespace nmos
705705
}
706706

707707
// Gets the lost packet counters
708-
web::json::value get_lost_packet_counters(nmos::resources& /*resources*/, const nmos::resource& /*resource*/, const web::json::value& /*arguments*/, bool is_deprecated, get_packet_counters_handler get_lost_packet_counters, slog::base_gate& gate)
708+
web::json::value get_lost_packet_counters(nmos::resources& /*resources*/, const nmos::resource& resource, const web::json::value& /*arguments*/, bool is_deprecated, get_packet_counters_handler get_lost_packet_counters, slog::base_gate& gate)
709709
{
710710
slog::log<slog::severities::more_info>(gate, SLOG_FLF) << "Gets the lost packet counters";
711711

712-
return details::get_packet_counters(is_deprecated, get_lost_packet_counters);
712+
return details::get_packet_counters(resource, is_deprecated, get_lost_packet_counters);
713713
}
714714

715715
// Gets the late packet counters
716-
web::json::value get_late_packet_counters(nmos::resources& /*resources*/, const nmos::resource& /*resource*/, const web::json::value& /*arguments*/, bool is_deprecated, get_packet_counters_handler get_late_packet_counters, slog::base_gate& gate)
716+
web::json::value get_late_packet_counters(nmos::resources& /*resources*/, const nmos::resource& resource, const web::json::value& /*arguments*/, bool is_deprecated, get_packet_counters_handler get_late_packet_counters, slog::base_gate& gate)
717717
{
718718
slog::log<slog::severities::more_info>(gate, SLOG_FLF) << "Gets the late packet counters";
719719

720-
return details::get_packet_counters(is_deprecated, get_late_packet_counters);
720+
return details::get_packet_counters(resource, is_deprecated, get_late_packet_counters);
721721
}
722722

723723
// Resets the packet counters and messages
@@ -786,7 +786,7 @@ namespace nmos
786786

787787
if (reset_monitor)
788788
{
789-
reset_monitor();
789+
reset_monitor(resource);
790790
}
791791

792792
return details::make_method_result({is_deprecated ? nmos::nc_method_status::method_deprecated : nc_method_status::ok});

Development/nmos/test/control_protocol_utils_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ BST_TEST_CASE(testActivateDeactivateReceiverMonitor)
323323

324324
bool reset_monitor_called = false;
325325

326-
nmos::reset_monitor_handler reset_monitor = [&reset_monitor_called]()
326+
nmos::reset_monitor_handler reset_monitor = [&reset_monitor_called](const nmos::resource&)
327327
{
328328
// check that the property changed handler gets called
329329
reset_monitor_called = true;
@@ -685,7 +685,7 @@ BST_TEST_CASE(testActivateDeactivateSenderMonitor)
685685

686686
bool reset_monitor_called = false;
687687

688-
nmos::reset_monitor_handler reset_monitor = [&reset_monitor_called]()
688+
nmos::reset_monitor_handler reset_monitor = [&reset_monitor_called](const nmos::resource&)
689689
{
690690
// check that the property changed handler gets called
691691
reset_monitor_called = true;
@@ -825,7 +825,7 @@ BST_TEST_CASE(testSetMonitorStatusWithDelay)
825825
bool reset_monitor_called = false;
826826
bool monitor_status_pending_called = false;
827827

828-
nmos::reset_monitor_handler reset_monitor = [&reset_monitor_called]()
828+
nmos::reset_monitor_handler reset_monitor = [&reset_monitor_called](const nmos::resource&)
829829
{
830830
// check that the property changed handler gets called
831831
reset_monitor_called = true;

0 commit comments

Comments
 (0)