| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/***************************************************************************** |
| 2 |
|
|
* |
| 3 |
|
|
* Copyright (C) 2021 Richard Hacker (lerichi at gmx dot net), |
| 4 |
|
|
* Florian Pose (fp at igh dot de), |
| 5 |
|
|
* Bjarne von Horn (vh at igh dot de). |
| 6 |
|
|
* |
| 7 |
|
|
* This file is part of the PdCom library. |
| 8 |
|
|
* |
| 9 |
|
|
* The PdCom library is free software: you can redistribute it and/or modify |
| 10 |
|
|
* it under the terms of the GNU Lesser General Public License as published by |
| 11 |
|
|
* the Free Software Foundation, either version 3 of the License, or (at your |
| 12 |
|
|
* option) any later version. |
| 13 |
|
|
* |
| 14 |
|
|
* The PdCom library is distributed in the hope that it will be useful, but |
| 15 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 16 |
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 17 |
|
|
* License for more details. |
| 18 |
|
|
* |
| 19 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
| 20 |
|
|
* along with the PdCom library. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
|
|
* |
| 22 |
|
|
*****************************************************************************/ |
| 23 |
|
|
|
| 24 |
|
|
#ifndef PDCOM5_MSRPROTO_SUBSCRIPTION_H |
| 25 |
|
|
#define PDCOM5_MSRPROTO_SUBSCRIPTION_H |
| 26 |
|
|
|
| 27 |
|
|
#include "../Selector.h" |
| 28 |
|
|
#include "../Subscription.h" |
| 29 |
|
|
|
| 30 |
|
|
#include <vector> |
| 31 |
|
|
|
| 32 |
|
|
namespace PdCom { namespace impl { namespace MsrProto { |
| 33 |
|
|
|
| 34 |
|
|
class Variable; |
| 35 |
|
|
|
| 36 |
|
123 |
class InvalidSubscription : public PdCom::impl::Subscription |
| 37 |
|
|
{ |
| 38 |
|
|
public: |
| 39 |
|
123 |
InvalidSubscription( |
| 40 |
|
|
PdCom::Subscription *This, |
| 41 |
|
|
PdCom::Subscriber &subscriber, |
| 42 |
|
|
std::weak_ptr<impl::Process> process, |
| 43 |
|
123 |
std::shared_ptr<const PdCom::impl::Variable> var = nullptr) : |
| 44 |
|
123 |
PdCom::impl::Subscription(var, This, subscriber, process) |
| 45 |
|
123 |
{} |
| 46 |
|
|
|
| 47 |
|
|
void poll() override; |
| 48 |
|
|
const void *getData() const override; |
| 49 |
|
|
|
| 50 |
|
|
protected: |
| 51 |
|
|
template <typename T> |
| 52 |
|
|
static void unsubscribe(T &This); |
| 53 |
|
|
}; |
| 54 |
|
|
|
| 55 |
|
32 |
class PendingSubscription : public InvalidSubscription |
| 56 |
|
|
{ |
| 57 |
|
|
std::shared_ptr<const PdCom::impl::Selector> selector_; |
| 58 |
|
|
|
| 59 |
|
|
public: |
| 60 |
|
32 |
PendingSubscription( |
| 61 |
|
|
PdCom::Subscription *This, |
| 62 |
|
|
PdCom::Subscriber &subscriber, |
| 63 |
|
|
std::weak_ptr<impl::Process> process, |
| 64 |
|
32 |
std::shared_ptr<const PdCom::impl::Selector> selector) : |
| 65 |
|
|
InvalidSubscription(This, subscriber, process), |
| 66 |
|
32 |
selector_(std::move(selector)) |
| 67 |
|
32 |
{} |
| 68 |
|
|
|
| 69 |
|
25 |
std::shared_ptr<const PdCom::impl::Selector> getSelector() const |
| 70 |
|
|
{ |
| 71 |
|
25 |
return selector_; |
| 72 |
|
|
} |
| 73 |
|
|
}; |
| 74 |
|
|
|
| 75 |
|
86 |
class PollSubscription : |
| 76 |
|
|
public InvalidSubscription, |
| 77 |
|
|
public std::enable_shared_from_this<PollSubscription> |
| 78 |
|
|
{ |
| 79 |
|
|
public: |
| 80 |
|
|
PollSubscription( |
| 81 |
|
|
std::shared_ptr<const Variable> variable, |
| 82 |
|
|
PdCom::Subscription *This, |
| 83 |
|
|
PdCom::Subscriber &subscriber, |
| 84 |
|
|
std::weak_ptr<impl::Process> process, |
| 85 |
|
|
const PdCom::Selector &selector); |
| 86 |
|
|
void poll() override; |
| 87 |
|
78 |
const void *getData() const override { return data_.data(); } |
| 88 |
|
|
|
| 89 |
|
101 |
void readData(const char *data) { copy_function_(data_.data(), data); } |
| 90 |
|
|
bool pollData(uint64_t mtime, const char *data); |
| 91 |
|
|
const bool is_parameter_; |
| 92 |
|
|
|
| 93 |
|
|
private: |
| 94 |
|
|
PdCom::impl::Selector::CopyFunctionType copy_function_; |
| 95 |
|
|
std::vector<char> data_; |
| 96 |
|
|
}; |
| 97 |
|
|
|
| 98 |
|
|
class EventSubscription : public PollSubscription |
| 99 |
|
|
{ |
| 100 |
|
|
public: |
| 101 |
|
28 |
using PollSubscription::PollSubscription; |
| 102 |
|
|
|
| 103 |
|
|
~EventSubscription(); |
| 104 |
|
|
}; |
| 105 |
|
|
|
| 106 |
|
|
class PeriodicSubscription : public PollSubscription |
| 107 |
|
|
{ |
| 108 |
|
|
public: |
| 109 |
|
56 |
using PollSubscription::PollSubscription; |
| 110 |
|
|
~PeriodicSubscription(); |
| 111 |
|
|
}; |
| 112 |
|
|
}}} // namespace PdCom::impl::MsrProto |
| 113 |
|
|
#endif // PDCOM5_MSRPROTO_SUBSCRIPTION_H |
| 114 |
|
|
|