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