celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [1/4] celix git commit: Fixed some issue with dm. Changed some naming which reflects better with Celix (e.g. addInterface instead of setItnterface). Add support for callbacks with refs.
Date Mon, 12 Oct 2015 10:53:28 GMT
Repository: celix
Updated Branches:
  refs/heads/feature/CELIX-269_depman [created] cc6fd4322


Fixed some issue with dm. Changed some naming which reflects better with Celix (e.g. addInterface
instead of setItnterface). Add support for callbacks with refs.


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

Branch: refs/heads/feature/CELIX-269_depman
Commit: a135fad4f28842ac61a30ef1f2a24c1a163b6419
Parents: 4fc908f
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Fri Oct 9 14:11:55 2015 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Fri Oct 9 14:11:55 2015 +0200

----------------------------------------------------------------------
 .../private/include/dm_component_impl.h         | 13 +++--
 .../include/dm_service_dependency_impl.h        |  5 ++
 .../private/src/dm_activator_base.c             |  4 +-
 .../private/src/dm_component_impl.c             | 58 +++++++++++++++-----
 .../private/src/dm_service_dependency.c         | 45 +++++++++++++--
 .../public/include/dm_activator_base.h          |  1 +
 .../public/include/dm_component.h               |  2 +-
 .../public/include/dm_service_dependency.h      | 14 +++--
 framework/private/src/service_registry.c        |  2 +-
 9 files changed, 113 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/private/include/dm_component_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/include/dm_component_impl.h b/dependency_manager_2/private/include/dm_component_impl.h
