event-driven
vCollectSend.h
1 /*
2  * Copyright (C) 2017 Event-driven Perception for Robotics
3  * Author: arren.glover@iit.it
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __VCOLLECTSEND__
20 #define __VCOLLECTSEND__
21 
22 #include "event-driven/vCodec.h"
23 #include "event-driven/vPort.h"
24 #include <yarp/os/all.h>
25 
26 namespace ev {
27 
30 class collectorPort : public yarp::os::RateThread
31 {
32 private:
33 
34  vQueue filler;
35  ev::vWritePort sendPort;
36  yarp::os::Mutex m;
37  yarp::os::Stamp ystamp;
38 
39 
40 
41 public:
42 
44  collectorPort() : RateThread(1.0) {}
45 
47  bool open(std::string name) {
48 
49  return sendPort.open(name);
50 
51  }
52 
54  void pushevent(event<> v, yarp::os::Stamp y) {
55 
56  m.lock();
57  filler.push_back(v);
58  ystamp = y;
59  m.unlock();
60 
61  }
62 
66  void run() {
67 
68  if(filler.size()) {
69 
70  m.lock();
71  sendPort.write(filler, ystamp);
72  filler.clear();
73  m.unlock();
74 
75  }
76  }
77 
78 };
79 
80 
81 
82 }
83 
84 #endif
Definition: vBottle.h:29
Definition: vPort.h:287
bool open(std::string name)
open the output port
Definition: vCollectSend.h:47
collectorPort()
constructor
Definition: vCollectSend.h:44
void run()
on each call of the thread, all events that have been added are sent on the port in a vBottle...
Definition: vCollectSend.h:66
an output port that can safely accept events from multiple threads and sends them at a fixed output r...
Definition: vCollectSend.h:30
void pushevent(event<> v, yarp::os::Stamp y)
add an event to be sent on next thread execution
Definition: vCollectSend.h:54