incubator-celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1163212 - in /incubator/celix/trunk: dependency_manager/ examples/whiteboard/publisherA/ examples/whiteboard/publisherB/ examples/whiteboard/tracker_depman/ framework/private/include/ framework/private/src/
Date Tue, 30 Aug 2011 13:56:41 GMT
Author: abroekhuis
Date: Tue Aug 30 13:56:41 2011
New Revision: 1163212

URL: http://svn.apache.org/viewvc?rev=1163212&view=rev
Log:
Added filter support to the dependency manager

Modified:
    incubator/celix/trunk/dependency_manager/service_dependency.c
    incubator/celix/trunk/dependency_manager/service_dependency.h
    incubator/celix/trunk/examples/whiteboard/publisherA/activator.c
    incubator/celix/trunk/examples/whiteboard/publisherB/activator.c
    incubator/celix/trunk/examples/whiteboard/tracker_depman/dependency_activator.c
    incubator/celix/trunk/framework/private/include/service_tracker.h
    incubator/celix/trunk/framework/private/src/service_tracker.c

Modified: incubator/celix/trunk/dependency_manager/service_dependency.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/service_dependency.c?rev=1163212&r1=1163211&r2=1163212&view=diff
==============================================================================
--- incubator/celix/trunk/dependency_manager/service_dependency.c (original)
+++ incubator/celix/trunk/dependency_manager/service_dependency.c Tue Aug 30 13:56:41 2011
@@ -28,6 +28,7 @@
 #include "service_dependency.h"
 #include "service_tracker.h"
 #include "bundle_context.h"
+#include "constants.h"
 
 void * serviceDependency_addingService(void * handle, SERVICE_REFERENCE reference);
 void serviceDependency_addedService(void * handle, SERVICE_REFERENCE reference, void * service);
@@ -41,6 +42,7 @@ SERVICE_DEPENDENCY serviceDependency_cre
 	dependency->autoConfigureField = NULL;
 	dependency->tracker = NULL;
 	dependency->trackedServiceName = NULL;
+	dependency->trackedServiceFilter = NULL;
 	dependency->service = NULL;
 	dependency->serviceInstance = NULL;
 	dependency->reference = NULL;