index e56a261..133ef06 100644
--- a/dependency_manager_2/private/include/dm_component_impl.h
+++ b/dependency_manager_2/private/include/dm_component_impl.h
@@ -42,15 +42,20 @@ typedef enum dm_component_state {
 
 typedef struct dm_executor * dm_executor_pt;
 
+typedef struct dm_interface_struct {
+    char *serviceName;
+    void *service;
+    properties_pt properties;
+    service_registration_pt registration;
+} dm_interface;
+
 struct dm_component {
     bundle_context_pt context;
     dm_dependency_manager_pt manager;
 
-    char *serviceName;
-    void *service;
+    array_list_pt dm_interface;
+
     void *implementation;
-    properties_pt properties;
-    service_registration_pt registration;
 
     init_fpt callbackInit;
     start_fpt callbackStart;

http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/private/include/dm_service_dependency_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/include/dm_service_dependency_impl.h b/dependency_manager_2/private/include/dm_service_dependency_impl.h
index e4c0f6e..1396f31 100644
--- a/dependency_manager_2/private/include/dm_service_dependency_impl.h
+++ b/dependency_manager_2/private/include/dm_service_dependency_impl.h
@@ -46,6 +46,11 @@ struct dm_service_dependency {
 	service_remove_fpt remove;
 	service_swap_fpt swap;
 
+	service_add_with_ref_fpt add_with_ref;
+	service_change_with_ref_fpt change_with_ref;
+	service_remove_with_ref_fpt remove_with_ref;
+	service_swap_with_ref_fpt swap_with_ref;
+
 	void **autoConfigure;
 	celix_thread_mutex_t lock;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/private/src/dm_activator_base.c
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/src/dm_activator_base.c b/dependency_manager_2/private/src/dm_activator_base.c
index 7623780..a97194e 100644
--- a/dependency_manager_2/private/src/dm_activator_base.c
+++ b/dependency_manager_2/private/src/dm_activator_base.c
@@ -74,7 +74,7 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context
_
 	celix_status_t status = CELIX_SUCCESS;
 	dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
 
-	dm_destroy(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
+	dm_deinit(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
 
 	dependencyManager_destroy(&dependency_activator->manager);
 
@@ -88,6 +88,8 @@ celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt
contex
 	celix_status_t status = CELIX_SUCCESS;
 	dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
 
+	dm_destroy(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
+
 	free(dependency_activator);
 
 	return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/src/dm_component_impl.c b/dependency_manager_2/private/src/dm_component_impl.c
index 7217c24..72fe7eb 100644
--- a/dependency_manager_2/private/src/dm_component_impl.c
+++ b/dependency_manager_2/private/src/dm_component_impl.c
@@ -26,6 +26,7 @@
 
 #include <stdarg.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "dm_component_impl.h"
 #include "../../../framework/private/include/framework_private.h"
@@ -101,11 +102,9 @@ celix_status_t component_create(bundle_context_pt context, dm_dependency_manager
         (*component)->context = context;
         (*component)->manager = manager;
 
-        (*component)->serviceName = NULL;
-        (*component)->service = NULL;
+	arrayList_create(&((*component)->dm_interface));
+
         (*component)->implementation = NULL;
-        (*component)->properties = NULL;
-        (*component)->registration = NULL;
 
         (*component)->callbackInit = NULL;
         (*component)->callbackStart = NULL;
@@ -137,6 +136,15 @@ celix_status_t component_destroy(dm_component_pt *component_ptr) {
 	}
 
 	if (status == CELIX_SUCCESS) {
+		unsigned int i;
+
+		for (i = 0; i < arrayList_size((*component_ptr)->dm_interface); i++) {
+		    dm_interface *interface = arrayList_get((*component_ptr)->dm_interface, i);
+
+		    free (interface->serviceName);
+		}
+		arrayList_destroy((*component_ptr)->dm_interface);
+
 		// #TODO destroy dependencies?
 		executor_destroy(&(*component_ptr)->executor);
 		hashMap_destroy((*component_ptr)->dependencyEvents, false, false);
@@ -279,15 +287,27 @@ celix_status_t component_stopTask(dm_component_pt component, void *data
__attrib
     return status;
 }
 
-celix_status_t component_setInterface(dm_component_pt component, char *serviceName, void
*service, properties_pt properties) {
+celix_status_t component_addInterface(dm_component_pt component, char *serviceName, void
*service, properties_pt properties) {
     celix_status_t status = CELIX_SUCCESS;
 
     if (component->active) {
         return CELIX_ILLEGAL_STATE;
     } else {
-        component->serviceName = serviceName;
-        component->service = service;
-        component->properties = properties;
+	dm_interface *interface = (dm_interface *) malloc (sizeof (dm_interface));
+	char *name = strdup (serviceName);
+
+	if (interface && name) {
+            interface->serviceName = name;
+            interface->service = service;
+            interface->properties = properties;
+            interface->registration = NULL;
+	    arrayList_add(component->dm_interface, interface);
+	}
+	else {
+	   free (interface);
+	   free (name);
+	   status = CELIX_ENOMEM;
+	}
     }
 
     return status;
@@ -1063,7 +1083,7 @@ celix_status_t component_configureImplementation(dm_component_pt component,
dm_s
 celix_status_t component_destroyComponent(dm_component_pt component) {
     celix_status_t status = CELIX_SUCCESS;
 
-    component->implementation = NULL;
+//    component->implementation = NULL;
 
     return status;
 }
@@ -1071,8 +1091,14 @@ celix_status_t component_destroyComponent(dm_component_pt component)
{
 celix_status_t component_registerService(dm_component_pt component) {
     celix_status_t status = CELIX_SUCCESS;
 
-    if (component->context && component->serviceName) {
-        bundleContext_registerService(component->context, component->serviceName, component->service,
component->properties, &component->registration);
+    if (component->context) {
+	unsigned int i;
+
+	for (i = 0; i < arrayList_size(component->dm_interface); i++) {
+	    dm_interface *interface = arrayList_get(component->dm_interface, i);
+
+            bundleContext_registerService(component->context, interface->serviceName,
interface->service, interface->properties, &interface->registration);
+	}
     }
 
     return status;
@@ -1081,9 +1107,13 @@ celix_status_t component_registerService(dm_component_pt component)
{
 celix_status_t component_unregisterService(dm_component_pt component) {
     celix_status_t status = CELIX_SUCCESS;
 
-    if (component->registration && component->serviceName) {
-        serviceRegistration_unregister(component->registration);
-        component->registration = NULL;
+    unsigned int i;
+
+    for (i = 0; i < arrayList_size(component->dm_interface); i++) {
+	dm_interface *interface = arrayList_get(component->dm_interface, i);
+
+	serviceRegistration_unregister(interface->registration);
+	interface->registration = NULL;
     }
 
     return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/src/dm_service_dependency.c b/dependency_manager_2/private/src/dm_service_dependency.c
index dbe5d70..8f65ddb 100644
--- a/dependency_manager_2/private/src/dm_service_dependency.c
+++ b/dependency_manager_2/private/src/dm_service_dependency.c
@@ -52,6 +52,12 @@ celix_status_t serviceDependency_create(dm_service_dependency_pt *dependency_ptr
 		(*dependency_ptr)->add = NULL;
 		(*dependency_ptr)->change = NULL;
 		(*dependency_ptr)->remove = NULL;
+		(*dependency_ptr)->swap = NULL;
+
+		(*dependency_ptr)->add_with_ref = NULL;
+		(*dependency_ptr)->change_with_ref = NULL;
+		(*dependency_ptr)->remove_with_ref = NULL;
+		(*dependency_ptr)->swap_with_ref = NULL;
 
 		(*dependency_ptr)->autoConfigure = NULL;
 
@@ -157,6 +163,23 @@ celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt
dependenc
 	return status;
 }
 
+celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt
dependency, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt
remove, service_swap_with_ref_fpt swap) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (!dependency) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	}
+
+	if (status == CELIX_SUCCESS) {
+		dependency->add_with_ref = add;
+		dependency->change_with_ref = change;
+		dependency->remove_with_ref = remove;
+		dependency->swap_with_ref = swap;
+	}
+
+	return status;
+}
+
 celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t
*service_lock, void **field) {
 	celix_status_t status = CELIX_SUCCESS;
 
@@ -295,7 +318,10 @@ celix_status_t serviceDependency_invokeAdd(dm_service_dependency_pt dependency,
 
 	if (status == CELIX_SUCCESS) {
 		if (dependency->add) {
-			dependency->add(dependency->component->implementation, event->reference, event->service);
+			dependency->add(dependency->component->implementation, event->service);
+		}
+		if (dependency->add_with_ref) {
+			dependency->add_with_ref(dependency->component->implementation, event->reference,
event->service);
 		}
 	}
 
@@ -311,7 +337,10 @@ celix_status_t serviceDependency_invokeChange(dm_service_dependency_pt
dependenc
 
 	if (status == CELIX_SUCCESS) {
 		if (dependency->change) {
-			dependency->change(dependency->component->implementation, event->reference,
event->service);
+			dependency->change(dependency->component->implementation, event->service);
+		}
+		if (dependency->change_with_ref) {
+			dependency->change_with_ref(dependency->component->implementation, event->reference,
event->service);
 		}
 	}
 
@@ -327,7 +356,10 @@ celix_status_t serviceDependency_invokeRemove(dm_service_dependency_pt
dependenc
 
 	if (status == CELIX_SUCCESS) {
 		if (dependency->remove) {
-			dependency->remove(dependency->component->implementation, event->reference,
event->service);
+			dependency->remove(dependency->component->implementation, event->service);
+		}
+		if (dependency->remove_with_ref) {
+			dependency->remove_with_ref(dependency->component->implementation, event->reference,
event->service);
 		}
 	}
 
@@ -343,9 +375,10 @@ celix_status_t serviceDependency_invokeSwap(dm_service_dependency_pt
dependency,
 
 	if (status == CELIX_SUCCESS) {
 		if (dependency->swap) {
-			dependency
-					->swap(dependency->component->implementation, event->reference, event->service,
newEvent->reference,
-							newEvent->service);
+			dependency->swap(dependency->component->implementation, event->service, newEvent->service);
+		}
+		if (dependency->swap_with_ref) {
+			dependency->swap_with_ref(dependency->component->implementation, event->reference,
event->service, newEvent->reference, newEvent->service);
 		}
 	}
 

http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/public/include/dm_activator_base.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/public/include/dm_activator_base.h b/dependency_manager_2/public/include/dm_activator_base.h
index a439ee5..80196e2 100644
--- a/dependency_manager_2/public/include/dm_activator_base.h
+++ b/dependency_manager_2/public/include/dm_activator_base.h
@@ -35,6 +35,7 @@
 
 celix_status_t dm_create(bundle_context_pt context, void ** userData);
 celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt
manager);
+celix_status_t dm_deinit(void * userData, bundle_context_pt context, dm_dependency_manager_pt
manager);
 celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt
manager);
 
 #endif /* DM_ACTIVATOR_BASE_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/public/include/dm_component.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/public/include/dm_component.h b/dependency_manager_2/public/include/dm_component.h
index 3471fdb..f98c3bb 100644
--- a/dependency_manager_2/public/include/dm_component.h
+++ b/dependency_manager_2/public/include/dm_component.h
@@ -43,7 +43,7 @@ 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_setInterface(dm_component_pt component, char *serviceName, void
*service, properties_pt properties);
+celix_status_t component_addInterface(dm_component_pt component, char *serviceName, void
*service, properties_pt properties);
 celix_status_t component_setImplementation(dm_component_pt component, void *implementation);
 
 celix_status_t component_addServiceDependency(dm_component_pt component, ...);

http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/public/include/dm_service_dependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/public/include/dm_service_dependency.h b/dependency_manager_2/public/include/dm_service_dependency.h
index f885336..e9a5513 100644
--- a/dependency_manager_2/public/include/dm_service_dependency.h
+++ b/dependency_manager_2/public/include/dm_service_dependency.h
@@ -33,10 +33,15 @@ 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);
+typedef celix_status_t (*service_add_fpt)(void *handle, void *service);
+typedef celix_status_t (*service_change_fpt)(void *handle, void *service);
+typedef celix_status_t (*service_remove_fpt)(void *handle, void *service);
+typedef celix_status_t (*service_swap_fpt)(void *handle, void *oldService, void *newService);
+
+typedef celix_status_t (*service_add_with_ref_fpt)(void *handle, service_reference_pt reference,
void *service);
+typedef celix_status_t (*service_change_with_ref_fpt)(void *handle, service_reference_pt
reference, void *service);
+typedef celix_status_t (*service_remove_with_ref_fpt)(void *handle, service_reference_pt
reference, void *service);
+typedef celix_status_t (*service_swap_with_ref_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);
@@ -44,6 +49,7 @@ celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_pt
 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);
 celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_add_fpt
add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap);
+celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt
dependency, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt
remove, service_swap_with_ref_fpt swap);
 celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t
*service_lock, void **field);
 
 #endif /* DM_SERVICE_DEPENDENCY_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/framework/private/src/service_registry.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_registry.c b/framework/private/src/service_registry.c
index 85639b4..76c67f3 100644
--- a/framework/private/src/service_registry.c
+++ b/framework/private/src/service_registry.c
@@ -265,7 +265,7 @@ celix_status_t serviceRegistry_unregisterService(service_registry_pt registry,
b
 	//TODO not needed, the registration is destroyed, any reference to the registration is invalid
and will result in a segfault
 	serviceRegistration_invalidate(registration);
 
-	serviceRegistration_destroy(registration);
+	// serviceRegistration_destroy(registration);
 
 	celixThreadMutex_unlock(&registry->mutex);
 


Mime
View raw message