YARP
Yet Another Robot Platform
Subscriber.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_SUBSCRIBER_H
8 #define YARP_SERVERSQL_IMPL_SUBSCRIBER_H
9 
10 #include <yarp/name/NameService.h>
12 
13 #include <string>
14 #include <yarp/os/Vocab.h>
15 #include <yarp/os/NameStore.h>
16 #include <yarp/os/NameSpace.h>
17 
18 
19 namespace yarp {
20 namespace serversql {
21 namespace impl {
22 
26 class Subscriber :
28 {
29 public:
31  store(nullptr),
32  delegate(nullptr)
33  {
34  }
35 
37  {
38  this->store = &store;
39  }
40 
42  {
43  return store;
44  }
45 
46  void clear()
47  {
48  manager.clear();
49  }
50 
51  void connect(const std::string& src,
52  const std::string& dest)
53  {
54  manager.connect(src,dest);
55  }
56 
57  void disconnect(const std::string& src,
58  const std::string& dest,
59  bool srcDrop)
60  {
61  manager.disconnect(src,dest,srcDrop);
62  }
63 
64  virtual bool addSubscription(const std::string& src,
65  const std::string& dest,
66  const std::string& mode) = 0;
67 
68  virtual bool removeSubscription(const std::string& src,
69  const std::string& dest) = 0;
70 
71  virtual bool listSubscriptions(const std::string& src,
72  yarp::os::Bottle& reply) = 0;
73 
74  virtual bool welcome(const std::string& port, int activity) = 0;
75 
76  virtual bool setTopic(const std::string& port,
77  const std::string& structure, bool active) = 0;
78 
79  virtual bool listTopics(yarp::os::Bottle& topics) = 0;
80 
81  virtual bool setType(const std::string& family,
82  const std::string& structure,
83  const std::string& value) = 0;
84 
85  virtual std::string getType(const std::string& family,
86  const std::string& structure) = 0;
87 
88  bool apply(yarp::os::Bottle& cmd,
89  yarp::os::Bottle& reply,
90  yarp::os::Bottle& event,
91  const yarp::os::Contact& remote) override;
92 
93  void onEvent(yarp::os::Bottle& event) override
94  {
95  }
96 
97  int replyCode(bool flag)
98  {
99  return flag ? yarp::os::createVocab32('o', 'k')
100  : yarp::os::createVocab32('f', 'a', 'i', 'l');
101  }
102 
104  {
105  this->delegate = delegate;
106  }
107 
109  {
110  return delegate;
111  }
112 
113 private:
114  yarp::os::NameStore *store;
115  ConnectManager manager;
116  yarp::os::NameSpace *delegate;
117 };
118 
119 } // namespace impl
120 } // namespace serversql
121 } // namespace yarp
122 
123 
124 #endif // YARP_SERVERSQL_IMPL_SUBSCRIBER_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
Abstract interface for a database of port names.
Definition: NameStore.h:20
void connect(const std::string &src, const std::string &dest, bool positive=true)
void disconnect(const std::string &src, const std::string &dest, bool srcDrop)
Abstract interface for maintaining persistent connections.
Definition: Subscriber.h:28
void setDelegate(yarp::os::NameSpace *delegate)
Definition: Subscriber.h:103
void disconnect(const std::string &src, const std::string &dest, bool srcDrop)
Definition: Subscriber.h:57
void onEvent(yarp::os::Bottle &event) override
Definition: Subscriber.h:93
void setStore(yarp::os::NameStore &store)
Definition: Subscriber.h:36
virtual bool listTopics(yarp::os::Bottle &topics)=0
bool apply(yarp::os::Bottle &cmd, yarp::os::Bottle &reply, yarp::os::Bottle &event, const yarp::os::Contact &remote) override
Definition: Subscriber.cpp:17
virtual bool listSubscriptions(const std::string &src, yarp::os::Bottle &reply)=0
virtual bool setTopic(const std::string &port, const std::string &structure, bool active)=0
virtual bool removeSubscription(const std::string &src, const std::string &dest)=0
virtual bool addSubscription(const std::string &src, const std::string &dest, const std::string &mode)=0
yarp::os::NameStore * getStore()
Definition: Subscriber.h:41
virtual std::string getType(const std::string &family, const std::string &structure)=0
virtual bool welcome(const std::string &port, int activity)=0
yarp::os::NameSpace * getDelegate()
Definition: Subscriber.h:108
virtual bool setType(const std::string &family, const std::string &structure, const std::string &value)=0
void connect(const std::string &src, const std::string &dest)
Definition: Subscriber.h:51
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
Definition: Vocab.h:28
The main, catch-all namespace for YARP.
Definition: dirs.h:16