celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1647258 - in /celix/trunk: dependency_manager_2/private/include/ dependency_manager_2/private/src/ dependency_manager_2/public/include/ examples/whiteboard/tracker_depman/private/include/ examples/whiteboard/tracker_depman/private/src/
Date Mon, 22 Dec 2014 08:29:35 GMT
Author: abroekhuis
Date: Mon Dec 22 08:29:34 2014
New Revision: 1647258

URL: http://svn.apache.org/r1647258
Log:
Updated new DM, added cleanup.

Modified:
    celix/trunk/dependency_manager_2/private/include/dm_event.h
    celix/trunk/dependency_manager_2/private/src/dm_component_impl.c
    celix/trunk/dependency_manager_2/private/src/dm_event.c
    celix/trunk/dependency_manager_2/private/src/dm_service_dependency.c
    celix/trunk/dependency_manager_2/public/include/dm_component.h
    celix/trunk/dependency_manager_2/public/include/dm_service_dependency.h
    celix/trunk/examples/whiteboard/tracker_depman/private/include/tracker.h
    celix/trunk/examples/whiteboard/tracker_depman/private/src/dependency_activator.c

Modified: celix/trunk/dependency_manager_2/private/include/dm_event.h
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/private/include/dm_event.h?rev=1647258&r1=1647257&r2=1647258&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/private/include/dm_event.h (original)
+++ celix/trunk/dependency_manager_2/private/include/dm_event.h Mon Dec 22 08:29:34 2014
@@ -54,5 +54,7 @@ typedef struct dm_event *dm_event_pt;
 celix_status_t event_create(dm_event_type_e event_type, bundle_pt bundle, bundle_context_pt
context, service_reference_pt reference, void *service, dm_event_pt *event);
 celix_status_t event_destroy(dm_event_pt *event);
 
+celix_status_t event_equals(void *a, void *b, bool *equals);
+
 
 #endif /* DM_EVENT_H_ */

