]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/servnotf.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2001-2012, International Business Machines Corporation and *
6 * others. All Rights Reserved. *
7 *******************************************************************************
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_SERVICE
21 EventListener::~EventListener() {}
22 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EventListener
)
24 static UMutex notifyLock
= U_MUTEX_INITIALIZER
;
26 ICUNotifier::ICUNotifier(void)
31 ICUNotifier::~ICUNotifier(void) {
33 Mutex
lmx(¬ifyLock
);
41 ICUNotifier::addListener(const EventListener
* l
, UErrorCode
& status
)
43 if (U_SUCCESS(status
)) {
45 status
= U_ILLEGAL_ARGUMENT_ERROR
;
49 if (acceptsListener(*l
)) {
50 Mutex
lmx(¬ifyLock
);
51 if (listeners
== NULL
) {
52 listeners
= new UVector(5, status
);
54 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
55 const EventListener
* el
= (const EventListener
*)(listeners
->elementAt(i
));
62 listeners
->addElement((void*)l
, status
); // cast away const
66 fprintf(stderr
, "Listener invalid for this notifier.");
74 ICUNotifier::removeListener(const EventListener
*l
, UErrorCode
& status
)
76 if (U_SUCCESS(status
)) {
78 status
= U_ILLEGAL_ARGUMENT_ERROR
;
83 Mutex
lmx(¬ifyLock
);
84 if (listeners
!= NULL
) {
85 // identity equality check
86 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
87 const EventListener
* el
= (const EventListener
*)listeners
->elementAt(i
);
89 listeners
->removeElementAt(i
);
90 if (listeners
->size() == 0) {
103 ICUNotifier::notifyChanged(void)
105 if (listeners
!= NULL
) {
106 Mutex
lmx(¬ifyLock
);
107 if (listeners
!= NULL
) {
108 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
109 EventListener
* el
= (EventListener
*)listeners
->elementAt(i
);
118 /* UCONFIG_NO_SERVICE */