]>
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() {
25 static UMutex
*m
= STATIC_NEW(UMutex
);
29 ICUNotifier::ICUNotifier(void)
34 ICUNotifier::~ICUNotifier(void) {
36 Mutex
lmx(notifyLock());
44 ICUNotifier::addListener(const EventListener
* l
, UErrorCode
& status
)
46 if (U_SUCCESS(status
)) {
48 status
= U_ILLEGAL_ARGUMENT_ERROR
;
52 if (acceptsListener(*l
)) {
53 Mutex
lmx(notifyLock());
54 if (listeners
== NULL
) {
55 listeners
= new UVector(5, status
);
57 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
58 const EventListener
* el
= (const EventListener
*)(listeners
->elementAt(i
));
65 listeners
->addElement((void*)l
, status
); // cast away const
69 fprintf(stderr
, "Listener invalid for this notifier.");
77 ICUNotifier::removeListener(const EventListener
*l
, UErrorCode
& status
)
79 if (U_SUCCESS(status
)) {
81 status
= U_ILLEGAL_ARGUMENT_ERROR
;
86 Mutex
lmx(notifyLock());
87 if (listeners
!= NULL
) {
88 // identity equality check
89 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
90 const EventListener
* el
= (const EventListener
*)listeners
->elementAt(i
);
92 listeners
->removeElementAt(i
);
93 if (listeners
->size() == 0) {
106 ICUNotifier::notifyChanged(void)
108 if (listeners
!= NULL
) {
109 Mutex
lmx(notifyLock());
110 if (listeners
!= NULL
) {
111 for (int i
= 0, e
= listeners
->size(); i
< e
; ++i
) {
112 EventListener
* el
= (EventListener
*)listeners
->elementAt(i
);
121 /* UCONFIG_NO_SERVICE */