|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
30 std::string getYARPRuntimeDir()
33 std::lock_guard<std::mutex> lock(m);
35 static std::string yarp_runtime_dir;
39 if (!yarp_runtime_dir.empty()) {
40 return yarp_runtime_dir;
46 return yarp_runtime_dir;
53 return yarp_runtime_dir;
60 return yarp_runtime_dir;
79 "The ports are on different machines, unix socket not supported...");
99 return requireAckFlag;
109 if (header.
length() != headerSize) {
114 bool isUnix_ack =
true;
116 const char* target = headerCode;
117 const char* target_ack = headerCode_ack;
118 for (
size_t i = 0; i < headerSize; i++) {
119 if (header.
get()[i] != target[i]) {
122 if (header.
get()[i] != target_ack[i]) {
127 return (isUnix || isUnix_ack);
132 const char* target = requireAckFlag ? headerCode_ack : headerCode;
133 for (
size_t i = 0; i < headerSize && i < header.
length(); i++) {
134 header.
get()[i] = target[i];
155 if (requireAckFlag) {
156 const Bytes ack_bytes(
const_cast<char*
>(ack_string), ack_string_size);
164 if (requireAckFlag) {
165 std::array<char, ack_string_size> buf;
166 Bytes ack(buf.data(), buf.size());
168 if (
static_cast<size_t>(hdr) != ack.
length()) {
173 const char* target = ack_string;
174 for (
size_t i = 0; i < ack_string_size; i++) {
175 if (ack.
get()[i] != target[i]) {
187 return becomeUnixSocket(proto,
false);
193 return becomeUnixSocket(proto,
true);
196 bool UnixSocketCarrier::becomeUnixSocket(
ConnectionState& proto,
bool sender)
198 if (!isUnixSockSupported(proto)) {
207 std::string runtime_dir = getYARPRuntimeDir();
222 stream->setLocalAddress(local);
223 stream->setRemoteAddress(remote);
225 if (!stream->open(sender)) {
228 yCError(
UNIXSOCK_CARRIER,
"Failed to open stream on socket %s as %s", socketPath.c_str(), (sender ?
"sender" :
"receiver"));
235 yCDebug(
UNIXSOCK_CARRIER,
"Connected on socket %s as %s", socketPath.c_str(), (sender ?
"sender" :
"receiver"));
244 return configureFromProperty(options);
249 if (options.
check(
"ack")) {
251 requireAckFlag =
true;
258 const char* target_ack = headerCode_ack;
259 for (
size_t i = 0; i < headerSize; i++) {
260 if (header.
get()[i] != target_ack[i]) {
265 requireAckFlag =
true;
virtual const Contact & getLocalAddress() const =0
Get the address of the local side of the stream.
Communicating between two ports(IPC) via Unix Socket.
void getHeader(yarp::os::Bytes &header) const override
Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to se...
bool expectAck(yarp::os::ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
bool checkHeader(const yarp::os::Bytes &header) override
Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for...
bool expectIndex(yarp::os::ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
virtual void write(char ch)
Write a single byte to the stream.
std::string getEnvironment(const char *key, bool *found=nullptr)
Read a variable from the environment.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
yarp::os::Carrier * create() const override
Factory method.
bool configure(yarp::os::ConnectionState &proto) override
Give carrier a shot at looking at how the connection is set up.
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
virtual void takeStreams(TwoWayStream *streams)=0
Provide streams to be used with the connection.
OutputStream & os()
Shorthand for getOutputStream()
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
virtual const Contact & getRemoteAddress() const =0
Get the address of the remote side of the stream.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
virtual TwoWayStream & getStreams()=0
Access the streams associated with the connection.
A simple abstraction for a block of bytes.
int mkdir_p(const char *p, int ignoreLevels=0)
Create a directory and all parent directories needed.
The basic state of a connection - route, streams in use, etc.
#define yCError(component,...)
virtual std::string getSenderSpecifier() const =0
Extract a name for the sender, if the connection type supports that.
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
bool sendAck(yarp::os::ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
InputStream & is()
Shorthand for getInputStream()
const yarp::os::LogComponent & UNIXSOCK_CARRIER()
static constexpr value_type preferred_separator
bool sendIndex(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
A stream abstraction for unix socket communication.
bool configureFromProperty(yarp::os::Property &options) override
bool respondToHeader(yarp::os::ConnectionState &proto) override
Respond to the header.
Minimal requirements for an efficient Writer.
A class for storing options and configuration information.
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)