YARP
Yet Another Robot Platform
NameServiceOnTriples.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_NAMESERVICEONTRIPLES_H
8 #define YARP_SERVERSQL_IMPL_NAMESERVICEONTRIPLES_H
9 
10 #include <yarp/name/NameService.h>
14 #include <yarp/os/NameStore.h>
15 #include <yarp/os/Semaphore.h>
16 
17 #include <mutex>
18 
19 namespace yarp {
20 namespace serversql {
21 namespace impl {
22 
27 {
28 public:
34  bool bottleMode;
35  bool nestedMode;
36 
41  TripleSource& mem) :
42  cmd(cmd),
43  reply(reply),
44  event(event),
45  remote(remote),
46  mem(mem),
47  bottleMode(false),
48  nestedMode(false)
49  {
50  }
51 };
52 
57 {
58 private:
59  TripleSource *db;
60  Allocator *alloc;
61  Subscriber *subscriber;
62  std::string lastRegister;
63  yarp::os::Contact serverContact;
64  std::mutex mutex;
65  yarp::os::Semaphore access;
66  bool gonePublic;
67  bool silent;
68  yarp::os::NameSpace *delegate;
69 public:
71  db(nullptr),
72  alloc(nullptr),
73  subscriber(nullptr),
74  lastRegister(""),
75  mutex(),
76  access(1),
77  gonePublic(false),
78  silent(false),
79  delegate(nullptr)
80  {
81  }
82 
83  void open(TripleSource *db,
84  Allocator *alloc,
85  const yarp::os::Contact& serverContact)
86  {
87  this->db = db;
88  this->alloc = alloc;
89  this->serverContact = serverContact;
90  }
91 
92  void setSubscriber(Subscriber *subscriber)
93  {
94  this->subscriber = subscriber;
95  }
96 
97  void setSilent(bool flag)
98  {
99  this->silent = flag;
100  }
101 
102  yarp::os::Contact query(const std::string& portName,
103  NameTripleState& act,
104  const std::string& prefix,
105  bool nested = false);
106 
107  bool announce(const std::string& name, int activity) override;
108 
109  yarp::os::Contact query(const std::string& portName) override;
110 
111  bool cmdQuery(NameTripleState& act, bool nested = false);
112 
113  bool cmdRegister(NameTripleState& act);
114 
115  bool cmdUnregister(NameTripleState& act);
116 
117  bool cmdList(NameTripleState& act);
118 
119  bool cmdListRunners(NameTripleState& act);
120 
121  bool cmdSet(NameTripleState& act);
122 
123  bool cmdGet(NameTripleState& act);
124 
125  bool cmdCheck(NameTripleState& act);
126 
127  bool cmdRoute(NameTripleState& act);
128 
129  bool cmdGc(NameTripleState& act);
130 
131  bool cmdHelp(NameTripleState& act);
132 
133  bool apply(yarp::os::Bottle& cmd,
134  yarp::os::Bottle& reply,
135  yarp::os::Bottle& event,
136  const yarp::os::Contact& remote) override;
137 
138  void goPublic() override
139  {
140  gonePublic = true;
141  }
142 
143  void lock() override;
144 
145  void unlock() override;
146 
148  {
149  this->delegate = delegate;
150  }
151 
153  {
154  return delegate;
155  }
156 };
157 
158 } // namespace impl
159 } // namespace serversql
160 } // namespace yarp
161 
162 
163 #endif // YARP_SERVERSQL_IMPL_NAMESERVICEONTRIPLES_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
An abstract name space for ports.
Definition: NameSpace.h:23
A class for thread synchronization and mutual exclusion.
Definition: Semaphore.h:26
Abstract interface for allocating network resources.
Definition: Allocator.h:39
An implementation of name service operators on a triple store.
bool cmdQuery(NameTripleState &act, bool nested=false)
void setDelegate(yarp::os::NameSpace *delegate)
void open(TripleSource *db, Allocator *alloc, const yarp::os::Contact &serverContact)
bool apply(yarp::os::Bottle &cmd, yarp::os::Bottle &reply, yarp::os::Bottle &event, const yarp::os::Contact &remote) override
bool announce(const std::string &name, int activity) override
yarp::os::Contact query(const std::string &portName, NameTripleState &act, const std::string &prefix, bool nested=false)
State information for a single name server operation on a database.
NameTripleState(yarp::os::Bottle &cmd, yarp::os::Bottle &reply, yarp::os::Bottle &event, const yarp::os::Contact &remote, TripleSource &mem)
Abstract interface for maintaining persistent connections.
Definition: Subscriber.h:28
Abstract view of a database as a collection of triples.
Definition: TripleSource.h:41
The main, catch-all namespace for YARP.
Definition: dirs.h:16