37 return !isConnectionless();
84 return defaultSendHeader(proto);
95 return defaultSendIndex(proto, writer);
106 return defaultExpectIndex(proto);
115 if ((
size_t)r != number.
length()) {
116 yCDebug(ABSTRACTCARRIER,
"did not get sender name length");
130 yCDebug(ABSTRACTCARRIER,
"did not get sender name");
133 std::string s = b.
get();
142 return defaultSendAck(proto);
147 return defaultExpectAck(proto);
167 int x = interpretYarpNumber(b);
176 createYarpNumber(7777 + specifier, header);
181 bool ok = sendIndex(proto, writer);
192 bool ok = sendConnectionStateSpecifier(proto);
196 return sendSenderSpecifier(proto);
202 Bytes header((
char*)&buf[0],
sizeof(buf));
219 Bytes b((
char*)senderName.c_str(), senderName.length() + 1);
227 writeYarpInt(10, proto);
228 int len = (int)writer.
length();
229 char lens[] = {(char)len, (
char)1, (char)-1, (
char)-1, (char)-1, (
char)-1, (char)-1, (
char)-1, (char)-1, (
char)-1};
235 for (
int i = 0; i < len; i++) {
248 Bytes header((
char*)&buf[0],
sizeof(buf));
250 if ((
size_t)hdr != header.
length()) {
251 yCDebug(ABSTRACTCARRIER,
"did not get acknowledgement header");
254 int len = interpretYarpNumber(header);
256 yCDebug(ABSTRACTCARRIER,
"acknowledgement header is bad");
260 if ((
size_t)len != len2) {
261 yCDebug(ABSTRACTCARRIER,
"did not get an acknowledgement of the promised length");
270 yCDebug(ABSTRACTCARRIER,
"expecting an index");
274 Bytes header((
char*)&buf[0],
sizeof(buf));
276 if ((
size_t)r != header.
length()) {
277 yCDebug(ABSTRACTCARRIER,
"broken index");
280 int len = interpretYarpNumber(header);
282 yCDebug(ABSTRACTCARRIER,
"broken index - header is not a number");
286 yCDebug(ABSTRACTCARRIER,
"broken index - header is wrong length");
289 yCDebug(ABSTRACTCARRIER,
"index coming in happily...");
291 Bytes indexHeader((
char*)&buf2[0],
sizeof(buf2));
293 if ((
size_t)r != indexHeader.
length()) {
294 yCDebug(ABSTRACTCARRIER,
"broken index, secondary header");
297 yCDebug(ABSTRACTCARRIER,
"secondary header came in happily...");
298 int inLen = (
unsigned char)(indexHeader.
get()[0]);
299 int outLen = (
unsigned char)(indexHeader.
get()[1]);
306 for (
int i = 0; i < inLen; i++) {
308 if ((
size_t)l != number.
length()) {
309 yCDebug(ABSTRACTCARRIER,
"bad input block length");
315 for (
int i2 = 0; i2 < outLen; i2++) {
317 if ((
size_t)l != number.
length()) {
318 yCDebug(ABSTRACTCARRIER,
"bad output block length");
325 yCDebug(ABSTRACTCARRIER,
"Total message length: %d", total);
332 yCDebug(ABSTRACTCARRIER,
"sending an acknowledgment");
334 writeYarpInt(0, proto);
342 Bytes header(&(buf[0]),
sizeof(buf));
344 if ((
size_t)len != header.
length()) {
345 yCDebug(ABSTRACTCARRIER,
"data stream died");
348 return interpretYarpNumber(header);
354 Bytes header(&(buf[0]),
sizeof(buf));
355 createYarpNumber(n, header);
362 const char* base = b.
get();
363 if (base[0] ==
'Y' && base[1] ==
'A' && base[6] ==
'R' && base[7] ==
'P') {
374 if (header.
length() != 8) {
377 char* base = header.
get();
bool sendConnectionStateSpecifier(ConnectionState &proto)
virtual bool sendIndex(ConnectionState &proto, SizedWriter &writer)
static int interpretYarpNumber(const yarp::os::Bytes &b)
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
bool defaultSendAck(ConnectionState &proto)
Default implementation for the sendAck method.
bool canAccept() const override
Check if reading is implemented for this carrier.
void setCarrierParams(const yarp::os::Property ¶ms) override
Configure carrier from port administrative commands.
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
bool expectAck(ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
int getSpecifier(const Bytes &b) const
bool write(ConnectionState &proto, SizedWriter &writer) override
Write a message.
void writeYarpInt(int n, ConnectionState &proto)
Write n as an 8 bytes yarp number.
bool sendHeader(ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
bool prepareSend(ConnectionState &proto) override
Perform any initialization needed before writing on a connection.
void createStandardHeader(int specifier, yarp::os::Bytes &header) const
bool sendAck(ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
bool isLocal() const override
Check if carrier operates within a single process.
bool sendSenderSpecifier(ConnectionState &proto)
bool defaultSendIndex(ConnectionState &proto, SizedWriter &writer)
Default implementation for the sendIndex method.
void getCarrierParams(yarp::os::Property ¶ms) const override
Get carrier configuration and deliver it by port administrative commands.
bool expectSenderSpecifier(ConnectionState &proto) override
Expect the name of the sending port.
bool expectReplyToHeader(ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
bool defaultExpectAck(ConnectionState &proto)
Default implementation for the expectAck method.
bool canOffer() const override
Check if writing is implemented for this carrier.
bool isTextMode() const override
Check if carrier is textual in nature.
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
int readYarpInt(ConnectionState &proto)
Read 8 bytes and interpret them as a YARP number.
bool canEscape() const override
Check if carrier can encode administrative messages, as opposed to just user data.
bool defaultExpectIndex(ConnectionState &proto)
Default implementation for the expectIndex method.
bool defaultSendHeader(ConnectionState &proto)
Default implementation for the sendHeader method.
std::string toString() const override
Get name of carrier.
bool supportReply() const override
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
bool isActive() const override
Check if carrier is alive and error free.
bool expectIndex(ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
bool expectExtraHeader(ConnectionState &proto) override
Receive any carrier-specific header.
static void createYarpNumber(int x, yarp::os::Bytes &header)
A simple abstraction for a block of bytes.
The basic state of a connection - route, streams in use, etc.
virtual void setRemainingLength(int len)=0
Tell the connection that the given number of bytes are left to be read.
virtual const Route & getRoute() const =0
Get the route associated with this connection.
virtual Connection & getConnection()=0
Access the controller for this connection.
virtual std::string getSenderSpecifier() const =0
Extract a name for the sender, if the connection type supports that.
InputStream & is()
Shorthand for getInputStream()
OutputStream & os()
Shorthand for getOutputStream()
virtual void setRoute(const Route &route)=0
Set the route associated with this connection.
virtual bool requireAck() const =0
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...
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
static int netInt(const yarp::os::Bytes &code)
Simple specification of the minimum functions needed from output streams.
virtual void flush()
Make sure all pending write operations are finished.
virtual bool isOk() const =0
Check if the stream is ok or in an error state.
virtual void write(char ch)
Write a single byte to the stream.
A class for storing options and configuration information.
Information about a connection between two ports.
std::string toString() const
Render a text form of the route, "source->carrier->dest".
void setFromName(const std::string &fromName)
Set the source of the route.
Minimal requirements for an efficient Writer.
virtual void write(OutputStream &os)
virtual size_t length() const =0
#define yCDebug(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
std::int32_t NetInt32
Definition of the NetInt32 type.