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