YARP
Yet Another Robot Platform
MpiStream.cpp
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 #include "MpiStream.h"
8 
9 #include <yarp/os/Log.h>
10 
11 #include <utility>
12 
13 using namespace yarp::os;
14 
15 
16 /* --------------------------------------- */
17 /* MpiStream */
18 
19 MpiStream::MpiStream(std::string n, MpiComm* c)
20  : terminate(false), name(std::move(n)), comm(c) {
21  readBuffer = nullptr;
22  resetBuffer();
23 
24 }
25 
27  yCTrace(MPI_CARRIER, "[MpiStream @ %s] Destructor", name.c_str());
28 }
29 
31  // reset buffer
32  readAt = 0;
33  readAvail = 0;
34  delete [] readBuffer;
35  readBuffer = nullptr;
36 }
37 
38 bool MpiStream::isOk() const {
39  return !terminate;
40 }
41 
43  yCDebug(MPI_CARRIER, "[MpiStream @ %s] Trying to interrupt", name.c_str());
44  terminate = true;
45 }
46 
47 /* --------------------------------------- */
48 /* TwoWayStream */
49 
51  return *this;
52 }
54  return *this;
55 }
57  // left undefined
58  return local;
59 }
61  // left undefined
62  return remote;
63 }
65  // nothing to do
66 }
68  // nothing to do
69 }
const yarp::os::LogComponent & MPI_CARRIER()
Wrapper for MPI_Comm communicator.
Definition: MpiComm.h:50
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
OutputStream & getOutputStream() override
Get an OutputStream to write to.
Definition: MpiStream.cpp:53
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
bool terminate
Definition: MpiStream.h:33
yarp::os::Contact local
Definition: MpiStream.h:37
void resetBuffer()
Definition: MpiStream.cpp:30
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
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
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:22
#define yCTrace(component,...)
Definition: LogComponent.h:85
#define yCDebug(component,...)
Definition: LogComponent.h:109
An interface to the operating system, including Port based communication.