Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of IS-13 NMOS Annotation API #331

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
75 changes: 75 additions & 0 deletions Development/cmake/NmosCppLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,77 @@ target_include_directories(nmos_is12_schemas PUBLIC
list(APPEND NMOS_CPP_TARGETS nmos_is12_schemas)
add_library(nmos-cpp::nmos_is12_schemas ALIAS nmos_is12_schemas)

# nmos_is13_schemas library

set(NMOS_IS13_SCHEMAS_HEADERS
nmos/is13_schemas/is13_schemas.h
)

set(NMOS_IS13_V1_0_TAG v1.0-dev)

set(NMOS_IS13_V1_0_SCHEMAS_JSON
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/annotationapi-base.json
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/annotationapi-node-base.json
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/error.json
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/resource_core.json
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/resource_core_patch.json
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/resource-list.json
)

set(NMOS_IS13_SCHEMAS_JSON_MATCH "third_party/is-13/([^/]+)/APIs/schemas/([^;]+)\\.json")
set(NMOS_IS13_SCHEMAS_SOURCE_REPLACE "${CMAKE_CURRENT_BINARY_DIR_REPLACE}/nmos/is13_schemas/\\1/\\2.cpp")
string(REGEX REPLACE "${NMOS_IS13_SCHEMAS_JSON_MATCH}(;|$)" "${NMOS_IS13_SCHEMAS_SOURCE_REPLACE}\\3" NMOS_IS13_V1_0_SCHEMAS_SOURCES "${NMOS_IS13_V1_0_SCHEMAS_JSON}")

foreach(JSON ${NMOS_IS13_V1_0_SCHEMAS_JSON})
string(REGEX REPLACE "${NMOS_IS13_SCHEMAS_JSON_MATCH}" "${NMOS_IS13_SCHEMAS_SOURCE_REPLACE}" SOURCE "${JSON}")
string(REGEX REPLACE "${NMOS_IS13_SCHEMAS_JSON_MATCH}" "\\1" NS "${JSON}")
string(REGEX REPLACE "${NMOS_IS13_SCHEMAS_JSON_MATCH}" "\\2" VAR "${JSON}")
string(MAKE_C_IDENTIFIER "${NS}" NS)
string(MAKE_C_IDENTIFIER "${VAR}" VAR)

file(WRITE "${SOURCE}.in" "\
// Auto-generated from: ${JSON}\n\
\n\
namespace nmos\n\
{\n\
namespace is13_schemas\n\
{\n\
namespace ${NS}\n\
{\n\
const char* ${VAR} = R\"-auto-generated-(")

file(READ "${JSON}" RAW)
file(APPEND "${SOURCE}.in" "${RAW}")

file(APPEND "${SOURCE}.in" ")-auto-generated-\";\n\
}\n\
}\n\
}\n")

configure_file("${SOURCE}.in" "${SOURCE}" COPYONLY)
endforeach()

add_library(
nmos_is13_schemas STATIC
${NMOS_IS13_SCHEMAS_HEADERS}
${NMOS_IS13_V1_0_SCHEMAS_SOURCES}
)

source_group("nmos\\is13_schemas\\Header Files" FILES ${NMOS_IS13_SCHEMAS_HEADERS})
source_group("nmos\\is13_schemas\\${NMOS_IS13_V1_0_TAG}\\Source Files" FILES ${NMOS_IS13_V1_0_SCHEMAS_SOURCES})

target_link_libraries(
nmos_is13_schemas PRIVATE
nmos-cpp::compile-settings
)
target_include_directories(nmos_is13_schemas PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${NMOS_CPP_INSTALL_INCLUDEDIR}>
)

list(APPEND NMOS_CPP_TARGETS nmos_is13_schemas)
add_library(nmos-cpp::nmos_is13_schemas ALIAS nmos_is13_schemas)

# nmos-cpp library

set(NMOS_CPP_BST_SOURCES
Expand Down Expand Up @@ -903,6 +974,7 @@ set(NMOS_CPP_JWK_HEADERS
set(NMOS_CPP_NMOS_SOURCES
nmos/activation_utils.cpp
nmos/admin_ui.cpp
nmos/annotation_api.cpp
nmos/api_downgrade.cpp
nmos/api_utils.cpp
nmos/authorization.cpp
Expand Down Expand Up @@ -989,6 +1061,7 @@ set(NMOS_CPP_NMOS_HEADERS
nmos/activation_mode.h
nmos/activation_utils.h
nmos/admin_ui.h
nmos/annotation_api.h
nmos/api_downgrade.h
nmos/api_utils.h
nmos/api_version.h
Expand Down Expand Up @@ -1048,6 +1121,7 @@ set(NMOS_CPP_NMOS_HEADERS
nmos/is09_versions.h
nmos/is10_versions.h
nmos/is12_versions.h
nmos/is13_versions.h
nmos/issuers.h
nmos/json_fields.h
nmos/json_schema.h
Expand Down Expand Up @@ -1198,6 +1272,7 @@ target_link_libraries(
nmos-cpp::nmos_is09_schemas
nmos-cpp::nmos_is10_schemas
nmos-cpp::nmos_is12_schemas
nmos-cpp::nmos_is13_schemas
nmos-cpp::mdns
nmos-cpp::slog
nmos-cpp::OpenSSL
Expand Down
1 change: 1 addition & 0 deletions Development/cmake/NmosCppTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ set(NMOS_CPP_TEST_MDNS_TEST_HEADERS
)

set(NMOS_CPP_TEST_NMOS_TEST_SOURCES
nmos/test/annotation_api_test.cpp
nmos/test/api_utils_test.cpp
nmos/test/capabilities_test.cpp
nmos/test/channels_test.cpp
Expand Down
4 changes: 4 additions & 0 deletions Development/nmos-cpp-node/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
// is12_versions [node]: used to specify the enabled API versions for a version-locked configuration
//"is12_versions": ["v1.0"],

// is13_versions [node]: used to specify the enabled API versions for a version-locked configuration
//"is13_versions": ["v1.0"],

// pri [registry, node]: used for the 'pri' TXT record; specifying nmos::service_priorities::no_priority (maximum value) disables advertisement completely
//"pri": 100,

Expand Down Expand Up @@ -145,6 +148,7 @@
//"events_port": 3216,
//"events_ws_port": 3217,
//"channelmapping_port": 3215,
//"annotation_port": 3212,
// system_port [node]: used to construct request URLs for the System API (if not discovered via DNS-SD)
//"system_port": 10641,
// control_protocol_ws_port [node]: used to construct request URLs for the Control Protocol websocket, or negative to disable the control protocol features
Expand Down
22 changes: 22 additions & 0 deletions Development/nmos-cpp-node/node_implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,27 @@ nmos::channelmapping_activation_handler make_node_implementation_channelmapping_
};
}

// Example Annotation API patch callback to update resource labels, descriptions and tags
nmos::annotation_patch_merger make_node_implementation_annotation_patch_merger(const nmos::settings& settings, slog::base_gate& gate)
{
using web::json::value;
using web::json::value_of;

return [&settings, &gate](const nmos::resource& resource, web::json::value& value, const web::json::value& patch)
{
const std::pair<nmos::id, nmos::type> id_type{ resource.id, resource.type };
slog::log<slog::severities::info>(gate, SLOG_FLF) << nmos::stash_category(impl::categories::node_implementation) << "Updating " << id_type;
// this example uses the specified tags for node and device resources as defaults
const auto default_tags
= id_type.second == nmos::types::node ? impl::fields::node_tags(settings)
: id_type.second == nmos::types::device ? impl::fields::device_tags(settings)
: value::object();
// and uses the default predicate for read-only tags
nmos::details::merge_annotation_patch(value, patch, &nmos::details::is_read_only_tag, value_of({ { nmos::fields::tags, default_tags } }));
// this example does not save the new values to persistent storage or e.g. reject values that are too large
};
}

// Example Control Protocol WebSocket API property changed callback to perform application-specific operations to complete the property changed
nmos::control_protocol_property_changed_handler make_node_implementation_control_protocol_property_changed_handler(slog::base_gate& gate)
{
Expand Down Expand Up @@ -1868,5 +1889,6 @@ nmos::experimental::node_implementation make_node_implementation(nmos::node_mode
.on_connection_activated(make_node_implementation_connection_activation_handler(model, gate))
.on_validate_channelmapping_output_map(make_node_implementation_map_validator()) // may be omitted if not required
.on_channelmapping_activated(make_node_implementation_channelmapping_activation_handler(gate))
.on_merge_annotation_patch(make_node_implementation_annotation_patch_merger(model.settings, gate)) // may be omitted if not required
.on_control_protocol_property_changed(make_node_implementation_control_protocol_property_changed_handler(gate)); // may be omitted if IS-12 not required
}
Loading
Loading