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...
 
typedef multi_link_registry< ISource< _Type > > _SourceLinkRegistry
 

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::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::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::function<void(_Type const&)>>
typedef _FunctorType Concurrency::call< _Type, _FunctorType >::_Call_method
private

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

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

Constructor & Destructor Documentation

template<class _Type , class _FunctorType = std::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
7143  :
7144  _M_pFunc(_Func)
7145  {
7146  this->initialize_target();
7147  this->enable_batched_processing();
7148  }
void enable_batched_processing()
Enables batched processing for this block.
Definition: agents.h:4757
_Call_method _M_pFunc
Definition: agents.h:7448
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:4738
template<class _Type , class _FunctorType = std::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
7169  :
7170  _M_pFunc(_Func)
7171  {
7172  this->initialize_target();
7173  this->enable_batched_processing();
7174  this->register_filter(_Filter);
7175  }
void enable_batched_processing()
Enables batched processing for this block.
Definition: agents.h:4757
_Call_method _M_pFunc
Definition: agents.h:7448
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:4738
void register_filter(filter_method const &_Filter)
Registers a filter method that will be invoked on every message received.
Definition: agents.h:4705
template<class _Type , class _FunctorType = std::function<void(_Type const&)>>
Concurrency::call< _Type, _FunctorType >::~call ( )
inline

Destroys the call messaging block.

7312  {
7313  this->remove_sources();
7314  }
void remove_sources()
Unlinks all sources after waiting for outstanding asynchronous send operations to complete...
Definition: agents.h:4815
template<class _Type , class _FunctorType = std::function<void(_Type const&)>>
Concurrency::call< _Type, _FunctorType >::call ( call< _Type, _FunctorType > const &  )
private

Member Function Documentation

template<class _Type , class _FunctorType = std::function<void(_Type const&)>>
call const& Concurrency::call< _Type, _FunctorType >::operator= ( call< _Type, _FunctorType > const &  )
private
template<class _Type , class _FunctorType = std::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.

7434  {
7435  // Invoke the function provided by the user
7436  _CONCRT_ASSERT(_PMessage != NULL);
7437  _M_pFunc(_PMessage->payload);
7438  delete _PMessage;
7439  }
#define NULL
Definition: vcruntime.h:236
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
_Call_method _M_pFunc
Definition: agents.h:7448
template<class _Type , class _FunctorType = std::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.
7425  {
7426  // No longer necessary with CRT110 change
7427  }
template<class _Type , class _FunctorType = std::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.
7338  {
7339  // It is important that calls to propagate do *not* take the same lock on the
7340  // internal structure that is used by Consume and the LWT. Doing so could
7341  // result in a deadlock with the Consume call.
7342 
7343  message_status _Result = accepted;
7344 
7345  //
7346  // Accept the message being propagated
7347  // Note: depending on the source block propagating the message
7348  // this may not necessarily be the same message (pMessage) first
7349  // passed into the function.
7350  //
7351  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
7352 
7353  if (_PMessage != NULL)
7354  {
7355  this->async_send(_PMessage);
7356  }
7357  else
7358  {
7359  _Result = missed;
7360  }
7361 
7362  return _Result;
7363  }
#define NULL
Definition: vcruntime.h:236
void async_send(_Inout_opt_ message< _Source_type > *_PMessage)
Asynchronously sends a message for processing.
Definition: agents.h:4775
message_status
The valid responses for an offer of a message object to a block.
Definition: agents.h:1740
The target tried to accept the message, but it was no longer available.
Definition: agents.h:1761
The target accepted the message.
Definition: agents.h:1746
template<class _Type , class _FunctorType = std::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.
7381  {
7382  message_status _Result = accepted;
7383 
7384  //
7385  // Accept the message being propagated
7386  // Note: depending on the source block propagating the message
7387  // this may not necessarily be the same message (pMessage) first
7388  // passed into the function.
7389  //
7390  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
7391 
7392  if (_PMessage != NULL)
7393  {
7394  this->sync_send(_PMessage);
7395  }
7396  else
7397  {
7398  _Result = missed;
7399  }
7400 
7401  return _Result;
7402  }
#define NULL
Definition: vcruntime.h:236
message_status
The valid responses for an offer of a message object to a block.
Definition: agents.h:1740
The target tried to accept the message, but it was no longer available.
Definition: agents.h:1761
The target accepted the message.
Definition: agents.h:1746
void sync_send(_Inout_opt_ message< _Source_type > *_PMessage)
Synchronously send a message for processing.
Definition: agents.h:4787
template<class _Type , class _FunctorType = std::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 >.

7413  {
7414  return true;
7415  }

Member Data Documentation

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

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