You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2018/10/03 18:39:44 UTC

celix git commit: CELIX-454: Fixes a bug in the serviceTrackerTracker call wich ignored the provided service name.

Repository: celix
Updated Branches:
  refs/heads/feature/CELIX-454-pubsub-disc 3a5ff672b -> 1a26edb6a


CELIX-454: Fixes a bug in the serviceTrackerTracker call wich ignored the provided service name.


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

Branch: refs/heads/feature/CELIX-454-pubsub-disc
Commit: 1a26edb6adcf25a8fe50773cecebbf5b6282fedb
Parents: 3a5ff67
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Oct 3 20:38:52 2018 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Oct 3 20:39:33 2018 +0200

----------------------------------------------------------------------
 .../src/pubsub_topology_manager.c                       | 12 ------------
 libs/framework/src/bundle_context.c                     | 12 ++++++++++--
 libs/framework/src/bundle_context_private.h             |  1 +
 libs/framework/tst/bundle_context_services_test.cpp     |  5 +++++
 4 files changed, 16 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/1a26edb6/bundles/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c
----------------------------------------------------------------------
diff --git a/bundles/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c b/bundles/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c
index 9c7fff4..fe32ae7 100644
--- a/bundles/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c
+++ b/bundles/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c
@@ -372,12 +372,6 @@ void pubsub_topologyManager_publisherTrackerAdded(void *handle, const celix_serv
 	//2) update the usage count. if not found
 	//3) signal psaHandling thread to find a psa and setup TopicSender
 
-	//TODO FIXME
-	if (strcmp(info->serviceName, PUBSUB_PUBLISHER_SERVICE_NAME) != 0) {
-	    logHelper_log(manager->loghelper, OSGI_LOGSERVICE_WARNING, "Bug. trackServiceTracker should only trigger for %s. Now triggering on %s", PUBSUB_PUBLISHER_SERVICE_NAME, info->serviceName);
-	    return;
-	}
-
 
 	char *topicFromFilter = NULL;
 	char *scopeFromFilter = NULL;
@@ -426,12 +420,6 @@ void pubsub_topologyManager_publisherTrackerRemoved(void *handle, const celix_se
 	//NOTE local subscriber service unregister
 	//1) Find topic sender and decrease count
 
-    //TODO FIXME
-    if (strcmp(info->serviceName, PUBSUB_PUBLISHER_SERVICE_NAME) != 0) {
-        logHelper_log(manager->loghelper, OSGI_LOGSERVICE_WARNING, "Bug. trackServiceTracker should only trigger for %s. Now triggering on %s", PUBSUB_PUBLISHER_SERVICE_NAME, info->serviceName);
-        return;
-    }
-
 	char *topic = NULL;
 	char *scopeFromFilter = NULL;
 	pubsub_getPubSubInfoFromFilter(info->filter->filterStr, &topic, &scopeFromFilter);

http://git-wip-us.apache.org/repos/asf/celix/blob/1a26edb6/libs/framework/src/bundle_context.c
----------------------------------------------------------------------
diff --git a/libs/framework/src/bundle_context.c b/libs/framework/src/bundle_context.c
index a60a842..4f90314 100644
--- a/libs/framework/src/bundle_context.c
+++ b/libs/framework/src/bundle_context.c
@@ -966,9 +966,11 @@ static celix_status_t bundleContext_callServicedTrackerTrackerCallback(void *han
             trkInfo.filter = celix_filter_create(info->filter);
             trkInfo.serviceName = celix_filter_findAttribute(trkInfo.filter, OSGI_FRAMEWORK_OBJECTCLASS);
             trkInfo.serviceLanguage = celix_filter_findAttribute(trkInfo.filter, CELIX_FRAMEWORK_SERVICE_LANGUAGE);
-            if (add && entry->add != NULL) {
+            const char *filterSvcName = celix_filter_findAttribute(trkInfo.filter, OSGI_FRAMEWORK_OBJECTCLASS);
+
+            if (add && entry->add != NULL && filterSvcName != NULL && strncmp(filterSvcName, entry->serviceName, 1024*1024) == 0) {
                 entry->add(entry->callbackHandle, &trkInfo);
-            } else if (entry->remove != NULL) {
+            } else if (entry->remove != NULL && filterSvcName != NULL && strncmp(filterSvcName, entry->serviceName, 1024*1024) == 0) {
                 entry->remove(entry->callbackHandle, &trkInfo);
             }
             celix_filter_destroy(trkInfo.filter);
@@ -994,11 +996,17 @@ long celix_bundleContext_trackServiceTrackers(
 
     long trackerId = -1L;
 
+    if (serviceName == NULL) {
+        fw_log(ctx->framework->logger, OSGI_FRAMEWORK_LOG_ERROR, "Required serviceName not provided for function ", __FUNCTION__);
+        return trackerId;
+    }
+
     celix_bundle_context_service_tracker_tracker_entry_t *entry = calloc(1, sizeof(*entry));
 
     entry->callbackHandle = callbackHandle;
     entry->add = trackerAdd;
     entry->remove = trackerRemove;
+    entry->serviceName = strndup(serviceName, 1024*1024);
 
     entry->hook.handle = entry;
     entry->hook.added = bundleContext_callServicedTrackerTrackerAdd;

http://git-wip-us.apache.org/repos/asf/celix/blob/1a26edb6/libs/framework/src/bundle_context_private.h
----------------------------------------------------------------------
diff --git a/libs/framework/src/bundle_context_private.h b/libs/framework/src/bundle_context_private.h
index bdd20f8..f32a347 100644
--- a/libs/framework/src/bundle_context_private.h
+++ b/libs/framework/src/bundle_context_private.h
@@ -47,6 +47,7 @@ typedef struct celix_bundle_context_service_tracker_tracker_entry {
 	struct listener_hook_service hook;
 	service_registration_t *hookReg;
 
+	char *serviceName;
 	void *callbackHandle;
 	void (*add)(void *handle, const celix_service_tracker_info_t *info);
 	void (*remove)(void *handle, const celix_service_tracker_info_t *info);

http://git-wip-us.apache.org/repos/asf/celix/blob/1a26edb6/libs/framework/tst/bundle_context_services_test.cpp
----------------------------------------------------------------------
diff --git a/libs/framework/tst/bundle_context_services_test.cpp b/libs/framework/tst/bundle_context_services_test.cpp
index 892fab4..0e929a2 100644
--- a/libs/framework/tst/bundle_context_services_test.cpp
+++ b/libs/framework/tst/bundle_context_services_test.cpp
@@ -684,6 +684,10 @@ TEST(CelixBundleContextServicesTests, trackServiceTrackerTest) {
     CHECK_TRUE(tracker3 >= 0);
     CHECK_EQUAL(2, count);
 
+    long tracker4 = celix_bundleContext_trackServices(ctx, "no-match", NULL, NULL, NULL);
+    CHECK_TRUE(tracker4 >= 0);
+    CHECK_EQUAL(2, count);
+
     celix_bundleContext_stopTracker(ctx, tracker2);
     celix_serviceTracker_syncForContext(ctx); //service tracker shutdown on separate track -> need sync
     CHECK_EQUAL(1, count);
@@ -692,4 +696,5 @@ TEST(CelixBundleContextServicesTests, trackServiceTrackerTest) {
     CHECK_EQUAL(0, count);
 
     celix_bundleContext_stopTracker(ctx, trackerId);
+    celix_bundleContext_stopTracker(ctx, tracker4);
 }