1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/servnotf.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,123 @@ 1.4 +/** 1.5 + ******************************************************************************* 1.6 + * Copyright (C) 2001-2011, International Business Machines Corporation and * 1.7 + * others. All Rights Reserved. * 1.8 + ******************************************************************************* 1.9 + */ 1.10 +#ifndef ICUNOTIF_H 1.11 +#define ICUNOTIF_H 1.12 + 1.13 +#include "unicode/utypes.h" 1.14 + 1.15 +#if UCONFIG_NO_SERVICE 1.16 + 1.17 +U_NAMESPACE_BEGIN 1.18 + 1.19 +/* 1.20 + * Allow the declaration of APIs with pointers to BreakIterator 1.21 + * even when break iteration is removed from the build. 1.22 + */ 1.23 +class ICUNotifier; 1.24 + 1.25 +U_NAMESPACE_END 1.26 + 1.27 +#else 1.28 + 1.29 +#include "unicode/uobject.h" 1.30 +#include "unicode/unistr.h" 1.31 + 1.32 +#include "mutex.h" 1.33 +#include "uvector.h" 1.34 + 1.35 +U_NAMESPACE_BEGIN 1.36 + 1.37 +class U_COMMON_API EventListener : public UObject { 1.38 +public: 1.39 + virtual ~EventListener(); 1.40 + 1.41 +public: 1.42 + static UClassID U_EXPORT2 getStaticClassID(); 1.43 + 1.44 + virtual UClassID getDynamicClassID() const; 1.45 + 1.46 +public: 1.47 +#ifdef SERVICE_DEBUG 1.48 + virtual UnicodeString& debug(UnicodeString& result) const { 1.49 + return debugClass(result); 1.50 + } 1.51 + 1.52 + virtual UnicodeString& debugClass(UnicodeString& result) const { 1.53 + return result.append("Key"); 1.54 + } 1.55 +#endif 1.56 +}; 1.57 + 1.58 +/** 1.59 + * <p>Abstract implementation of a notification facility. Clients add 1.60 + * EventListeners with addListener and remove them with removeListener. 1.61 + * Notifiers call notifyChanged when they wish to notify listeners. 1.62 + * This queues the listener list on the notification thread, which 1.63 + * eventually dequeues the list and calls notifyListener on each 1.64 + * listener in the list.</p> 1.65 + * 1.66 + * <p>Subclasses override acceptsListener and notifyListener 1.67 + * to add type-safe notification. AcceptsListener should return 1.68 + * true if the listener is of the appropriate type; ICUNotifier 1.69 + * itself will ensure the listener is non-null and that the 1.70 + * identical listener is not already registered with the Notifier. 1.71 + * NotifyListener should cast the listener to the appropriate 1.72 + * type and call the appropriate method on the listener. 1.73 + */ 1.74 + 1.75 +class U_COMMON_API ICUNotifier : public UMemory { 1.76 +private: UVector* listeners; 1.77 + 1.78 +public: 1.79 + ICUNotifier(void); 1.80 + 1.81 + virtual ~ICUNotifier(void); 1.82 + 1.83 + /** 1.84 + * Add a listener to be notified when notifyChanged is called. 1.85 + * The listener must not be null. AcceptsListener must return 1.86 + * true for the listener. Attempts to concurrently 1.87 + * register the identical listener more than once will be 1.88 + * silently ignored. 1.89 + */ 1.90 + virtual void addListener(const EventListener* l, UErrorCode& status); 1.91 + 1.92 + /** 1.93 + * Stop notifying this listener. The listener must 1.94 + * not be null. Attemps to remove a listener that is 1.95 + * not registered will be silently ignored. 1.96 + */ 1.97 + virtual void removeListener(const EventListener* l, UErrorCode& status); 1.98 + 1.99 + /** 1.100 + * ICU doesn't spawn its own threads. All listeners are notified in 1.101 + * the thread of the caller. Misbehaved listeners can therefore 1.102 + * indefinitely block the calling thread. Callers should beware of 1.103 + * deadlock situations. 1.104 + */ 1.105 + virtual void notifyChanged(void); 1.106 + 1.107 +protected: 1.108 + /** 1.109 + * Subclasses implement this to return TRUE if the listener is 1.110 + * of the appropriate type. 1.111 + */ 1.112 + virtual UBool acceptsListener(const EventListener& l) const = 0; 1.113 + 1.114 + /** 1.115 + * Subclasses implement this to notify the listener. 1.116 + */ 1.117 + virtual void notifyListener(EventListener& l) const = 0; 1.118 +}; 1.119 + 1.120 +U_NAMESPACE_END 1.121 + 1.122 +/* UCONFIG_NO_SERVICE */ 1.123 +#endif 1.124 + 1.125 +/* ICUNOTIF_H */ 1.126 +#endif