hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
subscription.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SUBSCRIPTION_HPP
7 #define IROHA_SUBSCRIPTION_HPP
8 
9 #include <memory>
10 
11 #include "common/common.hpp"
15 
16 namespace iroha {
17  std::shared_ptr<Dispatcher> getDispatcher();
18  std::shared_ptr<Subscription> getSubscription();
19 
20  template <typename ObjectType, typename EventData>
22  template <EventTypes key, typename F, typename... Args>
24  F &&callback,
25  Args &&... args) {
27  getSubscription()->getEngine<EventTypes, EventData>(),
28  std::forward<Args>(args)...);
29  subscriber->setCallback(
30  [f{std::forward<F>(callback)}](auto /*set_id*/,
31  auto &object,
32  auto event_key,
33  EventData args) mutable {
34  assert(key == event_key);
35  std::forward<F>(f)(object, std::move(args));
36  });
37  subscriber->subscribe(0, key, tid);
38  return subscriber;
39  }
40  };
41 } // namespace iroha
42 
43 #endif // IROHA_SUBSCRIPTION_HPP
SubscriptionEngineHandlers
Definition: subscription_fwd.hpp:12
EventTypes
Definition: subscription_fwd.hpp:21
Definition: block_query.hpp:15
static auto create(SubscriptionEngineHandlers tid, F &&callback, Args &&... args)
Definition: subscription.hpp:23
std::shared_ptr< Subscription > getSubscription()
Definition: subscription.cpp:12
static std::shared_ptr< SubscriberImpl > create(SubscriptionEnginePtr const &ptr, SubscriberConstructorArgs &&... args)
Definition: subscriber_impl.hpp:88
std::shared_ptr< Dispatcher > getDispatcher()
Definition: async_dispatcher.cpp:12
Definition: subscription.hpp:21