]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/icunotif.cpp
2 *******************************************************************************
3 * Copyright (C) 2001-2003, 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 ICUNotifier::ICUNotifier(void)
23 : notifyLock(0), listeners(NULL
)
25 umtx_init(¬ifyLock
);
28 ICUNotifier::~ICUNotifier(void) {
30 Mutex
lmx(¬ifyLock
);
34 umtx_destroy(¬ifyLock
);
39 ICUNotifier::addListener(const EventListener
* l
, UErrorCode
& status
)
41 if (U_SUCCESS(status
)) {
43 status
= U_ILLEGAL_ARGUMENT_ERROR
;
46 if (acceptsListener(*l
)) {
47 Mutex
lmx(¬ifyLock
);
48 if (listeners
== NULL
) {
49 listeners
= new UVector(5, status
);
51 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
52 const EventListener
* el
= (const EventListener
*)(listeners
->elementAt(i
));
59 listeners
->addElement((void*)l
, status
); // cast away const
62 fprintf(stderr
, "Listener invalid for this notifier.");
70 ICUNotifier::removeListener(const EventListener
*l
, UErrorCode
& status
)
72 if (U_SUCCESS(status
)) {
74 status
= U_ILLEGAL_ARGUMENT_ERROR
;
79 Mutex
lmx(¬ifyLock
);
80 if (listeners
!= NULL
) {
81 // identity equality check
82 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
83 const EventListener
* el
= (const EventListener
*)listeners
->elementAt(i
);
85 listeners
->removeElementAt(i
);
86 if (listeners
->size() == 0) {
99 ICUNotifier::notifyChanged(void)
101 if (listeners
!= NULL
) {
102 Mutex
lmx(¬ifyLock
);
103 if (listeners
!= NULL
) {
104 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
105 EventListener
* el
= (EventListener
*)listeners
->elementAt(i
);
114 /* UCONFIG_NO_SERVICE */