YARP
Yet Another Robot Platform
ComposedNameService.h
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
7#ifndef YARP_SERVERSQL_IMPL_COMPOSEDNAMESERVICE_H
8#define YARP_SERVERSQL_IMPL_COMPOSEDNAMESERVICE_H
9
10#include <yarp/os/Bottle.h>
11#include <yarp/os/Contact.h>
13
14
15namespace yarp::serversql::impl {
16
21{
22public:
24 {
25 ns1 = nullptr;
26 ns2 = nullptr;
27 }
28
29 void open(NameService& ns1,NameService& ns2)
30 {
31 this->ns1 = &ns1;
32 this->ns2 = &ns2;
33 }
34
36 yarp::os::Bottle& reply,
37 yarp::os::Bottle& event,
38 const yarp::os::Contact& remote) override
39 {
40 if (ns1->apply(cmd,reply,event,remote)) {
41 return true;
42 }
43 return ns2->apply(cmd,reply,event,remote);
44 }
45
46 void onEvent(yarp::os::Bottle& event) override
47 {
48 ns1->onEvent(event);
49 ns2->onEvent(event);
50 }
51
52 void goPublic() override
53 {
54 ns1->goPublic();
55 ns2->goPublic();
56 }
57
58 yarp::os::Contact query(const std::string& name) override
59 {
60 yarp::os::Contact result;
61 result = ns1->query(name);
62 if (!result.isValid()) {
63 result = ns2->query(name);
64 }
65 return result;
66 }
67
68 bool announce(const std::string& name, int activity) override
69 {
70 if (ns2->announce(name,activity)) {
71 return true;
72 }
73 return ns1->announce(name,activity);
74 }
75
76private:
77 NameService *ns1;
78 NameService *ns2;
79};
80
81} // namespace yarp::serversql::impl
82
83#endif // YARP_SERVERSQL_IMPL_COMPOSEDNAMESERVICE_H
Abstract interface for a name server operator.
Definition: NameService.h:24
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:64
Represents how to reach a part of a YARP network.
Definition: Contact.h:33
bool isValid() const
Checks if a Contact is tagged as valid.
Definition: Contact.cpp:298
Compose two name services into one.
bool announce(const std::string &name, int activity) override
void open(NameService &ns1, NameService &ns2)
void onEvent(yarp::os::Bottle &event) override
yarp::os::Contact query(const std::string &name) override
bool apply(yarp::os::Bottle &cmd, yarp::os::Bottle &reply, yarp::os::Bottle &event, const yarp::os::Contact &remote) override