CppWAMP
C++11 client library for the WAMP protocol
wamp::CoroSession< TIgnoredBase > Class Template Reference

Coroutine API used by a client peer in WAMP applications. More...

#include <cppwamp/coro/corosession.hpp>

Inheritance diagram for wamp::CoroSession< TIgnoredBase >:

Public Types

using Ptr = std::shared_ptr< CoroSession >
 Shared pointer to a CoroSession.
 
using Base = Session
 The base class type that this mixin extends.
 
using State = SessionState
 Enumerates the possible states that a CoroSession can be in.
 
using EventSlot = std::function< void(Event)>
 Function type for handling pub/sub events.
 
using CallSlot = std::function< Outcome(Invocation)>
 Function type for handling remote procedure calls.
 
using InterruptSlot = std::function< Outcome(Interruption)>
 Function type for handling RPC interruptions.
 
template<typename TSpawnHandler >
using YieldContext = boost::asio::basic_yield_context< TSpawnHandler >
 Yield context type used by the boost::asio::spawn handler.
 
- Public Types inherited from wamp::Session
using Ptr = std::shared_ptr< Session >
 Shared pointer to a Session.
 
using State = SessionState
 Enumerates the possible states that a Session can be in.
 
using EventSlot = AnyReusableHandler< void(Event)>
 Type-erased wrapper around a WAMP event handler.
 
using CallSlot = AnyReusableHandler< Outcome(Invocation)>
 Type-erased wrapper around an RPC handler.
 
using InterruptSlot = AnyReusableHandler< Outcome(Interruption)>
 Type-erased wrapper around an RPC interruption handler.
 
using LogHandler = AnyReusableHandler< void(std::string)>
 Type-erased wrapper around a log event handler.
 
using StateChangeHandler = AnyReusableHandler< void(SessionState)>
 Type-erased wrapper around a Session state change handler.
 
using ChallengeHandler = AnyReusableHandler< void(Challenge)>
 Type-erased wrapper around an authentication challenge handler.
 
template<typename T , typename C >
using Deduced = decltype(boost::asio::async_initiate< C, void(T)>(std::declval< GenericOp & >(), std::declval< C & >()))
 Obtains the type returned by boost::asio::async_initiate with given the completion token type C and signature void(T). More...
 

Public Member Functions

Session Management
void connect (AsyncHandler< size_t > handler)
 Asynchronously attempts to connect to a router. More...
 
template<typename H >
size_t connect (YieldContext< H > yield, std::error_code *ec=nullptr)
 Attempts to connect to a router. More...
 
void join (Realm realm, AsyncHandler< SessionInfo > handler)
 Asynchronously attempts to join the given WAMP realm. More...
 
template<typename H >
SessionInfo join (Realm realm, YieldContext< H > yield, std::error_code *ec=nullptr)
 Attempts to join the given WAMP realm. More...
 
void authenticate (Authentication auth)
 Sends an AUTHENTICATE in response to a CHALLENGE. More...
 
void leave (AsyncHandler< Reason > handler)
 Asynchronously leaves the WAMP session. More...
 
template<typename H >
Reason leave (YieldContext< H > yield, std::error_code *ec=nullptr)
 Leaves the WAMP session. More...
 
void leave (Reason reason, AsyncHandler< Reason > handler)
 Asynchronously leaves the WAMP session with the given reason. More...
 
template<typename H >
Reason leave (Reason reason, YieldContext< H > yield, std::error_code *ec=nullptr)
 Leaves the WAMP session with the given reason. More...
 
Pub/Sub
void subscribe (Topic topic, EventSlot slot, AsyncHandler< Subscription > handler)
 Asynchronously subscribes to WAMP pub/sub events having the given topic. More...
 
template<typename H >
Subscription subscribe (Topic topic, EventSlot slot, YieldContext< H > yield, std::error_code *ec=nullptr)
 Subscribes to WAMP pub/sub events having the given topic. More...
 
void unsubscribe (const Subscription &sub)
 Unsubscribes a subscription to a topic. More...
 
void unsubscribe (const Subscription &sub, AsyncHandler< bool > handler)
 Asynchronously unsubscribes a subscription to a topic and waits for router acknowledgement, if necessary. More...
 
template<typename H >
bool unsubscribe (const Subscription &sub, YieldContext< H > yield, std::error_code *ec=nullptr)
 Unsubscribes a subscription to a topic and waits for router acknowledgement if necessary. More...
 
void publish (Pub pub)
 Publishes an event. More...
 
void publish (Pub pub, AsyncHandler< PublicationId > handler)
 Asynchronously publishes an event and waits for an acknowledgement from the router. More...
 
