YARP
Yet Another Robot Platform
FallbackNameServer.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
8 
9 #include <yarp/conf/system.h>
10 
11 #include <yarp/os/Bytes.h>
12 #include <yarp/os/NetType.h>
16 
17 using namespace yarp::os::impl;
18 using namespace yarp::os;
19 
20 namespace {
21 YARP_OS_LOG_COMPONENT(FALLBACKNAMESERVER, "yarp.os.impl.FallbackNameServer")
22 } // namespace
23 
24 
26 {
27  return Contact("fallback",
28  "mcast",
29  "224.2.1.1",
31 }
32 
33 
35 {
36  DgramTwoWayStream send;
37  send.join(getAddress(), true);
38  listen.join(getAddress(), false);
39 
40  yCDebug(FALLBACKNAMESERVER, "Fallback server running");
41  while (listen.isOk() && send.isOk() && !closed) {
42  yCDebug(FALLBACKNAMESERVER, "Fallback server waiting");
43  std::string msg;
44  listen.beginPacket();
45  msg = listen.readLine();
46  listen.endPacket();
47  yCDebug(FALLBACKNAMESERVER, "Fallback server got something");
48  if (listen.isOk() && !closed) {
49  yCDebug(FALLBACKNAMESERVER, "Fallback server got %s", msg.c_str());
50  if (msg.find("NAME_SERVER ") == 0) {
51  Contact addr;
52  std::string result = owner.apply(msg, addr);
53  send.beginPacket();
54  send.writeLine(result.c_str(), (int)result.length());
55  send.flush();
56  send.endPacket();
57  }
58  }
59  }
60 }
61 
62 
64 {
65  closed = true;
66  listen.interrupt();
67 }
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
static int getDefaultPortRange()
Under normal operation, YARP has a name server that manages a pool of (socket) ports starting at a po...
Definition: Network.cpp:2002
virtual void writeLine(const char *data, int len)
Write some text followed by a line feed.
A stream abstraction for datagram communication.
void endPacket() override
Mark the end of a logical packet (see beginPacket).
virtual bool join(const Contact &group, bool sender, const Contact &ipLocal)
void beginPacket() override
Mark the beginning of a logical packet.
void flush() override
Make sure all pending write operations are finished.
bool isOk() const override
Check if the stream is ok or in an error state.
#define yCDebug(component,...)
Definition: LogComponent.h:109
#define YARP_OS_LOG_COMPONENT(name, name_string)
Definition: LogComponent.h:35
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.