133 TemperatureSample(
int aTemp = 0) : temperature(aTemp) {}
141 OverheatingState(
bool aState =
false) : isOverheating(aState) {}
154 Subscribe<TemperatureSample>(
this);
155 SetupPublishing<OverheatingState>(
this);
158 virtual void Evaluate(
const TemperatureSample& sample)
160 if (sample.temperature > kThreshold)
162 Publish(OverheatingState(
true));
166 Publish(OverheatingState(
false));
170 static const int kThreshold = 100;
179 : mOverheatingDetector(&mGraph)
183 OverheatingDetector mOverheatingDetector;
185 virtual void ProcessOutput()
190 const OverheatingState& overheatingState = overheatingStateTopic->
GetNewValue();
191 cout <<
"OverheatingState.isOverheating = " << ((overheatingState.isOverheating) ?
"true" :
"false") << endl;
198 void Test_AboveThreshold()
202 OverheatingDetector detector(&graph);
208 graph.
PushData(TemperatureSample(OverheatingDetector::kThreshold+1));
215 DG_ASSERT(outTopic->GetNewValue().isOverheating ==
true);
219 void Test_BelowThreshold()
223 OverheatingDetector detector(&graph);
227 graph.
PushData(TemperatureSample(OverheatingDetector::kThreshold-1));
232 DG_ASSERT(outTopic->GetNewValue().isOverheating ==
false);
243 OverheatingDetector detector(&graph);
247 graph.
PushData(TemperatureSample(110));
250 const OverheatingState& output =
252 cout <<
"IsOverheating = " << ((output.isOverheating) ?
"true" :
"false") << endl;
256 HelloWorldGraph thermostat;
257 thermostat.ProcessData(TemperatureSample(70));
258 thermostat.ProcessData(TemperatureSample(90));
259 thermostat.ProcessData(TemperatureSample(100));
260 thermostat.ProcessData(TemperatureSample(110));
261 thermostat.ProcessData(TemperatureSample(120));
266 Test_AboveThreshold();
267 Test_BelowThreshold();
Implements a graph of Topics & Detectors with Input/Output APIs.
void PushData(const TTopicState &aTopicState)
Push data to a specific topic in the graph.
bool HasNewValue() const
Returns true if the new Data is available.
A Base class for a basic Graph container.
Manage data and its handler.
Topic< TTopicState > * ResolveTopic()
Find/add a topic in the detector graph.
const T & GetNewValue() const
Returns reference to the new/latest value in the topic.
Base struct for topic data types.
Base class that implements a Publisher behavior.
A unit of logic in a DetectorGraph.
A Pure interface that declares the Subscriber behavior.
ErrorType EvaluateGraph()
Evaluate the whole graph.
#define DG_ASSERT(condition)