template<typename H >
PublicationId publish (Pub pub, YieldContext< H > yield, std::error_code *ec=nullptr)
 Publishes an event and waits for an acknowledgement from the router. More...
 
Remote Procedures
void enroll (Procedure procedure, CallSlot slot, AsyncHandler< Registration > handler)
 Asynchronously registers a WAMP remote procedure call. More...
 
template<typename H >
Registration enroll (Procedure procedure, CallSlot slot, YieldContext< H > yield, std::error_code *ec=nullptr)
 Registers a WAMP remote procedure call. More...
 
void enroll (Procedure procedure, CallSlot callSlot, InterruptSlot interruptSlot, AsyncHandler< Registration > handler)
 Asynchronously registers a WAMP remote procedure call with an interruption handler. More...
 
template<typename H >
Registration enroll (Procedure procedure, CallSlot slot, InterruptSlot interruptSlot, YieldContext< H > yield, std::error_code *ec=nullptr)
 Registers a WAMP remote procedure call with an interruption handler. More...
 
void unregister (const Registration &reg)
 Unregisters a remote procedure call. More...
 
void unregister (const Registration &reg, AsyncHandler< bool > handler)
 Asynchronously unregisters a remote procedure call and waits for router acknowledgement. More...
 
template<typename H >
bool unregister (const Registration &reg, YieldContext< H > yield, std::error_code *ec=nullptr)
 Unregisters a remote procedure call and waits for router acknowledgement. More...
 
RequestId call (Rpc procedure, AsyncHandler< Result > handler)
 Asynchronously calls a remote procedure. More...
 
template<typename H >
Result call (Rpc rpc, YieldContext< H > yield, std::error_code *ec=nullptr)
 Calls a remote procedure. More...
 
Coroutine
template<typename H >
void suspend (YieldContext< H > yield)
 Cooperatively suspend this coroutine to allow others to run. More...
 
Deleted Functions
void reset ()=delete
 The reset function is removed from the coroutine API. More...
 
- Public Member Functions inherited from wamp::Session
virtual ~Session ()
 Destructor. More...
 
 Session (const Session &)=delete
 
Sessionoperator= (const Session &)=delete
 
AnyIoExecutor userExecutor () const
 Obtains the fallback executor used to execute user-provided handlers.
 
AnyIoExecutor userIosvc () const
 Legacy function kept for backward compatiblity. More...
 
IoStrand strand () const
 Obtains the execution context in which which I/O operations are serialized.
 
SessionState state () const
 Returns the current state of the session.
 
void setWarningHandler (LogHandler handler)
 Sets the log handler that is dispatched for warnings. More...
 
void setWarningHandler (ThreadSafe, LogHandler handler)
 Thread-safe setting of warning handler. More...
 
void setTraceHandler (LogHandler handler)
 Sets the log handler that is dispatched for debug traces. More...
 
void setTraceHandler (ThreadSafe, LogHandler handler)
 Thread-safe setting of trace handler. More...
 
void setStateChangeHandler (StateChangeHandler handler)
 Sets the handler that is posted for session state changes. More...
 
void setStateChangeHandler (ThreadSafe, StateChangeHandler handler)
 Thread-safe setting of state change handler. More...
 
void setChallengeHandler (ChallengeHandler handler)
 Sets the handler that is dispatched for authentication challenges. More...
 
void setChallengeHandler (ThreadSafe, ChallengeHandler handler)
 Thread-safe setting of state change handler. More...
 
template<typename C >
Deduced< ErrorOr< std::size_t >, C > connect (C &&completion)
 Asynchronously attempts to connect to a router. More...
 
template<typename C >
Deduced< ErrorOr< std::size_t >, C > connect (ThreadSafe, C &&completion)
 Thread-safe connect. More...
 
template<typename C >
Deduced< ErrorOr< SessionInfo >, C > join (Realm realm, C &&completion)
 Asynchronously attempts to join the given WAMP realm. More...
 
template<typename C >
Deduced< ErrorOr< SessionInfo >, C > join (ThreadSafe, Realm realm, C &&completion)
 Thread-safe join. More...
 
void authenticate (Authentication auth)
 Sends an AUTHENTICATE in response to a CHALLENGE. More...
 
void authenticate (ThreadSafe, Authentication auth)
 Thread-safe authenticate. More...
 
template<typename C >
Deduced< ErrorOr< Reason >, C > leave (C &&completion)
 Asynchronously leaves the WAMP session. More...
 
template<typename C >
Deduced< ErrorOr< Reason >, C > leave (ThreadSafe, C &&completion)
 Thread-safe leave. More...
 
