mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-4703 addListener should return when detecting bad arguments.
X-SVN-Rev: 19481
This commit is contained in:
parent
0ba4bdac5d
commit
7b939088a9
1 changed files with 52 additions and 50 deletions
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2001-2004, International Business Machines Corporation and *
|
||||
* Copyright (C) 2001-2006, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -20,7 +20,7 @@ EventListener::~EventListener() {}
|
|||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EventListener)
|
||||
|
||||
ICUNotifier::ICUNotifier(void)
|
||||
: notifyLock(0), listeners(NULL)
|
||||
: notifyLock(0), listeners(NULL)
|
||||
{
|
||||
umtx_init(¬ifyLock);
|
||||
}
|
||||
|
@ -38,75 +38,77 @@ ICUNotifier::~ICUNotifier(void) {
|
|||
void
|
||||
ICUNotifier::addListener(const EventListener* l, UErrorCode& status)
|
||||
{
|
||||
if (U_SUCCESS(status)) {
|
||||
if (l == NULL) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
}
|
||||
|
||||
if (acceptsListener(*l)) {
|
||||
Mutex lmx(¬ifyLock);
|
||||
if (listeners == NULL) {
|
||||
listeners = new UVector(5, status);
|
||||
} else {
|
||||
for (int i = 0, e = listeners->size(); i < e; ++i) {
|
||||
const EventListener* el = (const EventListener*)(listeners->elementAt(i));
|
||||
if (l == el) {
|
||||
if (U_SUCCESS(status)) {
|
||||
if (l == NULL) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
listeners->addElement((void*)l, status); // cast away const
|
||||
} else {
|
||||
if (acceptsListener(*l)) {
|
||||
Mutex lmx(¬ifyLock);
|
||||
if (listeners == NULL) {
|
||||
listeners = new UVector(5, status);
|
||||
} else {
|
||||
for (int i = 0, e = listeners->size(); i < e; ++i) {
|
||||
const EventListener* el = (const EventListener*)(listeners->elementAt(i));
|
||||
if (l == el) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
listeners->addElement((void*)l, status); // cast away const
|
||||
}
|
||||
#ifdef NOTIFIER_DEBUG
|
||||
fprintf(stderr, "Listener invalid for this notifier.");
|
||||
exit(1);
|
||||
else {
|
||||
fprintf(stderr, "Listener invalid for this notifier.");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ICUNotifier::removeListener(const EventListener *l, UErrorCode& status)
|
||||
{
|
||||
if (U_SUCCESS(status)) {
|
||||
if (l == NULL) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
Mutex lmx(¬ifyLock);
|
||||
if (listeners != NULL) {
|
||||
// identity equality check
|
||||
for (int i = 0, e = listeners->size(); i < e; ++i) {
|
||||
const EventListener* el = (const EventListener*)listeners->elementAt(i);
|
||||
if (l == el) {
|
||||
listeners->removeElementAt(i);
|
||||
if (listeners->size() == 0) {
|
||||
delete listeners;
|
||||
listeners = NULL;
|
||||
}
|
||||
if (U_SUCCESS(status)) {
|
||||
if (l == NULL) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
Mutex lmx(¬ifyLock);
|
||||
if (listeners != NULL) {
|
||||
// identity equality check
|
||||
for (int i = 0, e = listeners->size(); i < e; ++i) {
|
||||
const EventListener* el = (const EventListener*)listeners->elementAt(i);
|
||||
if (l == el) {
|
||||
listeners->removeElementAt(i);
|
||||
if (listeners->size() == 0) {
|
||||
delete listeners;
|
||||
listeners = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ICUNotifier::notifyChanged(void)
|
||||
{
|
||||
if (listeners != NULL) {
|
||||
Mutex lmx(¬ifyLock);
|
||||
if (listeners != NULL) {
|
||||
for (int i = 0, e = listeners->size(); i < e; ++i) {
|
||||
EventListener* el = (EventListener*)listeners->elementAt(i);
|
||||
notifyListener(*el);
|
||||
}
|
||||
Mutex lmx(¬ifyLock);
|
||||
if (listeners != NULL) {
|
||||
for (int i = 0, e = listeners->size(); i < e; ++i) {
|
||||
EventListener* el = (EventListener*)listeners->elementAt(i);
|
||||
notifyListener(*el);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
|
Loading…
Add table
Reference in a new issue