Add Subscription::shared_from_this()
Allow event() handler to acquire a shared_ptr<Subscription> to eg. queue for later processing.
This commit is contained in:
@@ -39,6 +39,7 @@ struct SubscriptionImpl : public OperationBase, public Subscription
|
||||
evevent ackTick;
|
||||
|
||||
// const after exec()
|
||||
std::weak_ptr<SubscriptionImpl> self; // internal
|
||||
std::function<void (const Value&)> onInit;
|
||||
std::function<void(Subscription&)> event;
|
||||
Value pvRequest;
|
||||
@@ -173,6 +174,10 @@ struct SubscriptionImpl : public OperationBase, public Subscription
|
||||
return ret;
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<Subscription> shared_from_this() const override final {
|
||||
return std::shared_ptr<Subscription>(self);
|
||||
}
|
||||
|
||||
virtual bool cancel() override final {
|
||||
auto context = chan->context;
|
||||
decltype (event) junk;
|
||||
@@ -552,6 +557,7 @@ std::shared_ptr<Subscription> MonitorBuilder::exec()
|
||||
auto chan = Channel::build(ctx->shared_from_this(), _name);
|
||||
|
||||
auto op = std::make_shared<SubscriptionImpl>(Operation::Monitor, chan);
|
||||
op->self = op;
|
||||
op->event = std::move(_event);
|
||||
op->onInit = std::move(_onInit);
|
||||
op->pvRequest = _buildReq();
|
||||
|
||||
Reference in New Issue
Block a user