YARP
Yet Another Robot Platform
FallbackNameServer.cpp
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 
11 
12 #include <yarp/conf/system.h>
13 
14 #include <yarp/os/Bytes.h>
15 #include <yarp/os/NetType.h>
19 
20 using namespace yarp::os::impl;
21 using namespace yarp::os;
22 
23 namespace {
24 YARP_OS_LOG_COMPONENT(FALLBACKNAMESERVER, "yarp.os.impl.FallbackNameServer")
25 } // namespace
26 
27 
29 {
30  return Contact("fallback",
31  "mcast",
32  "224.2.1.1",
34 }
35 
36 
38 {
39  DgramTwoWayStream send;
40  send.join(getAddress(), true);
41  listen.join(getAddress(), false);
42 
43  yCDebug(FALLBACKNAMESERVER, "Fallback server running");
44  while (listen.isOk() && send.isOk() && !closed) {
45  yCDebug(FALLBACKNAMESERVER, "Fallback server waiting");
46  std::string msg;
47  listen.beginPacket();
48  msg = listen.readLine();
49  listen.endPacket();
50  yCDebug(FALLBACKNAMESERVER, "Fallback server got something");
51  if (listen.isOk() && !closed) {
52  yCDebug(FALLBACKNAMESERVER, "Fallback server got %s", msg.c_str());
53  if (msg.find("NAME_SERVER ") == 0) {
54  Contact addr;
55  std::string result = owner.apply(msg, addr);
56  send.beginPacket();
57  send.writeLine(result.c_str(), (int)result.length());
58  send.flush();
59  send.endPacket();
60  }
61  }
62  }
63 }
64 
65 
67 {
68  closed = true;
69  listen.interrupt();
70 }
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
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:2005
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:112
#define YARP_OS_LOG_COMPONENT(name, name_string)
Definition: LogComponent.h:37
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.