|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
33 if (caster ==
nullptr) {
36 if (caster ==
nullptr) {
37 yCError(MCASTCARRIER,
"No memory for McastCarrier::caster");
56 bool elect = isElect();
60 if (peer ==
nullptr) {
65 yCError(MCASTCARRIER,
"Something went wrong during the shift of the election...");
91 bool ok = defaultSendHeader(proto);
96 yCDebug(MCASTCARRIER,
"Adding extra mcast header");
103 if (elect !=
nullptr) {
104 yCDebug(MCASTCARRIER,
"picking up peer mcast name");
110 Contact target(
"...",
"mcast",
"...", 0);
121 int ip[] = {224, 3, 1, 1};
125 if (ss.
size() != 4) {
129 for (
int i = 0; i < 4; i++) {
137 yCError(MCASTCARRIER,
"Name server not responding helpfully, setting mcast name arbitrarily.");
138 yCError(MCASTCARRIER,
"Only a single mcast address supported in this mode.");
139 addr =
Contact(
"/tmp/mcast",
"mcast",
"224.3.1.1", 11000);
143 for (
int i = 0; i < 4; i++) {
144 ((
unsigned char*)block.
get())[i] = (
unsigned char)ip[i];
146 block.
get()[5] = (char)(port % 256);
147 block.
get()[4] = (char)(port / 256);
155 yCDebug(MCASTCARRIER,
"Expecting extra mcast header");
158 if ((
size_t)len != block.
length()) {
159 yCError(MCASTCARRIER,
"problem with MCAST header");
163 int ip[] = {0, 0, 0, 0};
166 auto* base = (
unsigned char*)block.
get();
168 for (
int i = 0; i < 4; i++) {
174 sprintf(buf,
"%d", ip[i]);
177 port = 256 * base[4] + base[5];
178 Contact addr(
"mcast", add, port);
179 yCDebug(MCASTCARRIER,
"got mcast header %s", addr.
toURI().c_str());
189 yCAssert(MCASTCARRIER, stream !=
nullptr);
206 key += local.getHost();
208 yCDebug(MCASTCARRIER,
"multicast key: %s", key.c_str());
213 if (isElect() || !sender) {
214 ok = stream->join(mcastAddress, sender, local);
227 return becomeMcast(proto,
false);
233 return becomeMcast(proto,
true);
238 getCaster().add(key,
this);
243 getCaster().remove(key,
this);
248 void* elect = getCaster().getElect(key);
250 return elect ==
this || elect ==
nullptr;
255 if (stream !=
nullptr) {
256 return stream->join(mcastAddress,
true, local);
virtual const Contact & getLocalAddress() const =0
Get the address of the local side of the stream.
static Contact registerContact(const Contact &contact)
Register contact information with the name server.
void removeSender(const std::string &key)
bool sendHeader(ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
static void lock()
Call wait() on a global mutual-exclusion semaphore allocated by YARP.
virtual void write(char ch)
Write a single byte to the stream.
Split a string into pieces.
static bool setProperty(const char *name, const char *key, const Value &value)
Names registered with the nameserver can have arbitrary key->value properties associated with them.
bool respondToHeader(ConnectionState &proto) override
Respond to the header.
bool isActive() const override
Check if carrier is alive and error free.
Carrier * create() const override
Factory method.
bool becomeMcast(ConnectionState &proto, bool sender)
int getSpecifierCode() const override
const Bytes & bytes() const
virtual void takeStreams(TwoWayStream *streams)=0
Provide streams to be used with the connection.
OutputStream & os()
Shorthand for getOutputStream()
virtual const Route & getRoute() const =0
Get the route associated with this connection.
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
void addSender(const std::string &key)
bool expectExtraHeader(ConnectionState &proto) override
Receive any carrier-specific header.
static ElectionOf< PeerRecord< McastCarrier > > * caster
static Contact unregisterName(const std::string &name)
Removes the registration for a name from the name server.
virtual const Contact & getRemoteAddress() const =0
Get the address of the remote side of the stream.
static ElectionOf< PeerRecord< McastCarrier > > & getCaster()
bool isBroadcast() const override
Check if this carrier uses a broadcast mechanism.
bool takeElection()
takeElection, this function is called when the elect mcast carrier dies and pass the write buffers to...
A stream abstraction for datagram communication.
virtual TwoWayStream & getStreams()=0
Access the streams associated with the connection.
#define yCAssert(component, x)
Pick one of a set of peers to be "active".
The basic state of a connection - route, streams in use, etc.
#define yCError(component,...)
bool expectReplyToHeader(ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
static void unlock()
Call post() on a global mutual-exclusion semaphore allocated by YARP.
Communicating between two ports via MCAST.
InputStream & is()
Shorthand for getInputStream()
A single value (typically within a Bottle).
const std::string & getFromName() const
Get the source of the route.
const char * get(int idx)
#define YARP_OS_LOG_COMPONENT(name, name_string)
The components from which ports and connections are built.
static int toInt(const std::string &x)