43#include <boost/uuid.hpp>
44#include <boost/system/result.hpp>
45#include <fmt/ostream.h>
47#include <unordered_map>
67 boost::uuids::uuid
id;
80 [[nodiscard]] boost::system::result<void, Error>
validate()
const;
85 [[nodiscard]] boost::json::object
to_json()
const;
92 static boost::system::result<Configuration, std::string>
from_json(
const boost::json::value& json);
94 [[nodiscard]]
auto constexpr tie()
const {
99 return lhs.
tie() == rhs.
tie();
103 return lhs.
tie() != rhs.
tie();
119 boost::asio::io_context& io_context,
ptp::Instance& ptp_instance, std::unique_ptr<RegistryBrowserBase> registry_browser =
nullptr,
120 std::unique_ptr<HttpClientBase> http_client =
nullptr
129 [[nodiscard]] boost::system::result<void, Error>
start();
261 [[nodiscard]]
const boost::uuids::uuid&
get_uuid()
const;
271 [[nodiscard]]
const std::vector<FlowAudioRaw*>&
get_flows()
const;
286 [[nodiscard]]
const std::vector<SourceAudio*>&
get_sources()
const;
314 static constexpr uint8_t k_max_failed_heartbeats = 5;
315 static constexpr auto k_heartbeat_interval = std::chrono::seconds(5);
316 static constexpr size_t k_clock_ptp_index = 1;
320 std::vector<Device*> devices_;
321 std::vector<FlowAudioRaw*> flows_;
322 std::vector<ReceiverAudio*> receivers_;
323 std::vector<Sender*> senders_;
324 std::vector<SourceAudio*> sources_;
328 int post_resource_error_count_ = 0;
331 std::optional<dnssd::ServiceDescription> selected_registry_;
332 StatusInfo status_info_;
335 std::unique_ptr<HttpClientBase> http_client_;
336 std::unique_ptr<RegistryBrowserBase> registry_browser_;
339 uint8_t failed_heartbeat_count_ = 0;
343 [[nodiscard]] boost::system::result<void, Error> start_internal();
344 void stop_internal();
346 void register_async();
347 void unregister_async();
348 void post_resource_async(std::string type, boost::json::value resource);
349 void delete_resource_async(std::string resource_type,
const boost::uuids::uuid&
id);
351 void send_heartbeat_async();
352 void connect_to_registry_async();
353 void connect_to_registry_async(std::string_view host, std::string_view service);
355 [[nodiscard]]
bool add_receiver_to_device(
const ReceiverAudio& receiver)
const;
356 [[nodiscard]]
bool add_sender_to_device(
const Sender& sender)
const;
361 void set_status(
Status new_status);
362 void update_all_resources_to_now();
363 void send_updated_resources_async();
364 void update_device(
Device& device);
A timer that uses boost::asio::steady_timer to provide a simple way of creating a timer without think...
A high-level wrapper around boost::beast for creating an HTTP server.
A simple callback function wrapper that can be used to store and call a function with a specific sign...
const std::vector< SourceAudio * > & get_sources() const
static std::array< ApiVersion, 2 > k_connection_api_versions
bool remove_sender(Sender *sender)
Removes a sender from the node by its uuid.
void set_network_interface_config(NetworkInterfaceConfig config)
Updates the node based on given network interface configuration.
const std::vector< ReceiverAudio * > & get_receivers() const
static constexpr auto k_ptp_clock_name
Node(boost::asio::io_context &io_context, ptp::Instance &ptp_instance, std::unique_ptr< RegistryBrowserBase > registry_browser=nullptr, std::unique_ptr< HttpClientBase > http_client=nullptr)
bool remove_source(SourceAudio *source)
Removes a source from the node by its uuid.
bool add_or_update_sender(Sender *sender)
Adds the given sender to the node or updates an existing sender if it already exists (based on the uu...
static std::array< ApiVersion, 2 > k_node_api_versions
bool add_or_update_device(Device *device)
Adds the given device to the node or updates an existing device if it already exists (based on the uu...
const std::vector< Sender * > & get_senders() const
const FlowAudioRaw * find_flow(const boost::uuids::uuid &uuid) const
Finds a flow by its uuid.
const Configuration & get_configuration() const
const std::vector< FlowAudioRaw * > & get_flows() const
const Device * find_device(const boost::uuids::uuid &uuid) const
Finds a device by its uuid.
bool remove_flow(FlowAudioRaw *flow)
Removes a flow from the node by its uuid.
void ptp_parent_changed(const ptp::ParentDs &parent) override
Called when the parent of the PTP instance changes.
const ReceiverAudio * find_receiver(const boost::uuids::uuid &uuid) const
Finds a receiver by its uuid.
const Status & get_status() const
static constexpr auto k_default_timeout
SafeFunction< void(const Status &status, const StatusInfo &status_info)> on_status_changed
const boost::uuids::uuid & get_uuid() const
const StatusInfo & get_registry_info() const
bool add_or_update_receiver(ReceiverAudio *receiver)
Adds the given receiver to the node or updates an existing receiver if it already exists (based on th...
boost::asio::ip::tcp::endpoint get_local_endpoint() const
bool add_or_update_source(SourceAudio *source)
Adds the given source to the node or updates an existing source if it already exists (based on the uu...
void ptp_port_changed_state(const ptp::Port &port) override
Called when the state of a port changes.
const SourceAudio * find_source(const boost::uuids::uuid &uuid) const
Finds a source by its uuid.
bool remove_device(Device *device)
Removes a device from the node by its uuid.
Sender * find_sender(const boost::uuids::uuid &uuid) const
Finds a sender by its uuid.
SafeFunction< void(const Configuration &config)> on_configuration_changed
static std::optional< size_t > index_of_supported_api_version(const ApiVersion &version)
static constexpr auto k_internal_clock_name
void stop()
Stops all the operations of this node (HTTP server, advertisements, etc.).
const std::vector< Device * > & get_devices() const
bool remove_receiver(ReceiverAudio *receiver)
Removes a receiver from the node by its uuid.
tl::expected< void, Error > set_configuration(Configuration new_configuration, bool force_update=false)
Sets the configuration of the NMOS node.
bool add_or_update_flow(FlowAudioRaw *flow)
Adds the given flow to the node or updates an existing flow if it already exists (based on the uuid).
boost::system::result< void, Error > start()
Starts the services of this node (HTTP server, advertisements, etc.).
Represents a PTP instance as defined in IEEE 1588-2019.
void tag_invoke(const boost::json::value_from_tag &, boost::json::value &jv, const Timestamp ×tamp)
const char * to_string(const OperationMode operation_mode)
Timestamp Version
An nmos version is represented as TAI timestamp.
OperationMode
The mode of operation for the NMOS node.
@ mdns_p2p
Discovers registries via mDNS, falling back to p2p if no registry is available.
A struct containing data which represents a service on the network.
Represents the version of the NMOS API.
The configuration of the NMOS node.
static boost::system::result< Configuration, std::string > from_json(const boost::json::value &json)
Creates a configuration object from a JSON object.
auto constexpr tie() const
friend bool operator!=(const Configuration &lhs, const Configuration &rhs)
boost::json::object to_json() const
std::string registry_address
boost::system::result< void, Error > validate() const
Checks if the configuration is semantically valid, return a message if not.
OperationMode operation_mode
friend bool operator==(const Configuration &lhs, const Configuration &rhs)
Describes an audio Receiver.
Describes the Node and the services which run on it.
Describes an audio source.
Represents the parent data set as described in IEEE1588-2019: 8.2.3.