9 #include <yarp/os/LogComponent.h>
10 #include <yarp/os/Log.h>
11 #include <yarp/os/LogStream.h>
12 #include <yarp/os/Bottle.h>
13 #include <yarp/os/Network.h>
16 YARP_LOG_COMPONENT(RAWVALUESPUBLISHERCLIENT,
"iCub.debugLibrary.rawvaluespublisherclient")
19 #undef DEBUG_RAW_VALUES_MACRO
21 using namespace yarp::os;
26 yCError(RAWVALUESPUBLISHERCLIENT) << txt <<
"has not yet been implemented";
32 yCError(RAWVALUESPUBLISHERCLIENT) << txt <<
"has been deprecated";
39 std::lock_guard<std::mutex> guard(dataMutex);
45 if (!parseParams(config))
50 std::string localStreamingPortName = m_local +
"/rawdata:i";
51 std::string remoteStreamingPortName = m_remote +
"/rawdata:o";
52 std::string localRPCPortName = m_local +
"/rpc:i";
53 std::string remoteRPCPortName = m_remote +
"/rpc:o";
57 if(!m_rpcPort.open(localRPCPortName))
59 yCError(RAWVALUESPUBLISHERCLIENT) <<
"Failure opening RPC port" << localStreamingPortName;
65 if(!m_streamingPort.open(localStreamingPortName))
67 yCError(RAWVALUESPUBLISHERCLIENT) <<
"Failure opening streaming port" << localStreamingPortName;
71 m_streamingPort.useCallback();
74 if (!m_externalConnection)
77 if (!yarp::os::Network::connect(localRPCPortName, remoteRPCPortName, m_carrier))
79 yCError(RAWVALUESPUBLISHERCLIENT) <<
80 "Failure in connecting remote port" << remoteRPCPortName <<
81 "to local port" << localRPCPortName;
83 yCError(RAWVALUESPUBLISHERCLIENT) <<
84 "Check that the specified RawValuesPublisherServer is up. Closing.";
91 if(!yarp::os::Network::connect(remoteStreamingPortName, localStreamingPortName, m_carrier))
93 yCError(RAWVALUESPUBLISHERCLIENT) <<
94 "Failure in connecting remote port" << remoteStreamingPortName <<
95 "to local port" << localStreamingPortName;
97 yCError(RAWVALUESPUBLISHERCLIENT) <<
98 "Check that the specified RawValuesPublisherServer is up. Closing.";
104 if (!m_RPCInterface.yarp().attachAsClient(m_rpcPort)) {
105 yCError(RAWVALUESPUBLISHERCLIENT,
"Failure opening Thrift-based RPC interface.");
109 m_streamingPort.receivedRawDataMap = {};
111 yCInfo(RAWVALUESPUBLISHERCLIENT) <<
"Open completes";
117 m_streamingPort.close();
120 yCInfo(RAWVALUESPUBLISHERCLIENT) <<
"Close completes";
127 std::lock_guard<std::mutex> guard(m_streamingPort.dataMutex);
128 map = m_streamingPort.receivedRawDataMap;
135 std::lock_guard<std::mutex> guard(m_streamingPort.dataMutex);
136 if(m_streamingPort.receivedRawDataMap.find(key) != m_streamingPort.receivedRawDataMap.end())
138 data = m_streamingPort.receivedRawDataMap[key];
142 yCError(RAWVALUESPUBLISHERCLIENT) <<
"Requested key:" << key <<
"does not exist in the raw data map.";
161 metamap = m_RPCInterface.getMetadata();
167 std::map<std::string, rawValuesKeyMetadata> metamap = (m_RPCInterface.getMetadata()).metadataMap;
168 if(metamap.find(key) != metamap.end())
174 yCError(RAWVALUESPUBLISHERCLIENT) <<
"Requested key" << key <<
"is not available in the map. Exiting";
static bool NOT_YET_IMPLEMENTED(const char *txt)
static bool DEPRECATED(const char *txt)
virtual bool getKeyMetadata(std::string key, rawValuesKeyMetadata &meta) override
virtual bool getRawDataMap(std::map< std::string, std::vector< std::int32_t >> &map) override
virtual bool getMetadataMap(rawValuesKeyMetadataMap &metamap) override
virtual bool getKeys(std::vector< std::string > &keys) override
virtual int getNumberOfKeys() override
virtual bool getRawData(std::string key, std::vector< std::int32_t > &data) override
bool open(yarp::os::Searchable &config) override
rawValuesDataVectorsMap IDL struct of a map of vectors to store the raw value data sent by the device
std::map< std::string, std::vector< std::int32_t > > vectorsMap
contain a map of vectors of the raw data as <string, vector> the user wanna send from low to higher l...
yarp::sig::Vector & map(yarp::sig::Vector &v, double(op)(double))
Performs a unary operator inplace on each element of a vector.