celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [01/12] celix git commit: CELIX-446: Renames services example to best practice and create a new services example for C.
Date Mon, 14 May 2018 19:17:52 GMT
Repository: celix
Updated Branches:
  refs/heads/feature/CELIX-426-cxx-api e3339ca42 -> 8464f3d5c


http://git-wip-us.apache.org/repos/asf/celix/blob/5872268f/framework/src/bundle_context.c
----------------------------------------------------------------------
diff --git a/framework/src/bundle_context.c b/framework/src/bundle_context.c
index b75b692..5a9bbd1 100644
--- a/framework/src/bundle_context.c
+++ b/framework/src/bundle_context.c
@@ -676,7 +676,7 @@ bool celix_bundleContext_useServiceWithId(
         long serviceId,
         const char *serviceName,
         void *callbackHandle,
-        void (*use)(void *handle, void *svc, const properties_t *props, const bundle_t *owner))
{
+        void (*use)(void *handle, void *svc)) {
     celix_service_use_options_t opts;
     memset(&opts, 0, sizeof(opts));
 
@@ -694,7 +694,7 @@ bool celix_bundleContext_useService(
         bundle_context_t *ctx,
         const char* serviceName,
         void *callbackHandle,
-        void (*use)(void *handle, void *svc, const properties_t *props, const bundle_t *owner))
{
+        void (*use)(void *handle, void *svc)) {
     celix_service_use_options_t opts;
     memset(&opts, 0, sizeof(opts));
     opts.serviceName = serviceName;
@@ -708,7 +708,7 @@ void celix_bundleContext_useServices(
         bundle_context_t *ctx,
         const char* serviceName,
         void *callbackHandle,
-        void (*use)(void *handle, void *svc, const properties_t *props, const bundle_t *owner))
{
+        void (*use)(void *handle, void *svc)) {
     celix_service_use_options_t opts;
     memset(&opts, 0, sizeof(opts));
     opts.serviceName = serviceName;
@@ -717,6 +717,7 @@ void celix_bundleContext_useServices(
     celix_bundleContext_useServicesWithOptions(ctx, &opts);
 }
 
+
 bool celix_bundleContext_useServiceWithOptions(
         celix_bundle_context_t *ctx,
         const celix_service_use_options_t *opts) {
@@ -732,7 +733,16 @@ bool celix_bundleContext_useServiceWithOptions(
 
         service_tracker_t *trk = celix_serviceTracker_createWithOptions(ctx, &trkOpts);
         if (trk != NULL) {
-            called = celix_serviceTracker_useHighestRankingService(trk, opts->serviceName,
opts->callbackHandle, opts->use);
+            if (opts->use != NULL) {
+
+            }
+            if (opts->useWithProperties != NULL) {
+
+            }
+            if (opts->useWithOwner != NULL) {
+
+            }
+            called = celix_serviceTracker_useHighestRankingService(trk, opts->serviceName,
opts->callbackHandle, opts->use, opts->useWithProperties, opts->useWithOwner);
             celix_serviceTracker_destroy(trk);
         }
     }
@@ -755,7 +765,7 @@ void celix_bundleContext_useServicesWithOptions(
 
         service_tracker_t *trk = celix_serviceTracker_createWithOptions(ctx, &trkOpts);
         if (trk != NULL) {
-            celix_serviceTracker_useServices(trk, opts->serviceName, opts->callbackHandle,
opts->use);
+            celix_serviceTracker_useServices(trk, opts->serviceName, opts->callbackHandle,
opts->use, opts->useWithProperties, opts->useWithOwner);
             celix_serviceTracker_destroy(trk);
         }
     }

http://git-wip-us.apache.org/repos/asf/celix/blob/5872268f/framework/src/service_tracker.c
----------------------------------------------------------------------
diff --git a/framework/src/service_tracker.c b/framework/src/service_tracker.c
index 194d9ac..c92efa3 100644
--- a/framework/src/service_tracker.c
+++ b/framework/src/service_tracker.c
@@ -332,7 +332,7 @@ static celix_status_t serviceTracker_track(service_tracker_pt tracker,
service_r
             celixThreadRwlock_unlock(&tracker->lock);
 
             serviceTracker_invokeAddService(tracker, tracked);
-            celix_serviceTracker_useHighestRankingService(tracker, tracked->serviceName,
tracker, serviceTracker_checkAndInvokeSetService);
+            celix_serviceTracker_useHighestRankingService(tracker, tracked->serviceName,
tracker, NULL, NULL, serviceTracker_checkAndInvokeSetService);
             tracked_decreaseUse(tracked);
         }
     }
@@ -482,7 +482,7 @@ static celix_status_t serviceTracker_untrack(service_tracker_pt tracker,
service
     if (size == 0) {
         serviceTracker_checkAndInvokeSetService(tracker, NULL, NULL, NULL);
     } else {
-        celix_serviceTracker_useHighestRankingService(tracker, serviceName, tracker, serviceTracker_checkAndInvokeSetService);
+        celix_serviceTracker_useHighestRankingService(tracker, serviceName, tracker, NULL,
NULL, serviceTracker_checkAndInvokeSetService);
     }
 
     framework_logIfError(logger, status, NULL, "Cannot untrack reference");
@@ -645,7 +645,9 @@ bool celix_serviceTracker_useHighestRankingService(
         celix_service_tracker_t *tracker,
         const char *serviceName /*sanity*/,
         void *callbackHandle,
-        void (*use)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t
*owner)) {
+        void (*use)(void *handle, void *svc),
+        void (*useWithProperties)(void *handle, void *svc, const celix_properties_t *props),
+        void (*useWithOwner)(void *handle, void *svc, const celix_properties_t *props, const
celix_bundle_t *owner)) {
     bool called = false;
     celix_tracked_entry_t *tracked = NULL;
     celix_tracked_entry_t *highest = NULL;
@@ -673,7 +675,15 @@ bool celix_serviceTracker_useHighestRankingService(
 
     if (highest != NULL) {
         //got service, call, decrease use count an signal useCond after.
-        use(callbackHandle, highest->service, highest->properties, highest->serviceOwner);
+        if (use != NULL) {
+            use(callbackHandle, highest->service);
+        }
+        if (useWithProperties != NULL) {
+            useWithProperties(callbackHandle, highest->service, highest->properties);
+        }
+        if (useWithOwner != NULL) {
+            useWithOwner(callbackHandle, highest->service, highest->properties, highest->serviceOwner);
+        }
         called = true;
         tracked_decreaseUse(highest);
     }
@@ -685,7 +695,9 @@ void celix_serviceTracker_useServices(
         service_tracker_t *tracker,
         const char* serviceName /*sanity*/,
         void *callbackHandle,
-        void (*use)(void *handle, void *svc, const properties_t *props, const bundle_t *owner))
{
+        void (*use)(void *handle, void *svc),
+        void (*useWithProperties)(void *handle, void *svc, const celix_properties_t *props),
+        void (*useWithOwner)(void *handle, void *svc, const celix_properties_t *props, const
celix_bundle_t *owner)) {
     int i;
 
     //first lock tracker, get tracked entries and increase use count
@@ -704,7 +716,15 @@ void celix_serviceTracker_useServices(
     for (i = 0; i < size; i++) {
         celix_tracked_entry_t *entry = entries[i];
         //got service, call, decrease use count an signal useCond after.
-        use(callbackHandle, entry->service, entry->properties, entry->serviceOwner);
+        if (use != NULL) {
+            use(callbackHandle, entry->service);
+        }
+        if (useWithProperties != NULL) {
+            useWithProperties(callbackHandle, entry->service, entry->properties);
+        }
+        if (useWithOwner != NULL) {
+            useWithOwner(callbackHandle, entry->service, entry->properties, entry->serviceOwner);
+        }
 
         tracked_decreaseUse(entry);
     }

http://git-wip-us.apache.org/repos/asf/celix/blob/5872268f/framework/tst/bundle_context_services_test.cpp
----------------------------------------------------------------------
diff --git a/framework/tst/bundle_context_services_test.cpp b/framework/tst/bundle_context_services_test.cpp
index 7cbe057..790cbd2 100644
--- a/framework/tst/bundle_context_services_test.cpp
+++ b/framework/tst/bundle_context_services_test.cpp
@@ -98,10 +98,8 @@ TEST(CelixBundleContextServicesTests, registerMultipleAndUseServices) {
     long svcId3 = celix_bundleContext_registerService(ctx, calcName, &svc, NULL, NULL);
     CHECK(svcId3 >= 0);
 
-    auto use = [](void *handle, void *svc, const properties_t *props, const bundle_t *bnd)
{
+    auto use = [](void *handle, void *svc) {
         CHECK(svc != NULL);
-        CHECK(props != NULL);
-        CHECK(bnd != NULL);
         int *total =  static_cast<int*>(handle);
         struct calc *calc = static_cast<struct calc*>(svc);
         int tmp = calc->calc(1);
@@ -142,10 +140,8 @@ TEST(CelixBundleContextServicesTests, registerAndUseService) {
     CHECK(svcId >= 0);
 
     int result = 0;
-    bool called = celix_bundleContext_useServiceWithId(ctx, svcId, calcName, &result,
[](void *handle, void *svc, const properties_t *props, const bundle_t *bnd) {
+    bool called = celix_bundleContext_useServiceWithId(ctx, svcId, calcName, &result,
[](void *handle, void *svc) {
         CHECK(svc != NULL);
-        CHECK(props != NULL);
-        CHECK(bnd != NULL);
         int *result =  static_cast<int*>(handle);
         struct calc *calc = static_cast<struct calc*>(svc);
         int tmp = calc->calc(2);
@@ -156,7 +152,7 @@ TEST(CelixBundleContextServicesTests, registerAndUseService) {
 
     result = 0;
     long nonExistingSvcId = 101;
-    called = celix_bundleContext_useServiceWithId(ctx, nonExistingSvcId, calcName, &result,
[](void *handle, void *svc, const properties_t *, const bundle_t *) {
+    called = celix_bundleContext_useServiceWithId(ctx, nonExistingSvcId, calcName, &result,
[](void *handle, void *svc) {
         int *result =  static_cast<int*>(handle);
         struct calc *calc = static_cast<struct calc*>(svc);
         int tmp = calc->calc(2);
@@ -192,10 +188,8 @@ TEST(CelixBundleContextServicesTests, registerAndUseWithForcedRaceCondition)
{
     };
     struct sync callInfo{};
 
-    auto use = [](void *handle, void *svc, const properties_t *props, const bundle_t *bnd)
{
+    auto use = [](void *handle, void *svc) {
         CHECK(svc != NULL);
-        CHECK(props != NULL);
-        CHECK(bnd != NULL);
 
         struct sync *h = static_cast<struct sync*>(handle);
 


Mime
View raw message