24 @
typedef CPPostingStyle
46 @
typedef CPNotificationCoalescing
89 BOOL _runLoopLaunched;
98 #pragma mark Class methods 113 #pragma mark Init methods 122 if (
self = [super
init])
124 _notificationCenter = aNotificationCenter;
135 #pragma mark Enqueue methods 142 - (void)enqueueNotification:(
CPNotification)notification postingStyle:(CPPostingStyle)postingStyle
154 - (void)enqueueNotification:(
CPNotification)notification postingStyle:(CPPostingStyle)postingStyle coalesceMask:(CPNotificationCoalescing)coalesceMask forModes:(CPArray)modes
156 [
self _removeNotification:notification coalesceMask:coalesceMask];
158 switch (postingStyle)
161 [_postIdleNotifications addObject:notification];
165 [_postASAPNotifications addObject:notification];
169 [_postNowNotifications addObject:notification];
173 if ([_postIdleNotifications count] || [_postASAPNotifications count] || [_postNowNotifications count])
178 for (var i = [modes count] - 1; i >= 0; i--)
179 [[
CPRunLoop currentRunLoop] limitDateForMode:modes[i]];
185 #pragma mark Dequeue methods 192 - (void)dequeueNotificationsMatching:(
CPNotification)notification coalesceMask:(CPUInteger)coalesceMask
194 [
self _removeNotification:notification coalesceMask:coalesceMask];
199 #pragma mark RunLoop methods 206 if (!_runLoopLaunched)
208 [runLoop performSelector:@selector(_launchNotificationsInQueue) target:self argument:nil order:0 modes:[CPDefaultRunLoopMode]];
209 _runLoopLaunched = YES;
216 - (void)_launchNotificationsInQueue
218 _runLoopLaunched = NO;
220 if ([_postNowNotifications count])
222 [
self _launchNotificationsForArray:_postNowNotifications];
227 if ([_postASAPNotifications count])
229 [
self _launchNotificationsForArray:_postASAPNotifications];
234 if ([_postIdleNotifications count])
236 [
self _launchNotificationsForArray:_postIdleNotifications];
244 #pragma mark Posting methods 249 - (void)_launchNotificationsForArray:(CPArray)anArray
251 for (var i = [anArray count] - 1; i >= 0; i--)
253 var notification = anArray[i];
254 [_notificationCenter postNotification:notification];
257 [anArray removeAllObjects];
262 #pragma mark Remove methods 267 - (void)_removeNotification:(
CPNotification)notification coalesceMask:(CPUInteger)coalesceMask
269 [
self _removeNotification:notification coalesceMask:coalesceMask inNotifications:_postNowNotifications];
270 [
self _removeNotification:notification coalesceMask:coalesceMask inNotifications:_postASAPNotifications];
271 [
self _removeNotification:notification coalesceMask:coalesceMask inNotifications:_postIdleNotifications];
277 - (void)_removeNotification:(
CPNotification)aNotification coalesceMask:(CPUInteger)coalesceMask inNotifications:(CPArray)notifications
279 var notificationsToRemove = [],
281 sender = [aNotification
object];
283 for (var i = [notifications count] - 1; i >= 0; i--)
285 var notification = notifications[i];
287 if (notification == aNotification)
289 [notificationsToRemove addObject:notification];
298 if ([notification
object] == sender && [notification
name] ==
name)
299 [notificationsToRemove addObject:notification];
307 [notificationsToRemove addObject:notification];
314 if ([notification
object] == sender)
315 [notificationsToRemove addObject:notification];
321 [notifications removeObjectsInArray:notificationsToRemove];
The main run loop for the application.
id initWithNotificationCenter:(CPNotificationCenter aNotificationCenter)
var CPNotificationDefaultQueue
CPNotificationCenter defaultCenter()
CPPostingStyle CPPostWhenIdle
CPNotificationCoalescing CPNotificationNoCoalescing
CPNotificationQueue objects act as buffers for notification centers (instances of CPNotificationCente...
A notification that can be posted to a CPNotificationCenter.
void enqueueNotification:postingStyle:coalesceMask:forModes:(CPNotification notification, [postingStyle] CPPostingStyle postingStyle, [coalesceMask] CPNotificationCoalescing coalesceMask, [forModes] CPArray modes)
CPNotificationCoalescingOnSender
Sends messages (CPNotification) between objects.
CPNotificationCoalescingOnName