2 *******************************************************************************
3 * Copyright (C) 2001-2003, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
10 #include "unicode/utypes.h"
12 #if UCONFIG_NO_SERVICE
17 * Allow the declaration of APIs with pointers to BreakIterator
18 * even when break iteration is removed from the build.
26 #include "unicode/uobject.h"
27 #include "unicode/unistr.h"
34 class U_COMMON_API EventListener
: public UObject
{
36 virtual ~EventListener() {}
39 static inline UClassID
getStaticClassID() {
40 return (UClassID
)&fgClassID
;
43 virtual UClassID
getDynamicClassID() const {
44 return getStaticClassID();
48 virtual UnicodeString
& debug(UnicodeString
& result
) const {
49 return debugClass(result
);
52 virtual UnicodeString
& debugClass(UnicodeString
& result
) const {
53 return result
.append("Key");
57 static const char fgClassID
;
61 * <p>Abstract implementation of a notification facility. Clients add
62 * EventListeners with addListener and remove them with removeListener.
63 * Notifiers call notifyChanged when they wish to notify listeners.
64 * This queues the listener list on the notification thread, which
65 * eventually dequeues the list and calls notifyListener on each
66 * listener in the list.</p>
68 * <p>Subclasses override acceptsListener and notifyListener
69 * to add type-safe notification. AcceptsListener should return
70 * true if the listener is of the appropriate type; ICUNotifier
71 * itself will ensure the listener is non-null and that the
72 * identical listener is not already registered with the Notifier.
73 * NotifyListener should cast the listener to the appropriate
74 * type and call the appropriate method on the listener.
77 class U_COMMON_API ICUNotifier
: public UMemory
{
78 private: UMTX notifyLock
;
79 private: UVector
* listeners
;
83 : notifyLock(0), listeners(NULL
)
85 umtx_init(¬ifyLock
);
88 virtual ~ICUNotifier(void) {
90 Mutex
lmx(¬ifyLock
);
94 umtx_destroy(¬ifyLock
);
98 * Add a listener to be notified when notifyChanged is called.
99 * The listener must not be null. AcceptsListener must return
100 * true for the listener. Attempts to concurrently
101 * register the identical listener more than once will be
104 virtual void addListener(const EventListener
* l
, UErrorCode
& status
);
107 * Stop notifying this listener. The listener must
108 * not be null. Attemps to remove a listener that is
109 * not registered will be silently ignored.
111 virtual void removeListener(const EventListener
* l
, UErrorCode
& status
);
114 * ICU doesn't spawn its own threads. All listeners are notified in
115 * the thread of the caller. Misbehaved listeners can therefore
116 * indefinitely block the calling thread. Callers should beware of
117 * deadlock situations.
119 virtual void notifyChanged(void);
123 * Subclasses implement this to return TRUE if the listener is
124 * of the appropriate type.
126 virtual UBool
acceptsListener(const EventListener
& l
) const = 0;
129 * Subclasses implement this to notify the listener.
131 virtual void notifyListener(EventListener
& l
) const = 0;
136 /* UCONFIG_NO_SERVICE */