VSM C++ SDK
Vehicle Specific Modules SDK
ugcs::vsm::Operation_waiter Class Reference

Class for synchronizing with request execution. More...

#include <operation_waiter.h>

Public Types

typedef std::unique_ptr< Operation_waiterPtr
 Pointer type when used as argument in callbacks. More...
 
typedef Callback_proxy< void, PtrTimeout_handler
 Timeout handler prototype. More...
 

Public Member Functions

 Operation_waiter (Request::Ptr request=nullptr)
 Construct operation waiter. More...
 
template<class Request_type >
 Operation_waiter (std::shared_ptr< Request_type > request)
 Construct operation waiter from any type of request pointer. More...
 
 ~Operation_waiter ()
 Destructor which might wait for the request to be done. More...
 
 Operation_waiter (Operation_waiter &&)=default
 Default move constructor. More...
 
 Operation_waiter (const Operation_waiter &)=delete
 Copy constructor disabled. More...
 
Operation_waiteroperator= (Operation_waiter &&)
 Move assignment operator. More...
 
Operation_waiteroperator= (const Operation_waiter &)=delete
 Assignment operator is disabled. More...
 
 operator bool () const
 Test the waiter has request associated. More...
 
bool Wait (bool process_ctx=true, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero())
 Wait for request is fully processed, i.e. More...
 
void Timeout (std::chrono::milliseconds timeout, Timeout_handler timeout_handler=Timeout_handler(), bool cancel_operation=true, Request_completion_context::Ptr ctx=nullptr)
 Schedule timeout for the operation. More...
 
void Cancel ()
 Cancel the operation. More...
 
void Abort ()
 Abort the operation. More...
 
bool Is_done () const
 Check if request is fully processed, i.e. More...
 

Detailed Description

Class for synchronizing with request execution.

Instance of this class should be returned by value from asynchronous methods of request processors. Only one instance is allowed (copying is disabled).

Examples:
async_workflow.cpp.

Member Typedef Documentation

Pointer type when used as argument in callbacks.

Timeout handler prototype.

Constructor & Destructor Documentation

ugcs::vsm::Operation_waiter::Operation_waiter ( Request::Ptr  request = nullptr)
inline

Construct operation waiter.

Parameters
requestAssociated request. No request is associated if nullptr. In such case it is dummy waiter object which behaves like its associated request is already done.
template<class Request_type >
ugcs::vsm::Operation_waiter::Operation_waiter ( std::shared_ptr< Request_type >  request)
inline

Construct operation waiter from any type of request pointer.

ugcs::vsm::Operation_waiter::~Operation_waiter ( )

Destructor which might wait for the request to be done.

ugcs::vsm::Operation_waiter::Operation_waiter ( Operation_waiter &&  )
default

Default move constructor.

ugcs::vsm::Operation_waiter::Operation_waiter ( const Operation_waiter )
delete

Copy constructor disabled.

Having more than one copy of operation waiter is confusing and error prone.

Member Function Documentation

void ugcs::vsm::Operation_waiter::Abort ( )

Abort the operation.

Completion handler will not be executed, unless it has been already executed or execution already started.

void ugcs::vsm::Operation_waiter::Cancel ( )

Cancel the operation.

This action behavior is defined by specific operation and processor.

bool ugcs::vsm::Operation_waiter::Is_done ( ) const
inline

Check if request is fully processed, i.e.

all handlers were invoked and no more actions pending.

ugcs::vsm::Operation_waiter::operator bool ( ) const
inline

Test the waiter has request associated.

Operation_waiter& ugcs::vsm::Operation_waiter::operator= ( Operation_waiter &&  )

Move assignment operator.

If the waiter instance which is assigned to is not empty, it is properly destroyed.

Operation_waiter& ugcs::vsm::Operation_waiter::operator= ( const Operation_waiter )
delete

Assignment operator is disabled.

Having more than one copy of operation waiter is confusing and error prone.

void ugcs::vsm::Operation_waiter::Timeout ( std::chrono::milliseconds  timeout,
Timeout_handler  timeout_handler = Timeout_handler(),
bool  cancel_operation = true,
Request_completion_context::Ptr  ctx = nullptr 
)

Schedule timeout for the operation.

After the specified time the optional callback is invoked and the operation is optionally canceled.

Parameters
timeoutTimeout for the operation.
timeout_handlerHandler which should be invoked when timeout elapses. The handler should have constant reference to Operation_waiter::Ptr as the first argument.
cancel_operationCancel the operation after the timeout elapses if "true".
ctxContext used for handler invocation. By default the handler is invoked in request completion context, which should be present in this case.
bool ugcs::vsm::Operation_waiter::Wait ( bool  process_ctx = true,
std::chrono::milliseconds  timeout = std::chrono::milliseconds::zero() 
)

Wait for request is fully processed, i.e.

all handlers were invoked and no more actions pending.

Parameters
process_ctxProcess all requests in the associated completion context. This may be useful if the context is normally processed in the calling thread.
timeoutTimeout value for waiting. Zero value indicates indefinite waiting.
Returns
"true" if request was processed, "false" if the function returned by timeout expiration.

The documentation for this class was generated from the following file: