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 2023/04/06 14:08:44 UTC
[celix] branch feature/cap_req_model_lib updated (52b95af3 -> a8cb54f8)
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a change to branch feature/cap_req_model_lib
in repository https://gitbox.apache.org/repos/asf/celix.git
from 52b95af3 Add rcm lib with base requirement-capability-model implementation
new 8aaed860 Replace c11 tss usage with posix tss
new a8cb54f8 Remove equals/hashCode from celix_resource
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../src/RequirementCapabilityModelTestSuite.cc | 25 ++++++-----
libs/rcm/include/celix_resource.h | 4 +-
libs/rcm/src/celix_rcm_err.c | 27 ++++++++----
libs/rcm/src/celix_resource.c | 49 ++++++++++++++++------
4 files changed, 71 insertions(+), 34 deletions(-)
[celix] 02/02: Remove equals/hashCode from celix_resource
Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/cap_req_model_lib
in repository https://gitbox.apache.org/repos/asf/celix.git
commit a8cb54f862e5431e2466caa287da0ad910e972af
Author: Pepijn Noltes <pn...@apache.org>
AuthorDate: Thu Apr 6 16:08:31 2023 +0200
Remove equals/hashCode from celix_resource
---
.../src/RequirementCapabilityModelTestSuite.cc | 25 ++++++-----
libs/rcm/include/celix_resource.h | 4 +-
libs/rcm/src/celix_resource.c | 49 ++++++++++++++++------
3 files changed, 53 insertions(+), 25 deletions(-)
diff --git a/libs/rcm/gtest/src/RequirementCapabilityModelTestSuite.cc b/libs/rcm/gtest/src/RequirementCapabilityModelTestSuite.cc
index e90b0aa5..b9c7d555 100644
--- a/libs/rcm/gtest/src/RequirementCapabilityModelTestSuite.cc
+++ b/libs/rcm/gtest/src/RequirementCapabilityModelTestSuite.cc
@@ -153,35 +153,40 @@ TEST_F(RequirementCapabilityModelTestSuite, TestResource) {
EXPECT_EQ(0, celix_arrayList_size(celix_resource_getRequirements(res, nullptr)));
EXPECT_EQ(0, celix_arrayList_size(celix_resource_getCapabilities(res, nullptr)));
- EXPECT_EQ(celix_resource_hashCode(res), celix_resource_hashCode(res2));
- EXPECT_TRUE(celix_resource_equals(res, res2));
+// EXPECT_EQ(celix_resource_hashCode(res), celix_resource_hashCode(res2));
+// EXPECT_TRUE(celix_resource_equals(res, res2));
celix_requirement_t* req = celix_requirement_create(res, "test-namespace", "(&(capability.attribute1=foo)(capability.attribute2=bar))");
- celix_resource_addRequirement(res, req);
+ EXPECT_TRUE(celix_resource_addRequirement(res, req));
EXPECT_EQ(res, celix_requirement_getResource(req));
EXPECT_EQ(1, celix_arrayList_size(celix_resource_getRequirements(res, nullptr)));
+ req = celix_requirement_create(res, "test-namespace2", nullptr);
+ EXPECT_TRUE(celix_resource_addRequirement(res, req));
+ EXPECT_EQ(2, celix_arrayList_size(celix_resource_getRequirements(res, nullptr)));
celix_capability_t *cap = celix_capability_create(res, "test-namespace");
- celix_resource_addCapability(res, cap);
+ EXPECT_TRUE(celix_resource_addCapability(res, cap));
EXPECT_EQ(res, celix_capability_getResource(cap));
EXPECT_EQ(1, celix_arrayList_size(celix_resource_getCapabilities(res, nullptr)));
- EXPECT_FALSE(celix_resource_equals(res, res2)); //note res 1 changed
- EXPECT_NE(celix_resource_hashCode(res), celix_resource_hashCode(res2));
+// EXPECT_FALSE(celix_resource_equals(res, res2)); //note res 1 changed
+// EXPECT_NE(celix_resource_hashCode(res), celix_resource_hashCode(res2));
+ req = celix_requirement_create(res2, "test-namespace2", nullptr);
+ EXPECT_TRUE(celix_resource_addRequirement(res2, req));
req = celix_requirement_create(res2, "test-namespace", "(&(capability.attribute1=foo)(capability.attribute2=bar))");
- cap = celix_capability_create(res2, "test-namespace");
EXPECT_TRUE(celix_resource_addRequirement(res2, req));
+ cap = celix_capability_create(res2, "test-namespace");
EXPECT_TRUE(celix_resource_addCapability(res2, cap));
- EXPECT_TRUE(celix_resource_equals(res, res2)); //note res and res2 are the same again
- EXPECT_EQ(celix_resource_hashCode(res), celix_resource_hashCode(res2));
+// EXPECT_TRUE(celix_resource_equals(res, res2)); //note res and res2 are the same again
+// EXPECT_EQ(celix_resource_hashCode(res), celix_resource_hashCode(res2));
//test get capabilities/requirements by namespace
req = celix_requirement_create(res, "test-namespace2", nullptr);
cap = celix_capability_create(res, "test-namespace2");
EXPECT_TRUE(celix_resource_addRequirement(res, req));
EXPECT_TRUE(celix_resource_addCapability(res, cap));
- EXPECT_EQ(2, celix_arrayList_size(celix_resource_getRequirements(res, nullptr)));
+ EXPECT_EQ(3, celix_arrayList_size(celix_resource_getRequirements(res, nullptr)));
EXPECT_EQ(2, celix_arrayList_size(celix_resource_getCapabilities(res, nullptr)));
const celix_array_list_t* caps = celix_resource_getCapabilities(res, "test-namespace");
EXPECT_EQ(1, celix_arrayList_size(caps));
diff --git a/libs/rcm/include/celix_resource.h b/libs/rcm/include/celix_resource.h
index 59b31cf1..99821f7a 100644
--- a/libs/rcm/include/celix_resource.h
+++ b/libs/rcm/include/celix_resource.h
@@ -42,9 +42,9 @@ celix_resource_t* celix_resource_create();
void celix_resource_destroy(celix_resource_t* resource);
-bool celix_resource_equals(const celix_resource_t* res1, const celix_resource_t* res2);
+//bool celix_resource_equals(const celix_resource_t* res1, const celix_resource_t* res2);
-unsigned int celix_resource_hashCode(const celix_resource_t* res);
+//unsigned int celix_resource_hashCode(const celix_resource_t* res);
const celix_array_list_t* celix_resource_getCapabilities(const celix_resource_t* res, const char* ns);
diff --git a/libs/rcm/src/celix_resource.c b/libs/rcm/src/celix_resource.c
index 6b41f457..e981e0ee 100644
--- a/libs/rcm/src/celix_resource.c
+++ b/libs/rcm/src/celix_resource.c
@@ -82,7 +82,7 @@ void celix_resource_destroy(celix_resource_t* resource) {
free(resource);
}
}
-
+/*
bool celix_resource_equals(const celix_resource_t* res1, const celix_resource_t* res2) {
if (res1 == res2) {
return true;
@@ -93,42 +93,57 @@ bool celix_resource_equals(const celix_resource_t* res1, const celix_resource_t*
return false;
}
- //FIXME this is not correct, as the order of the capabilities and requirements is not important
+
+ int equalCount = 0;
for (int i = 0; i < celix_arrayList_size(res1->allCapabilities); ++i) {
celix_capability_t* cap1 = celix_arrayList_get(res1->allCapabilities, i);
- celix_capability_t* cap2 = celix_arrayList_get(res2->allCapabilities, i);
- if (!celix_capability_equals(cap1, cap2)) {
- return false;
+ for (int k = 0; k < celix_arrayList_size(res2->allCapabilities); ++k) {
+ celix_capability_t* cap2 = celix_arrayList_get(res2->allCapabilities, k);
+ if (celix_capability_equals(cap1, cap2)) {
+ equalCount++;
+ break;
+ }
}
}
+ //FIXME only correct if all capabilities are unique
+ if (equalCount != celix_arrayList_size(res1->allCapabilities)) {
+ return false;
+ }
- //FIXME this is not correct, as the order of the capabilities and requirements is not important
- for (int i = 0; i < celix_arrayList_size(res1->allCapabilities); ++i) {
- celix_requirement_t* req1 = celix_arrayList_get(res1->allCapabilities, i);
- celix_requirement_t* req2 = celix_arrayList_get(res2->allCapabilities, i);
- if (!celix_requirement_equals(req1, req2)) {
- return false;
+ equalCount = 0;
+ for (int i = 0; i < celix_arrayList_size(res1->allRequirements); ++i) {
+ celix_requirement_t* req1 = celix_arrayList_get(res1->allRequirements, i);
+ for (int k = 0; k < celix_arrayList_size(res2->allRequirements); ++k) {
+ celix_requirement_t* req2 = celix_arrayList_get(res2->allRequirements, k);
+ if (celix_requirement_equals(req1, req2)) {
+ equalCount++;
+ break;
+ }
}
}
+ //FIXME only correct if all capabilities are unique
+ if (equalCount != celix_arrayList_size(res1->allCapabilities)) {
+ return false;
+ }
+
return true;
}
unsigned int celix_resource_hashCode(const celix_resource_t* res) {
unsigned int hash = 0;
- //FIXME this is not correct, as the order of the capabilities and requirements is not important
for (int i = 0; i < celix_arrayList_size(res->allCapabilities); ++i) {
celix_capability_t* cap = celix_arrayList_get(res->allCapabilities, i);
hash += celix_capability_hashCode(cap);
}
- //FIXME this is not correct, as the order of the capabilities and requirements is not important
for (int i = 0; i < celix_arrayList_size(res->allRequirements); ++i) {
celix_requirement_t* req = celix_arrayList_get(res->allRequirements, i);
hash += celix_requirement_hashCode(req);
}
return hash;
}
+ */
const celix_array_list_t* celix_resource_getCapabilities(const celix_resource_t* res, const char* ns) {
if (ns != NULL) {
@@ -157,6 +172,10 @@ bool celix_resource_addCapability(celix_resource_t* res, celix_capability_t* cap
celix_array_list_t* caps = celix_stringHashMap_get(res->capabilitiesByNamespace, ns);
if (caps == NULL) {
caps = celix_arrayList_create();
+ if (caps == NULL) {
+ celix_rcmErr_push("Failed to allocate capabilities list. Out of memory.");
+ return false;
+ }
celix_stringHashMap_put(res->capabilitiesByNamespace, ns, caps);
}
celix_arrayList_add(caps, cap);
@@ -176,6 +195,10 @@ bool celix_resource_addRequirement(celix_resource_t* res, celix_requirement_t* r
celix_array_list_t* reqs = celix_stringHashMap_get(res->requirementsByNamespace, ns);
if (reqs == NULL) {
reqs = celix_arrayList_create();
+ if (reqs == NULL) {
+ celix_rcmErr_push("Failed to allocate requirement list. Out of memory.");
+ return false;
+ }
celix_stringHashMap_put(res->requirementsByNamespace, ns, reqs);
}
celix_arrayList_add(reqs, req);
[celix] 01/02: Replace c11 tss usage with posix tss
Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/cap_req_model_lib
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 8aaed860dc4c259ffeba82212a3cbba0846ca509
Author: Pepijn Noltes <pn...@apache.org>
AuthorDate: Thu Apr 6 15:55:00 2023 +0200
Replace c11 tss usage with posix tss
---
libs/rcm/src/celix_rcm_err.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/libs/rcm/src/celix_rcm_err.c b/libs/rcm/src/celix_rcm_err.c
index d98fdbbf..8938726e 100644
--- a/libs/rcm/src/celix_rcm_err.c
+++ b/libs/rcm/src/celix_rcm_err.c
@@ -18,16 +18,18 @@
*/
#include <stdlib.h>
-#include <threads.h>
#include <stdarg.h>
#include <stdio.h>
+//#include <threads.h>
+#include <pthread.h>
#include "celix_array_list.h"
#include "celix_rcm_err_private.h"
#include "celix_rcm_err.h"
#include "celix_utils.h"
-static tss_t celix_rcm_tssErrorsKey;
+//static tss_t celix_rcm_tssErrorsKey;
+pthread_key_t celix_rcm_tssErrorsKey;
static void celix_rcm_destroyTssErrors(void* data) {
celix_array_list_t* errors = data;
@@ -41,16 +43,19 @@ static void celix_rcm_destroyTssErrors(void* data) {
}
__attribute__((constructor)) static void celix_rcm_initThreadSpecificStorageKey() {
- tss_create(&celix_rcm_tssErrorsKey, celix_rcm_destroyTssErrors);
+ //tss_create(&celix_rcm_tssErrorsKey, celix_rcm_destroyTssErrors);
+ pthread_key_create(&celix_rcm_tssErrorsKey, celix_rcm_destroyTssErrors);
}
__attribute__((destructor)) static void celix_rcm_deinitThreadSpecificStorageKey() {
- tss_delete(celix_rcm_tssErrorsKey);
+ //tss_delete(celix_rcm_tssErrorsKey);
+ pthread_key_delete(celix_rcm_tssErrorsKey);
}
char* celix_rcmErr_popLastError() {
char* result = NULL;
- celix_array_list_t* errors = tss_get(celix_rcm_tssErrorsKey);
+ //celix_array_list_t* errors = tss_get(celix_rcm_tssErrorsKey);
+ celix_array_list_t* errors = pthread_getspecific(celix_rcm_tssErrorsKey);
if (errors != NULL && celix_arrayList_size(errors) > 0) {
result = celix_arrayList_get(errors, 0);
celix_arrayList_removeAt(errors, 0);
@@ -60,7 +65,8 @@ char* celix_rcmErr_popLastError() {
int celix_rcmErr_getErrorCount() {
int result = 0;
- celix_array_list_t* errors = tss_get(celix_rcm_tssErrorsKey);
+ //celix_array_list_t* errors = tss_get(celix_rcm_tssErrorsKey);
+ celix_array_list_t* errors = pthread_getspecific(celix_rcm_tssErrorsKey);
if (errors != NULL) {
result = celix_arrayList_size(errors);
}
@@ -68,7 +74,8 @@ int celix_rcmErr_getErrorCount() {
}
void celix_rcmErr_resetErrors() {
- celix_array_list_t* errors = tss_get(celix_rcm_tssErrorsKey);
+ //celix_array_list_t* errors = tss_get(celix_rcm_tssErrorsKey);
+ celix_array_list_t* errors = pthread_getspecific(celix_rcm_tssErrorsKey);
if (errors != NULL) {
for (int i = 0; i < celix_arrayList_size(errors); ++i) {
char* msg = celix_arrayList_get(errors, i);
@@ -79,10 +86,12 @@ void celix_rcmErr_resetErrors() {
}
static void celix_rcm_pushMsg(char* msg) {
- celix_array_list_t* errors = tss_get(celix_rcm_tssErrorsKey);
+ //celix_array_list_t* errors = tss_get(celix_rcm_tssErrorsKey);
+ celix_array_list_t* errors = pthread_getspecific(celix_rcm_tssErrorsKey);
if (errors == NULL) {
errors = celix_arrayList_create();
- tss_set(celix_rcm_tssErrorsKey, errors);
+ //tss_set(celix_rcm_tssErrorsKey, errors);
+ pthread_setspecific(celix_rcm_tssErrorsKey, errors);
}
if (errors != NULL) {
celix_arrayList_add(errors, msg);