Kanzi Connect  1.1.10
Kanzi Connect C++ API
kanzi::connect::ConnectWorkItem Class Reference

Base class for work items that are passed through the workitem queue. More...

#include <connect_work_item.hpp>

Inheritance diagram for kanzi::connect::ConnectWorkItem:
kanzi::connect::ConnectionManagerWorkItem kanzi::connect::VirtualFileWorkItem

Classes

class  TimerInfo
 

Public Types

enum  ExecutionContext { ExecutionContext::RUN_IN_MAIN_THREAD, ExecutionContext::RUN_IN_WORKER_THREAD }
 How to execute the work item. More...
 
typedef function< void(void)> Executor
 Callback function that is dispatched to work queue and is used to execute work. More...
 
enum  Priority { LowPriority = 1, NormalPriority = 10, HighPriority = 20, SystemPriority = 30 }
 Priority levels for the work items. More...
 
enum  Type { Base, User = 1000 }
 Types for the work items. More...
 

Public Member Functions

 ConnectWorkItem (int32_t type=Base, int32_t priority=NormalPriority, ExecutionContext executionContext=ExecutionContext::RUN_IN_MAIN_THREAD)
 Constructor. More...
 
bool deadlineIsEarlierThan (const ConnectWorkItem &workItem) const
 Checks whether this object(s) deadline is earlier than with the "other" item. More...
 
ConnectWorkItem::Executor getExecutor () const
 Retrieve the executor function. More...
 
int32_t getPriority () const
 retrieve the work item priority More...
 
AbstractServiceSharedPtr getTargetService ()
 retrieve the service this work item is traveling to. More...
 
int32_t getType () const
 retrieve the work item type identifier More...
 
int64_t handle () const
 Returns the handle associated with the object. More...
 
bool hasExecutor () const
 Does the object have custom executor. More...
 
bool hasTimeout () const
 determines whether object defines a timeout More...
 
bool invokeWithExecutor ()
 Dispatches the object with executor. More...
 
bool runInWorkerThread () const
 Should this work item be run in worker thread or main thread. More...
 
void setExecutor (ConnectWorkItem::Executor executorFunction)
 Setups an executor function to execute the work item. More...
 
void setTargetService (AbstractServiceSharedPtr service)
 setups the target service More...
 
void setTimeout (chrono::milliseconds timeout, int64_t handle)
 Sets the timeout for the work item. More...
 
chrono::milliseconds timeoutUntilDeadline (chrono::time_point< chrono::steady_clock > &now) const
 returns the timeout in milliseconds until this object time(s) out. More...
 
chrono::milliseconds timeoutUntilDeadline () const
 returns the timeout in milliseconds until this object time(s) out. More...
 
virtual ~ConnectWorkItem ()
 virtual destructor for cleanup. More...
 

Static Public Member Functions

static ConnectWorkItemSharedPtr create (ExecutionContext executionContext=ExecutionContext::RUN_IN_MAIN_THREAD)
 Creates a default instance of the work item. More...
 

Protected Attributes

ExecutionContext m_executionContext
 Defines whether work item should be executed in main thread or one of the workers. More...
 
Executor m_executor
 Optional executor function that get(s) invoked to handle the item instead of passing it to the services handler function. More...
 
int32_t m_priority
 Priority value. More...
 
AbstractServiceWeakPtr m_service
 defines the service this work item is traveling to. More...
 
optional< TimerInfom_timerInfo
 Optional object that defines the scheduling information. More...
 
int32_t m_type
 Type identifier. More...
 

Detailed Description

Base class for work items that are passed through the workitem queue.

Member Typedef Documentation

◆ Executor

typedef function<void(void)> kanzi::connect::ConnectWorkItem::Executor

Callback function that is dispatched to work queue and is used to execute work.

Member Enumeration Documentation

◆ ExecutionContext

How to execute the work item.

Enumerator
RUN_IN_MAIN_THREAD 
RUN_IN_WORKER_THREAD 

◆ Priority

Priority levels for the work items.

Enumerator
LowPriority 

The lowest three are subject to fairness, that is, in certain situations lower priority items are processed even if Lowest priority for work items - gets processed last.

NormalPriority 

Normal/Default priority for work items.

HighPriority 

Highest priority for common work items. Gets processed first.

SystemPriority 

Highest priority for work items.

Gets processed first regardless of fairness.

◆ Type

Types for the work items.

Enumerator
Base 

Base work item to be used for instances for ConnectWorkItem.

User 

For user inherited work item classes, use identifier >= ID_USER.

Constructor & Destructor Documentation

◆ ConnectWorkItem()

kanzi::connect::ConnectWorkItem::ConnectWorkItem ( int32_t  type = Base,
int32_t  priority = NormalPriority,
ExecutionContext  executionContext = ExecutionContext::RUN_IN_MAIN_THREAD 
)

Constructor.

Parameters
typeType of the work item.
priorityPriority of the work item.
executionContextIn which thread to execute the work item