template<typename C >
Deduced< ErrorOr< Reason >, C > leave (Reason reason, C &&completion)
 Asynchronously leaves the WAMP session with the given reason. More...
 
template<typename C >
Deduced< ErrorOr< Reason >, C > leave (ThreadSafe, Reason reason, C &&completion)
 Thread-safe leave with reason. More...
 
void disconnect ()
 Disconnects the transport between the client and router. More...
 
void disconnect (ThreadSafe)
 Thread-safe disconnect. More...
 
void reset ()
 Terminates the transport connection between the client and router. More...
 
void reset (ThreadSafe)
 Thread-safe reset. More...
 
template<typename C >
Deduced< ErrorOr< Subscription >, C > subscribe (Topic topic, EventSlot eventSlot, C &&completion)
 Subscribes to WAMP pub/sub events having the given topic. More...
 
template<typename C >
Deduced< ErrorOr< Subscription >, C > subscribe (ThreadSafe, Topic topic, EventSlot eventSlot, C &&completion)
 Thread-safe subscribe. More...
 
void unsubscribe (Subscription sub)
 Unsubscribes a subscription to a topic. More...
 
void unsubscribe (ThreadSafe, Subscription sub)
 Thread-safe unsubscribe. More...
 
template<typename C >
Deduced< ErrorOr< bool >, C > unsubscribe (Subscription sub, C &&completion)
 Unsubscribes a subscription to a topic and waits for router acknowledgement, if necessary. More...
 
template<typename C >
Deduced< ErrorOr< bool >, C > unsubscribe (ThreadSafe, Subscription sub, C &&completion)
 Thread-safe acknowledged unsubscribe. More...
 
void publish (Pub pub)
 Publishes an event. More...
 
void publish (ThreadSafe, Pub pub)
 Thread-safe publish. More...
 
template<typename C >
Deduced< ErrorOr< PublicationId >, C > publish (Pub pub, C &&completion)
 Publishes an event and waits for an acknowledgement from the router. More...
 
template<typename C >
Deduced< ErrorOr< PublicationId >, C > publish (ThreadSafe, Pub pub, C &&completion)
 Thread-safe acknowledged publish. More...
 
template<typename C >
Deduced< ErrorOr< Registration >, C > enroll (Procedure procedure, CallSlot callSlot, C &&completion)
 Registers a WAMP remote procedure call. More...
 
template<typename C >
Deduced< ErrorOr< Registration >, C > enroll (ThreadSafe, Procedure procedure, CallSlot callSlot, C &&completion)
 Thread-safe enroll. More...
 
template<typename C >
Deduced< ErrorOr< Registration >, C > enroll (Procedure procedure, CallSlot callSlot, InterruptSlot interruptSlot, C &&completion)
 Registers a WAMP remote procedure call with an interruption handler. More...
 
template<typename C >
Deduced< ErrorOr< Registration >, C > enroll (ThreadSafe, Procedure procedure, CallSlot callSlot, InterruptSlot interruptSlot, C &&completion)
 Thread-safe enroll interruptible. More...
 
void unregister (Registration reg)
 Unregisters a remote procedure call. More...
 
void unregister (ThreadSafe, Registration reg)
 Thread-safe unregister. More...
 
template<typename C >
Deduced< ErrorOr< bool >, C > unregister (Registration reg, C &&completion)
 Unregisters a remote procedure call and waits for router acknowledgement. More...
 
template<typename C >
Deduced< ErrorOr< bool >, C > unregister (ThreadSafe, Registration reg, C &&completion)
 Thread-safe acknowledged unregister. More...
 
template<typename C >
Deduced< ErrorOr< Result >, C > call (Rpc rpc, C &&completion)
 Calls a remote procedure. More...
 
template<typename C >
Deduced< ErrorOr< Result >, C > call (ThreadSafe, Rpc rpc, C &&completion)
 Thread-safe call. More...
 
template<typename C >
Deduced< ErrorOr< Result >, C > call (Rpc rpc, CallChit &chit, C &&completion)
 Calls a remote procedure, obtaining a token that can be used for cancellation. More...
 
template<typename C >
Deduced< ErrorOr< Result >, C > call (ThreadSafe, Rpc rpc, CallChit &chit, C &&completion)
 Thread-safe call with CallChit capture. More...
 
void cancel (CallChit)
 Cancels a remote procedure using the cancel mode that was specified in the Rpc. More...
 
void cancel (ThreadSafe, CallChit)
 Thread-safe cancel. More...
 
void cancel (CallChit, CallCancelMode mode)
 Cancels a remote procedure using the given mode. More...
 
