]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/icunotif.cpp
2 *******************************************************************************
3 * Copyright (C) 2001-2002, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
8 #include "unicode/utypes.h"
10 #if !UCONFIG_NO_SERVICE
17 const char EventListener::fgClassID
= '\0';
20 ICUNotifier::addListener(const EventListener
* l
, UErrorCode
& status
)
22 if (U_SUCCESS(status
)) {
24 status
= U_ILLEGAL_ARGUMENT_ERROR
;
27 if (acceptsListener(*l
)) {
28 Mutex
lmx(¬ifyLock
);
29 if (listeners
== NULL
) {
30 listeners
= new UVector(5, status
);
32 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
33 const EventListener
* el
= (const EventListener
*)(listeners
->elementAt(i
));
40 listeners
->addElement((void*)l
, status
); // cast away const
43 fprintf(stderr
, "Listener invalid for this notifier.");
51 ICUNotifier::removeListener(const EventListener
*l
, UErrorCode
& status
)
53 if (U_SUCCESS(status
)) {
55 status
= U_ILLEGAL_ARGUMENT_ERROR
;
60 Mutex
lmx(¬ifyLock
);
61 if (listeners
!= NULL
) {
62 // identity equality check
63 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
64 const EventListener
* el
= (const EventListener
*)listeners
->elementAt(i
);
66 listeners
->removeElementAt(i
);
67 if (listeners
->size() == 0) {
80 ICUNotifier::notifyChanged(void)
82 if (listeners
!= NULL
) {
83 Mutex
lmx(¬ifyLock
);
84 if (listeners
!= NULL
) {
85 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
86 EventListener
* el
= (EventListener
*)listeners
->elementAt(i
);
95 /* UCONFIG_NO_SERVICE */