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