Subscribe

Subscribe

Subscribe class is used to receive continuous parameter updates from motorcortex server. It simplifies creating and removing subscription groups. More…

Classes

Name
class mcx_cpp::Subscribe
class mcx_cpp::Subscription

Functions

Name
Subscribe() =delete
Subscribe(const Request & request)
Creates new Subscribe.
~Subscribe()
Destructor.
std::string url() const
Returns connection URL.
ConnectionReply connect(std::string url, size_t timeout_ms =0)
Open a subscribe connection.
ConnectionReply connect(std::string url, const ConnectionOptions & connection_options)
Open a subscribe connection.
void close()
Closes connection to the server.
SubscriptionReply subscribe(std::vector< std::string > path_list, const std::string & group_alias, size_t frequency_divider) const
Create a subscription group for a list of the parameters.
StatusReply unsubscribe(const Subscription & subscription) const
Unsubscribes from the group.
Subscription()
Create new Subscription.
Subscription(const McxStatus & status)
Create new Subscription.
Subscription(const motorcortex_GroupStatusMsg & group_status_msg)
Create new Subscription.
std::vector< GetParameter > read() const
Read the latest values of the parameters in the group.
void notify(const std::function< void(std::vector< GetParameter >)> & observer_list)
Set an observer, which is notified on every group update.
uint32_t id() const
Return subscription identifier.
std::string alias() const
Return group alias.

Detailed Description

Subscribe class is used to receive continuous parameter updates from motorcortex server. It simplifies creating and removing subscription groups.

Subscription class represents a group of parameters. It returns the latest values and a timestamp of the group. Subscription class could be used as an observer, which notifies on every update or could be used as polling.

Functions Documentation

function Subscribe

Subscribe() =delete

function Subscribe

explicit Subscribe(
    const Request & request
)

Creates new Subscribe.

Parameters:

  • request - reference to a Request instance.

function ~Subscribe

~Subscribe()

Destructor.

function url

std::string url() const

Returns connection URL.

function connect

ConnectionReply connect(
    std::string url,
    size_t timeout_ms =0
)

Open a subscribe connection.

Parameters:

  • url - motorcortex server URL
  • timeout_ms - connection timeout in milliseconds

Return: status of the connection.

function connect

ConnectionReply connect(
    std::string url,
    const ConnectionOptions & connection_options
)

Open a subscribe connection.

Parameters:

  • url - motorcortex server URL
  • connection_options - additional options, e.g. certificate, timeout and connection state callback

Return: status of the connection.

function close

void close()

Closes connection to the server.

function subscribe

SubscriptionReply subscribe(
    std::vector< std::string > path_list,
    const std::string & group_alias,
    size_t frequency_divider
) const

Create a subscription group for a list of the parameters.

Parameters:

  • path_list - list of the parameters to subscribe to
  • group_alias - name of the group
  • frq_divider - frequency divider is a downscaling factor for the group publish rate

Return: a subscription handle, which acts as a Promise, it is resolved when subscription is ready or failed. After the subscription is ready the handle is used to retrieve latest data.

function unsubscribe

StatusReply unsubscribe(
    const Subscription & subscription
) const

Unsubscribes from the group.

Parameters:

  • subscription - subscription handle

Return: a promise, which resolves when the unsubscribe operation is complete, fails otherwise.

function Subscription

Subscription()

Create new Subscription.

function Subscription

explicit Subscription(
    const McxStatus & status
)

Create new Subscription.

Parameters:

  • status - set status to the subscription

function Subscription

explicit Subscription(
    const motorcortex_GroupStatusMsg & group_status_msg
)

Create new Subscription.

Parameters:

  • group_status_msg - set group status to the subscription

function read

std::vector< GetParameter > read() const

Read the latest values of the parameters in the group.

Return: list of the parameters.

function notify

void notify(
    const std::function< void(std::vector< GetParameter >)> & observer_list
)

Set an observer, which is notified on every group update.

Parameters:

  • observer_list - a list of callback functions

function id

uint32_t id() const

Return subscription identifier.

Return: subscription identifier

function alias

std::string alias() const

Return group alias.

Return: group alias


Updated on 2022-06-27 at 11:57:14 +0200