YARP
Yet Another Robot Platform
MpiBcastCarrier.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_MPIBCASTCARRIER_H
11 #define YARP_MPIBCASTCARRIER_H
12 
13 #include "MpiCarrier.h"
14 #include "MpiBcastStream.h"
15 
16 #include <yarp/os/Election.h>
17 
18 
30  public MpiCarrier
31 {
32 private:
35 
36  bool electionMember;
37 
38 public:
39  MpiBcastCarrier() : MpiCarrier(), electionMember(false) {
40  target = "MPIBCAST";
41  }
42 
43  virtual ~MpiBcastCarrier();
44 
45  void close() override;
46 
47  Carrier *create() const override {
48  return new MpiBcastCarrier();
49  }
50 
51  void createStream(bool sender) override;
52 
53  std::string getName() const override {
54  return "bcast";
55  }
56 
57  bool supportReply() const override {
58  return false;
59  }
60 
61  bool isBroadcast() const override {
62  return true;
63  }
64 
65  void prepareDisconnect() override;
66 
68  bool ok = MpiCarrier::expectReplyToHeader(proto);
69  MpiBcastStream *mpiStream = dynamic_cast<MpiBcastStream*> (stream);
70  if(mpiStream)
71  mpiStream->post();
72  return ok;
73  }
74 
75  bool isActive() const override;
76 
77  virtual bool isElect() const;
78 };
79 
80 #endif // YARP_MPIBCASTCARRIER_H
MpiBcastCarrier::isBroadcast
bool isBroadcast() const override
Check if this carrier uses a broadcast mechanism.
Definition: MpiBcastCarrier.h:61
MpiBcastStream
Implements communication via MPI broadcast.
Definition: MpiBcastStream.h:25
MpiBcastCarrier::getName
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: MpiBcastCarrier.h:53
MpiBcastCarrier::close
void close() override
Close the carrier.
Definition: MpiBcastCarrier.cpp:21
MpiBcastCarrier::prepareDisconnect
void prepareDisconnect() override
Do cleanup and preparation for the coming disconnect, if necessary.
Definition: MpiBcastCarrier.cpp:56
MpiBcastCarrier
Carrier for port communicating via MPI broadcast.
Definition: MpiBcastCarrier.h:31
MpiCarrier::stream
MpiStream * stream
Definition: MpiCarrier.h:31
MpiBcastCarrier::isActive
bool isActive() const override
Check if carrier is alive and error free.
Definition: MpiBcastCarrier.cpp:100
MpiCarrier::target
std::string target
Definition: MpiCarrier.h:35
MpiBcastStream::post
void post()
Definition: MpiBcastStream.h:38
MpiCarrier.h
MpiCarrier
Abstract base carrier for managing port communication via MPI.
Definition: MpiCarrier.h:29
MpiBcastCarrier::expectReplyToHeader
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
Definition: MpiBcastCarrier.h:67
MpiBcastCarrier::isElect
virtual bool isElect() const
Definition: MpiBcastCarrier.cpp:95
yarp::os::ElectionOf
Pick one of a set of peers to be "active".
Definition: Election.h:64
yarp::os::ConnectionState
The basic state of a connection - route, streams in use, etc.
Definition: ConnectionState.h:31
MpiBcastCarrier::~MpiBcastCarrier
virtual ~MpiBcastCarrier()
Definition: MpiBcastCarrier.cpp:17
Election.h
MpiBcastCarrier::supportReply
bool supportReply() const override
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
Definition: MpiBcastCarrier.h:57
MpiBcastCarrier::MpiBcastCarrier
MpiBcastCarrier()
Definition: MpiBcastCarrier.h:39
MpiCarrier::expectReplyToHeader
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
Definition: MpiCarrier.cpp:135
MpiBcastCarrier::create
Carrier * create() const override
Factory method.
Definition: MpiBcastCarrier.h:47
MpiBcastStream.h
MpiBcastCarrier::createStream
void createStream(bool sender) override
Definition: MpiBcastCarrier.cpp:34