void cancel (ThreadSafe, CallChit, CallCancelMode mode)
 Thread-safe cancel with a given mode. More...
 
void cancel (CallCancellation cancellation)
 Cancels a remote procedure. More...
 
void cancel (ThreadSafe, CallCancellation cancellation)
 Thread-safe cancel. More...
 

Static Public Member Functions

static Ptr create (AnyIoExecutor exec, const Connector::Ptr &connector)
 Creates a new CoroSession instance. More...
 
static Ptr create (AnyIoExecutor exec, const ConnectorList &connectors)
 Creates a new CoroSession instance. More...
 
template<typename TExecutionContext >
static Ptr create (TExecutionContext &context, const Connector::Ptr &connector)
 Creates a new CoroSession instance. More...
 
template<typename TExecutionContext >
static Ptr create (TExecutionContext &context, const ConnectorList &connectors)
 Creates a new CoroSession instance. More...
 
- Static Public Member Functions inherited from wamp::Session
static Ptr create (AnyIoExecutor exec, const Connector::Ptr &connector)
 Creates a new Session instance. More...
 
static Ptr create (AnyIoExecutor exec, const ConnectorList &connectors)
 Creates a new Session instance. More...
 
template<typename TExecutionContext >
static Ptr create (TExecutionContext &context, const Connector::Ptr &connector)
 Creates a new Session instance. More...
 
template<typename TExecutionContext >
static Ptr create (TExecutionContext &context, const ConnectorList &connectors)
 Creates a new Session instance. More...
 
static const Objectroles ()
 Obtains a dictionary of roles and features supported on the client side. More...
 

Detailed Description

template<typename TIgnoredBase = Session>
class wamp::CoroSession< TIgnoredBase >

Coroutine API used by a client peer in WAMP applications.

Deprecated:
Use wamp::Session with completion tokens instead.

This class differs from Session as follows:

  • Only callback handler functions or [boost::asio::yield_context][yieldcontext] can be used as completion tokens.
  • The results of coroutine operations are returned directly by the function, instead of via an ErrorOr object.
  • Runtime errors are thrown as error::Failure exceptions.
  • An optional pointer to a std::error_code can be passed to coroutine operations. If a runtime error occurs, it will set the pointed-to error code instead of throwing an error::Failure exception.
Aborting Coroutine Operations
All pending coroutine operations can be aborted by dropping the client connection via Session::disconnect. Pending post-join operations can be also be aborted via CoroSession::leave. Operations aborted in this manner will throw an error::Failure exception. There is currently no way to abort a single operation via this class without dropping the connection or leaving the realm.
Mixins
The mixin feature where this class can be combined with other Session-like classes has been disabled. This class' template parameter is now ignored and it now behaves as if it were mixed in with Session.
Template Parameters
TBaseIgnored
See also
Session, Registration, Subscription.

Member Function Documentation

◆ create() [1/4]

template<typename B >
CoroSession< B >::Ptr wamp::CoroSession< B >::create ( AnyIoExecutor  exec,
const Connector::Ptr connector 
)
static

Creates a new CoroSession instance.

The provided executor serves as a fallback when asynchronous operation handlers don't bind a specific executor (in lieu of using the system executor as fallback.

Postcondition
session->state() == SessionState::disconnected
Returns
A shared pointer to the created session object.
Parameters
execExecutor with which to post all user-provided handlers.
connectorConnection details for the transport to use.

◆ create() [2/4]

template<typename B >
CoroSession< B >::Ptr wamp::CoroSession< B >::create ( AnyIoExecutor  exec,
const ConnectorList connectors 
)
static

Creates a new CoroSession instance.

The provided executor serves as a fallback when asynchronous operation handlers don't bind a specific executor (in lieu of using the system executor as fallback.

Precondition
connectors.empty() == false
Postcondition
session->state() == SessionState::disconnected
Returns
A shared pointer to the created Session object.
Exceptions
error::Logicif connectors.empty() == true
Parameters
execExecutor with which to post all user-provided handlers.
connectorsA list of connection details for the transports to use.

◆ create() [3/4]

template<typename TIgnoredBase = Session>
template<typename TExecutionContext >
static Ptr wamp::CoroSession< TIgnoredBase >::create ( TExecutionContext &  context,
const Connector::Ptr connector 
)
inlinestatic

Creates a new CoroSession instance.

The provided executor serves as a fallback when asynchronous operation handlers don't bind a specific executor (in lieu of using the system executor as fallback.

Postcondition
session->state() == SessionState::disconnected
Returns
A shared pointer to the created session object.

Only participates in overload resolution when isExecutionContext<TExecutionContext>() == true