Modified: celix/trunk/dependency_manager_2/private/src/dm_component_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/private/src/dm_component_impl.c?rev=1647258&r1=1647257&r2=1647258&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/private/src/dm_component_impl.c (original)
+++ celix/trunk/dependency_manager_2/private/src/dm_component_impl.c Mon Dec 22 08:29:34 2014
@@ -95,21 +95,24 @@ celix_status_t component_create(bundle_c
         (*component)->context = context;
         (*component)->manager = manager;
 
-        (*component)->state = DM_CMP_STATE_INACTIVE;
+        (*component)->serviceName = NULL;
+        (*component)->implementation = NULL;
+        (*component)->properties = NULL;
+        (*component)->registration = NULL;
 
         (*component)->callbackInit = NULL;
         (*component)->callbackStart = NULL;
         (*component)->callbackStop = NULL;
         (*component)->callbackDestroy = NULL;
 
-        (*component)->implementation = NULL;
 
         arrayList_create(&(*component)->dependencies);
-
         pthread_mutex_init(&(*component)->mutex, NULL);
 
+        (*component)->state = DM_CMP_STATE_INACTIVE;
         (*component)->isStarted = false;
         (*component)->active = false;
+
         (*component)->dependencyEvents = hashMap_create(NULL, NULL, NULL, NULL);
 
         (*component)->executor = NULL;
@@ -119,21 +122,22 @@ celix_status_t component_create(bundle_c
     return status;
 }
 
-celix_status_t component_destroy(dm_component_pt component_ptr) {
+celix_status_t component_destroy(dm_component_pt *component_ptr) {
 	celix_status_t status = CELIX_SUCCESS;
 
-	if (!component_ptr) {
+	if (!*component_ptr) {
 		status = CELIX_ILLEGAL_ARGUMENT;
 	}
 
 	if (status == CELIX_SUCCESS) {
 		// #TODO destroy dependencies?
-		executor_destroy(&component_ptr->executor);
-		hashMap_destroy(component_ptr->dependencyEvents, false, false);
-		pthread_mutex_destroy(&component_ptr->mutex);
-		arrayList_destroy(component_ptr->dependencies);
+		executor_destroy(&(*component_ptr)->executor);
+		hashMap_destroy((*component_ptr)->dependencyEvents, false, false);
+		pthread_mutex_destroy(&(*component_ptr)->mutex);
+		arrayList_destroy((*component_ptr)->dependencies);
 
-		free(component_ptr);
+		free(*component_ptr);
+		*component_ptr = NULL;
 	}
 
 	return status;
@@ -173,7 +177,7 @@ celix_status_t component_addTask(dm_comp
 
         pthread_mutex_lock(&component->mutex);
         array_list_pt events = NULL;
-        arrayList_create(&events);
+        arrayList_createWithEquals(event_equals, &events);
         hashMap_put(component->dependencyEvents, dependency, events);
 
         arrayList_add(component->dependencies, dependency);
@@ -313,8 +317,11 @@ celix_status_t component_handleEventTask
 celix_status_t component_handleAdded(dm_component_pt component, dm_service_dependency_pt
dependency, dm_event_pt event) {
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
     arrayList_add(events, event);
+    pthread_mutex_unlock(&component->mutex);
+
     serviceDependency_setAvailable(dependency, true);
 
     switch (component->state) {
@@ -359,9 +366,12 @@ celix_status_t component_handleAdded(dm_
 celix_status_t component_handleChanged(dm_component_pt component, dm_service_dependency_pt
dependency, dm_event_pt event) {
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
-    arrayList_removeElement(events, event);
+    int index = arrayList_indexOf(events, event);
+    dm_event_pt old = arrayList_remove(events, index);
     arrayList_add(events, event);
+    pthread_mutex_unlock(&component->mutex);
 
     switch (component->state) {
         case DM_CMP_STATE_TRACKING_OPTIONAL:
@@ -381,21 +391,28 @@ celix_status_t component_handleChanged(d
             break;
     }
 
+    event_destroy(&old);
+
     return status;
 }
 
 celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dependency_pt
dependency, dm_event_pt event) {
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
     int size = arrayList_size(events);
     if (arrayList_contains(events, event)) {
         size--;
     }
+    pthread_mutex_unlock(&component->mutex);
     serviceDependency_setAvailable(dependency, size > 0);
     component_handleChange(component);
 
-    arrayList_removeElement(events, event);
+    pthread_mutex_lock(&component->mutex);
+    int index = arrayList_indexOf(events, event);
+	dm_event_pt old = arrayList_remove(events, index);
+	pthread_mutex_unlock(&component->mutex);
 
     switch (component->state) {
         case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
@@ -419,15 +436,23 @@ celix_status_t component_handleRemoved(d
             break;
     }
 
+    event_destroy(&event);
+    if (old) {
+    	event_destroy(&old);
+    }
+
     return status;
 }
 
 celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dependency_pt
dependency, dm_event_pt event, dm_event_pt newEvent) {
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
-    arrayList_removeElement(events, event);
+    int index = arrayList_indexOf(events, event);
+	dm_event_pt old = arrayList_remove(events, index);
     arrayList_add(events, newEvent);
+    pthread_mutex_unlock(&component->mutex);
 
     switch (component->state) {
         case DM_CMP_STATE_WAITING_FOR_REQUIRED:
@@ -452,6 +477,11 @@ celix_status_t component_handleSwapped(d
             break;
     }
 
+    event_destroy(&event);
+	if (old) {
+		event_destroy(&old);
+	}
+
     return status;
 }
 
@@ -482,10 +512,12 @@ celix_status_t component_startDependenci
 celix_status_t component_stopDependencies(dm_component_pt component) {
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     for (int i = 0; i < arrayList_size(component->dependencies); i++) {
         dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
         serviceDependency_stop(dependency);
     }
+    pthread_mutex_unlock(&component->mutex);
 
     return status;
 }
@@ -656,6 +688,7 @@ celix_status_t component_performTransiti
 celix_status_t component_allRequiredAvailable(dm_component_pt component, bool *available)
{
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     *available = true;
     for (int i = 0; i < arrayList_size(component->dependencies); i++) {
         dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
@@ -674,6 +707,7 @@ celix_status_t component_allRequiredAvai
             }
         }
     }
+    pthread_mutex_unlock(&component->mutex);
 
     return status;
 }
@@ -681,6 +715,7 @@ celix_status_t component_allRequiredAvai
 celix_status_t component_allInstanceBoundAvailable(dm_component_pt component, bool *available)
{
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     *available = true;
     for (int i = 0; i < arrayList_size(component->dependencies); i++) {
         dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
@@ -699,6 +734,7 @@ celix_status_t component_allInstanceBoun
             }
         }
     }
+    pthread_mutex_unlock(&component->mutex);
 
     return status;
 }
@@ -706,6 +742,7 @@ celix_status_t component_allInstanceBoun
 celix_status_t component_invokeAddRequiredDependencies(dm_component_pt component) {
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     for (int i = 0; i < arrayList_size(component->dependencies); i++) {
         dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
 
@@ -725,6 +762,7 @@ celix_status_t component_invokeAddRequir
             }
         }
     }
+    pthread_mutex_unlock(&component->mutex);
 
     return status;
 }
@@ -732,6 +770,7 @@ celix_status_t component_invokeAddRequir
 celix_status_t component_invokeAddRequiredInstanceBoundDependencies(dm_component_pt component)
{
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     for (int i = 0; i < arrayList_size(component->dependencies); i++) {
         dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
 
@@ -751,6 +790,7 @@ celix_status_t component_invokeAddRequir
             }
         }
     }
+    pthread_mutex_unlock(&component->mutex);
 
     return status;
 }
@@ -758,6 +798,7 @@ celix_status_t component_invokeAddRequir
 celix_status_t component_invokeAddOptionalDependencies(dm_component_pt component) {
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     for (int i = 0; i < arrayList_size(component->dependencies); i++) {
         dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
 
@@ -775,6 +816,7 @@ celix_status_t component_invokeAddOption
             }
         }
     }
