YARP
Yet Another Robot Platform
McastCarrier.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
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_OS_IMPL_MCASTCARRIER_H
11 #define YARP_OS_IMPL_MCASTCARRIER_H
12 
14 #include <yarp/os/Election.h>
18 
19 #include <cstdio>
20 
21 namespace yarp {
22 namespace os {
23 namespace impl {
24 
28 class McastCarrier :
29  public UdpCarrier
30 {
31 protected:
33  std::string mcastName;
34  std::string key;
37 
39 
41 
42 public:
43  McastCarrier();
44 
45  virtual ~McastCarrier();
46 
47  Carrier* create() const override;
48  std::string getName() const override;
49 
50  int getSpecifierCode() const override;
51 
52  bool sendHeader(ConnectionState& proto) override;
53  bool expectExtraHeader(ConnectionState& proto) override;
54  bool respondToHeader(ConnectionState& proto) override;
55  bool expectReplyToHeader(ConnectionState& proto) override;
56 
57  bool becomeMcast(ConnectionState& proto, bool sender);
58  void addSender(const std::string& key);
59  void removeSender(const std::string& key);
60  bool isElect() const;
66  bool takeElection();
67 
68  bool isActive() const override;
69  bool isBroadcast() const override;
70 };
71 
72 } // namespace impl
73 } // namespace os
74 } // namespace yarp
75 
76 #endif // YARP_OS_IMPL_MCASTCARRIER_H
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition: Carrier.h:48
The basic state of a connection - route, streams in use, etc.
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
Pick one of a set of peers to be "active".
Definition: Election.h:64
A stream abstraction for datagram communication.
Communicating between two ports via MCAST.
Definition: McastCarrier.h:30
bool respondToHeader(ConnectionState &proto) override
Respond to the header.
bool expectExtraHeader(ConnectionState &proto) override
Receive any carrier-specific header.
bool expectReplyToHeader(ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
bool takeElection()
takeElection, this function is called when the elect mcast carrier dies and pass the write buffers to...
void addSender(const std::string &key)
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
void removeSender(const std::string &key)
Carrier * create() const override
Factory method.
static ElectionOf< PeerRecord< McastCarrier > > * caster
Definition: McastCarrier.h:38
bool becomeMcast(ConnectionState &proto, bool sender)
int getSpecifierCode() const override
bool isActive() const override
Check if carrier is alive and error free.
bool isBroadcast() const override
Check if this carrier uses a broadcast mechanism.
DgramTwoWayStream * stream
Definition: McastCarrier.h:35
bool sendHeader(ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
static ElectionOf< PeerRecord< McastCarrier > > & getCaster()
Communicating between two ports via UDP.
Definition: UdpCarrier.h:25
The main, catch-all namespace for YARP.
Definition: environment.h:18