Skip to content

Commit f1b4898

Browse files
committed
Rename Read/Write Node API to Annotation API
(cf. AMWA-TV/is-13#19)
1 parent bf67e66 commit f1b4898

19 files changed

+106
-83
lines changed

Development/cmake/NmosCppLibraries.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,12 @@ set(NMOS_IS13_SCHEMAS_HEADERS
695695
set(NMOS_IS13_V1_0_TAG v1.0-dev)
696696

697697
set(NMOS_IS13_V1_0_SCHEMAS_JSON
698+
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/annotationapi-base.json
699+
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/annotationapi-node-base.json
698700
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/error.json
699701
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/resource_core.json
700702
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/resource_core_patch.json
701703
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/resource_cores.json
702-
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/rwnodeapi-base.json
703704
)
704705

705706
set(NMOS_IS13_SCHEMAS_JSON_MATCH "third_party/is-13/([^/]+)/APIs/schemas/([^;]+)\\.json")
@@ -813,6 +814,7 @@ set(NMOS_CPP_CPPREST_DETAILS_HEADERS
813814
set(NMOS_CPP_NMOS_SOURCES
814815
nmos/activation_utils.cpp
815816
nmos/admin_ui.cpp
817+
nmos/annotation_api.cpp
816818
nmos/api_downgrade.cpp
817819
nmos/api_utils.cpp
818820
nmos/capabilities.cpp
@@ -864,7 +866,6 @@ set(NMOS_CPP_NMOS_SOURCES
864866
nmos/registry_server.cpp
865867
nmos/resource.cpp
866868
nmos/resources.cpp
867-
nmos/rwnode_api.cpp
868869
nmos/schemas_api.cpp
869870
nmos/sdp_utils.cpp
870871
nmos/server.cpp
@@ -879,6 +880,7 @@ set(NMOS_CPP_NMOS_HEADERS
879880
nmos/activation_mode.h
880881
nmos/activation_utils.h
881882
nmos/admin_ui.h
883+
nmos/annotation_api.h
882884
nmos/api_downgrade.h
883885
nmos/api_utils.h
884886
nmos/api_version.h
@@ -958,7 +960,6 @@ set(NMOS_CPP_NMOS_HEADERS
958960
nmos/registry_server.h
959961
nmos/resource.h
960962
nmos/resources.h
961-
nmos/rwnode_api.h
962963
nmos/schemas_api.h
963964
nmos/sdp_utils.h
964965
nmos/server.h

Development/cmake/NmosCppTest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ set(NMOS_CPP_TEST_MDNS_TEST_HEADERS
3939
)
4040

4141
set(NMOS_CPP_TEST_NMOS_TEST_SOURCES
42+
nmos/test/annotation_api_test.cpp
4243
nmos/test/api_utils_test.cpp
4344
nmos/test/capabilities_test.cpp
4445
nmos/test/channels_test.cpp
4546
nmos/test/did_sdid_test.cpp
4647
nmos/test/event_type_test.cpp
4748
nmos/test/json_validator_test.cpp
4849
nmos/test/paging_utils_test.cpp
49-
nmos/test/rwnode_api_test.cpp
5050
nmos/test/query_api_test.cpp
5151
nmos/test/sdp_utils_test.cpp
5252
nmos/test/system_resources_test.cpp

Development/nmos-cpp-node/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
//"events_port": 3216,
136136
//"events_ws_port": 3217,
137137
//"channelmapping_port": 3215,
138-
//"rwnode_port": 3212,
138+
//"annotation_port": 3212,
139139
// system_port [node]: used to construct request URLs for the System API (if not discovered via DNS-SD)
140140
//"system_port": 10641,
141141

Development/nmos-cpp-node/node_implementation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,13 +1270,13 @@ nmos::channelmapping_activation_handler make_node_implementation_channelmapping_
12701270
}
12711271

12721272
// Example Read/Write Node API patch callback to update resource labels, descriptions and tags
1273-
nmos::rwnode_patch_merger make_node_implementation_rwnode_patch_merger(slog::base_gate& gate)
1273+
nmos::annotation_patch_merger make_node_implementation_annotation_patch_merger(slog::base_gate& gate)
12741274
{
12751275
return [&gate](const nmos::resource& resource, web::json::value& value, const web::json::value& patch)
12761276
{
12771277
const std::pair<nmos::id, nmos::type> id_type{ resource.id, resource.type };
12781278
slog::log<slog::severities::info>(gate, SLOG_FLF) << nmos::stash_category(impl::categories::node_implementation) << "Updating " << id_type;
1279-
nmos::details::merge_rwnode_patch(value, patch);
1279+
nmos::details::merge_annotation_patch(value, patch);
12801280
};
12811281
}
12821282

@@ -1434,5 +1434,5 @@ nmos::experimental::node_implementation make_node_implementation(nmos::node_mode
14341434
.on_connection_activated(make_node_implementation_connection_activation_handler(model, gate))
14351435
.on_validate_channelmapping_output_map(make_node_implementation_map_validator()) // may be omitted if not required
14361436
.on_channelmapping_activated(make_node_implementation_channelmapping_activation_handler(gate))
1437-
.on_merge_rwnode_patch(make_node_implementation_rwnode_patch_merger(gate)); // may be omitted if not required
1437+
.on_merge_annotation_patch(make_node_implementation_annotation_patch_merger(gate)); // may be omitted if not required
14381438
}
Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "nmos/rwnode_api.h"
1+
#include "nmos/annotation_api.h"
22

33
#include <boost/algorithm/string/predicate.hpp>
44
#include <boost/range/adaptor/filtered.hpp>
@@ -11,39 +11,39 @@
1111

1212
namespace nmos
1313
{
14-
web::http::experimental::listener::api_router make_unmounted_rwnode_api(nmos::model& model, nmos::rwnode_patch_merger merge_patch, slog::base_gate& gate);
14+
web::http::experimental::listener::api_router make_unmounted_annotation_api(nmos::model& model, nmos::annotation_patch_merger merge_patch, slog::base_gate& gate);
1515

16-
web::http::experimental::listener::api_router make_rwnode_api(nmos::model& model, nmos::rwnode_patch_merger merge_patch, slog::base_gate& gate)
16+
web::http::experimental::listener::api_router make_annotation_api(nmos::model& model, nmos::annotation_patch_merger merge_patch, slog::base_gate& gate)
1717
{
1818
using namespace web::http::experimental::listener::api_router_using_declarations;
1919

20-
api_router rwnode_api;
20+
api_router annotation_api;
2121

22-
rwnode_api.support(U("/?"), methods::GET, [](http_request req, http_response res, const string_t&, const route_parameters&)
22+
annotation_api.support(U("/?"), methods::GET, [](http_request req, http_response res, const string_t&, const route_parameters&)
2323
{
2424
set_reply(res, status_codes::OK, nmos::make_sub_routes_body({ U("x-nmos/") }, req, res));
2525
return pplx::task_from_result(true);
2626
});
2727

28-
rwnode_api.support(U("/x-nmos/?"), methods::GET, [](http_request req, http_response res, const string_t&, const route_parameters&)
28+
annotation_api.support(U("/x-nmos/?"), methods::GET, [](http_request req, http_response res, const string_t&, const route_parameters&)
2929
{
30-
set_reply(res, status_codes::OK, nmos::make_sub_routes_body({ U("rwnode/") }, req, res));
30+
set_reply(res, status_codes::OK, nmos::make_sub_routes_body({ U("annotation/") }, req, res));
3131
return pplx::task_from_result(true);
3232
});
3333

3434
const auto versions = with_read_lock(model.mutex, [&model] { return nmos::is13_versions::from_settings(model.settings); });
35-
rwnode_api.support(U("/x-nmos/") + nmos::patterns::rwnode_api.pattern + U("/?"), methods::GET, [versions](http_request req, http_response res, const string_t&, const route_parameters&)
35+
annotation_api.support(U("/x-nmos/") + nmos::patterns::annotation_api.pattern + U("/?"), methods::GET, [versions](http_request req, http_response res, const string_t&, const route_parameters&)
3636
{
3737
set_reply(res, status_codes::OK, nmos::make_sub_routes_body(nmos::make_api_version_sub_routes(versions), req, res));
3838
return pplx::task_from_result(true);
3939
});
4040

41-
rwnode_api.mount(U("/x-nmos/") + nmos::patterns::rwnode_api.pattern + U("/") + nmos::patterns::version.pattern, make_unmounted_rwnode_api(model, std::move(merge_patch), gate));
41+
annotation_api.mount(U("/x-nmos/") + nmos::patterns::annotation_api.pattern + U("/") + nmos::patterns::version.pattern, make_unmounted_annotation_api(model, std::move(merge_patch), gate));
4242

43-
return rwnode_api;
43+
return annotation_api;
4444
}
4545

46-
web::json::value make_rwnode_patch(const nmos::resource& resource)
46+
web::json::value make_annotation_patch(const nmos::resource& resource)
4747
{
4848
using web::json::value_of;
4949
return value_of({
@@ -53,7 +53,7 @@ namespace nmos
5353
});
5454
}
5555

56-
web::json::value make_rwnode_response(const nmos::resource& resource)
56+
web::json::value make_annotation_response(const nmos::resource& resource)
5757
{
5858
using web::json::value_of;
5959
return value_of({
@@ -73,7 +73,7 @@ namespace nmos
7373
|| boost::algorithm::starts_with(key, U("urn:x-nmos:tag:grouphint/"));
7474
}
7575

76-
void merge_rwnode_patch(web::json::value& value, const web::json::value& patch)
76+
void merge_annotation_patch(web::json::value& value, const web::json::value& patch)
7777
{
7878
// reject changes to read-ony tags
7979

@@ -105,16 +105,16 @@ namespace nmos
105105
web::json::insert(value, std::make_pair(nmos::fields::tags, readonly_tags));
106106
}
107107

108-
void assign_rwnode_patch(web::json::value& value, web::json::value&& patch)
108+
void assign_annotation_patch(web::json::value& value, web::json::value&& patch)
109109
{
110110
if (value.has_string_field(nmos::fields::label)) value[nmos::fields::label] = std::move(patch.at(nmos::fields::label));
111111
if (value.has_string_field(nmos::fields::description)) value[nmos::fields::description] = std::move(patch.at(nmos::fields::description));
112112
if (value.has_object_field(nmos::fields::tags)) value[nmos::fields::tags] = std::move(patch.at(nmos::fields::tags));
113113
}
114114

115-
void handle_rwnode_patch(nmos::resources& resources, const nmos::resource& resource, const web::json::value& patch, const nmos::rwnode_patch_merger& merge_patch, slog::base_gate& gate)
115+
void handle_annotation_patch(nmos::resources& resources, const nmos::resource& resource, const web::json::value& patch, const nmos::annotation_patch_merger& merge_patch, slog::base_gate& gate)
116116
{
117-
auto merged = nmos::make_rwnode_patch(resource);
117+
auto merged = nmos::make_annotation_patch(resource);
118118
try
119119
{
120120
if (merge_patch)
@@ -123,7 +123,7 @@ namespace nmos
123123
}
124124
else
125125
{
126-
nmos::merge_rwnode_patch(resource, merged, patch);
126+
nmos::merge_annotation_patch(resource, merged, patch);
127127
}
128128
}
129129
catch (const web::json::json_exception& e)
@@ -137,28 +137,34 @@ namespace nmos
137137
modify_resource(resources, resource.id, [&merged](nmos::resource& resource)
138138
{
139139
resource.data[nmos::fields::version] = web::json::value::string(nmos::make_version());
140-
details::assign_rwnode_patch(resource.data, std::move(merged));
140+
details::assign_annotation_patch(resource.data, std::move(merged));
141141
});
142142
}
143143
}
144144

145-
web::http::experimental::listener::api_router make_unmounted_rwnode_api(nmos::model& model, nmos::rwnode_patch_merger merge_patch, slog::base_gate& gate_)
145+
web::http::experimental::listener::api_router make_unmounted_annotation_api(nmos::model& model, nmos::annotation_patch_merger merge_patch, slog::base_gate& gate_)
146146
{
147147
using namespace web::http::experimental::listener::api_router_using_declarations;
148148

149-
api_router rwnode_api;
149+
api_router annotation_api;
150150

151151
// check for supported API version
152152
const auto versions = with_read_lock(model.mutex, [&model] { return nmos::is13_versions::from_settings(model.settings); });
153-
rwnode_api.support(U(".*"), details::make_api_version_handler(versions, gate_));
153+
annotation_api.support(U(".*"), details::make_api_version_handler(versions, gate_));
154154

155-
rwnode_api.support(U("/?"), methods::GET, [](http_request req, http_response res, const string_t&, const route_parameters&)
155+
annotation_api.support(U("/?"), methods::GET, [](http_request req, http_response res, const string_t&, const route_parameters&)
156+
{
157+
set_reply(res, status_codes::OK, nmos::make_sub_routes_body({ U("node/") }, req, res));
158+
return pplx::task_from_result(true);
159+
});
160+
161+
annotation_api.support(U("/node/?"), methods::GET, [](http_request req, http_response res, const string_t&, const route_parameters&)
156162
{
157163
set_reply(res, status_codes::OK, nmos::make_sub_routes_body({ U("self/"), U("devices/"), U("sources/"), U("flows/"), U("senders/"), U("receivers/") }, req, res));
158164
return pplx::task_from_result(true);
159165
});
160166

161-
rwnode_api.support(U("/self/?"), methods::GET, [&model, &gate_](http_request req, http_response res, const string_t&, const route_parameters& parameters)
167+
annotation_api.support(U("/node/self/?"), methods::GET, [&model, &gate_](http_request req, http_response res, const string_t&, const route_parameters& parameters)
162168
{
163169
nmos::api_gate gate(gate_, req, parameters);
164170
auto lock = model.read_lock();
@@ -168,7 +174,7 @@ namespace nmos
168174
if (resources.end() != resource)
169175
{
170176
slog::log<slog::severities::more_info>(gate, SLOG_FLF) << "Returning self resource: " << resource->id;
171-
set_reply(res, status_codes::OK, nmos::make_rwnode_response(*resource));
177+
set_reply(res, status_codes::OK, nmos::make_annotation_response(*resource));
172178
}
173179
else
174180
{
@@ -182,18 +188,18 @@ namespace nmos
182188
const web::json::experimental::json_validator validator
183189
{
184190
nmos::experimental::load_json_schema,
185-
boost::copy_range<std::vector<web::uri>>(versions | boost::adaptors::transformed(experimental::make_rwnodeapi_resource_core_patch_request_schema_uri))
191+
boost::copy_range<std::vector<web::uri>>(versions | boost::adaptors::transformed(experimental::make_annotationapi_resource_core_patch_request_schema_uri))
186192
};
187193

188-
rwnode_api.support(U("/self/?"), methods::PATCH, [&model, validator, merge_patch, &gate_](http_request req, http_response res, const string_t&, const route_parameters& parameters)
194+
annotation_api.support(U("/node/self/?"), methods::PATCH, [&model, validator, merge_patch, &gate_](http_request req, http_response res, const string_t&, const route_parameters& parameters)
189195
{
190196
nmos::api_gate gate(gate_, req, parameters);
191197

192198
return details::extract_json(req, gate).then([&model, &validator, merge_patch, req, res, parameters, gate](value body) mutable
193199
{
194200
const nmos::api_version version = nmos::parse_api_version(parameters.at(nmos::patterns::version.name));
195201

196-
validator.validate(body, experimental::make_rwnodeapi_resource_core_patch_request_schema_uri(version));
202+
validator.validate(body, experimental::make_annotationapi_resource_core_patch_request_schema_uri(version));
197203

198204
auto lock = model.write_lock();
199205
auto& resources = model.node_resources;
@@ -203,9 +209,9 @@ namespace nmos
203209
{
204210
slog::log<slog::severities::more_info>(gate, SLOG_FLF) << "Patching self resource: " << resource->id;
205211

206-
details::handle_rwnode_patch(resources, *resource, body, merge_patch, gate);
212+
details::handle_annotation_patch(resources, *resource, body, merge_patch, gate);
207213

208-
set_reply(res, status_codes::OK, nmos::make_rwnode_response(*resource));
214+
set_reply(res, status_codes::OK, nmos::make_annotation_response(*resource));
209215

210216
model.notify();
211217
}
@@ -219,7 +225,7 @@ namespace nmos
219225
});
220226
});
221227

222-
rwnode_api.support(U("/") + nmos::patterns::subresourceType.pattern + U("/?"), methods::GET, [&model, &gate_](http_request req, http_response res, const string_t&, const route_parameters& parameters)
228+
annotation_api.support(U("/node/") + nmos::patterns::subresourceType.pattern + U("/?"), methods::GET, [&model, &gate_](http_request req, http_response res, const string_t&, const route_parameters& parameters)
223229
{
224230
nmos::api_gate gate(gate_, req, parameters);
225231
auto lock = model.read_lock();
@@ -235,7 +241,7 @@ namespace nmos
235241
web::json::serialize_array(resources
236242
| boost::adaptors::filtered(match)
237243
| boost::adaptors::transformed(
238-
[&count](const nmos::resources::value_type& resource) { ++count; return nmos::make_rwnode_response(resource); }
244+
[&count](const nmos::resources::value_type& resource) { ++count; return nmos::make_annotation_response(resource); }
239245
)),
240246
web::http::details::mime_types::application_json);
241247

@@ -244,7 +250,7 @@ namespace nmos
244250
return pplx::task_from_result(true);
245251
});
246252

247-
rwnode_api.support(U("/") + nmos::patterns::subresourceType.pattern + U("/") + nmos::patterns::resourceId.pattern + U("/?"), methods::GET, [&model, &gate_](http_request req, http_response res, const string_t&, const route_parameters& parameters)
253+
annotation_api.support(U("/node/") + nmos::patterns::subresourceType.pattern + U("/") + nmos::patterns::resourceId.pattern + U("/?"), methods::GET, [&model, &gate_](http_request req, http_response res, const string_t&, const route_parameters& parameters)
248254
{
249255
nmos::api_gate gate(gate_, req, parameters);
250256
auto lock = model.read_lock();
@@ -258,7 +264,7 @@ namespace nmos
258264
if (resources.end() != resource)
259265
{
260266
slog::log<slog::severities::more_info>(gate, SLOG_FLF) << "Returning " << id_type;
261-
set_reply(res, status_codes::OK, nmos::make_rwnode_response(*resource));
267+
set_reply(res, status_codes::OK, nmos::make_annotation_response(*resource));
262268
}
263269
else
264270
{
@@ -268,15 +274,15 @@ namespace nmos
268274
return pplx::task_from_result(true);
269275
});
270276

271-
rwnode_api.support(U("/") + nmos::patterns::subresourceType.pattern + U("/") + nmos::patterns::resourceId.pattern + U("/?"), methods::PATCH, [&model, validator, merge_patch, &gate_](http_request req, http_response res, const string_t&, const route_parameters& parameters)
277+
annotation_api.support(U("/node/") + nmos::patterns::subresourceType.pattern + U("/") + nmos::patterns::resourceId.pattern + U("/?"), methods::PATCH, [&model, validator, merge_patch, &gate_](http_request req, http_response res, const string_t&, const route_parameters& parameters)
272278
{
273279
nmos::api_gate gate(gate_, req, parameters);
274280

275281
return details::extract_json(req, gate).then([&model, &validator, merge_patch, req, res, parameters, gate](value body) mutable
276282
{
277283
const nmos::api_version version = nmos::parse_api_version(parameters.at(nmos::patterns::version.name));
278284

279-
validator.validate(body, experimental::make_rwnodeapi_resource_core_patch_request_schema_uri(version));
285+
validator.validate(body, experimental::make_annotationapi_resource_core_patch_request_schema_uri(version));
280286

281287
auto lock = model.write_lock();
282288
auto& resources = model.node_resources;
@@ -290,9 +296,9 @@ namespace nmos
290296
{
291297
slog::log<slog::severities::more_info>(gate, SLOG_FLF) << "Patching " << id_type;
292298

293-
details::handle_rwnode_patch(resources, *resource, body, merge_patch, gate);
299+
details::handle_annotation_patch(resources, *resource, body, merge_patch, gate);
294300

295-
set_reply(res, status_codes::OK, nmos::make_rwnode_response(*resource));
301+
set_reply(res, status_codes::OK, nmos::make_annotation_response(*resource));
296302

297303
model.notify();
298304
}
@@ -305,6 +311,6 @@ namespace nmos
305311
});
306312
});
307313

308-
return rwnode_api;
314+
return annotation_api;
309315
}
310316
}

0 commit comments

Comments
 (0)