YARP
Yet Another Robot Platform
MpiBcastStream.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_MPIBCASTSTREAM_H
11 #define YARP_MPIBCASTSTREAM_H
12 
13 #include "MpiStream.h"
14 
15 #include <cstring>
16 
17 #define CMD_JOIN -1
18 #define CMD_DISCONNECT -2
19 
24  public MpiStream
25 {
26 public:
29  yCTrace(MPI_CARRIER, "[MpiBcastStream @ %s] Destructor", name.c_str());
30  }
31 
32  using MpiStream::write;
33  using MpiStream::read;
34 
35  ssize_t read(yarp::os::Bytes& b) override;
36  void write(const yarp::os::Bytes& b) override;
37  void startJoin();
38  void post() {
39  comm->sema.post();
40  }
41  void close() override {
42  yCDebug(MPI_CARRIER, "[MpiBcastStream @ %s] Closing stream", name.c_str());
43  }
44  void execCmd(int cmd);
45 };
46 
47 
48 #endif // YARP_MPIBCASTSTREAM_H
const yarp::os::LogComponent & MPI_CARRIER()
Implements communication via MPI broadcast.
void close() override
Terminate the stream.
ssize_t read(yarp::os::Bytes &b) override=0
Read and return a single byte.
void write(const yarp::os::Bytes &b) override=0
void execCmd(int cmd)
MpiBcastStream(std::string name, MpiComm *comm)
Wrapper for MPI_Comm communicator.
Definition: MpiComm.h:53
yarp::os::Semaphore sema
Definition: MpiComm.h:60
Abstract base class for port communication via MPI.
Definition: MpiStream.h:32
MpiComm * comm
Definition: MpiStream.h:38
std::string name
Definition: MpiStream.h:37
void write(const yarp::os::Bytes &b) override=0
Write a block of bytes to the stream.
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
virtual int read()
Read and return a single byte.
Definition: InputStream.cpp:23
void post()
Increment the counter.
Definition: Semaphore.cpp:114
#define yCTrace(component,...)
Definition: LogComponent.h:88
#define yCDebug(component,...)
Definition: LogComponent.h:112
::ssize_t ssize_t
Definition: numeric.h:60