Node

class Node

Node interface.

A node is the base of all communications in Melo: it is the interface used by every parts of the application to send / receive requests and events.

The request and event handlers are directly implemented by the derived class while the send functions and address are provided by a Node::Implem.

Subclassed by melo::Browser, melo::Settings

Public Functions

inline const node::Address &get_address() const

Get node address.

Returns:

the address of the current node.

inline virtual bool handle_request(std::shared_ptr<Request> req)

Handle request.

This function will be called when a new request is received on the node.

If false is returned, the request will be aborted by the Node implementation, otherwise, the developer is responsible to complete or abort the request at some time.

Parameters:

req[in] The received request

Returns:

true if the request is in progress or has been processed, false otherwise.

inline virtual void handle_event(std::shared_ptr<Message> msg)

Handle event.

This function will be called when a new event message is received on the node.

Parameters:

msg[in] The received event message

inline void set_implementation(std::unique_ptr<Implem> implem)

Set implementation.

This function should be called by the router class and is intended to setup the low level communication functions.

Parameters:

implem[in] The implementation to use for up-coming communications

class Implem

Node implementation.

This class will provide the functions to send a request and an event to the rest of the application. It also holds the address of the node within the application.

The handler for requests and events are directly implemented by the Node itself.

Public Functions

inline const node::Address &get_address() const

Get node address.

Returns:

the address of the current node.

inline virtual void send_request(std::shared_ptr<Request> req)

Send a request to another node.

This function is used to send a request to another node and it is called by the Node::send_request() function.

Note

The request source is already checked by Node::send_request().

Parameters:

req[in] The request to send

Returns:

true if the request has been sent, false otherwise.

inline virtual void send_event(std::shared_ptr<Message> msg)

Send an event.

This function is used to broadcast an event to other nodes and it is called by the Node::send_event() function.

Note

The message type and source is already checked by Node::send_event().

Parameters:

msg[in] The event message to broadcast

enum class melo::node::Type : std::uint8_t

Node type.

Please read the Protobuf documentation for more details.

Values:

enumerator kInvalid

Invalid node type.

enumerator kEvent

Event node.

enumerator kSDK

SDK node.

enumerator kPlugin

Plugin node.

enumerator kSettings

Settings node.

enumerator kBrowser

Browser node.

enumerator kPlayer

Player node.

enumerator kPlayerQueue

Player Queue node.

enumerator kPlaylist

Playlist node.

class Address

Address structure.

Public Functions

inline Address()

Create an invalid address.

inline explicit Address(Type type, std::string id = "")

Create a new address.

Parameters:
  • type[in] The type of the node

  • id[in] The ID of the node

inline explicit Address(std::string addr)

Create an address from a string.

Parameters:

addr[in] The address string to use

Address(const Address &addr) = default

Copy an address.

Parameters:

addr[in] The address to copy

Address &operator=(const Address &addr) = default

Assign an address by copy.

Parameters:

addr[in] The address to move

inline Address(Address &&addr)

Move an address.

Parameters:

addr[in] The address to move

inline Address &operator=(Address &&addr)

Assign an address by move.

Parameters:

addr[in] The address to move

inline Type get_type() const

Get node type.

Returns:

the type of the current node.

inline const std::string_view get_id() const

Get node ID.

Returns:

the ID of the current node.

inline const std::string &to_string() const

Get node address.

Returns:

the address of the current node.

inline std::string to_print() const

Get node address as a printable string.

Returns:

the address of the current node.

template<class T>
inline bool operator==(const T &str) const noexcept

Compare with an address string.

Parameters:

str[in] The address string to compare with

Returns:

true if the addresses are equal, false otherwise.

Public Static Functions

static inline Type get_type(const std::string &addr)

Get node type from an address.

Parameters:

addr[in] The address string

Returns:

the type of the node.

static inline std::string get_address(Type type, const std::string &id)

Get address string from a node type and ID.

Parameters:
  • type[in] The type of the node

  • id[in] The ID of the node

Returns:

the address string.