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 1 commit
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
Next Next commit
Initial draft NMOS Read/Write Node API implementation
  • Loading branch information
garethsb committed May 11, 2023
commit 3b7f736605c2af5d35f3b2257206c91dfd6c3b79
74 changes: 74 additions & 0 deletions Development/cmake/NmosCppLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,76 @@ 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/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_cores.json
third_party/is-13/${NMOS_IS13_V1_0_TAG}/APIs/schemas/rwnodeapi-base.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 @@ -794,6 +864,7 @@ set(NMOS_CPP_NMOS_SOURCES
nmos/registry_server.cpp
nmos/resource.cpp
nmos/resources.cpp
nmos/rwnode_api.cpp
nmos/schemas_api.cpp
nmos/sdp_utils.cpp
nmos/server.cpp
Expand Down Expand Up @@ -847,6 +918,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 @@ -886,6 +958,7 @@ set(NMOS_CPP_NMOS_HEADERS
nmos/registry_server.h
nmos/resource.h
nmos/resources.h
nmos/rwnode_api.h
nmos/schemas_api.h
nmos/sdp_utils.h
nmos/server.h
Expand Down Expand Up @@ -985,6 +1058,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
3 changes: 3 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
2 changes: 2 additions & 0 deletions Development/nmos/api_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace nmos
const route_pattern channelmapping_api = make_route_pattern(U("api"), U("channelmapping"));
// IS-09 System API (originally specified in JT-NM TR-1001-1:2018 Annex A)
const route_pattern system_api = make_route_pattern(U("api"), U("system"));
// IS-13 Read/Write Node API
const route_pattern rwnode_api = make_route_pattern(U("api"), U("rwnode"));

// API version pattern
const route_pattern version = make_route_pattern(U("version"), U("v[0-9]+\\.[0-9]+"));
Expand Down
21 changes: 21 additions & 0 deletions Development/nmos/is13_schemas/is13_schemas.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef NMOS_IS13_SCHEMAS_H
#define NMOS_IS13_SCHEMAS_H

// Extern declarations for auto-generated constants
// could be auto-generated, but isn't currently!
namespace nmos
{
namespace is13_schemas
{
namespace v1_0_dev
{
extern const char* error;
extern const char* resource_core;
extern const char* resource_core_patch;
extern const char* resource_cores;
extern const char* rwnodeapi_base;
}
}
}

#endif
26 changes: 26 additions & 0 deletions Development/nmos/is13_versions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef NMOS_IS13_VERSIONS_H
#define NMOS_IS13_VERSIONS_H

#include <set>
#include <boost/range/adaptor/transformed.hpp>
#include "nmos/api_version.h"
#include "nmos/settings.h"

namespace nmos
{
namespace is13_versions
{
const api_version v1_0{ 1, 0 };

const std::set<api_version> all{ nmos::is13_versions::v1_0 };

inline std::set<api_version> from_settings(const nmos::settings& settings)
{
return settings.has_field(nmos::fields::is13_versions)
? boost::copy_range<std::set<api_version>>(nmos::fields::is04_versions(settings) | boost::adaptors::transformed([](const web::json::value& v) { return nmos::parse_api_version(v.as_string()); }))
: nmos::is13_versions::all;
}
}
}

#endif
36 changes: 36 additions & 0 deletions Development/nmos/json_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "nmos/is08_schemas/is08_schemas.h"
#include "nmos/is09_versions.h"
#include "nmos/is09_schemas/is09_schemas.h"
#include "nmos/is13_versions.h"
#include "nmos/is13_schemas/is13_schemas.h"
#include "nmos/type.h"

namespace nmos
Expand Down Expand Up @@ -126,6 +128,23 @@ namespace nmos
const web::uri systemapi_global_schema_uri = make_schema_uri(tag, _XPLATSTR("global.json"));
}
}

namespace is13_schemas
{
web::uri make_schema_uri(const utility::string_t& tag, const utility::string_t& ref = {})
{
return{ _XPLATSTR("https://github.com/AMWA-TV/nmos-rwnode/raw/") + tag + _XPLATSTR("/APIs/schemas/") + ref };
}

// See https://github.com/AMWA-TV/nmos-rwnode/blob/v1.0-dev/APIs/schemas/
namespace v1_0
{
using namespace nmos::is13_schemas::v1_0_dev;
const utility::string_t tag(_XPLATSTR("v1.0-dev"));

const web::uri rwnodeapi_resource_core_patch_request_uri = make_schema_uri(tag, _XPLATSTR("resource_core_patch.json"));
}
}
}

namespace nmos
Expand Down Expand Up @@ -310,6 +329,17 @@ namespace nmos
};
}

static std::map<web::uri, web::json::value> make_is13_schemas()
{
using namespace nmos::is13_schemas;

return
{
// v1.0
{ make_schema_uri(v1_0::tag, _XPLATSTR("resource_core_patch.json")), make_schema(v1_0::resource_core_patch) }
};
}

inline void merge(std::map<web::uri, web::json::value>& to, std::map<web::uri, web::json::value>&& from)
{
to.insert(from.begin(), from.end()); // std::map::merge in C++17
Expand All @@ -321,6 +351,7 @@ namespace nmos
merge(result, make_is05_schemas());
merge(result, make_is08_schemas());
merge(result, make_is09_schemas());
merge(result, make_is13_schemas());
return result;
}

Expand Down Expand Up @@ -382,6 +413,11 @@ namespace nmos
return is08_schemas::v1_0::map_activations_post_request_uri;
}

web::uri make_rwnodeapi_resource_core_patch_request_schema_uri(const nmos::api_version& version)
{
return is13_schemas::v1_0::rwnodeapi_resource_core_patch_request_uri;
}

// load the json schema for the specified base URI
web::json::value load_json_schema(const web::uri& id)
{
Expand Down
2 changes: 2 additions & 0 deletions Development/nmos/json_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace nmos

web::uri make_channelmappingapi_map_activations_post_request_schema_uri(const nmos::api_version& version);

web::uri make_rwnodeapi_resource_core_patch_request_schema_uri(const nmos::api_version& version);

// load the json schema for the specified base URI
web::json::value load_json_schema(const web::uri& id);
}
Expand Down
2 changes: 2 additions & 0 deletions Development/nmos/node_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "nmos/model.h"
#include "nmos/node_api.h"
#include "nmos/node_behaviour.h"
#include "nmos/rwnode_api.h"
#include "nmos/server.h"
#include "nmos/server_utils.h"
#include "nmos/settings_api.h"
Expand Down Expand Up @@ -51,6 +52,7 @@ namespace nmos

nmos::node_api_target_handler target_handler = nmos::make_node_api_target_handler(node_model, node_implementation.load_ca_certificates, node_implementation.parse_transport_file, node_implementation.validate_staged);
node_server.api_routers[{ {}, nmos::fields::node_port(node_model.settings) }].mount({}, nmos::make_node_api(node_model, target_handler, gate));
node_server.api_routers[{ {}, nmos::fields::node_port(node_model.settings) }].mount({}, nmos::make_rwnode_api(node_model, gate));
node_server.api_routers[{ {}, nmos::experimental::fields::manifest_port(node_model.settings) }].mount({}, nmos::experimental::make_manifest_api(node_model, gate));

// Configure the Connection API
Expand Down
Loading