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 2021/01/11 15:18:02 UTC
[celix] 03/08: Fixes issue with dm info test
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/refactor_c_dep_man_service_trackers
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 58ccb2559be1d5967a7c6fc19a8d43ca13102970
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Mon Jan 4 18:41:50 2021 +0100
Fixes issue with dm info test
---
.../gtest/src/DependencyManagerTestSuite.cc | 8 ++-
libs/framework/gtest/src/single_framework_test.cpp | 67 ++++++----------------
libs/framework/include/celix_dependency_manager.h | 5 +-
libs/framework/src/dm_component_impl.c | 39 ++++---------
libs/framework/src/dm_dependency_manager_impl.c | 22 ++++---
libs/framework/src/dm_service_dependency.c | 3 +-
6 files changed, 47 insertions(+), 97 deletions(-)
diff --git a/libs/framework/gtest/src/DependencyManagerTestSuite.cc b/libs/framework/gtest/src/DependencyManagerTestSuite.cc
index 7cfab64..7b0bf12 100644
--- a/libs/framework/gtest/src/DependencyManagerTestSuite.cc
+++ b/libs/framework/gtest/src/DependencyManagerTestSuite.cc
@@ -97,11 +97,15 @@ TEST_F(DependencyManagerTestSuite, DmGetInfo) {
celix_dependencyManager_add(mng, cmp);
auto* infos = celix_dependencyManager_createInfos(mng);
- EXPECT_EQ(1, celix_arrayList_size(infos));
- auto* info = (celix_dm_component_info_t*)celix_arrayList_get(infos, 0);
+ ASSERT_EQ(1, celix_arrayList_size(infos));
+ auto* dmInfo = (celix_dependency_manager_info_t*)celix_arrayList_get(infos, 0);
+ ASSERT_EQ(1, celix_arrayList_size(dmInfo->components));
+ auto *info = (celix_dm_component_info_t*)celix_arrayList_get(dmInfo->components, 0);
EXPECT_EQ(1, celix_arrayList_size(info->interfaces));
EXPECT_EQ(1, celix_arrayList_size(info->dependency_list));
celix_dependencyManager_destroyInfos(mng, infos);
+
+ celix_dependencyManager_removeAllComponents(mng);
}
diff --git a/libs/framework/gtest/src/single_framework_test.cpp b/libs/framework/gtest/src/single_framework_test.cpp
index 05ab3c2..9244c8b 100644
--- a/libs/framework/gtest/src/single_framework_test.cpp
+++ b/libs/framework/gtest/src/single_framework_test.cpp
@@ -19,66 +19,31 @@
#include <gtest/gtest.h>
-extern "C" {
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
#include "celix_launcher.h"
#include "celix_framework_factory.h"
- static celix_framework_t *framework = nullptr;
- static celix_bundle_context_t *context = nullptr;
-
- static void setupFm(void) {
- int rc = 0;
-
- rc = celixLauncher_launch("config.properties", &framework);
- ASSERT_EQ(CELIX_SUCCESS, rc);
-
- bundle_pt bundle = nullptr;
- rc = framework_getFrameworkBundle(framework, &bundle);
- ASSERT_EQ(CELIX_SUCCESS, rc);
-
- rc = bundle_getContext(bundle, &context);
- ASSERT_EQ(CELIX_SUCCESS, rc);
- }
-
- static void teardownFm(void) {
-
- celixLauncher_stop(framework);
- celixLauncher_waitForShutdown(framework);
- celixLauncher_destroy(framework);
-
- context = nullptr;
- framework = nullptr;
- }
+class CelixFramework : public ::testing::Test {
+};
- static void testFramework(void) {
- //intentional empty. start/shutdown test
- printf("testing startup/shutdown single framework\n");
- }
+TEST_F(CelixFramework, testFramework) {
+ int rc;
+ celix_framework_t *framework = nullptr;
+ celix_bundle_context_t *context = nullptr;
-}
+ rc = celixLauncher_launch("config.properties", &framework);
+ EXPECT_EQ(CELIX_SUCCESS, rc);
+ bundle_pt bundle = nullptr;
+ rc = framework_getFrameworkBundle(framework, &bundle);
+ EXPECT_EQ(CELIX_SUCCESS, rc);
-class CelixFramework : public ::testing::Test {
-public:
- CelixFramework() {
- setupFm();
- }
-
- ~CelixFramework() override {
- teardownFm();
- }
-};
+ rc = bundle_getContext(bundle, &context);
+ EXPECT_EQ(CELIX_SUCCESS, rc);
-TEST_F(CelixFramework, testFramework) {
- testFramework();
+ celixLauncher_stop(framework);
+ celixLauncher_waitForShutdown(framework);
+ celixLauncher_destroy(framework);
}
class FrameworkFactory : public ::testing::Test {
diff --git a/libs/framework/include/celix_dependency_manager.h b/libs/framework/include/celix_dependency_manager.h
index 612491f..2bff28b 100644
--- a/libs/framework/include/celix_dependency_manager.h
+++ b/libs/framework/include/celix_dependency_manager.h
@@ -59,13 +59,14 @@ celix_status_t celix_dependencyManager_removeAllComponents(celix_dependency_mana
celix_dependency_manager_info_t* celix_dependencyManager_createInfo(celix_dependency_manager_t *manager, long bndId);
/**
- * Create and returns a dependency manager info structd for all started bundles.
+ * Create and returns a dependency manager info struct for all started bundles.
* The dependency manager info contains information about the state of the dependency manager components
*
* Caller has ownership of the return values (use celix_dependencyManager_destroyInfos to free the memory).
*
* @param manager The dependency manager
- * @returns A celix array of dependency manager infos for the provided bundle id or NULL if the bundle id is invalid.
+ * @returns A Celix array of dependency manager infos (celix_dependency_manager_info_t*)
+ * for the provided bundle id or NULL if the bundle id is invalid.
*/
celix_array_list_t * /*celix_dependency_manager_info_t entries*/ celix_dependencyManager_createInfos(celix_dependency_manager_t *manager);
diff --git a/libs/framework/src/dm_component_impl.c b/libs/framework/src/dm_component_impl.c
index e887ca0..409da5a 100644
--- a/libs/framework/src/dm_component_impl.c
+++ b/libs/framework/src/dm_component_impl.c
@@ -634,6 +634,7 @@ static celix_status_t component_registerServices(celix_dm_component_t *component
opts.svc = (void*)interface->service;
opts.serviceName = interface->serviceName;
opts.serviceLanguage = celix_properties_get(regProps, CELIX_FRAMEWORK_SERVICE_LANGUAGE, NULL);
+ interface->svcId = 99999999; //TODO remove, not needed when using async svc registration
celixThreadMutex_unlock(&component->mutex);
long svcId = celix_bundleContext_registerServiceWithOptions(component->context, &opts); //TODO fix race condition with async branch -> registerAsync
celixThreadMutex_lock(&component->mutex);
@@ -701,18 +702,11 @@ celix_status_t component_getComponentInfo(celix_dm_component_t *component, dm_co
}
celix_status_t celix_dmComponent_getComponentInfo(celix_dm_component_t *component, dm_component_info_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
- int i;
- int size;
- dm_component_info_pt info = NULL;
- info = calloc(1, sizeof(*info));
-
- if (info == NULL) {
- return CELIX_ENOMEM;
- }
+ dm_component_info_pt info = calloc(1, sizeof(*info));
+ info->dependency_list = celix_arrayList_create();
+ celix_dmComponent_getInterfaces(component, &info->interfaces);
- arrayList_create(&info->dependency_list);
- component_getInterfaces(component, &info->interfaces);
+ celixThreadMutex_lock(&component->mutex);
info->active = false;
memcpy(info->id, component->uuid, DM_COMPONENT_MAX_ID_LENGTH);
memcpy(info->name, component->name, DM_COMPONENT_MAX_NAME_LENGTH);
@@ -736,27 +730,16 @@ celix_status_t celix_dmComponent_getComponentInfo(celix_dm_component_t *componen
break;
}
- celixThreadMutex_lock(&component->mutex);
- size = celix_arrayList_size(component->dependencies);
- for (i = 0; i < size; i += 1) {
+ for (int i = 0; i < celix_arrayList_size(component->dependencies); i += 1) {
celix_dm_service_dependency_t *dep = celix_arrayList_get(component->dependencies, i);
- dm_service_dependency_info_pt depInfo = NULL;
- status = serviceDependency_getServiceDependencyInfo(dep, &depInfo);
- if (status == CELIX_SUCCESS) {
- celix_arrayList_add(info->dependency_list, depInfo);
- } else {
- break;
- }
+ dm_service_dependency_info_pt depInfo = celix_dmServiceDependency_createInfo(dep);
+ celix_arrayList_add(info->dependency_list, depInfo);
}
- celixThreadMutex_unlock(&component->mutex);
- if (status == CELIX_SUCCESS) {
- *out = info;
- } else if (info != NULL) {
- component_destroyComponentInfo(info);
- }
+ celixThreadMutex_unlock(&component->mutex);
- return status;
+ *out = info;
+ return CELIX_SUCCESS;
}
void component_destroyComponentInfo(dm_component_info_pt info) {
return celix_dmComponent_destroyComponentInfo(info);
diff --git a/libs/framework/src/dm_dependency_manager_impl.c b/libs/framework/src/dm_dependency_manager_impl.c
index 80438e9..81f5cbb 100644
--- a/libs/framework/src/dm_dependency_manager_impl.c
+++ b/libs/framework/src/dm_dependency_manager_impl.c
@@ -156,19 +156,17 @@ static void celix_dm_getInfosCallback(void *handle, const celix_bundle_t *bnd) {
celix_dependency_manager_info_t *info = calloc(1, sizeof(*info));
celixThreadMutex_lock(&mng->mutex);
- if (info != NULL) {
- info->bndId = celix_bundle_getId(bnd);
- info->components = celix_arrayList_create();
- int size = celix_arrayList_size(mng->components);
- for (int i = 0; i < size; i += 1) {
- celix_dm_component_t *cmp = celix_arrayList_get(mng->components, i);
- celix_dm_component_info_t *cmpInfo = NULL;
- component_getComponentInfo(cmp, &cmpInfo);
- celix_arrayList_add(info->components, cmpInfo);
- }
+ info->bndId = celix_bundle_getId(bnd);
+ info->components = celix_arrayList_create();
+ int size = celix_arrayList_size(mng->components);
+ for (int i = 0; i < size; i += 1) {
+ celix_dm_component_t *cmp = celix_arrayList_get(mng->components, i);
+ celix_dm_component_info_t *cmpInfo = NULL;
+ celix_dmComponent_getComponentInfo(cmp, &cmpInfo);
+ celix_arrayList_add(info->components, cmpInfo);
+ }
- celix_arrayList_add(infos, info);
- }
+ celix_arrayList_add(infos, info);
celixThreadMutex_unlock(&mng->mutex);
}
diff --git a/libs/framework/src/dm_service_dependency.c b/libs/framework/src/dm_service_dependency.c
index 2a242c1..5b33261 100644
--- a/libs/framework/src/dm_service_dependency.c
+++ b/libs/framework/src/dm_service_dependency.c
@@ -186,7 +186,6 @@ celix_status_t celix_serviceDependency_start(celix_dm_service_dependency_t *depe
celix_bundle_context_t* ctx = celix_dmComponent_getBundleContext(dependency->component);
if (dependency->serviceName == NULL && dependency->filter == NULL) {
- //TODO improve log (via bundle context?)
fw_log(ctx->framework->logger, CELIX_LOG_LEVEL_ERROR,
"Cannot start a service dependency without a service name and filter");
return CELIX_ILLEGAL_ARGUMENT;
@@ -212,7 +211,7 @@ celix_status_t celix_serviceDependency_start(celix_dm_service_dependency_t *depe
} else {
opts.filter.ignoreServiceLanguage = true;
}
- long newTrackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
+ long newTrackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts); //TODO async
celixThreadMutex_lock(&dependency->mutex);
dependency->svcTrackerId = newTrackerId;