8#ifndef ROBOTSIO_YARPBUFFEREDPORT_H
9#define ROBOTSIO_YARPBUFFEREDPORT_H
11#include <yarp/os/BufferedPort.h>
12#include <yarp/os/Network.h>
13#include <yarp/os/Stamp.h>
16#include <unordered_map>
21 class YarpBufferedPort;
34 void send_data(
const T& data);
36 T* receive_data(
const bool& blocking);
40 void set_time_stamp(
const double& stamp);
45 yarp::os::Network yarp_;
47 yarp::os::BufferedPort<T> port_;
49 yarp::os::Stamp stamp_;
51 const std::string log_name_ =
"YarpBufferedPort";
58 if (!yarp_.checkNetwork())
60 throw(std::runtime_error(log_name_ +
"::ctor. Error: YARP network is not available."));
63 if(!port_.open(port_name))
65 throw(std::runtime_error(log_name_ +
"::ctor. Error: cannot open port " + port_name +
"."));
73 if(!(port_.isClosed()))
81 T& data_to_be_sent = port_.prepare();
83 port_.setEnvelope(stamp_);
85 data_to_be_sent = data;
94 return port_.read(blocking);
101 yarp::os::Stamp stamp;
102 port_.getEnvelope(stamp);
104 return stamp.getTime();
111 stamp_.update(stamp);
118 std::size_t pending_reads = port_.getPendingReads();
119 for (std::size_t i = 0; i < pending_reads; i++)
122 return pending_reads;