YARP
Yet Another Robot Platform
NameserCarrier.h
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 #ifndef YARP_OS_IMPL_NAMESERCARRIER_H
11 #define YARP_OS_IMPL_NAMESERCARRIER_H
12 
13 #include <yarp/os/TwoWayStream.h>
15 
16 
17 namespace yarp {
18 namespace os {
19 namespace impl {
20 
27  public TwoWayStream,
29 {
30 private:
31  TwoWayStream* delegate;
32  std::string pendingRead;
33  std::string swallowRead;
34 
35 public:
37 
38  virtual ~NameserTwoWayStream();
39 
40  InputStream& getInputStream() override;
41  OutputStream& getOutputStream() override;
42  const Contact& getLocalAddress() const override;
43  const Contact& getRemoteAddress() const override;
44 
45  bool isOk() const override;
46  void reset() override;
47  void close() override;
48  void beginPacket() override;
49  void endPacket() override;
50 
53 };
54 
55 
62  public TcpCarrier
63 {
64 private:
65  bool firstSend;
66 
67 public:
69 
70  std::string getName() const override;
71  std::string getSpecifierName() const;
72 
73  Carrier* create() const override;
74 
75  bool checkHeader(const Bytes& header) override;
76  void getHeader(Bytes& header) const override;
77  bool requireAck() const override;
78  bool isTextMode() const override;
79  bool supportReply() const override;
80  bool canEscape() const override;
81  bool sendHeader(ConnectionState& proto) override;
82  bool expectSenderSpecifier(ConnectionState& proto) override;
83  bool expectIndex(ConnectionState& proto) override;
84  bool sendAck(ConnectionState& proto) override;
85  bool expectAck(ConnectionState& proto) override;
86  bool respondToHeader(ConnectionState& proto) override;
87  bool expectReplyToHeader(ConnectionState& proto) override;
88  bool write(ConnectionState& proto, SizedWriter& writer) override;
89 };
90 
91 } // namespace impl
92 } // namespace os
93 } // namespace yarp
94 
95 #endif // YARP_OS_IMPL_NAMESERCARRIER_H
yarp::os::TwoWayStream
A stream which can be asked to perform bidirectional communication.
Definition: TwoWayStream.h:29
yarp::os::Carrier
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition: Carrier.h:48
yarp::os::impl::NameserCarrier::isTextMode
bool isTextMode() const override
Check if carrier is textual in nature.
Definition: NameserCarrier.cpp:163
yarp::os::impl::NameserCarrier::sendHeader
bool sendHeader(ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
Definition: NameserCarrier.cpp:178
TcpCarrier.h
yarp::os::impl::NameserCarrier::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: NameserCarrier.cpp:147
yarp::os::impl::NameserTwoWayStream::endPacket
void endPacket() override
Mark the end of a logical packet (see beginPacket).
Definition: NameserCarrier.cpp:76
yarp::os::OutputStream
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:25
yarp::os::impl::NameserCarrier::create
Carrier * create() const override
Factory method.
Definition: NameserCarrier.cpp:128
yarp::os::impl::NameserTwoWayStream::getRemoteAddress
const Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
Definition: NameserCarrier.cpp:51
yarp::os::impl::NameserCarrier::canEscape
bool canEscape() const override
Check if carrier can encode administrative messages, as opposed to just user data.
Definition: NameserCarrier.cpp:173
TwoWayStream.h
yarp::os::impl::NameserCarrier::expectReplyToHeader
bool expectReplyToHeader(ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
Definition: NameserCarrier.cpp:221
yarp::os::impl::NameserTwoWayStream
Communicating between two ports via a variant plain-text protocol originally designed for the yarp na...
Definition: NameserCarrier.h:29
yarp::os::impl::NameserTwoWayStream::~NameserTwoWayStream
virtual ~NameserTwoWayStream()
Definition: NameserCarrier.cpp:28
yarp::os::impl::NameserCarrier::supportReply
bool supportReply() const override
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
Definition: NameserCarrier.cpp:168
yarp::os::impl::NameserCarrier::expectSenderSpecifier
bool expectSenderSpecifier(ConnectionState &proto) override
Expect the name of the sending port.
Definition: NameserCarrier.cpp:187
yarp::os::impl::NameserCarrier::getSpecifierName
std::string getSpecifierName() const
Definition: NameserCarrier.cpp:123
yarp::os::impl::NameserTwoWayStream::getLocalAddress
const Contact & getLocalAddress() const override
Get the address of the local side of the stream.
Definition: NameserCarrier.cpp:46
yarp::os::impl::NameserCarrier::getName
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: NameserCarrier.cpp:118
yarp::os::impl::NameserCarrier::sendAck
bool sendAck(ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
Definition: NameserCarrier.cpp:201
yarp::os::impl::NameserTwoWayStream::getOutputStream
OutputStream & getOutputStream() override
Get an OutputStream to write to.
Definition: NameserCarrier.cpp:41
yarp::os::impl::NameserTwoWayStream::close
void close() override
Terminate the stream.
Definition: NameserCarrier.cpp:66
yarp::conf::ssize_t
::ssize_t ssize_t
Definition: numeric.h:60
yarp::os::impl::TcpCarrier
Communicating between two ports via TCP.
Definition: TcpCarrier.h:24
yarp::os::impl::NameserCarrier::write
bool write(ConnectionState &proto, SizedWriter &writer) override
Write a message.
Definition: NameserCarrier.cpp:228
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
yarp::os::impl::NameserCarrier::respondToHeader
bool respondToHeader(ConnectionState &proto) override
Respond to the header.
Definition: NameserCarrier.cpp:213
yarp::os::impl::NameserCarrier::expectAck
bool expectAck(ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
Definition: NameserCarrier.cpp:207
yarp::os::ConnectionState
The basic state of a connection - route, streams in use, etc.
Definition: ConnectionState.h:31
yarp::os::impl::NameserTwoWayStream::isOk
bool isOk() const override
Check if the stream is ok or in an error state.
Definition: NameserCarrier.cpp:56
yarp::os::InputStream::read
virtual int read()
Read and return a single byte.
Definition: InputStream.cpp:23
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::impl::NameserCarrier
Communicating between two ports via a variant plain-text protocol originally designed for the yarp na...
Definition: NameserCarrier.h:63
yarp::os::impl::NameserCarrier::expectIndex
bool expectIndex(ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
Definition: NameserCarrier.cpp:195
yarp::os::Contact
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
yarp::os::impl::NameserTwoWayStream::getInputStream
InputStream & getInputStream() override
Get an InputStream to read from.
Definition: NameserCarrier.cpp:36
yarp::os::impl::NameserTwoWayStream::reset
void reset() override
Reset the stream.
Definition: NameserCarrier.cpp:61
yarp::os::impl::NameserCarrier::NameserCarrier
NameserCarrier()
Definition: NameserCarrier.cpp:113
yarp::os::InputStream
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:29
yarp::os::impl::NameserTwoWayStream::beginPacket
void beginPacket() override
Mark the beginning of a logical packet.
Definition: NameserCarrier.cpp:71
yarp::os::impl::NameserTwoWayStream::NameserTwoWayStream
NameserTwoWayStream(TwoWayStream *delegate)
Definition: NameserCarrier.cpp:21
yarp::os::SizedWriter
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:36
yarp::os::impl::NameserCarrier::checkHeader
bool checkHeader(const Bytes &header) override
Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for...
Definition: NameserCarrier.cpp:133
yarp::os::impl::NameserCarrier::requireAck
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
Definition: NameserCarrier.cpp:158