Template Parameters
TExecutionContextMust meet the requirements of Boost.Asio's ExecutionContext
Parameters
contextProvides executor with which to post all user-provided handlers.
connectorConnection details for the transport to use.

◆ create() [4/4]

template<typename TIgnoredBase = Session>
template<typename TExecutionContext >
static Ptr wamp::CoroSession< TIgnoredBase >::create ( TExecutionContext &  context,
const ConnectorList connectors 
)
inlinestatic

Creates a new CoroSession instance.

The provided executor serves as a fallback when asynchronous operation handlers don't bind a specific executor (in lieu of using the system executor as fallback.

Postcondition
session->state() == SessionState::disconnected
Returns
A shared pointer to the created session object.

Only participates in overload resolution when isExecutionContext<TExecutionContext>() == true

Template Parameters
TExecutionContextMust meet the requirements of Boost.Asio's ExecutionContext
Parameters
contextProvides executor with which to post all user-provided handlers.
connectorsConnection details for the transport to use.

◆ connect() [1/2]

template<typename B >
void wamp::CoroSession< B >::connect ( AsyncHandler< size_t >  handler)

Asynchronously attempts to connect to a router.

The session will attempt to connect using the transports that were specified by the wamp::Connector objects passed during create(). If more than one transport was specified, they will be traversed in the same order as they appeared in the ConnectorList.

Returns
The index of the Connector object used to establish the connetion.
Precondition
this->state() == SessionState::disconnected
Postcondition
this->state() == SessionState::connecting
Error Codes
  • TransportErrc::aborted if the connection attempt was aborted.
  • SessionErrc::allTransportsFailed if more than one transport was specified and they all failed to connect.
  • Some other platform or transport-dependent std::error_code if only one transport was specified and it failed to connect.
Exceptions
error::Logicif this->state() != SessionState::disconnected
Parameters
handlerHandler to invoke when the operation completes.

◆ connect() [2/2]

template<typename B >
template<typename H >
size_t wamp::CoroSession< B >::connect ( YieldContext< H >  yield,
std::error_code *  ec = nullptr 
)

Attempts to connect to a router.

The session will attempt to connect using the transports that were specified by the wamp::Connector objects passed during create(). If more than one transport was specified, they will be traversed in the same order as they appeared in the ConnectorList.

Returns
The index of the Connector object used to establish the connetion.
Precondition
this->state() == SessionState::disconnected
Postcondition
this->state() == SessionState::connecting
Error Codes
  • TransportErrc::aborted if the connection attempt was aborted.
  • SessionErrc::allTransportsFailed if more than one transport was specified and they all failed to connect.
  • Some other platform or transport-dependent std::error_code if only one transport was specified and it failed to connect.
Exceptions
error::Logicif this->state() != SessionState::disconnected
error::Failurewith an error code if a runtime error occured and the ec parameter is null.
Parameters
yieldRepresents the current coroutine.
ecOptional pointer to an error code to set, instead of throwing an exception upon failure.

◆ join() [1/2]

template<typename B >
void wamp::CoroSession< B >::join ( Realm  realm,
AsyncHandler< SessionInfo handler 
)

Asynchronously attempts to join the given WAMP realm.

Returns
A SessionInfo object with details on the newly established session.
Precondition
this->state() == SessionState::connected
Postcondition
this->state() == SessionState::establishing
Error Codes
Exceptions
error::Logicif this->state() != SessionState::connected
Parameters
realmDetails on the realm to join.
handlerHandler to invoke when the operation completes.

◆ join() [2/2]

template<typename B >
template<typename H >
SessionInfo wamp::CoroSession< B >::join ( Realm  realm,
YieldContext< H >  yield,
std::error_code *  ec = nullptr 
)

Attempts to join the given WAMP realm.

Returns
A SessionInfo object with details on the newly established session.
Precondition
this->state() == SessionState::connected
Postcondition
this->state() == SessionState::establishing
Error Codes
Exceptions
error::Logicif this->state() != SessionState::connected
error::Failurewith an error code if a runtime error occured and the ec parameter is null.
Parameters
realmDetails on the realm to join.
yieldRepresents the current coroutine.
ecOptional pointer to an error code to set, instead of throwing an exception upon failure.

◆ authenticate()

template<typename B >
void wamp::CoroSession< B >::authenticate ( Authentication  auth)

Sends an AUTHENTICATE in response to a CHALLENGE.

Precondition
this->state() == SessionState::authenticating
Exceptions
error::Logicif this->state() != SessionState::authenticating

◆ leave() [1/4]

template<typename B >
void wamp::CoroSession< B >::leave ( AsyncHandler< Reason handler)

