DetectorGraph
2.0
|
The basics - A trivial Graph with a single Detector. More...
Go to the source code of this file.
The basics - A trivial Graph with a single Detector.
This examples cover the basics of using the DetectorGraph framework - a "Hello World" of sorts. For the purposes of this example imagine a temperature sensor that produces samples regularly and that we're tasked to signal other parts of the system whenever that temperature crosses a threshold.
We start by splitting the problem, within the scope of our task, in three parts:
Topics are defined by the DetectorGraph::TopicState type they carry. A TopicState is any C++ struct/class that inherits from DetectorGraph::TopicState.
For the 'input' to our system we'll declare a TemperatureSample
TopicState:
The important here is that this struct
inherits TopicState and that it has data field(s).
Next we define the 'output'; another struct that also inherits DetectorGraph::TopicState and has data fields:
Now we just need to fill in the gap; the Detector that creates OverheatingState
from TemperatureSample
: two.
The final plumbing is to add our newly created Detector to a DetectorGraph::Graph. Depending on the situation this can be done in different ways but here's the simplest:
With that the Graph instance will internally create the following graph:
Topics are represented by rectangles, Detectors by the oval shapes and arrows follow the flow of data - this is the standard representation for DetectorGraph graphs. The numeric prefix to the names is each node's order in the Topological sort of the graph. Output topics are painted Lime Green and input ones Light Blue.
Finally, using the graph is done by Pushing data in, evaluating the graph and checking outputs:
Running the program then gives:
DetectorGraph: Graph Initialized IsOverheating = true
An alternative way to do things is to subclass the DetectorGraph::ProcessorContainer utility that streamlines the DetectorGraph::Graph::PushData, DetectorGraph::Graph::EvaluateGraph and subsequent inspection steps. For the example above, the DetectorGraph::ProcessorContainer implementation would be:
And then usage would be like:
DetectorGraph: Graph Initialized OverheatingState.isOverheating = false OverheatingState.isOverheating = false OverheatingState.isOverheating = false OverheatingState.isOverheating = true OverheatingState.isOverheating = true
This example can be built with:
Definition in file helloworld.cpp.