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