ConnectWorkItem¶
-
class
kanzi::connect::ConnectWorkItem¶ Base class for work items that are passed through the workitem queue.
Subclassed by ConnectionManagerWorkItem, VirtualFileWorkItem
Public Types
-
enum
ExecutionContext¶ How to execute the work item.
Values:
-
enumerator
RUN_IN_MAIN_THREAD¶
-
enumerator
RUN_IN_WORKER_THREAD¶
-
enumerator
-
typedef function<void(void)>
Executor¶ Callback function that is dispatched to work queue and is used to execute work.
-
enum
Priority¶ Priority levels for the work items.
Values:
-
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.
-
enumerator
NormalPriority¶ Normal/Default priority for work items.
-
enumerator
HighPriority¶ Highest priority for common work items. Gets processed first.
-
enumerator
SystemPriority¶ Highest priority for work items.
Gets processed first regardless of fairness.
-
enumerator
Public Functions
-
ConnectWorkItem(int32_t type = Base, int32_t priority = NormalPriority, ExecutionContext executionContext = ExecutionContext::RUN_IN_MAIN_THREAD)¶ Constructor.
- Parameters
type: Type of the work item.priority: Priority of the work item.executionContext: In which thread to execute the work item
-
~ConnectWorkItem()¶ virtual destructor for cleanup.
-
bool
deadlineIsEarlierThan(const ConnectWorkItem &workItem) const¶ Checks whether this object(s) deadline is earlier than with the “other” item.
- Return
true if this object triggers earlier than the other item.
- Parameters
workItem: the other time
-
ConnectWorkItem::Executor
getExecutor() const¶ Retrieve the executor function.
- Return
executor to handle the call.
-
int32_t
getPriority() const¶ retrieve the work item priority
- Return
numeric priority value.
-
AbstractServiceSharedPtr
getTargetService()¶ retrieve the service this work item is traveling to.
- Return
service pointer.
-
int32_t
getType() const¶ retrieve the work item type identifier
- Return
numeric identifier
-
int64_t
handle() const¶ Returns the handle associated with the object.
Handle is available only with timed objects.
- Return
handle. 0 if not defined.
-
bool
hasExecutor() const¶ Does the object have custom executor.
- Return
true if executor exists.
-
bool
hasTimeout() const¶ determines whether object defines a timeout
- Return
true if timeout is defined.
-
bool
invokeWithExecutor()¶ Dispatches the object with executor.
This function is single shot type and will clear the executor instance once complete.
- Return
true if executor was defined and got invoked.
-
bool
runInWorkerThread() const¶ Should this work item be run in worker thread or main thread.
- Return
True if worker thread
-
void
setExecutor(ConnectWorkItem::Executor executorFunction)¶ Setups an executor function to execute the work item.
Function can be created with std::bind.
- Parameters
executorFunction: function to be called when it is time to handle the functionality.
setups the target service
- Parameters
service:
-
void
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
timeout: timeout in milliseconds to delay the delivery.handle: unique handle that can be used to refer to object later on.
-
chrono::milliseconds
timeoutUntilDeadline(chrono::time_point<chrono::steady_clock> &now) const¶ returns the timeout in milliseconds until this object time(s) out.
- Return
timeout in milliseconds.
- Parameters
now: current timestamp if any.
-
chrono::milliseconds
timeoutUntilDeadline() const¶ returns the timeout in milliseconds until this object time(s) out.
- Return
the timeout in milliseconds.
Public Static Functions
-
ConnectWorkItemSharedPtr
create(ExecutionContext executionContext = ExecutionContext::RUN_IN_MAIN_THREAD)¶ Creates a default instance of the work item.
- Return
newly allocated instance.
- Parameters
executionContext: Defines if the work item is to be run in main or worker thread
-
enum