Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Development/nmos/configuration_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ namespace nmos
}

// Order role paths by length so we implicitly process blocks before the child objects of that block
std::sort(role_paths.begin(), role_paths.end(), [](auto a, auto b) { return a.size() < b.size(); });
std::sort(role_paths.begin(), role_paths.end(), [](const web::json::array& a, const web::json::array& b) { return a.size() < b.size(); });

for (const auto& role_path: role_paths)
{
Expand Down
6 changes: 5 additions & 1 deletion Development/nmos/control_protocol_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ namespace nmos
struct counter
{
utility::string_t name;
uint64_t value{0};
uint64_t value;
utility::string_t description;

counter() : name(), value(0), description() {}
counter(const utility::string_t& name, uint64_t value, const utility::string_t& description)
: name(name), value(value), description(description) {}
};
}
typedef std::function<std::vector<nc::counter>(void)> get_packet_counters_handler;
Expand Down
152 changes: 76 additions & 76 deletions Development/nmos/control_protocol_resource.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Development/nmos/control_protocol_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ namespace nmos
// only update pending received time if not already set
if (pending_received_time.as_integer() == 0)
{
if (!set_property(resources, oid, status_pending_received_time_field_name, now_time, gate))
if (!set_property(resources, oid, status_pending_received_time_field_name, static_cast<int64_t>(now_time), gate))
{
return false;
}
Expand Down Expand Up @@ -797,7 +797,7 @@ namespace nmos
{
const auto& class_id = nc::details::parse_class_id(nmos::fields::nc::class_id(descriptor));

if (include_derived) { return !boost::find_first(class_id, class_id_).empty(); }
if (include_derived) { return class_id_.size() <= class_id.size() && std::equal(class_id_.begin(), class_id_.end(), class_id.begin()); }
else { return class_id == class_id_; }
};

Expand Down
50 changes: 25 additions & 25 deletions Development/nmos/control_protocol_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,80 +195,80 @@ namespace nmos
namespace details
{
// Deprecated: use nc::details::get_runtime_property_constraints
inline web::json::value get_runtime_property_constraints(const nc_property_id& property_id, const web::json::value& runtime_property_constraints_list) { return nc::details::get_runtime_property_constraints(property_id, runtime_property_constraints_list); };
inline web::json::value get_runtime_property_constraints(const nc_property_id& property_id, const web::json::value& runtime_property_constraints_list) { return nc::details::get_runtime_property_constraints(property_id, runtime_property_constraints_list); }

// Deprecated: use nc::details::get_datatype_descriptor
inline web::json::value get_datatype_descriptor(const web::json::value& type_name, get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype) { return nc::details::get_datatype_descriptor(type_name, get_control_protocol_datatype); };
inline web::json::value get_datatype_descriptor(const web::json::value& type_name, get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype) { return nc::details::get_datatype_descriptor(type_name, get_control_protocol_datatype); }

// Deprecated: use nc::details::get_datatype_constraints
inline web::json::value get_datatype_constraints(const web::json::value& type_name, get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype) { return nc::details::get_datatype_constraints(type_name, get_control_protocol_datatype); };
inline web::json::value get_datatype_constraints(const web::json::value& type_name, get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype) { return nc::details::get_datatype_constraints(type_name, get_control_protocol_datatype); }

struct datatype_constraints_validation_parameters
{
web::json::value datatype_descriptor;
get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor;
};
// Deprecated: use nc::details::constraints_validation
inline void constraints_validation(const web::json::value& value, const web::json::value& runtime_property_constraints, const web::json::value& property_constraints, const datatype_constraints_validation_parameters& params) { return nc::details::constraints_validation(value, runtime_property_constraints, property_constraints, nc::details::datatype_constraints_validation_parameters{params.datatype_descriptor, params.get_control_protocol_datatype_descriptor}); };
inline void constraints_validation(const web::json::value& value, const web::json::value& runtime_property_constraints, const web::json::value& property_constraints, const datatype_constraints_validation_parameters& params) { return nc::details::constraints_validation(value, runtime_property_constraints, property_constraints, nc::details::datatype_constraints_validation_parameters{params.datatype_descriptor, params.get_control_protocol_datatype_descriptor}); }

// Deprecated: use nc::details::method_parameter_constraints_validation
inline void method_parameter_constraints_validation(const web::json::value& data, const web::json::value& property_constraints, const datatype_constraints_validation_parameters& params) { return nc::details::method_parameter_constraints_validation(data, property_constraints, nc::details::datatype_constraints_validation_parameters{params.datatype_descriptor, params.get_control_protocol_datatype_descriptor}); };
inline void method_parameter_constraints_validation(const web::json::value& data, const web::json::value& property_constraints, const datatype_constraints_validation_parameters& params) { return nc::details::method_parameter_constraints_validation(data, property_constraints, nc::details::datatype_constraints_validation_parameters{params.datatype_descriptor, params.get_control_protocol_datatype_descriptor}); }
}

// Deprecated: use nc::is_block
inline bool is_nc_block(const nc_class_id& class_id) { return nc::is_block(class_id); };
inline bool is_nc_block(const nc_class_id& class_id) { return nc::is_block(class_id); }

// Deprecated: use nc::is_worker
inline bool is_nc_worker(const nc_class_id& class_id) { return nc::is_worker(class_id); };
inline bool is_nc_worker(const nc_class_id& class_id) { return nc::is_worker(class_id); }

// Deprecated: use nc::is_manager
inline bool is_nc_manager(const nc_class_id& class_id) { return nc::is_manager(class_id); };
inline bool is_nc_manager(const nc_class_id& class_id) { return nc::is_manager(class_id); }

// Deprecated: use nc::is_device_manager
inline bool is_nc_device_manager(const nc_class_id& class_id) { return nc::is_device_manager(class_id); };
inline bool is_nc_device_manager(const nc_class_id& class_id) { return nc::is_device_manager(class_id); }

// Deprecated: use nc::is_class_manager
inline bool is_nc_class_manager(const nc_class_id& class_id) { return nc::is_class_manager(class_id); };
inline bool is_nc_class_manager(const nc_class_id& class_id) { return nc::is_class_manager(class_id); }

// Deprecated: use nc::make_class_id
inline nc_class_id make_nc_class_id(const nc_class_id& prefix, int32_t authority_key, const std::vector<int32_t>& suffix) { return nc::make_class_id(prefix, authority_key, suffix); };
inline nc_class_id make_nc_class_id(const nc_class_id& prefix, const std::vector<int32_t>& suffix) { return nc::make_class_id(prefix, suffix); };
inline nc_class_id make_nc_class_id(const nc_class_id& prefix, int32_t authority_key, const std::vector<int32_t>& suffix) { return nc::make_class_id(prefix, authority_key, suffix); }
inline nc_class_id make_nc_class_id(const nc_class_id& prefix, const std::vector<int32_t>& suffix) { return nc::make_class_id(prefix, suffix); }

// Deprecated: use nc::find_property_descriptor
inline web::json::value find_property_descriptor(const nc_property_id& property_id, const nc_class_id& class_id, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor) { return nc::find_property_descriptor(property_id, class_id, get_control_protocol_class_descriptor); };
inline web::json::value find_property_descriptor(const nc_property_id& property_id, const nc_class_id& class_id, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor) { return nc::find_property_descriptor(property_id, class_id, get_control_protocol_class_descriptor); }

// Deprecated: use nc::get_member_descriptors
inline void get_member_descriptors(const resources& resources, const resource& resource, bool recurse, web::json::array& descriptors) { return nc::get_member_descriptors(resources, resource, recurse, descriptors); };
inline void get_member_descriptors(const resources& resources, const resource& resource, bool recurse, web::json::array& descriptors) { return nc::get_member_descriptors(resources, resource, recurse, descriptors); }

// Deprecated: use nc::find_members_by_role
inline void find_members_by_role(const resources& resources, const resource& resource, const utility::string_t& role, bool match_whole_string, bool case_sensitive, bool recurse, web::json::array& nc_block_member_descriptors) { return nc::find_members_by_role(resources, resource, role, match_whole_string, case_sensitive, recurse, nc_block_member_descriptors); };
inline void find_members_by_role(const resources& resources, const resource& resource, const utility::string_t& role, bool match_whole_string, bool case_sensitive, bool recurse, web::json::array& nc_block_member_descriptors) { return nc::find_members_by_role(resources, resource, role, match_whole_string, case_sensitive, recurse, nc_block_member_descriptors); }

// Deprecated: use nc::find_members_by_class_id
inline void find_members_by_class_id(const resources& resources, const resource& resource, const nc_class_id& class_id, bool include_derived, bool recurse, web::json::array& descriptors) { return nc::find_members_by_class_id(resources, resource, class_id, include_derived, recurse, descriptors); };
inline void find_members_by_class_id(const resources& resources, const resource& resource, const nc_class_id& class_id, bool include_derived, bool recurse, web::json::array& descriptors) { return nc::find_members_by_class_id(resources, resource, class_id, include_derived, recurse, descriptors); }

// Deprecated: use nc::push_back
inline void push_back(control_protocol_resource& nc_block_resource, const control_protocol_resource& resource) { return nc::push_back(nc_block_resource, resource); };
inline void push_back(control_protocol_resource& nc_block_resource, const control_protocol_resource& resource) { return nc::push_back(nc_block_resource, resource); }

// Deprecated: use nc::insert_resource
inline std::pair<resources::iterator, bool> insert_control_protocol_resource(resources& resources, resource&& resource) { return nc::insert_resource(resources, std::move(resource)); };
inline std::pair<resources::iterator, bool> insert_control_protocol_resource(resources& resources, resource&& resource) { return nc::insert_resource(resources, std::move(resource)); }

// Deprecated: use nc::modify_resource
inline bool modify_control_protocol_resource(resources& resources, const id& id, std::function<void(resource&)> modifier, const web::json::value& notification_event = web::json::value::null()) { return nc::modify_resource(resources, id, modifier, notification_event); };
inline bool modify_control_protocol_resource(resources& resources, const id& id, std::function<void(resource&)> modifier, const web::json::value& notification_event = web::json::value::null()) { return nc::modify_resource(resources, id, modifier, notification_event); }

// Deprecated: use nc::erase_resource
inline resources::size_type erase_control_protocol_resource(resources& resources, const id& id) { return nc::erase_resource(resources, id); };
inline resources::size_type erase_control_protocol_resource(resources& resources, const id& id) { return nc::erase_resource(resources, id); }

// Deprecated: use nc::find_resource
inline resources::const_iterator find_control_protocol_resource(resources& resources, type type, const id& id) { return nc::find_resource(resources, type, id); };
inline resources::const_iterator find_control_protocol_resource(resources& resources, type type, const id& id) { return nc::find_resource(resources, type, id); }

// Deprecated: use nc::method_parameters_contraints_validation
inline void method_parameters_contraints_validation(const web::json::value& arguments, const web::json::value& nc_method_descriptor, get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor) { return nc::method_parameters_contraints_validation(arguments, nc_method_descriptor, get_control_protocol_datatype_descriptor); };
inline void method_parameters_contraints_validation(const web::json::value& arguments, const web::json::value& nc_method_descriptor, get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor) { return nc::method_parameters_contraints_validation(arguments, nc_method_descriptor, get_control_protocol_datatype_descriptor); }

// Deprecated: use nc::insert_notification_events
inline void insert_notification_events(resources& resources, const api_version& version, const api_version& downgrade_version, const type& type, const web::json::value& pre, const web::json::value& post, const web::json::value& event) { return nc::insert_notification_events(resources, version, downgrade_version, type, pre, post, event); };
inline void insert_notification_events(resources& resources, const api_version& version, const api_version& downgrade_version, const type& type, const web::json::value& pre, const web::json::value& post, const web::json::value& event) { return nc::insert_notification_events(resources, version, downgrade_version, type, pre, post, event); }

// Deprecated: use nc::get_property
inline web::json::value get_control_protocol_property(const resources& resources, nc_oid oid, const nc_property_id& property_id, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate) { return nc::get_property(resources, oid, property_id, get_control_protocol_class_descriptor, gate); };
inline web::json::value get_control_protocol_property(const resources& resources, nc_oid oid, const nc_property_id& property_id, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate) { return nc::get_property(resources, oid, property_id, get_control_protocol_class_descriptor, gate); }
}

