celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1613753 - in /celix/trunk/event_admin: ./ event_admin/private/src/ event_handler/private/src/ event_publisher/private/include/ event_publisher/private/src/
Date Sun, 27 Jul 2014 05:59:20 GMT
Author: abroekhuis
Date: Sun Jul 27 05:59:19 2014
New Revision: 1613753

URL: http://svn.apache.org/r1613753
Log:
CELIX-131: Applied patch

Modified:
    celix/trunk/event_admin/deploy.cmake
    celix/trunk/event_admin/event_admin/private/src/event_admin_impl.c
    celix/trunk/event_admin/event_handler/private/src/event_handler_activator.c
    celix/trunk/event_admin/event_handler/private/src/event_handler_impl.c
    celix/trunk/event_admin/event_publisher/private/include/event_publisher_impl.h
    celix/trunk/event_admin/event_publisher/private/src/event_publisher_activator.c
    celix/trunk/event_admin/event_publisher/private/src/event_publisher_impl.c

Modified: celix/trunk/event_admin/deploy.cmake
URL: http://svn.apache.org/viewvc/celix/trunk/event_admin/deploy.cmake?rev=1613753&r1=1613752&r2=1613753&view=diff
==============================================================================
--- celix/trunk/event_admin/deploy.cmake (original)
+++ celix/trunk/event_admin/deploy.cmake Sun Jul 27 05:59:19 2014
@@ -17,7 +17,7 @@
 is_enabled(EVENT_ADMIN)
 if(EVENT_ADMIN)
 	deploy("event_admin" BUNDLES event_admin shell shell_tui log_service log_writer)
-	deploy("event_publisher_example" BUNDLES event_publisher shell shell_tui log_service log_writer)
-	deploy("event_handler_example" BUNDLES event_handler shell shell_tui log_service log_writer)
+    deploy("event_publisher_example" BUNDLES event_admin event_publisher shell shell_tui
log_service log_writer)
+	deploy("event_handler_example" BUNDLES event_admin event_handler shell shell_tui log_service
log_writer)
 	deploy("event_admin_example" BUNDLES event_admin event_publisher event_handler shell shell_tui
log_service log_writer)
-endif(EVENT_ADMIN)
\ No newline at end of file
+endif(EVENT_ADMIN)

Modified: celix/trunk/event_admin/event_admin/private/src/event_admin_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/event_admin/event_admin/private/src/event_admin_impl.c?rev=1613753&r1=1613752&r2=1613753&view=diff
==============================================================================
--- celix/trunk/event_admin/event_admin/private/src/event_admin_impl.c (original)
+++ celix/trunk/event_admin/event_admin/private/src/event_admin_impl.c Sun Jul 27 05:59:19
2014
@@ -23,6 +23,7 @@
  *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project
Team</a>
  *  \copyright	Apache License, Version 2.0
  */
+#include <stdlib.h>
 
 #include "event_admin.h"
 #include "event_admin_impl.h"
@@ -34,180 +35,180 @@
 celix_status_t eventAdmin_create(apr_pool_t *pool, bundle_context_pt context, event_admin_pt
*event_admin){
 	celix_status_t status = CELIX_SUCCESS;
 	*event_admin = apr_palloc(pool, sizeof(**event_admin));
-	if(!*event_admin){
-				status = CELIX_ENOMEM;
-		}else {
-
-			(*event_admin)->pool = pool;
-			printf("pool evenadmin create: %p\n",(*event_admin)->pool);
-			(*event_admin)->channels = hashMap_create(utils_stringHash, utils_stringHash, utils_stringEquals,
utils_stringEquals);
-			(*event_admin)->context =context;
-			printf("event admin pointer: %p\n",(*event_admin));
-			status = arrayList_create(&(*event_admin)->event_handlers);
-		}
+	if (!*event_admin) {
+        status = CELIX_ENOMEM;
+    } else {
+        (*event_admin)->pool = pool;
+        (*event_admin)->channels = hashMap_create(utils_stringHash, utils_stringHash,
utils_stringEquals, utils_stringEquals);
+        (*event_admin)->context =context;
+        status = arrayList_create(&(*event_admin)->event_handlers);
+    }
 	return status;
 }
 
 celix_status_t eventAdmin_getEventHandlersByChannel(bundle_context_pt context, const char
* serviceName, array_list_pt *eventHandlers) {
-	celix_status_t status = CELIX_SUCCESS;
-	status = bundleContext_getServiceReferences(context, serviceName,NULL, eventHandlers);
+	celix_status_t status = bundleContext_getServiceReferences(context, serviceName, NULL, eventHandlers);
 	return status;
 }
 
