VSM C++ SDK
Vehicle Specific Modules SDK
ugcs::vsm::Request_container Class Referenceabstract

Generic container for queued requests. More...

#include <request_container.h>

Inheritance diagram for ugcs::vsm::Request_container:
ugcs::vsm::Request_context< is_processor > ugcs::vsm::Android_serial_processor ugcs::vsm::Cucs_processor ugcs::vsm::File_processor ugcs::vsm::Request_temp_completion_context ugcs::vsm::Request_worker ugcs::vsm::Service_discovery_processor ugcs::vsm::Socket_processor ugcs::vsm::Timer_processor

Classes

class  Request
 Generic request for implementing inter-threads communications and asynchronous operations. More...
 
class  Request_waiter
 Represents request synchronization entity which is used for request queues protected access, submission notifications and waiting. More...
 

Public Types

enum  Type {
  Type::NONE = 0x0, Type::PROCESSOR = 0x1, Type::COMPLETION_CONTEXT = 0x2, Type::ANY = PROCESSOR | COMPLETION_CONTEXT,
  Type::TEMPORAL = 0x4, Type::TEMP_COMPLETION_CONTEXT = COMPLETION_CONTEXT | TEMPORAL
}
 Container type. More...
 
typedef std::shared_ptr< Request_containerPtr
 Pointer type.
 
typedef std::weak_ptr< Request_containerWeak_ptr
 Pointer type.
 

Public Member Functions

 Request_container (const std::string &name, Request_waiter::Ptr waiter=Request_waiter::Create())
 Create container with default associated waiter. More...
 
virtual Type Get_type () const
 Get this container type. More...
 
bool Check_type (Type mask)
 Check if the container type conforms the specified characteristic mask. More...
 
void Submit_request (Request::Ptr request)
 Submit request to this container for further processing or notification handlers invocation. More...
 
void Submit_request_locked (Request::Ptr request, Request_waiter::Locker locker)
 The same as Submit_request, but with previously acquired lock of the associated waiter. More...
 
int Process_requests (int requests_limit=0)
 Process all currently queued requests. More...
 
int Process_requests (std::unique_lock< std::mutex > &lock, int requests_limit=0)
 Process all currently queued requests. More...
 
void Set_waiter (Request_waiter::Ptr waiter)
 Set request waiter associated with this container. More...
 
Request_waiter::Ptr Get_waiter () const
 Get request waiter associated with this container. More...
 
const std::string & Get_name ()
 Get the name of the container. More...
 
void Enable ()
 Enable the container. More...
 
void Disable ()
 Disable the container. More...
 
bool Is_enabled () const
 Check if the container is currently enabled. More...
 

Static Public Member Functions

template<typename... Args>
static Ptr Create (Args &&...args)
 Create an instance. More...
 

Protected Member Functions

void Processing_loop ()
 Request processing loop implementation. More...
 
virtual void Process_request (Request::Ptr request)=0
 Process request. More...
 
virtual void On_enable ()
 Called when the container is enabled. More...
 
virtual void On_disable ()
 Called when the container is terminated. More...
 
void Set_disabled ()
 Disable the container and notify its waiter. More...
 
virtual void On_wait_and_process ()
 Called when default processing loop want to wait for work and process it. More...
 

Protected Attributes

Request_waiter::Ptr waiter
 Waiter associated with this container. More...
 
std::list< Request::Ptrrequest_queue
 Queue of pending requests, i.e. More...
 

Detailed Description

Generic container for queued requests.

It provides interface for submitting requests into the container and executing associated handlers for queued requests.

Member Enumeration Documentation

Container type.

Enumerator
NONE 

None type used in base class.

PROCESSOR 

Request processor.

COMPLETION_CONTEXT 

Request completion context.

ANY 

Container capable of handling both requests and completions.

TEMPORAL 

Temporal context used for a separate request synchronization.

TEMP_COMPLETION_CONTEXT 

Temporal completion context.

Constructor & Destructor Documentation

ugcs::vsm::Request_container::Request_container ( const std::string &  name,
Request_waiter::Ptr  waiter = Request_waiter::Create() 
)

Create container with default associated waiter.

Member Function Documentation

