YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Protocol.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
8
9#include <yarp/os/Bottle.h>
10#include <yarp/os/Carrier.h>
11#include <yarp/os/Carriers.h>
12#include <yarp/os/NetType.h>
13#include <yarp/os/Portable.h>
14#include <yarp/os/ShiftStream.h>
18
19#include <cstdio>
20#include <cstdlib>
21#include <string>
22
23using namespace yarp::os::impl;
24using namespace yarp::os;
25
26namespace {
27YARP_OS_LOG_COMPONENT(PROTOCOL, "yarp.os.impl.Protocol")
28} // namespace
29
31 messageLen(0),
32 pendingAck(false),
33 active(true),
34 delegate(nullptr),
35 recv_delegate(nullptr),
36 send_delegate(nullptr),
37 need_recv_delegate(false),
38 need_send_delegate(false),
39 recv_delegate_fail(false),
40 send_delegate_fail(false),
41 route("null", "null", "tcp"),
42 writer(nullptr),
43 ref(nullptr),
44 envelope(""),
45 port(nullptr),
46 pendingReply(false)
47{
48 // We start off with the streams used to contact the port that
49 // owns this connection.
50 shift.takeStream(stream);
51
52 reader.setProtocol(this);
53 yCDebug(PROTOCOL, "Remote contact = %s", reader.getRemoteContact().toURI().c_str());
54}
55
56
58{
59 closeHelper();
60}
61
62
63void Protocol::setRoute(const Route& route)
64{
65 Route r = route;
66
67 // We reorganize the route to reduce variation in naming.
68 // If there are qualifiers in the source port name, propagate
69 // those qualifiers to the carrier.
70 std::string from = r.getFromName();
71 std::string carrier = r.getCarrierName();
72 if (from.find(' ') != std::string::npos) {
73 Bottle b(from);
74 if (b.size() > 1) {
75 r.setFromName(b.get(0).toString());
76 for (size_t i = 1; i < b.size(); i++) {
77 Value& v = b.get(i);
78 Bottle* lst = v.asList();
79 if (lst != nullptr) {
80 carrier.append("+").append(lst->get(0).toString()).append(".").append(lst->get(1).toString());
81 } else {
82 carrier.append("+").append(v.toString());
83 }
84 }
85 r.setCarrierName(carrier);
86 }
87 }
88
89 // Record canonicalized route.
90 this->route = r;
91
92 // Check if we have a receiver modifier.
93 if (recv_delegate == nullptr) {
95 if (b.check("recv")) {
96 need_recv_delegate = true;
97 }
98 }
99
100 // Check if we have a sender modifier.
101 if (send_delegate == nullptr) {
103 if (b.check("send")) {
104 need_send_delegate = true;
105 }
106 }
107}
108
109
111{
112 return route;
113}
114
115
117{
118 return shift;
119}
120
121
123{
124 shift.takeStream(streams);
125 if (streams != nullptr) {
126 active = true;
127 }
128}
129
130
132{
133 return shift.giveStream();
134}
135
136
138{
139 return shift.isOk();
140}
141
142
144{
145 this->ref = ref;
146}
147
148
150{
151 Route r = getRoute();
152 // We pull the sender name from the route.
153 std::string from = r.getFromName();
154 // But we need to add any qualifiers looking in the carrier
155 // name. Ideally, we wouldn't need to bundle that in with
156 // the sender name, but we do it for now in the name of
157 // backwards compatibility.
158
159 //This is an example string:
160 //fast_tcp+send.portmonitor+file.bottle_compression_zlib+type.dll
161 //will be splitted into:
162 //(fast_tcp) (send portmonitor) (file bottle_compression_zlib) (type dll)
163 std::string carrier = r.getCarrierName();
164 size_t start = carrier.find('+');
165 if (start != std::string::npos) {
166 from += " (";
167 for (size_t i = start + 1; i < (size_t)carrier.length(); i++) {
168 char ch = carrier[i];
169 if (ch == '+') {
170 from += ") (";
171 } else if (ch == '.') {
172 from += " ";
173 } else {
174 from += ch;
175 }
176 }
177 from += ")";
178 }
179 return from;
180}
181
182
183const std::string& Protocol::getEnvelope() const
184{
185 return envelope;
186}
187
188
190{
191 messageLen = len;
192}
193
194
196{
197 if (delegate == nullptr) {
198 return nullConnection;
199 }
200 return *delegate;
201}
202
203
205{
206 return port;
207}
208
209
210bool Protocol::open(const std::string& name)
211{
212 if (name.empty()) {
213 return false;
214 }
215 Route r = getRoute();
216 r.setToName(name);
217 setRoute(r);
218 // We are not the initiator of the connection, so we
219 // expect to receive a header (carrier-dependent).
220 bool ok = expectHeader();
221 if (!ok) {
222 return false;
223 }
224 // Respond to header (carrier-dependent).
225 return respondToHeader();
226}
227
228
229bool Protocol::open(const Route& route)
230{
231 setRoute(route);
232 setCarrier(route.getCarrierName());
233 if (delegate == nullptr) {
234 return false;
235 }
236 // We are the initiator of the connection, so we
237 // send a header (carrier-dependent).
238 bool ok = sendHeader();
239 if (!ok) {
240 return false;
241 }
242 // Expect a resonse to the header (carrier-dependent).
243 return expectReplyToHeader();
244}
245
246
248{
249 closeHelper();
250}
251
252
254{
255 if (!active) {
256 return;
257 }
258 if (pendingAck) {
259 // Don't neglect to send one last acknowledgement if needed.
260 sendAck();
261 }
262 // Break the input stream.
263 shift.interruptInputStream();
264 active = false;
265}
266
267
272
273
275{
276 return shift.getInputStream();
277}
278
279
280void Protocol::rename(const Route& route)
281{
282 setRoute(route);
283}
284
285
286bool Protocol::isOk() const
287{
288 return !(!checkStreams() || recv_delegate_fail || send_delegate_fail);
289}
290
291
293{
294 // End any current write.
295 writer.stopWrite();
296 // Skip if this connection is not active (e.g. when there are several
297 // logical mcast connections but only one write is actually needed).
298 if (!getConnection().isActive()) {
299 return false;
300 }
301 this->writer = &writer;
302 bool replied = false;
303 yCAssert(PROTOCOL, delegate != nullptr);
304 getStreams().beginPacket(); // Message begins.
305 bool ok = delegate->write(*this, writer);
306 getStreams().endPacket(); // Message ends.
307 PortReader* reply = writer.getReplyHandler();
308 if (reply != nullptr) {
309 if (!delegate->supportReply()) {
310 // We are expected to get a reply, but cannot.
311 yCInfo(PROTOCOL, "connection %s does not support replies (try \"tcp\" or \"text_ack\")", getRoute().toString().c_str());
312 }
313 if (ok) {
314 // Read reply.
315 reader.reset(is(), &getStreams(), getRoute(), messageLen, delegate->isTextMode(), delegate->isBareMode());
316 replied = reply->read(reader);
317 }
318 }
319 expectAck(); // Expect acknowledgement (carrier-specific).
320 this->writer = nullptr;
321 return replied;
322}
323
324
326{
327 writer.stopWrite();
328 delegate->reply(*this, writer);
329 pendingReply = false;
330}
331
332
334{
335 return *this;
336}
337
338
340{
341 return *this;
342}
343
344
346{
347 // We take care of reading the message index
348 // (carrier-specific preamble), then leave it
349 // up to caller to read the actual message payload.
350 getRecvDelegate();
351 if (delegate != nullptr) {
352 bool ok = false;
353 while (!ok) {
354 ok = expectIndex();
355 if (!ok) {
356 if (!is().isOk()) {
357 // Go ahead, we'll be shutting down, it'll
358 // work out.
359 ok = true;
360 }
361 }
362 }
363 respondToIndex();
364 }
365 return reader;
366}
367
368
370{
371 reader.flushWriter();
372 sendAck(); // acknowledge after reply (if there is one)
373}
374
375
377{
378 reader.suppressReply();
379}
380
381
382bool Protocol::setTimeout(double timeout)
383{
384 bool ok = os().setWriteTimeout(timeout);
385 if (!ok) {
386 return false;
387 }
388 return is().setReadTimeout(timeout);
389}
390
391
392void Protocol::setEnvelope(const std::string& str)
393{
394 envelope = str;
395}
396
397
399{
400 if (recv_delegate == nullptr) {
401 return nullConnection;
402 }
403 return *recv_delegate;
404}
405
406
408{
409 this->port = port;
410}
411
412
414{
415 return pendingReply;
416}
417
418
420{
421 getSendDelegate();
422}
423
424
426{
427 if (send_delegate == nullptr) {
428 return nullConnection;
429 }
430 return *send_delegate;
431}
432
433
434bool Protocol::getRecvDelegate()
435{
436 // If we've already checked for a receiver modifier, return.
437 if (recv_delegate != nullptr) {
438 return true;
439 }
440 if (!need_recv_delegate) {
441 return true;
442 }
443 if (recv_delegate_fail) {
444 return false;
445 }
447 // Check for a "recv" qualifier.
448 std::string tag = b.find("recv").asString();
449 recv_delegate = Carriers::chooseCarrier(tag);
450 if (recv_delegate == nullptr) {
451 fprintf(stderr, "Need carrier \"%s\", but cannot find it.\n", tag.c_str());
452 recv_delegate_fail = true;
453 close();
454 return false;
455 }
456 if (!recv_delegate->modifiesIncomingData()) {
457 fprintf(stderr, "Carrier \"%s\" does not modify incoming data as expected.\n", tag.c_str());
458 recv_delegate_fail = true;
459 close();
460 return false;
461 }
462 // Configure the receiver modifier.
463 if (!recv_delegate->configure(*this)) {
464 fprintf(stderr, "Carrier \"%s\" could not configure the send delegate.\n", tag.c_str());
465 recv_delegate_fail = true;
466 close();
467 return false;
468 }
469 return true;
470}
471
472
473bool Protocol::getSendDelegate()
474{
475 // If we've already checked for a sender modifier, return.
476 if (send_delegate != nullptr) {
477 return true;
478 }
479 if (!need_send_delegate) {
480 return true;
481 }
482 if (send_delegate_fail) {
483 return false;
484 }
486 // Check for a "send" qualifier.
487 std::string tag = b.find("send").asString();
488 send_delegate = Carriers::chooseCarrier(tag);
489 if (send_delegate == nullptr) {
490 fprintf(stderr, "Need carrier \"%s\", but cannot find it.\n", tag.c_str());
491 send_delegate_fail = true;
492 close();
493 return false;
494 }
495 if (!send_delegate->modifiesOutgoingData()) {
496 fprintf(stderr, "Carrier \"%s\" does not modify outgoing data as expected.\n", tag.c_str());
497 send_delegate_fail = true;
498 close();
499 return false;
500 }
501 // Configure the sender modifier.
502 if (!send_delegate->configure(*this)) {
503 fprintf(stderr, "Carrier \"%s\" could not configure the send delegate.\n", tag.c_str());
504 send_delegate_fail = true;
505 close();
506 return false;
507 }
508 return true;
509}
510
511
512bool Protocol::respondToHeader()
513{
514 yCAssert(PROTOCOL, delegate != nullptr);
515 bool ok = delegate->respondToHeader(*this);
516 if (!ok) {
517 return false;
518 }
519 os().flush();
520 return os().isOk();
521}
522
523
524bool Protocol::expectAck()
525{
526 yCAssert(PROTOCOL, delegate != nullptr);
527 if (delegate->requireAck()) {
528 return delegate->expectAck(*this);
529 }
530 return true;
531}
532
533
534void Protocol::closeHelper()
535{
536 active = false;
537 if (pendingAck) {
538 sendAck();
539 }
540 shift.close();
541 if (delegate != nullptr) {
542 delegate->close();
543 delete delegate;
544 delegate = nullptr;
545 }
546 if (recv_delegate != nullptr) {
547 recv_delegate->close();
548 delete recv_delegate;
549 recv_delegate = nullptr;
550 }
551 if (send_delegate != nullptr) {
552 send_delegate->close();
553 delete send_delegate;
554 send_delegate = nullptr;
555 }
556}
557
558
559bool Protocol::sendAck()
560{
561 bool ok = true;
562 pendingAck = false;
563 if (delegate == nullptr) {
564 return false;
565 }
566 if (delegate->requireAck()) {
567 ok = delegate->sendAck(*this);
568 os().flush();
569 }
571 return ok;
572}
573
574
575bool Protocol::expectIndex()
576{
577 // We'll eventually need to send an acknowledgement
578 // (if the carrier in use requires that).
579 pendingAck = true;
580 messageLen = 0;
581 // This is where a message can be considered to begin.
582 // If things go wrong on an unreliable carrier (e.g. on
583 // udp), we should skip to the beginning of the next
584 // message, as marked by this call.
586 ref = nullptr;
587 bool ok = false;
588 if (delegate != nullptr) {
589 // What we actually do here is carrier-specific.
590 // Perhaps we do nothing at all.
591 ok = delegate->expectIndex(*this);
592 }
593 if (ok) {
594 // Set up a reader for the user payload.
595 reader.reset(is(), &getStreams(), getRoute(), messageLen, delegate->isTextMode(), delegate->isBareMode());
596 // Pass on a reference to the object being
597 // send, if we know it, for local connections.
598 if (ref != nullptr) {
599 reader.setReference(ref);
600 }
601 } else {
602 reader.reset(is(), &getStreams(), getRoute(), 0, false);
603 }
604 return ok;
605}
606
607
608void Protocol::setCarrier(const std::string& carrierNameBase)
609{
610 // Set up the carrier for this connection. The carrier
611 // has all the protocol-specific behavior.
612 std::string carrierName = carrierNameBase;
613 if (carrierNameBase.empty()) {
614 carrierName = "tcp";
615 }
616 Route route = getRoute();
617 route.setCarrierName(carrierName);
618 setRoute(route);
619 if (delegate == nullptr) {
620 delegate = Carriers::chooseCarrier(carrierName);
621 if (delegate != nullptr) {
622 if (delegate->modifiesIncomingData()) {
623 if (active) {
624 fprintf(stderr, "Carrier \"%s\" cannot be used this way, try \"tcp+recv.%s\" instead.\n", carrierName.c_str(), carrierName.c_str());
625 }
626 close();
627 return;
628 }
629 // Configure the carrier.
630 if (!delegate->configure(*this)) {
631 fprintf(stderr, "Carrier \"%s\" could not be configured.\n", carrierName.c_str());
632 close();
633 return;
634 }
635 delegate->prepareSend(*this);
636 }
637 }
638}
639
640
641bool Protocol::expectHeader()
642{
643 // A header, for historic reasons, is seen as
644 // a protocol fingerprint (at least 8 bytes)
645 // and the name of the sender. In practice,
646 // these callbacks have been stretched to the
647 // point where their names have little bearing
648 // on what the get used for.
649 messageLen = 0;
650 bool ok = expectProtocolSpecifier();
651 if (!ok) {
652 return false;
653 }
654 ok = expectSenderSpecifier();
655 if (!ok) {
656 return false;
657 }
658 yCAssert(PROTOCOL, delegate != nullptr);
659 ok = delegate->expectExtraHeader(*this);
660 return ok;
661}
662
663
664bool Protocol::expectProtocolSpecifier()
665{
666 // Historically YARP has used the first 8 bytes of
667 // every connection as a way to identify it. This
668 // assumption is showing its age, and should really
669 // be generalized.
670 char buf[8];
671 yarp::os::Bytes header((char*)&buf[0], sizeof(buf));
672 yarp::conf::ssize_t len = is().readFull(header);
673 if (len == -1) {
674 yCDebug(PROTOCOL, "no connection");
675 return false;
676 }
677 if ((size_t)len != header.length()) {
678 yCDebug(PROTOCOL, "data stream died");
679 return false;
680 }
681 bool already = false;
682 if (delegate != nullptr) {
683 if (delegate->checkHeader(header)) {
684 already = true;
685 }
686 }
687 if (!already) {
688 delegate = Carriers::chooseCarrier(header);
689 if (delegate == nullptr) {
690 // Carrier not found; send a human-readable message.
691 std::string msg = "* Error. Protocol not found.\r\n* Hello. You appear to be trying to communicate with a YARP Port.\r\n* The first 8 bytes sent to a YARP Port are critical for identifying the\r\n* protocol you wish to speak.\r\n* The first 8 bytes you sent were not associated with any particular protocol.\r\n* If you are a human, try typing \"CONNECT foo\" followed by a <RETURN>.\r\n* The 8 bytes \"CONNECT \" correspond to a simple text-mode protocol.\r\n* Goodbye.\r\n";
692 yarp::os::Bytes b((char*)msg.c_str(), msg.length());
693 os().write(b);
694 os().flush();
695 }
696 }
697 if (delegate == nullptr) {
698 yCDebug(PROTOCOL, "unrecognized protocol");
699 return false;
700 }
701 Route r = getRoute();
702 r.setCarrierName(delegate->getName());
703 setRoute(r);
704 delegate->setParameters(header);
705 return true;
706}
707
708
709bool Protocol::expectSenderSpecifier()
710{
711 yCAssert(PROTOCOL, delegate != nullptr);
712 return delegate->expectSenderSpecifier(*this);
713}
714
715
716bool Protocol::sendHeader()
717{
718 yCAssert(PROTOCOL, delegate != nullptr);
719 return delegate->sendHeader(*this);
720}
721
722
723bool Protocol::expectReplyToHeader()
724{
725 yCAssert(PROTOCOL, delegate != nullptr);
726 return delegate->expectReplyToHeader(*this);
727}
728
729
730bool Protocol::respondToIndex()
731{
732 return true;
733}
std::string toString(const T &value)
convert an arbitrary type to string.
size_t size_t
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:65
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:257
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:252
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition Bottle.cpp:283
A mini-server for performing network communication in the background.
T * read(bool shouldWait=true) override
Read an available object from the port.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
bool supportReply() const override=0
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
virtual bool write(ConnectionState &proto, SizedWriter &writer)=0
Write a message.
virtual bool configure(ConnectionState &proto)
Give carrier a shot at looking at how the connection is set up.
Definition Carrier.cpp:109
virtual bool respondToHeader(ConnectionState &proto)=0
Respond to the header.
bool requireAck() const override=0
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
bool isTextMode() const override=0
Check if carrier is textual in nature.
virtual bool expectSenderSpecifier(ConnectionState &proto)=0
Expect the name of the sending port.
virtual bool sendHeader(ConnectionState &proto)=0
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
virtual void close()
Close the carrier.
Definition Carrier.cpp:91
virtual void setParameters(const Bytes &header)=0
Configure this carrier based on the first 8 bytes of the connection.
virtual bool expectExtraHeader(ConnectionState &proto)=0
Receive any carrier-specific header.
virtual bool expectIndex(ConnectionState &proto)=0
Expect a message header, if there is one for this carrier.
virtual bool expectAck(ConnectionState &proto)=0
Receive an acknowledgement, if expected for this carrier.
bool modifiesIncomingData() const override
Check if this carrier modifies incoming data through the Carrier::modifyIncomingData method.
Definition Carrier.cpp:53
virtual bool checkHeader(const Bytes &header)=0
Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for...
virtual bool reply(ConnectionState &proto, SizedWriter &writer)
Definition Carrier.cpp:28
virtual bool expectReplyToHeader(ConnectionState &proto)=0
Process reply to header, if one is expected for this carrier.
virtual bool prepareSend(ConnectionState &proto)=0
Perform any initialization needed before writing on a connection.
virtual bool sendAck(ConnectionState &proto)=0
Send an acknowledgement, if needed for this carrier.
bool modifiesOutgoingData() const override
Check if this carrier modifies outgoing data through the Carrier::modifyOutgoingData method.
Definition Carrier.cpp:71
static Carrier * chooseCarrier(const std::string &name)
Select a carrier by name.
Definition Carriers.cpp:233
An interface for reading from a network connection.
OutputStream & os()
Shorthand for getOutputStream()
InputStream & is()
Shorthand for getInputStream()
A controller for an individual connection.
Definition Connection.h:26
virtual bool isBareMode() const
Check if carrier excludes type information from payload.
virtual std::string getName() const =0
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
std::string toURI(bool includeCarrier=true) const
Get a representation of the Contact as a URI.
Definition Contact.cpp:313
An abstract port.
Definition Contactable.h:28
The input side of an active connection between two ports.
Simple specification of the minimum functions needed from input streams.
Definition InputStream.h:25
yarp::conf::ssize_t readFull(Bytes &b)
Keep reading until buffer is full.
virtual bool setReadTimeout(double timeout)
Set activity timeout.
The output side of an active connection between two ports.
Simple specification of the minimum functions needed from output streams.
virtual void flush()
Make sure all pending write operations are finished.
virtual bool setWriteTimeout(double timeout)
Set activity timeout.
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.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
Information about a connection between two ports.
Definition Route.h:28
const std::string & getCarrierName() const
Get the carrier type of the route.
Definition Route.cpp:123
void setToName(const std::string &toName)
Set the destination of the route.
Definition Route.cpp:108
const std::string & getFromName() const
Get the source of the route.
Definition Route.cpp:93
void setFromName(const std::string &fromName)
Set the source of the route.
Definition Route.cpp:98
void setCarrierName(const std::string &carrierName)
Set the carrier type of the route.
Definition Route.cpp:128
virtual void takeStream(TwoWayStream *stream)
Wrap the supplied stream.
bool isOk() const override
Check if the stream is ok or in an error state.
virtual TwoWayStream * giveStream()
Removes the wrapped stream and returns it.
InputStream & getInputStream() override
Get an InputStream to read from.
void close() override
Terminate the stream.
OutputStream & getOutputStream() override
Get an OutputStream to write to.
Minimal requirements for an efficient Writer.
Definition SizedWriter.h:32
virtual void stopWrite() const =0
Call when all writing is finished.
virtual PortReader * getReplyHandler()=0
A stream which can be asked to perform bidirectional communication.
virtual void endPacket()=0
Mark the end of a logical packet (see beginPacket).
virtual void beginPacket()=0
Mark the beginning of a logical packet.
A single value (typically within a Bottle).
Definition Value.h:44
virtual Bottle * asList() const
Get list value.
Definition Value.cpp:252
std::string toString() const override
Return a standard text representation of the content of the object.
Definition Value.cpp:368
yarp::os::ConnectionReader & beginRead() override
Begin a read operation, with bytes read via the returned yarp::os::ConnectionReader object.
Definition Protocol.cpp:345
std::string getSenderSpecifier() const override
Extract a name for the sender, if the connection type supports that.
Definition Protocol.cpp:149
bool isOk() const override
Check if the connection is valid and can be used.
Definition Protocol.cpp:286
OutputStream & getOutputStream() override
Access the output stream associated with the connection.
Definition Protocol.cpp:268
TwoWayStream * giveStreams() override
Take ownership of the streams associated with the connection.
Definition Protocol.cpp:131
void attachPort(yarp::os::Contactable *port) override
Set the port to be associated with the connection.
Definition Protocol.cpp:407
void endRead() override
End the current read operation, begin by beginRead().
Definition Protocol.cpp:369
bool setTimeout(double timeout) override
Set the timeout to be used for network operations.
Definition Protocol.cpp:382
Contactable * getContactable() const override
Get the port associated with the connection.
Definition Protocol.cpp:204
void rename(const Route &route) override
Relabel the route after the fact (e.g.
Definition Protocol.cpp:280
bool open(const std::string &name) override
Start negotiating a carrier, using the given name as our own if a name is needed (this should general...
Definition Protocol.cpp:210
void suppressReply() override
Make sure that any attempt to send a reply to input will be denied.
Definition Protocol.cpp:376
bool checkStreams() const override
Check whether streams are in a good state.
Definition Protocol.cpp:137
Connection & getReceiver() override
It is possible to chain a basic connection with a modifier.
Definition Protocol.cpp:398
bool isReplying() const override
Definition Protocol.cpp:413
const std::string & getEnvelope() const override
Read the envelope associated with the current message.
Definition Protocol.cpp:183
void beginWrite() override
Notify connection that we intend to write to it.
Definition Protocol.cpp:419
TwoWayStream & getStreams() override
Access the streams associated with the connection.
Definition Protocol.cpp:116
~Protocol() override
Destructor.
Definition Protocol.cpp:57
void setEnvelope(const std::string &str) override
Set the envelope that will be attached to the next message.
Definition Protocol.cpp:392
bool write(SizedWriter &writer) override
Write a message on the connection.
Definition Protocol.cpp:292
void takeStreams(TwoWayStream *streams) override
Provide streams to be used with the connection.
Definition Protocol.cpp:122
void interrupt() override
Definition Protocol.cpp:253
InputStream & getInputStream() override
Access the input stream associated with the connection.
Definition Protocol.cpp:274
void setReference(yarp::os::Portable *ref) override
Give a direct pointer to an object being sent on the connection.
Definition Protocol.cpp:143
void setRemainingLength(int len) override
Tell the connection that the given number of bytes are left to be read.
Definition Protocol.cpp:189
Connection & getConnection() override
Get the connection whose protocol operations we are managing.
Definition Protocol.cpp:195
OutputProtocol & getOutput() override
Get an interface for doing write operations on the connection.
Definition Protocol.cpp:333
void close() override
Negotiate an end to operations.
Definition Protocol.cpp:247
Connection & getSender() override
It is possible to chain a basic connection with a modifier.
Definition Protocol.cpp:425
void reply(SizedWriter &writer) override
Reply to a message we have just read.
Definition Protocol.cpp:325
InputProtocol & getInput() override
Get an interface for doing read operations on the connection.
Definition Protocol.cpp:339
Protocol(TwoWayStream *stream)
Constructor.
Definition Protocol.cpp:30
const Route & getRoute() const override
Definition Protocol.cpp:110
void setRoute(const Route &route) override
Set the route associated with this connection.
Definition Protocol.cpp:63
yarp::os::Contact getRemoteContact() const override
Gets information about who is supplying the data being read, if that information is available.
void reset(yarp::os::InputStream &in, TwoWayStream *str, const Route &route, size_t len, bool textMode, bool bareMode=false)
virtual void setReference(yarp::os::Portable *obj)
#define yCInfo(component,...)
#define yCAssert(component, x)
#define yCDebug(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
::ssize_t ssize_t
Definition numeric.h:87
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
Definition OSTestMsg.cpp:13