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>
12 #include <yarp/name/NameService.h>
13 
14 
15 namespace yarp {
16 namespace serversql {
17 namespace impl {
18 
23 {
24 public:
26  {
27  ns1 = nullptr;
28  ns2 = nullptr;
29  }
30 
31  void open(NameService& ns1,NameService& ns2)
32  {
33  this->ns1 = &ns1;
34  this->ns2 = &ns2;
35  }
36 
38  yarp::os::Bottle& reply,
39  yarp::os::Bottle& event,
40  const yarp::os::Contact& remote) override
41  {
42  if (ns1->apply(cmd,reply,event,remote)) {
43  return true;
44  }
45  return ns2->apply(cmd,reply,event,remote);
46  }
47 
48  void onEvent(yarp::os::Bottle& event) override
49  {
50  ns1->onEvent(event);
51  ns2->onEvent(event);
52  }
53 
54  void goPublic() override
55  {
56  ns1->goPublic();
57  ns2->goPublic();
58  }
59 
60  yarp::os::Contact query(const std::string& name) override
61  {
62  yarp::os::Contact result;
63  result = ns1->query(name);
64  if (!result.isValid()) {
65  result = ns2->query(name);
66  }
67  return result;
68  }
69 
70  bool announce(const std::string& name, int activity) override
71  {
72  if (ns2->announce(name,activity)) {
73  return true;
74  }
75  return ns1->announce(name,activity);
76  }
77 
78 private:
79  NameService *ns1;
80  NameService *ns2;
81 };
82 
83 } // namespace impl
84 } // namespace serversql
85 } // namespace yarp
86 
87 #endif // YARP_SERVERSQL_IMPL_COMPOSEDNAMESERVICE_H
Abstract interface for a name server operator.
Definition: NameService.h:36
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
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
The main, catch-all namespace for YARP.
Definition: dirs.h:16