CatapultServer  v0.5.0.1 (Elephant)
NotificationType.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "FacilityCode.h"
23 #include "catapult/utils/Casting.h"
24 
25 namespace catapult { namespace model {
26 
28  enum class NotificationChannel : uint8_t {
30  None = 0x00,
31 
33  Validator = 0x01,
34 
36  Observer = 0x02,
37 
39  All = 0xFF
40  };
41 
43  enum class NotificationType : uint32_t {};
44 
46  constexpr NotificationType MakeNotificationType(NotificationChannel channel, FacilityCode facility, uint16_t code) {
47  return static_cast<NotificationType>(
48  static_cast<uint32_t>(channel) << 24 | // 01..08: channel
49  static_cast<uint32_t>(facility) << 16 | // 09..16: facility
50  code); // 16..32: code
51  }
52 
54 #define DEFINE_NOTIFICATION_TYPE(CHANNEL, FACILITY, DESCRIPTION, CODE) \
55  constexpr auto FACILITY##_##DESCRIPTION##_Notification = model::MakeNotificationType( \
56  (model::NotificationChannel::CHANNEL), \
57  (model::FacilityCode::FACILITY), \
58  CODE)
59 
61  constexpr bool IsSet(NotificationType type, NotificationChannel channel) {
62  return utils::to_underlying_type(channel) == (utils::to_underlying_type(channel) & (utils::to_underlying_type(type) >> 24));
63  }
64 
67  return static_cast<NotificationChannel>(utils::to_underlying_type(type) >> 24);
68  }
69 
72  type = static_cast<NotificationType>(
73  static_cast<uint32_t>(utils::to_underlying_type(channel) << 24) |
74  (0x00FFFFFFu & utils::to_underlying_type(type)));
75  }
76 
79  return (0x00FFFFFFu & utils::to_underlying_type(lhs)) == (0x00FFFFFFu & utils::to_underlying_type(rhs));
80  }
81 
82  // region core notification types
83 
85 #define DEFINE_CORE_NOTIFICATION(DESCRIPTION, CODE, CHANNEL) DEFINE_NOTIFICATION_TYPE(CHANNEL, Core, DESCRIPTION, CODE)
86 
88  DEFINE_CORE_NOTIFICATION(Register_Account_Address, 0x0001, All);
89 
91  DEFINE_CORE_NOTIFICATION(Register_Account_Public_Key, 0x0002, Observer);
92 
94  DEFINE_CORE_NOTIFICATION(Balance_Transfer, 0x0003, All);
95 
97  DEFINE_CORE_NOTIFICATION(Entity, 0x0004, Validator);
98 
100  DEFINE_CORE_NOTIFICATION(Block, 0x0005, All);
101 
103  DEFINE_CORE_NOTIFICATION(Transaction, 0x0006, All);
104 
106  DEFINE_CORE_NOTIFICATION(Signature, 0x0007, Validator);
107 
109  DEFINE_CORE_NOTIFICATION(Balance_Debit, 0x0008, All);
110 
112  DEFINE_CORE_NOTIFICATION(Address_Interaction, 0x0009, Validator);
113 
115  DEFINE_CORE_NOTIFICATION(Mosaic_Required, 0x000A, Validator);
116 
118  DEFINE_CORE_NOTIFICATION(Source_Change, 0x000B, Observer);
119 
121  DEFINE_CORE_NOTIFICATION(Transaction_Fee, 0x000C, All);
122 
124  DEFINE_CORE_NOTIFICATION(Transaction_Deadline, 0x000D, Validator);
125 
126 #undef DEFINE_CORE_NOTIFICATION
127 
128  // endregion
129 }}
catapult::model::SetNotificationChannel
constexpr void SetNotificationChannel(NotificationType &type, NotificationChannel channel)
Sets the notification channel in type to channel.
Definition: NotificationType.h:71
catapult::model::NotificationChannel::Observer
Publish notification on observer channel.
catapult::model::IsSet
constexpr bool IsSet(NotificationType type, NotificationChannel channel)
Checks if type has channel set.
Definition: NotificationType.h:61
catapult::utils::to_underlying_type
constexpr std::underlying_type_t< TEnum > to_underlying_type(TEnum value)
Converts a strongly typed enumeration value to its underlying integral value.
Definition: Casting.h:37
catapult::model::FacilityCode
FacilityCode
Possible facility codes.
Definition: model/FacilityCode.h:27
catapult::model::GetNotificationChannel
constexpr NotificationChannel GetNotificationChannel(NotificationType type)
Gets the notification channel set in type.
Definition: NotificationType.h:66
catapult::model::NotificationType
NotificationType
Enumeration of all possible notification types.
Definition: NotificationType.h:43
catapult::model::NotificationChannel
NotificationChannel
Notification channel.
Definition: NotificationType.h:28
catapult::model::DEFINE_CORE_NOTIFICATION
DEFINE_CORE_NOTIFICATION(Register_Account_Address, 0x0001, All)
Account was used with specified address.
Casting.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::model::MosaicFlags::All
All flags.
FacilityCode.h
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::model::MakeNotificationType
constexpr NotificationType MakeNotificationType(NotificationChannel channel, FacilityCode facility, uint16_t code)
Makes a notification type given channel, facility and code.
Definition: NotificationType.h:46
catapult::model::NotificationChannel::Validator
Publish notification on validator channel.
catapult::model::MosaicFlags::None
No flags present.