DetectorGraph  2.0
Public Member Functions | Protected Member Functions | List of all members
DetectorGraph::Detector Class Reference

A unit of logic in a DetectorGraph. More...

Collaboration diagram for DetectorGraph::Detector:

Public Member Functions

 Detector (Graph *graph)
 Constructor. More...
 
virtual ~Detector ()
 Destructor. More...
 
virtual VertexType GetVertexType () const
 Returns kDetectorVertex to identify this subclass of Vertex. More...
 
void ProcessVertex ()
 Consume data in the topics. More...
 
- Public Member Functions inherited from DetectorGraph::Vertex
 Vertex ()
 
virtual ~Vertex ()
 
VertexSearchState GetState () const
 
void SetState (VertexSearchState aNewState)
 
void InsertEdge (Vertex *aVertex)
 
void RemoveEdge (Vertex *aVertex)
 
VertexPtrContainerGetOutEdges ()
 
void MarkFutureEdge (Vertex *aVertex)
 
VertexPtrContainerGetInEdges ()
 
VertexPtrContainerGetFutureOutEdges ()
 
VertexPtrContainerGetFutureInEdges ()
 
const char * GetName () const
 

Protected Member Functions

template<class TTopicState >
void Subscribe (SubscriberInterface< TTopicState > *aSubscriber)
 Setup an subscription on a specific topic. More...
 
template<class TTopic >
void SetupPublishing (Publisher< TTopic > *aPublisher)
 Setup an advertisement on a specific topic. More...
 
template<class TTopic >
void SetupFuturePublishing (FuturePublisher< TTopic > *aFuturePublisher)
 Setup an future advertisement on a specific topic. More...
 
template<class TTopic >
void SetupTimeoutPublishing (TimeoutPublisher< TTopic > *aTimeoutPublisher, TimeoutPublisherService *aTimeoutPublisherService)
 Setup an timeout advertisement on a specific topic. More...
 
template<class TTopic >
void SetupPeriodicPublishing (const uint64_t aPeriodInMilliseconds, TimeoutPublisherService *aTimeoutPublisherService)
 Setup an periodic advertisement on a specific topic. More...
 
virtual void BeginEvaluation ()
 Called before any calls to SubscriberInterface::Evaluate. More...
 
virtual void CompleteEvaluation ()
 Called after all calls to SubscriberInterface::Evaluate. More...
 

Additional Inherited Members

- Public Types inherited from DetectorGraph::Vertex
enum  VertexSearchState { kVertexClear, kVertexProcessing, kVertexDone }
 Enum used for topological sort & traverse context keeping. More...
 
enum  VertexType { kTopicVertex, kDetectorVertex, kTestVertex }
 
typedef std::list< Vertex * > VertexPtrContainer
 
- Protected Attributes inherited from DetectorGraph::Vertex
VertexSearchState mState
 
VertexPtrContainer mOutEdges
 
VertexPtrContainer mInEdges
 
VertexPtrContainer mFutureOutEdges
 
VertexPtrContainer mFutureInEdges
 

Detailed Description

A unit of logic in a DetectorGraph.

Detectors are compartmentalized algorithm with clear inputs & outputs. It has fixed input types (Subscriptions) and fixed output types (Publishing).

A new detector is implemented by a new class that:

Detectors should be designed to be modular & finely grained. Note that there's a trade-off between granularity & practicality/overhead and sometimes it's easier to find the sweet spot by designing TopicStates that provide intuitive intermediary state representations and then design the detectors afterwards.

For example, a trivial 'temperature threshold' detector could be:

class OverheatingDetector : public DetectorGraph::Detector
, public DetectorGraph::SubscriberInterface<TemperatureSample>
, public DetectorGraph::Publisher<OverheatingState>
{
public:
OverheatingDetector(DetectorGraph::Graph* graph) : DetectorGraph::Detector(graph)
{
Subscribe<TemperatureSample>(this);
SetupPublishing<OverheatingState>(this);
}
virtual void Evaluate(const TemperatureSample& sample)
{
if (sample.temperature > kThreshold)
{
Publish(OverheatingState(true));
}
else
{
Publish(OverheatingState(false));
}
}
static const int kThreshold = 100;
};

