1
+ #include " nmos/configuration_methods.h"
2
+
3
+ #include < boost/range/adaptor/filtered.hpp>
4
+ #include " cpprest/json_utils.h"
5
+ #include " nmos/configuration_handlers.h"
6
+ #include " nmos/configuration_utils.h"
7
+ #include " nmos/control_protocol_resource.h"
8
+ #include " nmos/control_protocol_resources.h"
9
+ #include " nmos/control_protocol_state.h"
10
+ #include " nmos/control_protocol_utils.h"
11
+ #include " nmos/slog.h"
12
+
13
+ namespace nmos
14
+ {
15
+ namespace details
16
+ {
17
+ web::json::value make_property_value_holders (const nmos::resource& resource, nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor)
18
+ {
19
+ using web::json::value;
20
+
21
+ value property_value_holders = value::array ();
22
+
23
+ nmos::nc_class_id class_id = nmos::details::parse_nc_class_id (nmos::fields::nc::class_id (resource.data ));
24
+
25
+ // make NcPropertyValueHolder objects
26
+ while (!class_id.empty ())
27
+ {
28
+ const auto & control_class_descriptor = get_control_protocol_class_descriptor (class_id);
29
+
30
+ for (const auto & property_descriptor : control_class_descriptor.property_descriptors .as_array ())
31
+ {
32
+ value property_value_holder = nmos::details::make_nc_property_value_holder (nmos::details::parse_nc_property_id (nmos::fields::nc::id (property_descriptor)), nmos::fields::nc::name (property_descriptor), nmos::fields::nc::type_name (property_descriptor), nmos::fields::nc::is_read_only (property_descriptor), resource.data .at (nmos::fields::nc::name (property_descriptor)));
33
+
34
+ web::json::push_back (property_value_holders, property_value_holder);
35
+ }
36
+ class_id.pop_back ();
37
+ }
38
+ return property_value_holders;
39
+ }
40
+
41
+ void populate_object_property_holder (const nmos::resources& resources, nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, const nmos::resource& resource, bool recurse, web::json::value& object_properties_holders)
42
+ {
43
+ using web::json::value;
44
+
45
+ // Get property_value_holders for this resource
46
+ const auto & property_value_holders = make_property_value_holders (resource, get_control_protocol_class_descriptor).as_array ();
47
+
48
+ const auto role_path = get_role_path (resources, resource);
49
+
50
+ auto object_properties_holder = nmos::details::make_nc_object_properties_holder (role_path, property_value_holders, nmos::fields::nc::is_rebuildable (resource.data ));
51
+
52
+ web::json::push_back (object_properties_holders, object_properties_holder);
53
+
54
+ // Recurse into members...if we want to...and the object has them
55
+ if (recurse && nmos::nc::is_block (nmos::details::parse_nc_class_id (nmos::fields::nc::class_id (resource.data ))))
56
+ {
57
+ if (resource.data .has_field (nmos::fields::nc::members))
58
+ {
59
+ const auto & members = nmos::fields::nc::members (resource.data );
60
+
61
+ for (const auto & member : members)
62
+ {
63
+ const auto & found = find_resource (resources, utility::s2us (std::to_string (nmos::fields::nc::oid (member))));
64
+
65
+ if (resources.end () != found)
66
+ {
67
+ populate_object_property_holder (resources, get_control_protocol_class_descriptor, *found, recurse, object_properties_holders);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ std::size_t generate_validation_fingerprint (const nmos::resources& resources, const nmos::resource& resource)
75
+ {
76
+ // Generate a hash based on structure of the Device Model
77
+ size_t hash (0 );
78
+
79
+ nmos::nc_class_id class_id = nmos::details::parse_nc_class_id (nmos::fields::nc::class_id (resource.data ));
80
+
81
+ boost::hash_combine (hash, class_id);
82
+ boost::hash_combine (hash, nmos::fields::nc::role (resource.data ));
83
+
84
+ // Recurse into members...if we want to...and the object has them
85
+ if (nmos::nc::is_block (nmos::details::parse_nc_class_id (nmos::fields::nc::class_id (resource.data ))))
86
+ {
87
+ if (resource.data .has_field (nmos::fields::nc::members))
88
+ {
89
+ const auto & members = nmos::fields::nc::members (resource.data );
90
+
91
+ // Generate hash for block members
92
+ for (const auto & member : members)
93
+ {
94
+ const auto & oid = nmos::fields::nc::oid (member);
95
+ const auto & found = find_resource (resources, utility::s2us (std::to_string (oid)));
96
+ if (resources.end () != found)
97
+ {
98
+ size_t sub_hash = generate_validation_fingerprint (resources, *found);
99
+ boost::hash_combine (hash, sub_hash);
100
+ }
101
+ }
102
+ }
103
+ }
104
+
105
+ return hash;
106
+ }
107
+ }
108
+
109
+ web::json::value get_properties_by_path (const nmos::resources& resources, const nmos::resource& resource, bool recurse, nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, nmos::get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor)
110
+ {
111
+ using web::json::value;
112
+ using web::json::value_of;
113
+
114
+ value object_properties_holders = value::array ();
115
+
116
+ details::populate_object_property_holder (resources, get_control_protocol_class_descriptor, resource, recurse, object_properties_holders);
117
+
118
+ size_t validation_fingerprint = details::generate_validation_fingerprint (resources, resource);
119
+
120
+ utility::ostringstream_t ss;
121
+ ss << validation_fingerprint;
122
+
123
+ auto bulk_values_holder = nmos::details::make_nc_bulk_values_holder (ss.str (), object_properties_holders);
124
+
125
+ return nmos::details::make_nc_method_result ({ nmos::nc_method_status::ok }, bulk_values_holder);
126
+ }
127
+
128
+ web::json::value validate_set_properties_by_path (nmos::resources& resources, const nmos::resource& resource, const web::json::value& backup_data_set, bool recurse, const web::json::value& restore_mode, nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, nmos::filter_property_value_holders_handler filter_property_value_holders, nmos::modify_rebuildable_block_handler modify_rebuildable_block)
129
+ {
130
+ // Do something with validation fingerprint?
131
+ const auto & object_properties_holders = nmos::fields::nc::values (backup_data_set);
132
+
133
+ const auto & object_properties_set_validation = apply_backup_data_set (resources, resource, object_properties_holders, recurse, restore_mode, true , get_control_protocol_class_descriptor, filter_property_value_holders, modify_rebuildable_block);
134
+
135
+ return nmos::details::make_nc_method_result ({ nmos::nc_method_status::ok }, object_properties_set_validation);
136
+ }
137
+
138
+ web::json::value set_properties_by_path (nmos::resources& resources, const nmos::resource& resource, const web::json::value& backup_data_set, bool recurse, const web::json::value& restore_mode, nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, nmos::filter_property_value_holders_handler filter_property_value_holders, nmos::modify_rebuildable_block_handler modify_rebuildable_block)
139
+ {
140
+ // Do something with validation fingerprint?
141
+ const auto & object_properties_holders = nmos::fields::nc::values (backup_data_set);
142
+
143
+ const auto & object_properties_set_validation = apply_backup_data_set (resources, resource, object_properties_holders, recurse, restore_mode, false , get_control_protocol_class_descriptor, filter_property_value_holders, modify_rebuildable_block);
144
+
145
+ return nmos::details::make_nc_method_result ({ nmos::nc_method_status::ok }, object_properties_set_validation);
146
+ }
147
+
148
+ }
0 commit comments