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