Kagome
Polkadot Runtime Engine in C++17
kagome::subscription::Subscriber< EventKey, Receiver, Arguments > Class Template Reference

#include <author_api_impl.hpp>

Inheritance diagram for kagome::subscription::Subscriber< EventKey, Receiver, Arguments >:
Collaboration diagram for kagome::subscription::Subscriber< EventKey, Receiver, Arguments >:

Public Types

using EventType = EventKey
 
using ReceiverType = Receiver
 
using Hash = size_t
 
using SubscriptionEngineType = SubscriptionEngine< EventType, ReceiverType, Arguments... >
 
using SubscriptionEnginePtr = std::shared_ptr< SubscriptionEngineType >
 
using CallbackFnType = std::function< void(SubscriptionSetId, ReceiverType &, const EventType &, const Arguments &...)>
 

Public Member Functions

template<typename... SubscriberConstructorArgs>
 Subscriber (SubscriptionEnginePtr &ptr, SubscriberConstructorArgs &&...args)
 
 ~Subscriber ()
 
 Subscriber (const Subscriber &)=delete
 
Subscriberoperator= (const Subscriber &)=delete
 
 Subscriber (Subscriber &&)=default
 
Subscriberoperator= (Subscriber &&)=default
 
void setCallback (CallbackFnType &&f)
 
SubscriptionSetId generateSubscriptionSetId ()
 
void subscribe (SubscriptionSetId id, const EventType &key)
 
bool unsubscribe (SubscriptionSetId id, const EventType &key)
 
bool unsubscribe (SubscriptionSetId id)
 
void unsubscribe ()
 
void on_notify (SubscriptionSetId set_id, const EventType &key, const Arguments &...args)
 
ReceiverTypeget ()
 

Private Types

using SubscriptionsContainer = std::unordered_map< EventType, typename SubscriptionEngineType::IteratorType >
 
using SubscriptionsSets = std::unordered_map< SubscriptionSetId, SubscriptionsContainer >
 

Private Attributes

SubscriptionEnginePtr engine_
 
ReceiverType object_
 
std::mutex subscriptions_cs_
 
SubscriptionsSets subscriptions_sets_
 
CallbackFnType on_notify_callback_
 

Detailed Description

template<typename EventKey, typename Receiver, typename... Arguments>
class kagome::subscription::Subscriber< EventKey, Receiver, Arguments >

Is a wrapper class, which provides subscription to events from SubscriptionEngine

Template Parameters
EventKeyis a type of a particular subscription event (might be a key from an observed storage or a specific event type from an enumeration).
ReceiverTypeis a type of an object which is a part of Subscriber's internal state and can be accessed on every event notification.
Argumentsis a set of types of objects that are passed on every event notification.

Definition at line 51 of file author_api_impl.hpp.

Member Typedef Documentation

template<typename EventKey , typename Receiver , typename... Arguments>
using kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::CallbackFnType = std::function<void(SubscriptionSetId, ReceiverType &, const EventType &, const Arguments &...)>

Definition at line 49 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
using kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::EventType = EventKey

Definition at line 38 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
using kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::Hash = size_t

Definition at line 40 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
using kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::ReceiverType = Receiver

Definition at line 39 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
using kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::SubscriptionEnginePtr = std::shared_ptr<SubscriptionEngineType>

Definition at line 44 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
using kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::SubscriptionEngineType = SubscriptionEngine<EventType, ReceiverType, Arguments...>

Definition at line 43 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
using kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::SubscriptionsContainer = std::unordered_map<EventType, typename SubscriptionEngineType::IteratorType>
private

Definition at line 54 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
using kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::SubscriptionsSets = std::unordered_map<SubscriptionSetId, SubscriptionsContainer>
private

Definition at line 56 of file subscriber.hpp.

Constructor & Destructor Documentation

template<typename EventKey , typename Receiver , typename... Arguments>
template<typename... SubscriberConstructorArgs>
kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::Subscriber ( SubscriptionEnginePtr ptr,
SubscriberConstructorArgs &&...  args 
)
inlineexplicit

Definition at line 67 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::~Subscriber ( )
inline

Definition at line 72 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::Subscriber ( const Subscriber< EventKey, Receiver, Arguments > &  )
delete
template<typename EventKey , typename Receiver , typename... Arguments>
kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::Subscriber ( Subscriber< EventKey, Receiver, Arguments > &&  )
default

Member Function Documentation

template<typename EventKey , typename Receiver , typename... Arguments>
SubscriptionSetId kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::generateSubscriptionSetId ( )
inline

Definition at line 88 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
ReceiverType& kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::get ( )
inline

Definition at line 155 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
void kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::on_notify ( SubscriptionSetId  set_id,
const EventType key,
const Arguments &...  args 
)
inline

Definition at line 148 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
Subscriber& kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::operator= ( const Subscriber< EventKey, Receiver, Arguments > &  )
delete
template<typename EventKey , typename Receiver , typename... Arguments>
Subscriber& kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::operator= ( Subscriber< EventKey, Receiver, Arguments > &&  )
default
template<typename EventKey , typename Receiver , typename... Arguments>
void kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::setCallback ( CallbackFnType &&  f)
inline

Definition at line 84 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
void kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::subscribe ( SubscriptionSetId  id,
const EventType key 
)
inline

Here we check first local subscriptions because of strong connection with SubscriptionEngine.

Definition at line 92 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
bool kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::unsubscribe ( SubscriptionSetId  id,
const EventType key 
)
inline
Parameters
id– subscription set id that unsubscribes from
  • key
key– event key to unsubscribe from
Returns
true if was subscribed to
  • key, false otherwise

Definition at line 108 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
bool kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::unsubscribe ( SubscriptionSetId  id)
inline
Parameters
id– subscription set id to unsubscribe from
Returns
true if was subscribed to
  • id, false otherwise

Definition at line 127 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
void kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::unsubscribe ( )
inline

Definition at line 140 of file subscriber.hpp.

Member Data Documentation

template<typename EventKey , typename Receiver , typename... Arguments>
SubscriptionEnginePtr kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::engine_
private

Definition at line 57 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
ReceiverType kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::object_
private

Definition at line 58 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
CallbackFnType kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::on_notify_callback_
private

Definition at line 63 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
std::mutex kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::subscriptions_cs_
private

Definition at line 60 of file subscriber.hpp.

template<typename EventKey , typename Receiver , typename... Arguments>
SubscriptionsSets kagome::subscription::Subscriber< EventKey, Receiver, Arguments >::subscriptions_sets_
private

Definition at line 61 of file subscriber.hpp.


The documentation for this class was generated from the following files: