123 EventCount(
int aCount = 0) : count(aCount) {}
143 Subscribe<EventHappened>(
this);
144 Subscribe<Reset>(
this);
145 SetupPublishing<EventCount>(
this);
148 void Evaluate(
const EventHappened&)
152 void Evaluate(
const Reset&)
154 mEventCount.count = 0;
156 void CompleteEvaluation()
158 Publish(mEventCount);
162 EventCount mEventCount;
170 EventCountDetector detector(&graph);
177 DG_ASSERT(outTopic->GetNewValue().count == 1);
185 DG_ASSERT(outTopic->GetNewValue().count == 2);
190 void Test_ResetCount()
194 EventCountDetector detector(&graph);
205 DG_ASSERT(outTopic->GetNewValue().count == 0);
217 Subscribe<EventCount>(
this);
218 SetupFuturePublishing<Reset>(
this);
221 void Evaluate(
const EventCount& aEventCount)
223 if (aEventCount.count >= kMaxCount)
225 PublishOnFutureEvaluation(Reset());
229 static const int kMaxCount = 5;
234 void Test_ResetDetected()
238 ResetDetector detector(&graph);
240 graph.
PushData(EventCount(ResetDetector::kMaxCount));
254 void Test_NoResetDetected()
258 ResetDetector detector(&graph);
260 graph.
PushData(EventCount(ResetDetector::kMaxCount-1));
274 CounterWithResetGraph()
275 : mEventCountDetector(&mGraph)
276 , mResetDetector(&mGraph)
277 , mEventCountTopic(mGraph.ResolveTopic<EventCount>())
281 EventCountDetector mEventCountDetector;
282 ResetDetector mResetDetector;
285 virtual void ProcessOutput()
289 const EventCount& eventCount = mEventCountTopic->
GetNewValue();
290 cout <<
"EventCount.count = " << eventCount.count << endl;
297 void Test_CounterResetIntegration()
300 EventCountDetector counterDetector(&graph);
301 ResetDetector resetDetector(&graph);
304 for (
int i = 1; i <= ResetDetector::kMaxCount; i++)
309 DG_ASSERT(outTopic->GetNewValue().count == i);
317 DG_ASSERT(outTopic->GetNewValue().count == 1);
324 CounterWithResetGraph counterGraph;
325 for (
int i = 0; i < 7; ++i)
327 counterGraph.ProcessData(EventHappened());
332 Test_ResetDetected();
333 Test_NoResetDetected();
334 Test_CounterResetIntegration();
Implements a graph of Topics & Detectors with Input/Output APIs.
Publish data to the graph for future evaluation.
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.
bool EvaluateIfHasDataPending()
Evaluates Graph if data is pending and returns true if so.
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)