This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/674-improve-properties in repository https://gitbox.apache.org/repos/asf/celix.git
commit e5b99c1ed69b327a352b9e8c1abeffcd8eb2f87a Author: Pepijn Noltes <[email protected]> AuthorDate: Sun Jan 21 19:18:25 2024 +0100 Fix RSA import due to changed properties behaviour --- .../src/import_registration_dfi.c | 23 ++++++--- .../src/RsaShmExportRegistrationUnitTestSuite.cc | 22 +++++++-- .../rsa_rpc_json/src/rsa_json_rpc_proxy_impl.c | 57 +++++++++++++--------- .../rsa_utils/src/celix_rsa_utils.c | 13 ++--- 4 files changed, 72 insertions(+), 43 deletions(-) diff --git a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c index 5cc0327e..95e93743 100644 --- a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c +++ b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c @@ -17,16 +17,18 @@ * under the License. */ -#include <stdlib.h> -#include <json_rpc.h> -#include <assert.h> -#include "version.h" +#include "import_registration_dfi.h" +#include "celix_rsa_utils.h" +#include "celix_constants.h" #include "dyn_interface.h" #include "import_registration.h" -#include "import_registration_dfi.h" -#include "remote_service_admin_dfi.h" #include "remote_interceptors_handler.h" +#include "remote_service_admin_dfi.h" #include "remote_service_admin_dfi_constants.h" +#include "version.h" +#include <assert.h> +#include <json_rpc.h> +#include <stdlib.h> struct import_registration { celix_bundle_context_t *context; @@ -151,8 +153,13 @@ void importRegistration_destroy(import_registration_t *import) { } celix_status_t importRegistration_start(import_registration_t *import) { - celix_properties_t *props = celix_properties_copy(import->endpoint->properties); - import->factorySvcId = celix_bundleContext_registerServiceFactoryAsync(import->context, &import->factory, import->classObject, props); + celix_properties_t* svcProperties = NULL; + celix_status_t status = celix_rsaUtils_createServicePropertiesFromEndpointProperties(import->endpoint->properties, &svcProperties); + if (status != CELIX_SUCCESS) { + return status; + } + + import->factorySvcId = celix_bundleContext_registerServiceFactoryAsync(import->context, &import->factory, import->classObject, svcProperties); return import->factorySvcId >= 0 ? CELIX_SUCCESS : CELIX_ILLEGAL_STATE; } diff --git a/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmExportRegistrationUnitTestSuite.cc b/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmExportRegistrationUnitTestSuite.cc index a8569190..07fce411 100644 --- a/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmExportRegistrationUnitTestSuite.cc +++ b/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmExportRegistrationUnitTestSuite.cc @@ -90,7 +90,11 @@ public: }; celix_properties_t *properties = celix_properties_create(); celix_properties_set(properties, OSGI_RSA_SERVICE_EXPORTED_INTERFACES, RSA_SHM_CALCULATOR_SERVICE); - celix_properties_set(properties, CELIX_FRAMEWORK_SERVICE_VERSION, RSA_SHM_CALCULATOR_SERVICE_VERSION); + auto* version = celix_version_createVersionFromString(RSA_SHM_CALCULATOR_SERVICE_VERSION); + EXPECT_NE(nullptr, version); + if (version) { + celix_properties_assignVersion(properties, CELIX_FRAMEWORK_SERVICE_VERSION, version); + } celix_properties_set(properties, OSGI_RSA_SERVICE_EXPORTED_CONFIGS, RSA_SHM_CALCULATOR_CONFIGURATION_TYPE"," RSA_RPC_TYPE_PREFIX"mock"); calcSvcId = celix_bundleContext_registerServiceAsync(ctx.get(), &calcService, RSA_SHM_CALCULATOR_SERVICE, properties); EXPECT_GE(calcSvcId, 0); @@ -104,7 +108,11 @@ public: celix_properties_t *rpcFacProps = celix_properties_create(); celix_properties_set(rpcFacProps, RSA_RPC_TYPE_KEY, RSA_RPC_TYPE_PREFIX"mock"); - celix_properties_set(rpcFacProps, CELIX_FRAMEWORK_SERVICE_VERSION, RSA_RPC_FACTORY_VERSION); + version = celix_version_createVersionFromString(RSA_RPC_FACTORY_VERSION); + EXPECT_NE(nullptr, version); + if (version) { + celix_properties_assignVersion(rpcFacProps, CELIX_FRAMEWORK_SERVICE_VERSION, version); + } rpcFactorySvcId = celix_bundleContext_registerServiceAsync(ctx.get(), &rpcFactory, RSA_RPC_FACTORY_NAME, rpcFacProps); EXPECT_GE(rpcFactorySvcId, 1); @@ -127,7 +135,11 @@ public: endpoint_description_t *CreateEndpointDescription() { celix_properties_t *properties = celix_properties_create(); celix_properties_set(properties, CELIX_FRAMEWORK_SERVICE_NAME, RSA_SHM_CALCULATOR_SERVICE); - celix_properties_set(properties, CELIX_FRAMEWORK_SERVICE_VERSION, RSA_SHM_CALCULATOR_SERVICE_VERSION); + celix_version_t* version = celix_version_createVersionFromString(RSA_SHM_CALCULATOR_SERVICE_VERSION); + EXPECT_NE(nullptr, version); + if (version) { + celix_properties_assignVersion(properties, CELIX_FRAMEWORK_SERVICE_VERSION, version); + } celix_properties_set(properties, OSGI_RSA_SERVICE_IMPORTED_CONFIGS, RSA_SHM_CALCULATOR_CONFIGURATION_TYPE"," RSA_RPC_TYPE_PREFIX"mock"); celix_properties_set(properties, OSGI_RSA_ENDPOINT_ID, "7f7efba5-500f-4ee9-b733-68de012091da"); celix_properties_setLong(properties, OSGI_RSA_ENDPOINT_SERVICE_ID, calcSvcId); @@ -330,7 +342,9 @@ TEST_F(RsaShmExportRegUnitTestSuite, RegisterMoreThanOneRpcFactory) { //register another rpc factory celix_properties_t *props = celix_properties_create(); celix_properties_set(props, RSA_RPC_TYPE_KEY, RSA_RPC_TYPE_PREFIX"mock"); - celix_properties_set(props, CELIX_FRAMEWORK_SERVICE_VERSION, RSA_RPC_FACTORY_VERSION); + auto* version = celix_version_createVersionFromString(RSA_RPC_FACTORY_VERSION); + ASSERT_NE(nullptr, version); + celix_properties_assignVersion(props, CELIX_FRAMEWORK_SERVICE_VERSION, version); auto svcId = celix_bundleContext_registerServiceAsync(ctx.get(), (void*)"dumb-rpc-service", RSA_RPC_FACTORY_NAME, props); EXPECT_GE(svcId, 1); celix_bundleContext_waitForEvents(ctx.get()); diff --git a/bundles/remote_services/rsa_rpc_json/src/rsa_json_rpc_proxy_impl.c b/bundles/remote_services/rsa_rpc_json/src/rsa_json_rpc_proxy_impl.c index 83d505bc..4fac982e 100644 --- a/bundles/remote_services/rsa_rpc_json/src/rsa_json_rpc_proxy_impl.c +++ b/bundles/remote_services/rsa_rpc_json/src/rsa_json_rpc_proxy_impl.c @@ -18,19 +18,22 @@ */ #include "rsa_json_rpc_proxy_impl.h" -#include "rsa_request_sender_tracker.h" -#include "json_rpc.h" -#include "endpoint_description.h" -#include "celix_stdlib_cleanup.h" -#include "celix_log_helper.h" -#include "dfi_utils.h" -#include "celix_version.h" -#include "celix_constants.h" + +#include <assert.h> +#include <stdbool.h> +#include <sys/queue.h> + #include "celix_build_assert.h" +#include "celix_constants.h" +#include "celix_log_helper.h" #include "celix_long_hash_map.h" -#include <sys/queue.h> -#include <stdbool.h> -#include <assert.h> +#include "celix_rsa_utils.h" +#include "celix_stdlib_cleanup.h" +#include "celix_version.h" +#include "dfi_utils.h" +#include "endpoint_description.h" +#include "json_rpc.h" +#include "rsa_request_sender_tracker.h" struct rsa_json_rpc_proxy_factory { celix_bundle_context_t* ctx; @@ -69,10 +72,15 @@ static celix_status_t rsaJsonRpcProxy_create(rsa_json_rpc_proxy_factory_t *proxy static void rsaJsonRpcProxy_destroy(rsa_json_rpc_proxy_t *proxy); static void rsaJsonRpcProxy_unregisterFacSvcDone(void *data); -celix_status_t rsaJsonRpcProxy_factoryCreate(celix_bundle_context_t* ctx, celix_log_helper_t *logHelper, - FILE *logFile, remote_interceptors_handler_t *interceptorsHandler, - const endpoint_description_t *endpointDesc, rsa_request_sender_tracker_t *reqSenderTracker, - long requestSenderSvcId, unsigned int serialProtoId, rsa_json_rpc_proxy_factory_t **proxyFactoryOut) { +celix_status_t rsaJsonRpcProxy_factoryCreate(celix_bundle_context_t* ctx, + celix_log_helper_t* logHelper, + FILE* logFile, + remote_interceptors_handler_t* interceptorsHandler, + const endpoint_description_t* endpointDesc, + rsa_request_sender_tracker_t* reqSenderTracker, + long requestSenderSvcId, + unsigned int serialProtoId, + rsa_json_rpc_proxy_factory_t** proxyFactoryOut) { assert(ctx != NULL); assert(logHelper != NULL); assert(interceptorsHandler != NULL); @@ -93,15 +101,15 @@ celix_status_t rsaJsonRpcProxy_factoryCreate(celix_bundle_context_t* ctx, celix_ proxyFactory->reqSenderSvcId = requestSenderSvcId; proxyFactory->serialProtoId = serialProtoId; - CELIX_BUILD_ASSERT(sizeof(long) == sizeof(void*));//The hash_map uses the pointer as key, so this should be true + CELIX_BUILD_ASSERT(sizeof(long) == sizeof(void*)); // The hash_map uses the pointer as key, so this should be true celix_autoptr(celix_long_hash_map_t) proxies = proxyFactory->proxies = celix_longHashMap_create(); if (proxyFactory->proxies == NULL) { celix_logHelper_error(logHelper, "Proxy: Error creating proxy map."); return CELIX_ENOMEM; } - celix_autoptr(endpoint_description_t) endpointDescCopy = - proxyFactory->endpointDesc = endpointDescription_clone(endpointDesc); + celix_autoptr(endpoint_description_t) endpointDescCopy = proxyFactory->endpointDesc = + endpointDescription_clone(endpointDesc); if (proxyFactory->endpointDesc == NULL) { celix_logHelper_error(logHelper, "Proxy: Failed to clone endpoint description."); return CELIX_ENOMEM; @@ -110,11 +118,16 @@ celix_status_t rsaJsonRpcProxy_factoryCreate(celix_bundle_context_t* ctx, celix_ proxyFactory->factory.handle = proxyFactory; proxyFactory->factory.getService = rsaJsonRpcProxy_getService; proxyFactory->factory.ungetService = rsaJsonRpcProxy_ungetService; - celix_properties_t *props = celix_properties_copy(endpointDesc->properties); - assert(props != NULL); + celix_properties_t* svcProperties = NULL; + celix_status_t status = + celix_rsaUtils_createServicePropertiesFromEndpointProperties(endpointDesc->properties, &svcProperties); + if (status != CELIX_SUCCESS) { + return status; + } + assert(svcProperties != NULL); proxyFactory->factorySvcId = celix_bundleContext_registerServiceFactoryAsync( - ctx, &proxyFactory->factory, endpointDesc->serviceName, props); - if (proxyFactory->factorySvcId < 0) { + ctx, &proxyFactory->factory, endpointDesc->serviceName, svcProperties); + if (proxyFactory->factorySvcId < 0) { celix_logHelper_error(logHelper, "Proxy: Error Registering proxy service."); return CELIX_SERVICE_EXCEPTION; } diff --git a/bundles/remote_services/rsa_utils/src/celix_rsa_utils.c b/bundles/remote_services/rsa_utils/src/celix_rsa_utils.c index d20e69b9..a2cac61d 100644 --- a/bundles/remote_services/rsa_utils/src/celix_rsa_utils.c +++ b/bundles/remote_services/rsa_utils/src/celix_rsa_utils.c @@ -30,21 +30,16 @@ celix_rsaUtils_createServicePropertiesFromEndpointProperties(const celix_propert } celix_status_t status = CELIX_SUCCESS; - long bundleId = celix_properties_getAsLong(props, CELIX_FRAMEWORK_BUNDLE_ID, -1L); - if (bundleId >= 0) { - status = celix_properties_setLong(props, CELIX_FRAMEWORK_BUNDLE_ID, bundleId); - } - const celix_properties_entry_t* entry = celix_properties_getEntry(props, CELIX_FRAMEWORK_SERVICE_RANKING); - if (status == CELIX_SUCCESS && entry && entry->valueType == CELIX_PROPERTIES_VALUE_TYPE_STRING) { + if (entry && entry->valueType == CELIX_PROPERTIES_VALUE_TYPE_STRING) { long ranking = celix_properties_getAsLong(props, CELIX_FRAMEWORK_SERVICE_RANKING, 0L); status = celix_properties_setLong(props, CELIX_FRAMEWORK_SERVICE_RANKING, ranking); } - const char* versionStr = celix_properties_get(props, CELIX_FRAMEWORK_SERVICE_VERSION, NULL); - if (status == CELIX_SUCCESS && versionStr) { + entry = celix_properties_getEntry(props, CELIX_FRAMEWORK_SERVICE_VERSION); + if (status == CELIX_SUCCESS && entry && entry->valueType == CELIX_PROPERTIES_VALUE_TYPE_STRING) { celix_autoptr(celix_version_t) version = NULL; - status = celix_version_parse(versionStr, &version); + status = celix_version_parse(entry->value, &version); if (status == CELIX_SUCCESS) { status = celix_properties_assignVersion(props, CELIX_FRAMEWORK_SERVICE_VERSION, celix_steal_ptr(version)); }
