YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
17using namespace yarp::os::impl;
18using namespace yarp::os;
19
20namespace {
21YARP_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{
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) {
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}
A mini-server for performing network communication in the background.
Represents how to reach a part of a YARP network.
Definition Contact.h:33
std::string readLine(const char terminal='\n', bool *success=nullptr)
Read a block of text terminated with a specific marker (or EOF).
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:1961
virtual void writeLine(const char *data, int len)
Write some text followed by a line feed.
A stream abstraction for datagram communication.
void interrupt() override
Interrupt the stream.
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.
virtual std::string apply(const std::string &txt, const Contact &remote)=0
#define yCDebug(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.