2004-04-17 11:30:47 +00:00
|
|
|
/* -*-objc-*-
|
2002-11-15 22:57:05 +00:00
|
|
|
EOObserver.h
|
|
|
|
|
2005-08-17 08:07:57 +00:00
|
|
|
Copyright (C) 2000,2002,2003,2004,2005 Free Software Foundation, Inc.
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2006-09-14 16:06:21 +00:00
|
|
|
Author: Mirko Viviani <mirko.viviani@gmail.com>
|
2002-11-15 22:57:05 +00:00
|
|
|
Date: June 2000
|
|
|
|
|
|
|
|
This file is part of the GNUstep Database 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
|
2007-07-12 06:39:22 +00:00
|
|
|
version 3 of the License, or (at your option) any later version.
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
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; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
2005-08-17 08:07:57 +00:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-11-15 22:57:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __EOObserver_h__
|
|
|
|
#define __EOObserver_h__
|
|
|
|
|
2002-12-30 22:10:43 +00:00
|
|
|
|
2010-04-21 13:59:28 +00:00
|
|
|
#include <EOControl/EOCustomObject.h>
|
2002-12-30 22:10:43 +00:00
|
|
|
|
|
|
|
@class NSArray;
|
|
|
|
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
@interface NSObject (EOObserver)
|
|
|
|
|
|
|
|
- (void)willChange;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@protocol EOObserving <NSObject>
|
2004-04-17 11:30:47 +00:00
|
|
|
|
2002-11-15 22:57:05 +00:00
|
|
|
- (void)objectWillChange: (id)subject;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface EOObserverCenter : NSObject
|
|
|
|
|
|
|
|
+ (void)addObserver: (id <EOObserving>)observer forObject: (id)object;
|
|
|
|
|
|
|
|
+ (void)removeObserver: (id <EOObserving>)observer forObject: (id)object;
|
|
|
|
|
|
|
|
+ (void)notifyObserversObjectWillChange: (id)object;
|
|
|
|
|
|
|
|
+ (NSArray *)observersForObject: (id)object;
|
|
|
|
|
|
|
|
+ (id)observerForObject: (id)object ofClass: (Class)targetClass;
|
|
|
|
|
|
|
|
+ (void)suppressObserverNotification;
|
|
|
|
+ (void)enableObserverNotification;
|
|
|
|
|
|
|
|
+ (unsigned)observerNotificationSuppressCount;
|
|
|
|
|
|
|
|
+ (void)addOmniscientObserver: (id <EOObserving>)observer;
|
|
|
|
+ (void)removeOmniscientObserver: (id <EOObserving>)observer;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@class EODelayedObserverQueue;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
EOObserverPriorityImmediate,
|
|
|
|
EOObserverPriorityFirst,
|
|
|
|
EOObserverPrioritySecond,
|
|
|
|
EOObserverPriorityThird,
|
|
|
|
EOObserverPriorityFourth,
|
|
|
|
EOObserverPriorityFifth,
|
|
|
|
EOObserverPrioritySixth,
|
|
|
|
EOObserverPriorityLater
|
|
|
|
} EOObserverPriority;
|
2002-12-30 22:10:43 +00:00
|
|
|
|
2002-11-15 22:57:05 +00:00
|
|
|
#define EOObserverNumberOfPriorities ((unsigned)EOObserverPriorityLater + 1)
|
|
|
|
|
|
|
|
|
2010-04-21 13:59:28 +00:00
|
|
|
@interface EODelayedObserver : EOCustomObject <EOObserving>
|
2002-12-30 22:10:43 +00:00
|
|
|
{
|
2002-11-15 22:57:05 +00:00
|
|
|
@public
|
2004-04-17 11:30:47 +00:00
|
|
|
EODelayedObserver *_next; /* Linked List. */
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)objectWillChange: (id)subject;
|
|
|
|
|
|
|
|
- (EOObserverPriority)priority;
|
|
|
|
|
|
|
|
- (EODelayedObserverQueue *)observerQueue;
|
|
|
|
|
2004-04-17 11:30:47 +00:00
|
|
|
- (void)subjectChanged; /* Subclass responsibility. */
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
- (void)discardPendingNotification;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2004-04-17 11:30:47 +00:00
|
|
|
/* To be used with NSRunLoop's performSelector:target:argument:order:modes: */
|
2002-12-30 22:10:43 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
EOFlushDelayedObserversRunLoopOrdering = 400000
|
2002-11-15 22:57:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@interface EODelayedObserverQueue : NSObject
|
|
|
|
{
|
2004-04-17 11:30:47 +00:00
|
|
|
/* Lists per priority. */
|
|
|
|
EODelayedObserver *_queue[EOObserverNumberOfPriorities];
|
2002-12-30 22:10:43 +00:00
|
|
|
unsigned _highestNonEmptyQueue;
|
|
|
|
BOOL _haveEntryInNotificationQueue;
|
|
|
|
NSArray *_modes;
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (EODelayedObserverQueue *)defaultObserverQueue;
|
|
|
|
|
|
|
|
- (void)enqueueObserver: (EODelayedObserver *)observer;
|
|
|
|
- (void)dequeueObserver: (EODelayedObserver *)observer;
|
|
|
|
|
2006-12-30 17:41:02 +00:00
|
|
|
- (void)notifyObserversUpToPriority: (EOObserverPriority)priority;
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
- (void)setRunLoopModes: (NSArray *)modes;
|
|
|
|
- (NSArray *)runLoopModes;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
2002-12-30 22:10:43 +00:00
|
|
|
@interface EOObserverProxy : EODelayedObserver
|
|
|
|
{
|
|
|
|
id _target;
|
|
|
|
SEL _action;
|
|
|
|
EOObserverPriority _priority;
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
2004-04-17 11:30:47 +00:00
|
|
|
- (id)initWithTarget: (id)target
|
|
|
|
action: (SEL)action
|
|
|
|
priority: (EOObserverPriority)priority;
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
#endif
|