com.wallstop-studios.dxmessaging 2.0.0-rc11 → 2.0.0-rc13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/.gitattributes +63 -63
  2. package/.github/workflows/npm-publish.yml +66 -0
  3. package/CHANGELOG.md.meta +7 -7
  4. package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll.meta +33 -33
  5. package/Editor/Analyzers/Microsoft.CodeAnalysis.dll.meta +33 -33
  6. package/Editor/Analyzers/System.Reflection.Metadata.dll.meta +33 -33
  7. package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll.meta +71 -71
  8. package/Editor/Analyzers.meta +8 -8
  9. package/Editor/SetupCscRsp.cs +162 -146
  10. package/Editor/SetupCscRsp.cs.meta +2 -2
  11. package/Editor/WallstopStudios.DxMessaging.Editor.asmdef +17 -17
  12. package/Editor/WallstopStudios.DxMessaging.Editor.asmdef.meta +7 -7
  13. package/Editor.meta +8 -8
  14. package/LICENSE.md +6 -6
  15. package/LICENSE.md.meta +7 -7
  16. package/README.md +387 -363
  17. package/README.md.meta +7 -7
  18. package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs +7 -9
  19. package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs.meta +2 -2
  20. package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs +7 -10
  21. package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs.meta +2 -2
  22. package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs +7 -10
  23. package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs.meta +2 -2
  24. package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs +7 -10
  25. package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs.meta +2 -2
  26. package/Runtime/Core/Attributes.meta +2 -2
  27. package/Runtime/Core/Extensions/MessageExtensions.cs +342 -275
  28. package/Runtime/Core/Extensions/MessageExtensions.cs.meta +11 -11
  29. package/Runtime/Core/Extensions.meta +8 -8
  30. package/Runtime/Core/IMessage.cs +12 -12
  31. package/Runtime/Core/IMessage.cs.meta +11 -11
  32. package/Runtime/Core/InstanceId.cs +149 -149
  33. package/Runtime/Core/InstanceId.cs.meta +11 -11
  34. package/Runtime/Core/MessageBus/IMessageBus.cs +309 -309
  35. package/Runtime/Core/MessageBus/IMessageBus.cs.meta +11 -11
  36. package/Runtime/Core/MessageBus/MessageBus.cs +2243 -2084
  37. package/Runtime/Core/MessageBus/MessageBus.cs.meta +11 -11
  38. package/Runtime/Core/MessageBus/MessagingRegistration.cs +105 -100
  39. package/Runtime/Core/MessageBus/MessagingRegistration.cs.meta +11 -11
  40. package/Runtime/Core/MessageBus/RegistrationLog.cs +111 -111
  41. package/Runtime/Core/MessageBus/RegistrationLog.cs.meta +11 -11
  42. package/Runtime/Core/MessageBus.meta +8 -8
  43. package/Runtime/Core/MessageHandler.cs +2778 -2759
  44. package/Runtime/Core/MessageHandler.cs.meta +11 -11
  45. package/Runtime/Core/MessageRegistrationHandle.cs +110 -110
  46. package/Runtime/Core/MessageRegistrationHandle.cs.meta +11 -11
  47. package/Runtime/Core/MessageRegistrationToken.cs +1234 -1234
  48. package/Runtime/Core/MessageRegistrationToken.cs.meta +11 -11
  49. package/Runtime/Core/Messages/IBroadcastMessage.cs +27 -27
  50. package/Runtime/Core/Messages/IBroadcastMessage.cs.meta +11 -11
  51. package/Runtime/Core/Messages/ITargetedMessage.cs +27 -26
  52. package/Runtime/Core/Messages/ITargetedMessage.cs.meta +11 -11
  53. package/Runtime/Core/Messages/IUntargetedMessage.cs +27 -26
  54. package/Runtime/Core/Messages/IUntargetedMessage.cs.meta +11 -11
  55. package/Runtime/Core/Messages.meta +8 -8
  56. package/Runtime/Core/MessagingDebug.cs +70 -71
  57. package/Runtime/Core/MessagingDebug.cs.meta +11 -11
  58. package/Runtime/Core.meta +8 -8
  59. package/Runtime/Unity/MessageAwareComponent.cs +77 -77
  60. package/Runtime/Unity/MessageAwareComponent.cs.meta +11 -11
  61. package/Runtime/Unity/MessagingComponent.cs +99 -99
  62. package/Runtime/Unity/MessagingComponent.cs.meta +11 -11
  63. package/Runtime/Unity.meta +8 -8
  64. package/Runtime/WallstopStudios.DxMessaging.asmdef +15 -15
  65. package/Runtime.meta +8 -8
  66. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs +92 -75
  67. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs.meta +11 -11
  68. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs +94 -77
  69. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs.meta +2 -2
  70. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs +94 -77
  71. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs.meta +2 -2
  72. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs +94 -78
  73. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs.meta +2 -2
  74. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj +21 -21
  75. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj.meta +7 -7
  76. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.meta +8 -8
  77. package/SourceGenerators.meta +8 -8
  78. package/Tests/Runtime/Benchmarks/PerformanceTests.cs +373 -310
  79. package/Tests/Runtime/Benchmarks/PerformanceTests.cs.meta +11 -11
  80. package/Tests/Runtime/Benchmarks.meta +8 -8
  81. package/Tests/Runtime/Core/BroadcastTests.cs +899 -899
  82. package/Tests/Runtime/Core/GlobalAcceptAllTests.cs +190 -169
  83. package/Tests/Runtime/Core/GlobalAcceptAllTests.cs.meta +11 -11
  84. package/Tests/Runtime/Core/MessagingTestBase.cs +185 -164
  85. package/Tests/Runtime/Core/MessagingTestBase.cs.meta +11 -11
  86. package/Tests/Runtime/Core/NominalTests.cs +1740 -1518
  87. package/Tests/Runtime/Core/PostProcessorTests.cs +1236 -849
  88. package/Tests/Runtime/Core/PostProcessorTests.cs.meta +11 -11
  89. package/Tests/Runtime/Core/RegistrationTests.cs +1266 -995
  90. package/Tests/Runtime/Core/RegistrationTests.cs.meta +11 -11
  91. package/Tests/Runtime/Core/TargetedTests.cs +888 -888
  92. package/Tests/Runtime/Core/TargetedTests.cs.meta +11 -11
  93. package/Tests/Runtime/Core/UntargetedTests.cs +272 -272
  94. package/Tests/Runtime/Core/UntargetedTests.cs.meta +11 -11
  95. package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs +9 -9
  96. package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs.meta +11 -11
  97. package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +186 -140
  98. package/Tests/Runtime/Scripts/Messages/ComplexTargetedMessage.cs +30 -30
  99. package/Tests/Runtime/Scripts/Messages/SimpleBroadcastMessage.cs +8 -8
  100. package/Tests/Runtime/Scripts/Messages/SimpleTargetedMessage.cs +8 -8
  101. package/Tests/Runtime/Scripts/Messages/SimpleUntargetedMessage.cs +8 -8
  102. package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.asmdef +22 -22
  103. package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj.meta +7 -7
  104. package/Tests.meta +8 -8
  105. package/Third Party Notices.md.meta +7 -7
  106. package/package.json +36 -36
  107. package/package.json.meta +7 -7