+    pthread_mutex_unlock(&component->mutex);
 
     return status;
 }
@@ -782,6 +824,7 @@ celix_status_t component_invokeAddOption
 celix_status_t component_invokeRemoveOptionalDependencies(dm_component_pt component) {
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     for (int i = 0; i < arrayList_size(component->dependencies); i++) {
         dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
 
@@ -799,6 +842,7 @@ celix_status_t component_invokeRemoveOpt
             }
         }
     }
+    pthread_mutex_unlock(&component->mutex);
 
     return status;
 }
@@ -806,6 +850,7 @@ celix_status_t component_invokeRemoveOpt
 celix_status_t component_invokeRemoveInstanceBoundDependencies(dm_component_pt component)
{
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     for (int i = 0; i < arrayList_size(component->dependencies); i++) {
         dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
 
@@ -823,6 +868,7 @@ celix_status_t component_invokeRemoveIns
             }
         }
     }
+    pthread_mutex_unlock(&component->mutex);
 
     return status;
 }
@@ -830,6 +876,7 @@ celix_status_t component_invokeRemoveIns
 celix_status_t component_invokeRemoveRequiredDependencies(dm_component_pt component) {
     celix_status_t status = CELIX_SUCCESS;
 
+    pthread_mutex_lock(&component->mutex);
     for (int i = 0; i < arrayList_size(component->dependencies); i++) {
         dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
 
@@ -849,6 +896,7 @@ celix_status_t component_invokeRemoveReq
             }
         }
     }
+    pthread_mutex_unlock(&component->mutex);
 
     return status;
 }
@@ -1021,6 +1069,8 @@ celix_status_t executor_runTasks(dm_exec
             entry->command(entry->component, entry->data);
 
             pthread_mutex_lock(&executor->mutex);
+
+            free(entry);
         }
         executor->runningThreadSet = false;
         pthread_mutex_unlock(&executor->mutex);

Modified: celix/trunk/dependency_manager_2/private/src/dm_event.c
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/private/src/dm_event.c?rev=1647258&r1=1647257&r2=1647258&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/private/src/dm_event.c (original)
+++ celix/trunk/dependency_manager_2/private/src/dm_event.c Mon Dec 22 08:29:34 2014
@@ -42,3 +42,19 @@ celix_status_t event_destroy(dm_event_pt
 
 	return status;
 }
+
+celix_status_t event_equals(void *a, void *b, bool *equals) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (!a || !b) {
+		*equals = false;
+	} else {
+		dm_event_pt a_ptr = a;
+		dm_event_pt b_ptr = b;
+
+		status = serviceReference_equals(a_ptr->reference, b_ptr->reference, equals);
+	}
+
+	return status;
+
+}

Modified: celix/trunk/dependency_manager_2/private/src/dm_service_dependency.c
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/private/src/dm_service_dependency.c?rev=1647258&r1=1647257&r2=1647258&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/private/src/dm_service_dependency.c (original)
+++ celix/trunk/dependency_manager_2/private/src/dm_service_dependency.c Mon Dec 22 08:29:34
2014
@@ -68,6 +68,21 @@ celix_status_t serviceDependency_create(
 	return status;
 }
 
+celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_ptr) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (!*dependency_ptr) {
+		status = CELIX_ENOMEM;
+	}
+
+	if (status == CELIX_SUCCESS) {
+		free(*dependency_ptr);
+		*dependency_ptr = NULL;
+	}
+
+	return status;
+}
+
 celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required)
{
 	celix_status_t status = CELIX_SUCCESS;
 
@@ -207,6 +222,7 @@ celix_status_t serviceDependency_stop(dm
 	if (status == CELIX_SUCCESS) {
 		if (dependency->tracker) {
 			status = serviceTracker_close(dependency->tracker);
+			status = serviceTracker_destroy(dependency->tracker);
 		}
 	}
 

Modified: celix/trunk/dependency_manager_2/public/include/dm_component.h
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/public/include/dm_component.h?rev=1647258&r1=1647257&r2=1647258&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/public/include/dm_component.h (original)
+++ celix/trunk/dependency_manager_2/public/include/dm_component.h Mon Dec 22 08:29:34 2014
@@ -33,6 +33,7 @@
 typedef struct dm_component *dm_component_pt;
 
 #include "dm_dependency_manager.h"
+#include "dm_service_dependency.h"
 
 typedef celix_status_t (*init_fpt)(void *userData);
 typedef celix_status_t (*start_fpt)(void *userData);
@@ -40,11 +41,12 @@ typedef celix_status_t (*stop_fpt)(void
 typedef celix_status_t (*destroy_fpt)(void *userData);
 
 celix_status_t component_create(bundle_context_pt context, dm_dependency_manager_pt manager,
dm_component_pt *component);
-celix_status_t component_destroy(dm_component_pt component);
+celix_status_t component_destroy(dm_component_pt *component);
 
 celix_status_t component_setImplementation(dm_component_pt component, void *implementation);
 
 celix_status_t component_addServiceDependency(dm_component_pt component, ...);
+celix_status_t component_removeServiceDependency(dm_component_pt component, dm_service_dependency_pt
dependency);
 
 celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt
start, stop_fpt, destroy_fpt);
 

Modified: celix/trunk/dependency_manager_2/public/include/dm_service_dependency.h
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/public/include/dm_service_dependency.h?rev=1647258&r1=1647257&r2=1647258&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/public/include/dm_service_dependency.h (original)
+++ celix/trunk/dependency_manager_2/public/include/dm_service_dependency.h Mon Dec 22 08:29:34
2014
@@ -29,16 +29,17 @@
 
 #include "celix_errno.h"
 
-#include "dm_component.h"
-
 typedef struct dm_service_dependency *dm_service_dependency_pt;
 
+#include "dm_component.h"
+
 typedef celix_status_t (*service_add_fpt)(void *handle, service_reference_pt reference, void
*service);
 typedef celix_status_t (*service_change_fpt)(void *handle, service_reference_pt reference,
void *service);
 typedef celix_status_t (*service_remove_fpt)(void *handle, service_reference_pt reference,
void *service);
 typedef celix_status_t (*service_swap_fpt)(void *handle, service_reference_pt oldReference,
void *oldService, service_reference_pt newReference, void *newService);
 
 celix_status_t serviceDependency_create(dm_service_dependency_pt *dependency_ptr);
+celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_ptr);
 
 celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required);
 celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName,
char *filter);

Modified: celix/trunk/examples/whiteboard/tracker_depman/private/include/tracker.h
URL: http://svn.apache.org/viewvc/celix/trunk/examples/whiteboard/tracker_depman/private/include/tracker.h?rev=1647258&r1=1647257&r2=1647258&view=diff
==============================================================================
--- celix/trunk/examples/whiteboard/tracker_depman/private/include/tracker.h (original)
+++ celix/trunk/examples/whiteboard/tracker_depman/private/include/tracker.h Mon Dec 22 08:29:34
2014
@@ -32,6 +32,8 @@
 
 struct data {
 	dm_component_pt service;
+	dm_service_dependency_pt dep;
+	dm_service_dependency_pt dep2;
 	bundle_context_pt context;
 	array_list_pt publishers;
 	pthread_t sender;

Modified: celix/trunk/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/examples/whiteboard/tracker_depman/private/src/dependency_activator.c?rev=1647258&r1=1647257&r2=1647258&view=diff
==============================================================================
--- celix/trunk/examples/whiteboard/tracker_depman/private/src/dependency_activator.c (original)
+++ celix/trunk/examples/whiteboard/tracker_depman/private/src/dependency_activator.c Mon
Dec 22 08:29:34 2014
@@ -75,13 +75,26 @@ celix_status_t dm_init(void * userData,
     component_addServiceDependency(service, dep2, NULL);
 
 	data->service = service;
+	data->dep = dep;
+	data->dep2 = dep2;
+
 	dependencyManager_add(manager, service);
+
 	return CELIX_SUCCESS;
 }
 
 celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt
manager) {
 	struct data * data = (struct data *) userData;
 	dependencyManager_remove(manager, data->service);
+
+	component_removeServiceDependency(data->service, data->dep);
+	serviceDependency_destroy(&data->dep);
+
+	component_removeServiceDependency(data->service, data->dep2);
+	serviceDependency_destroy(&data->dep2);
+
+	component_destroy(&data->service);
+
 	arrayList_destroy(data->publishers);
 	data->publishers = NULL;
 	free(data);



Mime
View raw message