incubator-celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1163183 - in /incubator/celix/trunk: dependency_manager/service_dependency.c examples/whiteboard/tracker/activator.c framework/private/include/headers.h framework/private/include/service_tracker.h framework/private/src/service_tracker.c
Date Tue, 30 Aug 2011 12:18:54 GMT
Author: abroekhuis
Date: Tue Aug 30 12:18:53 2011
New Revision: 1163183

URL: http://svn.apache.org/viewvc?rev=1163183&view=rev
Log:
Added support for filters to the service tracker

Modified:
    incubator/celix/trunk/dependency_manager/service_dependency.c
    incubator/celix/trunk/examples/whiteboard/tracker/activator.c
    incubator/celix/trunk/framework/private/include/headers.h
    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=1163183&r1=1163182&r2=1163183&view=diff
==============================================================================
--- incubator/celix/trunk/dependency_manager/service_dependency.c (original)
+++ incubator/celix/trunk/dependency_manager/service_dependency.c Tue Aug 30 12:18:53 2011
@@ -76,7 +76,8 @@ void serviceDependency_start(SERVICE_DEP
 		cust->modifiedService = serviceDependency_modifiedService;
 		cust->removedService = serviceDependency_removedService;
 
-		dependency->tracker = tracker_create(dependency->context, dependency->trackedServiceName,
cust);
+		dependency->tracker = NULL;
+		tracker_create(dependency->context, dependency->trackedServiceName, cust, &dependency->tracker);
 	} else {
 
 	}

Modified: incubator/celix/trunk/examples/whiteboard/tracker/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/examples/whiteboard/tracker/activator.c?rev=1163183&r1=1163182&r2=1163183&view=diff
==============================================================================
--- incubator/celix/trunk/examples/whiteboard/tracker/activator.c (original)
+++ incubator/celix/trunk/examples/whiteboard/tracker/activator.c Tue Aug 30 12:18:53 2011
@@ -107,7 +107,8 @@ celix_status_t bundleActivator_start(voi
         cust->addingService = addingServ;
         cust->modifiedService = modifiedServ;
         cust->removedService = removedServ;
-        SERVICE_TRACKER tracker = tracker_create(context, (char *) PUBLISHER_NAME, cust);
+        SERVICE_TRACKER tracker = NULL;
+        tracker_create(context, (char *) PUBLISHER_NAME, cust, &tracker);
         data->tracker = tracker;
 
         tracker_open(tracker);

Modified: incubator/celix/trunk/framework/private/include/headers.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/headers.h?rev=1163183&r1=1163182&r2=1163183&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/headers.h (original)
+++ incubator/celix/trunk/framework/private/include/headers.h Tue Aug 30 12:18:53 2011
@@ -188,7 +188,7 @@ typedef struct serviceTrackerCustomizer 
 
 struct serviceTracker {
 	BUNDLE_CONTEXT context;
-	char * className;
+	char * filter;
 };
 
 typedef struct serviceTracker * SERVICE_TRACKER;

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=1163183&r1=1163182&r2=1163183&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/service_tracker.h (original)
+++ incubator/celix/trunk/framework/private/include/service_tracker.h Tue Aug 30 12:18:53
2011
@@ -44,7 +44,8 @@ struct tracked {
 
 typedef struct tracked * TRACKED;
 
-SERVICE_TRACKER tracker_create(BUNDLE_CONTEXT context, char * className, SERVICE_TRACKER_CUSTOMIZER
customizer);
+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);
 
 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=1163183&r1=1163182&r2=1163183&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/service_tracker.c (original)
+++ incubator/celix/trunk/framework/private/src/service_tracker.c Tue Aug 30 12:18:53 2011
@@ -35,14 +35,43 @@ void * addingService(FW_SERVICE_TRACKER,
 void track(FW_SERVICE_TRACKER, SERVICE_REFERENCE, SERVICE_EVENT);
 void untrack(FW_SERVICE_TRACKER, SERVICE_REFERENCE, SERVICE_EVENT);
 
-SERVICE_TRACKER tracker_create(BUNDLE_CONTEXT context, char * className, SERVICE_TRACKER_CUSTOMIZER
customizer) {
+celix_status_t tracker_create(BUNDLE_CONTEXT context, char * service, SERVICE_TRACKER_CUSTOMIZER
customizer, SERVICE_TRACKER *tracker) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (service == NULL) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	} else {
+		apr_pool_t *pool = NULL;
+		//status = bundleContext_getMemoryPool(context, &pool);
+		if (status == CELIX_SUCCESS) {
+			int len = strlen(service) + strlen(OBJECTCLASS) + 4;
+			//char *filter = apr_palloc(pool, sizeof(char) * len);
+			char *filter = malloc(sizeof(char) * len);
+			if (filter == NULL) {
+				status = CELIX_ENOMEM;
+			} else {
+				strcpy(filter, "(");
+				strcat(filter, OBJECTCLASS);
+				strcat(filter, "=");
+				strcat(filter, service);
+				strcat(filter, ")\0");
+				*tracker = tracker_createWithFilter(context, filter, customizer);
+			}
+		}
+	}
+
+
+	return status;
+}
+
+SERVICE_TRACKER tracker_createWithFilter(BUNDLE_CONTEXT context, char * filter, SERVICE_TRACKER_CUSTOMIZER
customizer) {
 	SERVICE_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->className = className;
+	tracker->filter = filter;
 
 	fw_tracker->tracker = tracker;
 	fw_tracker->tracked = arrayList_create();
@@ -58,21 +87,12 @@ void tracker_open(SERVICE_TRACKER tracke
 	FW_SERVICE_TRACKER fwTracker = findFwServiceTracker(tracker);
 	ARRAY_LIST initial = NULL;
 
-	bundleContext_getServiceReferences(tracker->context, tracker->className, NULL, &initial);
+	bundleContext_getServiceReferences(tracker->context, NULL, tracker->filter, &initial);
 	SERVICE_REFERENCE initial_reference;
 	unsigned int i;
-	int len = strlen(tracker->className);
-	len += strlen(OBJECTCLASS);
-	len += 4;
-	char filter[len];
-	strcpy(filter, "(");
-	strcat(filter, OBJECTCLASS);
-	strcat(filter, "=");
-	strcat(filter, tracker->className);
-	strcat(filter, ")\0");
 
 	listener->serviceChanged = (void *) tracker_serviceChanged;
-	bundleContext_addServiceListener(tracker->context, listener, filter);
+	bundleContext_addServiceListener(tracker->context, listener, tracker->filter);
 	fwTracker->listener = listener;
 
 	for (i = 0; i < arrayList_size(initial); i++) {



Mime
View raw message