@@ -68,15 +70,18 @@ void * serviceDependency_getService(SERV
 void serviceDependency_start(SERVICE_DEPENDENCY dependency, SERVICE service) {
 	dependency->service = service;
 
-	if (dependency->trackedServiceName != NULL) {
-		SERVICE_TRACKER_CUSTOMIZER cust = (SERVICE_TRACKER_CUSTOMIZER) malloc(sizeof(*cust));
-		cust->handle = dependency;
-		cust->addingService = serviceDependency_addingService;
-		cust->addedService = serviceDependency_addedService;
-		cust->modifiedService = serviceDependency_modifiedService;
-		cust->removedService = serviceDependency_removedService;
+	SERVICE_TRACKER_CUSTOMIZER cust = (SERVICE_TRACKER_CUSTOMIZER) malloc(sizeof(*cust));
+	cust->handle = dependency;
+	cust->addingService = serviceDependency_addingService;
+	cust->addedService = serviceDependency_addedService;
+	cust->modifiedService = serviceDependency_modifiedService;
+	cust->removedService = serviceDependency_removedService;
 
-		dependency->tracker = NULL;
+	dependency->tracker = NULL;
+
+	if (dependency->trackedServiceFilter != NULL) {
+		tracker_createWithFilter(dependency->context, dependency->trackedServiceFilter, cust,
&dependency->tracker);
+	} else if (dependency->trackedServiceName != NULL) {
 		tracker_create(dependency->context, dependency->trackedServiceName, cust, &dependency->tracker);
 	} else {
 
@@ -152,7 +157,24 @@ void serviceDependency_invokeRemoved(SER
 
 SERVICE_DEPENDENCY serviceDependency_setService(SERVICE_DEPENDENCY dependency, char * serviceName,
char * filter) {
 	dependency->trackedServiceName = serviceName;
-//	dependency->filter = filter;
+
+	if (filter != NULL) {
+		if (serviceName != NULL) {
+			int len = strlen(serviceName) + strlen(OBJECTCLASS) + strlen(filter) + 7;
+			char *nfilter = malloc(sizeof(char) * len);
+			strcpy(nfilter, "(&(");
+			strcat(nfilter, OBJECTCLASS);
+			strcat(nfilter, "=");
+			strcat(nfilter, serviceName);
+			strcat(nfilter, ")");
+			strcat(nfilter, filter);
+			strcat(nfilter, ")\0");
+			dependency->trackedServiceFilter = nfilter;
+		} else {
+			dependency->trackedServiceFilter = filter;
+		}
+	}
+
 	return dependency;
 }
 

Modified: incubator/celix/trunk/dependency_manager/service_dependency.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/service_dependency.h?rev=1163212&r1=1163211&r2=1163212&view=diff
==============================================================================
--- incubator/celix/trunk/dependency_manager/service_dependency.h (original)
+++ incubator/celix/trunk/dependency_manager/service_dependency.h Tue Aug 30 13:56:41 2011
@@ -46,6 +46,7 @@ struct serviceDependency {
 	BUNDLE_CONTEXT context;
 	void * serviceInstance;
 	char * trackedServiceName;
+	char * trackedServiceFilter;
 };
 
 typedef struct serviceDependency * SERVICE_DEPENDENCY;

Modified: incubator/celix/trunk/examples/whiteboard/publisherA/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/examples/whiteboard/publisherA/activator.c?rev=1163212&r1=1163211&r2=1163212&view=diff
==============================================================================
--- incubator/celix/trunk/examples/whiteboard/publisherA/activator.c (original)
+++ incubator/celix/trunk/examples/whiteboard/publisherA/activator.c Tue Aug 30 13:56:41 2011
@@ -56,8 +56,11 @@ celix_status_t bundleActivator_start(voi
         data->ps->invoke = publisher_invoke;
         data->ps->publisher = data->pub;
 
+        PROPERTIES props = properties_create();
+        properties_set(props, "id", "A");
+
         SERVICE_REGISTRATION service_registration = NULL;
-        bundleContext_registerService(context, PUBLISHER_NAME, data->ps, NULL, &service_registration);
+        bundleContext_registerService(context, PUBLISHER_NAME, data->ps, props, &service_registration);
     } else {
         status = CELIX_START_ERROR;
     }

Modified: incubator/celix/trunk/examples/whiteboard/publisherB/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/examples/whiteboard/publisherB/activator.c?rev=1163212&r1=1163211&r2=1163212&view=diff
==============================================================================
--- incubator/celix/trunk/examples/whiteboard/publisherB/activator.c (original)
+++ incubator/celix/trunk/examples/whiteboard/publisherB/activator.c Tue Aug 30 13:56:41 2011
@@ -55,8 +55,11 @@ celix_status_t bundleActivator_start(voi
         data->ps->invoke = publisher_invoke;
         data->ps->publisher = data->pub;
 
+        PROPERTIES props = properties_create();
+		properties_set(props, "id", "B");
+
     	SERVICE_REGISTRATION service_registration = NULL;
-    	bundleContext_registerService(context, PUBLISHER_NAME, data->ps, NULL, &service_registration);
+    	bundleContext_registerService(context, PUBLISHER_NAME, data->ps, props, &service_registration);
     } else {
         status = CELIX_START_ERROR;
     }

Modified: incubator/celix/trunk/examples/whiteboard/tracker_depman/dependency_activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/examples/whiteboard/tracker_depman/dependency_activator.c?rev=1163212&r1=1163211&r2=1163212&view=diff
==============================================================================
--- incubator/celix/trunk/examples/whiteboard/tracker_depman/dependency_activator.c (original)
+++ incubator/celix/trunk/examples/whiteboard/tracker_depman/dependency_activator.c Tue Aug
30 13:56:41 2011
@@ -54,7 +54,7 @@ void dm_init(void * userData, BUNDLE_CON
 
 	SERVICE_DEPENDENCY dep = dependencyActivatorBase_createServiceDependency(manager);
 	serviceDependency_setRequired(dep, false);
-	serviceDependency_setService(dep, PUBLISHER_NAME, NULL);
+	serviceDependency_setService(dep, PUBLISHER_NAME, "(|(id=A)(id=B))");
 	serviceDependency_setCallbacks(dep, tracker_addedServ, tracker_modifiedServ, tracker_removedServ);
 	serviceComponent_addServiceDependency(service, dep);
 

Modified: incubator/celix/trunk/framework/private/include/service_tracker.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/service_tracker.h?rev=1163212&r1=1163211&r2=1163212&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/service_tracker.h (original)
+++ incubator/celix/trunk/framework/private/include/service_tracker.h Tue Aug 30 13:56:41
2011
@@ -45,7 +45,7 @@ struct tracked {
 typedef struct tracked * TRACKED;
 
 celix_status_t tracker_create(BUNDLE_CONTEXT context, char * service, SERVICE_TRACKER_CUSTOMIZER
customizer, SERVICE_TRACKER *tracker);
-SERVICE_TRACKER tracker_createWithFilter(BUNDLE_CONTEXT context, char * filter, SERVICE_TRACKER_CUSTOMIZER
customizer);
+celix_status_t tracker_createWithFilter(BUNDLE_CONTEXT context, char * filter, SERVICE_TRACKER_CUSTOMIZER
customizer, SERVICE_TRACKER *tracker);
 
 void tracker_open(SERVICE_TRACKER tracker);
 void tracker_close(SERVICE_TRACKER tracker);

Modified: incubator/celix/trunk/framework/private/src/service_tracker.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/service_tracker.c?rev=1163212&r1=1163211&r2=1163212&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/service_tracker.c (original)
+++ incubator/celix/trunk/framework/private/src/service_tracker.c Tue Aug 30 13:56:41 2011
@@ -55,7 +55,7 @@ celix_status_t tracker_create(BUNDLE_CON
 				strcat(filter, "=");
 				strcat(filter, service);
 				strcat(filter, ")\0");
-				*tracker = tracker_createWithFilter(context, filter, customizer);
+				tracker_createWithFilter(context, filter, customizer, tracker);
 			}
 		}
 	}
@@ -64,22 +64,22 @@ celix_status_t tracker_create(BUNDLE_CON
 	return status;
 }
 
-SERVICE_TRACKER tracker_createWithFilter(BUNDLE_CONTEXT context, char * filter, SERVICE_TRACKER_CUSTOMIZER
customizer) {
-	SERVICE_TRACKER tracker = (SERVICE_TRACKER) malloc(sizeof(*tracker));
+celix_status_t tracker_createWithFilter(BUNDLE_CONTEXT context, char * filter, SERVICE_TRACKER_CUSTOMIZER
customizer, SERVICE_TRACKER *tracker) {
+	*tracker = (SERVICE_TRACKER) malloc(sizeof(*tracker));
 	FW_SERVICE_TRACKER fw_tracker = (FW_SERVICE_TRACKER) malloc(sizeof(*fw_tracker));
 	if (m_trackers == NULL) {
 		m_trackers = arrayList_create();
 	}
-	tracker->context = context;
-	tracker->filter = filter;
+	(*tracker)->context = context;
+	(*tracker)->filter = filter;
 
-	fw_tracker->tracker = tracker;
+	fw_tracker->tracker = *tracker;
 	fw_tracker->tracked = arrayList_create();
 	fw_tracker->customizer = customizer;
 
 	arrayList_add(m_trackers, fw_tracker);
 
-	return tracker;
+	return CELIX_SUCCESS;
 }
 
 void tracker_open(SERVICE_TRACKER tracker) {



Mime
View raw message