PdCom  5.0
Process data communication client
Loading...
Searching...
No Matches
Subscription.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vim:tw=78
3 *
4 * Copyright (C) 2021 Richard Hacker (lerichi at gmx dot net),
5 * Florian Pose (fp at igh dot de),
6 * Bjarne von Horn (vh at igh dot de).
7 *
8 * This file is part of the PdCom library.
9 *
10 * The PdCom library is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or (at your
13 * option) any later version.
14 *
15 * The PdCom library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
22 *
23 *****************************************************************************/
24
27#ifndef PDCOM5_SUBSCRIPTION_H
28#define PDCOM5_SUBSCRIPTION_H
29
30#include "DataDeserializer.h"
31#include "Exception.h"
32#include "Selector.h"
33#include "Variable.h"
34#include "details.h"
35#include "pdcom5_export.h"
36
37#include <memory>
38#include <string>
39#include <vector>
40
41namespace PdCom {
42namespace impl {
43class Subscription;
44} // namespace impl
45
46class Process;
47class Variable;
48class Subscriber;
49
50
65class PDCOM5_PUBLIC Subscription : public DataDeserializer<Subscription>
66{
67 public:
68 enum class State {
69 Invalid = 0,
70 Pending,
71 Active,
72 };
73
75 Subscription() = default;
76 Subscription(Subscription &&) noexcept;
77 Subscription &operator=(Subscription &&) noexcept;
78
86 Subscriber &subscriber,
87 const Variable &variable,
88 const Selector &selector = {});
89
98 Subscriber &subscriber,
99 Process &process,
100 const std::string &path,
101 const Selector &selector = {});
102
107 void poll();
114 const void *getData() const;
115
122
128 void print(std::ostream &os, char delimiter) const;
129
133 bool empty() const noexcept { return !(pimpl); }
137 State getState() const noexcept { return state_; }
138
139 private:
140 friend impl::Subscription;
141
142 std::shared_ptr<impl::Subscription> pimpl = {};
143
144 State state_ = State::Invalid;
145};
146} // namespace PdCom
147
148
149#endif // PDCOM5_SUBSCRIPTION_H
Base class for PdCom protocol handler.
Definition: Process.h:84
Definition: Subscriber.h:102
PdCom Subscription interface.
Definition: Subscription.h:66
void print(std::ostream &os, char delimiter) const
Print the value(s).
void poll()
Poll values from the server.
State getState() const noexcept
Get the current state.
Definition: Subscription.h:137
Variable getVariable() const
Access the subscribed variable.
const void * getData() const
Get the data Pointer.
bool empty() const noexcept
Check whether the subscription is default-constructed.
Definition: Subscription.h:133
Subscription(Subscriber &subscriber, Process &process, const std::string &path, const Selector &selector={})
Constructor for an unknown variable.
Subscription()=default
Default constructor for an empty subscription.
PdCom Variable interface.
Definition: Variable.h:67
library version string as "major.minor.patch"
Definition: ClientStatistics.h:31
Data Deserialisation helper.
Definition: DataDeserializer.h:51
Selector base class for creating views on multidimensional data.
Definition: Selector.h:48