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