YARP
Yet Another Robot Platform
MpiStream.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_MPISTREAM_H
8 #define YARP_MPISTREAM_H
9 
10 #include <yarp/os/TwoWayStream.h>
11 #include <string>
12 #include <yarp/os/Bytes.h>
13 #include <yarp/os/ManagedBytes.h>
14 #include <yarp/os/NetType.h>
15 
16 #include "MpiComm.h"
17 
18 #include <string>
19 #include <iostream>
20 
21 
25 class MpiStream :
27  public yarp::os::InputStream,
29 {
30 protected:
32  char* readBuffer;
33  bool terminate;
34  std::string name;
36 
39 public:
40  MpiStream(std::string name, MpiComm* comm);
41  virtual ~MpiStream();
42 
45 
46  void close() override = 0;
47  bool isOk() const override;
48  void interrupt() override;
49  ssize_t read(yarp::os::Bytes& b) override = 0;
50  void write(const yarp::os::Bytes& b) override = 0;
51  InputStream& getInputStream() override;
52  OutputStream& getOutputStream() override;
53  const yarp::os::Contact& getLocalAddress() const override;
54  const yarp::os::Contact& getRemoteAddress() const override;
55  void resetBuffer();
56  void reset() override { resetBuffer();}
57  void beginPacket() override;
58  void endPacket() override;
59 };
60 
61 
62 #endif // YARP_MPISTREAM_H
Wrapper for MPI_Comm communicator.
Definition: MpiComm.h:50
Abstract base class for port communication via MPI.
Definition: MpiStream.h:29
InputStream & getInputStream() override
Get an InputStream to read from.
Definition: MpiStream.cpp:50
void interrupt() override
Interrupt the stream.
Definition: MpiStream.cpp:42
bool isOk() const override
Check if the stream is ok or in an error state.
Definition: MpiStream.cpp:38
const yarp::os::Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
Definition: MpiStream.cpp:60
void beginPacket() override
Mark the beginning of a logical packet.
Definition: MpiStream.cpp:64
void close() override=0
Terminate the stream.
OutputStream & getOutputStream() override
Get an OutputStream to write to.
Definition: MpiStream.cpp:53
MpiComm * comm
Definition: MpiStream.h:35
int readAvail
Definition: MpiStream.h:31
char * readBuffer
Definition: MpiStream.h:32
virtual ~MpiStream()
Definition: MpiStream.cpp:26
const yarp::os::Contact & getLocalAddress() const override
Get the address of the local side of the stream.
Definition: MpiStream.cpp:56
MpiStream(std::string name, MpiComm *comm)
Definition: MpiStream.cpp:19
std::string name
Definition: MpiStream.h:34
ssize_t read(yarp::os::Bytes &b) override=0
Read a block of data from the stream.
bool terminate
Definition: MpiStream.h:33
yarp::os::Contact local
Definition: MpiStream.h:37
void write(const yarp::os::Bytes &b) override=0
Write a block of bytes to the stream.
void resetBuffer()
Definition: MpiStream.cpp:30
void reset() override
Reset the stream.
Definition: MpiStream.h:56
yarp::os::Contact remote
Definition: MpiStream.h:38
void endPacket() override
Mark the end of a logical packet (see beginPacket).
Definition: MpiStream.cpp:67
int readAt
Definition: MpiStream.h:31
A simple abstraction for a block of bytes.
Definition: Bytes.h:25
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:26
virtual int read()
Read and return a single byte.
Definition: InputStream.cpp:20
InputStream()
Constructor.
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:22
virtual void write(char ch)
Write a single byte to the stream.
A stream which can be asked to perform bidirectional communication.
Definition: TwoWayStream.h:26
::ssize_t ssize_t
Definition: numeric.h:86