1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2001-2014, International Business Machines Corporation and *
6 * others. All Rights Reserved. *
7 *******************************************************************************
12 #include "unicode/utypes.h"
14 #if UCONFIG_NO_SERVICE
19 * Allow the declaration of APIs with pointers to BreakIterator
20 * even when break iteration is removed from the build.
28 #include "unicode/uobject.h"
29 #include "unicode/unistr.h"
36 class U_COMMON_API EventListener
: public UObject
{
38 virtual ~EventListener();
41 static UClassID U_EXPORT2
getStaticClassID();
43 virtual UClassID
getDynamicClassID() const;
47 virtual UnicodeString
& debug(UnicodeString
& result
) const {
48 return debugClass(result
);
51 virtual UnicodeString
& debugClass(UnicodeString
& result
) const {
52 return result
.append((UnicodeString
)"Key");
58 * <p>Abstract implementation of a notification facility. Clients add
59 * EventListeners with addListener and remove them with removeListener.
60 * Notifiers call notifyChanged when they wish to notify listeners.
61 * This queues the listener list on the notification thread, which
62 * eventually dequeues the list and calls notifyListener on each
63 * listener in the list.</p>
65 * <p>Subclasses override acceptsListener and notifyListener
66 * to add type-safe notification. AcceptsListener should return
67 * true if the listener is of the appropriate type; ICUNotifier
68 * itself will ensure the listener is non-null and that the
69 * identical listener is not already registered with the Notifier.
70 * NotifyListener should cast the listener to the appropriate
71 * type and call the appropriate method on the listener.
74 class U_COMMON_API ICUNotifier
: public UMemory
{
75 private: UVector
* listeners
;
80 virtual ~ICUNotifier(void);
83 * Add a listener to be notified when notifyChanged is called.
84 * The listener must not be null. AcceptsListener must return
85 * true for the listener. Attempts to concurrently
86 * register the identical listener more than once will be
89 virtual void addListener(const EventListener
* l
, UErrorCode
& status
);
92 * Stop notifying this listener. The listener must
93 * not be null. Attemps to remove a listener that is
94 * not registered will be silently ignored.
96 virtual void removeListener(const EventListener
* l
, UErrorCode
& status
);
99 * ICU doesn't spawn its own threads. All listeners are notified in
100 * the thread of the caller. Misbehaved listeners can therefore
101 * indefinitely block the calling thread. Callers should beware of
102 * deadlock situations.
104 virtual void notifyChanged(void);
108 * Subclasses implement this to return TRUE if the listener is
109 * of the appropriate type.
111 virtual UBool
acceptsListener(const EventListener
& l
) const = 0;
114 * Subclasses implement this to notify the listener.
116 virtual void notifyListener(EventListener
& l
) const = 0;
121 /* UCONFIG_NO_SERVICE */