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
yarp::os::TwoWayStream
A stream which can be asked to perform bidirectional communication.
Definition: TwoWayStream.h:29
MpiStream::endPacket
void endPacket() override
Mark the end of a logical packet (see beginPacket).
Definition: MpiStream.cpp:70
yarp::os::OutputStream::write
virtual void write(char ch)
Write a single byte to the stream.
Definition: OutputStream.cpp:17
MpiStream::comm
MpiComm * comm
Definition: MpiStream.h:38
yarp::os::OutputStream
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:25
MpiStream::getRemoteAddress
const yarp::os::Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
Definition: MpiStream.cpp:63
yarp::os::InputStream::InputStream
InputStream()
Constructor.
MpiStream::~MpiStream
virtual ~MpiStream()
Definition: MpiStream.cpp:29
MpiStream::terminate
bool terminate
Definition: MpiStream.h:36
MpiStream::readAt
int readAt
Definition: MpiStream.h:34
MpiStream::readAvail
int readAvail
Definition: MpiStream.h:34
MpiStream::resetBuffer
void resetBuffer()
Definition: MpiStream.cpp:33
MpiStream::local
yarp::os::Contact local
Definition: MpiStream.h:40
TwoWayStream.h
NetType.h
MpiStream::write
void write(const yarp::os::Bytes &b) override=0
Write a block of bytes to the stream.
MpiStream::reset
void reset() override
Reset the stream.
Definition: MpiStream.h:59
ManagedBytes.h
MpiStream::MpiStream
MpiStream(std::string name, MpiComm *comm)
Definition: MpiStream.cpp:22
MpiStream::getLocalAddress
const yarp::os::Contact & getLocalAddress() const override
Get the address of the local side of the stream.
Definition: MpiStream.cpp:59
MpiComm.h
yarp::conf::ssize_t
::ssize_t ssize_t
Definition: numeric.h:60
MpiStream::getInputStream
InputStream & getInputStream() override
Get an InputStream to read from.
Definition: MpiStream.cpp:53
MpiStream::beginPacket
void beginPacket() override
Mark the beginning of a logical packet.
Definition: MpiStream.cpp:67
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
MpiStream::readBuffer
char * readBuffer
Definition: MpiStream.h:35
MpiStream::isOk
bool isOk() const override
Check if the stream is ok or in an error state.
Definition: MpiStream.cpp:41
MpiStream::interrupt
void interrupt() override
Interrupt the stream.
Definition: MpiStream.cpp:45
MpiStream::name
std::string name
Definition: MpiStream.h:37
yarp::os::InputStream::read
virtual int read()
Read and return a single byte.
Definition: InputStream.cpp:23
Bytes.h
MpiStream::getOutputStream
OutputStream & getOutputStream() override
Get an OutputStream to write to.
Definition: MpiStream.cpp:56
yarp::os::Contact
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
MpiComm
Wrapper for MPI_Comm communicator.
Definition: MpiComm.h:53
yarp::os::InputStream
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:29
MpiStream::remote
yarp::os::Contact remote
Definition: MpiStream.h:41
MpiStream::close
void close() override=0
Terminate the stream.
MpiStream
Abstract base class for port communication via MPI.
Definition: MpiStream.h:32