celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ejans...@apache.org
Subject [2/2] celix git commit: [CELIX-256] made sure events are given to the right event handlers
Date Tue, 23 Aug 2016 14:02:24 GMT
[CELIX-256] made sure events are given to the right event handlers


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/e3fd7f1b
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/e3fd7f1b
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/e3fd7f1b

Branch: refs/heads/feature/event_admin
Commit: e3fd7f1b25e7ebbd860e252ef9dba849de924cc4
Parents: 05d7192
Author: Erik Jansman <ejansman@apache.org>
Authored: Tue Aug 23 16:01:31 2016 +0200
Committer: Erik Jansman <ejansman@apache.org>
Committed: Tue Aug 23 16:01:31 2016 +0200

----------------------------------------------------------------------
 .../event_admin/private/src/event_admin_impl.c  | 32 +++++++++++++++++---
 1 file changed, 28 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/e3fd7f1b/event_admin/event_admin/private/src/event_admin_impl.c
----------------------------------------------------------------------
diff --git a/event_admin/event_admin/private/src/event_admin_impl.c b/event_admin/event_admin/private/src/event_admin_impl.c
index a7204e1..40cbaa1 100644
--- a/event_admin/event_admin/private/src/event_admin_impl.c
+++ b/event_admin/event_admin/private/src/event_admin_impl.c
@@ -82,7 +82,17 @@ celix_status_t eventAdmin_postEvent(event_admin_pt event_admin, event_pt
event)
     bool added = false;
     while (event_admin->eventAdminRunning && added == false) {
         if (celixThreadMutex_tryLock(event_admin->eventListLock) == 0) {
-            linkedList_addLast(event_admin->eventList, event);
+            //linkedList_addLast(event_admin->eventList, event);
+            array_list_pt event_handlers;
+            array_list_pt event_and_handlers;
+            const char *topic;
+            eventAdmin_getTopic(&event, &topic);
+            arrayList_create(&event_and_handlers);
+            arrayList_create(&event_handlers);
+            eventAdmin_findHandlersByTopic(event_admin, topic, event_handlers);
+            arrayList_addIndex(event_and_handlers, 0, event);
+            arrayList_addIndex(event_and_handlers, 1, event_handlers);
+            linkedList_addLast(event_admin->eventList, event_and_handlers);
             celixThreadMutex_unlock(event_admin->eventListLock);
             added = true;
         }
@@ -94,6 +104,9 @@ void *eventProcessor(void *handle) {
     celix_status_t status = CELIX_SUCCESS;
     event_admin_pt *eventAdminPt = handle;
     event_pt event = NULL;
+    array_list_pt event_and_handlers;
+
+    arrayList_create(&event_and_handlers);
     int waitcounter = 1;
     while ((*eventAdminPt)->eventAdminRunning) {
         if (celixThreadMutex_tryLock((*eventAdminPt)->eventListLock) == 0) {
@@ -104,7 +117,7 @@ void *eventProcessor(void *handle) {
                     waitcounter = 1;
                 }
             } else {
-                event = linkedList_removeFirst((*eventAdminPt)->eventList);
+                event_and_handlers = linkedList_removeFirst((*eventAdminPt)->eventList);
                 waitcounter = 1;
 
             }
@@ -116,8 +129,19 @@ void *eventProcessor(void *handle) {
                 waitcounter = 1;
             }
         }
-        if (event != NULL) {
-            status = processEvent((*eventAdminPt), event);
+        if (arrayList_isEmpty(event_and_handlers) == false) {
+            event = arrayList_get(event_and_handlers, 0);
+            array_list_pt event_handlers;
+            arrayList_create(&event_handlers);
+            event_handlers = arrayList_get(event_and_handlers, 1);
+            array_list_iterator_pt handlers_iterator = arrayListIterator_create(event_handlers);
+            while (arrayListIterator_hasNext(handlers_iterator)) {
+                event_handler_service_pt event_handler_service = (event_handler_service_pt)
arrayListIterator_next(
+                        handlers_iterator);
+                if (event_handler_service != NULL) {
+                    event_handler_service->handle_event(&event_handler_service->event_handler,
event);
+                }
+            }
             const char *topic;
 
             eventAdmin_getTopic(&event, &topic);


Mime
View raw message