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 14 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 @@ -686,6 +686,77 @@ target_include_directories(nmos_is09_schemas PUBLIC
list(APPEND NMOS_CPP_TARGETS nmos_is09_schemas)
add_library(nmos-cpp::nmos_is09_schemas ALIAS nmos_is09_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 @@ -743,6 +814,7 @@ set(NMOS_CPP_CPPREST_DETAILS_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/capabilities.cpp
Expand Down Expand Up @@ -808,6 +880,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 @@ -847,6 +920,7 @@ set(NMOS_CPP_NMOS_HEADERS
nmos/is07_versions.h
nmos/is08_versions.h
nmos/is09_versions.h
nmos/is13_versions.h
nmos/json_fields.h
nmos/json_schema.h
nmos/lldp_handler.h
Expand Down Expand Up @@ -985,6 +1059,7 @@ target_link_libraries(
nmos-cpp::nmos_is05_schemas
nmos-cpp::nmos_is08_schemas
nmos-cpp::nmos_is09_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 @@ -39,6 +39,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 @@ -101,6 +101,9 @@
// is09_versions [registry, node]: used to specify the enabled API versions for a version-locked configuration
//"is09_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 @@ -132,6 +135,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,

Expand Down
24 changes: 23 additions & 1 deletion Development/nmos-cpp-node/node_implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,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
};
}

namespace impl
{
nmos::interlace_mode get_interlace_mode(const nmos::settings& settings)
Expand Down Expand Up @@ -1422,5 +1443,6 @@ nmos::experimental::node_implementation make_node_implementation(nmos::node_mode
.on_set_transportfile(make_node_implementation_transportfile_setter(model.node_resources, model.settings))
.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_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
}
Loading