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 > *)
 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
7144  :
7145  _M_pFunc(_Func)
7146  {
7147  this->initialize_target();
7148  this->enable_batched_processing();
7149  }
void enable_batched_processing()
Enables batched processing for this block.
Definition: agents.h:4757
_Call_method _M_pFunc
Definition: agents.h:7450
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
7170  :
7171  _M_pFunc(_Func)
7172  {
7173  this->initialize_target();
7174  this->enable_batched_processing();
7175  this->register_filter(_Filter);
7176  }
void enable_batched_processing()
Enables batched processing for this block.
Definition: agents.h:4757
_Call_method _M_pFunc
Definition: agents.h:7450
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.

7313  {
7314  this->remove_sources();
7315  }
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.

7436  {
7437  // Invoke the function provided by the user
7438  _CONCRT_ASSERT(_PMessage != NULL);
7439  _M_pFunc(_PMessage->payload);
7440  delete _PMessage;
7441  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
_Call_method _M_pFunc
Definition: agents.h:7450
#define NULL
Definition: corecrt.h:158
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.
7426  {
7427  (void) _PMessage;
7428  // No longer necessary with CRT110 change
7429  }
_CRT_BEGIN_C_HEADER typedef void(__CRTDECL *terminate_handler)()
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.
7339  {
7340  // It is important that calls to propagate do *not* take the same lock on the
7341  // internal structure that is used by Consume and the LWT. Doing so could
7342  // result in a deadlock with the Consume call.
7343 
7345 
7346  //
7347  // Accept the message being propagated
7348  // Note: depending on the source block propagating the message
7349  // this may not necessarily be the same message (pMessage) first
7350  // passed into the function.
7351  //
7352  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
7353 
7354  if (_PMessage != NULL)
7355  {
7356  this->async_send(_PMessage);
7357  }
7358  else
7359  {
7360  _Result = missed;
7361  }
7362 
7363  return _Result;
7364  }
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
_Pre_maybenull_ _Inout_ _Deref_prepost_z_ wchar_t const _PSource
Definition: wchar.h:148
_Result
Definition: corecrt_wconio.h:362
#define NULL
Definition: corecrt.h:158
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.
7382  {
7384 
7385  //
7386  // Accept the message being propagated
7387  // Note: depending on the source block propagating the message
7388  // this may not necessarily be the same message (pMessage) first
7389  // passed into the function.
7390  //
7391  _PMessage = _PSource->accept(_PMessage->msg_id(), this);
7392 
7393  if (_PMessage != NULL)
7394  {
7395  this->sync_send(_PMessage);
7396  }
7397  else
7398  {
7399  _Result = missed;
7400  }
7401 
7402  return _Result;
7403  }
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
_Pre_maybenull_ _Inout_ _Deref_prepost_z_ wchar_t const _PSource
Definition: wchar.h:148
_Result
Definition: corecrt_wconio.h:362
void sync_send(_Inout_opt_ message< _Source_type > *_PMessage)
Synchronously send a message for processing.
Definition: agents.h:4787
#define NULL
Definition: corecrt.h:158
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 >.

7414  {
7415  return true;
7416  }

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: