This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/87-refactor-use-services
in repository https://gitbox.apache.org/repos/asf/celix.git
The following commit(s) were added to
refs/heads/feature/87-refactor-use-services by this push:
new f0e1b228 gh-87: Remove use direct and sod option from useService*
functions
f0e1b228 is described below
commit f0e1b228ffcca1a024a3571adc5e7b810f03153b
Author: Pepijn Noltes <[email protected]>
AuthorDate: Sat Mar 9 15:49:38 2024 +0100
gh-87: Remove use direct and sod option from useService* functions
---
.../rsa_shm/gtest/src/RsaShmImplUnitTestSuite.cc | 2 -
.../src/CelixBundleContextServicesTestSuite.cc | 53 ++++------------------
libs/framework/include/celix_bundle_context.h | 15 +-----
3 files changed, 10 insertions(+), 60 deletions(-)
diff --git
a/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmImplUnitTestSuite.cc
b/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmImplUnitTestSuite.cc
index e602ee9e..833b55a0 100644
---
a/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmImplUnitTestSuite.cc
+++
b/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmImplUnitTestSuite.cc
@@ -813,7 +813,6 @@ TEST_F(RsaShmRpcTestSuite, CallRemoteService) {
EXPECT_EQ(CELIX_SUCCESS, calc->add(calc->handle, 1, 2, &result));
EXPECT_EQ(3.0, result);
};
- opts.flags = CELIX_SERVICE_USE_DIRECT | CELIX_SERVICE_USE_SOD;
auto found = celix_bundleContext_useServiceWithOptions(clientCtx.get(),
&opts);
EXPECT_TRUE(found);
@@ -835,7 +834,6 @@ TEST_F(RsaShmRpcTestSuite, CallRemoteService) {
double result;
EXPECT_NE(CELIX_SUCCESS, calc->add(calc->handle, 1, 2, &result));
};
- opts.flags = CELIX_SERVICE_USE_DIRECT | CELIX_SERVICE_USE_SOD;
found = celix_bundleContext_useServiceWithOptions(clientCtx.get(), &opts);
EXPECT_TRUE(found);
diff --git a/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc
b/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc
index a164520f..0a0c6af9 100644
--- a/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc
+++ b/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc
@@ -64,7 +64,7 @@ public:
CelixBundleContextServicesTestSuite&
operator=(CelixBundleContextServicesTestSuite&&) = delete;
CelixBundleContextServicesTestSuite& operator=(const
CelixBundleContextServicesTestSuite&) = delete;
- void registerAndUseServiceWithCorrectVersion(bool direct) const {
+ void registerAndUseServiceWithCorrectVersion() const {
struct calc {
int (*calc)(int);
};
@@ -78,9 +78,6 @@ public:
celix_service_use_options_t use_opts{};
use_opts.filter.serviceName = "calc";
use_opts.filter.versionRange = "[1,2)";
- if(direct) {
- use_opts.flags = CELIX_SERVICE_USE_DIRECT;
- }
celix_service_registration_options_t reg_opts{};
reg_opts.serviceName = calcName;
@@ -105,7 +102,7 @@ public:
celix_bundleContext_unregisterService(ctx, svcId);
}
- void registerAndUseServiceWithIncorrectVersion(bool direct) const {
+ void registerAndUseServiceWithIncorrectVersion() const {
struct calc {
int (*calc)(int);
};
@@ -119,9 +116,6 @@ public:
celix_service_use_options_t use_opts{};
use_opts.filter.serviceName = "calc";
use_opts.filter.versionRange = "[2,3)";
- if(direct) {
- use_opts.flags = CELIX_SERVICE_USE_DIRECT;
- }
celix_service_registration_options_t reg_opts{};
reg_opts.serviceName = calcName;
@@ -145,7 +139,7 @@ public:
celix_bundleContext_unregisterService(ctx, svcId);
}
- void registerAndUseServiceWithTimeout(bool direct) const {
+ void registerAndUseServiceWithTimeout() const {
const int NR_ITERATIONS = 5; //NOTE this test is sensitive for
triggering race condition in the celix framework, therefore is used a few times.
for (int i = 0; i < NR_ITERATIONS; ++i) {
printf("Iter %i\n", i);
@@ -161,9 +155,6 @@ public:
celix_service_use_options_t opts{};
opts.filter.serviceName = "calc";
- if(direct) {
- opts.flags = CELIX_SERVICE_USE_DIRECT;
- }
bool called = celix_bundleContext_useServiceWithOptions(ctx,
&opts);
EXPECT_FALSE(called); //service not avail.
@@ -197,7 +188,7 @@ public:
}
}
- void registerAsyncAndUseServiceWithTimeout(bool direct) const {
+ void registerAsyncAndUseServiceWithTimeout() const {
const int NR_ITERATIONS = 5; //NOTE this test is sensitive for
triggering race condition in the celix framework, therefore is used a few times.
for (int i = 0; i < NR_ITERATIONS; ++i) {
printf("Iter %i\n", i);
@@ -213,9 +204,6 @@ public:
celix_service_use_options_t opts{};
opts.filter.serviceName = "calc";
- if(direct) {
- opts.flags = CELIX_SERVICE_USE_DIRECT;
- }
bool called = celix_bundleContext_useServiceWithOptions(ctx,
&opts);
EXPECT_FALSE(called); //service not avail.
@@ -355,7 +343,7 @@ TEST_F(CelixBundleContextServicesTestSuite,
UseServicesWithoutNameTest) {
celix_bundleContext_unregisterService(ctx, svcId1);
}
-TEST_F(CelixBundleContextServicesTestSuite,
TegisterMultipleAndUseServicesTest) {
+TEST_F(CelixBundleContextServicesTestSuite,
RegisterMultipleAndUseServicesTest) {
struct calc {
int (*calc)(int);
};
@@ -393,13 +381,11 @@ TEST_F(CelixBundleContextServicesTestSuite,
TegisterMultipleAndUseServicesTest)
use_opts.filter.versionRange = nullptr;
use_opts.callbackHandle = &total;
use_opts.use = use;
- use_opts.flags = 0;
total = 0;
count = celix_bundleContext_useServicesWithOptions(ctx, &use_opts);
EXPECT_EQ(3, count);
EXPECT_EQ(42 * 3, total);
- use_opts.flags = CELIX_SERVICE_USE_DIRECT;
total = 0;
count = celix_bundleContext_useServicesWithOptions(ctx, &use_opts);
EXPECT_EQ(3, count);
@@ -411,13 +397,11 @@ TEST_F(CelixBundleContextServicesTestSuite,
TegisterMultipleAndUseServicesTest)
EXPECT_EQ(2, count);
EXPECT_EQ(42 * 2, total);
- use_opts.flags = 0;
total = 0;
count = celix_bundleContext_useServicesWithOptions(ctx, &use_opts);
EXPECT_EQ(2, count);
EXPECT_EQ(42 * 2, total);
- use_opts.flags = CELIX_SERVICE_USE_DIRECT;
total = 0;
count = celix_bundleContext_useServicesWithOptions(ctx, &use_opts);
EXPECT_EQ(2, count);
@@ -470,7 +454,6 @@ TEST_F(CelixBundleContextServicesTestSuite,
UseServiceInUseCallbackTest) {
opts.filter.serviceName = calcName;
opts.callbackHandle = ctx;
opts.use = use;
- opts.flags = 0;
bool called = celix_bundleContext_useServiceWithOptions(ctx, &opts);
EXPECT_TRUE(called);
@@ -519,35 +502,19 @@ TEST_F(CelixBundleContextServicesTestSuite,
RegisterAndUseServiceTest) {
};
TEST_F(CelixBundleContextServicesTestSuite,
RegisterAndUseServiceWithTimeoutTest) {
- registerAndUseServiceWithTimeout(false);
-}
-
-TEST_F(CelixBundleContextServicesTestSuite,
RegisterAndUseServiceDirectWithTimeoutTest) {
- registerAndUseServiceWithTimeout(true);
+ registerAndUseServiceWithTimeout();
}
TEST_F(CelixBundleContextServicesTestSuite,
RegisterAsyncAndUseServiceWithTimeoutTest) {
- registerAsyncAndUseServiceWithTimeout(false);
-}
-
-TEST_F(CelixBundleContextServicesTestSuite,
RegisterAsyncAndUseServiceDirectWithTimeoutTest) {
- registerAsyncAndUseServiceWithTimeout(true);
+ registerAsyncAndUseServiceWithTimeout();
}
TEST_F(CelixBundleContextServicesTestSuite,
RegisterAndUseServiceWithCorrectVersionTest) {
- registerAndUseServiceWithCorrectVersion(false);
-}
-
-TEST_F(CelixBundleContextServicesTestSuite,
RegisterAndUseServiceDirectWithCorrectVersionTest) {
- registerAndUseServiceWithCorrectVersion(true);
+ registerAndUseServiceWithCorrectVersion();
}
TEST_F(CelixBundleContextServicesTestSuite,
RegisterAndUseServiceWithIncorrectVersionTest) {
- registerAndUseServiceWithIncorrectVersion(false);
-}
-
-TEST_F(CelixBundleContextServicesTestSuite,
RegisterAndUseServiceDirectWithIncorrectVersionTest) {
- registerAndUseServiceWithIncorrectVersion(true);
+ registerAndUseServiceWithIncorrectVersion();
}
TEST_F(CelixBundleContextServicesTestSuite,
RegisterAndUseWithForcedRaceConditionTest) {
@@ -1462,7 +1429,6 @@ TEST_F(CelixBundleContextServicesTestSuite,
UseServiceOnDemandDirectlyWithAsyncR
}, nullptr);
celix_service_use_options_t opts{};
opts.filter.serviceName = "test";
- opts.flags = CELIX_SERVICE_USE_DIRECT | CELIX_SERVICE_USE_SOD;
called = celix_bundleContext_useServiceWithOptions(ctx, &opts);
EXPECT_TRUE(called); //service created on demand.
@@ -1500,7 +1466,6 @@ TEST_F(CelixBundleContextServicesTestSuite,
UseServicesOnDemandDirectlyWithAsync
celix_service_use_options_t opts{};
opts.filter.serviceName = "test";
- opts.flags = CELIX_SERVICE_USE_DIRECT | CELIX_SERVICE_USE_SOD;
size_t count = celix_bundleContext_useServicesWithOptions(ctx, &opts);
EXPECT_EQ(2, count);
diff --git a/libs/framework/include/celix_bundle_context.h
b/libs/framework/include/celix_bundle_context.h
index 56ec0e5c..e93d88aa 100644
--- a/libs/framework/include/celix_bundle_context.h
+++ b/libs/framework/include/celix_bundle_context.h
@@ -519,18 +519,6 @@ typedef struct celix_service_use_options {
*/
void (*useWithOwner)(void* handle, void* svc, const celix_properties_t*
props, const celix_bundle_t* svcOwner)
CELIX_OPTS_INIT;
- /**
- * @brief Call the provided callbacks from the caller thread directly if
set, otherwise the callbacks will be called
- * from the Celix event loop (most likely indirectly). Note that using
blocking service in the Celix event loop is
- * generally a bad idea, which should be avoided if possible.
- */
-#define CELIX_SERVICE_USE_DIRECT (1)
- /**
- * @brief Whether "service on demand" pattern is supported when
CELIX_SERVICE_USE_DIRECT is set.
- * Note that it has no effect in indirect mode, in which case "service on
demand" is supported.
- */
-#define CELIX_SERVICE_USE_SOD (2)
- int flags CELIX_OPTS_INIT;
} celix_service_use_options_t;
#ifndef __cplusplus
@@ -544,8 +532,7 @@ typedef struct celix_service_use_options {
.callbackHandle = NULL, \
.use = NULL, \
.useWithProperties = NULL, \
- .useWithOwner = NULL, \
- .flags=0}
+ .useWithOwner = NULL}
#endif
/**