Session
The zenoh::Session is the main zenoh object. The instance of the session reprsents a single
zenoh node in the network.
Builder function
-
std::variant<zenoh::Session, zenoh::ErrorMessage> zenoh::open(zenoh::Config &&config, bool start_background_tasks = true)
Create a
Sessionwith the givenConfig- Parameters:
config –
Configto usestart_background_tasks – for zenoh-pico only. If true, start background threads which handles the network traffic. If false, the threads should be called manually with
Session::start_read_taskandSession::start_lease_taskor methodsSession::read,Session::send_keep_aliveandSession::send_joinshould be called in loop.
- Returns:
a
Sessionif the session was successfully created, anzenoh::ErrorMessageotherwise
Utility functions
-
void zenoh::init_logger()
Initializes logger.
User may set environment variable RUST_LOG to values debug | info | warn | error to show diagnostic output
Note
zenoh-c only
-
bool zenoh::scout(zenoh::ScoutingConfig &&config, zenoh::ClosureHello &&callback, ErrNo &error)
Scout for zenoh entities in the network.
- Parameters:
config –
ScoutingConfigto usecallback –
zenoh::ClosureHelloto process receivedHelloserror –
zenoh:ErrNoto store the error code
- Returns:
true if the scout operation was successful, false otherwise
-
bool zenoh::scout(zenoh::ScoutingConfig &&config, zenoh::ClosureHello &&callback)
Scout for zenoh entities in the network.
- Parameters:
config –
ScoutingConfigto usecallback –
zenoh::ClosureHelloto process receivedHellos
- Returns:
true if the scout operation was successful, false otherwise
Session class
-
class Session : public zenohcxx::Owned<::z_owned_session_t>
Main zenoh session class.
Methods
-
inline Session rcinc()
Clone the
Sessioninstance incrementing the reference count This is possible in zenoh-c only whereSessionis a reference counted object.- Returns:
a new
Sessioninstance
Note
zenoh-c only
-
inline zenoh::Id info_zid() const
Get the unique identifier of the zenoh node associated to this
Session- Returns:
the unique identifier
Id
-
zenoh::KeyExpr declare_keyexpr(const zenoh::KeyExprView &keyexpr)
Create
KeyExprinstance with numeric id registered inSessionrouting tables.- Parameters:
keyexpr –
KeyExprViewrepresenting string key expression- Returns:
KeyExprinstance
-
bool undeclare_keyexpr(zenoh::KeyExpr &&keyexpr, ErrNo &error)
Remove
KeyExprinstance fromSessionand dropKeyExprinstance.- Parameters:
keyexpr –
KeyExprinstance to droperror –
zenoh::ErrNoto store the error code
- Returns:
true if the
KeyExprinstance was successfully removed, false otherwise
-
bool undeclare_keyexpr(zenoh::KeyExpr &&keyexpr)
Remove
KeyExprinstance fromSessionand dropKeyExprinstance.
-
bool get(zenoh::KeyExprView keyexpr, const char *parameters, zenoh::ClosureReply &&callback, const zenoh::GetOptions &options, ErrNo &error)
Query data from the matching queryables in the system. Replies are provided through a callback function.
- Parameters:
keyexpr –
KeyExprViewthe key expression matching resources to queryparameters – the null-terminated string of query parameters
callback –
zenoh::ClosureReplycallback for processReplysoptions –
GetOptionsquery optionserror –
zenoh::ErrNoto store the error code
- Returns:
true if the query operation was successful, false otherwise
-
bool get(zenoh::KeyExprView keyexpr, const char *parameters, zenoh::ClosureReply &&callback, const zenoh::GetOptions &options)
Query data from the matching queryables in the system. Replies are provided through a callback function.
- Parameters:
keyexpr –
KeyExprViewthe key expression matching resources to queryparameters – the null-terminated string of query parameters
callback –
zenoh::ClosureReplycallback for processReplysoptions –
GetOptionsquery options
- Returns:
true if the query operation was successful, false otherwise
-
bool get(zenoh::KeyExprView keyexpr, const char *parameters, zenoh::ClosureReply &&callback, ErrNo &error)
Query data from the matching queryables in the system.
- Parameters:
keyexpr –
KeyExprViewthe key expression matching resources to queryparameters – the null-terminated string of query parameters
callback –
zenoh::ClosureReplycallback for processReplyserror –
zenoh::ErrNoto store the error code
- Returns:
true if the query operation was successful, false otherwise
-
bool get(zenoh::KeyExprView keyexpr, const char *parameters, zenoh::ClosureReply &&callback)
Query data from the matching queryables in the system.
- Parameters:
keyexpr –
KeyExprViewthe key expression matching resources to queryparameters – the null-terminated string of query parameters
callback –
zenoh::ClosureReplycallback for processReplys
- Returns:
true if the query operation was successful, false otherwise
-
bool put(zenoh::KeyExprView keyexpr, const zenoh::BytesView &payload, const zenoh::PutOptions &options, ErrNo &error)
Publish data to the matching subscribers in the system. Equal to
Publisher::put- Parameters:
keyexpr –
KeyExprViewthe key expression to put the datapayload –
BytesViewthe data to publishoptions –
PutOptionsput optionserror –
zenoh::ErrNoto store the error code
- Returns:
true if the publish operation was successful, false otherwise
-
bool put(zenoh::KeyExprView keyexpr, const zenoh::BytesView &payload, const zenoh::PutOptions &options)
Publish data to the matching subscribers in the system. Equal to
Publisher::put- Parameters:
keyexpr –
KeyExprViewthe key expression to put the datapayload –
BytesViewthe data to publishoptions –
PutOptionsput options
- Returns:
true if the publish operation was successful, false otherwise
-
bool put(zenoh::KeyExprView keyexpr, const zenoh::BytesView &payload, ErrNo &error)
Publish data to the matching subscribers in the system. Equal to
Publisher::put- Parameters:
keyexpr –
KeyExprViewthe key expression to put the datapayload –
BytesViewthe data to publisherror –
zenoh::ErrNoto store the error code
- Returns:
true if the publish operation was successful, false otherwise
-
bool put(zenoh::KeyExprView keyexpr, const zenoh::BytesView &payload)
Publish data to the matching subscribers in the system. Equal to
Publisher::put- Parameters:
keyexpr –
KeyExprViewthe key expression to put the datapayload –
BytesViewthe data to publish
- Returns:
true if the publish operation was successful, false otherwise
-
bool delete_resource(zenoh::KeyExprView keyexpr, const zenoh::DeleteOptions &options, ErrNo &error)
Undeclare a resource. Equal to
Publisher::delete_resource- Parameters:
keyexpr –
KeyExprViewthe key expression to delete the resourceoptions –
DeleteOptionsdelete optionserror –
zenoh::ErrNoto store the error code
- Returns:
true if the undeclare operation was successful, false otherwise
-
bool delete_resource(zenoh::KeyExprView keyexpr, const zenoh::DeleteOptions &options)
Undeclare a resource. Equal to
Publisher::delete_resource- Parameters:
keyexpr –
KeyExprViewthe key expression to delete the resourceoptions –
DeleteOptionsdelete options
- Returns:
true if the undeclare operation was successful, false otherwise
-
bool delete_resource(zenoh::KeyExprView keyexpr, ErrNo &error)
Undeclare a resource. Equal to
Publisher::delete_resource- Parameters:
keyexpr –
KeyExprViewthe key expression to delete the resourceerror –
zenoh::ErrNoto store the error code
- Returns:
true if the undeclare operation was successful, false otherwise
-
bool delete_resource(zenoh::KeyExprView keyexpr)
Undeclare a resource.
- Parameters:
keyexpr –
KeyExprViewthe key expression to delete the resource- Returns:
true if the undeclare operation was successful, false otherwise
-
bool put_owned(zenoh::KeyExprView keyexpr, zenoh::Payload &&payload, const zenoh::PutOptions &options, ErrNo &error)
Publish data to the matching subscribers in the system. Equal to
Publisher::put_owned- Parameters:
keyexpr –
KeyExprViewthe key expression to put the datapayload –
Payloadthe data to publishoptions –
PutOptionsput optionserror –
zenoh::ErrNoto store the error code
- Returns:
true if the publish operation was successful, false otherwise
Note
zenoh-c only
-
bool put_owned(zenoh::KeyExprView keyexpr, zenoh::Payload &&payload, const zenoh::PutOptions &options)
Publish data to the matching subscribers in the system. Equal to
Publisher::put_owned- Parameters:
keyexpr –
KeyExprViewthe key expression to put the datapayload –
Payloadthe data to publishoptions –
PutOptionsput options
- Returns:
true if the publish operation was successful, false otherwise
Note
zenoh-c only
-
bool put_owned(zenoh::KeyExprView keyexpr, zenoh::Payload &&payload, ErrNo &error)
Publish data to the matching subscribers in the system. Equal to
Publisher::put_owned- Parameters:
keyexpr –
KeyExprViewthe key expression to put the datapayload –
Payloadthe data to publisherror –
zenoh::ErrNoto store the error code
- Returns:
true if the publish operation was successful, false otherwise
Note
zenoh-c only
-
bool put_owned(zenoh::KeyExprView keyexpr, zenoh::Payload &&payload)
Publish data to the matching subscribers in the system. Equal to
Publisher::put_owned- Parameters:
keyexpr –
KeyExprViewthe key expression to put the datapayload –
Payloadthe data to publish
- Returns:
true if the publish operation was successful, false otherwise
Note
zenoh-c only
-
std::variant<zenoh::Queryable, ErrorMessage> declare_queryable(zenoh::KeyExprView keyexpr, zenoh::ClosureQuery &&callback, const zenoh::QueryableOptions &options)
Create a
Queryableobject to answer toSession::getrequests.- Parameters:
keyexpr –
KeyExprViewthe key expression to match theSession::getrequestscallback –
zenoh::ClosureQuerythe callback to handleQueryrequestsoptions –
QueryableOptionsqueryable options
- Returns:
a
Queryableobject if the declaration was successful, anzenoh::ErrorMessageotherwise
-
std::variant<zenoh::Queryable, ErrorMessage> declare_queryable(zenoh::KeyExprView keyexpr, zenoh::ClosureQuery &&callback)
Create a
Queryableobject to answer toSession::getrequests.- Parameters:
keyexpr –
KeyExprViewthe key expression to match theSession::getrequestscallback –
zenoh::ClosureQuerythe callback to handleQueryrequests
- Returns:
a
Queryableobject if the declaration was successful, anzenoh::ErrorMessageotherwise
-
std::variant<zenoh::Subscriber, ErrorMessage> declare_subscriber(zenoh::KeyExprView keyexpr, zenoh::ClosureSample &&callback, const zenoh::SubscriberOptions &options)
Create a
Subscriberobject to receive data from matchingPublisherobjects or fromSession::put,Session::delete_resourcerequests.- Parameters:
keyexpr –
KeyExprViewthe key expression to match the publisherscallback –
zenoh::ClosureSamplethe callback to handle the receivedSampleobjectsoptions –
SubscriberOptionssubscriber options
- Returns:
a
Subscriberobject if the declaration was successful, anzenoh::ErrorMessageotherwise
-
std::variant<zenoh::Subscriber, ErrorMessage> declare_subscriber(zenoh::KeyExprView keyexpr, zenoh::ClosureSample &&callback)
Create a
Subscriberobject to receive data from matchingPublisherobjects or fromSession::put,Session::delete_resourcerequests.- Parameters:
keyexpr –
KeyExprViewthe key expression to match the publisherscallback –
zenoh::ClosureSamplethe callback to handle the receivedSampleobjects
- Returns:
a
Subscriberobject if the declaration was successful, anzenoh::ErrorMessageotherwise
-
std::variant<zenoh::PullSubscriber, ErrorMessage> declare_pull_subscriber(zenoh::KeyExprView keyexpr, zenoh::ClosureSample &&callback, const zenoh::PullSubscriberOptions &options)
Create a
PullSubscriberobject to receive data from matchingPublisherobjects or fromSession::put,Session::delete_resourcerequests.- Parameters:
keyexpr –
KeyExprViewthe key expression to match the publisherscallback –
zenoh::ClosureSamplethe callback to handle the receivedSampleobjectsoptions –
PullSubscriberOptionspull subscriber options
- Returns:
a
PullSubscriberobject if the declaration was successful, anzenoh::ErrorMessageotherwise
-
std::variant<zenoh::PullSubscriber, ErrorMessage> declare_pull_subscriber(zenoh::KeyExprView keyexpr, zenoh::ClosureSample &&callback)
Create a
PullSubscriberobject to receive data from matchingPublisherobjects or fromSession::put,Session::delete_resourcerequests.- Parameters:
keyexpr –
KeyExprViewthe key expression to match the publisherscallback –
zenoh::ClosureSamplethe callback to handle the receivedSampleobjects
- Returns:
a
PullSubscriberobject if the declaration was successful, anzenoh::ErrorMessageotherwise
-
std::variant<zenoh::Publisher, ErrorMessage> declare_publisher(zenoh::KeyExprView keyexpr, const zenoh::PublisherOptions &options)
Create a
Publisherobject to publish data to matchingSubscriberandPullSubscriberobjects.- Parameters:
keyexpr –
KeyExprViewthe key expression to match the subscribersoptions –
PublisherOptionspublisher options
- Returns:
a
Publisherobject if the declaration was successful, anzenoh::ErrorMessageotherwise
-
std::variant<zenoh::Publisher, ErrorMessage> declare_publisher(zenoh::KeyExprView keyexpr)
Create a
Publisherobject to publish data to matchingSubscriberandPullSubscriberobjects.- Parameters:
keyexpr –
KeyExprViewthe key expression to match the subscribers- Returns:
a
Publisherobject if the declaration was successful, anzenoh::ErrorMessageotherwise
-
bool info_routers_zid(zenoh::ClosureZid &&callback, ErrNo &error)
Fetches the Zenoh IDs of all connected routers.
- Parameters:
callback –
zenoh::ClosureZidthe callback to handle the receivedIdobjects. Callback is guaranteed to never be called concurrently, and is guaranteed to be dropped before this function exits.error –
zenoh::ErrNothe error code
- Returns:
true if the operation was successful, false otherwise
-
bool info_routers_zid(zenoh::ClosureZid &&callback)
Fetches the Zenoh IDs of all connected routers.
- Parameters:
callback –
zenoh::ClosureZidthe callback to handle the receivedIdobjects. Callback is guaranteed to never be called concurrently, and is guaranteed to be dropped before this function exits.- Returns:
true if the operation was successful, false otherwise
-
bool info_peers_zid(zenoh::ClosureZid &&callback, ErrNo &error)
Fetches the Zenoh IDs of all connected peers.
- Parameters:
callback –
zenoh::ClosureZidthe callback to handle the receivedIdobjects. Callback is guaranteed to never be called concurrently, and is guaranteed to be dropped before this function exits.error –
zenoh::ErrNothe error code
- Returns:
true if the operation was successful, false otherwise
-
bool info_peers_zid(zenoh::ClosureZid &&callback)
Fetches the Zenoh IDs of all connected peers.
- Parameters:
callback –
zenoh::ClosureZidthe callback to handle the receivedIdobjects. Callback is guaranteed to never be called concurrently, and is guaranteed to be dropped before this function exits.- Returns:
true if the operation was successful, false otherwise
-
bool start_read_task()
Start a separate task to read from the network and process the messages as soon as they are received.
- Returns:
true if the operation was successful, false otherwise
Note
zenoh-pico only
-
bool start_read_task(ErrNo &error)
Start a separate task to read from the network and process the messages as soon as they are received.
- Parameters:
error –
zenoh::ErrNothe error code- Returns:
true if the operation was successful, false otherwise
Note
zenoh-pico only
-
bool stop_read_task()
Stop the read task.
- Returns:
true if the operation was successful, false otherwise
Note
zenoh-pico only
-
bool stop_read_task(ErrNo &error)
Stop the read task.
- Parameters:
error –
zenoh::ErrNothe error code- Returns:
true if the operation was successful, false otherwise
Note
zenoh-pico only
-
bool start_lease_task()
Start a separate task to handle the session lease. This task will send KeepAlive messages when needed and will close the session when the lease is expired. When operating over a multicast transport, it also periodically sends the Join messages.
- Returns:
true if the operation was successful, false otherwise
Note
zenoh-pico only
-
bool start_lease_task(ErrNo &error)
Start a separate task to handle the session lease. This task will send KeepAlive messages when needed and will close the session when the lease is expired. When operating over a multicast transport, it also periodically sends the Join messages.
- Parameters:
error –
zenoh::ErrNothe error code- Returns:
true if the operation was successful, false otherwise
Note
zenoh-pico only
-
bool stop_lease_task()
Stop the lease task.
- Returns:
true if the operation was successful, false otherwise
Note
zenoh-pico only
-
bool stop_lease_task(ErrNo &error)
Stop the lease task.
- Parameters:
error –
zenoh::ErrNothe error code- Returns:
true if the operation was successful, false otherwise
Note
zenoh-pico only
-
bool read()
Triggers a single execution of reading procedure from the network and processes of any received the message.
- Returns:
true if the operation was successful, false otherwise
Note
zenoh-pico only
-
bool read(ErrNo &error)
Triggers a single execution of reading procedure from the network and processes of any received the message.
- Parameters:
error –
zenoh::ErrNothe error code- Returns:
true if the operation was successful, false otherwise
Note
zenoh-pico only
-
bool send_keep_alive()
Triggers a single execution of keep alive procedure. It will send KeepAlive messages when needed and will close the session when the lease is expired.
- Returns:
true if the leasing procedure was executed successfully, false otherwise.
-
bool send_keep_alive(ErrNo &error)
Triggers a single execution of keep alive procedure. It will send KeepAlive messages when needed and will close the session when the lease is expired.
- Parameters:
error –
zenoh::ErrNothe error code- Returns:
true if the leasing procedure was executed successfully, false otherwise.
-
bool send_join()
Triggers a single execution of join procedure: send the Join message.
- Returns:
true if the join procedure was executed successfully, false otherwise.
-
bool send_join(ErrNo &error)
Triggers a single execution of join procedure: send the Join message.
- Parameters:
error –
zenoh::ErrNothe error code- Returns:
true if the join procedure was executed successfully, false otherwise.
-
zenoh::KeyExpr keyexpr_concat(const zenoh::KeyExprView &k, const std::string_view &s)
Concatenate the key expression and a string, resolving them if necessary.
- Parameters:
k – the key expression
s –
std::string_viewrepresenting a key expression
- Returns:
Newly allocated key expression
zenoh::KeyExpr
Note
zenoh-c only
-
zenoh::KeyExpr keyexpr_join(const zenoh::KeyExprView &a, const zenoh::KeyExprView &b)
Join two key expressions, inserting a separator between them.
- Parameters:
a – Key expression
b – Key expressio
- Returns:
Newly allocated key expression
zenoh::KeyExpr
Note
zenoh-c only
-
bool keyexpr_equals(const zenoh::KeyExprView &a, const zenoh::KeyExprView &b, ErrNo &error)
Checks if the two key expressions are equal, resolving them if necessary.
- Parameters:
a – Key expression
b – Key expression
error – Error code returned by
::z_keyexpr_equals(value < -1 if any of the key expressions is not valid)
- Returns:
true the key expressions are equal
-
bool keyexpr_equals(const zenoh::KeyExprView &a, const zenoh::KeyExprView &b)
Checks if the two key expressions are equal, resolving them if necessary.
- Parameters:
a – Key expression
b – Key expression
- Returns:
true the key expressions are equal
-
bool keyexpr_includes(const zenoh::KeyExprView &a, const zenoh::KeyExprView &b, ErrNo &error)
Checks if the key expression “a” includes expression “b”, resolving them if necessary.
- Parameters:
a – Key expression
b – Key expression
error – Error code returned by
::z_keyexpr_includes(value < -1 if any of the key expressions is not valid)
- Returns:
true the key expression includes the other key expression
-
bool keyexpr_includes(const zenoh::KeyExprView &a, const zenoh::KeyExprView &b)
Checks if the key expression “a” includes key expression “b”, resolving them if necessary.
- Parameters:
a – Key expression
b – Key expression
- Returns:
true the key expression includes the other key expression
-
bool keyexpr_intersects(const zenoh::KeyExprView &a, const zenoh::KeyExprView &b, ErrNo &error)
Checks if the key expression intersects with another key expression, resolving them if necessaRY. “Intersects” means that exists at least one key which is contained in both of the sets defined by the key expressions.
- Parameters:
a – Key expression
b – Key expression
error – Error code returned by
::z_keyexpr_intersects(value < -1 if any of the key expressions is not valid)
- Returns:
true the key expression intersects with the other key expression
-
bool keyexpr_intersects(const zenoh::KeyExprView &a, const zenoh::KeyExprView &b)
Checks if the key expression intersects with another key expression, resolving them if necessaRY. “Intersects” means that exists at least one key which is contained in both of the sets defined by the key expressions.
- Parameters:
a – Key expression
b – Key expression
- Returns:
true the key expression intersects with the other key expression
-
inline Session rcinc()