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