com.wallstop-studios.dxmessaging 2.0.0-rc10 → 2.0.0-rc12
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.
- package/Editor/SetupCscRsp.cs +29 -13
- package/README.md +10 -9
- package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs +2 -4
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs +2 -5
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs +2 -5
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs +2 -5
- package/Runtime/Core/Extensions/MessageExtensions.cs +83 -16
- package/Runtime/Core/MessageBus/MessageBus.cs +74 -74
- package/Runtime/Core/MessageBus/MessagingRegistration.cs +9 -4
- package/Runtime/Core/MessageHandler.cs +44 -1
- package/Runtime/Core/Messages/IBroadcastMessage.cs +2 -2
- package/Runtime/Core/Messages/ITargetedMessage.cs +2 -1
- package/Runtime/Core/Messages/IUntargetedMessage.cs +2 -1
- package/Runtime/Core/MessagingDebug.cs +0 -1
- package/Runtime/Unity/MessageAwareComponent.cs +1 -1
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs +36 -19
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs +37 -20
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs +37 -20
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs +38 -22
- package/Tests/Runtime/Core/GlobalAcceptAllTests.cs +32 -11
- package/Tests/Runtime/Core/MessagingTestBase.cs +36 -15
- package/Tests/Runtime/Core/NominalTests.cs +320 -98
- package/Tests/Runtime/Core/PostProcessorTests.cs +468 -81
- package/Tests/Runtime/Core/RegistrationTests.cs +390 -119
- package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +62 -16
- package/Tests/Runtime/Scripts/Messages/ComplexTargetedMessage.cs +1 -1
- package/Tests/Runtime/Scripts/Messages/SimpleBroadcastMessage.cs +1 -1
- package/Tests/Runtime/Scripts/Messages/SimpleTargetedMessage.cs +1 -1
- package/Tests/Runtime/Scripts/Messages/SimpleUntargetedMessage.cs +1 -1
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.asmdef +22 -22
- package/package.json +2 -2
- package/com.wallstop-studios.dxmessaging.sln +0 -39
- package/com.wallstop-studios.dxmessaging.sln.meta +0 -7
|
@@ -33,38 +33,38 @@
|
|
|
33
33
|
|
|
34
34
|
public RegistrationLog Log => _log;
|
|
35
35
|
|
|
36
|
-
private readonly Dictionary<Type, SortedList<int,
|
|
36
|
+
private readonly Dictionary<Type, SortedList<int, SortedList<MessageHandler, int>>> _sinks =
|
|
37
37
|
new();
|
|
38
38
|
private readonly Dictionary<
|
|
39
39
|
Type,
|
|
40
|
-
Dictionary<InstanceId, SortedList<int,
|
|
40
|
+
Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>
|
|
41
41
|
> _targetedSinks = new();
|
|
42
42
|
|
|
43
43
|
private readonly Dictionary<
|
|
44
44
|
Type,
|
|
45
|
-
Dictionary<InstanceId, SortedList<int,
|
|
45
|
+
Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>
|
|
46
46
|
> _broadcastSinks = new();
|
|
47
47
|
private readonly Dictionary<
|
|
48
48
|
Type,
|
|
49
|
-
SortedList<int,
|
|
49
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
50
50
|
> _postProcessingSinks = new();
|
|
51
51
|
private readonly Dictionary<
|
|
52
52
|
Type,
|
|
53
|
-
Dictionary<InstanceId, SortedList<int,
|
|
53
|
+
Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>
|
|
54
54
|
> _postProcessingTargetedSinks = new();
|
|
55
55
|
private readonly Dictionary<
|
|
56
56
|
Type,
|
|
57
|
-
Dictionary<InstanceId, SortedList<int,
|
|
57
|
+
Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>
|
|
58
58
|
> _postProcessingBroadcastSinks = new();
|
|
59
59
|
private readonly Dictionary<
|
|
60
60
|
Type,
|
|
61
|
-
SortedList<int,
|
|
61
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
62
62
|
> _postProcessingTargetedWithoutTargetingSinks = new();
|
|
63
63
|
private readonly Dictionary<
|
|
64
64
|
Type,
|
|
65
|
-
SortedList<int,
|
|
65
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
66
66
|
> _postProcessingBroadcastWithoutSourceSinks = new();
|
|
67
|
-
private readonly
|
|
67
|
+
private readonly SortedList<MessageHandler, int> _globalSinks = new();
|
|
68
68
|
private readonly Dictionary<Type, SortedList<int, List<object>>> _interceptsByType = new();
|
|
69
69
|
private readonly Dictionary<object, Dictionary<int, int>> _uniqueInterceptorsAndPriorities =
|
|
70
70
|
new();
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
// These are used so we aren't allocating as much every time we send messages
|
|
77
77
|
private readonly Stack<List<MessageHandler>> _messageHandlers = new();
|
|
78
78
|
private readonly Stack<
|
|
79
|
-
List<KeyValuePair<int,
|
|
79
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>>
|
|
80
80
|
> _sortedHandlers = new();
|
|
81
81
|
private readonly Stack<List<List<object>>> _interceptors = new();
|
|
82
82
|
private readonly Stack<List<object>> _innerInterceptorsStack = new();
|
|
@@ -458,7 +458,7 @@
|
|
|
458
458
|
if (
|
|
459
459
|
_postProcessingSinks.TryGetValue(
|
|
460
460
|
type,
|
|
461
|
-
out SortedList<int,
|
|
461
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
462
462
|
)
|
|
463
463
|
&& 0 < sortedHandlers.Count
|
|
464
464
|
)
|
|
@@ -466,18 +466,18 @@
|
|
|
466
466
|
foundAnyHandlers = true;
|
|
467
467
|
if (sortedHandlers.Count == 1)
|
|
468
468
|
{
|
|
469
|
-
KeyValuePair<int,
|
|
469
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry =
|
|
470
470
|
sortedHandlers.First();
|
|
471
471
|
RunUntargetedPostProcessing(ref typedMessage, entry.Key, entry.Value);
|
|
472
472
|
}
|
|
473
473
|
else
|
|
474
474
|
{
|
|
475
|
-
List<KeyValuePair<int,
|
|
475
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
476
476
|
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
477
477
|
try
|
|
478
478
|
{
|
|
479
479
|
foreach (
|
|
480
|
-
KeyValuePair<int,
|
|
480
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
481
481
|
)
|
|
482
482
|
{
|
|
483
483
|
RunUntargetedPostProcessing(ref typedMessage, entry.Key, entry.Value);
|
|
@@ -503,7 +503,7 @@
|
|
|
503
503
|
private void RunUntargetedPostProcessing<TMessage>(
|
|
504
504
|
ref TMessage typedMessage,
|
|
505
505
|
int priority,
|
|
506
|
-
|
|
506
|
+
SortedList<MessageHandler, int> handlers
|
|
507
507
|
)
|
|
508
508
|
where TMessage : IUntargetedMessage
|
|
509
509
|
{
|
|
@@ -594,12 +594,12 @@
|
|
|
594
594
|
type,
|
|
595
595
|
out Dictionary<
|
|
596
596
|
InstanceId,
|
|
597
|
-
SortedList<int,
|
|
597
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
598
598
|
> targetedHandlers
|
|
599
599
|
)
|
|
600
600
|
&& targetedHandlers.TryGetValue(
|
|
601
601
|
target,
|
|
602
|
-
out SortedList<int,
|
|
602
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
603
603
|
)
|
|
604
604
|
&& 0 < sortedHandlers.Count
|
|
605
605
|
)
|
|
@@ -607,18 +607,18 @@
|
|
|
607
607
|
foundAnyHandlers = true;
|
|
608
608
|
if (sortedHandlers.Count == 1)
|
|
609
609
|
{
|
|
610
|
-
KeyValuePair<int,
|
|
610
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry =
|
|
611
611
|
sortedHandlers.First();
|
|
612
612
|
RunTargetedBroadcast(ref target, ref typedMessage, entry.Key, entry.Value);
|
|
613
613
|
}
|
|
614
614
|
else
|
|
615
615
|
{
|
|
616
|
-
List<KeyValuePair<int,
|
|
616
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
617
617
|
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
618
618
|
try
|
|
619
619
|
{
|
|
620
620
|
foreach (
|
|
621
|
-
KeyValuePair<int,
|
|
621
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
622
622
|
)
|
|
623
623
|
{
|
|
624
624
|
RunTargetedBroadcast(
|
|
@@ -647,18 +647,18 @@
|
|
|
647
647
|
foundAnyHandlers = true;
|
|
648
648
|
if (sortedHandlers.Count == 1)
|
|
649
649
|
{
|
|
650
|
-
KeyValuePair<int,
|
|
650
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry =
|
|
651
651
|
sortedHandlers.First();
|
|
652
652
|
RunTargetedPostProcessing(ref target, ref typedMessage, entry.Key, entry.Value);
|
|
653
653
|
}
|
|
654
654
|
else
|
|
655
655
|
{
|
|
656
|
-
List<KeyValuePair<int,
|
|
656
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
657
657
|
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
658
658
|
try
|
|
659
659
|
{
|
|
660
660
|
foreach (
|
|
661
|
-
KeyValuePair<int,
|
|
661
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
662
662
|
)
|
|
663
663
|
{
|
|
664
664
|
RunTargetedPostProcessing(
|
|
@@ -683,7 +683,7 @@
|
|
|
683
683
|
{
|
|
684
684
|
if (sortedHandlers.Count == 1)
|
|
685
685
|
{
|
|
686
|
-
KeyValuePair<int,
|
|
686
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry =
|
|
687
687
|
sortedHandlers.First();
|
|
688
688
|
RunTargetedWithoutTargetingPostProcessing(
|
|
689
689
|
ref target,
|
|
@@ -694,12 +694,12 @@
|
|
|
694
694
|
}
|
|
695
695
|
else
|
|
696
696
|
{
|
|
697
|
-
List<KeyValuePair<int,
|
|
697
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
698
698
|
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
699
699
|
try
|
|
700
700
|
{
|
|
701
701
|
foreach (
|
|
702
|
-
KeyValuePair<int,
|
|
702
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
703
703
|
)
|
|
704
704
|
{
|
|
705
705
|
RunTargetedWithoutTargetingPostProcessing(
|
|
@@ -732,7 +732,7 @@
|
|
|
732
732
|
ref InstanceId target,
|
|
733
733
|
ref TMessage typedMessage,
|
|
734
734
|
int priority,
|
|
735
|
-
|
|
735
|
+
SortedList<MessageHandler, int> handlers
|
|
736
736
|
)
|
|
737
737
|
where TMessage : ITargetedMessage
|
|
738
738
|
{
|
|
@@ -784,7 +784,7 @@
|
|
|
784
784
|
ref InstanceId target,
|
|
785
785
|
ref TMessage typedMessage,
|
|
786
786
|
int priority,
|
|
787
|
-
|
|
787
|
+
SortedList<MessageHandler, int> handlers
|
|
788
788
|
)
|
|
789
789
|
where TMessage : ITargetedMessage
|
|
790
790
|
{
|
|
@@ -836,7 +836,7 @@
|
|
|
836
836
|
ref InstanceId target,
|
|
837
837
|
ref TMessage typedMessage,
|
|
838
838
|
int priority,
|
|
839
|
-
|
|
839
|
+
SortedList<MessageHandler, int> handlers
|
|
840
840
|
)
|
|
841
841
|
where TMessage : ITargetedMessage
|
|
842
842
|
{
|
|
@@ -926,12 +926,12 @@
|
|
|
926
926
|
type,
|
|
927
927
|
out Dictionary<
|
|
928
928
|
InstanceId,
|
|
929
|
-
SortedList<int,
|
|
929
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
930
930
|
> broadcastHandlers
|
|
931
931
|
)
|
|
932
932
|
&& broadcastHandlers.TryGetValue(
|
|
933
933
|
source,
|
|
934
|
-
out SortedList<int,
|
|
934
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
935
935
|
)
|
|
936
936
|
&& 0 < sortedHandlers.Count
|
|
937
937
|
)
|
|
@@ -939,18 +939,18 @@
|
|
|
939
939
|
foundAnyHandlers = true;
|
|
940
940
|
if (sortedHandlers.Count == 1)
|
|
941
941
|
{
|
|
942
|
-
KeyValuePair<int,
|
|
942
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry =
|
|
943
943
|
sortedHandlers.First();
|
|
944
944
|
RunBroadcast(ref source, ref typedMessage, entry.Key, entry.Value);
|
|
945
945
|
}
|
|
946
946
|
else
|
|
947
947
|
{
|
|
948
|
-
List<KeyValuePair<int,
|
|
948
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
949
949
|
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
950
950
|
try
|
|
951
951
|
{
|
|
952
952
|
foreach (
|
|
953
|
-
KeyValuePair<int,
|
|
953
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
954
954
|
)
|
|
955
955
|
{
|
|
956
956
|
RunBroadcast(ref source, ref typedMessage, entry.Key, entry.Value);
|
|
@@ -974,7 +974,7 @@
|
|
|
974
974
|
foundAnyHandlers = true;
|
|
975
975
|
if (sortedHandlers.Count == 1)
|
|
976
976
|
{
|
|
977
|
-
KeyValuePair<int,
|
|
977
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry =
|
|
978
978
|
sortedHandlers.First();
|
|
979
979
|
RunBroadcastPostProcessing(
|
|
980
980
|
ref source,
|
|
@@ -985,12 +985,12 @@
|
|
|
985
985
|
}
|
|
986
986
|
else
|
|
987
987
|
{
|
|
988
|
-
List<KeyValuePair<int,
|
|
988
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
989
989
|
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
990
990
|
try
|
|
991
991
|
{
|
|
992
992
|
foreach (
|
|
993
|
-
KeyValuePair<int,
|
|
993
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
994
994
|
)
|
|
995
995
|
{
|
|
996
996
|
RunBroadcastPostProcessing(
|
|
@@ -1015,7 +1015,7 @@
|
|
|
1015
1015
|
{
|
|
1016
1016
|
if (sortedHandlers.Count == 1)
|
|
1017
1017
|
{
|
|
1018
|
-
KeyValuePair<int,
|
|
1018
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry =
|
|
1019
1019
|
sortedHandlers.First();
|
|
1020
1020
|
RunBroadcastWithoutSourcePostProcessing(
|
|
1021
1021
|
ref source,
|
|
@@ -1026,12 +1026,12 @@
|
|
|
1026
1026
|
}
|
|
1027
1027
|
else
|
|
1028
1028
|
{
|
|
1029
|
-
List<KeyValuePair<int,
|
|
1029
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
1030
1030
|
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
1031
1031
|
try
|
|
1032
1032
|
{
|
|
1033
1033
|
foreach (
|
|
1034
|
-
KeyValuePair<int,
|
|
1034
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
1035
1035
|
)
|
|
1036
1036
|
{
|
|
1037
1037
|
RunBroadcastWithoutSourcePostProcessing(
|
|
@@ -1064,7 +1064,7 @@
|
|
|
1064
1064
|
ref InstanceId source,
|
|
1065
1065
|
ref TMessage typedMessage,
|
|
1066
1066
|
int priority,
|
|
1067
|
-
|
|
1067
|
+
SortedList<MessageHandler, int> handlers
|
|
1068
1068
|
)
|
|
1069
1069
|
where TMessage : IBroadcastMessage
|
|
1070
1070
|
{
|
|
@@ -1116,7 +1116,7 @@
|
|
|
1116
1116
|
ref InstanceId source,
|
|
1117
1117
|
ref TMessage typedMessage,
|
|
1118
1118
|
int priority,
|
|
1119
|
-
|
|
1119
|
+
SortedList<MessageHandler, int> handlers
|
|
1120
1120
|
)
|
|
1121
1121
|
where TMessage : IBroadcastMessage
|
|
1122
1122
|
{
|
|
@@ -1168,7 +1168,7 @@
|
|
|
1168
1168
|
ref InstanceId source,
|
|
1169
1169
|
ref TMessage typedMessage,
|
|
1170
1170
|
int priority,
|
|
1171
|
-
|
|
1171
|
+
SortedList<MessageHandler, int> handlers
|
|
1172
1172
|
)
|
|
1173
1173
|
where TMessage : IBroadcastMessage
|
|
1174
1174
|
{
|
|
@@ -1498,7 +1498,7 @@
|
|
|
1498
1498
|
if (
|
|
1499
1499
|
!_sinks.TryGetValue(
|
|
1500
1500
|
type,
|
|
1501
|
-
out SortedList<int,
|
|
1501
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
1502
1502
|
)
|
|
1503
1503
|
|| sortedHandlers.Count <= 0
|
|
1504
1504
|
)
|
|
@@ -1508,16 +1508,16 @@
|
|
|
1508
1508
|
|
|
1509
1509
|
if (sortedHandlers.Count == 1)
|
|
1510
1510
|
{
|
|
1511
|
-
KeyValuePair<int,
|
|
1511
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry = sortedHandlers.First();
|
|
1512
1512
|
RunUntargetedBroadcast(ref message, entry.Key, entry.Value);
|
|
1513
1513
|
return true;
|
|
1514
1514
|
}
|
|
1515
1515
|
|
|
1516
|
-
List<KeyValuePair<int,
|
|
1516
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
1517
1517
|
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
1518
1518
|
try
|
|
1519
1519
|
{
|
|
1520
|
-
foreach (KeyValuePair<int,
|
|
1520
|
+
foreach (KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList)
|
|
1521
1521
|
{
|
|
1522
1522
|
RunUntargetedBroadcast(ref message, entry.Key, entry.Value);
|
|
1523
1523
|
}
|
|
@@ -1533,7 +1533,7 @@
|
|
|
1533
1533
|
private void RunUntargetedBroadcast<TMessage>(
|
|
1534
1534
|
ref TMessage message,
|
|
1535
1535
|
int priority,
|
|
1536
|
-
|
|
1536
|
+
SortedList<MessageHandler, int> handlers
|
|
1537
1537
|
)
|
|
1538
1538
|
where TMessage : IMessage
|
|
1539
1539
|
{
|
|
@@ -1581,7 +1581,7 @@
|
|
|
1581
1581
|
if (
|
|
1582
1582
|
!_sinks.TryGetValue(
|
|
1583
1583
|
type,
|
|
1584
|
-
out SortedList<int,
|
|
1584
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
1585
1585
|
)
|
|
1586
1586
|
|| sortedHandlers.Count <= 0
|
|
1587
1587
|
)
|
|
@@ -1591,16 +1591,16 @@
|
|
|
1591
1591
|
|
|
1592
1592
|
if (sortedHandlers.Count == 1)
|
|
1593
1593
|
{
|
|
1594
|
-
KeyValuePair<int,
|
|
1594
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry = sortedHandlers.First();
|
|
1595
1595
|
RunTargetedWithoutTargeting(ref target, ref message, entry.Key, entry.Value);
|
|
1596
1596
|
return true;
|
|
1597
1597
|
}
|
|
1598
1598
|
|
|
1599
|
-
List<KeyValuePair<int,
|
|
1599
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
1600
1600
|
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
1601
1601
|
try
|
|
1602
1602
|
{
|
|
1603
|
-
foreach (KeyValuePair<int,
|
|
1603
|
+
foreach (KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList)
|
|
1604
1604
|
{
|
|
1605
1605
|
RunTargetedWithoutTargeting(ref target, ref message, entry.Key, entry.Value);
|
|
1606
1606
|
}
|
|
@@ -1617,7 +1617,7 @@
|
|
|
1617
1617
|
ref InstanceId target,
|
|
1618
1618
|
ref TMessage message,
|
|
1619
1619
|
int priority,
|
|
1620
|
-
|
|
1620
|
+
SortedList<MessageHandler, int> handlers
|
|
1621
1621
|
)
|
|
1622
1622
|
where TMessage : ITargetedMessage
|
|
1623
1623
|
{
|
|
@@ -1670,7 +1670,7 @@
|
|
|
1670
1670
|
if (
|
|
1671
1671
|
!_sinks.TryGetValue(
|
|
1672
1672
|
type,
|
|
1673
|
-
out SortedList<int,
|
|
1673
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
1674
1674
|
)
|
|
1675
1675
|
|| sortedHandlers.Count <= 0
|
|
1676
1676
|
)
|
|
@@ -1680,16 +1680,16 @@
|
|
|
1680
1680
|
|
|
1681
1681
|
if (sortedHandlers.Count == 1)
|
|
1682
1682
|
{
|
|
1683
|
-
KeyValuePair<int,
|
|
1683
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry = sortedHandlers.First();
|
|
1684
1684
|
RunBroadcastWithoutSource(ref source, ref message, entry.Key, entry.Value);
|
|
1685
1685
|
return true;
|
|
1686
1686
|
}
|
|
1687
1687
|
|
|
1688
|
-
List<KeyValuePair<int,
|
|
1688
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
1689
1689
|
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
1690
1690
|
try
|
|
1691
1691
|
{
|
|
1692
|
-
foreach (KeyValuePair<int,
|
|
1692
|
+
foreach (KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList)
|
|
1693
1693
|
{
|
|
1694
1694
|
RunBroadcastWithoutSource(ref source, ref message, entry.Key, entry.Value);
|
|
1695
1695
|
}
|
|
@@ -1706,7 +1706,7 @@
|
|
|
1706
1706
|
ref InstanceId source,
|
|
1707
1707
|
ref TMessage message,
|
|
1708
1708
|
int priority,
|
|
1709
|
-
|
|
1709
|
+
SortedList<MessageHandler, int> handlers
|
|
1710
1710
|
)
|
|
1711
1711
|
where TMessage : IBroadcastMessage
|
|
1712
1712
|
{
|
|
@@ -1756,7 +1756,7 @@
|
|
|
1756
1756
|
|
|
1757
1757
|
private Action InternalRegisterUntargeted<T>(
|
|
1758
1758
|
MessageHandler messageHandler,
|
|
1759
|
-
Dictionary<Type, SortedList<int,
|
|
1759
|
+
Dictionary<Type, SortedList<int, SortedList<MessageHandler, int>>> sinks,
|
|
1760
1760
|
RegistrationMethod registrationMethod,
|
|
1761
1761
|
int priority
|
|
1762
1762
|
)
|
|
@@ -1773,17 +1773,17 @@
|
|
|
1773
1773
|
if (
|
|
1774
1774
|
!sinks.TryGetValue(
|
|
1775
1775
|
type,
|
|
1776
|
-
out SortedList<int,
|
|
1776
|
+
out SortedList<int, SortedList<MessageHandler, int>> handlers
|
|
1777
1777
|
)
|
|
1778
1778
|
)
|
|
1779
1779
|
{
|
|
1780
|
-
handlers = new SortedList<int,
|
|
1780
|
+
handlers = new SortedList<int, SortedList<MessageHandler, int>>();
|
|
1781
1781
|
sinks[type] = handlers;
|
|
1782
1782
|
}
|
|
1783
1783
|
|
|
1784
|
-
if (!handlers.TryGetValue(priority, out
|
|
1784
|
+
if (!handlers.TryGetValue(priority, out SortedList<MessageHandler, int> handler))
|
|
1785
1785
|
{
|
|
1786
|
-
handler = new
|
|
1786
|
+
handler = new SortedList<MessageHandler, int>();
|
|
1787
1787
|
handlers[priority] = handler;
|
|
1788
1788
|
}
|
|
1789
1789
|
|
|
@@ -1860,7 +1860,7 @@
|
|
|
1860
1860
|
MessageHandler messageHandler,
|
|
1861
1861
|
Dictionary<
|
|
1862
1862
|
Type,
|
|
1863
|
-
Dictionary<InstanceId, SortedList<int,
|
|
1863
|
+
Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>
|
|
1864
1864
|
> sinks,
|
|
1865
1865
|
RegistrationMethod registrationMethod,
|
|
1866
1866
|
int priority
|
|
@@ -1877,30 +1877,30 @@
|
|
|
1877
1877
|
type,
|
|
1878
1878
|
out Dictionary<
|
|
1879
1879
|
InstanceId,
|
|
1880
|
-
SortedList<int,
|
|
1880
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
1881
1881
|
> broadcastHandlers
|
|
1882
1882
|
)
|
|
1883
1883
|
)
|
|
1884
1884
|
{
|
|
1885
1885
|
broadcastHandlers =
|
|
1886
|
-
new Dictionary<InstanceId, SortedList<int,
|
|
1886
|
+
new Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>();
|
|
1887
1887
|
sinks[type] = broadcastHandlers;
|
|
1888
1888
|
}
|
|
1889
1889
|
|
|
1890
1890
|
if (
|
|
1891
1891
|
!broadcastHandlers.TryGetValue(
|
|
1892
1892
|
context,
|
|
1893
|
-
out SortedList<int,
|
|
1893
|
+
out SortedList<int, SortedList<MessageHandler, int>> handlers
|
|
1894
1894
|
)
|
|
1895
1895
|
)
|
|
1896
1896
|
{
|
|
1897
|
-
handlers = new SortedList<int,
|
|
1897
|
+
handlers = new SortedList<int, SortedList<MessageHandler, int>>();
|
|
1898
1898
|
broadcastHandlers[context] = handlers;
|
|
1899
1899
|
}
|
|
1900
1900
|
|
|
1901
|
-
if (!handlers.TryGetValue(priority, out
|
|
1901
|
+
if (!handlers.TryGetValue(priority, out SortedList<MessageHandler, int> handler))
|
|
1902
1902
|
{
|
|
1903
|
-
handler = new
|
|
1903
|
+
handler = new SortedList<MessageHandler, int>();
|
|
1904
1904
|
handlers[priority] = handler;
|
|
1905
1905
|
}
|
|
1906
1906
|
|
|
@@ -1978,18 +1978,18 @@
|
|
|
1978
1978
|
}
|
|
1979
1979
|
|
|
1980
1980
|
private List<
|
|
1981
|
-
KeyValuePair<int,
|
|
1981
|
+
KeyValuePair<int, SortedList<MessageHandler, int>>
|
|
1982
1982
|
> GetOrAddMessageHandlerStack(
|
|
1983
|
-
IEnumerable<KeyValuePair<int,
|
|
1983
|
+
IEnumerable<KeyValuePair<int, SortedList<MessageHandler, int>>> handlers
|
|
1984
1984
|
)
|
|
1985
1985
|
{
|
|
1986
1986
|
if (
|
|
1987
1987
|
!_sortedHandlers.TryPop(
|
|
1988
|
-
out List<KeyValuePair<int,
|
|
1988
|
+
out List<KeyValuePair<int, SortedList<MessageHandler, int>>> messageHandlers
|
|
1989
1989
|
)
|
|
1990
1990
|
)
|
|
1991
1991
|
{
|
|
1992
|
-
return new List<KeyValuePair<int,
|
|
1992
|
+
return new List<KeyValuePair<int, SortedList<MessageHandler, int>>>(handlers);
|
|
1993
1993
|
}
|
|
1994
1994
|
|
|
1995
1995
|
messageHandlers.Clear();
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
public enum RegistrationType
|
|
10
10
|
{
|
|
11
11
|
Register,
|
|
12
|
-
Deregister
|
|
12
|
+
Deregister,
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/// <summary>
|
|
@@ -72,7 +72,12 @@
|
|
|
72
72
|
/// <param name="type">Type of Message.</param>
|
|
73
73
|
/// <param name="registrationType">Register? Deregister?</param>
|
|
74
74
|
/// <param name="registrationMethod">How the Message was chosen to be listened for.</param>
|
|
75
|
-
public MessagingRegistration(
|
|
75
|
+
public MessagingRegistration(
|
|
76
|
+
InstanceId id,
|
|
77
|
+
Type type,
|
|
78
|
+
RegistrationType registrationType,
|
|
79
|
+
RegistrationMethod registrationMethod
|
|
80
|
+
)
|
|
76
81
|
{
|
|
77
82
|
this.id = id;
|
|
78
83
|
this.type = type;
|
|
@@ -91,9 +96,9 @@
|
|
|
91
96
|
time,
|
|
92
97
|
#endif
|
|
93
98
|
id,
|
|
94
|
-
type,
|
|
99
|
+
type,
|
|
95
100
|
registrationType,
|
|
96
|
-
registrationMethod
|
|
101
|
+
registrationMethod,
|
|
97
102
|
}.ToString();
|
|
98
103
|
}
|
|
99
104
|
}
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
/// kinds of types to trigger functions that are registered with it.
|
|
13
13
|
/// </summary>
|
|
14
14
|
public sealed class MessageHandler
|
|
15
|
+
: IEquatable<MessageHandler>,
|
|
16
|
+
IComparable,
|
|
17
|
+
IComparable<MessageHandler>
|
|
15
18
|
{
|
|
16
19
|
public delegate void FastHandler<TMessage>(ref TMessage message)
|
|
17
20
|
where TMessage : IMessage;
|
|
@@ -1220,6 +1223,46 @@
|
|
|
1220
1223
|
return (messageBus ?? MessageBus).RegisterTargetedInterceptor(interceptor, priority);
|
|
1221
1224
|
}
|
|
1222
1225
|
|
|
1226
|
+
public override bool Equals(object obj)
|
|
1227
|
+
{
|
|
1228
|
+
return Equals(obj as MessageHandler);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
public bool Equals(MessageHandler other)
|
|
1232
|
+
{
|
|
1233
|
+
if (other == null)
|
|
1234
|
+
{
|
|
1235
|
+
return false;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
if (ReferenceEquals(other, this))
|
|
1239
|
+
{
|
|
1240
|
+
return true;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
return owner.Equals(other.owner);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
public override int GetHashCode()
|
|
1247
|
+
{
|
|
1248
|
+
return owner.GetHashCode();
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
public int CompareTo(MessageHandler other)
|
|
1252
|
+
{
|
|
1253
|
+
if (other == null)
|
|
1254
|
+
{
|
|
1255
|
+
return -1;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
return owner.CompareTo(other.owner);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
public int CompareTo(object obj)
|
|
1262
|
+
{
|
|
1263
|
+
return CompareTo(obj as MessageHandler);
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1223
1266
|
public override string ToString()
|
|
1224
1267
|
{
|
|
1225
1268
|
return new
|
|
@@ -1231,7 +1274,7 @@
|
|
|
1231
1274
|
.Values.SelectMany(handlers => handlers.Keys)
|
|
1232
1275
|
.Distinct()
|
|
1233
1276
|
.Select(type => type.Name)
|
|
1234
|
-
.OrderBy(
|
|
1277
|
+
.OrderBy(x => x)
|
|
1235
1278
|
),
|
|
1236
1279
|
}.ToString();
|
|
1237
1280
|
}
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
/// </code>
|
|
20
20
|
/// </summary>
|
|
21
21
|
/// <typeparam name="T">Concrete type of the derived. Should be the derived type and nothing else.</typeparam>
|
|
22
|
-
public interface IBroadcastMessage<T> : IBroadcastMessage
|
|
22
|
+
public interface IBroadcastMessage<T> : IBroadcastMessage
|
|
23
|
+
where T : IBroadcastMessage
|
|
23
24
|
{
|
|
24
25
|
Type IMessage.MessageType => typeof(T);
|
|
25
26
|
}
|
|
26
|
-
|
|
27
27
|
}
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
/// </code>
|
|
20
20
|
/// </summary>
|
|
21
21
|
/// <typeparam name="T">Concrete type of the derived. Should be the derived type and nothing else.</typeparam>
|
|
22
|
-
public interface ITargetedMessage<T> : ITargetedMessage
|
|
22
|
+
public interface ITargetedMessage<T> : ITargetedMessage
|
|
23
|
+
where T : ITargetedMessage
|
|
23
24
|
{
|
|
24
25
|
Type IMessage.MessageType => typeof(T);
|
|
25
26
|
}
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
/// </code>
|
|
20
20
|
/// </summary>
|
|
21
21
|
/// <typeparam name="T">Concrete type of the derived. Should be the derived type and nothing else.</typeparam>
|
|
22
|
-
public interface IUntargetedMessage<T> : IUntargetedMessage
|
|
22
|
+
public interface IUntargetedMessage<T> : IUntargetedMessage
|
|
23
|
+
where T : IUntargetedMessage
|
|
23
24
|
{
|
|
24
25
|
Type IMessage.MessageType => typeof(T);
|
|
25
26
|
}
|