]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/servnotf.cpp
2 *******************************************************************************
3 * Copyright (C) 2001-2012, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
8 #include "unicode/utypes.h"
10 #if !UCONFIG_NO_SERVICE
19 EventListener::~EventListener() {}
20 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EventListener
)
22 static UMutex notifyLock
= U_MUTEX_INITIALIZER
;
24 ICUNotifier::ICUNotifier(void)
29 ICUNotifier::~ICUNotifier(void) {
31 Mutex
lmx(¬ifyLock
);
39 ICUNotifier::addListener(const EventListener
* l
, UErrorCode
& status
)
41 if (U_SUCCESS(status
)) {
43 status
= U_ILLEGAL_ARGUMENT_ERROR
;
47 if (acceptsListener(*l
)) {
48 Mutex
lmx(¬ifyLock
);
49 if (listeners
== NULL
) {
50 listeners
= new UVector(5, status
);
52 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
53 const EventListener
* el
= (const EventListener
*)(listeners
->elementAt(i
));
60 listeners
->addElement((void*)l
, status
); // cast away const
64 fprintf(stderr
, "Listener invalid for this notifier.");
72 ICUNotifier::removeListener(const EventListener
*l
, UErrorCode
& status
)
74 if (U_SUCCESS(status
)) {
76 status
= U_ILLEGAL_ARGUMENT_ERROR
;
81 Mutex
lmx(¬ifyLock
);
82 if (listeners
!= NULL
) {
83 // identity equality check
84 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
85 const EventListener
* el
= (const EventListener
*)listeners
->elementAt(i
);
87 listeners
->removeElementAt(i
);
88 if (listeners
->size() == 0) {
101 ICUNotifier::notifyChanged(void)
103 if (listeners
!= NULL
) {
104 Mutex
lmx(¬ifyLock
);
105 if (listeners
!= NULL
) {
106 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
107 EventListener
* el
= (EventListener
*)listeners
->elementAt(i
);
116 /* UCONFIG_NO_SERVICE */