Part of a series of examples on the different ways of using ports. See Port power tutorial.
#include <stdio.h>
class DataProcessor : public TypedReaderCallback<Bottle>, public PortReader {
virtual void onRead(Bottle& b) {
printf("Got one-way message: %s\n", b.toString().c_str());
}
virtual bool read(ConnectionReader& connection) {
Bottle in, out;
in.read(connection);
printf("Got message to reply to: %s\n", in.toString().c_str());
out.clear();
out.addString("acknowledge");
out.append(in);
ConnectionWriter *returnToSender = connection.getWriter();
if (returnToSender!=NULL) {
out.write(*returnToSender);
}
return true;
}
};
DataProcessor processor;
DataProcessor processor;
BufferedPort<Bottle> p;
p.useCallback(processor);
p.setReplier(processor);
p.open("/in");
while (true) {
printf("main thread free to do whatever it wants\n");
}
return 0;
}
void delay(double seconds)
Wait for a certain number of seconds.
An interface to the operating system, including Port based communication.
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
The main, catch-all namespace for YARP.
int main(int argc, char *argv[])