-celix_status_t eventAdmin_postEvent(event_admin_pt event_admin, event_pt event){
+celix_status_t eventAdmin_postEvent(event_admin_pt event_admin, event_pt event) {
 	celix_status_t status = CELIX_SUCCESS;
-	array_list_pt event_handlers = NULL;
+
 	char *topic;
-		eventAdmin_getTopic(&event,&topic);
-	eventAdmin_lockHandlersList(event_admin,topic);
-	printf("post called\n");
-	eventAdmin_releaseHandersList(event_admin,topic);
+    eventAdmin_getTopic(&event, &topic);
+
+	array_list_pt event_handlers;
+	arrayList_create(&event_handlers);
+	eventAdmin_lockHandlersList(event_admin, topic);
+	eventAdmin_findHandlersByTopic(event_admin->channels, topic, event_handlers);
+    // TODO make this async!
+	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);
+		printf("handler found (POST EVENT) for %s\n", topic);
+		event_handler_service->handle_event(&event_handler_service->event_handler, event);
+	}
+	eventAdmin_releaseHandersList(event_admin, topic);
 	return status;
 }
 
-celix_status_t eventAdmin_sendEvent(event_admin_pt event_admin, event_pt event){
+celix_status_t eventAdmin_sendEvent(event_admin_pt event_admin, event_pt event) {
 	celix_status_t status = CELIX_SUCCESS;
-	printf("send called\n");
+
 	char *topic;
-	eventAdmin_getTopic(&event,&topic);
+	eventAdmin_getTopic(&event, &topic);
 
 	array_list_pt event_handlers;
 	arrayList_create(&event_handlers);
-	eventAdmin_lockHandlersList(event_admin,topic);
-	eventAdmin_findHandlersByTopic(event_admin->channels,topic,event_handlers);
-	array_list_iterator_pt handlers_itterator = arrayListIterator_create(event_handlers);
-	while(arrayListIterator_hasNext(handlers_itterator)){
-		void *handler = arrayListIterator_next(handlers_itterator);
-		event_handler_service_pt event_handler_service = (event_handler_service_pt) handler;
-		event_handler_service->handle_event(&event_handler_service->event_handler,event);
-		printf("handler found \n");
+	eventAdmin_lockHandlersList(event_admin, topic);
+	eventAdmin_findHandlersByTopic(event_admin->channels, topic, event_handlers);
+	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);
+		printf("handler found (SEND EVENT) for %s\n", topic);
+		event_handler_service->handle_event(&event_handler_service->event_handler, event);
 	}
-	eventAdmin_releaseHandersList(event_admin,topic);
+	eventAdmin_releaseHandersList(event_admin, topic);
 	return status;
 }
 
