YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
MpiCarrier.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2010 Daniel Krieg <krieg@fias.uni-frankfurt.de>
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef YARP_MPICARRIER_H
8#define YARP_MPICARRIER_H
9
11#include <yarp/os/Bytes.h>
13#include <yarp/os/SizedWriter.h>
14
15#include <string>
16#include <iostream>
17
18#include "MpiStream.h"
19
20
26{
27protected:
30 std::string port;
31 std::string name, other, route;
32 std::string target;
33public:
34 MpiCarrier() ;
35 virtual ~MpiCarrier();
36 void close() override = 0;
37 Carrier *create() const override = 0;
38 std::string getName() const override = 0;
39
40 virtual void createStream(bool sender) = 0;
41
42 bool isConnectionless() const override {
43 return false;
44 }
45
46 bool canEscape() const override {
47 return true;
48 }
49
50 bool supportReply() const override = 0;
51
52
53 void getHeader(yarp::os::Bytes& header) const override;
54 bool checkHeader(const yarp::os::Bytes& header) override;
55
56
57 bool sendHeader(yarp::os::ConnectionState& proto) override;
59
60 bool respondToHeader(yarp::os::ConnectionState& proto) override;
62
63
65 // Payload time!
66
67 bool write(yarp::os::ConnectionState& proto, yarp::os::SizedWriter& writer) override {
68 writer.write(proto.os());
69 return proto.os().isOk();
70 }
71
73 return true;
74 }
75
76 bool expectIndex(yarp::os::ConnectionState& proto) override {
77 return true;
78 }
79
81 // Acknowledgements, we don't do them
82
83 bool sendAck(yarp::os::ConnectionState& proto) override {
84 return true;
85 }
86
87 bool expectAck(yarp::os::ConnectionState& proto) override {
88 return true;
89 }
90
91};
92
93#endif // YARP_MPICARRIER_H
Abstract base carrier for managing port communication via MPI.
Definition MpiCarrier.h:26
void close() override=0
Close the carrier.
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 expectIndex(yarp::os::ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
Definition MpiCarrier.h:76
Carrier * create() const override=0
Factory method.
bool sendHeader(yarp::os::ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
std::string target
Definition MpiCarrier.h:32
bool sendIndex(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
Definition MpiCarrier.h:72
std::string port
Definition MpiCarrier.h:30
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
Definition MpiCarrier.h:42
bool expectSenderSpecifier(yarp::os::ConnectionState &proto) override
Expect the name of the sending port.
MpiStream * stream
Definition MpiCarrier.h:28
virtual void createStream(bool sender)=0
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
bool expectAck(yarp::os::ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
Definition MpiCarrier.h:87
std::string getName() const override=0
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
virtual ~MpiCarrier()
MpiComm * comm
Definition MpiCarrier.h:29
bool sendAck(yarp::os::ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
Definition MpiCarrier.h:83
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 respondToHeader(yarp::os::ConnectionState &proto) override
Respond to the header.
bool write(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
Write a message.
Definition MpiCarrier.h:67
std::string name
Definition MpiCarrier.h:31
bool supportReply() const override=0
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
std::string route
Definition MpiCarrier.h:31
bool canEscape() const override
Check if carrier can encode administrative messages, as opposed to just user data.
Definition MpiCarrier.h:46
std::string other
Definition MpiCarrier.h:31
Wrapper for MPI_Comm communicator.
Definition MpiComm.h:50
Abstract base class for port communication via MPI.
Definition MpiStream.h:29
A starter class for implementing simple carriers.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
The basic state of a connection - route, streams in use, etc.
OutputStream & os()
Shorthand for getOutputStream()
virtual bool isOk() const =0
Check if the stream is ok or in an error state.
Minimal requirements for an efficient Writer.
Definition SizedWriter.h:32
virtual void write(OutputStream &os)