Autowiring  1.0.3
A C++ Inversion of Control Framework
AutoPacketFactory Class Reference

A configurable factory class for pipeline packets with a built-in object pool More...

#include <AutoPacketFactory.h>

Inheritance diagram for AutoPacketFactory:
ContextMember CoreRunnable

Public Member Functions

const autowiring::AutoFilterDescriptor & AddSubscriber (const autowiring::AutoFilterDescriptor &rhs)
 Registers the passed subscriber, if it defines a method called AutoFilter More...
 
template<class T >
autowiring::AutoFilterDescriptor AddSubscriber (const std::shared_ptr< T > &rhs)
 Convenience override of AddSubscriber More...
 
template<class T >
void AppendAutoFiltersTo (T &container) const
 Copies the internal set of AutoFilter members to the specified container More...
 
void Clear (void)
 Causes this AutoPacketFactory to release all of its packet subscribers More...
 
autowiring::SatCounter * CreateSatCounterList (void) const
 Creates a linked list of saturation counters More...
 
std::shared_ptr< AutoPacketCurrentPacket (void)
 
void DoAdditionalWait (void) override
 Untimed variant of DoAdditionalWait More...
 
bool DoAdditionalWait (std::chrono::nanoseconds timeout) override
 Invoked just before control is returned to the user. More...
 
std::vector< autowiring::AutoFilterDescriptor > GetAutoFilters (void) const
 
double GetMeanPacketLifetime (void)
 Returns the mean lifespan of AutoPackets in nanoseconds since the last statistics reset. More...
 
size_t GetOutstandingPacketCount (void) const
 
Returns
the number of outstanding AutoPackets

 
double GetPacketLifetimeStandardDeviation (void)
 Returns the standard deviation of the lifespans of AutoPackets in nanoseconds since most recent statistics reset. More...
 
long long GetTotalPacketCount (void)
 Returns the number of packets which have recorded duration statistics since the most recent statistics reset. More...
 
bool IsRunning (void) const override
 Reports whether this runnable is currently running.
 
std::shared_ptr< AutoPacketNewPacket (void)
 Obtains a new packet from the object pool and configures it with the current satisfaction graph More...
 
bool OnStart (void) override
 Invoked by the Start() method. Override this method to perform any needed setup More...
 
void OnStop (bool graceful) override
 Invoked by the base class Stop() method. Override this method to perform any needed cleanup. More...
 
template<class Fx >
autowiring::AutoFilterDescriptor operator+= (Fx &&fx)
 Convienance overload of operator+= to add a subscriber from a lambda More...
 
void operator-= (const autowiring::AutoFilterDescriptor &desc)
 Overloaded counterpart to RemoveSubscriber More...
 
void RecordPacketDuration (std::chrono::nanoseconds duration)
 Called by each AutoPacket's Finalize method to allow the factory to record statistics about packet lifespan. More...
 
void RemoveSubscriber (const autowiring::AutoFilterDescriptor &autoFilter)
 Removes the designated AutoFilter from this factory More...
 
void ResetPacketStatistics (void)
 Resets the statistics accumulators stored by the AutoPacketFactory. More...
 
- Public Member Functions inherited from ContextMember
std::shared_ptr< CoreContextGetContext (void) const
 Retrieves the context associated with this object. More...
 
template<class T >
std::shared_ptr< const T > GetSelf (void) const
 Returns a shared pointer that refers to ourselves More...
 
template<class T >
std::shared_ptr< T > GetSelf (void)
 Returns a shared pointer that refers to ourselves More...
 
virtual void NotifyContextTeardown (void)
 Invoked by the parent context when the parent context is about to be destroyed More...
 
- Public Member Functions inherited from CoreRunnable
bool ShouldStop (void) volatile const
 Reports whether this runnable should stop.
 
virtual bool Start (std::shared_ptr< CoreObject > outstanding)
 Causes this runnable to begin processing. More...
 
void Stop (bool graceful=true)
 Stops this runnable. More...
 
bool ThreadSleep (std::chrono::nanoseconds timeout)
 Sleeps this thread for the specified duration. More...
 
void Wait (void)
 Waits indefinitely. Returns when this runnable stops. More...
 
bool WaitFor (std::chrono::nanoseconds timeout)
 Waits for the specified amount of time. More...
 
template<typename TimeType >
bool WaitUntil (TimeType timepoint)
 Waits until the specified time. More...
 
bool WasStarted (void) volatile const
 Reports whether this runnable was ever started.
 

Protected Member Functions

autowiring::AutoFilterDescriptor GetTypeDescriptorUnsafe (auto_id nodeType)
 Returns a description of the AutoFilter associated with the type nodeType More...
 
- Protected Member Functions inherited from CoreRunnable
const std::shared_ptr< CoreObject > & GetOutstanding (void) const
 

Detailed Description

A configurable factory class for pipeline packets with a built-in object pool

Generally, only one packet factory is required per context.

Member Function Documentation

const autowiring::AutoFilterDescriptor& AutoPacketFactory::AddSubscriber ( const autowiring::AutoFilterDescriptor &  rhs)

Registers the passed subscriber, if it defines a method called AutoFilter