-
-
-celix_status_t eventAdmin_findHandlersByTopic(hash_map_pt channels, char *topic , array_list_pt
event_handlers){
+celix_status_t eventAdmin_findHandlersByTopic(hash_map_pt channels, char *topic, array_list_pt
event_handlers) {
 	celix_status_t status = CELIX_SUCCESS;
-	channel_t channel;
-	char channel_name[strlen(topic)+1];
-	strcpy(channel_name,topic);
-	printf("Finding channel: %s\n",channel_name);
-	//check if the channel exists
-	if(hashMap_containsKey(channels,channel_name)==1) {
-		printf("found channel \n");
-		channel = hashMap_get(channels,channel_name);
-		if(channel != NULL && channel->eventHandlers != NULL && hashMap_size(channel->eventHandlers)>
0 ){
-			//itterate throught the handlers and add them to the array list for result.
-			hash_map_iterator_pt hashmap_itterator =  hashMapIterator_create(channel->eventHandlers);
-			while(hashMapIterator_hasNext(hashmap_itterator)){
-				printf("add handler \n");
-				event_handler_service_pt event_handler_service = NULL;
-				event_handler_service = (event_handler_service_pt) hashMapIterator_nextValue(hashmap_itterator);
-				arrayList_add(event_handlers,event_handler_service);
+    channel_t channel = hashMap_get(channels, topic);
+	if (channel != NULL) {
+		printf("found channel: %s\n", topic);
+		if (channel->eventHandlers != NULL && !hashMap_isEmpty(channel->eventHandlers))
{
+			// iterate throught the handlers and add them to the array list for result.
+			hash_map_iterator_pt hashmap_iterator =  hashMapIterator_create(channel->eventHandlers);
+			while (hashMapIterator_hasNext(hashmap_iterator)) {
+				arrayList_add(event_handlers, (event_handler_service_pt) hashMapIterator_nextValue(hashmap_iterator));
 			}
 		}
-	}else {
-		printf("no channel\n");
+	} else {
+		printf("no such channel: %s\n", topic);
 	}
 	return status;
 }
 
 celix_status_t eventAdmin_createEventChannels(event_admin_pt *event_admin, char *topic, event_handler_service_pt
event_handler_service){
 	celix_status_t status = CELIX_SUCCESS;
-	char channel_name[strlen(topic)+1];
-	strcpy(channel_name,topic);
-	printf("Creating channel: %s\n");
-	//char complete_channel_name[strlen(topic)+1];
-	channel_t channel;
-	apr_pool_t *subPool= NULL;
-	apr_pool_create(&subPool,(*event_admin)->pool);
-	if(hashMap_containsKey((*event_admin)->channels,channel_name)==1) {
-		channel = hashMap_get((*event_admin)->channels,channel_name);
-		//hashMap_put(channel->eventHandlers,&event_handler_service,event_handler_service);
-	}else {
+    channel_t channel = hashMap_get((*event_admin)->channels, topic);
+	if (channel == NULL) {
 		//create channel
+        printf("Creating channel: %s\n", topic);
+
+        apr_pool_t *subPool = NULL;
+        apr_pool_create(&subPool, (*event_admin)->pool);
+
 		channel = apr_palloc(subPool, sizeof(*channel));
-		if(!channel){
-			status = CELIX_ENOMEM;
-		}else {
+		if (!channel) {
+            status = CELIX_ENOMEM;
+        } else {
+            char *channel_name = strdup(topic);
 			channel->topic = channel_name;
 			channel->eventHandlers = hashMap_create(NULL,NULL,NULL,NULL);
 			channel->channelLock = NULL;
-			apr_thread_mutex_create(&channel->channelLock,APR_THREAD_MUTEX_NESTED, subPool);
-			hashMap_put((*event_admin)->channels,channel_name,channel);
+            apr_thread_mutex_create(&channel->channelLock, APR_THREAD_MUTEX_NESTED,
subPool);
+			hashMap_put((*event_admin)->channels, channel_name, channel);
 		}
-		hashMap_put(channel->eventHandlers,&event_handler_service,event_handler_service);
-	}
-
+    }
+    if (channel) {
+        hashMap_put(channel->eventHandlers, &event_handler_service, event_handler_service);
+    }
 	return status;
 
 	/*apr_pool_t *subPool= NULL;
-	apr_pool_create(&subPool,(*event_admin)->pool);
-	char delims[] = "/";
-	char *result = NULL;
-	result = strtok( topic, delims );
-	if(result != NULL){
-		strcpy(complete_channel_name, result);
-	}
-	while( result != NULL  && status == CELIX_SUCCESS) {
-	    channel_t channel;
-	    //check if the channel exists
-	    if(hashMap_containsKey((*event_admin)->channels,complete_channel_name)==1) {
-	    	channel = hashMap_get((*event_admin)->channels,complete_channel_name);
-	    	//hashMap_put(channel->eventHandlers,&event_handler_service,event_handler_service);
-	    }else {
-	    	//create channel
-	    	channel = apr_palloc(subPool, sizeof(*channel));
-	    	if(!channel){
-	    		status = CELIX_ENOMEM;
-	    	}else {
-	    		channel->topic = complete_channel_name;
-				channel->eventHandlers = hashMap_create(NULL,NULL,NULL,NULL);
-				channel->channelLock = NULL;
-				apr_thread_mutex_create(&channel->channelLock,APR_THREAD_MUTEX_NESTED, subPool);
-	    	}
-	    }
-	    result = strtok( NULL, delims );
-	    if(result != NULL && status == CELIX_SUCCESS){
-	    	strcat(complete_channel_name, "/");
-	    	strcat(complete_channel_name, result);
-	    }else if(status == CELIX_SUCCESS) {
-	    	hashMap_put(channel->eventHandlers,&event_handler_service,event_handler_service);
-	    }
-	}*/
+     apr_pool_create(&subPool,(*event_admin)->pool);
+     char delims[] = "/";
+     char *result = NULL;
+     result = strtok( topic, delims );
+     if(result != NULL){
+     strcpy(complete_channel_name, result);
+     }
+     while( result != NULL  && status == CELIX_SUCCESS) {
+     channel_t channel;
+     //check if the channel exists
+     if(hashMap_containsKey((*event_admin)->channels,complete_channel_name)==1) {
+     channel = hashMap_get((*event_admin)->channels,complete_channel_name);
+     //hashMap_put(channel->eventHandlers,&event_handler_service,event_handler_service);
+     }else {
+     //create channel
+     channel = apr_palloc(subPool, sizeof(*channel));
+     if(!channel){
+     status = CELIX_ENOMEM;
+     }else {
+     channel->topic = complete_channel_name;
+     channel->eventHandlers = hashMap_create(NULL,NULL,NULL,NULL);
+     channel->channelLock = NULL;
+     apr_thread_mutex_create(&channel->channelLock,APR_THREAD_MUTEX_NESTED, subPool);
+     }
+     }
+     result = strtok( NULL, delims );
+     if(result != NULL && status == CELIX_SUCCESS){
+     strcat(complete_channel_name, "/");
+     strcat(complete_channel_name, result);
+     }else if(status == CELIX_SUCCESS) {
+     hashMap_put(channel->eventHandlers,&event_handler_service,event_handler_service);
+     }
+     }*/
 
 }
 
-celix_status_t eventAdmin_lockHandlersList(event_admin_pt event_admin, char *topic ){
-	celix_status_t status = CELIX_SUCCESS;
-	char *channel_name;
-	printf("lock: %s\n",topic);
-
-	printf("LOCK!\n");
+celix_status_t eventAdmin_lockHandlersList(event_admin_pt event_admin, char *topic) {
+	celix_status_t status = CELIX_SUCCESS;
+    channel_t channel = hashMap_get(event_admin->channels, topic);
+	if (channel != NULL) {
+        // TODO verify this will never deadlock...
+        apr_status_t status;
+        do {
+            status = apr_thread_mutex_trylock(channel->channelLock);
+        } while (status != 0 && !APR_STATUS_IS_EBUSY(status));
+        printf("LOCK: %s!\n", topic);
+    }
 	return status;
 }
-celix_status_t eventAdmin_releaseHandersList(event_admin_pt event_admin, char *topic ){
-	celix_status_t status = CELIX_SUCCESS;
-	char *channel_name;
-	printf("release: %s\n",topic);
 
-	printf("UNLOCK\n");
+celix_status_t eventAdmin_releaseHandersList(event_admin_pt event_admin, char *topic) {
+	celix_status_t status = CELIX_SUCCESS;
+    channel_t channel = hashMap_get(event_admin->channels, topic);
+	if (channel != NULL) {
+        // TODO check the result value...
+        apr_status_t status = apr_thread_mutex_unlock(channel->channelLock);
+        printf("UNLOCK: %s!\n", topic);
+    }
 	return status;
 }
 
 celix_status_t eventAdmin_addingService(void * handle, service_reference_pt ref, void **service)
{
-
 	celix_status_t status = CELIX_SUCCESS;
 	event_admin_pt  event_admin = handle;
 	status = bundleContext_getService(event_admin->context, ref, service);
-  	return CELIX_SUCCESS;
+  	return status;
 }
 
 celix_status_t eventAdmin_addedService(void * handle, service_reference_pt ref, void * service)
{
 	celix_status_t status = CELIX_SUCCESS;
-	event_admin_pt  event_admin = handle;
+	event_admin_pt event_admin = handle;
 	event_handler_service_pt event_handler_service = NULL;
 	event_handler_service = (event_handler_service_pt) service;
 	service_registration_pt registration = NULL;
@@ -215,9 +216,9 @@ celix_status_t eventAdmin_addedService(v
 	properties_pt props = NULL;
 	serviceRegistration_getProperties(registration, &props);
 	char *topic = properties_get(props, (char*)EVENT_TOPIC);
-	printf("Original TOPIC: %s\n,",topic);
+	printf("Original TOPIC: %s\n", topic);
 	eventAdmin_createEventChannels(&event_admin,topic,event_handler_service);
-	return CELIX_SUCCESS;
+	return status;
 }
 
 celix_status_t eventAdmin_modifiedService(void * handle, service_reference_pt ref, void *
service) {

Modified: celix/trunk/event_admin/event_handler/private/src/event_handler_activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/event_admin/event_handler/private/src/event_handler_activator.c?rev=1613753&r1=1613752&r2=1613753&view=diff
==============================================================================
--- celix/trunk/event_admin/event_handler/private/src/event_handler_activator.c (original)
+++ celix/trunk/event_admin/event_handler/private/src/event_handler_activator.c Sun Jul 27
05:59:19 2014
@@ -17,11 +17,11 @@
  *under the License.
  */
 /*
- * activator.c
+ * event_handler_activator.c
  *
- *  Created on: Jul 9, 2013
- *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project
Team</a>
- *  \copyright	Apache License, Version 2.0
+ * Created on: Jul 9, 2013
+ * \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project
Team</a>
+ * \copyright	Apache License, Version 2.0
  */
 #include <stdlib.h>
 
@@ -42,23 +42,26 @@ celix_status_t bundleActivator_create(bu
 	apr_pool_t *pool = NULL;
 	apr_pool_t *parentPool;
 	struct activator *activator;
+
 	status = bundleContext_getMemoryPool(context, &parentPool);
-	if( status == CELIX_SUCCESS ) {
-		if(apr_pool_create(&pool,parentPool) != APR_SUCCESS) {
+	if (status == CELIX_SUCCESS) {
+		if (apr_pool_create(&pool,parentPool) != APR_SUCCESS) {
 			status = CELIX_BUNDLE_EXCEPTION;
-		}else {
-			activator = apr_palloc(pool,sizeof(*activator));
+		} else {
+			activator = apr_palloc(pool, sizeof(*activator));
 			activator->pool = pool;
 			activator->registration = NULL;
 			*userData = activator;
+
 			event_handler_pt event_handler = NULL;
 			event_handler_service_pt event_handler_service = NULL;
-			status = eventHandlerCreate(activator->pool,context,&event_handler);
-			if(status == CELIX_SUCCESS){
-				event_handler_service = apr_palloc(activator->pool,sizeof(event_handler_service));
-				if(!event_handler_service){
+
+			status = eventHandlerCreate(activator->pool, context, &event_handler);
+			if (status == CELIX_SUCCESS) {
+				event_handler_service = apr_palloc(activator->pool, sizeof(event_handler_service));
+				if (!event_handler_service) {
 					status = CELIX_ENOMEM;
-				}else {
+				} else {
 					event_handler_service->event_handler = event_handler;
 					event_handler_service->handle_event = eventHandlerHandleEvent;
 				}
@@ -73,20 +76,21 @@ celix_status_t bundleActivator_create(bu
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
 	celix_status_t status = CELIX_SUCCESS;
 	struct activator *activator = userData;
+
 	properties_pt properties = NULL;
 	properties = properties_create();
 	properties_set(properties,(char*)EVENT_HANDLER_SERVICE,(char *)EVENT_HANDLER_NAME);
 	properties_set(properties,(char*)EVENT_TOPIC, (char*) "log/error/eventpublishers/event");
+
 	event_handler_service_pt event_handler_service = activator->event_handler_service;
 	bundleContext_registerService(context, (char *) EVENT_HANDLER_SERVICE, event_handler_service,
properties, &activator->registration);
 	apr_pool_t *pool;
 	status = bundleContext_getMemoryPool(context, &pool);
-	if(status == CELIX_SUCCESS) {
+	if (status == CELIX_SUCCESS) {
 		service_tracker_customizer_pt customizer = NULL;
 		service_tracker_pt tracker = NULL;
-		serviceTrackerCustomizer_create(activator->event_handler_service->event_handler,
 eventHandlerAddingService, eventHandlerAddedService, eventHandlerModifiedService, eventHandlerRemovedService,
&customizer);
-		serviceTracker_create(context, (char *) EVENT_ADMIN_NAME, customizer,
-									&tracker);
+		serviceTrackerCustomizer_create(activator->event_handler_service->event_handler,
eventHandlerAddingService, eventHandlerAddedService, eventHandlerModifiedService, eventHandlerRemovedService,
&customizer);
+		serviceTracker_create(context, (char *) EVENT_ADMIN_NAME, customizer, &tracker);
 		activator->eventAdminTracker = tracker;
 		serviceTracker_open(tracker);
 		properties_pt properties = NULL;
@@ -97,13 +101,11 @@ celix_status_t bundleActivator_start(voi
 
 celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
 	celix_status_t status = CELIX_SUCCESS;
-
 	return status;
 }
 
 
 celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
 	celix_status_t status = CELIX_SUCCESS;
-
 	return status;
 }

Modified: celix/trunk/event_admin/event_handler/private/src/event_handler_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/event_admin/event_handler/private/src/event_handler_impl.c?rev=1613753&r1=1613752&r2=1613753&view=diff
==============================================================================
--- celix/trunk/event_admin/event_handler/private/src/event_handler_impl.c (original)
+++ celix/trunk/event_admin/event_handler/private/src/event_handler_impl.c Sun Jul 27 05:59:19
2014
@@ -31,67 +31,65 @@ struct event_handler {
 	bundle_context_pt context;
 };
 
-celix_status_t eventHandlerCreate(apr_pool_t *pool, bundle_context_pt context,  event_handler_pt
*event_handler){
+celix_status_t eventHandlerCreate(apr_pool_t *pool, bundle_context_pt context, event_handler_pt
*event_handler){
 	celix_status_t status = CELIX_SUCCESS;
 	*event_handler = apr_palloc(pool, sizeof(**event_handler));
-	if(!*event_handler){
-			status = CELIX_ENOMEM;
-	}else {
-			(*event_handler)->pool = pool;
-			(*event_handler)->event_admin_service = NULL;
-			(*event_handler)->context = context;
+	if (!*event_handler) {
+        status = CELIX_ENOMEM;
+	} else {
+        (*event_handler)->pool = pool;
+        (*event_handler)->event_admin_service = NULL;
+        (*event_handler)->context = context;
 	}
 	return status;
 }
 
 celix_status_t eventHandlerHandleEvent(event_handler_pt *event_handler, event_pt event) {
 	celix_status_t status = CELIX_SUCCESS;
-	printf("handle event called in first handler\n");
-	if(event != NULL){
+	if (event != NULL) {
 		char *topic = NULL;
-		status = (*event_handler)->event_admin_service->getTopic(&event,&topic);
-		printf("topic of event: %s\n",topic);
+		status = (*event_handler)->event_admin_service->getTopic(&event, &topic);
+		printf("[SUB] topic of event: %s\n", topic);
+
 		array_list_pt propertyNames;
 		arrayList_create(&propertyNames);
-		status = (*event_handler)->event_admin_service->getPropertyNames(&event,&propertyNames);
+		status = (*event_handler)->event_admin_service->getPropertyNames(&event, &propertyNames);
+
 		array_list_iterator_pt propertyIter = arrayListIterator_create(propertyNames);
-		while(arrayListIterator_hasNext(propertyIter)){
+		while (arrayListIterator_hasNext(propertyIter)) {
 			char *key = arrayListIterator_next(propertyIter);
 			char *value = NULL;
 			(*event_handler)->event_admin_service->getProperty(&event,key,&value);
-			//getProperty(&event,key,&value);
-			printf("Key: %s value: %s\n",key,value);
+
+			printf("[SUB] Key: %s value: %s\n",key,value);
 		}
 	}
 	return status;
 }
 
 
-celix_status_t  eventHandlerAddingService(void * handle, service_reference_pt ref, void **service)
{
+celix_status_t eventHandlerAddingService(void * handle, service_reference_pt ref, void **service)
{
 	celix_status_t status = CELIX_SUCCESS;
-	printf("event handler adding service \n");
 	event_handler_pt event_handler = handle;
 	status = bundleContext_getService(event_handler->context, ref, service);
 	return status;
 }
 
-celix_status_t  eventHandlerAddedService(void * handle, service_reference_pt ref, void *
service) {
-	printf("Event handler Added service \n");
-	event_handler_pt  data =  handle;
-	event_admin_service_pt event_admin_service = NULL;
-	event_admin_service = (event_admin_service_pt ) service;
-	data->event_admin_service = event_admin_service;
+celix_status_t eventHandlerAddedService(void * handle, service_reference_pt ref, void * service)
{
+	printf("[SUB] Event admin added...\n");
+	event_handler_pt data = handle;
+	data->event_admin_service = (event_admin_service_pt) service;
 	return CELIX_SUCCESS;
 }
 
-celix_status_t  eventHandlerModifiedService(void * handle, service_reference_pt ref, void
* service) {
-	struct data * data = (struct data *) handle;
-	printf("Event admin Modified\n");
+celix_status_t eventHandlerModifiedService(void * handle, service_reference_pt ref, void
* service) {
+	printf("[SUB] Event admin modified...\n");
 	return CELIX_SUCCESS;
 }
 
-celix_status_t  eventHandlerRemovedService(void * handle, service_reference_pt ref, void
* service) {
-	struct data * data = (struct data *) handle;
-	printf("Event admin Removed %p\n", service);
+celix_status_t eventHandlerRemovedService(void * handle, service_reference_pt ref, void *
service) {
+	printf("[SUB] Event admin removed...\n");
+	event_handler_pt data = handle;
+	data->event_admin_service = NULL;
 	return CELIX_SUCCESS;
 }

Modified: celix/trunk/event_admin/event_publisher/private/include/event_publisher_impl.h
URL: http://svn.apache.org/viewvc/celix/trunk/event_admin/event_publisher/private/include/event_publisher_impl.h?rev=1613753&r1=1613752&r2=1613753&view=diff
==============================================================================
--- celix/trunk/event_admin/event_publisher/private/include/event_publisher_impl.h (original)
+++ celix/trunk/event_admin/event_publisher/private/include/event_publisher_impl.h Sun Jul
27 05:59:19 2014
@@ -39,6 +39,8 @@
 #include "event_constants.h"
 #include <apr.h>
 #include <apr_pools.h>
+#include <apr_thread_proc.h>
+
 typedef struct event_publisher *event_publisher_pt;
 struct event_publisher {
 	apr_pool_t *pool;

Modified: celix/trunk/event_admin/event_publisher/private/src/event_publisher_activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/event_admin/event_publisher/private/src/event_publisher_activator.c?rev=1613753&r1=1613752&r2=1613753&view=diff
==============================================================================
--- celix/trunk/event_admin/event_publisher/private/src/event_publisher_activator.c (original)
+++ celix/trunk/event_admin/event_publisher/private/src/event_publisher_activator.c Sun Jul
27 05:59:19 2014
@@ -24,6 +24,7 @@
  *  \copyright	Apache License, Version 2.0
  */
 #include <stdlib.h>
+#include <apr_thread_proc.h>
 
 
 #include "event_publisher_impl.h"
@@ -70,9 +71,8 @@ celix_status_t bundleActivator_start(voi
 		service_tracker_customizer_pt cust = NULL;
 		service_tracker_pt tracker = NULL;
 		data->context = context;
-		serviceTrackerCustomizer_create(pool, data->event_publisher,  eventPublisherAddingService,
eventPublisherAddedService, eventPublisherModifiedService, eventPublisherRemovedService, &cust);
-		serviceTracker_create(pool, context, (char *) EVENT_ADMIN_NAME, cust,
-							&tracker);
+		serviceTrackerCustomizer_create(data->event_publisher, eventPublisherAddingService,
eventPublisherAddedService, eventPublisherModifiedService, eventPublisherRemovedService, &cust);
+		serviceTracker_create(context, (char *) EVENT_ADMIN_NAME, cust, &tracker);
 		data->tracker = tracker;
 
 		serviceTracker_open(tracker);

Modified: celix/trunk/event_admin/event_publisher/private/src/event_publisher_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/event_admin/event_publisher/private/src/event_publisher_impl.c?rev=1613753&r1=1613752&r2=1613753&view=diff
==============================================================================
--- celix/trunk/event_admin/event_publisher/private/src/event_publisher_impl.c (original)
+++ celix/trunk/event_admin/event_publisher/private/src/event_publisher_impl.c Sun Jul 27
05:59:19 2014
@@ -17,40 +17,38 @@
  *under the License.
  */
 /*
- * event_admin_impl.c
+ * event_publisher_impl.c
  *
- *  Created on: Jul 24, 2013
-  *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project
Team</a>
- *  \copyright	Apache License, Version 2.0
+ * Created on: Jul 24, 2013
+ * \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project
Team</a>
+ * \copyright	Apache License, Version 2.0
  */
 
 #include "event_publisher_impl.h"
 
-celix_status_t eventPublisherCreate(apr_pool_t *pool, bundle_context_pt context, event_publisher_pt
*event_publisher){
-        celix_status_t status = CELIX_SUCCESS;
-        *event_publisher = apr_palloc(pool, sizeof(**event_publisher));
-
-        if(!*event_publisher){
-                status = CELIX_ENOMEM;
-        }else {
-        	(*event_publisher)->event_admin_service = NULL;
-        	(*event_publisher)->pool = NULL;
-        	(*event_publisher)->eventAdminAdded = false;
-        	(*event_publisher)->running = false;
-        	(*event_publisher)->pool = pool;
-        	(*event_publisher)->context = context;
-        }
-        return status;
+celix_status_t eventPublisherCreate(apr_pool_t *pool, bundle_context_pt context, event_publisher_pt
*event_publisher) {
+    celix_status_t status = CELIX_SUCCESS;
+    *event_publisher = apr_palloc(pool, sizeof(**event_publisher));
+    if (!*event_publisher) {
+        status = CELIX_ENOMEM;
+    } else {
+        (*event_publisher)->event_admin_service = NULL;
+        (*event_publisher)->pool = NULL;
+        (*event_publisher)->eventAdminAdded = false;
+        (*event_publisher)->running = false;
+        (*event_publisher)->pool = pool;
+        (*event_publisher)->context = context;
+    }
+    return status;
 }
 
-celix_status_t eventPublisherStart(event_publisher_pt *event_publisher){
+celix_status_t eventPublisherStart(event_publisher_pt *event_publisher) {
 	(*event_publisher)->running = true;
 	apr_thread_create(&(*event_publisher)->sender, NULL, eventPublisherSendEventThread,
event_publisher, (*event_publisher)->pool);
-
 	return CELIX_SUCCESS;
 }
 
-celix_status_t eventPublisherStop(event_publisher_pt *event_publisher){
+celix_status_t eventPublisherStop(event_publisher_pt *event_publisher) {
 	(*event_publisher)->running = false;
 	apr_status_t status;
 	apr_thread_join(&status,(*event_publisher)->sender);
@@ -58,72 +56,51 @@ celix_status_t eventPublisherStop(event_
 }
 
 static void *APR_THREAD_FUNC eventPublisherSendEventThread(apr_thread_t *thd, void *handle)
{
-//celix_status_t trk_send(apr_thread_t *thd, void *handle) { //this function decleration
is for debuggin purposes only.
-	/*event_publisher_pt client =  handle;
+    event_publisher_pt *client = (event_publisher_pt *) handle;
 
-	while (client->running && client->eventAdminAdded) {
-		apr_sleep(1000000);
-		event_admin_service_pt event_admin_service = client->event_admin_service ;
-		event_admin_pt event_admin =   event_admin_service->eventAdmin;
-		if (event_admin_service != NULL) {
-			event_pt event;
-			properties_pt props = properties_create();
-			properties_set(props,"This is a key","this is a value");
-
-			createEvent("log/error/eventpublishers/event/testChannel",props,client->pool,&event);
-			event_admin_service->postEvent(event_admin,event);
-			event_admin_service->sendEvent(event_admin,event);
-		}
-
-	}*/
-	 event_publisher_pt *client = (event_publisher_pt *) handle;
-
-		while ((*client)->running && (*client)->eventAdminAdded) {
-				apr_sleep(1000000);
-				event_admin_service_pt *event_admin_service = &(*client)->event_admin_service
;
-				printf("event admin service pointer in publisher : %p\n",event_admin_service);
-				event_admin_pt event_admin =   (*event_admin_service)->eventAdmin;
-				if (event_admin_service != NULL) {
-
-						event_pt event;
-						properties_pt props = properties_create();
-						properties_set(props,"This is a key","this is a value");
-						(*event_admin_service)->createEvent(event_admin,"log/error/eventpublishers/event/testChannel",props,&event);
-						(*event_admin_service)->postEvent(event_admin,event);
-						(*event_admin_service)->sendEvent(event_admin,event);
-				}
+    while ((*client)->running && (*client)->eventAdminAdded) {
+        apr_sleep(1000000); // 1 sec.
 
-		}
+        event_admin_service_pt *event_admin_service = &(*client)->event_admin_service;
+        event_admin_pt event_admin = (*event_admin_service)->eventAdmin;
+        if (event_admin_service != NULL) {
+            event_pt event;
+            properties_pt props = properties_create();
+            properties_set(props, "This is a key", "this is a value");
+            (*event_admin_service)->createEvent(event_admin, "log/error/eventpublishers/event",
props, &event);
+            (*event_admin_service)->postEvent(event_admin, event);
+            (*event_admin_service)->sendEvent(event_admin, event);
+        }
+    }
 	apr_thread_exit(thd, APR_SUCCESS);
 	return NULL;
 }
 
-celix_status_t  eventPublisherAddingService(void * handle, service_reference_pt ref, void
**service) {
+celix_status_t eventPublisherAddingService(void * handle, service_reference_pt ref, void
**service) {
 	celix_status_t status = CELIX_SUCCESS;
 	event_publisher_pt event_publisher = handle;
 	status = bundleContext_getService(event_publisher->context, ref, service);
 	return status;
 }
 
-celix_status_t  eventPublisherAddedService(void * handle, service_reference_pt ref, void
* service) {
-
-	 event_publisher_pt  data =  handle;
-	 event_admin_service_pt event_admin_service = NULL;
-	 event_admin_service = (event_admin_service_pt ) service;
-	 data->event_admin_service = event_admin_service;
-	 data->eventAdminAdded = true;
+celix_status_t eventPublisherAddedService(void * handle, service_reference_pt ref, void *
service) {
+    printf("[PUB] Event admin added...\n");
+    event_publisher_pt data = handle;
+    data->event_admin_service = (event_admin_service_pt) service;
+    data->eventAdminAdded = true;
 	return CELIX_SUCCESS;
 }
 
-celix_status_t  eventPublisherModifiedService(void * handle, service_reference_pt ref, void
* service) {
-	struct data * data = (struct data *) handle;
-	printf("Event admin Modified\n");
+celix_status_t eventPublisherModifiedService(void * handle, service_reference_pt ref, void
* service) {
+	printf("[PUB] Event admin modified...\n");
 	return CELIX_SUCCESS;
 }
 
-celix_status_t  eventPublisherRemovedService(void * handle, service_reference_pt ref, void
* service) {
-	struct data * data = (struct data *) handle;
-	printf("Event admin Removed %p\n", service);
+celix_status_t eventPublisherRemovedService(void * handle, service_reference_pt ref, void
* service) {
+	printf("[PUB] Event admin removed...\n");
+    event_publisher_pt data = handle;
+    data->event_admin_service = NULL;
+    data->eventAdminAdded = false;
 	return CELIX_SUCCESS;
 }
 



Mime
View raw message