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::call< _Type, _FunctorType > Class Template Reference

A call messaging block is a multi-source, ordered target_block that invokes a specified function when receiving a message. More...

#include <agents.h>

Inheritance diagram for Concurrency::call< _Type, _FunctorType >:
Concurrency::target_block< multi_link_registry< ISource< _Type > > > Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type >

Public Member Functions

 call (_Call_method const &_Func)
 Constructs a call messaging block. More...
 
 call (_Call_method const &_Func, filter_method const &_Filter)
 Constructs a call messaging block. More...
 
 ~call ()
 Destroys the call messaging block. More...
 
- Public Member Functions inherited from Concurrency::target_block< multi_link_registry< ISource< _Type > > >
 target_block ()
 Constructs a target_block object. More...
 
virtual ~target_block ()
 Destroys the target_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 passes a message from a source block to this target block. More...
 
- Public Member Functions inherited from Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type >
virtual ~ITarget ()
 Destroys the ITarget object. More...
 
virtual message_status propagate (_Inout_opt_ message< multi_link_registry< ISource< _Type > >::type::source_type > *_PMessage, _Inout_opt_ ISource< multi_link_registry< ISource< _Type > >::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< _Type > >::type::source_type > *_PMessage, _Inout_ ISource< multi_link_registry< ISource< _Type > >::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< _Type > *_PMessage, _Inout_ ISource< _Type > *_PSource)
 Asynchronously passes a message from an ISource block to this call messaging block. It is invoked by the propagate method, when called by a source block. More...
 
virtual message_status send_message (_Inout_ message< _Type > *_PMessage, _Inout_ ISource< _Type > *_PSource)
 Synchronously passes a message from an ISource block to this call 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 void process_message (_Inout_ message< _Type > *_PMessage)
 Processes a message that was accepted by this call messaging block. More...
 
virtual void process_input_messages (_Inout_ message< _Type > *_PMessage)
 Executes the call function on the input messages. More...
 
- Protected Member Functions inherited from Concurrency::target_block< multi_link_registry< ISource< _Type > > >
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 target_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 target_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 target_block object. More...
 
virtual void unlink_source (_Inout_ ISource< _Source_type > *_PSource)
 Unlinks a specified source block from this target_block object. More...
 
virtual void unlink_sources ()
 Unlinks all source blocks from this target_block object. More...
 
virtual void process_message (message< _Source_type > *)
 When overridden in a derived class, processes a message that was accepted by this target_block object. More...
 
void register_filter (filter_method const &_Filter)
 Registers a filter method that will be invoked on every message received. More...
 
void decline_incoming_messages ()
 Indicates to the block that new messages should be declined. More...
 
void initialize_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 enable_batched_processing ()
 Enables batched processing for this block. More...
 
void async_send (_Inout_opt_ message< _Source_type > *_PMessage)
 Asynchronously sends a message for processing. More...
 
void sync_send (_Inout_opt_ message< _Source_type > *_PMessage)
 Synchronously send a message for processing. More...
 
void wait_for_async_sends ()
 Waits for all asynchronous propagations to complete. More...
 
void remove_sources ()
 Unlinks all sources after waiting for outstanding asynchronous send operations to complete. More...
 
virtual void process_input_messages (_Inout_ message< _Source_type > *_PMessage)
 Processes messages that are received as inputs. More...
 
- Protected Member Functions inherited from Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type >
virtual void link_source (_Inout_ ISource< multi_link_registry< ISource< _Type > >::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< _Type > >::type::source_type > *_PSource)=0
 When overridden in a derived class, unlinks a specified source block from this ITarget block. More...
 

Private Types

typedef _FunctorType _Call_method
 The function type that this block executes upon receiving a message. More...
 

Private Member Functions

call const & operator= (call const &)
 
 call (call const &)
 

Private Attributes

_Call_method _M_pFunc
 

Additional Inherited Members

- Public Types inherited from Concurrency::target_block< multi_link_registry< ISource< _Type > > >
typedef multi_link_registry< ISource< _Type > >::type::source_type _Source_type
 The type of the payload for the incoming messages to this target_block object. More...
 
typedef source_link_manager< multi_link_registry< ISource< _Type > > > _SourceLinkManager
 The type of the source_link_manager this target_block object. More...
 
typedef _SourceLinkManager::iterator source_iterator
 The type of the iterator for the source_link_manager for this target_block object. More...
 
- Public Types inherited from Concurrency::ITarget< multi_link_registry< ISource< _Type > >::type::source_type >
typedef multi_link_registry< ISource< _Type > >::type::source_type type
 A type alias for _Type . More...
 