Asynchronously leaves the WAMP session.

The "wamp.close.close_realm" reason is sent as part of the outgoing GOODBYE message.

Returns
The Reason URI and details from the GOODBYE response returned by the router.
Precondition
this->state() == SessionState::established
Postcondition
this->state() == SessionState::shuttingDown
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
Parameters
handlerHandler to invoke when the operation completes.

◆ leave() [2/4]

template<typename B >
template<typename H >
Reason wamp::CoroSession< B >::leave ( YieldContext< H >  yield,
std::error_code *  ec = nullptr 
)

Leaves the WAMP session.

The "wamp.close.close_realm" reason is sent as part of the outgoing GOODBYE message.

Returns
The Reason URI and details from the GOODBYE response returned by the router.
Precondition
this->state() == SessionState::established
Postcondition
this->state() == SessionState::shuttingDown
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
error::Failurewith an error code if a runtime error occured and the ec parameter is null.
Parameters
yieldRepresents the current coroutine.
ecOptional pointer to an error code to set, instead of throwing an exception upon failure.

◆ leave() [3/4]

template<typename B >
void wamp::CoroSession< B >::leave ( Reason  reason,
AsyncHandler< Reason handler 
)

Asynchronously leaves the WAMP session with the given reason.

Returns
The Reason URI and details from the GOODBYE response returned by the router.
Precondition
this->state() == SessionState::established
Postcondition
this->state() == SessionState::shuttingDown
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
Parameters
reasonReason URI and other options
handlerHandler to invoke when the operation completes.

◆ leave() [4/4]

template<typename B >
template<typename H >
Reason wamp::CoroSession< B >::leave ( Reason  reason,
YieldContext< H >  yield,
std::error_code *  ec = nullptr 
)

Leaves the WAMP session with the given reason.

Returns
The Reason URI and details from the GOODBYE response returned by the router.
Precondition
this->state() == SessionState::established
Postcondition
this->state() == SessionState::shuttingDown
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
error::Failurewith an error code if a runtime error occured and the ec parameter is null.
Parameters
reason_Reason_ URI and other details to send to the router.
yieldRepresents the current coroutine.
ecOptional pointer to an error code to set, instead of throwing an exception upon failure.

◆ subscribe() [1/2]

template<typename B >
void wamp::CoroSession< B >::subscribe ( Topic  topic,
EventSlot  slot,
AsyncHandler< Subscription handler 
)

Asynchronously subscribes to WAMP pub/sub events having the given topic.

See also
Subscriptions
Returns
A Subscription object, therafter used to manage the subscription's lifetime.
Precondition
this->state() == SessionState::established
Error Codes
  • SessionErrc::subscribeError if the router replied with an ERROR response.
  • Some other std::error_code for protocol and transport errors.
Exceptions
error::Logicif this->state() != SessionState::established
Parameters
topicThe topic to subscribe to.
slotThe callable target to invoke when a matching event is received.
handlerHandler to invoke when the subscribe operation completes.

◆ subscribe() [2/2]

template<typename B >
template<typename H >
Subscription wamp::CoroSession< B >::subscribe ( Topic  topic,
EventSlot  slot,
YieldContext< H >  yield,
std::error_code *  ec = nullptr 
)

Subscribes to WAMP pub/sub events having the given topic.

See also
Subscriptions
Returns
A Subscription object, therafter used to manage the subscription's lifetime.
Precondition
this->state() == SessionState::established
Error Codes
  • SessionErrc::subscribeError if the router replied with an ERROR response.
  • Some other std::error_code for protocol and transport errors.
Exceptions
error::Logicif this->state() != SessionState::established
error::Failurewith an error code if a runtime error occured and the ec parameter is null.
Parameters
topicDetails on the topic to subscribe to.
slotThe callable target to invoke when a matching event is received.
yieldRepresents the current coroutine.
ecPointer to an optional error code to set instead of throwing an exception upon failure.

◆ unsubscribe() [1/3]

template<typename B >
void wamp::CoroSession< B >::unsubscribe ( const Subscription sub)

Unsubscribes a subscription to a topic.

This function can be safely called during any session state. If the subscription is no longer applicable, then the unsubscribe operation will effectively do nothing.

See also
Subscription, ScopedSubscription
Note
Duplicate unsubscribes using the same Subscription object are safely ignored.
Precondition
!!sub == true
Exceptions
error::Logicif the given subscription is empty
Parameters
subThe subscription to unsubscribe from.

◆ unsubscribe() [2/3]

template<typename B >
void wamp::CoroSession< B >::unsubscribe ( const Subscription sub,
AsyncHandler< bool >  handler 
)

