|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
40 return !isConnectionless();
87 return defaultSendHeader(proto);
98 return defaultSendIndex(proto, writer);
109 return defaultExpectIndex(proto);
118 if ((
size_t)r != number.
length()) {
119 yCDebug(ABSTRACTCARRIER,
"did not get sender name length");
133 yCDebug(ABSTRACTCARRIER,
"did not get sender name");
136 std::string s = b.
get();
145 return defaultSendAck(proto);
150 return defaultExpectAck(proto);
170 int x = interpretYarpNumber(b);
179 createYarpNumber(7777 + specifier, header);
184 bool ok = sendIndex(proto, writer);
195 bool ok = sendConnectionStateSpecifier(proto);
199 return sendSenderSpecifier(proto);
205 Bytes header((
char*)&buf[0],
sizeof(buf));
222 Bytes b((
char*)senderName.c_str(), senderName.length() + 1);
230 writeYarpInt(10, proto);
231 int len = (int)writer.
length();
232 char lens[] = {(char)len, (
char)1, (char)-1, (
char)-1, (char)-1, (
char)-1, (char)-1, (
char)-1, (char)-1, (
char)-1};
238 for (
int i = 0; i < len; i++) {
251 Bytes header((
char*)&buf[0],
sizeof(buf));
253 if ((
size_t)hdr != header.
length()) {
254 yCDebug(ABSTRACTCARRIER,
"did not get acknowledgement header");
257 int len = interpretYarpNumber(header);
259 yCDebug(ABSTRACTCARRIER,
"acknowledgement header is bad");
263 if ((
size_t)len != len2) {
264 yCDebug(ABSTRACTCARRIER,
"did not get an acknowledgement of the promised length");
273 yCDebug(ABSTRACTCARRIER,
"expecting an index");
277 Bytes header((
char*)&buf[0],
sizeof(buf));
279 if ((
size_t)r != header.
length()) {
280 yCDebug(ABSTRACTCARRIER,
"broken index");
283 int len = interpretYarpNumber(header);
285 yCDebug(ABSTRACTCARRIER,
"broken index - header is not a number");
289 yCDebug(ABSTRACTCARRIER,
"broken index - header is wrong length");
292 yCDebug(ABSTRACTCARRIER,
"index coming in happily...");
294 Bytes indexHeader((
char*)&buf2[0],
sizeof(buf2));
296 if ((
size_t)r != indexHeader.
length()) {
297 yCDebug(ABSTRACTCARRIER,
"broken index, secondary header");
300 yCDebug(ABSTRACTCARRIER,
"secondary header came in happily...");
301 int inLen = (
unsigned char)(indexHeader.
get()[0]);
302 int outLen = (
unsigned char)(indexHeader.
get()[1]);
309 for (
int i = 0; i < inLen; i++) {
311 if ((
size_t)l != number.
length()) {
312 yCDebug(ABSTRACTCARRIER,
"bad input block length");
318 for (
int i2 = 0; i2 < outLen; i2++) {
320 if ((
size_t)l != number.
length()) {
321 yCDebug(ABSTRACTCARRIER,
"bad output block length");
328 yCDebug(ABSTRACTCARRIER,
"Total message length: %d", total);
335 yCDebug(ABSTRACTCARRIER,
"sending an acknowledgment");
337 writeYarpInt(0, proto);
345 Bytes header(&(buf[0]),
sizeof(buf));
347 if ((
size_t)len != header.
length()) {
348 yCDebug(ABSTRACTCARRIER,
"data stream died");
351 return interpretYarpNumber(header);
357 Bytes header(&(buf[0]),
sizeof(buf));
358 createYarpNumber(n, header);
365 const char* base = b.
get();
366 if (base[0] ==
'Y' && base[1] ==
'A' && base[6] ==
'R' && base[7] ==
'P') {
377 if (header.
length() != 8) {
380 char* base = header.
get();
std::string toString() const
Render a text form of the route, "source->carrier->dest".
virtual size_t length() const =0
void writeYarpInt(int n, ConnectionState &proto)
Write n as an 8 bytes yarp number.
bool prepareSend(ConnectionState &proto) override
Perform any initialization needed before writing on a connection.
bool defaultSendAck(ConnectionState &proto)
Default implementation for the sendAck method.
bool sendAck(ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
bool sendConnectionStateSpecifier(ConnectionState &proto)
virtual void write(char ch)
Write a single byte to the stream.
std::string toString() const override
Get name of carrier.
Simple specification of the minimum functions needed from output streams.
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
bool expectReplyToHeader(ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
virtual void write(OutputStream &os)
Information about a connection between two ports.
virtual void setRemainingLength(int len)=0
Tell the connection that the given number of bytes are left to be read.
bool supportReply() const override
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
bool defaultExpectAck(ConnectionState &proto)
Default implementation for the expectAck method.
static int interpretYarpNumber(const yarp::os::Bytes &b)
bool defaultSendHeader(ConnectionState &proto)
Default implementation for the sendHeader method.
void getCarrierParams(yarp::os::Property ¶ms) const override
Get carrier configuration and deliver it by port administrative commands.
bool defaultSendIndex(ConnectionState &proto, SizedWriter &writer)
Default implementation for the sendIndex method.
OutputStream & os()
Shorthand for getOutputStream()
virtual const Route & getRoute() const =0
Get the route associated with this connection.
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
bool isActive() const override
Check if carrier is alive and error free.
virtual Connection & getConnection()=0
Access the controller for this connection.
virtual bool requireAck() const =0
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
void createStandardHeader(int specifier, yarp::os::Bytes &header) const
virtual void setRoute(const Route &route)=0
Set the route associated with this connection.
virtual bool sendIndex(ConnectionState &proto, SizedWriter &writer)
bool sendHeader(ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
virtual void flush()
Make sure all pending write operations are finished.
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
virtual void getHeader(yarp::os::Bytes &header) const =0
Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to se...
void setCarrierParams(const yarp::os::Property ¶ms) override
Configure carrier from port administrative commands.
bool canOffer() const override
Check if writing is implemented for this carrier.
A simple abstraction for a block of bytes.
static void createYarpNumber(int x, yarp::os::Bytes &header)
bool expectSenderSpecifier(ConnectionState &proto) override
Expect the name of the sending port.
The basic state of a connection - route, streams in use, etc.
virtual bool isOk() const =0
Check if the stream is ok or in an error state.
virtual std::string getSenderSpecifier() const =0
Extract a name for the sender, if the connection type supports that.
bool expectIndex(ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
bool canAccept() const override
Check if reading is implemented for this carrier.
bool write(ConnectionState &proto, SizedWriter &writer) override
Write a message.
void setFromName(const std::string &fromName)
Set the source of the route.
InputStream & is()
Shorthand for getInputStream()
bool isTextMode() const override
Check if carrier is textual in nature.
bool expectExtraHeader(ConnectionState &proto) override
Receive any carrier-specific header.
bool sendSenderSpecifier(ConnectionState &proto)
#define YARP_OS_LOG_COMPONENT(name, name_string)
The components from which ports and connections are built.
bool expectAck(ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
static int netInt(const yarp::os::Bytes &code)
bool defaultExpectIndex(ConnectionState &proto)
Default implementation for the expectIndex method.
bool isLocal() const override
Check if carrier operates within a single process.
Minimal requirements for an efficient Writer.
bool canEscape() const override
Check if carrier can encode administrative messages, as opposed to just user data.
A class for storing options and configuration information.
int getSpecifier(const Bytes &b) const
std::int32_t NetInt32
Definition of the NetInt32 type.
int readYarpInt(ConnectionState &proto)
Read 8 bytes and interpret them as a YARP number.