forked from flexibity-team/boost-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialFeedAggregator.hpp
49 lines (41 loc) · 1021 Bytes
/
serialFeedAggregator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* serialFeedAggregator.hpp
*
* Created on: Aug 20, 2015
* Author: romeo
*/
#ifndef INCLUDE_FLEXIBITY_SERIALFEEDAGGREGATOR_HPP_
#define INCLUDE_FLEXIBITY_SERIALFEEDAGGREGATOR_HPP_
#include "flexibity/ioSerial.hpp"
namespace Flexibity{
/**
* not thread safe
*/
class ioSerialFeedAggregator:
public Flexibity::ioSerialMsgReceiver{
public:
virtual void feed( Flexibity::serialMsgContainer m ) override {
msgs.push_back(m);
}
Flexibity::oSerialMsgContainer aggregate(){
Flexibity::oSerialMsgContainer m = make_shared<Flexibity::oSerialMsg>();
while(!msgs.empty()){
*m += *(msgs.front());
msgs.pop_front();
}
return m;
}
void dispatch(Flexibity::ioSerialMsgReceiver &r){
r.feed(aggregate());
}
void dumpMessages(){
IINFO("dumping \"" << instanceName() << "\" aggregator")
for (auto i = msgs.begin(); i != msgs.end() ; i++) {
IINFO(log::dump(*i));
}
}
private:
deque<Flexibity::serialMsgContainer> msgs;
};
}
#endif /* INCLUDE_FLEXIBITY_SERIALFEEDAGGREGATOR_HPP_ */