Asynchronously unsubscribes a subscription to a topic and waits for router acknowledgement, if necessary.

If there are other local subscriptions on this session remaining for the same topic, then the session does not send an UNSUBSCRIBE message to the router.

See also
Subscription, ScopedSubscription
Returns
false if the subscription was already removed, true otherwise.
Note
Duplicate unsubscribes using the same Subscription handle are safely ignored.
Precondition
!!sub == true
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif the given subscription is empty
error::Logicif this->state() != SessionState::established
Parameters
subThe subscription to unsubscribe from.
handlerHandler to invoke when the operation completes.

◆ unsubscribe() [3/3]

template<typename B >
template<typename H >
bool wamp::CoroSession< B >::unsubscribe ( const Subscription sub,
YieldContext< H >  yield,
std::error_code *  ec = nullptr 
)

Unsubscribes a subscription to a topic and waits for router acknowledgement if necessary.

If there are other local subscriptions on this session remaining for the same topic, then the session does not send an UNSUBSCRIBE message to the router.

See also
Subscription, ScopedSubscription
Returns
false if the subscription was already removed, true otherwise.
Note
Duplicate unsubscribes using the same Subscription handle are safely ignored.
Precondition
!!sub == true
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif the given subscription is empty
error::Logicif this->state() != SessionState::established
error::Failurewith an error code if a runtime error occured and the ec parameter is null.
Parameters
subThe subscription to unsubscribe from.
yieldRepresents the current coroutine.
ecOptional pointer to an error code to set, instead of throwing an exception upon failure.

◆ publish() [1/3]

template<typename B >
void wamp::CoroSession< B >::publish ( Pub  pub)

Publishes an event.

Precondition
this->state() == SessionState::established
Exceptions
error::Logicif this->state() != SessionState::established
Parameters
pubThe publication to publish.

◆ publish() [2/3]

template<typename B >
void wamp::CoroSession< B >::publish ( Pub  pub,
AsyncHandler< PublicationId handler 
)

Asynchronously publishes an event and waits for an acknowledgement from the router.

Returns
The publication ID for this event.
Precondition
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
Parameters
pubThe publication to publish.
handlerHandler to invoke when the operation completes.

◆ publish() [3/3]

template<typename B >
template<typename H >
PublicationId wamp::CoroSession< B >::publish ( Pub  pub,
YieldContext< H >  yield,
std::error_code *  ec = nullptr 
)

Publishes an event and waits for an acknowledgement from the router.

Returns
The publication ID for this event.
Precondition
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
error::Failurewith an error code if a runtime error occured and the ec parameter is null
Parameters
pubThe publication to publish
yieldRepresents the current coroutine.
ecOptional error code to set, instead of throwing an exception.

◆ enroll() [1/4]

template<typename B >
void wamp::CoroSession< B >::enroll ( Procedure  procedure,
CallSlot  slot,
AsyncHandler< Registration handler 
)

Asynchronously registers a WAMP remote procedure call.

See also
Registrations
Returns
A Registration object, therafter used to manage the registration's lifetime.
Note
This function was named enroll because register is a reserved C++ keyword.
Precondition
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
Parameters
procedureThe procedure to register.
slotThe handler to execute when the RPC is invoked.
handlerHandler to invoke when the enroll operation completes.

◆ enroll() [2/4]

template<typename B >
template<typename H >
Registration wamp::CoroSession< B >::enroll ( Procedure  procedure,
CallSlot  slot,
YieldContext< H >  yield,
std::error_code *  ec = nullptr 
)

Registers a WAMP remote procedure call.

See also
Registrations
Returns
A Registration object, therafter used to manage the registration's lifetime.
Note
This function was named enroll because register is a reserved C++ keyword.
Precondition
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
error::Failurewith an error code if a runtime error occured and the ec parameter is null.
Parameters
procedureThe procedure URI to register.
slotCallable target to invoke when a matching RPC invocation is received.
yieldRepresents the current coroutine.
ecOptional pointer to an error code to set, instead of throwing an exception upon failure.

◆ enroll() [3/4]

template<typename B >
void wamp::CoroSession< B >::enroll ( Procedure  procedure,
CallSlot  callSlot,
InterruptSlot  interruptSlot,
AsyncHandler< Registration handler 
)

Asynchronously registers a WAMP remote procedure call with an interruption handler.

See also
Registrations
Returns
A Registration object, therafter used to manage the registration's lifetime.
Note
This function was named enroll because register is a reserved C++ keyword.
Precondition
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
Parameters
procedureThe procedure to register.
callSlotThe handler to execute when the RPC is invoked.
interruptSlotHandler to execute when RPC is interrupted.
handlerHandler to invoke when the enroll operation completes.

