Skip to content

Commit

Permalink
Code fix to construct nc_property_changed_event_data, thanks for @maweit
Browse files Browse the repository at this point in the history
 reviewing
  • Loading branch information
lo-simon committed Oct 6, 2023
1 parent 84f13d4 commit 645ff22
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Development/nmos/control_protocol_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ namespace nmos
return make_control_protocol_message_response(handle, { nc_method_status::parameter_error });
}

const auto notification = make_control_protocol_notification(nmos::fields::nc::oid(resource->data), nc_object_property_changed_event_id, { parse_nc_property_id(property_id), nc_property_change_type::type::value_changed, val });
const nc_property_changed_event_data property_changed_event_data{ parse_nc_property_id(property_id), nc_property_change_type::type::value_changed, val };
const auto notification = make_control_protocol_notification(nmos::fields::nc::oid(resource->data), nc_object_property_changed_event_id, property_changed_event_data);
const auto notification_event = make_control_protocol_notification(web::json::value_of({ notification }));

modify_resource(resources, resource->id, [&](nmos::resource& resource)
{
resource.data[nmos::fields::nc::name(property)] = val;
resource.data[nmos::fields::nc::name(property)] = property_changed_event_data.value;

}, notification_event);

Expand Down Expand Up @@ -146,12 +147,13 @@ namespace nmos

if (data.as_array().size() > (size_t)index)
{
const auto notification = make_control_protocol_notification(nmos::fields::nc::oid(resource->data), nc_object_property_changed_event_id, { parse_nc_property_id(property_id), nc_property_change_type::type::sequence_item_changed, val, nc_id(index) });
const nc_property_changed_event_data property_changed_event_data{ parse_nc_property_id(property_id), nc_property_change_type::type::sequence_item_changed, val, nc_id(index) };
const auto notification = make_control_protocol_notification(nmos::fields::nc::oid(resource->data), nc_object_property_changed_event_id, property_changed_event_data);
const auto notification_event = make_control_protocol_notification(web::json::value_of({ notification }));

modify_resource(resources, resource->id, [&](nmos::resource& resource)
{
resource.data[nmos::fields::nc::name(property)][index] = val;
resource.data[nmos::fields::nc::name(property)][index] = property_changed_event_data.value;

}, notification_event);

Expand Down Expand Up @@ -197,14 +199,15 @@ namespace nmos
auto& data = resource->data.at(nmos::fields::nc::name(property));

const nc_id sequence_item_index = data.is_null() ? 0 : nc_id(data.as_array().size());
const auto notification = make_control_protocol_notification(nmos::fields::nc::oid(resource->data), nc_object_property_changed_event_id, { parse_nc_property_id(property_id), nc_property_change_type::type::sequence_item_added, val, sequence_item_index });
const nc_property_changed_event_data property_changed_event_data{ parse_nc_property_id(property_id), nc_property_change_type::type::sequence_item_added, val, sequence_item_index };
const auto notification = make_control_protocol_notification(nmos::fields::nc::oid(resource->data), nc_object_property_changed_event_id, property_changed_event_data);
const auto notification_event = make_control_protocol_notification(web::json::value_of({ notification }));

modify_resource(resources, resource->id, [&](nmos::resource& resource)
{
auto& sequence = resource.data[nmos::fields::nc::name(property)];
if (data.is_null()) { sequence = value::array(); }
web::json::push_back(sequence, val);
web::json::push_back(sequence, property_changed_event_data.value);

}, notification_event);

Expand Down Expand Up @@ -243,7 +246,8 @@ namespace nmos

if (data.as_array().size() > (size_t)index)
{
const auto notification = make_control_protocol_notification(nmos::fields::nc::oid(resource->data), nc_object_property_changed_event_id, { parse_nc_property_id(property_id), nc_property_change_type::type::sequence_item_removed, data.as_array().at(index), nc_id(index)});
const nc_property_changed_event_data property_changed_event_data{ parse_nc_property_id(property_id), nc_property_change_type::type::sequence_item_removed, data.as_array().at(index), nc_id(index) };
const auto notification = make_control_protocol_notification(nmos::fields::nc::oid(resource->data), nc_object_property_changed_event_id, property_changed_event_data);
const auto notification_event = make_control_protocol_notification(web::json::value_of({ notification }));

modify_resource(resources, resource->id, [&](nmos::resource& resource)
Expand Down

0 comments on commit 645ff22

Please sign in to comment.