CatapultServer  v0.5.0.1 (Elephant)
DemuxObserverBuilder.h
Go to the documentation of this file.
1 
21 #pragma once
23 #include "ObserverTypes.h"
24 #include <functional>
25 #include <vector>
26 
27 namespace catapult { namespace observers {
28 
31  private:
33 
34  public:
36  template<typename TNotification>
38  auto predicate = [type = TNotification::Notification_Type](const auto& notification) {
39  return model::AreEqualExcludingChannel(type, notification.Type);
40  };
41  m_builder.add(std::make_unique<ConditionalObserver<TNotification>>(std::move(pObserver), predicate));
42  return *this;
43  }
44 
47  return m_builder.build();
48  }
49 
50  private:
51  template<typename TNotification>
53  public:
55  : m_pObserver(std::move(pObserver))
57  {}
58 
59  public:
60  const std::string& name() const override {
61  return m_pObserver->name();
62  }
63 
64  void notify(const model::Notification& notification, ObserverContext& context) const override {
65  if (!m_predicate(notification))
66  return;
67 
68  m_pObserver->notify(static_cast<const TNotification&>(notification), context);
69  }
70 
71  private:
74  };
75 
76  private:
78  };
79 
81  template<>
83  m_builder.add(std::move(pObserver));
84  return *this;
85  }
86 }}
catapult::observers::DemuxObserverBuilder::ConditionalObserver::ConditionalObserver
ConditionalObserver(NotificationObserverPointerT< TNotification > &&pObserver, const NotificationObserverPredicate &predicate)
Definition: DemuxObserverBuilder.h:54
catapult::observers::DemuxObserverBuilder::ConditionalObserver::m_pObserver
NotificationObserverPointerT< TNotification > m_pObserver
Definition: DemuxObserverBuilder.h:72
catapult::observers::ObserverContext
Context passed to all the observers.
Definition: ObserverContext.h:78
catapult::predicate
std::function< bool(TArgs...)> predicate
A predicate function.
Definition: functions.h:31
ObserverTypes.h
catapult::observers::DemuxObserverBuilder::NotificationObserverPredicate
predicate< const model::Notification & > NotificationObserverPredicate
Definition: DemuxObserverBuilder.h:32
catapult::observers::DemuxObserverBuilder::ConditionalObserver
Definition: DemuxObserverBuilder.h:52
catapult::observers::DemuxObserverBuilder::add
DemuxObserverBuilder & add(NotificationObserverPointerT< TNotification > &&pObserver)
Adds an observer (pObserver) to the builder that is invoked only when matching notifications are proc...
Definition: DemuxObserverBuilder.h:37
catapult::observers::AggregateObserverBuilder
A strongly typed aggregate notification observer builder.
Definition: AggregateObserverBuilder.h:30
catapult::observers::DemuxObserverBuilder::ConditionalObserver::name
const std::string & name() const override
Gets the observer name.
Definition: DemuxObserverBuilder.h:60
catapult::observers::DemuxObserverBuilder::ConditionalObserver::m_predicate
NotificationObserverPredicate m_predicate
Definition: DemuxObserverBuilder.h:73
catapult::observers::AggregateNotificationObserverPointerT
std::unique_ptr< const AggregateNotificationObserverT< TNotification > > AggregateNotificationObserverPointerT
An aggregate notification observer (unique) pointer.
Definition: ObserverTypes.h:41
catapult::observers::NotificationObserverT
A strongly typed notification observer.
Definition: NotificationObserver.h:29
catapult::observers::DemuxObserverBuilder::build
AggregateNotificationObserverPointerT< model::Notification > build()
Builds a demultiplexing observer.
Definition: DemuxObserverBuilder.h:46
catapult::observers::NotificationObserverPointerT
std::unique_ptr< const NotificationObserverT< TNotification > > NotificationObserverPointerT
A notification observer (unique) pointer.
Definition: ObserverTypes.h:34
catapult::model::Notification
A basic notification.
Definition: Notifications.h:36
catapult::observers::DemuxObserverBuilder::m_builder
AggregateObserverBuilder< model::Notification > m_builder
Definition: DemuxObserverBuilder.h:77
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::model::AreEqualExcludingChannel
constexpr bool AreEqualExcludingChannel(NotificationType lhs, NotificationType rhs)
Returns true if lhs and rhs have the same source (facility and code).
Definition: NotificationType.h:78
catapult::observers::DemuxObserverBuilder
A demultiplexing observer builder.
Definition: DemuxObserverBuilder.h:30
catapult::observers::DemuxObserverBuilder::ConditionalObserver::notify
void notify(const model::Notification &notification, ObserverContext &context) const override
Definition: DemuxObserverBuilder.h:64
AggregateObserverBuilder.h