@@ -1,309 +1,309 @@
1
- namespace DxMessaging.Core.MessageBus
2
- {
3
- using System;
4
- using Core;
5
- using Messages;
6
-
7
- /// <summary>
8
- /// Description of a general purpose message bus that provides both registration, de-registration, and broadcast capabilities.
9
- /// </summary>
10
- public interface IMessageBus
11
- {
12
- /// <summary>
13
- /// Given an Untargeted message, determines whether or not it should be processed or skipped
14
- /// </summary>
15
- /// <typeparam name="TMessage">Specific type of message.</typeparam>
16
- /// <param name="message">Message to consider.</param>
17
- /// <returns>True if the message should be processed, false if it should be skipped.</returns>
18
- public delegate bool UntargetedInterceptor<TMessage>(ref TMessage message)
19
- where TMessage : IUntargetedMessage;
20
-
21
- /// <summary>
22
- /// Given an Targeted message and its target, determines whether or not it should be processed or skipped.
23
- /// </summary>
24
- /// <typeparam name="TMessage">Specific type of message.</typeparam>
25
- /// <param name="target">Target of the message.</param>
26
- /// <param name="message">Message to consider.</param>
27
- /// <returns>True if the message should be processed, false if it should be skipped.</returns>
28
- public delegate bool TargetedInterceptor<TMessage>(
29
- ref InstanceId target,
30
- ref TMessage message
31
- )
32
- where TMessage : ITargetedMessage;
33
-
34
- /// <summary>
35
- /// Given an Broadcast message and its source, determines whether or not it should be processed or skipped.
36
- /// </summary>
37
- /// <typeparam name="TMessage">Specific type of message.</typeparam>
38
- /// <param name="source">Source of the message.</param>
39
- /// <param name="message">Message to consider.</param>
40
- /// <returns>True if the message should be processed, false if it should be skipped.</returns>
41
- public delegate bool BroadcastInterceptor<TMessage>(
42
- ref InstanceId source,
43
- ref TMessage message
44
- )
45
- where TMessage : IBroadcastMessage;
46
-
47
- /// <summary>
48
- /// The registration log of all messaging registrations for this MessageBus.
49
- /// </summary>
50
- RegistrationLog Log { get; }
51
-
52
- /// <summary>
53
- /// Registers the specified MessageHandler to receive UntargetedMessages of the specified type.
54
- /// </summary>
55
- /// <typeparam name="T">Specific type of UntargetedMessages to register for.</typeparam>
56
- /// <param name="messageHandler">MessageHandler to register to accept UntargetedMessages of the specified type.</param>
57
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
58
- Action RegisterUntargeted<T>(MessageHandler messageHandler, int priority = 0)
59
- where T : IUntargetedMessage;
60
-
61
- /// <summary>
62
- /// Registers the specified MessageHandler to receive TargetedMessages of the specified type for the specified target.
63
- /// </summary>
64
- /// <typeparam name="T">Specific type of TargetedMessages to register for.</typeparam>
65
- /// <param name="target">Target of messages to listen for.</param>
66
- /// <param name="messageHandler">MessageHandler to register the TargetedMessages of the specified type.</param>
67
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive the messages.</returns>
68
- Action RegisterTargeted<T>(
69
- InstanceId target,
70
- MessageHandler messageHandler,
71
- int priority = 0
72
- )
73
- where T : ITargetedMessage;
74
-
75
- /// <summary>
76
- /// Registers the specified MessageHandler to receive TargetedMessages of the specified type.
77
- /// This registration IGNORES the targeting of the TargetedMessage.
78
- /// </summary>
79
- /// <typeparam name="T">Specific type of TargetedMessages to register for.</typeparam>
80
- /// <param name="messageHandler">MessageHandler to register to accept all TargetedMessages of the specified type.</param>
81
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
82
- Action RegisterTargetedWithoutTargeting<T>(MessageHandler messageHandler, int priority = 0)
83
- where T : ITargetedMessage;
84
-
85
- /// <summary>
86
- /// Registers the specified MessageHandler to receive BroadcastMessages of the specified type from the provided source.
87
- /// </summary>
88
- /// <typeparam name="T">Type of the BroadcastMessage to register.</typeparam>
89
- /// <param name="source">InstanceId of the source for BroadcastMessages to listen to.</param>
90
- /// <param name="messageHandler">MessageHandler to register to accept BroadcastMessages.</param>
91
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
92
- Action RegisterSourcedBroadcast<T>(
93
- InstanceId source,
94
- MessageHandler messageHandler,
95
- int priority = 0
96
- )
97
- where T : IBroadcastMessage;
98
-
99
- /// <summary>
100
- /// Registers the specified MessageHandler to receive BroadcastMessages of the specified type from ALL sources.
101
- /// This registration IGNORES the source of the BroadcastMessage.
102
- /// </summary>
103
- /// <typeparam name="T">Type of the BroadcastMessage to register.</typeparam>
104
- /// <param name="messageHandler">MessageHandler to register to accept BroadcastMessages.</param>
105
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
106
- Action RegisterSourcedBroadcastWithoutSource<T>(
107
- MessageHandler messageHandler,
108
- int priority = 0
109
- )
110
- where T : IBroadcastMessage;
111
-
112
- /// <summary>
113
- /// Registers the specified MessageHandler to receive ALL messages.
114
- /// It doesn't matter if the message is Targeted or Untargeted, this MessageHandler will be invoked for it.
115
- /// </summary>
116
- /// <param name="messageHandler">MessageHandler to register to accept all messages.</param>
117
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
118
- Action RegisterGlobalAcceptAll(MessageHandler messageHandler);
119
-
120
- /// <summary>
121
- /// Registers the specified MessageHandler and transformer function as an interceptor for Messages of type T.
122
- /// Whenever messages of that type are sent, interceptors will be ran in order by priority and then order of registration within
123
- /// that priority, transforming that message into new, mutated types.
124
- /// If any interceptor returns false, message handling is immediately stopped.
125
- /// The message at the end of the transformations will be then sent to registered message handlers.
126
- /// </summary>
127
- /// <note>
128
- /// Transformer function can return false to "cancel" the message being sent.
129
- /// </note>
130
- /// <typeparam name="T">Type of message to intercept.</typeparam>
131
- /// <param name="interceptor">Transformation function to run on messages of the chosen type.</param>
132
- /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
133
- /// <note>
134
- /// The transform function takes:
135
- /// param1: Current message instance by reference
136
- /// And returns: true if message handling should continue, false if message handling should be stopped.
137
- /// </note>
138
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to intercept messages.</returns>
139
- Action RegisterUntargetedInterceptor<T>(
140
- UntargetedInterceptor<T> interceptor,
141
- int priority = 0
142
- )
143
- where T : IUntargetedMessage;
144
-
145
- /// <summary>
146
- /// Registers the specified MessageHandler and transformer function as an interceptor for Messages of type T.
147
- /// Whenever messages of that type are sent, interceptors will be ran in order by priority and then order of registration within
148
- /// that priority, transforming that message into new, mutated types.
149
- /// If any interceptor returns false, message handling is immediately stopped.
150
- /// The message at the end of the transformations will be then sent to registered message handlers.
151
- /// </summary>
152
- /// <note>
153
- /// Transformer function can return false to "cancel" the message being sent.
154
- /// </note>
155
- /// <typeparam name="T">Type of message to intercept.</typeparam>
156
- /// <param name="interceptor">Transformation function to run on messages of the chosen type.</param>
157
- /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
158
- /// <note>
159
- /// The transform function takes:
160
- /// param1: Current message instance by reference
161
- /// And returns: true if message handling should continue, false if message handling should be stopped.
162
- /// </note>
163
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to intercept messages.</returns>
164
- Action RegisterTargetedInterceptor<T>(TargetedInterceptor<T> interceptor, int priority = 0)
165
- where T : ITargetedMessage;
166
-
167
- /// <summary>
168
- /// Registers the specified MessageHandler and transformer function as an interceptor for Messages of type T.
169
- /// Whenever messages of that type are sent, interceptors will be ran in order by priority and then order of registration within
170
- /// that priority, transforming that message into new, mutated types.
171
- /// If any interceptor returns false, message handling is immediately stopped.
172
- /// The message at the end of the transformations will be then sent to registered message handlers.
173
- /// </summary>
174
- /// <note>
175
- /// Transformer function can return false to "cancel" the message being sent.
176
- /// </note>
177
- /// <typeparam name="T">Type of message to intercept.</typeparam>
178
- /// <param name="interceptor">Transformation function to run on messages of the chosen type.</param>
179
- /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
180
- /// <note>
181
- /// The transform function takes:
182
- /// param1: Current message instance by reference
183
- /// And returns: true if message handling should continue, false if message handling should be stopped.
184
- /// </note>
185
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to intercept messages.</returns>
186
- Action RegisterBroadcastInterceptor<T>(
187
- BroadcastInterceptor<T> interceptor,
188
- int priority = 0
189
- )
190
- where T : IBroadcastMessage;
191
-
192
- /// <summary>
193
- /// Registers the provided MessageHandler to post process Untargeted messages of the given type.
194
- /// (This will run after all handlers run for the provided message).
195
- /// </summary>
196
- /// <typeparam name="T">Type of UntargetedMessage to post process.</typeparam>
197
- /// <param name="messageHandler">MessageHandler to post process messages for.</param>
198
- /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
199
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
200
- Action RegisterUntargetedPostProcessor<T>(MessageHandler messageHandler, int priority = 0)
201
- where T : IUntargetedMessage;
202
-
203
- /// <summary>
204
- /// Registers the provided MessageHandler to post process Targeted messages of the given type.
205
- /// (This will run after all handlers run for the provided message).
206
- /// </summary>
207
- /// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
208
- /// <param name="target">Target of messages to listen for.</param>
209
- /// <param name="messageHandler">MessageHandler to post process messages for.</param>
210
- /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
211
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
212
- Action RegisterTargetedPostProcessor<T>(
213
- InstanceId target,
214
- MessageHandler messageHandler,
215
- int priority = 0
216
- )
217
- where T : ITargetedMessage;
218
-
219
- /// <summary>
220
- /// Registers the provided MessageHandler to post process Targeted messages of the given type for all targets.
221
- /// (This will run after all handlers run for the provided message).
222
- /// </summary>
223
- /// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
224
- /// <param name="messageHandler">MessageHandler to post process messages for.</param>
225
- /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
226
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
227
- Action RegisterTargetedWithoutTargetingPostProcessor<T>(
228
- MessageHandler messageHandler,
229
- int priority = 0
230
- )
231
- where T : ITargetedMessage;
232
-
233
- /// <summary>
234
- /// Registers the provided MessageHandler to post process Targeted messages of the given type.
235
- /// (This will run after all handlers run for the provided message).
236
- /// </summary>
237
- /// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
238
- /// <param name="source">Source of messages to listen for.</param>
239
- /// <param name="messageHandler">MessageHandler to post process messages for.</param>
240
- /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
241
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
242
- Action RegisterBroadcastPostProcessor<T>(
243
- InstanceId source,
244
- MessageHandler messageHandler,
245
- int priority = 0
246
- )
247
- where T : IBroadcastMessage;
248
-
249
- /// <summary>
250
- /// Registers the provided MessageHandler to post process Targeted messages of the given type for all sources.
251
- /// (This will run after all handlers run for the provided message).
252
- /// </summary>
253
- /// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
254
- /// <param name="messageHandler">MessageHandler to post process messages for.</param>
255
- /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
256
- /// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
257
- Action RegisterBroadcastWithoutSourcePostProcessor<T>(
258
- MessageHandler messageHandler,
259
- int priority = 0
260
- )
261
- where T : IBroadcastMessage;
262
-
263
- /// <summary>
264
- /// Broadcasts an Untargeted message to all listeners registered to this bus.
265
- /// </summary>
266
- /// <param name="typedMessage">Message to broadcast.</param>
267
- void UntypedUntargetedBroadcast(IUntargetedMessage typedMessage);
268
-
269
- /// <summary>
270
- /// Broadcasts a fast Untargeted message to all listeners registered to this bus.
271
- /// </summary>
272
- /// <param name="typedMessage">Message to broadcast.</param>
273
-
274
- void UntargetedBroadcast<TMessage>(ref TMessage typedMessage)
275
- where TMessage : IUntargetedMessage;
276
-
277
- /// <summary>
278
- /// Broadcasts a TargetedMessage to all listeners registered to this bus.
279
- /// </summary>
280
- /// <param name="target">Target to send the message to.</param>
281
- /// <param name="typedMessage">Message to broadcast.</param>
282
- void UntypedTargetedBroadcast(InstanceId target, ITargetedMessage typedMessage);
283
-
284
- /// <summary>
285
- /// Broadcasts a fast TargetedMessage to all listeners registered to this bus.
286
- /// </summary>
287
- /// <param name="target">Target to send the message to.</param>
288
- /// <param name="typedMessage">Message to broadcast.</param>
289
-
290
- void TargetedBroadcast<TMessage>(ref InstanceId target, ref TMessage typedMessage)
291
- where TMessage : ITargetedMessage;
292
-
293
- /// <summary>
294
- /// Broadcasts a BroadcastMessage to all listeners registered to this bus.
295
- /// </summary>
296
- /// <param name="source">Source of the message.</param>
297
- /// <param name="typedMessage">Message to broadcast.</param>
298
- void UntypedSourcedBroadcast(InstanceId source, IBroadcastMessage typedMessage);
299
-
300
- /// <summary>
301
- /// Broadcasts a fast BroadcastMessage to all listeners registered to this bus.
302
- /// </summary>
303
- /// <param name="source">Source of the message.</param>
304
- /// <param name="typedMessage">Message to broadcast.</param>
305
-
306
- void SourcedBroadcast<TMessage>(ref InstanceId source, ref TMessage typedMessage)
307
- where TMessage : IBroadcastMessage;
308
- }
309
- }
1
+ namespace DxMessaging.Core.MessageBus
2
+ {
3
+ using System;
4
+ using Core;
5
+ using Messages;
6
+
7
+ /// <summary>
8
+ /// Description of a general purpose message bus that provides both registration, de-registration, and broadcast capabilities.
9
+ /// </summary>
10
+ public interface IMessageBus
11
+ {
12
+ /// <summary>
13
+ /// Given an Untargeted message, determines whether or not it should be processed or skipped
14
+ /// </summary>
15
+ /// <typeparam name="TMessage">Specific type of message.</typeparam>
16
+ /// <param name="message">Message to consider.</param>
17
+ /// <returns>True if the message should be processed, false if it should be skipped.</returns>
18
+ public delegate bool UntargetedInterceptor<TMessage>(ref TMessage message)
19
+ where TMessage : IUntargetedMessage;
20
+
21
+ /// <summary>
22
+ /// Given an Targeted message and its target, determines whether or not it should be processed or skipped.
23
+ /// </summary>
24
+ /// <typeparam name="TMessage">Specific type of message.</typeparam>
25
+ /// <param name="target">Target of the message.</param>
26
+ /// <param name="message">Message to consider.</param>
27
+ /// <returns>True if the message should be processed, false if it should be skipped.</returns>
28
+ public delegate bool TargetedInterceptor<TMessage>(
29
+ ref InstanceId target,
30
+ ref TMessage message
31
+ )
32
+ where TMessage : ITargetedMessage;
33
+
34
+ /// <summary>
35
+ /// Given an Broadcast message and its source, determines whether or not it should be processed or skipped.
36
+ /// </summary>
37
+ /// <typeparam name="TMessage">Specific type of message.</typeparam>
38
+ /// <param name="source">Source of the message.</param>
39
+ /// <param name="message">Message to consider.</param>
40
+ /// <returns>True if the message should be processed, false if it should be skipped.</returns>
41
+ public delegate bool BroadcastInterceptor<TMessage>(
42
+ ref InstanceId source,
43
+ ref TMessage message
44
+ )
45
+ where TMessage : IBroadcastMessage;
46
+
47
+ /// <summary>
48
+ /// The registration log of all messaging registrations for this MessageBus.
49
+ /// </summary>
50
+ RegistrationLog Log { get; }
51
+
52
+ /// <summary>
53
+ /// Registers the specified MessageHandler to receive UntargetedMessages of the specified type.
54
+ /// </summary>
55
+ /// <typeparam name="T">Specific type of UntargetedMessages to register for.</typeparam>
56
+ /// <param name="messageHandler">MessageHandler to register to accept UntargetedMessages of the specified type.</param>
57
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
58
+ Action RegisterUntargeted<T>(MessageHandler messageHandler, int priority = 0)
59
+ where T : IUntargetedMessage;
60
+
61
+ /// <summary>
62
+ /// Registers the specified MessageHandler to receive TargetedMessages of the specified type for the specified target.
63
+ /// </summary>
64
+ /// <typeparam name="T">Specific type of TargetedMessages to register for.</typeparam>
65
+ /// <param name="target">Target of messages to listen for.</param>
66
+ /// <param name="messageHandler">MessageHandler to register the TargetedMessages of the specified type.</param>
67
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive the messages.</returns>
68
+ Action RegisterTargeted<T>(
69
+ InstanceId target,
70
+ MessageHandler messageHandler,
71
+ int priority = 0
72
+ )
73
+ where T : ITargetedMessage;
74
+
75
+ /// <summary>
76
+ /// Registers the specified MessageHandler to receive TargetedMessages of the specified type.
77
+ /// This registration IGNORES the targeting of the TargetedMessage.
78
+ /// </summary>
79
+ /// <typeparam name="T">Specific type of TargetedMessages to register for.</typeparam>
80
+ /// <param name="messageHandler">MessageHandler to register to accept all TargetedMessages of the specified type.</param>
81
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
82
+ Action RegisterTargetedWithoutTargeting<T>(MessageHandler messageHandler, int priority = 0)
83
+ where T : ITargetedMessage;
84
+
85
+ /// <summary>
86
+ /// Registers the specified MessageHandler to receive BroadcastMessages of the specified type from the provided source.
87
+ /// </summary>
88
+ /// <typeparam name="T">Type of the BroadcastMessage to register.</typeparam>
89
+ /// <param name="source">InstanceId of the source for BroadcastMessages to listen to.</param>
90
+ /// <param name="messageHandler">MessageHandler to register to accept BroadcastMessages.</param>
91
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
92
+ Action RegisterSourcedBroadcast<T>(
93
+ InstanceId source,
94
+ MessageHandler messageHandler,
95
+ int priority = 0
96
+ )
97
+ where T : IBroadcastMessage;
98
+
99
+ /// <summary>
100
+ /// Registers the specified MessageHandler to receive BroadcastMessages of the specified type from ALL sources.
101
+ /// This registration IGNORES the source of the BroadcastMessage.
102
+ /// </summary>
103
+ /// <typeparam name="T">Type of the BroadcastMessage to register.</typeparam>
104
+ /// <param name="messageHandler">MessageHandler to register to accept BroadcastMessages.</param>
105
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
106
+ Action RegisterSourcedBroadcastWithoutSource<T>(
107
+ MessageHandler messageHandler,
108
+ int priority = 0
109
+ )
110
+ where T : IBroadcastMessage;
111
+
112
+ /// <summary>
113
+ /// Registers the specified MessageHandler to receive ALL messages.
114
+ /// It doesn't matter if the message is Targeted or Untargeted, this MessageHandler will be invoked for it.
115
+ /// </summary>
116
+ /// <param name="messageHandler">MessageHandler to register to accept all messages.</param>
117
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
118
+ Action RegisterGlobalAcceptAll(MessageHandler messageHandler);
119
+
120
+ /// <summary>
121
+ /// Registers the specified MessageHandler and transformer function as an interceptor for Messages of type T.
122
+ /// Whenever messages of that type are sent, interceptors will be ran in order by priority and then order of registration within
123
+ /// that priority, transforming that message into new, mutated types.
124
+ /// If any interceptor returns false, message handling is immediately stopped.
125
+ /// The message at the end of the transformations will be then sent to registered message handlers.
126
+ /// </summary>
127
+ /// <note>
128
+ /// Transformer function can return false to "cancel" the message being sent.
129
+ /// </note>
130
+ /// <typeparam name="T">Type of message to intercept.</typeparam>
131
+ /// <param name="interceptor">Transformation function to run on messages of the chosen type.</param>
132
+ /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
133
+ /// <note>
134
+ /// The transform function takes:
135
+ /// param1: Current message instance by reference
136
+ /// And returns: true if message handling should continue, false if message handling should be stopped.
137
+ /// </note>
138
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to intercept messages.</returns>
139
+ Action RegisterUntargetedInterceptor<T>(
140
+ UntargetedInterceptor<T> interceptor,
141
+ int priority = 0
142
+ )
143
+ where T : IUntargetedMessage;
144
+
145
+ /// <summary>
146
+ /// Registers the specified MessageHandler and transformer function as an interceptor for Messages of type T.
147
+ /// Whenever messages of that type are sent, interceptors will be ran in order by priority and then order of registration within
148
+ /// that priority, transforming that message into new, mutated types.
149
+ /// If any interceptor returns false, message handling is immediately stopped.
150
+ /// The message at the end of the transformations will be then sent to registered message handlers.
151
+ /// </summary>
152
+ /// <note>
153
+ /// Transformer function can return false to "cancel" the message being sent.
154
+ /// </note>
155
+ /// <typeparam name="T">Type of message to intercept.</typeparam>
156
+ /// <param name="interceptor">Transformation function to run on messages of the chosen type.</param>
157
+ /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
158
+ /// <note>
159
+ /// The transform function takes:
160
+ /// param1: Current message instance by reference
161
+ /// And returns: true if message handling should continue, false if message handling should be stopped.
162
+ /// </note>
163
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to intercept messages.</returns>
164
+ Action RegisterTargetedInterceptor<T>(TargetedInterceptor<T> interceptor, int priority = 0)
165
+ where T : ITargetedMessage;
166
+
167
+ /// <summary>
168
+ /// Registers the specified MessageHandler and transformer function as an interceptor for Messages of type T.
169
+ /// Whenever messages of that type are sent, interceptors will be ran in order by priority and then order of registration within
170
+ /// that priority, transforming that message into new, mutated types.
171
+ /// If any interceptor returns false, message handling is immediately stopped.
172
+ /// The message at the end of the transformations will be then sent to registered message handlers.
173
+ /// </summary>
174
+ /// <note>
175
+ /// Transformer function can return false to "cancel" the message being sent.
176
+ /// </note>
177
+ /// <typeparam name="T">Type of message to intercept.</typeparam>
178
+ /// <param name="interceptor">Transformation function to run on messages of the chosen type.</param>
179
+ /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
180
+ /// <note>
181
+ /// The transform function takes:
182
+ /// param1: Current message instance by reference
183
+ /// And returns: true if message handling should continue, false if message handling should be stopped.
184
+ /// </note>
185
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to intercept messages.</returns>
186
+ Action RegisterBroadcastInterceptor<T>(
187
+ BroadcastInterceptor<T> interceptor,
188
+ int priority = 0
189
+ )
190
+ where T : IBroadcastMessage;
191
+
192
+ /// <summary>
193
+ /// Registers the provided MessageHandler to post process Untargeted messages of the given type.
194
+ /// (This will run after all handlers run for the provided message).
195
+ /// </summary>
196
+ /// <typeparam name="T">Type of UntargetedMessage to post process.</typeparam>
197
+ /// <param name="messageHandler">MessageHandler to post process messages for.</param>
198
+ /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
199
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
200
+ Action RegisterUntargetedPostProcessor<T>(MessageHandler messageHandler, int priority = 0)
201
+ where T : IUntargetedMessage;
202
+
203
+ /// <summary>
204
+ /// Registers the provided MessageHandler to post process Targeted messages of the given type.
205
+ /// (This will run after all handlers run for the provided message).
206
+ /// </summary>
207
+ /// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
208
+ /// <param name="target">Target of messages to listen for.</param>
209
+ /// <param name="messageHandler">MessageHandler to post process messages for.</param>
210
+ /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
211
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
212
+ Action RegisterTargetedPostProcessor<T>(
213
+ InstanceId target,
214
+ MessageHandler messageHandler,
215
+ int priority = 0
216
+ )
217
+ where T : ITargetedMessage;
218
+
219
+ /// <summary>
220
+ /// Registers the provided MessageHandler to post process Targeted messages of the given type for all targets.
221
+ /// (This will run after all handlers run for the provided message).
222
+ /// </summary>
223
+ /// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
224
+ /// <param name="messageHandler">MessageHandler to post process messages for.</param>
225
+ /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
226
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
227
+ Action RegisterTargetedWithoutTargetingPostProcessor<T>(
228
+ MessageHandler messageHandler,
229
+ int priority = 0
230
+ )
231
+ where T : ITargetedMessage;
232
+
233
+ /// <summary>
234
+ /// Registers the provided MessageHandler to post process Targeted messages of the given type.
235
+ /// (This will run after all handlers run for the provided message).
236
+ /// </summary>
237
+ /// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
238
+ /// <param name="source">Source of messages to listen for.</param>
239
+ /// <param name="messageHandler">MessageHandler to post process messages for.</param>
240
+ /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
241
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
242
+ Action RegisterBroadcastPostProcessor<T>(
243
+ InstanceId source,
244
+ MessageHandler messageHandler,
245
+ int priority = 0
246
+ )
247
+ where T : IBroadcastMessage;
248
+
249
+ /// <summary>
250
+ /// Registers the provided MessageHandler to post process Targeted messages of the given type for all sources.
251
+ /// (This will run after all handlers run for the provided message).
252
+ /// </summary>
253
+ /// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
254
+ /// <param name="messageHandler">MessageHandler to post process messages for.</param>
255
+ /// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
256
+ /// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
257
+ Action RegisterBroadcastWithoutSourcePostProcessor<T>(
258
+ MessageHandler messageHandler,
259
+ int priority = 0
260
+ )
261
+ where T : IBroadcastMessage;
262
+
263
+ /// <summary>
264
+ /// Broadcasts an Untargeted message to all listeners registered to this bus.
265
+ /// </summary>
266
+ /// <param name="typedMessage">Message to broadcast.</param>
267
+ void UntypedUntargetedBroadcast(IUntargetedMessage typedMessage);
268
+
269
+ /// <summary>
270
+ /// Broadcasts a fast Untargeted message to all listeners registered to this bus.
271
+ /// </summary>
272
+ /// <param name="typedMessage">Message to broadcast.</param>
273
+
274
+ void UntargetedBroadcast<TMessage>(ref TMessage typedMessage)
275
+ where TMessage : IUntargetedMessage;
276
+
277
+ /// <summary>
278
+ /// Broadcasts a TargetedMessage to all listeners registered to this bus.
279
+ /// </summary>
280
+ /// <param name="target">Target to send the message to.</param>
281
+ /// <param name="typedMessage">Message to broadcast.</param>
282
+ void UntypedTargetedBroadcast(InstanceId target, ITargetedMessage typedMessage);
283
+
284
+ /// <summary>
285
+ /// Broadcasts a fast TargetedMessage to all listeners registered to this bus.
286
+ /// </summary>
287
+ /// <param name="target">Target to send the message to.</param>
288
+ /// <param name="typedMessage">Message to broadcast.</param>
289
+
290
+ void TargetedBroadcast<TMessage>(ref InstanceId target, ref TMessage typedMessage)
291
+ where TMessage : ITargetedMessage;
292
+
293
+ /// <summary>
294
+ /// Broadcasts a BroadcastMessage to all listeners registered to this bus.
295
+ /// </summary>
296
+ /// <param name="source">Source of the message.</param>
297
+ /// <param name="typedMessage">Message to broadcast.</param>
298
+ void UntypedSourcedBroadcast(InstanceId source, IBroadcastMessage typedMessage);
299
+
300
+ /// <summary>
301
+ /// Broadcasts a fast BroadcastMessage to all listeners registered to this bus.
302
+ /// </summary>
303
+ /// <param name="source">Source of the message.</param>
304
+ /// <param name="typedMessage">Message to broadcast.</param>
305
+
306
+ void SourcedBroadcast<TMessage>(ref InstanceId source, ref TMessage typedMessage)
307
+ where TMessage : IBroadcastMessage;
308
+ }
309
+ }