]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/servnotf.h
ICU-57166.0.1.tar.gz
[apple/icu.git] / icuSources / common / servnotf.h
CommitLineData
b75a7d8f
A
1/**
2 *******************************************************************************
b331163b 3 * Copyright (C) 2001-2014, International Business Machines Corporation and *
b75a7d8f
A
4 * others. All Rights Reserved. *
5 *******************************************************************************
6 */
7#ifndef ICUNOTIF_H
8#define ICUNOTIF_H
9
10#include "unicode/utypes.h"
11
12#if UCONFIG_NO_SERVICE
13
14U_NAMESPACE_BEGIN
15
16/*
17 * Allow the declaration of APIs with pointers to BreakIterator
18 * even when break iteration is removed from the build.
19 */
20class ICUNotifier;
21
22U_NAMESPACE_END
23
24#else
25
26#include "unicode/uobject.h"
27#include "unicode/unistr.h"
28
29#include "mutex.h"
30#include "uvector.h"
31
32U_NAMESPACE_BEGIN
33
34class U_COMMON_API EventListener : public UObject {
374ca955
A
35public:
36 virtual ~EventListener();
b75a7d8f 37
374ca955
A
38public:
39 static UClassID U_EXPORT2 getStaticClassID();
b75a7d8f 40
374ca955 41 virtual UClassID getDynamicClassID() const;
b75a7d8f 42
374ca955
A
43public:
44#ifdef SERVICE_DEBUG
b75a7d8f
A
45 virtual UnicodeString& debug(UnicodeString& result) const {
46 return debugClass(result);
47 }
48
49 virtual UnicodeString& debugClass(UnicodeString& result) const {
b331163b 50 return result.append((UnicodeString)"Key");
b75a7d8f 51 }
374ca955 52#endif
b75a7d8f
A
53};
54
55/**
56 * <p>Abstract implementation of a notification facility. Clients add
57 * EventListeners with addListener and remove them with removeListener.
58 * Notifiers call notifyChanged when they wish to notify listeners.
59 * This queues the listener list on the notification thread, which
60 * eventually dequeues the list and calls notifyListener on each
61 * listener in the list.</p>
62 *
63 * <p>Subclasses override acceptsListener and notifyListener
64 * to add type-safe notification. AcceptsListener should return
65 * true if the listener is of the appropriate type; ICUNotifier
66 * itself will ensure the listener is non-null and that the
67 * identical listener is not already registered with the Notifier.
68 * NotifyListener should cast the listener to the appropriate
69 * type and call the appropriate method on the listener.
70 */
71
72class U_COMMON_API ICUNotifier : public UMemory {
374ca955
A
73private: UVector* listeners;
74
75public:
76 ICUNotifier(void);
77
78 virtual ~ICUNotifier(void);
79
80 /**
81 * Add a listener to be notified when notifyChanged is called.
82 * The listener must not be null. AcceptsListener must return
83 * true for the listener. Attempts to concurrently
84 * register the identical listener more than once will be
85 * silently ignored.
86 */
87 virtual void addListener(const EventListener* l, UErrorCode& status);
88
89 /**
90 * Stop notifying this listener. The listener must
91 * not be null. Attemps to remove a listener that is
92 * not registered will be silently ignored.
93 */
94 virtual void removeListener(const EventListener* l, UErrorCode& status);
95
96 /**
97 * ICU doesn't spawn its own threads. All listeners are notified in
98 * the thread of the caller. Misbehaved listeners can therefore
99 * indefinitely block the calling thread. Callers should beware of
100 * deadlock situations.
101 */
102 virtual void notifyChanged(void);
103
104protected:
105 /**
106 * Subclasses implement this to return TRUE if the listener is
107 * of the appropriate type.
108 */
109 virtual UBool acceptsListener(const EventListener& l) const = 0;
110
111 /**
112 * Subclasses implement this to notify the listener.
113 */
114 virtual void notifyListener(EventListener& l) const = 0;
b75a7d8f
A
115};
116
117U_NAMESPACE_END
118
119/* UCONFIG_NO_SERVICE */
120#endif
121
122/* ICUNOTIF_H */
123#endif