Skip to content

Commit cc8e601

Browse files
Merge pull request #468 from lo-simon/fix-nc
Minor fix on IS-12, IS-14 and C++11 Compatibility
2 parents 8080930 + d8fc1a6 commit cc8e601

File tree

7 files changed

+189
-108
lines changed

7 files changed

+189
-108
lines changed

Development/nmos/configuration_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ namespace nmos
724724
}
725725

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

729729
for (const auto& role_path: role_paths)
730730
{

Development/nmos/control_protocol_handlers.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ namespace nmos
4949
struct counter
5050
{
5151
utility::string_t name;
52-
uint64_t value{0};
52+
uint64_t value;
5353
utility::string_t description;
54+
55+
counter() : name(), value(0), description() {}
56+
counter(const utility::string_t& name, uint64_t value, const utility::string_t& description)
57+
: name(name), value(value), description(description) {}
5458
};
5559
}
5660
typedef std::function<std::vector<nc::counter>(void)> get_packet_counters_handler;

Development/nmos/control_protocol_resource.h

Lines changed: 76 additions & 76 deletions
Large diffs are not rendered by default.

Development/nmos/control_protocol_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ namespace nmos
502502
// only update pending received time if not already set
503503
if (pending_received_time.as_integer() == 0)
504504
{
505-
if (!set_property(resources, oid, status_pending_received_time_field_name, now_time, gate))
505+
if (!set_property(resources, oid, status_pending_received_time_field_name, static_cast<int64_t>(now_time), gate))
506506
{
507507
return false;
508508
}
@@ -797,7 +797,7 @@ namespace nmos
797797
{
798798
const auto& class_id = nc::details::parse_class_id(nmos::fields::nc::class_id(descriptor));
799799

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

Development/nmos/control_protocol_utils.h

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -195,80 +195,80 @@ namespace nmos
195195
namespace details
196196
{
197197
// Deprecated: use nc::details::get_runtime_property_constraints
198-
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); };
198+
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); }
199199

200200
// Deprecated: use nc::details::get_datatype_descriptor
201-
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); };
201+
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); }
202202

203203
// Deprecated: use nc::details::get_datatype_constraints
204-
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); };
204+
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); }
205205

206206
struct datatype_constraints_validation_parameters
207207
{
208208
web::json::value datatype_descriptor;
209209
get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor;
210210
};
211211
// Deprecated: use nc::details::constraints_validation
212-
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}); };
212+
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}); }
213213

214214
// Deprecated: use nc::details::method_parameter_constraints_validation
215-
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}); };
215+
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}); }
216216
}
217217

218218
// Deprecated: use nc::is_block
219-
inline bool is_nc_block(const nc_class_id& class_id) { return nc::is_block(class_id); };
219+
inline bool is_nc_block(const nc_class_id& class_id) { return nc::is_block(class_id); }
220220

221221
// Deprecated: use nc::is_worker
222-
inline bool is_nc_worker(const nc_class_id& class_id) { return nc::is_worker(class_id); };
222+
inline bool is_nc_worker(const nc_class_id& class_id) { return nc::is_worker(class_id); }
223223

224224
// Deprecated: use nc::is_manager
225-
inline bool is_nc_manager(const nc_class_id& class_id) { return nc::is_manager(class_id); };
225+
inline bool is_nc_manager(const nc_class_id& class_id) { return nc::is_manager(class_id); }
226226

227227
// Deprecated: use nc::is_device_manager
228-
inline bool is_nc_device_manager(const nc_class_id& class_id) { return nc::is_device_manager(class_id); };
228+
inline bool is_nc_device_manager(const nc_class_id& class_id) { return nc::is_device_manager(class_id); }
229229

230230
// Deprecated: use nc::is_class_manager
231-
inline bool is_nc_class_manager(const nc_class_id& class_id) { return nc::is_class_manager(class_id); };
231+
inline bool is_nc_class_manager(const nc_class_id& class_id) { return nc::is_class_manager(class_id); }
232232

233233
// Deprecated: use nc::make_class_id
234-
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); };
235-
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); };
234+
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); }
235+
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); }
236236

237237
// Deprecated: use nc::find_property_descriptor
238-
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); };
238+
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); }
239239

240240
// Deprecated: use nc::get_member_descriptors
241-
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); };
241+
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); }
242242

243243
// Deprecated: use nc::find_members_by_role
244-
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); };
244+
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); }
245245

246246
// Deprecated: use nc::find_members_by_class_id
247-
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); };
247+
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); }
248248

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

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

255255
// Deprecated: use nc::modify_resource
256-
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); };
256+
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); }
257257

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

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

264264
// Deprecated: use nc::method_parameters_contraints_validation
265-
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); };
265+
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); }
266266

267267
// Deprecated: use nc::insert_notification_events
268-
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); };
268+
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); }
269269

270270
// Deprecated: use nc::get_property
271-
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); };
271+
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); }
272272
}
273273

