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