◆ ~ConnectWorkItem()

virtual kanzi::connect::ConnectWorkItem::~ConnectWorkItem ( )
virtual

virtual destructor for cleanup.

Member Function Documentation

◆ create()

static ConnectWorkItemSharedPtr kanzi::connect::ConnectWorkItem::create ( ExecutionContext  executionContext = ExecutionContext::RUN_IN_MAIN_THREAD)
static

Creates a default instance of the work item.

Parameters
executionContextDefines if the work item is to be run in main or worker thread
Returns
newly allocated instance.

◆ deadlineIsEarlierThan()

bool kanzi::connect::ConnectWorkItem::deadlineIsEarlierThan ( const ConnectWorkItem workItem) const

Checks whether this object(s) deadline is earlier than with the "other" item.

Parameters
workItemthe other time
Returns
true if this object triggers earlier than the other item.

◆ getExecutor()

ConnectWorkItem::Executor kanzi::connect::ConnectWorkItem::getExecutor ( ) const

Retrieve the executor function.

Returns
executor to handle the call.

◆ getPriority()

int32_t kanzi::connect::ConnectWorkItem::getPriority ( ) const

retrieve the work item priority

Returns
numeric priority value.

◆ getTargetService()

AbstractServiceSharedPtr kanzi::connect::ConnectWorkItem::getTargetService ( )

retrieve the service this work item is traveling to.

Returns
service pointer.

◆ getType()

int32_t kanzi::connect::ConnectWorkItem::getType ( ) const

retrieve the work item type identifier

Returns
numeric identifier

◆ handle()

int64_t kanzi::connect::ConnectWorkItem::handle ( ) const

Returns the handle associated with the object.

Handle is available only with timed objects.

Returns
handle. 0 if not defined.

◆ hasExecutor()

bool kanzi::connect::ConnectWorkItem::hasExecutor ( ) const

Does the object have custom executor.

Returns
true if executor exists.

◆ hasTimeout()

bool kanzi::connect::ConnectWorkItem::hasTimeout ( ) const

determines whether object defines a timeout

Returns
true if timeout is defined.

◆ invokeWithExecutor()

bool kanzi::connect::ConnectWorkItem::invokeWithExecutor ( )

Dispatches the object with executor.

This function is single shot type and will clear the executor instance once complete.

Returns
true if executor was defined and got invoked.

◆ runInWorkerThread()

bool kanzi::connect::ConnectWorkItem::runInWorkerThread ( ) const

Should this work item be run in worker thread or main thread.

Returns
True if worker thread

◆ setExecutor()

void kanzi::connect::ConnectWorkItem::setExecutor ( ConnectWorkItem::Executor  executorFunction)

Setups an executor function to execute the work item.

Function can be created with std::bind.

Parameters
executorFunctionfunction to be called when it is time to handle the functionality.

◆ setTargetService()

void kanzi::connect::ConnectWorkItem::setTargetService ( AbstractServiceSharedPtr  service)

setups the target service

Parameters
service

◆ setTimeout()

void kanzi::connect::ConnectWorkItem::setTimeout ( chrono::milliseconds  timeout,
int64_t  handle 
)

Sets the timeout for the work item.

Timeout means this object will delay first specified amount of milliseconds and will then be delivered.

Parameters
timeouttimeout in milliseconds to delay the delivery.
handleunique handle that can be used to refer to object later on.

◆ timeoutUntilDeadline() [1/2]

chrono::milliseconds kanzi::connect::ConnectWorkItem::timeoutUntilDeadline ( chrono::time_point< chrono::steady_clock > &  now) const

returns the timeout in milliseconds until this object time(s) out.

Parameters
nowcurrent timestamp if any.
Returns
timeout in milliseconds.

◆ timeoutUntilDeadline() [2/2]

chrono::milliseconds kanzi::connect::ConnectWorkItem::timeoutUntilDeadline ( ) const

returns the timeout in milliseconds until this object time(s) out.

Returns
the timeout in milliseconds.

Member Data Documentation

◆ m_executionContext

ExecutionContext kanzi::connect::ConnectWorkItem::m_executionContext
protected

Defines whether work item should be executed in main thread or one of the workers.

◆ m_executor

Executor kanzi::connect::ConnectWorkItem::m_executor
protected

Optional executor function that get(s) invoked to handle the item instead of passing it to the services handler function.

◆ m_priority

int32_t kanzi::connect::ConnectWorkItem::m_priority
protected

Priority value.

◆ m_service

AbstractServiceWeakPtr kanzi::connect::ConnectWorkItem::m_service
protected

defines the service this work item is traveling to.

◆ m_timerInfo

optional<TimerInfo> kanzi::connect::ConnectWorkItem::m_timerInfo
protected

Optional object that defines the scheduling information.

◆ m_type

int32_t kanzi::connect::ConnectWorkItem::m_type
protected

Type identifier.


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