ObjXMPP  Check-in [99f879bb8e]

Overview
Comment:XMPPMulticastDelegate: Iterate over a copy of the delegates array
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 99f879bb8eab767a6862a39c7af66c245591e78472f9ebfa9d54b9f75e5b963a
User & Date: florob@babelmonkeys.de on 2013-06-05 19:00:13
Other Links: manifest | tags
Context
2013-06-05
19:01
XMPPDiscoEntity: Update JID on resource bind check-in: b0b4a4460a user: florob@babelmonkeys.de tags: trunk
19:00
XMPPMulticastDelegate: Iterate over a copy of the delegates array check-in: 99f879bb8e user: florob@babelmonkeys.de tags: trunk
2013-04-03
21:16
Add caps namespace to namespaces.h check-in: 50a225298f user: florob@babelmonkeys.de tags: trunk
Changes

Modified src/XMPPMulticastDelegate.h from [9827e55a83] to [6630339e62].

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
26
27
28
29
30
31
32

33
34
35
36
37
38
39







-








/**
 * \brief A class to provide multiple delegates in a single class
 */
@interface XMPPMulticastDelegate: OFObject
{
	OFDataArray *_delegates;
	size_t _handlerIndex;
}

/**
 * \brief Adds a delegate which should receive the broadcasts.
 *
 * \param delegate The delegate to add
 */

Modified src/XMPPMulticastDelegate.m from [f678339c69] to [3c26c3b049].

20
21
22
23
24
25
26

27
28
29
30
31
32
33
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34







+







 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#import <ObjFW/ObjFW.h>
#import <ObjFW/OFDataArray.h>

#import "XMPPMulticastDelegate.h"

@implementation XMPPMulticastDelegate
- init
{
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
107
108
109
110



111
112
113
114


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
107
108
109
110
111
112
113
114







115
116
117
118
119







-
-
-
-







-
-
+
+
+


-
-
+
+








-
-
-
-
-
-
-









-
-
+
+
+


-
-
+
+








-
-
-
-
-
-
-





	size_t i, count = [_delegates count];

	for (i = 0; i < count; i++) {
		if (items[i] != delegate)
			continue;

		[_delegates removeItemAtIndex: i];

		if (i <= _handlerIndex)
			_handlerIndex--;

		return;
	}
}

- (BOOL)broadcastSelector: (SEL)selector
	       withObject: (id)object
{
	size_t count = [_delegates count];
	id *items = [_delegates items];
	OFDataArray *currentDelegates = [_delegates copy];
	id *items = [currentDelegates items];
	size_t i, count = [currentDelegates count];
	BOOL handled = NO;

	for (_handlerIndex = 0; _handlerIndex < count; _handlerIndex++) {
		id responder = items[_handlerIndex];
	for (i = 0; i < count; i++) {
		id responder = items[i];

		if (![responder respondsToSelector: selector])
			continue;

		BOOL (*imp)(id, SEL, id) = (BOOL(*)(id, SEL, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object);

		/*
		 * Update count and items, since the handler might have changed
		 * them.
		 */
		count = [_delegates count];
		items = [_delegates items];
	}

	return handled;
}

- (BOOL)broadcastSelector: (SEL)selector
	       withObject: (id)object1
	       withObject: (id)object2
{
	size_t count = [_delegates count];
	id *items = [_delegates items];
	OFDataArray *currentDelegates = [_delegates copy];
	id *items = [currentDelegates items];
	size_t i, count = [currentDelegates count];
	BOOL handled = NO;

	for (_handlerIndex = 0; _handlerIndex < count; _handlerIndex++) {
		id responder = items[_handlerIndex];
	for (i = 0; i < count; i++) {
		id responder = items[i];

		if (![responder respondsToSelector: selector])
			continue;

		BOOL (*imp)(id, SEL, id, id) = (BOOL(*)(id, SEL, id, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object1, object2);

		/*
		 * Update count and items, since the handler might have changed
		 * them.
		 */
		count = [_delegates count];
		items = [_delegates items];
	}

	return handled;
}
@end