STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Concurrency::transformer< _Input, _Output > Class Template Reference

A transformer messaging block is a single-target, multi-source, ordered propagator_block which can accept messages of one type and is capable of storing an unbounded number of messages of a different type. More...

#include <agents.h>

Inheritance diagram for Concurrency::transformer< _Input, _Output >:
Concurrency::propagator_block< single_link_registry< ITarget< _Output > >, multi_link_registry< ISource< _Input > > > Concurrency::source_block< single_link_registry< ITarget< _Output > >, _MessageProcessorType > Concurrency::ITarget< multi_link_registry< ISource< _Input > >::type::source_type > Concurrency::ISource< single_link_registry< ITarget< _Output > >::type::type >

Public Member Functions

 transformer (_Transform_method const &_Func, _Inout_opt_ ITarget< _Output > *_PTarget=NULL)
 Constructs a transformer messaging block. More...
 
 transformer (_Transform_method const &_Func, _Inout_opt_ ITarget< _Output > *_PTarget, filter_method const &_Filter)
 Constructs a transformer messaging block. More...
 
 ~transformer ()
 Destroys the transformer messaging block. More...
 
- Public Member Functions inherited from Concurrency::propagator_block< single_link_registry< ITarget< _Output > >, multi_link_registry< ISource< _Input > > >
 propagator_block ()
 Constructs a propagator_block object. More...
 
virtual ~propagator_block ()
 Destroys a propagator_block object. More...
 
virtual message_status propagate (_Inout_opt_ message< _Source_type > *_PMessage, _Inout_opt_ ISource< _Source_type > *_PSource)
 Asynchronously passes a message from a source block to this target block. More...
 
virtual message_status send (_Inout_ message< _Source_type > *_PMessage, _Inout_ ISource< _Source_type > *_PSource)
 Synchronously initiates a message to this block. Called by an ISource block. When this function completes, the message will already have propagated into the block. More...
 
- Public Member Functions inherited from Concurrency::source_block< single_link_registry< ITarget< _Output > >, _MessageProcessorType >
 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< _Output > >::type::type >
virtual ~ISource ()
 Destroys the ISource object. More...
 
