YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
LocalCarrier.h
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#ifndef YARP_OS_IMPL_LOCALCARRIER_H
8#define YARP_OS_IMPL_LOCALCARRIER_H
9
11#include <yarp/os/InputStream.h>
13#include <yarp/os/Portable.h>
14#include <yarp/os/Semaphore.h>
16
17#include <mutex>
18
19namespace yarp::os::impl {
20
21class LocalCarrier;
22
27{
28public:
30
31 void setSender(LocalCarrier* sender);
34 void revoke(LocalCarrier* carrier);
35
36private:
37 std::mutex senderMutex;
38 std::mutex receiverMutex;
39 yarp::os::Semaphore received;
40 LocalCarrier *sender, *receiver;
41};
42
43
48 public TwoWayStream,
49 public InputStream,
50 public OutputStream
51{
52public:
53 void attach(LocalCarrier* owner, bool sender);
54
55 InputStream& getInputStream() override;
56 OutputStream& getOutputStream() override;
57 const Contact& getLocalAddress() const override;
58 const Contact& getRemoteAddress() const override;
59 bool setTypeOfService(int tos) override;
60
63
65 void write(const yarp::os::Bytes& b) override;
66
67 void reset() override;
68 void beginPacket() override;
69 void endPacket() override;
70 void interrupt() override;
71 void close() override;
72 bool isOk() const override;
73
74private:
75 Contact localAddress, remoteAddress;
76 LocalCarrier* owner;
77 bool sender;
78 bool done;
79};
80
85 public AbstractCarrier
86{
87public:
89
90 virtual ~LocalCarrier();
91
92 Carrier* create() const override;
93
94 std::string getName() const override;
95
96 bool requireAck() const override;
97 bool isConnectionless() const override;
98 bool canEscape() const override;
99 bool isLocal() const override;
100 virtual std::string getSpecifierName() const;
101 bool checkHeader(const Bytes& header) override;
102 void getHeader(Bytes& header) const override;
103 void setParameters(const Bytes& header) override;
104 bool sendHeader(ConnectionState& proto) override;
105 bool expectExtraHeader(ConnectionState& proto) override;
106 virtual bool becomeLocal(ConnectionState& proto, bool sender);
107 bool write(ConnectionState& proto, SizedWriter& writer) override;
108 bool respondToHeader(ConnectionState& proto) override;
109 bool expectReplyToHeader(ConnectionState& proto) override;
110 bool expectIndex(ConnectionState& proto) override;
111
112 void removePeer();
113 void shutdown();
115
116protected:
117 bool doomed;
120 std::mutex peerMutex;
123 std::string portName;
124
126};
127
128} // namespace yarp::os::impl
129
130#endif // YARP_OS_IMPL_LOCALCARRIER_H
A starter class for implementing simple carriers.
A mini-server for performing network communication in the background.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition Carrier.h:44
The basic state of a connection - route, streams in use, etc.
Represents how to reach a part of a YARP network.
Definition Contact.h:33
Simple specification of the minimum functions needed from input streams.
Definition InputStream.h:25
virtual int read()
Read and return a single byte.
Simple specification of the minimum functions needed from output streams.
virtual void write(char ch)
Write a single byte to the stream.
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
A class for thread synchronization and mutual exclusion.
Definition Semaphore.h:25
Minimal requirements for an efficient Writer.
Definition SizedWriter.h:32
A stream which can be asked to perform bidirectional communication.
Coordinate ports communicating locally within a process.
void setSender(LocalCarrier *sender)
void revoke(LocalCarrier *carrier)
LocalCarrier * getSender(LocalCarrier *receiver)
A stream for communicating locally within a process.
bool isOk() const override
Check if the stream is ok or in an error state.
void interrupt() override
Interrupt the stream.
InputStream & getInputStream() override
Get an InputStream to read from.
const Contact & getLocalAddress() const override
Get the address of the local side of the stream.
OutputStream & getOutputStream() override
Get an OutputStream to write to.
void close() override
Terminate the stream.
void beginPacket() override
Mark the beginning of a logical packet.
void write(const yarp::os::Bytes &b) override
Write a block of bytes to the stream.
void attach(LocalCarrier *owner, bool sender)
void endPacket() override
Mark the end of a logical packet (see beginPacket).
bool setTypeOfService(int tos) override
const Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
void reset() override
Reset the stream.
A carrier for communicating locally within a process.
bool sendHeader(ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
static LocalCarrierManager manager
bool write(ConnectionState &proto, SizedWriter &writer) override
Write a message.
yarp::os::Semaphore received
void accept(yarp::os::Portable *ref)
bool expectReplyToHeader(ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
bool expectExtraHeader(ConnectionState &proto) override
Receive any carrier-specific header.
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
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...
yarp::os::Portable * ref
bool canEscape() const override
Check if carrier can encode administrative messages, as opposed to just user data.
void setParameters(const Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
Carrier * create() const override
Factory method.
virtual bool becomeLocal(ConnectionState &proto, bool sender)
virtual std::string getSpecifierName() const
bool expectIndex(ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
void getHeader(Bytes &header) const override
Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to se...
yarp::os::Semaphore sent
bool isLocal() const override
Check if carrier operates within a single process.
bool respondToHeader(ConnectionState &proto) override
Respond to the header.
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
::ssize_t ssize_t
Definition numeric.h:86
The components from which ports and connections are built.