]> err.no Git - sope/blob - sope-core/EOControl/EOObserver.h
fixed makefiles to search FHS locations at the last resort
[sope] / sope-core / EOControl / EOObserver.h
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #ifndef __EOControl_EOObserver_H__
24 #define __EOControl_EOObserver_H__
25
26 #import <Foundation/NSObject.h>
27
28 @class NSArray;
29
30 @protocol EOObserving < NSObject >
31
32 - (void)objectWillChange:(id)_object;
33
34 @end
35
36 @interface NSObject(EOObserver)
37
38 - (void)willChange;
39
40 @end
41
42 /*
43   Note that -addObserver/-removeObserver methods do *not* nest !
44   Suppression methods do nest.
45 */
46
47 @interface EOObserverCenter : NSObject
48
49 + (void)notifyObserversObjectWillChange:(id)_object;
50
51 + (void)addObserver:(id<EOObserving>)_observer forObject:(id)_object;
52 + (void)removeObserver:(id<EOObserving>)_observer forObject:(id)_object;
53 + (void)addOmniscientObserver:(id<EOObserving>)_observer;
54 + (void)removeOmniscientObserver:(id<EOObserving>)_observer;
55
56 + (NSArray *)observersForObject:(id)_object;
57 + (id)observerForObject:(id)_object ofClass:(Class)_targetClass;
58
59 /* suppressing notifications */
60
61 + (void)suppressObserverNotification;
62 + (void)enableObserverNotification;
63 + (unsigned)observerNotificationSuppressCount;
64
65 @end
66
67 /* asynchronous observing */
68
69 typedef enum {
70   EOObserverPriorityImmediate,
71   EOObserverPriorityFirst,
72   EOObserverPrioritySecond,
73   EOObserverPriorityThird,
74   EOObserverPriorityFourth,
75   EOObserverPriorityFifth,
76   EOObserverPrioritySixth,
77   EOObserverPriorityLater
78 } EOObserverPriority;
79
80 @class EODelayedObserver;
81
82 @interface EODelayedObserverQueue : NSObject
83 {
84 @protected
85   EODelayedObserver *queues[8];
86   NSArray           *runLoopModes;
87   BOOL              hasObservers;
88 }
89
90 + (EODelayedObserverQueue *)defaultObserverQueue;
91
92 /* accessors */
93
94 - (void)setRunLoopModes:(NSArray *)_modes;
95 - (NSArray *)runLoopModes;
96
97 /* managing queue */
98
99 - (void)enqueueObserver:(EODelayedObserver *)_observer;
100 - (void)dequeueObserver:(EODelayedObserver *)_observer;
101
102 /* notification */
103
104 - (void)notifyObserversUpToPriority:(EOObserverPriority)_lastPriority;
105
106 @end
107
108 @interface EODelayedObserver : NSObject < EOObserving >
109 {
110 @public
111   EODelayedObserver *next; /* for access by queue */
112 }
113
114 /* accessors */
115
116 - (EOObserverPriority)priority;
117 - (EODelayedObserverQueue *)observerQueue;
118
119 /* notifications */
120
121 - (void)subjectChanged;
122 - (void)discardPendingNotification;
123
124 @end
125
126 @interface EOObserverProxy : EODelayedObserver
127 {
128 @protected
129   EOObserverPriority priority;
130   id  target;
131   SEL action;
132 }
133
134 - (id)initWithTarget:(id)_target action:(SEL)_action
135   priority:(EOObserverPriority)_priority;
136
137 @end
138
139 #endif /* __EOControl_EOObserver_H__ */