1997-09-01 21:59:51 +00:00
|
|
|
|
/*
|
|
|
|
|
NSNotificationQueue.m
|
|
|
|
|
|
|
|
|
|
Copyright (C) 1995, 1996 Ovidiu Predescu and Mircea Oancea.
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Author: Mircea Oancea <mircea@jupiter.elcom.pub.ro>
|
|
|
|
|
|
|
|
|
|
This file is part of libFoundation.
|
|
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
|
documentation for any purpose and without fee is hereby granted, provided
|
|
|
|
|
that the above copyright notice appear in all copies and that both that
|
|
|
|
|
copyright notice and this permission notice appear in supporting
|
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
|
|
We disclaim all warranties with regard to this software, including all
|
|
|
|
|
implied warranties of merchantability and fitness, in no event shall
|
|
|
|
|
we be liable for any special, indirect or consequential damages or any
|
|
|
|
|
damages whatsoever resulting from loss of use, data or profits, whether in
|
|
|
|
|
an action of contract, negligence or other tortious action, arising out of
|
|
|
|
|
or in connection with the use or performance of this software.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Implementation for NSNotificationQueue for GNUStep
|
1999-07-14 19:31:28 +00:00
|
|
|
|
Copyright (C) 1997-1999 Free Software Foundation, Inc.
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
|
|
Modified by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
|
Date: 1997
|
1999-07-14 19:31:28 +00:00
|
|
|
|
Rewritten: 1999
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
1999-08-20 15:21:59 +00:00
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
1997-09-01 21:59:51 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
|
#include <config.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
|
#include <base/preface.h>
|
1997-09-01 21:59:51 +00:00
|
|
|
|
#include <Foundation/NSRunLoop.h>
|
|
|
|
|
#include <Foundation/NSNotificationQueue.h>
|
|
|
|
|
#include <Foundation/NSNotification.h>
|
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
|
#include <Foundation/NSThread.h>
|
|
|
|
|
|
|
|
|
|
/* NotificationQueueList by Richard Frith-Macdonald
|
|
|
|
|
These objects are used to maintain lists of NSNotificationQueue objects.
|
|
|
|
|
There is one list per NSThread, with the first object in the list stored
|
|
|
|
|
in the thread dictionary and accessed using the key below.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static NSString* tkey = @"NotificationQueueListThreadKey";
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
typedef struct {
|
|
|
|
|
@defs(NSNotificationQueue)
|
|
|
|
|
} *accessQueue;
|
|
|
|
|
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
@interface NotificationQueueList : NSObject
|
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
@public
|
|
|
|
|
NotificationQueueList *next;
|
|
|
|
|
NSNotificationQueue *queue;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
1999-04-20 16:28:04 +00:00
|
|
|
|
+ (void) registerQueue: (NSNotificationQueue*)q;
|
|
|
|
|
+ (void) unregisterQueue: (NSNotificationQueue*)q;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
@end
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
static NotificationQueueList*
|
|
|
|
|
currentList()
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
NotificationQueueList *list;
|
|
|
|
|
NSMutableDictionary *d;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
d = GSCurrentThreadDictionary();
|
|
|
|
|
list = (NotificationQueueList*)[d objectForKey: tkey];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
if (list == nil)
|
|
|
|
|
{
|
|
|
|
|
list = [NotificationQueueList new];
|
1999-04-20 16:28:04 +00:00
|
|
|
|
[d setObject: list forKey: tkey];
|
|
|
|
|
RELEASE(list); /* retained in dictionary. */
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
@implementation NotificationQueueList
|
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
|
+ (void) registerQueue: (NSNotificationQueue*)q
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
|
|
|
|
NotificationQueueList* list;
|
|
|
|
|
NotificationQueueList* elem;
|
|
|
|
|
|
|
|
|
|
if (q == nil)
|
|
|
|
|
return; /* Can't register nil object. */
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
list = currentList(); /* List of queues for thread. */
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
|
|
if (list->queue == nil)
|
|
|
|
|
list->queue = q; /* Make this the default. */
|
|
|
|
|
|
|
|
|
|
while (list->queue != q && list->next != nil)
|
|
|
|
|
list = list->next;
|
|
|
|
|
|
|
|
|
|
if (list->queue == q)
|
|
|
|
|
return; /* Queue already registered. */
|
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
|
elem = (NotificationQueueList*)NSAllocateObject(self, 0,
|
|
|
|
|
NSDefaultMallocZone());
|
1997-09-01 21:59:51 +00:00
|
|
|
|
elem->queue = q;
|
|
|
|
|
list->next = elem;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
+ (void) unregisterQueue: (NSNotificationQueue*)q
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
|
|
|
|
NotificationQueueList* list;
|
|
|
|
|
|
|
|
|
|
if (q == nil)
|
|
|
|
|
return;
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
list = currentList();
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
|
|
if (list->queue == q)
|
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
NSMutableDictionary *d;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
d = GSCurrentThreadDictionary();
|
1997-09-01 21:59:51 +00:00
|
|
|
|
if (list->next)
|
|
|
|
|
{
|
|
|
|
|
NotificationQueueList* tmp = list->next;
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
[d setObject: tmp forKey: tkey];
|
|
|
|
|
RELEASE(tmp); /* retained in dictionary. */
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1999-04-20 16:28:04 +00:00
|
|
|
|
[d removeObjectForKey: tkey];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1999-04-20 16:28:04 +00:00
|
|
|
|
{
|
|
|
|
|
while (list->next != nil)
|
|
|
|
|
{
|
|
|
|
|
if (list->next->queue == q)
|
|
|
|
|
{
|
|
|
|
|
NotificationQueueList* tmp = list->next;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
list->next = tmp->next;
|
|
|
|
|
RELEASE(tmp);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* NSNotificationQueue queue
|
|
|
|
|
*/
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
typedef struct _NSNotificationQueueRegistration
|
|
|
|
|
{
|
|
|
|
|
struct _NSNotificationQueueRegistration* next;
|
|
|
|
|
struct _NSNotificationQueueRegistration* prev;
|
|
|
|
|
NSNotification* notification;
|
|
|
|
|
id name;
|
|
|
|
|
id object;
|
|
|
|
|
NSArray* modes;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
} NSNotificationQueueRegistration;
|
|
|
|
|
|
|
|
|
|
struct _NSNotificationQueueList;
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
typedef struct _NSNotificationQueueList
|
|
|
|
|
{
|
|
|
|
|
struct _NSNotificationQueueRegistration* head;
|
|
|
|
|
struct _NSNotificationQueueRegistration* tail;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
} NSNotificationQueueList;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Queue functions
|
|
|
|
|
*
|
|
|
|
|
* Queue Elem Elem Elem
|
|
|
|
|
* head ---------> prev -----------> prev -----------> prev --> nil
|
|
|
|
|
* nil <-- next <----------- next <----------- next
|
|
|
|
|
* tail --------------------------------------------->
|
|
|
|
|
*/
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
static inline void
|
|
|
|
|
remove_from_queue_no_release(
|
|
|
|
|
NSNotificationQueueList* queue,
|
|
|
|
|
NSNotificationQueueRegistration* item)
|
|
|
|
|
{
|
|
|
|
|
if (item->prev)
|
|
|
|
|
{
|
|
|
|
|
item->prev->next = item->next;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
queue->tail = item->next;
|
|
|
|
|
if (item->next)
|
|
|
|
|
{
|
|
|
|
|
item->next->prev = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item->next)
|
|
|
|
|
{
|
|
|
|
|
item->next->prev = item->prev;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
queue->head = item->prev;
|
|
|
|
|
if (item->prev)
|
|
|
|
|
{
|
|
|
|
|
item->prev->next = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
static void
|
|
|
|
|
remove_from_queue(
|
|
|
|
|
NSNotificationQueueList* queue,
|
|
|
|
|
NSNotificationQueueRegistration* item,
|
|
|
|
|
NSZone* zone)
|
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
remove_from_queue_no_release(queue, item);
|
|
|
|
|
RELEASE(item->notification);
|
|
|
|
|
RELEASE(item->modes);
|
|
|
|
|
NSZoneFree(zone, item);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_to_queue(
|
|
|
|
|
NSNotificationQueueList* queue,
|
|
|
|
|
NSNotification* notification,
|
|
|
|
|
NSArray* modes,
|
|
|
|
|
NSZone* zone)
|
|
|
|
|
{
|
1999-07-14 19:31:28 +00:00
|
|
|
|
NSNotificationQueueRegistration* item =
|
|
|
|
|
NSZoneCalloc(zone, 1, sizeof(NSNotificationQueueRegistration));
|
|
|
|
|
|
|
|
|
|
item->notification = RETAIN(notification);
|
|
|
|
|
item->name = [notification name];
|
|
|
|
|
item->object = [notification object];
|
|
|
|
|
item->modes = [modes copyWithZone: [modes zone]];
|
|
|
|
|
|
|
|
|
|
item->prev = NULL;
|
|
|
|
|
item->next = queue->tail;
|
|
|
|
|
queue->tail = item;
|
|
|
|
|
if (item->next)
|
|
|
|
|
item->next->prev = item;
|
|
|
|
|
if (!queue->head)
|
|
|
|
|
queue->head = item;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
/*
|
|
|
|
|
* NSNotificationQueue class implementation
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@implementation NSNotificationQueue
|
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
+ (NSNotificationQueue*) defaultQueue
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
NotificationQueueList *list;
|
|
|
|
|
NSNotificationQueue *item;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
list = currentList();
|
|
|
|
|
item = list->queue;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
if (item == nil)
|
1999-04-20 16:28:04 +00:00
|
|
|
|
{
|
|
|
|
|
item = (NSNotificationQueue*)NSAllocateObject(self,
|
|
|
|
|
0, NSDefaultMallocZone());
|
1999-07-14 19:31:28 +00:00
|
|
|
|
item = [item initWithNotificationCenter:
|
|
|
|
|
[NSNotificationCenter defaultCenter]];
|
1999-04-20 16:28:04 +00:00
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
- (id) init
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
return [self initWithNotificationCenter:
|
|
|
|
|
[NSNotificationCenter defaultCenter]];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
- (id) initWithNotificationCenter: (NSNotificationCenter*)notificationCenter
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
zone = [self zone];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
// init queue
|
|
|
|
|
center = RETAIN(notificationCenter);
|
|
|
|
|
asapQueue = NSZoneCalloc(zone, 1, sizeof(NSNotificationQueueList));
|
|
|
|
|
idleQueue = NSZoneCalloc(zone, 1, sizeof(NSNotificationQueueList));
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
// insert in global queue list
|
|
|
|
|
[NotificationQueueList registerQueue: self];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
- (void) dealloc
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-07-14 19:31:28 +00:00
|
|
|
|
NSNotificationQueueRegistration *item;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
// remove from class instances list
|
|
|
|
|
[NotificationQueueList unregisterQueue: self];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
// release self
|
|
|
|
|
for (item = asapQueue->head; item; item=item->prev)
|
|
|
|
|
remove_from_queue(asapQueue, item, zone);
|
|
|
|
|
NSZoneFree(zone, asapQueue);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
for (item = idleQueue->head; item; item=item->prev)
|
|
|
|
|
remove_from_queue(idleQueue, item, zone);
|
|
|
|
|
NSZoneFree(zone, idleQueue);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
RELEASE(center);
|
|
|
|
|
[super dealloc];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Inserting and Removing Notifications From a Queue */
|
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
- (void) dequeueNotificationsMatching: (NSNotification*)notification
|
1999-04-20 16:28:04 +00:00
|
|
|
|
coalesceMask: (NSNotificationCoalescing)coalesceMask
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-07-14 19:31:28 +00:00
|
|
|
|
NSNotificationQueueRegistration* item;
|
|
|
|
|
NSNotificationQueueRegistration* next;
|
|
|
|
|
id name = [notification name];
|
|
|
|
|
id object = [notification object];
|
|
|
|
|
|
|
|
|
|
// find in ASAP notification in queue
|
|
|
|
|
for (item = asapQueue->tail; item; item=next)
|
|
|
|
|
{
|
|
|
|
|
next = item->next;
|
|
|
|
|
if ((coalesceMask & NSNotificationCoalescingOnName)
|
|
|
|
|
&& [name isEqual: item->name])
|
|
|
|
|
{
|
|
|
|
|
remove_from_queue(asapQueue, item, zone);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ((coalesceMask & NSNotificationCoalescingOnSender)
|
|
|
|
|
&& (object == item->object))
|
|
|
|
|
{
|
|
|
|
|
remove_from_queue(asapQueue, item, zone);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
// find in idle notification in queue
|
|
|
|
|
for (item = idleQueue->tail; item; item=next)
|
|
|
|
|
{
|
|
|
|
|
next = item->next;
|
|
|
|
|
if ((coalesceMask & NSNotificationCoalescingOnName)
|
|
|
|
|
&& [name isEqual: item->name])
|
|
|
|
|
{
|
|
|
|
|
remove_from_queue(asapQueue, item, zone);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ((coalesceMask & NSNotificationCoalescingOnSender)
|
|
|
|
|
&& (object == item->object))
|
|
|
|
|
{
|
|
|
|
|
remove_from_queue(asapQueue, item, zone);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
- (void) postNotification: (NSNotification*)notification
|
|
|
|
|
forModes: (NSArray*)modes
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
NSString *mode = [NSRunLoop currentMode];
|
|
|
|
|
|
|
|
|
|
// check to see if run loop is in a valid mode
|
|
|
|
|
if (mode == nil || modes == nil
|
|
|
|
|
|| [modes indexOfObject: mode] != NSNotFound)
|
|
|
|
|
{
|
|
|
|
|
[center postNotification: notification];
|
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
- (void) enqueueNotification: (NSNotification*)notification
|
1999-04-20 16:28:04 +00:00
|
|
|
|
postingStyle: (NSPostingStyle)postingStyle
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-07-14 19:31:28 +00:00
|
|
|
|
[self enqueueNotification: notification
|
|
|
|
|
postingStyle: postingStyle
|
|
|
|
|
coalesceMask: NSNotificationCoalescingOnName
|
|
|
|
|
+ NSNotificationCoalescingOnSender
|
|
|
|
|
forModes: nil];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-14 19:31:28 +00:00
|
|
|
|
- (void) enqueueNotification: (NSNotification*)notification
|
1999-04-20 16:28:04 +00:00
|
|
|
|
postingStyle: (NSPostingStyle)postingStyle
|
|
|
|
|
coalesceMask: (NSNotificationCoalescing)coalesceMask
|
|
|
|
|
forModes: (NSArray*)modes
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-07-14 19:31:28 +00:00
|
|
|
|
if (coalesceMask != NSNotificationNoCoalescing)
|
|
|
|
|
[self dequeueNotificationsMatching: notification
|
|
|
|
|
coalesceMask: coalesceMask];
|
|
|
|
|
|
|
|
|
|
switch (postingStyle)
|
|
|
|
|
{
|
|
|
|
|
case NSPostNow:
|
|
|
|
|
[self postNotification: notification forModes: modes];
|
|
|
|
|
break;
|
|
|
|
|
case NSPostASAP:
|
|
|
|
|
add_to_queue(asapQueue, notification, modes, zone);
|
|
|
|
|
break;
|
|
|
|
|
case NSPostWhenIdle:
|
|
|
|
|
add_to_queue(idleQueue, notification, modes, zone);
|
|
|
|
|
break;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
@end
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
/*
|
1999-04-20 16:28:04 +00:00
|
|
|
|
* The following code handles sending of queued notifications by
|
|
|
|
|
* NSRunLoop.
|
1997-09-01 21:59:51 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
static inline void notifyASAP(NSNotificationQueue *q)
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
NSNotificationQueueList *list = ((accessQueue)q)->asapQueue;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* post all ASAP notifications in queue
|
|
|
|
|
*/
|
|
|
|
|
while (list->head)
|
|
|
|
|
{
|
|
|
|
|
NSNotificationQueueRegistration *item = list->head;
|
|
|
|
|
NSNotification *notification = item->notification;
|
|
|
|
|
NSArray *modes = item->modes;
|
|
|
|
|
|
|
|
|
|
remove_from_queue_no_release(list, item);
|
|
|
|
|
[q postNotification: notification forModes: modes];
|
|
|
|
|
RELEASE(notification);
|
|
|
|
|
RELEASE(modes);
|
|
|
|
|
NSZoneFree(((accessQueue)q)->zone, item);
|
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
void
|
|
|
|
|
GSNotifyASAP()
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
NotificationQueueList *item;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
for (item = currentList(); item; item = item->next)
|
|
|
|
|
if (item->queue)
|
|
|
|
|
notifyASAP(item->queue);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
static inline void notifyIdle(NSNotificationQueue *q)
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
NSNotificationQueueList *list = ((accessQueue)q)->idleQueue;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* post next IDLE notification in queue
|
|
|
|
|
*/
|
|
|
|
|
if (list->head)
|
|
|
|
|
{
|
|
|
|
|
NSNotificationQueueRegistration *item = list->head;
|
|
|
|
|
NSNotification *notification = item->notification;
|
|
|
|
|
NSArray *modes = item->modes;
|
|
|
|
|
|
|
|
|
|
remove_from_queue_no_release(list, item);
|
|
|
|
|
[q postNotification: notification forModes: modes];
|
|
|
|
|
RELEASE(notification);
|
|
|
|
|
RELEASE(modes);
|
|
|
|
|
NSZoneFree(((accessQueue)q)->zone, item);
|
|
|
|
|
}
|
1999-08-20 15:21:59 +00:00
|
|
|
|
/*
|
|
|
|
|
* Post all ASAP notifications.
|
|
|
|
|
*/
|
|
|
|
|
notifyASAP(q);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
void
|
|
|
|
|
GSNotifyIdle()
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
NotificationQueueList *item;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
for (item = currentList(); item; item = item->next)
|
|
|
|
|
if (item->queue)
|
|
|
|
|
notifyIdle(item->queue);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
BOOL
|
|
|
|
|
GSNotifyMore()
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-04-20 16:28:04 +00:00
|
|
|
|
NotificationQueueList *item;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-04-20 16:28:04 +00:00
|
|
|
|
for (item = currentList(); item; item = item->next)
|
|
|
|
|
if (item->queue && ((accessQueue)item->queue)->idleQueue->head)
|
|
|
|
|
return YES;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|