Parameters
rhsThe descriptor for the AutoFilter to be added
Returns
rhs

This method is idempotent

template<class T >
autowiring::AutoFilterDescriptor AutoPacketFactory::AddSubscriber ( const std::shared_ptr< T > &  rhs)
inline

Convenience override of AddSubscriber

Parameters
rhsA shared pointer to a type which has an AutoFilter routine on it

For this call to be valid, T::AutoFilter must be defined and must be a compliant AutoFilter

template<class T >
void AutoPacketFactory::AppendAutoFiltersTo ( T &  container) const
inline

Copies the internal set of AutoFilter members to the specified container

void AutoPacketFactory::Clear ( void  )

Causes this AutoPacketFactory to release all of its packet subscribers

This method will cause the factory to enter the Stopped state, if it's not there already. This method is idempotent.

autowiring::SatCounter* AutoPacketFactory::CreateSatCounterList ( void  ) const

Creates a linked list of saturation counters

Returns
The first element in the list, or nullptr if the list is empty
std::shared_ptr<AutoPacket> AutoPacketFactory::CurrentPacket ( void  )
Returns
The most recently issued packet, or possibly nullptr if that packet has already been destroyed

Referenced by operator+=().

void AutoPacketFactory::DoAdditionalWait ( void  )
overridevirtual

Untimed variant of DoAdditionalWait

Reimplemented from CoreRunnable.

bool AutoPacketFactory::DoAdditionalWait ( std::chrono::nanoseconds  timeout)
overridevirtual

Invoked just before control is returned to the user.

Parameters
timeoutThe maximum amount of time to wait
Returns
True if the wait succeeded, false if a timeout occurred

This virtual method provides implementors with a way to add further constraints to the wait operation beyond the condition variable held internally by this CoreRunnable.

This method must return true if the timeout is indefinite.

Reimplemented from CoreRunnable.

std::vector<autowiring::AutoFilterDescriptor> AutoPacketFactory::GetAutoFilters ( void  ) const
Returns
A copy of all AutoFilter instances on this class
double AutoPacketFactory::GetMeanPacketLifetime ( void  )

Returns the mean lifespan of AutoPackets in nanoseconds since the last statistics reset.

If the factory is left to run for an extended period of time without a reset the mean will decrease erroneously due to saturation of the accumulator.

double AutoPacketFactory::GetPacketLifetimeStandardDeviation ( void  )

Returns the standard deviation of the lifespans of AutoPackets in nanoseconds since most recent statistics reset.

If the factory is left to run for an extended period of time without a reset the standard deviation will behave erraticly due to saturation of the accumulators.

long long AutoPacketFactory::GetTotalPacketCount ( void  )
inline

Returns the number of packets which have recorded duration statistics since the most recent statistics reset.

autowiring::AutoFilterDescriptor AutoPacketFactory::GetTypeDescriptorUnsafe ( auto_id  nodeType)
protected

Returns a description of the AutoFilter associated with the type nodeType

If a matching description was not found GetTypeDescriptor(type).GetAutoFilterTypeInfo() == nullptr

Referenced by operator+=().

std::shared_ptr<AutoPacket> AutoPacketFactory::NewPacket ( void  )

Obtains a new packet from the object pool and configures it with the current satisfaction graph

Referenced by operator+=().

bool AutoPacketFactory::OnStart ( void  )
overridevirtual

Invoked by the Start() method. Override this method to perform any needed setup

Returns
True if processing has started, false otherwise. When overriding, returning false will shut down the runnable immediately.

This method will be called at most once. Returning false from this method will result in an immediate invocation of OnStop(false).

Reimplemented from CoreRunnable.

void AutoPacketFactory::OnStop ( bool  graceful)
overridevirtual

Invoked by the base class Stop() method. Override this method to perform any needed cleanup.

Parameters
gracefulSpecifies whether the runnable should stop normally or whether it should exit as quickly as possible.

This method will be called at most once from a passive level.

Reimplemented from CoreRunnable.

template<class Fx >
autowiring::AutoFilterDescriptor AutoPacketFactory::operator+= ( Fx &&  fx)
inline

Convienance overload of operator+= to add a subscriber from a lambda

This method provides a way to attach a lambda function directly to the factory

void AutoPacketFactory::operator-= ( const autowiring::AutoFilterDescriptor &  desc)

Overloaded counterpart to RemoveSubscriber

Referenced by operator+=().

void AutoPacketFactory::RecordPacketDuration ( std::chrono::nanoseconds  duration)

Called by each AutoPacket's Finalize method to allow the factory to record statistics about packet lifespan.

Parameters
durationThe total lifetime of the AutoPacket that is being Finalized

Referenced by operator+=().

void AutoPacketFactory::RemoveSubscriber ( const autowiring::AutoFilterDescriptor &  autoFilter)

Removes the designated AutoFilter from this factory

Parameters
autoFilterThe AutoFilter to be removed

This method will not retroactively modify packets that have already been issued with the specified AutoFilter on it. Only packets that are issued after this method returns will lack the presence of the autoFilter described by the parameter.

void AutoPacketFactory::ResetPacketStatistics ( void  )

Resets the statistics accumulators stored by the AutoPacketFactory.


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