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