Base class for work items that are passed through the workitem queue. More...
#include <connect_work_item.hpp>
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< TimerInfo > | m_timerInfo |
Optional object that defines the scheduling information. More... | |
int32_t | m_type |
Type identifier. More... | |
Base class for work items that are passed through the workitem queue.
typedef function<void(void)> kanzi::connect::ConnectWorkItem::Executor |
Callback function that is dispatched to work queue and is used to execute work.
Priority levels for the work items.
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. |
kanzi::connect::ConnectWorkItem::ConnectWorkItem | ( | int32_t | type = Base , |
int32_t | priority = NormalPriority , |
||
ExecutionContext | executionContext = ExecutionContext::RUN_IN_MAIN_THREAD |
||
) |
Constructor.
type | Type of the work item. |
priority | Priority of the work item. |
executionContext | In which thread to execute the work item |
|
virtual |
virtual destructor for cleanup.
|
static |
Creates a default instance of the work item.
executionContext | Defines if the work item is to be run in main or worker thread |
bool kanzi::connect::ConnectWorkItem::deadlineIsEarlierThan | ( | const ConnectWorkItem & | workItem | ) | const |
Checks whether this object(s) deadline is earlier than with the "other" item.
workItem | the other time |
ConnectWorkItem::Executor kanzi::connect::ConnectWorkItem::getExecutor | ( | ) | const |
Retrieve the executor function.
int32_t kanzi::connect::ConnectWorkItem::getPriority | ( | ) | const |
retrieve the work item priority
AbstractServiceSharedPtr kanzi::connect::ConnectWorkItem::getTargetService | ( | ) |
retrieve the service this work item is traveling to.
int32_t kanzi::connect::ConnectWorkItem::getType | ( | ) | const |
retrieve the work item type identifier
int64_t kanzi::connect::ConnectWorkItem::handle | ( | ) | const |
Returns the handle associated with the object.
Handle is available only with timed objects.
bool kanzi::connect::ConnectWorkItem::hasExecutor | ( | ) | const |
Does the object have custom executor.
bool kanzi::connect::ConnectWorkItem::hasTimeout | ( | ) | const |
determines whether object defines a timeout
bool kanzi::connect::ConnectWorkItem::invokeWithExecutor | ( | ) |
Dispatches the object with executor.
This function is single shot type and will clear the executor instance once complete.
bool kanzi::connect::ConnectWorkItem::runInWorkerThread | ( | ) | const |
Should this work item be run in worker thread or main thread.
void kanzi::connect::ConnectWorkItem::setExecutor | ( | ConnectWorkItem::Executor | executorFunction | ) |
Setups an executor function to execute the work item.
Function can be created with std::bind.
executorFunction | function to be called when it is time to handle the functionality. |
void kanzi::connect::ConnectWorkItem::setTargetService | ( | AbstractServiceSharedPtr | service | ) |
setups the target service
service |
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.
timeout | timeout in milliseconds to delay the delivery. |
handle | unique handle that can be used to refer to object later on. |
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.
now | current timestamp if any. |
chrono::milliseconds kanzi::connect::ConnectWorkItem::timeoutUntilDeadline | ( | ) | const |
returns the timeout in milliseconds until this object time(s) out.
|
protected |
Defines whether work item should be executed in main thread or one of the workers.
|
protected |
Optional executor function that get(s) invoked to handle the item instead of passing it to the services handler function.
|
protected |
Priority value.
|
protected |
defines the service this work item is traveling to.
|
protected |
Optional object that defines the scheduling information.
|
protected |
Type identifier.