-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMDMulticastDelegate.h
More file actions
executable file
·106 lines (81 loc) · 2.87 KB
/
MDMulticastDelegate.h
File metadata and controls
executable file
·106 lines (81 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#import <Foundation/Foundation.h>
/**
* This class provides multicast delegate functionality. That is:
* - it provides a means for managing a list of delegates
* - any method invocations to an instance of this class are automatically forwarded to all delegates
*
* For example:
*
* // Make this method call on every added delegate (there may be several)
* [multicastDelegate cog:self didFindThing:thing];
*
* This allows multiple delegates to be added to an xmpp stream or any xmpp module,
* which in turn makes development easier as there can be proper separation of logically different code sections.
*
* In addition, this makes module development easier,
* as multiple delegates can usually be handled in a manner similar to the traditional single delegate paradigm.
*
* This class also provides proper support for GCD queues.
* So each delegate specifies which queue they would like their delegate invocations to be dispatched onto.
*
* All delegate dispatching is done asynchronously (which is a critically important architectural design).
**/
NS_ASSUME_NONNULL_BEGIN
@interface MDMulticastDelegate<__covariant DelegateType> : NSObject
/**
Add delegate with main queue.
@param delegate target to invoke
*/
- (void)addDelegate:(DelegateType)delegate;
/**
Add delegate with queue.
@param delegate target to invoke
@param delegateQueue queue to dispatch for invoking
*/
- (void)addDelegate:(DelegateType)delegate delegateQueue:(dispatch_queue_t)delegateQueue;
/**
Remove delegate and all of different queues for this delegate.
@param delegate target to remove
*/
- (void)removeDelegate:(DelegateType)delegate;
/**
Remove delegate and queue.
@param delegate target to remove
@param delegateQueue queue to dispatch for invoking
*/
- (void)removeDelegate:(DelegateType)delegate delegateQueue:(nullable dispatch_queue_t)delegateQueue;
/**
Remove all delegates and queues
*/
- (void)removeAllDelegates;
/**
Count of delegate items, maybe multiple queues of an delegate.
*/
- (NSUInteger)count;
/**
Count of delegates.
@param aClass class of delegate
*/
- (NSUInteger)countOfDelegates;
/**
Count of delegate items is kind of this class, maybe multiple queues of an delegate.
@param aClass class of delegate
*/
- (NSUInteger)countOfClass:(Class)aClass;
/**
Count of delegate items is repsonding this selector, maybe multiple queues of an delegate.
@param aSelector selector to repsond for delegates
*/
- (NSUInteger)countForSelector:(SEL)aSelector;
/**
Whether there is any delegate responding selector.
@param aSelector selector to repsond for delegates
*/
- (BOOL)hasDelegateThatRespondsToSelector:(SEL)aSelector;
/**
Enumerate all of delegates and queues
@param block block for selection of delegate item
*/
- (void)enumerateDelegatesAndQueuesUsingBlock:(void (^)(DelegateType delegate, dispatch_queue_t delegateQueue, BOOL *stop))block;
@end
NS_ASSUME_NONNULL_END