274-
#endif
274+
#endif

Development/nmos/node_resources.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ namespace nmos
159159
{
160160
auto configuration_uri = web::uri_builder()
161161
.set_scheme(nmos::http_scheme(settings))
162-
.set_port(nmos::fields::connection_port(settings))
162+
.set_port(nmos::fields::configuration_port(settings))
163163
.set_path(U("/x-nmos/configuration/") + make_api_version(version));
164164
auto type = U("urn:x-nmos:control:configuration/") + make_api_version(version);
165165

Development/nmos/test/control_protocol_utils_test.cpp

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#include "nmos/control_protocol_state.h"
77
#include "nmos/control_protocol_typedefs.h"
88
#include "nmos/control_protocol_utils.h"
9+
#include "nmos/is04_versions.h"
10+
#include "nmos/is12_versions.h"
911
#include "nmos/log_gate.h"
1012
#include "nmos/slog.h"
1113

12-
#include "nmos/is04_versions.h"
13-
1414
#include "bst/test/test.h"
1515

1616
////////////////////////////////////////////////////////////////////////////////////////////
@@ -1177,3 +1177,80 @@ BST_TEST_CASE(testFindTouchpointResources)
11771177
BST_CHECK_EQUAL(touchpoint, resources.end());
11781178
}
11791179
}
1180+
1181+
////////////////////////////////////////////////////////////////////////////////////////////
1182+
BST_TEST_CASE(testFindMembersByClassId)
1183+
{
1184+
using web::json::value_of;
1185+
using web::json::value;
1186+
1187+
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)
1188+
{
1189+
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());
1190+
1191+
return nmos::control_protocol_resource{ nmos::is12_versions::v1_0, nmos::types::nc_worker, std::move(data), true };
1192+
};
1193+
1194+
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)
1195+
{
1196+
auto data = nmos::nc::details::make_worker(class_id, oid, true, owner, role, value::string(user_label), description, value::null(), value::null(), true);
1197+
1198+
return nmos::control_protocol_resource{ nmos::is12_versions::v1_0, nmos::types::nc_worker, std::move(data), true };
1199+
};
1200+
1201+
nmos::nc_oid oid = nmos::root_block_oid;
1202+
1203+
auto root_block = nmos::make_root_block();
1204+
1205+
// { 1, 1, 0, 1 }
1206+
const auto example_class_id_1 = nmos::nc::make_class_id(nmos::nc_block_class_id, 0, { 1 });
1207+
// { 1, 2, 0, 1, 1 }
1208+
const auto example_class_id_2 = nmos::nc::make_class_id(nmos::nc_worker_class_id, 0, { 1, 1 });
1209+
1210+
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"));
1211+
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"));
1212+
1213+
nmos::nc::push_back(root_block, example_1);
1214+
nmos::nc::push_back(root_block, example_2);
1215+
1216+
nmos::resources resources;
1217+
1218+
// insert root block and all sub control protocol resources to resource list
1219+
nmos::nc::insert_root(resources, root_block);
1220+
1221+
// get root block
1222+
const auto found_root_block = nmos::find_resource_if(resources, nmos::types::nc_block, [&](const nmos::resource& resource)
1223+
{
1224+
return nmos::root_block_oid == nmos::fields::nc::oid(resource.data);
1225+
});
1226+
1227+
// search unknown class_id members
1228+
{
1229+
auto members = value::array();
1230+
nmos::nc::find_members_by_class_id(resources, *found_root_block, { 1, 0 }, true, true, members.as_array());
1231+
BST_REQUIRE_EQUAL(0, members.size());
1232+
}
1233+
1234+
// search all NcObject members
1235+
{
1236+
auto members = value::array();
1237+
nmos::nc::find_members_by_class_id(resources, *found_root_block, nmos::nc_object_class_id, true, true, members.as_array());
1238+
BST_REQUIRE_EQUAL(2, members.size());
1239+
}
1240+
1241+
// search all NcBlock members
1242+
{
1243+
auto members = value::array();
1244+
nmos::nc::find_members_by_class_id(resources, *found_root_block, nmos::nc_block_class_id, true, true, members.as_array());
1245+
BST_REQUIRE_EQUAL(1, members.size());
1246+
BST_REQUIRE_EQUAL(example_class_id_1, nmos::nc::details::parse_class_id(nmos::fields::nc::class_id(members.at(0))));
1247+
}
1248+
1249+
// search NcWorker members
1250+
{
1251+
auto members = value::array();
1252+
nmos::nc::find_members_by_class_id(resources, *found_root_block, nmos::nc_worker_class_id, true, true, members.as_array());
1253+
BST_REQUIRE_EQUAL(1, members.size());
1254+
BST_REQUIRE_EQUAL(example_class_id_2, nmos::nc::details::parse_class_id(nmos::fields::nc::class_id(members.at(0))));
1255+
}
1256+
}

0 commit comments

Comments
 (0)