forked from sony/nmos-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol_protocol_utils.h
More file actions
277 lines (205 loc) · 23.7 KB
/
control_protocol_utils.h
File metadata and controls
277 lines (205 loc) · 23.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#ifndef NMOS_CONTROL_PROTOCOL_UTILS_H
#define NMOS_CONTROL_PROTOCOL_UTILS_H
#include "cpprest/basic_utils.h"
#include "nmos/control_protocol_handlers.h"
namespace nmos
{
struct control_protocol_resource;
struct control_protocol_exception : std::runtime_error
{
control_protocol_exception(const std::string& message) : std::runtime_error(message) {}
};
namespace nc
{
namespace details
{
// get the runtime property constraints of a given property_id
web::json::value get_runtime_property_constraints(const nc_property_id& property_id, const web::json::value& runtime_property_constraints_list);
// get the datatype descriptor of a specific type_name
web::json::value get_datatype_descriptor(const web::json::value& type_name, get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype);
// get the datatype property constraints of a given type_name
web::json::value get_datatype_constraints(const web::json::value& type_name, get_control_protocol_datatype_descriptor_handler 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;
};
// multiple levels of constraints validation, may throw nmos::control_protocol_exception
// See https://specs.amwa.tv/ms-05-02/branches/v1.0.x/docs/Constraints.html
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);
// method parameter constraints validation, may throw nmos::control_protocol_exception
void method_parameter_constraints_validation(const web::json::value& data, const web::json::value& property_constraints, const datatype_constraints_validation_parameters& params);
// convert . delimited string into role path object
web::json::value parse_role_path(const utility::string_t& role_path);
bool set_monitor_status(resources& resources, nc_oid oid, int status, const utility::string_t& status_message, const nc_property_id& status_property_id,
const nc_property_id& status_message_property_id,
const nc_property_id& status_transition_counter_property_id,
const utility::string_t& status_pending_received_time_field_name,
get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor,
slog::base_gate& gate);
bool set_monitor_status_with_delay(resources& resources, nc_oid oid, int status, const utility::string_t& status_message,
const nc_property_id& status_property_id,
const nc_property_id& status_message_property_id,
const nc_property_id& status_transition_counter_property_id,
const utility::string_t& status_pending_field_name,
const utility::string_t& status_message_pending_time_field_name,
const utility::string_t& status_pending_received_time_field_name,
long long current_time,
monitor_status_pending_handler monitor_status_pending,
get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor,
slog::base_gate& gate);
bool update_receiver_monitor_overall_status(resources& resources, nc_oid oid, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
bool update_sender_monitor_overall_status(resources& resources, nc_oid oid, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
}
// is the given class_id a NcBlock
bool is_block(const nc_class_id& class_id);
// is the given class_id a NcWorker
bool is_worker(const nc_class_id& class_id);
// is the given class_id a NcManager
bool is_manager(const nc_class_id& class_id);
// is the given class_id a NcDeviceManager
bool is_device_manager(const nc_class_id& class_id);
// is the given class_id a NcClassManager
bool is_class_manager(const nc_class_id& class_id);
// is the given class_id a NcStatusMonitor
bool is_status_monitor(const nc_class_id& class_id);
// is the given class_id a NcSenderMonitor
bool is_sender_monitor(const nc_class_id& class_id);
// construct NcClassId
nc_class_id make_class_id(const nc_class_id& prefix, int32_t authority_key, const std::vector<int32_t>& suffix);
nc_class_id make_class_id(const nc_class_id& prefix, const std::vector<int32_t>& suffix); // using default authority_key 0
// find control class property descriptor (NcPropertyDescriptor)
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);
// get block memeber descriptors
void get_member_descriptors(const resources& resources, const resource& resource, bool recurse, web::json::array& descriptors);
// find members with given role name or fragment
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);
// find members with given class id
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);
// push control protocol resource into other control protocol NcBlock resource
void push_back(control_protocol_resource& nc_block_resource, const control_protocol_resource& resource);
// insert root block and all sub control protocol resources
void insert_root(resources& resources, control_protocol_resource& root);
// insert a control protocol resource
std::pair<resources::iterator, bool> insert_resource(resources& resources, resource&& resource);
// modify a control protocol resource, and insert notification event to all subscriptions
bool modify_resource(resources& resources, const id& id, std::function<void(resource&)> modifier, const web::json::value& notification_event=web::json::value::null());
// erase a control protocol resource
resources::size_type erase_resource(resources& resources, const id& id);
// find the control protocol resource which is associated with the given IS-04/IS-05/IS-08 resource id
resources::const_iterator find_resource(resources& resources, type type, const id& id);
// find resource based on role path.
resources::const_iterator find_resource_by_role_path(const resources& resources, const web::json::array& role_path);
// find resource based on role path. Roles in role path string must be delimited with a '.'
resources::const_iterator find_resource_by_role_path(const resources& resources, const utility::string_t& role_path);
// method parameters constraints validation, may throw nmos::control_protocol_exception
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);
// Validate that the resource has been correctly constructed according to the class_descriptor
void validate_resource(const resource& resource, const experimental::control_class_descriptor& class_descriptor);
resources::const_iterator find_touchpoint_resource(const resources& resources, const resource& resource);
// insert 'value changed', 'sequence item added', 'sequence item changed' or 'sequence item removed' notification events into all grains whose subscriptions match the specified version, type and "pre" or "post" values
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);
// get property value given oid and property_id
web::json::value get_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);
// set property value given oid and property_id and notify
bool set_property_and_notify(resources& resources, nc_oid oid, const nc_property_id& property_id, const web::json::value& value, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// set hidden property but don't notify, as property isn't part of class definition
bool set_property(resources& resources, nc_oid oid, const utility::string_t& property_name, const web::json::value& value, slog::base_gate& gate);
// Set link status and link status message
bool set_receiver_monitor_link_status(resources& resources, nc_oid oid, nmos::nc_link_status::status link_status, const utility::string_t& link_status_message, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set link status and status message and apply status reporting delay
bool set_receiver_monitor_link_status_with_delay(resources& resources, nc_oid oid, nmos::nc_link_status::status link_status, const utility::string_t& link_status_message, monitor_status_pending_handler monitor_status_pending, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set connection status and connection status message
bool set_receiver_monitor_connection_status(resources& resources, nc_oid oid, nmos::nc_connection_status::status connection_status, const utility::string_t& connection_status_message, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set connection status and status message and apply status reporting delay
bool set_receiver_monitor_connection_status_with_delay(resources& resources, nc_oid oid, nmos::nc_connection_status::status connection_status, const utility::string_t& connection_status_message, monitor_status_pending_handler monitor_status_pending, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set external synchronization status and external synchronization status message
bool set_receiver_monitor_external_synchronization_status(resources& resources, nc_oid oid, nmos::nc_synchronization_status::status external_synchronization_status, const utility::string_t& external_synchronization_status_message, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set external synchronization status and status message and apply status reporting delay
bool set_receiver_monitor_external_synchronization_status_with_delay(resources& resources, nc_oid oid, nmos::nc_synchronization_status::status external_synchronization_status, const utility::string_t& external_synchronization_status_message, monitor_status_pending_handler monitor_status_pending, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set stream status and stream status message
bool set_receiver_monitor_stream_status(resources& resources, nc_oid oid, nmos::nc_stream_status::status stream_status, const utility::string_t& stream_status_message, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set stream status and status message and apply status reporting delay
bool set_receiver_monitor_stream_status_with_delay(resources& resources, nc_oid oid, nmos::nc_stream_status::status stream_status, const utility::string_t& stream_status_message, monitor_status_pending_handler monitor_status_pending, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set synchronization source id
bool set_monitor_synchronization_source_id(resources& resources, nc_oid oid, const bst::optional<utility::string_t>& source_id, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Call when monitor is activated
bool activate_monitor(resources& resources, nc_oid oid, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, nmos::get_control_protocol_method_descriptor_handler get_control_protocol_method_descriptor, slog::base_gate& gate);
// Call when monitor is deactivated
bool deactivate_monitor(resources& resources, nc_oid oid, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set link status and link status message
bool set_sender_monitor_link_status(resources& resources, nc_oid oid, nmos::nc_link_status::status link_status, const utility::string_t& link_status_message, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set link status and status message and apply status reporting delay
bool set_sender_monitor_link_status_with_delay(resources& resources, nc_oid oid, nmos::nc_link_status::status link_status, const utility::string_t& link_status_message, monitor_status_pending_handler monitor_status_pending, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set transmission status and transmission status message
bool set_sender_monitor_transmission_status(resources& resources, nc_oid oid, nmos::nc_transmission_status::status transmission_status, const utility::string_t& transmission_status_message, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set transmission status and status message and apply status reporting delay
bool set_sender_monitor_transmission_status_with_delay(resources& resources, nc_oid oid, nmos::nc_transmission_status::status transmission_status, const utility::string_t& transmission_status_message, monitor_status_pending_handler monitor_status_pending, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set external synchronization status and external synchronization status message
bool set_sender_monitor_external_synchronization_status(resources& resources, nc_oid oid, nmos::nc_synchronization_status::status external_synchronization_status, const utility::string_t& external_synchronization_status_message, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set external synchronization status and status message and apply status reporting delay
bool set_sender_monitor_external_synchronization_status_with_delay(resources& resources, nc_oid oid, nmos::nc_synchronization_status::status external_synchronization_status, const utility::string_t& external_synchronization_status_message, monitor_status_pending_handler monitor_status_pending, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set essence status and stream status message
bool set_sender_monitor_essence_status(resources& resources, nc_oid oid, nmos::nc_essence_status::status essence_status, const utility::string_t& essence_status_message, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Set essence status and status message and apply status reporting delay
bool set_sender_monitor_essence_status_with_delay(resources& resources, nc_oid oid, nmos::nc_essence_status::status essence_status, const utility::string_t& essence_status_message, monitor_status_pending_handler monitor_status_pending, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Get property by name, rather than by property id. Used to get "hidden" resource properties
web::json::value get_property(const resources& resources, nc_oid oid, const utility::string_t& property_name, slog::base_gate& gate);
}
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); }
// 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); }
// 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); }
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}); }
// 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}); }
}
// Deprecated: use nc::is_block
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); }
// Deprecated: use nc::is_manager
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); }
// 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); }
// 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); }
// 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); }
// 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); }
// 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); }
// 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); }
// 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); }
// 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)); }
// 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); }
// Deprecated: use nc::erase_resource
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); }
// 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); }
// 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); }
// 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); }
}
#endif