typedef std::tr1::function< bool(multi_link_registry< ISource< _Type > >::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::target_block< multi_link_registry< ISource< _Type > > >
_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...
 
bool _M_fDeclineMessages
 A bool that is set to indicate that all messages should be declined in preparation for deleting the block More...
 
_MessageProcessorType _M_messageProcessor
 The message_processor for this target_block. More...
 

Detailed Description

template<class _Type, class _FunctorType = std::tr1::function<void(_Type const&)>>
class Concurrency::call< _Type, _FunctorType >

A call messaging block is a multi-source, ordered target_block that invokes a specified function when receiving a message.

Template Parameters
_TypeThe payload type of the messages propagated to this block.
_FunctorTypeThe signature of functions that this block can accept.

For more information, see Asynchronous Message Blocks.

See also
transformer Class

Member Typedef Documentation

template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
typedef _FunctorType Concurrency::call< _Type, _FunctorType >::_Call_method
private

The function type that this block executes upon receiving a message.

Constructor & Destructor Documentation

template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
Concurrency::call< _Type, _FunctorType >::call ( _Call_method const &  _Func)
inline

Constructs a call messaging block.

Parameters
_FuncA function that will be invoked for each accepted message.

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

The type _Call_method is a functor with signature void (_Type const &) which is invoked by this call messaging block to process a message.

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

See also
Scheduler Class, ScheduleGroup Class
5470  :
5471  _M_pFunc(_Func)
5472  {
5475  }
void enable_batched_processing()
Enables batched processing for this block.
Definition: agents.h:3106
_Call_method _M_pFunc
Definition: agents.h:5775
void initialize_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:3087
template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
Concurrency::call< _Type, _FunctorType >::call ( _Call_method const &  _Func,
filter_method const &  _Filter 
)
inline

Constructs a call messaging block.

Parameters
_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 _Call_method is a functor with signature void (_Type const &) which is invoked by this call messaging block to process a message.

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

See also
Scheduler Class, ScheduleGroup Class
5496  :
5497  _M_pFunc(_Func)
5498  {
5501  register_filter(_Filter);
5502  }
void enable_batched_processing()
Enables batched processing for this block.
Definition: agents.h:3106
_Call_method _M_pFunc
Definition: agents.h:5775
void initialize_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:3087
void register_filter(filter_method const &_Filter)
Registers a filter method that will be invoked on every message received.
Definition: agents.h:3054
template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
Concurrency::call< _Type, _FunctorType >::~call ( )
inline

Destroys the call messaging block.

5639  {
5640  remove_sources();
5641  }
void remove_sources()
Unlinks all sources after waiting for outstanding asynchronous send operations to complete...
Definition: agents.h:3164
template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
Concurrency::call< _Type, _FunctorType >::call ( call< _Type, _FunctorType > const &  )
private

Member Function Documentation

template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
call const& Concurrency::call< _Type, _FunctorType >::operator= ( call< _Type, _FunctorType > const &  )
private
template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
virtual void Concurrency::call< _Type, _FunctorType >::process_input_messages ( _Inout_ message< _Type > *  _PMessage)
inlineprotectedvirtual

Executes the call function on the input messages.

5761  {
5762  // Invoke the function provided by the user
5763  _CONCRT_ASSERT(_PMessage != NULL);
5764  _M_pFunc(_PMessage->payload);
5765  delete _PMessage;
5766  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
#define NULL
Definition: crtdbg.h:30
_Call_method _M_pFunc
Definition: agents.h:5775
template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
virtual void Concurrency::call< _Type, _FunctorType >::process_message ( _Inout_ message< _Type > *  _PMessage)
inlineprotectedvirtual

Processes a message that was accepted by this call messaging block.

Parameters
_PMessageA pointer to the message that is to be handled.
5752  {
5753  // No longer necessary with CRT110 change
5754  }
template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
virtual message_status Concurrency::call< _Type, _FunctorType >::propagate_message ( _Inout_ message< _Type > *  _PMessage,
_Inout_ ISource< _Type > *  _PSource 
)
inlineprotectedvirtual

Asynchronously passes a message from an ISource block to this call 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.
5665  {
5666  // It is important that calls to propagate do *not* take the same lock on the
5667  // internal structure that is used by Consume and the LWT. Doing so could
5668  // result in a deadlock with the Consume call.
5669 
5670  message_status _Result = accepted;
5671 
5672  //
5673  // Accept the message being propagated
5674  // Note: depending on the source block propagating the message
5675  // this may not necessarily be the same message (pMessage) first
5676  // passed into the function.
5677  //
5678  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
5679 
5680  if (_PMessage != NULL)
5681  {
5682  async_send(_PMessage);
5683  }
5684  else
5685  {
5686  _Result = missed;
5687  }
5688 
5689  return _Result;
5690  }
void async_send(_Inout_opt_ message< _Source_type > *_PMessage)
Asynchronously sends a message for processing.
Definition: agents.h:3124
#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
template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
virtual message_status Concurrency::call< _Type, _FunctorType >::send_message ( _Inout_ message< _Type > *  _PMessage,
_Inout_ ISource< _Type > *  _PSource 
)
inlineprotectedvirtual

Synchronously passes a message from an ISource block to this call 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.
5708  {
5709  message_status _Result = accepted;
5710 
5711  //
5712  // Accept the message being propagated
5713  // Note: depending on the source block propagating the message
5714  // this may not necessarily be the same message (pMessage) first
5715  // passed into the function.
5716  //
5717  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
5718 
5719  if (_PMessage != NULL)
5720  {
5721  sync_send(_PMessage);
5722  }
5723  else
5724  {
5725  _Result = missed;
5726  }
5727 
5728  return _Result;
5729  }
#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
void sync_send(_Inout_opt_ message< _Source_type > *_PMessage)
Synchronously send a message for processing.
Definition: agents.h:3136
template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
virtual bool Concurrency::call< _Type, _FunctorType >::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< _Type > >::type::source_type >.

5740  {
5741  return true;
5742  }

Member Data Documentation

template<class _Type , class _FunctorType = std::tr1::function<void(_Type const&)>>
_Call_method Concurrency::call< _Type, _FunctorType >::_M_pFunc
private

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