For a complete example, go to Hello World

More complex Detectors will subscribe & publish to multiple different topics.

Detectors can also implement BeginEvaluation() and CompleteEvaluation() methods if performing a summary across multiple Evaluate() calls - with calls to Publish() from within CompleteEvaluation().

Definition at line 68 of file detector.hpp.

Constructor & Destructor Documentation

◆ Detector()

DetectorGraph::Detector::Detector ( Graph graph)

Constructor.

A Detector is always created within a Graph. The detector is "attached" to the graph during construction. Also, during construction a subclass must make the necessary calls to:

Definition at line 20 of file detector.cpp.

◆ ~Detector()

DetectorGraph::Detector::~Detector ( )
virtual

Destructor.

Destruction of a Detector removes it from the graph it's contained. It also removes it's own subscription dispatchers and the 'out' edges pointing to this detector owned by the topics it subscribes to.

Definition at line 25 of file detector.cpp.

Member Function Documentation

◆ BeginEvaluation()

void DetectorGraph::Detector::BeginEvaluation ( )
protectedvirtual

Called before any calls to SubscriberInterface::Evaluate.

See more at ProcessVertex()

Definition at line 53 of file detector.cpp.

◆ CompleteEvaluation()

void DetectorGraph::Detector::CompleteEvaluation ( )
protectedvirtual

Called after all calls to SubscriberInterface::Evaluate.

See more at ProcessVertex()

Definition at line 58 of file detector.cpp.

◆ GetVertexType()

virtual VertexType DetectorGraph::Detector::GetVertexType ( ) const
inlinevirtual

Returns kDetectorVertex to identify this subclass of Vertex.

Implements DetectorGraph::Vertex.

Definition at line 99 of file detector.hpp.

◆ ProcessVertex()

void DetectorGraph::Detector::ProcessVertex ( )
virtual

Consume data in the topics.

Executes the evaluation of this detector. This entails:

  • Calling BeginEvaluation()
  • Iterating through all the subscription dispatchers firing only the ones with new data. Firing causes the correct SubscriptionInterface::Evaluate method to be called with the new data.
  • Calling CompleteEvaluation()

Implements DetectorGraph::Vertex.

Definition at line 38 of file detector.cpp.

◆ SetupFuturePublishing()

template<class TTopic >
void DetectorGraph::Detector::SetupFuturePublishing ( FuturePublisher< TTopic > *  aFuturePublisher)
inlineprotected

Setup an future advertisement on a specific topic.

This method must be called at the constructor of a detector; once per FuturePublisher<T> implementation it contains.

Definition at line 148 of file detector.hpp.

◆ SetupPeriodicPublishing()

template<class TTopic >
void DetectorGraph::Detector::SetupPeriodicPublishing ( const uint64_t  aPeriodInMilliseconds,
TimeoutPublisherService aTimeoutPublisherService 
)
inlineprotected

Setup an periodic advertisement on a specific topic.

This method must be called at the constructor of a detector;

Definition at line 173 of file detector.hpp.

◆ SetupPublishing()

template<class TTopic >
void DetectorGraph::Detector::SetupPublishing ( Publisher< TTopic > *  aPublisher)
inlineprotected

Setup an advertisement on a specific topic.

This method must be called at the constructor of a detector; once per Publisher<T> implementation it contains.

Definition at line 135 of file detector.hpp.

◆ SetupTimeoutPublishing()

template<class TTopic >
void DetectorGraph::Detector::SetupTimeoutPublishing ( TimeoutPublisher< TTopic > *  aTimeoutPublisher,
TimeoutPublisherService aTimeoutPublisherService 
)
inlineprotected

Setup an timeout advertisement on a specific topic.

This method must be called at the constructor of a detector; once per TimeoutPublisher<T> implementation it contains.

Definition at line 161 of file detector.hpp.

◆ Subscribe()

template<class TTopicState >
void DetectorGraph::Detector::Subscribe ( SubscriberInterface< TTopicState > *  aSubscriber)
inlineprotected

Setup an subscription on a specific topic.

This method must be called at the constructor of a detector; once per SubscriberInterface<T> interfaces it implements.

Definition at line 120 of file detector.hpp.


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