1
2
3
4
5
6
7
8
9
|
1
2
3
4
5
6
7
8
9
|
-
+
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
| ︙ | | |
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
-
+
|
{
self = [super init];
@try {
void *pool = objc_autoreleasePoolPush();
_name = [name copy];
_observer = [observer retain];
_observer = observer;
_selector = selector;
_object = [object retain];
_selectorHash = [[OFString stringWithUTF8String:
sel_getName(_selector)] hash];
objc_autoreleasePoolPop(pool);
|
| ︙ | | |
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
-
|
return self;
}
#endif
- (void)dealloc
{
[_name release];
[_observer release];
[_object release];
#ifdef OF_HAVE_BLOCKS
[_block release];
#endif
[super dealloc];
}
|
| ︙ | | |
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
-
-
-
-
+
+
+
-
+
+
+
+
+
+
+
+
-
+
|
object: object]
autorelease]];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_HAVE_BLOCKS
- (OFNotificationCenterHandle *)
addObserverForName: (OFNotificationName)name
object: (id)object
usingBlock: (OFNotificationCenterBlock)block
- (id)addObserverForName: (OFNotificationName)name
object: (id)object
usingBlock: (OFNotificationCenterBlock)block
{
void *pool = objc_autoreleasePoolPush();
OFNotificationCenterHandle *handle =
[[[OFNotificationCenterHandle alloc] initWithName: name
object: object
block: block]
autorelease];
[self of_addObserver: handle];
[handle retain];
objc_autoreleasePoolPop(pool);
return [handle autorelease];
}
#endif
- (void)removeObserver: (OFNotificationCenterHandle *)handle
- (void)removeObserver: (id)handle_
{
OFNotificationCenterHandle *handle;
void *pool;
if (![handle_ isKindOfClass: [OFNotificationCenterHandle class]])
@throw [OFInvalidArgumentException exception];
handle = handle_;
void *pool = objc_autoreleasePoolPush();
pool = objc_autoreleasePoolPush();
/* {} required to avoid -Wmisleading-indentation false positive. */
if (![handle isKindOfClass: [OFNotificationCenterHandle class]]) {
@throw [OFInvalidArgumentException exception];
}
#ifdef OF_HAVE_THREADS
|
| ︙ | | |
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
379
380
381
382
383
384
385
386
387
|
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
|
userInfo: userInfo]];
objc_autoreleasePoolPop(pool);
}
@end
@implementation OFDefaultNotificationCenter
- (instancetype)autorelease
{
return self;
}
OF_SINGLETON_METHODS
- (instancetype)retain
{
return self;
}
- (void)release
{
}
- (unsigned int)retainCount
{
return OFMaxRetainCount;
}
@end
|