ISystemControllerInterface

ISystemControllerInterface

An ISystemControllerInterface is the interface between a component and the System controller controlling the component. The interface allows for two-way communication between the component and the system controller by means of sending requests and getting responses. Classes deriving from the ISystemControllerInterface should provide the component side implementation of the communication with the system controller. This interface can be inherited and implemented by developers to connect to custom system controllers, or to directly control a component programmatically, without the need for connecting to a remote server. An ISystemControllerInterface can have a parent-child relationship with other interfaces, where the children are aware of which their parent interface is. This is useful for components that provides extra features for another component, but where the components are still to be considered as two separate entities with separate connections to the System controller.

#include <ISystemControllerInterface.h>

Inherited by SystemControllerConnection

Public Classes

Name
structCallbacks
A struct containing the callbacks that needs to be registered by the component using this interface.
structResponse
A response to a request, consists of a status code and an (optional) parameters JSON object.

Public Types

Name
enum class uint32_tStatusCode { SUCCESS = 3001, TOO_MANY_REQUESTS = 3101, UUID_ALREADY_REGISTERED = 3201, FORMAT_ERROR = 3202, ALREADY_CONFIGURED = 3203, OUT_OF_RESOURCES = 3204, NOT_FOUND = 3205, INTERNAL_ERROR = 3206, CONNECTION_FAILED = 3207, TIMEOUT_EXCEEDED = 3208, KEY_MISMATCH = 3209, UNKNOWN_REQUEST = 3210, MALFORMED_REQUEST = 3211, ALREADY_IN_USE = 3212}
Status codes used in JSON response messages for Websockets. These are starting at 3000 since the 1000 - 2000 range is taken up by the Spec: https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1.

Public Functions

Name
virtual~ISystemControllerInterface() =default
Virtual destructor.
virtual ResponsesendRequest(const std::string & request, const nlohmann::json & parameters) =0
Send a request with some JSON parameters to the controller and await the response.
virtual boolregisterRequestCallback(const Callbacks & callbacks) =0
Register the callbacks to call for events in this class.
virtual boolconnect() =0
Connect to the System controller.
virtual booldisconnect() =0
Disconnect from the System controller.
virtual boolisConnected() const =0
virtual std::stringgetUUID() const =0
virtual boolhasParent() const =0
virtual std::shared_ptr< ISystemControllerInterface >getParentInterface() const =0

Public Types Documentation

enum StatusCode

EnumeratorValueDescription
SUCCESS30013000-3099 Info/Notifications
TOO_MANY_REQUESTS31013100-3199 Warnings
UUID_ALREADY_REGISTERED32013200-3299 Error
FORMAT_ERROR3202
ALREADY_CONFIGURED3203
OUT_OF_RESOURCES3204
NOT_FOUND3205
INTERNAL_ERROR3206
CONNECTION_FAILED3207
TIMEOUT_EXCEEDED3208
KEY_MISMATCH3209
UNKNOWN_REQUEST3210
MALFORMED_REQUEST3211
ALREADY_IN_USE3212

Status codes used in JSON response messages for Websockets. These are starting at 3000 since the 1000 - 2000 range is taken up by the Spec: https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1.

Public Functions Documentation

function ~ISystemControllerInterface

virtual ~ISystemControllerInterface() =default

Virtual destructor.

function sendRequest

virtual Response sendRequest(
    const std::string & request,
    const nlohmann::json & parameters
) =0

Send a request with some JSON parameters to the controller and await the response.

Parameters:

  • request The name of the request command
  • parameters The parameters part of the JSON message

Return: The response from the controller.

Reimplemented by: SystemControllerConnection::sendRequest

function registerRequestCallback

virtual bool registerRequestCallback(
    const Callbacks & callbacks
) =0

Register the callbacks to call for events in this class.

Parameters:

  • callbacks The callbacks to use when events in this class happen

Return: True on successful registration, false if some callback is not set or if already connected

Reimplemented by: SystemControllerConnection::registerRequestCallback

function connect

virtual bool connect() =0

Connect to the System controller.

Return: True on successful connection, false on error or if already connected

Reimplemented by: SystemControllerConnection::connect

function disconnect

virtual bool disconnect() =0

Disconnect from the System controller.

Return: True on successful disconnection, false on error or if not connected

Reimplemented by: SystemControllerConnection::disconnect

function isConnected

virtual bool isConnected() const =0

Return: True if connected to the System controller, false otherwise

Reimplemented by: SystemControllerConnection::isConnected

function getUUID

virtual std::string getUUID() const =0

Return: The UUID of this interface to the System controller

Reimplemented by: SystemControllerConnection::getUUID

function hasParent

virtual bool hasParent() const =0

Return: True if this component has a parent ISystemControllerInterface, false otherwise

Reimplemented by: SystemControllerConnection::hasParent

function getParentInterface

virtual std::shared_ptr< ISystemControllerInterface > getParentInterface() const =0

Return: A pointer to parent’s ISystemControllerInterface, if any. Returns nullptr in case there is no parent

Reimplemented by: SystemControllerConnection::getParentInterface


Updated on 2023-01-23 at 12:02:53 +0100