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