YARP
Yet Another Robot Platform
HumanCarrier.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 
7 #include <yarp/os/ManagedBytes.h>
8 #include "HumanCarrier.h"
9 
11  // Send the "magic number" for this carrier
12  ManagedBytes header(8);
13  getHeader(header.bytes());
14  proto.os().write(header.bytes());
15  if (!proto.os().isOk()) {
16  return false;
17  }
18 
19  // Now we can do whatever we want, as long as somehow
20  // we also send the name of the originating port
21 
22  // let's just send the port name in plain text terminated with a
23  // carriage-return / line-feed
24  std::string from = proto.getRoute().getFromName();
25  Bytes b2((char*)from.c_str(),from.length());
26  proto.os().write(b2);
27  proto.os().write('\r');
28  proto.os().write('\n');
29  proto.os().flush();
30  return proto.os().isOk();
31 }
void getHeader(Bytes &header) const override
Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to se...
Definition: HumanCarrier.h:62
bool sendHeader(ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
A simple abstraction for a block of bytes.
Definition: Bytes.h:25
The basic state of a connection - route, streams in use, etc.
virtual const Route & getRoute() const =0
Get the route associated with this connection.
OutputStream & os()
Shorthand for getOutputStream()
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
Definition: ManagedBytes.h:22
const Bytes & bytes() const
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.
const std::string & getFromName() const
Get the source of the route.
Definition: Route.cpp:93