◆ enroll() [4/4]

template<typename B >
template<typename H >
Registration wamp::CoroSession< B >::enroll ( Procedure  procedure,
CallSlot  callSlot,
InterruptSlot  interruptSlot,
YieldContext< H >  yield,
std::error_code *  ec = nullptr 
)

Registers a WAMP remote procedure call with an interruption handler.

See also
Registrations
Returns
A Registration object, therafter used to manage the registration's lifetime.
Note
This function was named enroll because register is a reserved C++ keyword.
Precondition
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
error::Failurewith an error code if a runtime error occured and the ec parameter is null.
Parameters
procedureThe procedure URI to register.
callSlotCallable target to invoke when a matching RPC invocation is received.
interruptSlotHandler to execute when RPC is interrupted.
yieldRepresents the current coroutine.
ecOptional pointer to an error code to set, instead of throwing an exception upon failure.

◆ unregister() [1/3]

template<typename B >
void wamp::CoroSession< B >::unregister ( const Registration reg)

Unregisters a remote procedure call.

This function can be safely called during any session state. If the registration is no longer applicable, then the unregister operation will effectively do nothing.

See also
Registration, ScopedRegistration
Note
Duplicate unregistrations using the same Registration handle are safely ignored.
Precondition
!!reg == true
Exceptions
error::Logicif the given registration is empty
Parameters
regThe RPC registration to unregister.

◆ unregister() [2/3]

template<typename B >
void wamp::CoroSession< B >::unregister ( const Registration reg,
AsyncHandler< bool >  handler 
)

Asynchronously unregisters a remote procedure call and waits for router acknowledgement.

See also
Registration, ScopedRegistration
Returns
false if the registration was already removed, true otherwise.
Note
Duplicate unregistrations using the same Registration handle are safely ignored.
Precondition
!!reg == true
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif the given registration is empty
error::Logicif this->state() != SessionState::established
Parameters
regThe RPC registration to unregister.
handlerHandler to invoke when the operation completes.

◆ unregister() [3/3]

template<typename B >
template<typename H >
bool wamp::CoroSession< B >::unregister ( const Registration reg,
YieldContext< H >  yield,
std::error_code *  ec = nullptr 
)

Unregisters a remote procedure call and waits for router acknowledgement.

See also
Registration, ScopedRegistration
Returns
false if the registration was already removed, true otherwise.
Note
Duplicate unregistrations using the same Registration handle are safely ignored.
Precondition
!!reg == true
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif the given registration is empty
error::Logicif this->state() != SessionState::established
error::Failurewith an error code if a runtime error occured and the ec parameter is null.
Parameters
regThe RPC registration to unregister.
yieldRepresents the current coroutine.
ecOptional pointer to an error code to set, instead of throwing an exception upon failure.

◆ call() [1/2]

template<typename B >
RequestId wamp::CoroSession< B >::call ( Rpc  rpc,
AsyncHandler< Result handler 
)

Asynchronously calls a remote procedure.

Returns
The Result yielded by the remote procedure
Precondition
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
Parameters
rpcDetails about the RPC.
handlerHandler to invoke when the operation completes.

◆ call() [2/2]

template<typename B >
template<typename H >
Result wamp::CoroSession< B >::call ( Rpc  rpc,
YieldContext< H >  yield,
std::error_code *  ec = nullptr 
)

Calls a remote procedure.

Returns
The Result yielded by the remote procedure
Precondition
this->state() == SessionState::established
Error Codes
Exceptions
error::Logicif this->state() != SessionState::established
error::Failurewith an error code if a runtime error occured and the ec parameter is null.
Parameters
rpcDetails on the RPC to call.
yieldRepresents the current coroutine.
ecOptional error code to set, instead of throwing an exception.

◆ suspend()

template<typename B >
template<typename H >
void wamp::CoroSession< B >::suspend ( YieldContext< H >  yield)

Cooperatively suspend this coroutine to allow others to run.

Has the same effect as

boost::asio::post(this->userIosvc(), yield);

◆ reset()

template<typename TIgnoredBase = Session>
void wamp::CoroSession< TIgnoredBase >::reset ( )
delete

The reset function is removed from the coroutine API.

It is removed because its behavior in Session is to abort all pending operations without invoking their associated asynchronous completion handlers. Implementing this same behavior in CoroSession could result in hung coroutines (because the pending CoroSession operations might never return).


The documentation for this class was generated from the following file:
wamp::Session::userIosvc
AnyIoExecutor userIosvc() const
Legacy function kept for backward compatiblity.
Definition: session.ipp:86