#endif
#endif
2 changes: 1 addition & 1 deletion Development/nmos/node_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ namespace nmos
{
auto configuration_uri = web::uri_builder()
.set_scheme(nmos::http_scheme(settings))
.set_port(nmos::fields::connection_port(settings))
.set_port(nmos::fields::configuration_port(settings))
.set_path(U("/x-nmos/configuration/") + make_api_version(version));
auto type = U("urn:x-nmos:control:configuration/") + make_api_version(version);

Expand Down
81 changes: 79 additions & 2 deletions Development/nmos/test/control_protocol_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include "nmos/control_protocol_state.h"
#include "nmos/control_protocol_typedefs.h"
#include "nmos/control_protocol_utils.h"
#include "nmos/is04_versions.h"
#include "nmos/is12_versions.h"
#include "nmos/log_gate.h"
#include "nmos/slog.h"

#include "nmos/is04_versions.h"

#include "bst/test/test.h"

////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1177,3 +1177,80 @@ BST_TEST_CASE(testFindTouchpointResources)
BST_CHECK_EQUAL(touchpoint, resources.end());
}
}

////////////////////////////////////////////////////////////////////////////////////////////
BST_TEST_CASE(testFindMembersByClassId)
{
using web::json::value_of;
using web::json::value;

auto make_example_block_resource = [](const nmos::nc_class_id& class_id, nmos::nc_oid oid, nmos::nc_oid owner, const utility::string_t& role, const utility::string_t& user_label, const utility::string_t& description)
{
auto data = nmos::nc::details::make_block(class_id, oid, true, owner, role, value::string(user_label), description, value::null(), value::null(), true, value::array());

return nmos::control_protocol_resource{ nmos::is12_versions::v1_0, nmos::types::nc_worker, std::move(data), true };
};

auto make_example_worker_resource = [](const nmos::nc_class_id& class_id, nmos::nc_oid oid, nmos::nc_oid owner, const utility::string_t& role, const utility::string_t& user_label, const utility::string_t& description)
{
auto data = nmos::nc::details::make_worker(class_id, oid, true, owner, role, value::string(user_label), description, value::null(), value::null(), true);

return nmos::control_protocol_resource{ nmos::is12_versions::v1_0, nmos::types::nc_worker, std::move(data), true };
};

nmos::nc_oid oid = nmos::root_block_oid;

auto root_block = nmos::make_root_block();

// { 1, 1, 0, 1 }
const auto example_class_id_1 = nmos::nc::make_class_id(nmos::nc_block_class_id, 0, { 1 });
// { 1, 2, 0, 1, 1 }
const auto example_class_id_2 = nmos::nc::make_class_id(nmos::nc_worker_class_id, 0, { 1, 1 });

auto example_1 = make_example_block_resource(example_class_id_1, ++oid, nmos::root_block_oid, U("example block 1"), U("Example Block 1"), U("Example Block 1"));
auto example_2 = make_example_worker_resource(example_class_id_2, ++oid, nmos::root_block_oid, U("example block 2"), U("Example Block 2"), U("Example Block 2"));

nmos::nc::push_back(root_block, example_1);
nmos::nc::push_back(root_block, example_2);

nmos::resources resources;

// insert root block and all sub control protocol resources to resource list
nmos::nc::insert_root(resources, root_block);

// get root block
const auto found_root_block = nmos::find_resource_if(resources, nmos::types::nc_block, [&](const nmos::resource& resource)
{
return nmos::root_block_oid == nmos::fields::nc::oid(resource.data);
});

// search unknown class_id members
{
auto members = value::array();
nmos::nc::find_members_by_class_id(resources, *found_root_block, { 1, 0 }, true, true, members.as_array());
BST_REQUIRE_EQUAL(0, members.size());
}

// search all NcObject members
{
auto members = value::array();
nmos::nc::find_members_by_class_id(resources, *found_root_block, nmos::nc_object_class_id, true, true, members.as_array());
BST_REQUIRE_EQUAL(2, members.size());
}

// search all NcBlock members
{
auto members = value::array();
nmos::nc::find_members_by_class_id(resources, *found_root_block, nmos::nc_block_class_id, true, true, members.as_array());
BST_REQUIRE_EQUAL(1, members.size());
BST_REQUIRE_EQUAL(example_class_id_1, nmos::nc::details::parse_class_id(nmos::fields::nc::class_id(members.at(0))));
}

// search NcWorker members
{
auto members = value::array();
nmos::nc::find_members_by_class_id(resources, *found_root_block, nmos::nc_worker_class_id, true, true, members.as_array());
BST_REQUIRE_EQUAL(1, members.size());
BST_REQUIRE_EQUAL(example_class_id_2, nmos::nc::details::parse_class_id(nmos::fields::nc::class_id(members.at(0))));
}
}
Loading