bool ugcs::vsm::Request_container::Check_type ( Type  mask)
inline

Check if the container type conforms the specified characteristic mask.

template<typename... Args>
static Ptr ugcs::vsm::Request_container::Create ( Args &&...  args)
inlinestatic

Create an instance.

void ugcs::vsm::Request_container::Disable ( )

Disable the container.

All requests which are submitted after this method is called will be aborted. It is up to container implementation to decide whether to process or abort requests which are already submitted or being processed. If a container has dedicated threads, it should terminate them (should be done synchronously in On_disable() method). Method must be called from the same thread as Enable method.

void ugcs::vsm::Request_container::Enable ( )

Enable the container.

The container is ready to accept requests after that. Derived class can start dedicated threads there.

Exceptions
Invalid_op_exceptionif the container is already enabled.
const std::string& ugcs::vsm::Request_container::Get_name ( )
inline

Get the name of the container.

virtual Type ugcs::vsm::Request_container::Get_type ( ) const
inlinevirtual
Request_waiter::Ptr ugcs::vsm::Request_container::Get_waiter ( ) const
inline

Get request waiter associated with this container.

bool ugcs::vsm::Request_container::Is_enabled ( ) const

Check if the container is currently enabled.

virtual void ugcs::vsm::Request_container::On_disable ( )
protectedvirtual

Called when the container is terminated.

Derived classes should override this method to perform container-specific disabling, i.e. abort all pending operations related to this context and synchronously terminate dedicated threads. Set_disabled() method should be called by a derived class from inside this method when appropriate.

Reimplemented in ugcs::vsm::Socket_processor.

virtual void ugcs::vsm::Request_container::On_enable ( )
protectedvirtual

Called when the container is enabled.

Derived classes should override this method to perform container-specific enabling, e.g. launch dedicated threads.

Reimplemented in ugcs::vsm::Socket_processor.

Examples:
async_workflow.cpp.
virtual void ugcs::vsm::Request_container::On_wait_and_process ( )
protectedvirtual

Called when default processing loop want to wait for work and process it.

Can be overridden by derived classes if they have non-trivial wait and process implementation.

Reimplemented in ugcs::vsm::Socket_processor.

virtual void ugcs::vsm::Request_container::Process_request ( Request::Ptr  request)
protectedpure virtual

Process request.

Parameters
requestRequest to process.
int ugcs::vsm::Request_container::Process_requests ( int  requests_limit = 0)

Process all currently queued requests.

Parameters
requests_limitLimit of requests to process at once. Zero means no limit.
Returns
Number of requests processed.
int ugcs::vsm::Request_container::Process_requests ( std::unique_lock< std::mutex > &  lock,
int  requests_limit = 0 
)

Process all currently queued requests.

This version does not lock the waiter but uses provided mutex instead assuming it is locked when called. Intended for use from Request_waiter::Wait_and_process.

Parameters
lockExternal lock to use for protecting queue access.
requests_limitLimit of requests to process at once. Zero means no limit.
Returns
Number of requests processed.
void ugcs::vsm::Request_container::Processing_loop ( )
protected

Request processing loop implementation.

It does not return while the container is enabled.

void ugcs::vsm::Request_container::Set_disabled ( )
protected

Disable the container and notify its waiter.

void ugcs::vsm::Request_container::Set_waiter ( Request_waiter::Ptr  waiter)

Set request waiter associated with this container.

Parameters
waiterWaiter object.
void ugcs::vsm::Request_container::Submit_request ( Request::Ptr  request)

Submit request to this container for further processing or notification handlers invocation.

Parameters
requestRequest to submit.
void ugcs::vsm::Request_container::Submit_request_locked ( Request::Ptr  request,
Request_waiter::Locker  locker 
)

The same as Submit_request, but with previously acquired lock of the associated waiter.

Lock should be with notify.

Member Data Documentation

std::list<Request::Ptr> ugcs::vsm::Request_container::request_queue
protected

Queue of pending requests, i.e.

waiting for completion notification processing.

Request_waiter::Ptr ugcs::vsm::Request_container::waiter
protected

Waiter associated with this container.

It is used to synchronize access to the request queue in derived classes.


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