STLdoc
STLdocumentation
|
A timer
messaging block is a single-target source_block
capable of sending a message to its target after a specified time period has elapsed or at specific intervals.
More...
#include <agents.h>
Public Member Functions | |
timer (unsigned int _Ms, _Type const &_Value, ITarget< _Type > *_PTarget=NULL, bool _Repeating=false) | |
Constructs a timer messaging block that will fire a given message after a specified interval. More... | |
~timer () | |
Destroys a timer messaging block. More... | |
void | start () |
Starts the timer messaging block. The specified number of milliseconds after this is called, the specified value will be propagated downstream as a message . More... | |
void | stop () |
Stops the timer messaging block. More... | |
void | pause () |
Stops the timer messaging block. If it is a repeating timer messaging block, it can be restarted with a subsequent start() call. For non-repeating timers, this has the same effect as a stop call. More... | |
Public Member Functions inherited from Concurrency::source_block< single_link_registry< ITarget< _Type > > > | |
source_block () | |
Constructs a source_block object. More... | |
virtual | ~source_block () |
Destroys the source_block object. More... | |
virtual void | link_target (_Inout_ ITarget< _Target_type > *_PTarget) |
Links a target block to this source_block object. More... | |
virtual void | unlink_target (_Inout_ ITarget< _Target_type > *_PTarget) |
Unlinks a target block from this source_block object. More... | |
virtual void | unlink_targets () |
Unlinks all target blocks from this source_block object. More... | |
virtual message< _Target_type > * | accept (runtime_object_identity _MsgId, _Inout_ ITarget< _Target_type > *_PTarget) |
Accepts a message that was offered by this source_block object, transferring ownership to the caller. More... | |
virtual bool | reserve (runtime_object_identity _MsgId, _Inout_ ITarget< _Target_type > *_PTarget) |
Reserves a message previously offered by this source_block object. More... | |
virtual message< _Target_type > * | consume (runtime_object_identity _MsgId, _Inout_ ITarget< _Target_type > *_PTarget) |
Consumes a message previously offered by this source_block object and successfully reserved by the target, transferring ownership to the caller. More... | |
virtual void | release (runtime_object_identity _MsgId, _Inout_ ITarget< _Target_type > *_PTarget) |
Releases a previous successful message reservation. More... | |
virtual void | acquire_ref (_Inout_ ITarget< _Target_type > *) |
Acquires a reference count on this source_block object, to prevent deletion. More... | |
virtual void | release_ref (_Inout_ ITarget< _Target_type > *_PTarget) |
Releases a reference count on this source_block object. More... | |
Public Member Functions inherited from Concurrency::ISource< single_link_registry< ITarget< _Type > >::type::type > | |
virtual | ~ISource () |
Destroys the ISource object. More... | |
virtual void | link_target (_Inout_ ITarget< single_link_registry< ITarget< _Type > >::type::type > *_PTarget)=0 |
When overridden in a derived class, links a target block to this ISource block. More... | |
virtual void | unlink_target (_Inout_ ITarget< single_link_registry< ITarget< _Type > >::type::type > *_PTarget)=0 |
When overridden in a derived class, unlinks a target block from this ISource block, if found to be previously linked. More... | |
virtual message< single_link_registry< ITarget< _Type > >::type::type > * | accept (runtime_object_identity _MsgId, _Inout_ ITarget< single_link_registry< ITarget< _Type > >::type::type > *_PTarget)=0 |
When overridden in a derived class, accepts a message that was offered by this ISource block, transferring ownership to the caller. More... | |
virtual bool | reserve (runtime_object_identity _MsgId, _Inout_ ITarget< single_link_registry< ITarget< _Type > >::type::type > *_PTarget)=0 |
When overridden in a derived class, reserves a message previously offered by this ISource block. More... | |
virtual message< single_link_registry< ITarget< _Type > >::type::type > * | consume (runtime_object_identity _MsgId, _Inout_ ITarget< single_link_registry< ITarget< _Type > >::type::type > *_PTarget)=0 |
When overridden in a derived class, consumes a message previously offered by this ISource block and successfully reserved by the target, transferring ownership to the caller. More... | |
virtual void | release (runtime_object_identity _MsgId, _Inout_ ITarget< single_link_registry< ITarget< _Type > >::type::type > *_PTarget)=0 |
When overridden in a derived class, releases a previous successful message reservation. More... | |
virtual void | acquire_ref (_Inout_ ITarget< single_link_registry< ITarget< _Type > >::type::type > *_PTarget)=0 |
When overridden in a derived class, acquires a reference count on this ISource block, to prevent deletion. More... | |
virtual void | release_ref (_Inout_ ITarget< single_link_registry< ITarget< _Type > >::type::type > *_PTarget)=0 |
When overridden in a derived class, releases a reference count on this ISource block. More... | |
Protected Member Functions | |
virtual message< _Type > * | accept_message (runtime_object_identity _MsgId) |
Accepts a message that was offered by this timer messaging block, transferring ownership to the caller. More... | |
virtual bool | reserve_message (runtime_object_identity _MsgId) |
Reserves a message previously offered by this timer messaging block. More... | |
virtual message< _Type > * | consume_message (runtime_object_identity _MsgId) |
Consumes a message previously offered by the timer and reserved by the target, transferring ownership to the caller. More... | |
virtual void | release_message (runtime_object_identity _MsgId) |
Releases a previous message reservation. More... | |
virtual void | resume_propagation () |
Resumes propagation after a reservation has been released. More... | |
virtual void | link_target_notification (_Inout_ ITarget< _Type > *_PTarget) |
A callback that notifies that a new target has been linked to this timer messaging block. More... | |
virtual void | propagate_to_any_targets (_Inout_opt_ message< _Type > *) |
Tries to offer the message produced by the timer block to all of the linked targets. More... | |
Protected Member Functions inherited from Concurrency::details::_Timer | |
_CRTIMP | _Timer (unsigned int _Ms, bool _FRepeating) |
virtual _CRTIMP | ~_Timer () |
_CRTIMP void | _Start () |
_CRTIMP void | _Stop () |
Protected Member Functions inherited from Concurrency::source_block< single_link_registry< ITarget< _Type > > > | |
virtual void | link_target_notification (_Inout_ ITarget< _Target_type > *) |
A callback that notifies that a new target has been linked to this source_block object. More... | |
virtual void | unlink_target_notification (_Inout_ ITarget< _Target_type > *_PTarget) |
A callback that notifies that a target has been unlinked from this source_block object. More... | |
virtual void | process_input_messages (_Inout_ message< _Target_type > *_PMessage) |
Process input messages. This is only useful for propagator blocks, which derive from source_block More... | |
virtual void | propagate_output_messages () |
Propagate messages to targets. More... | |
virtual void | propagate_to_any_targets (_Inout_opt_ message< _Target_type > *_PMessage) |
When overridden in a derived class, propagates the given message to any or all of the linked targets. This is the main propagation routine for message blocks. More... | |
void | initialize_source (_Inout_opt_ Scheduler *_PScheduler=NULL, _Inout_opt_ ScheduleGroup *_PScheduleGroup=NULL) |
Initializes the message_propagator within this source_block . More... | |
void | enable_batched_processing () |
Enables batched processing for this block. More... | |
virtual void | sync_send (_Inout_opt_ message< _Target_type > *_Msg) |
Synchronously queues up messages and starts a propagation task, if this has not been done already. More... | |
virtual void | async_send (_Inout_opt_ message< _Target_type > *_Msg) |
Asynchronously queues up messages and starts a propagation task, if this has not been done already More... | |
void | wait_for_outstanding_async_sends () |
Waits for all asynchronous propagations to complete. This propagator-specific spin wait is used in destructors of message blocks to make sure that all asynchronous propagations have time to finish before destroying the block. More... | |
void | remove_targets () |
Removes all target links for this source block. This should be called from the destructor. More... | |
Protected Member Functions inherited from Concurrency::ISource< single_link_registry< ITarget< _Type > >::type::type > | |
void | _Invoke_link_source (ITarget< single_link_registry< ITarget< _Type > >::type::type > *_PLinkFrom) |
Links this source to a target. More... | |
void | _Invoke_unlink_source (ITarget< single_link_registry< ITarget< _Type > >::type::type > *_PUnlinkFrom) |
Unlinks this source from a target. More... | |
Private Types | |
enum | State { Initialized, Started, Paused, Stopped } |
Tracks the state machine of the timer. More... | |
Private Member Functions | |
message< _Type > * | _NewMessage () const |
Allocates a new message. More... | |
virtual void | _Fire () |
Called when the timer fires. More... | |
void | _Initialize (const _Type &_Value, _Inout_ ITarget< _Type > *_PTarget, bool _Repeating, _Inout_opt_ Scheduler *_PScheduler=NULL, _Inout_opt_ ScheduleGroup *_PScheduleGroup=NULL) |
Common initialization. More... | |
void | _Delete_stored_messages () |
Deletes all messages currently stored in this message block. Should be called by the destructor to ensure any messages propagated in are cleaned up. More... | |
timer const & | operator= (timer const &) |
timer (timer const &) | |
Private Attributes | |
message< _Type > * | _M_pMessage |
State | _M_state |
_Type | _M_value |
bool | _M_fRepeating |
bool | _M_fReferencedScheduler |
Scheduler * | _M_pScheduler |
A timer
messaging block is a single-target source_block
capable of sending a message to its target after a specified time period has elapsed or at specific intervals.
_Type | The payload type of the output messages of this block. |
For more information, see Asynchronous Message Blocks.
|
private |
Tracks the state machine of the timer.
Enumerator | |
---|---|
Initialized |
The timer has been initialized, but not yet started. |
Started |
The timer has been started. |
Paused |
The timer has started and been paused. |
Stopped |
The timer has been stopped. |
|
inline |
Constructs a timer
messaging block that will fire a given message after a specified interval.
_Ms | The number of milliseconds that must elapse after the call to start for the specified message to be propagated downstream. |
_Value | The value which will be propagated downstream when the timer elapses. |
_PTarget | The target to which the timer will propagate its message. |
_Repeating | If true, indicates that the timer will fire periodically every _Ms milliseconds. |
The runtime uses the default scheduler if you do not specify the _Scheduler or _ScheduleGroup parameters.
|
inline |
Destroys a timer
messaging block.
|
private |
|
inlineprivate |
Deletes all messages currently stored in this message block. Should be called by the destructor to ensure any messages propagated in are cleaned up.
|
inlineprivatevirtual |
Called when the timer fires.
Implements Concurrency::details::_Timer.
|
inlineprivate |
Common initialization.
_Value | The value which will be propagated downstream when the timer elapses. |
_PTarget | The target to which the timer will propagate its message. |
_Repeating | If true, indicates that the timer will fire periodically every _Ms milliseconds. |
|
inlineprivate |
Allocates a new message.
|
inlineprotectedvirtual |
Accepts a message that was offered by this timer
messaging block, transferring ownership to the caller.
_MsgId | The runtime_object_identity of the offered message object. |
message
object that the caller now has ownership of. Implements Concurrency::source_block< single_link_registry< ITarget< _Type > > >.
|
inlineprotectedvirtual |
Consumes a message previously offered by the timer
and reserved by the target, transferring ownership to the caller.
_MsgId | The runtime_object_identity of the message object being consumed. |
message
object that the caller now has ownership of. Similar to accept
, but is always preceded by a call to reserve
.
Implements Concurrency::source_block< single_link_registry< ITarget< _Type > > >.
|
inlineprotectedvirtual |
A callback that notifies that a new target has been linked to this timer
messaging block.
_PTarget | A pointer to the newly linked target. |
|
private |
|
inline |
Stops the timer
messaging block. If it is a repeating timer
messaging block, it can be restarted with a subsequent start()
call. For non-repeating timers, this has the same effect as a stop
call.
|
inlineprotectedvirtual |
Tries to offer the message produced by the timer
block to all of the linked targets.
|
inlineprotectedvirtual |
Releases a previous message reservation.
_MsgId | The runtime_object_identity of the message object being released. |
Implements Concurrency::source_block< single_link_registry< ITarget< _Type > > >.
|
inlineprotectedvirtual |
Reserves a message previously offered by this timer
messaging block.
_MsgId | The runtime_object_identity of the message object being reserved. |
true
if the message was successfully reserved, false
otherwise. After reserve
is called, if it returns true
, either consume
or release
must be called to either take or release ownership of the message.
Implements Concurrency::source_block< single_link_registry< ITarget< _Type > > >.
|
inlineprotectedvirtual |
Resumes propagation after a reservation has been released.
Implements Concurrency::source_block< single_link_registry< ITarget< _Type > > >.
|
inline |
Starts the timer
messaging block. The specified number of milliseconds after this is called, the specified value will be propagated downstream as a message
.
|
inline |
Stops the timer
messaging block.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |