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();
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.