Skip to content

Commit

Permalink
Add logging for contraints validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lo-simon committed Nov 21, 2023
1 parent 14aa16f commit 0bed427
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 252 deletions.
83 changes: 49 additions & 34 deletions Development/nmos/control_protocol_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,26 @@ namespace nmos
return make_control_protocol_message_response(handle, { nc_method_status::parameter_error });
}

// do property constraints validation
if (!val.is_null())
try
{
if (!nmos::details::constraints_validation(val, get_runtime_property_constraints(property_id_, resource->data.at(nmos::fields::nc::runtime_property_constraints)), nmos::fields::nc::constraints(property), { get_datatype_descriptor(property.at(nmos::fields::nc::type_name), get_control_protocol_datatype), get_control_protocol_datatype }))
// do property constraints validation
nmos::details::constraints_validation(val, get_runtime_property_constraints(property_id_, resource->data.at(nmos::fields::nc::runtime_property_constraints)), nmos::fields::nc::constraints(property), { get_datatype_descriptor(property.at(nmos::fields::nc::type_name), get_control_protocol_datatype), get_control_protocol_datatype });

// update property
modify_control_protocol_resource(resources, resource->id, [&](nmos::resource& resource)
{
return make_control_protocol_message_response(handle, { nc_method_status::parameter_error });
}
}
resource.data[nmos::fields::nc::name(property)] = val;

// update property
modify_control_protocol_resource(resources, resource->id, [&](nmos::resource& resource)
{
resource.data[nmos::fields::nc::name(property)] = val;
}, make_propertry_changed_event(nmos::fields::nc::oid(resource->data), { { property_id_, nc_property_change_type::type::value_changed, val } }));

}, make_propertry_changed_event(nmos::fields::nc::oid(resource->data), { { property_id_, nc_property_change_type::type::value_changed, val } }));
return make_control_protocol_message_response(handle, { is_deprecated ? nmos::nc_method_status::method_deprecated : nmos::fields::nc::is_deprecated(property) ? nc_method_status::property_deprecated : nc_method_status::ok });
}
catch (const nmos::control_protocol_exception& e)
{
slog::log<slog::severities::error>(gate, SLOG_FLF) << "Set property: " << property_id.serialize() << " value: " << val.serialize() << " error: " << e.what();

return make_control_protocol_message_response(handle, { is_deprecated ? nmos::nc_method_status::method_deprecated : nmos::fields::nc::is_deprecated(property) ? nc_method_status::property_deprecated : nc_method_status::ok });
return make_control_protocol_message_response(handle, { nc_method_status::parameter_error });
}
}

// unknown property
Expand Down Expand Up @@ -161,20 +164,26 @@ namespace nmos

if (data.as_array().size() > (size_t)index)
{
// do property constraints validation
if (!nmos::details::constraints_validation(val, get_runtime_property_constraints(property_id_, resource->data.at(nmos::fields::nc::runtime_property_constraints)), nmos::fields::nc::constraints(property), { get_datatype_descriptor(property.at(nmos::fields::nc::type_name), get_control_protocol_datatype), get_control_protocol_datatype }))
try
{
return make_control_protocol_message_response(handle, { nc_method_status::parameter_error });
}
// do property constraints validation
nmos::details::constraints_validation(val, get_runtime_property_constraints(property_id_, resource->data.at(nmos::fields::nc::runtime_property_constraints)), nmos::fields::nc::constraints(property), { get_datatype_descriptor(property.at(nmos::fields::nc::type_name), get_control_protocol_datatype), get_control_protocol_datatype });

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

}, make_propertry_changed_event(nmos::fields::nc::oid(resource->data), { { property_id_, nc_property_change_type::type::sequence_item_changed, val, nc_id(index) } }));
}, make_propertry_changed_event(nmos::fields::nc::oid(resource->data), { { property_id_, nc_property_change_type::type::sequence_item_changed, val, nc_id(index) } }));

return make_control_protocol_message_response(handle, { is_deprecated ? nmos::nc_method_status::method_deprecated : nmos::fields::nc::is_deprecated(property) ? nc_method_status::property_deprecated : nc_method_status::ok });
return make_control_protocol_message_response(handle, { is_deprecated ? nmos::nc_method_status::method_deprecated : nmos::fields::nc::is_deprecated(property) ? nc_method_status::property_deprecated : nc_method_status::ok });
}
catch (const nmos::control_protocol_exception& e)
{
slog::log<slog::severities::error>(gate, SLOG_FLF) << "Set sequence item: " << property_id.serialize() << " index: " << index << " value: " << val.serialize() << " error: " << e.what();

return make_control_protocol_message_response(handle, { nc_method_status::parameter_error });
}
}

// out of bound
Expand Down Expand Up @@ -223,22 +232,28 @@ namespace nmos

const nc_id sequence_item_index = data.is_null() ? 0 : nc_id(data.as_array().size());

// do property constraints validation
if (!nmos::details::constraints_validation(val, get_runtime_property_constraints(property_id_, resource->data.at(nmos::fields::nc::runtime_property_constraints)), nmos::fields::nc::constraints(property), { get_datatype_descriptor(property.at(nmos::fields::nc::type_name), get_control_protocol_datatype), get_control_protocol_datatype }))
try
{
return make_control_protocol_message_response(handle, { nc_method_status::parameter_error });
}
// do property constraints validation
nmos::details::constraints_validation(val, get_runtime_property_constraints(property_id_, resource->data.at(nmos::fields::nc::runtime_property_constraints)), nmos::fields::nc::constraints(property), { get_datatype_descriptor(property.at(nmos::fields::nc::type_name), get_control_protocol_datatype), get_control_protocol_datatype });

// update property
modify_control_protocol_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);
// update property
modify_control_protocol_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);

}, make_propertry_changed_event(nmos::fields::nc::oid(resource->data), { { property_id_, nc_property_change_type::type::sequence_item_added, val, sequence_item_index } }));
}, make_propertry_changed_event(nmos::fields::nc::oid(resource->data), { { property_id_, nc_property_change_type::type::sequence_item_added, val, sequence_item_index } }));

return make_control_protocol_message_response(handle, { is_deprecated ? nmos::nc_method_status::method_deprecated : nmos::fields::nc::is_deprecated(property) ? nc_method_status::property_deprecated : nc_method_status::ok }, sequence_item_index);
return make_control_protocol_message_response(handle, { is_deprecated ? nmos::nc_method_status::method_deprecated : nmos::fields::nc::is_deprecated(property) ? nc_method_status::property_deprecated : nc_method_status::ok }, sequence_item_index);
}
catch (const nmos::control_protocol_exception& e)
{
slog::log<slog::severities::error>(gate, SLOG_FLF) << "Add sequence item: " << property_id.serialize() << " value: " << val.serialize() << " error: " << e.what();

return make_control_protocol_message_response(handle, { nc_method_status::parameter_error });
}
}

// unknown property
Expand Down
Loading

0 comments on commit 0bed427

Please sign in to comment.