virtual void link_target (_Inout_ ITarget< single_link_registry< ITarget< _Output > >::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< _Output > >::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< _Output > >::type::type > * accept (runtime_object_identity _MsgId, _Inout_ ITarget< single_link_registry< ITarget< _Output > >::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< _Output > >::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< _Output > >::type::type > * consume (runtime_object_identity _MsgId, _Inout_ ITarget< single_link_registry< ITarget< _Output > >::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< _Output > >::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< _Output > >::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< _Output > >::type::type > *_PTarget)=0
 When overridden in a derived class, releases a reference count on this ISource block. More...
 
- Public Member Functions inherited from Concurrency::ITarget< multi_link_registry< ISource< _Input > >::type::source_type >
virtual ~ITarget ()
 Destroys the ITarget object. More...
 
virtual message_status propagate (_Inout_opt_ message< multi_link_registry< ISource< _Input > >::type::source_type > *_PMessage, _Inout_opt_ ISource< multi_link_registry< ISource< _Input > >::type::source_type > *_PSource)=0
 When overridden in a derived class, asynchronously passes a message from a source block to this target block. More...
 
virtual message_status send (_Inout_ message< multi_link_registry< ISource< _Input > >::type::source_type > *_PMessage, _Inout_ ISource< multi_link_registry< ISource< _Input > >::type::source_type > *_PSource)=0
 When overridden in a derived class, synchronously passes a message to the target block. More...
 

Protected Member Functions

virtual message_status propagate_message (_Inout_ message< _Input > *_PMessage, _Inout_ ISource< _Input > *_PSource)
 Asynchronously passes a message from an ISource block to this transformer messaging block. It is invoked by the propagate method, when called by a source block. More...
 
virtual message_status send_message (_Inout_ message< _Input > *_PMessage, _Inout_ ISource< _Input > *_PSource)
 Synchronously passes a message from an ISource block to this transformer messaging block. It is invoked by the send method, when called by a source block. More...
 
virtual bool supports_anonymous_source ()
 Overrides the supports_anonymous_source method to indicate that this block can accept messages offered to it by a source that is not linked. More...
 
virtual message< _Output > * accept_message (runtime_object_identity _MsgId)
 Accepts a message that was offered by this transformer messaging block, transferring ownership to the caller. More...
 
virtual bool reserve_message (runtime_object_identity _MsgId)
 Reserves a message previously offered by this transformer messaging block. More...
 
virtual message< _Output > * consume_message (runtime_object_identity _MsgId)
 Consumes a message previously offered by the transformer 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< _Output > *)
 A callback that notifies that a new target has been linked to this transformer messaging block. More...
 
virtual void propagate_to_any_targets (_Inout_opt_ message< _Output > *)
 Executes the transformer function on the input messages. More...
 
- Protected Member Functions inherited from Concurrency::propagator_block< single_link_registry< ITarget< _Output > >, multi_link_registry< ISource< _Input > > >
virtual message_status propagate_message (_Inout_ message< _Source_type > *_PMessage, _Inout_ ISource< _Source_type > *_PSource)=0
 When overridden in a derived class, this method asynchronously passes a message from an ISource block to this propagator_block object. It is invoked by the propagate method, when called by a source block. More...
 
virtual message_status send_message (_Inout_ message< _Source_type > *, _Inout_ ISource< _Source_type > *)
 When overridden in a derived class, this method synchronously passes a message from an ISource block to this propagator_block object. It is invoked by the send method, when called by a source block. More...
 
virtual void link_source (_Inout_ ISource< _Source_type > *_PSource)
 Links a specified source block to this propagator_block object. More...
 
virtual void unlink_source (_Inout_ ISource< _Source_type > *_PSource)
 Unlinks a specified source block from this propagator_block object. More...
 
virtual void unlink_sources ()
 Unlinks all source blocks from this propagator_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...
 
void initialize_source_and_target (_Inout_opt_ Scheduler *_PScheduler=NULL, _Inout_opt_ ScheduleGroup *_PScheduleGroup=NULL)
 Initializes the base object. Specifically, the message_processor object needs to be initialized. More...
 
void register_filter (filter_method const &_Filter)
 Registers a filter method that will be invoked on every received message. More...
 
void decline_incoming_messages ()
 Indicates to the block that new messages should be declined. More...
 
void remove_network_links ()
 Removes all the source and target network links from this propagator_block object. More...
 
- Protected Member Functions inherited from Concurrency::source_block< single_link_registry< ITarget< _Output > >, _MessageProcessorType >
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 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< _Output > >::type::type >
void _Invoke_link_source (ITarget< single_link_registry< ITarget< _Output > >::type::type > *_PLinkFrom)
 Links this source to a target. More...
 
void _Invoke_unlink_source (ITarget< single_link_registry< ITarget< _Output > >::type::type > *_PUnlinkFrom)
 Unlinks this source from a target. More...
 
- Protected Member Functions inherited from Concurrency::ITarget< multi_link_registry< ISource< _Input > >::type::source_type >
virtual void link_source (_Inout_ ISource< multi_link_registry< ISource< _Input > >::type::source_type > *_PSource)=0
 When overridden in a derived class, links a specified source block to this ITarget block. More...
 
virtual void unlink_source (_Inout_ ISource< multi_link_registry< ISource< _Input > >::type::source_type > *_PSource)=0
 When overridden in a derived class, unlinks a specified source block from this ITarget block. More...
 

Private Types

typedef std::tr1::function< _Output(_Input const &)> _Transform_method
 

Private Member Functions

void _Propagate_priority_order (::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
 Propagates messages in priority order. 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...
 
transformer const & operator= (transformer const &)
 
 transformer (transformer const &)
 

Private Attributes

_Transform_method _M_pFunc
 
concurrent_queue< message< _Input > * > _M_inputMessages
 
::Concurrency::details::_Queue< message< _Output > > _M_messageBuffer
 Message queue used to store outbound messages More...
 

Additional Inherited Members

- Public Types inherited from Concurrency::propagator_block< single_link_registry< ITarget< _Output > >, multi_link_registry< ISource< _Input > > >
typedef multi_link_registry< ISource< _Input > >::type::source_type _Source_type
 The type of the payload for the incoming message to this propagator_block. More...
 
typedef source_link_manager< multi_link_registry< ISource< _Input > > > _SourceLinkManager
 The type of the source_link_manager this propagator_block. More...
 
typedef _SourceLinkManager::iterator source_iterator
 The type of the iterator for the source_link_manager for this propagator_block. More...
 
- Public Types inherited from Concurrency::source_block< single_link_registry< ITarget< _Output > >, _MessageProcessorType >
typedef single_link_registry< ITarget< _Output > >::type::type _Target_type
 The payload type of messages handled by this source_block. More...
 
typedef single_link_registry< ITarget< _Output > >::iterator target_iterator
 The iterator to walk the connected targets. More...
 
- Public Types inherited from Concurrency::ISource< single_link_registry< ITarget< _Output > >::type::type >
typedef single_link_registry< ITarget< _Output > >::type::type source_type
 A type alias for _Type . More...
 
- Public Types inherited from Concurrency::ITarget< multi_link_registry< ISource< _Input > >::type::source_type >
typedef multi_link_registry< ISource< _Input > >::type::source_type type
 A type alias for _Type . More...
 
typedef std::tr1::function< bool(multi_link_registry< ISource< _Input > >::type::source_typeconst &)> filter_method
 The signature of any method used by the block that returns a bool value to determine whether an offered message should be accepted. More...
 
- Protected Attributes inherited from Concurrency::propagator_block< single_link_registry< ITarget< _Output > >, multi_link_registry< ISource< _Input > > >
_SourceLinkManager _M_connectedSources
 The container for all the sources connected to this block. More...
 
filter_method_M_pFilter
 The filter function which determines whether offered messages should be accepted. More...
 
volatile bool _M_fDeclineMessages
 A bool that is set to indicate that all messages should be declined in preparation for deleting the block More...
 
- Protected Attributes inherited from Concurrency::source_block< single_link_registry< ITarget< _Output > >, _MessageProcessorType >
ITarget< _Target_type > * _M_pReservedFor
 Connected target that is holding a reservation More...
 
runtime_object_identity _M_reservedId
 Reserved message ID More...
 
single_link_registry< ITarget< _Output > > _M_connectedTargets
 Connected targets More...
 
_MessageProcessorType _M_messageProcessor
 Processor used for asynchronous message handling More...
 

Detailed Description

template<class _Input, class _Output>
class Concurrency::transformer< _Input, _Output >

A transformer messaging block is a single-target, multi-source, ordered propagator_block which can accept messages of one type and is capable of storing an unbounded number of messages of a different type.

Template Parameters
_InputThe payload type of the messages accepted by the buffer.
_OutputThe payload type of the messages stored and propagated out by the buffer.

For more information, see Asynchronous Message Blocks.

See also
call Class

Member Typedef Documentation

template<class _Input , class _Output >
typedef std::tr1::function<_Output(_Input const&)> Concurrency::transformer< _Input, _Output >::_Transform_method
private

Constructor & Destructor Documentation

template<class _Input , class _Output >
Concurrency::transformer< _Input, _Output >::transformer ( _Transform_method const &  _Func,
_Inout_opt_ ITarget< _Output > *  _PTarget = NULL 
)
inline

Constructs a transformer messaging block.

Parameters
_FuncA function that will be invoked for each accepted message.
_PTargetA pointer to a target block to link with the transformer.

The runtime uses the default scheduler if you do not specify the _PScheduler or _PScheduleGroup parameters.

The type _Transform_method is a functor with signature _Output (_Input const &) which is invoked by this transformer messaging block to process a message.

The type filter_method is a functor with signature bool (_Input const &) which is invoked by this transformer messaging block to determine whether or not it should accept an offered message.

See also
Scheduler Class, ScheduleGroup Class
5833  :
5834  _M_pFunc(_Func)
5835  {
5837 
5838  if (_PTarget != NULL)
5839  {
5840  link_target(_PTarget);
5841  }
5842  }
#define NULL
Definition: crtdbg.h:30
virtual void link_target(_Inout_ ITarget< _Target_type > *_PTarget)
Links a target block to this source_block object.
Definition: agents.h:3281
void initialize_source_and_target(_Inout_opt_ Scheduler *_PScheduler=NULL, _Inout_opt_ ScheduleGroup *_PScheduleGroup=NULL)
Initializes the base object. Specifically, the message_processor object needs to be initialized...
Definition: agents.h:4173
_Transform_method _M_pFunc
Definition: agents.h:6394
template<class _Input , class _Output >
Concurrency::transformer< _Input, _Output >::transformer ( _Transform_method const &  _Func,
_Inout_opt_ ITarget< _Output > *  _PTarget,
filter_method const &  _Filter 
)
inline

Constructs a transformer messaging block.

Parameters
_FuncA function that will be invoked for each accepted message.
_PTargetA pointer to a target block to link with the transform.
_FilterA filter function which determines whether offered messages should be accepted.

The runtime uses the default scheduler if you do not specify the _PScheduler or _PScheduleGroup parameters.

The type _Transform_method is a functor with signature _Output (_Input const &) which is invoked by this transformer messaging block to process a message.

The type filter_method is a functor with signature bool (_Input const &) which is invoked by this transformer messaging block to determine whether or not it should accept an offered message.

See also
Scheduler Class, ScheduleGroup Class
5870  :
5871  _M_pFunc(_Func)
5872  {
5874  register_filter(_Filter);
5875 
5876  if (_PTarget != NULL)
5877  {
5878  link_target(_PTarget);
5879  }
5880  }
#define NULL
Definition: crtdbg.h:30
virtual void link_target(_Inout_ ITarget< _Target_type > *_PTarget)
Links a target block to this source_block object.
Definition: agents.h:3281
void initialize_source_and_target(_Inout_opt_ Scheduler *_PScheduler=NULL, _Inout_opt_ ScheduleGroup *_PScheduleGroup=NULL)
Initializes the base object. Specifically, the message_processor object needs to be initialized...
Definition: agents.h:4173
void register_filter(filter_method const &_Filter)
Registers a filter method that will be invoked on every received message.
Definition: agents.h:4188
_Transform_method _M_pFunc
Definition: agents.h:6394
template<class _Input , class _Output >
Concurrency::transformer< _Input, _Output >::~transformer ( )
inline

Destroys the transformer messaging block.

6049  {
6050  // Remove all links
6052 
6053  // Clean up any messages left in this message block
6055  }
void _Delete_stored_messages()
Deletes all messages currently stored in this message block. Should be called by the destructor to en...
Definition: agents.h:6364
void remove_network_links()
Removes all the source and target network links from this propagator_block object.
Definition: agents.h:4212
template<class _Input , class _Output >
Concurrency::transformer< _Input, _Output >::transformer ( transformer< _Input, _Output > const &  )
private

Member Function Documentation

template<class _Input , class _Output >
void Concurrency::transformer< _Input, _Output >::_Delete_stored_messages ( )
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.

6365  {
6366  // Delete input messages
6367  // Because the transformer uses its own input queue, it's possible there are messages
6368  // in this queue and no LWT will be executed to handle them.
6369  message<_Input> * _PInputQueueMessage = NULL;
6370 
6371  while (_M_inputMessages.try_pop(_PInputQueueMessage))
6372  {
6373  // Message cleanup
6374  delete _PInputQueueMessage;
6375  }
6376 
6377  // Delete any messages remaining in the output queue
6378  for (;;)
6379  {
6380  message<_Output> * _Msg = _M_messageBuffer._Dequeue();
6381  if (_Msg == NULL)
6382  {
6383  break;
6384  }
6385  delete _Msg;
6386  }
6387  }
::Concurrency::details::_Queue< message< _Output > > _M_messageBuffer
Message queue used to store outbound messages
Definition: agents.h:6403
#define NULL
Definition: crtdbg.h:30
concurrent_queue< message< _Input > * > _M_inputMessages
Definition: agents.h:6397
template<class _Input , class _Output >
void Concurrency::transformer< _Input, _Output >::_Propagate_priority_order ( ::Concurrency::details::_Queue< message< _Target_type >> &  _MessageBuffer)
inlineprivate

Propagates messages in priority order.

Parameters
_MessageBufferReference to a message queue with messages to be propagated
6312  {
6313  message<_Target_type> * _Msg = _MessageBuffer._Peek();
6314 
6315  // If someone has reserved the _Head message, don't propagate anymore
6316  if (_M_pReservedFor != NULL)
6317  {
6318  return;
6319  }
6320 
6321  while (_Msg != NULL)
6322  {
6323  message_status _Status = declined;
6324 
6325  // Always start from the first target that linked
6326  for (target_iterator _Iter = _M_connectedTargets.begin(); *_Iter != NULL; ++_Iter)
6327  {
6328  ITarget<_Target_type> * _PTarget = *_Iter;
6329  _Status = _PTarget->propagate(_Msg, this);
6330 
6331  // Ownership of message changed. Do not propagate this
6332  // message to any other target.
6333  if (_Status == accepted)
6334  {
6335  break;
6336  }
6337 
6338  // If the target just propagated to reserved this message, stop
6339  // propagating it to others
6340  if (_M_pReservedFor != NULL)
6341  {
6342  break;
6343  }
6344  }
6345 
6346  // If status is anything other than accepted, then the head message
6347  // was not propagated out. Thus, nothing after it in the queue can
6348  // be propagated out. Cease propagation.
6349  if (_Status != accepted)
6350  {
6351  break;
6352  }
6353 
6354  // Get the next message
6355  _Msg = _MessageBuffer._Peek();
6356  }
6357  }
_Message * _Peek()
Definition: agents.h:226
single_link_registry< ITarget< _Output > >::iterator target_iterator
The iterator to walk the connected targets.
Definition: agents.h:3242
single_link_registry< ITarget< _Output > > _M_connectedTargets
Connected targets
Definition: agents.h:3833
The target did not accept the message.
Definition: agents.h:1750
#define NULL
Definition: crtdbg.h:30
message_status
The valid responses for an offer of a message object to a block.
Definition: agents.h:1739
The target accepted the message.
Definition: agents.h:1745
ITarget< _Target_type > * _M_pReservedFor
Connected target that is holding a reservation
Definition: agents.h:3821
template<class _Input , class _Output >
virtual message<_Output>* Concurrency::transformer< _Input, _Output >::accept_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Accepts a message that was offered by this transformer messaging block, transferring ownership to the caller.

Parameters
_MsgIdThe runtime_object_identity of the offered message object.
Returns
A pointer to the message object that the caller now has ownership of.

Implements Concurrency::source_block< single_link_registry< ITarget< _Output > >, _MessageProcessorType >.

6164  {
6165  //
6166  // Peek at the head message in the message buffer. If the IDs match
6167  // dequeue and transfer ownership
6168  //
6169  message<_Output> * _Msg = NULL;
6170 
6171  if (_M_messageBuffer._Is_head(_MsgId))
6172  {
6173  _Msg = _M_messageBuffer._Dequeue();
6174  }
6175 
6176  return _Msg;
6177  }
::Concurrency::details::_Queue< message< _Output > > _M_messageBuffer
Message queue used to store outbound messages
Definition: agents.h:6403
#define NULL
Definition: crtdbg.h:30
template<class _Input , class _Output >
virtual message<_Output>* Concurrency::transformer< _Input, _Output >::consume_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Consumes a message previously offered by the transformer and reserved by the target, transferring ownership to the caller.

Parameters
_MsgIdThe runtime_object_identity of the message object being consumed.
Returns
A pointer to the 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< _Output > >, _MessageProcessorType >.

6214  {
6215  // By default, accept the message
6216  return accept_message(_MsgId);
6217  }
virtual message< _Output > * accept_message(runtime_object_identity _MsgId)
Accepts a message that was offered by this transformer messaging block, transferring ownership to the...
Definition: agents.h:6163
template<class _Input , class _Output >
virtual void Concurrency::transformer< _Input, _Output >::link_target_notification ( _Inout_ ITarget< _Output > *  )
inlineprotectedvirtual

A callback that notifies that a new target has been linked to this transformer messaging block.

Parameters
_PTargetA pointer to the newly linked target.
6257  {
6258  // If the message queue is blocked due to reservation
6259  // there is no need to do any message propagation
6260  if (_M_pReservedFor != NULL)
6261  {
6262  return;
6263  }
6264 
6266  }
::Concurrency::details::_Queue< message< _Output > > _M_messageBuffer
Message queue used to store outbound messages
Definition: agents.h:6403
#define NULL
Definition: crtdbg.h:30
ITarget< _Target_type > * _M_pReservedFor
Connected target that is holding a reservation
Definition: agents.h:3821
void _Propagate_priority_order(::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
Propagates messages in priority order.
Definition: agents.h:6311
template<class _Input , class _Output >
transformer const& Concurrency::transformer< _Input, _Output >::operator= ( transformer< _Input, _Output > const &  )
private
template<class _Input , class _Output >
virtual message_status Concurrency::transformer< _Input, _Output >::propagate_message ( _Inout_ message< _Input > *  _PMessage,
_Inout_ ISource< _Input > *  _PSource 
)
inlineprotectedvirtual

Asynchronously passes a message from an ISource block to this transformer messaging block. It is invoked by the propagate method, when called by a source block.

Parameters
_PMessageA pointer to the message object.
_PSourceA pointer to the source block offering the message.
Returns
A message_status indication of what the target decided to do with the message.
6077  {
6078  // It is important that calls to propagate do *not* take the same lock on the
6079  // internal structure that is used by Consume and the LWT. Doing so could
6080  // result in a deadlock with the Consume call.
6081 
6082  message_status _Result = accepted;
6083 
6084  //
6085  // Accept the message being propagated
6086  // Note: depending on the source block propagating the message
6087  // this may not necessarily be the same message (pMessage) first
6088  // passed into the function.
6089  //
6090  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
6091 
6092  if (_PMessage != NULL)
6093  {
6094  // Enqueue the input message
6095  _M_inputMessages.push(_PMessage);
6096  async_send(NULL);
6097  }
6098  else
6099  {
6100  _Result = missed;
6101  }
6102 
6103  return _Result;
6104  }
#define NULL
Definition: crtdbg.h:30
message_status
The valid responses for an offer of a message object to a block.
Definition: agents.h:1739
The target tried to accept the message, but it was no longer available.
Definition: agents.h:1760
The target accepted the message.
Definition: agents.h:1745
concurrent_queue< message< _Input > * > _M_inputMessages
Definition: agents.h:6397
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 ...
Definition: agents.h:3783
template<class _Input , class _Output >
virtual void Concurrency::transformer< _Input, _Output >::propagate_to_any_targets ( _Inout_opt_ message< _Output > *  )
inlineprotectedvirtual

Executes the transformer function on the input messages.

6273  {
6274  message<_Output> * _Msg = NULL;
6275 
6276  // Process input message.
6277  message<_Input> * _PInputMessage = NULL;
6278  _M_inputMessages.try_pop(_PInputMessage);
6279 
6280  if (_PInputMessage != NULL)
6281  {
6282  // Invoke the TransformMethod on the data
6283  // Let exceptions flow
6284  _Output _Out = _M_pFunc(_PInputMessage->payload);
6285 
6286  // Reuse the input message ID
6287  _Msg = new message<_Output>(_Out, _PInputMessage->msg_id());
6288  _M_messageBuffer._Enqueue(_Msg);
6289 
6290  // Message cleanup
6291  delete _PInputMessage;
6292 
6293  if (!_M_messageBuffer._Is_head(_Msg->msg_id()))
6294  {
6295  return;
6296  }
6297  }
6298 
6300  }
::Concurrency::details::_Queue< message< _Output > > _M_messageBuffer
Message queue used to store outbound messages
Definition: agents.h:6403
basic_ostream< _Elem, _Traits > & _Out(basic_ostream< _Elem, _Traits > &_Os, _Ty _Dx)
Definition: random:169
#define NULL
Definition: crtdbg.h:30
concurrent_queue< message< _Input > * > _M_inputMessages
Definition: agents.h:6397
_Transform_method _M_pFunc
Definition: agents.h:6394
void _Propagate_priority_order(::Concurrency::details::_Queue< message< _Target_type >> &_MessageBuffer)
Propagates messages in priority order.
Definition: agents.h:6311
template<class _Input , class _Output >
virtual void Concurrency::transformer< _Input, _Output >::release_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Releases a previous message reservation.

Parameters
_MsgIdThe runtime_object_identity of the message object being released.

Implements Concurrency::source_block< single_link_registry< ITarget< _Output > >, _MessageProcessorType >.

6227  {
6228  // The head message is the one reserved.
6229  if (!_M_messageBuffer._Is_head(_MsgId))
6230  {
6231  throw message_not_found();
6232  }
6233  }
::Concurrency::details::_Queue< message< _Output > > _M_messageBuffer
Message queue used to store outbound messages
Definition: agents.h:6403
template<class _Input , class _Output >
virtual bool Concurrency::transformer< _Input, _Output >::reserve_message ( runtime_object_identity  _MsgId)
inlineprotectedvirtual

Reserves a message previously offered by this transformer messaging block.

Parameters
_MsgIdThe runtime_object_identity of the message object being reserved.
Returns
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< _Output > >, _MessageProcessorType >.

6194  {
6195  // Allow reservation if this is the head message
6196  return _M_messageBuffer._Is_head(_MsgId);
6197  }
::Concurrency::details::_Queue< message< _Output > > _M_messageBuffer
Message queue used to store outbound messages
Definition: agents.h:6403
template<class _Input , class _Output >
virtual void Concurrency::transformer< _Input, _Output >::resume_propagation ( )
inlineprotectedvirtual

Resumes propagation after a reservation has been released.

Implements Concurrency::source_block< single_link_registry< ITarget< _Output > >, _MessageProcessorType >.

6240  {
6241  // If there are any messages in the buffer, propagate them out
6242  if (_M_messageBuffer._Count() > 0)
6243  {
6244  // async send a NULL value to initiate the repropagation
6245  async_send(NULL);
6246  }
6247  }
::Concurrency::details::_Queue< message< _Output > > _M_messageBuffer
Message queue used to store outbound messages
Definition: agents.h:6403
#define NULL
Definition: crtdbg.h:30
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 ...
Definition: agents.h:3783
template<class _Input , class _Output >
virtual message_status Concurrency::transformer< _Input, _Output >::send_message ( _Inout_ message< _Input > *  _PMessage,
_Inout_ ISource< _Input > *  _PSource 
)
inlineprotectedvirtual

Synchronously passes a message from an ISource block to this transformer messaging block. It is invoked by the send method, when called by a source block.

Parameters
_PMessageA pointer to the message object.
_PSourceA pointer to the source block offering the message.
Returns
A message_status indication of what the target decided to do with the message.
6122  {
6123  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
6124 
6125  if (_PMessage != NULL)
6126  {
6127  // Enqueue the input message
6128  _M_inputMessages.push(_PMessage);
6129  sync_send(NULL);
6130  }
6131  else
6132  {
6133  return missed;
6134  }
6135 
6136  return accepted;
6137  }
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...
Definition: agents.h:3769
#define NULL
Definition: crtdbg.h:30
The target tried to accept the message, but it was no longer available.
Definition: agents.h:1760
The target accepted the message.
Definition: agents.h:1745
concurrent_queue< message< _Input > * > _M_inputMessages
Definition: agents.h:6397
template<class _Input , class _Output >
virtual bool Concurrency::transformer< _Input, _Output >::supports_anonymous_source ( )
inlineprotectedvirtual

Overrides the supports_anonymous_source method to indicate that this block can accept messages offered to it by a source that is not linked.

Returns
true because the block does not postpone offered messages.

Reimplemented from Concurrency::ITarget< multi_link_registry< ISource< _Input > >::type::source_type >.

6148  {
6149  return true;
6150  }

Member Data Documentation

template<class _Input , class _Output >
concurrent_queue<message<_Input> *> Concurrency::transformer< _Input, _Output >::_M_inputMessages
private
template<class _Input , class _Output >
::Concurrency::details::_Queue<message<_Output> > Concurrency::transformer< _Input, _Output >::_M_messageBuffer
private

Message queue used to store outbound messages

template<class _Input , class _Output >
_Transform_method Concurrency::transformer< _Input, _Output >::_M_pFunc
private

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