summaryrefslogtreecommitdiffstats
path: root/intl/icu/source/common/servnotf.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /intl/icu/source/common/servnotf.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'intl/icu/source/common/servnotf.cpp')
-rw-r--r--intl/icu/source/common/servnotf.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/intl/icu/source/common/servnotf.cpp b/intl/icu/source/common/servnotf.cpp
new file mode 100644
index 000000000..69a81da25
--- /dev/null
+++ b/intl/icu/source/common/servnotf.cpp
@@ -0,0 +1,120 @@
+// Copyright (C) 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/**
+ *******************************************************************************
+ * Copyright (C) 2001-2012, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_SERVICE
+
+#include "servnotf.h"
+#ifdef NOTIFIER_DEBUG
+#include <stdio.h>
+#endif
+
+U_NAMESPACE_BEGIN
+
+EventListener::~EventListener() {}
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EventListener)
+
+static UMutex notifyLock = U_MUTEX_INITIALIZER;
+
+ICUNotifier::ICUNotifier(void)
+: listeners(NULL)
+{
+}
+
+ICUNotifier::~ICUNotifier(void) {
+ {
+ Mutex lmx(&notifyLock);
+ delete listeners;
+ listeners = NULL;
+ }
+}
+
+
+void
+ICUNotifier::addListener(const EventListener* l, UErrorCode& status)
+{
+ if (U_SUCCESS(status)) {
+ if (l == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ if (acceptsListener(*l)) {
+ Mutex lmx(&notifyLock);
+ 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
+ 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(&notifyLock);
+ 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(&notifyLock);
+ if (listeners != NULL) {
+ for (int i = 0, e = listeners->size(); i < e; ++i) {
+ EventListener* el = (EventListener*)listeners->elementAt(i);
+ notifyListener(*el);
+ }
+ }
+ }
+}
+
+U_NAMESPACE_END
+
+/* UCONFIG_NO_SERVICE */
+#endif
+