Skip to content

Commit

Permalink
#509: Remove deprecated macro (incl usage) CELIX_PROPERTIES_FOR_EACH
Browse files Browse the repository at this point in the history
  • Loading branch information
pnoltes committed Oct 7, 2023
1 parent 1f5bf79 commit 77f212a
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,17 @@ celix_status_t pubsubProtocol_encodeMetadata(pubsub_protocol_message_t* message,
*bufferInOut = newBuffer;
*bufferLengthInOut = newLength;
}
const char* key;
if (metadataSize == 0) {
encoded = true;
continue;
}
celix_status_t status = CELIX_SUCCESS;
CELIX_PROPERTIES_FOR_EACH(message->metadata.metadata, key) {
const char *val = celix_properties_get(message->metadata.metadata, key, "");
CELIX_PROPERTIES_ITERATE(message->metadata.metadata, iter) {
if (status == CELIX_SUCCESS) {
status = pubsubProtocol_addNetstringEntryToBuffer(*bufferInOut, *bufferLengthInOut, &offset, key);
status = pubsubProtocol_addNetstringEntryToBuffer(*bufferInOut, *bufferLengthInOut, &offset, iter.key);
}
if (status == CELIX_SUCCESS) {
status = pubsubProtocol_addNetstringEntryToBuffer(*bufferInOut, *bufferLengthInOut, &offset, val);
status = pubsubProtocol_addNetstringEntryToBuffer(*bufferInOut, *bufferLengthInOut, &offset, iter.entry.value);
}
}
if (status == CELIX_FILE_IO_EXCEPTION) {
Expand Down
5 changes: 2 additions & 3 deletions libs/framework/gtest/src/ManifestTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ class ManifestTestSuite : public ::testing::Test {
}
void CheckPropertiesEqual(const celix_properties_t* prop1, const celix_properties_t* prop2) {
EXPECT_EQ(celix_properties_size(prop1), celix_properties_size(prop2));
const char* key = nullptr;
CELIX_PROPERTIES_FOR_EACH(prop1, key) {
EXPECT_STREQ(celix_properties_get(prop1, key, nullptr), celix_properties_get(prop2, key, nullptr));
CELIX_PROPERTIES_ITERATE(prop1, iter) {
EXPECT_STREQ(celix_properties_get(prop1, iter.key, nullptr), celix_properties_get(prop2, iter.key, nullptr));
}
}
void CheckManifestEqual(const manifest_pt manifest1, const manifest_pt manifest2) {
Expand Down
2 changes: 1 addition & 1 deletion libs/framework/include/celix/Trackers.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ namespace celix {
long svcId = celix_properties_getAsLong(cProps, OSGI_FRAMEWORK_SERVICE_ID, -1L);
long svcRanking = celix_properties_getAsLong(cProps, OSGI_FRAMEWORK_SERVICE_RANKING, 0);
auto svc = std::shared_ptr<I>{static_cast<I*>(voidSvc), [](I*){/*nop*/}};
auto props = celix::Properties::wrap(cProps);
auto props = std::make_shared<const celix::Properties>(celix::Properties::wrap(cProps));
auto owner = std::make_shared<celix::Bundle>(const_cast<celix_bundle_t*>(cBnd));
return std::make_shared<SvcEntry>(svcId, svcRanking, svc, props, owner);
}
Expand Down
4 changes: 2 additions & 2 deletions libs/framework/include/celix/UseServiceBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ namespace celix {
func(*svc);
}
for (const auto& func : builder->callbacksWithProperties) {
func(*svc, *props);
func(*svc, props);
}
for (const auto& func : builder->callbacksWithOwner) {
func(*svc, *props, bnd);
func(*svc, props, bnd);
}
};

Expand Down
6 changes: 2 additions & 4 deletions libs/framework/include/celix/dm/DependencyManager_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ static celix::dm::DependencyManagerInfo createDepManInfoFromC(celix_dependency_m
auto* cIntInfo = static_cast<dm_interface_info_t*>(celix_arrayList_get(cCmpInfo->interfaces, k));
celix::dm::InterfaceInfo intInfo{};
intInfo.serviceName = std::string{cIntInfo->name};
const char* key;
CELIX_PROPERTIES_FOR_EACH(cIntInfo->properties, key) {
const char* val =celix_properties_get(cIntInfo->properties, key, "");
intInfo.properties[std::string{key}] = std::string{val};
CELIX_PROPERTIES_ITERATE(cIntInfo->properties, iter) {
intInfo.properties[std::string{iter.key}] = std::string{iter.entry.value};
}
cmpInfo.interfacesInfo.emplace_back(std::move(intInfo));
}
Expand Down
32 changes: 4 additions & 28 deletions libs/framework/include/celix/dm/ServiceDependency_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,8 @@ void CServiceDependency<T,I>::setupCallbacks() {

template<class T, typename I>
int CServiceDependency<T,I>::invokeCallback(std::function<void(const I*, Properties&&)> fp, const celix_properties_t *props, const void* service) {
Properties properties {};
const char* key {nullptr};
const char* value {nullptr};

if (props != nullptr) {
CELIX_PROPERTIES_FOR_EACH(props, key) {
value = celix_properties_get(props, key, ""); //note. C++ does not allow nullptr entries for std::string
//std::cout << "got property " << key << "=" << value << "\n";
properties[key] = value;
}
}

auto properties = Properties::copy(props);
const I* srv = (const I*) service;

fp(srv, std::move(properties));
return 0;
}
Expand Down Expand Up @@ -504,19 +492,7 @@ ServiceDependency<T,I>& ServiceDependency<T,I>::setStrategy(DependencyUpdateStra
template<class T, class I>
int ServiceDependency<T,I>::invokeCallback(std::function<void(I*, Properties&&)> fp, const celix_properties_t *props, const void* service) {
I *svc = (I*)service;

Properties properties {};
const char* key {nullptr};
const char* value {nullptr};

if (props != nullptr) {
CELIX_PROPERTIES_FOR_EACH(props, key) {
value = celix_properties_get(props, key, "");
//std::cout << "got property " << key << "=" << value << "\n";
properties[key] = value;
}
}

auto properties = celix::Properties::wrap(props);
fp(svc, std::move(properties)); //explicit move of lvalue properties.
return 0;
}
Expand All @@ -539,7 +515,7 @@ void ServiceDependency<T,I>::setupCallbacks() {
std::weak_ptr<I> replacedSvc = dep->setService.first;
std::weak_ptr<const celix::Properties> replacedProps = dep->setService.second;
auto svc = std::shared_ptr<I>{static_cast<I*>(rawSvc), [](I*){/*nop*/}};
auto props = rawProps ? celix::Properties::wrap(rawProps) : nullptr;
auto props = rawProps ? std::make_shared<const celix::Properties>(celix::Properties::wrap(rawProps)) : nullptr;
dep->setService = std::make_pair(std::move(svc), std::move(props));
dep->setFpUsingSharedPtr(dep->setService.first, dep->setService.second);
dep->waitForExpired(replacedSvc, svcId, "service pointer");
Expand All @@ -556,7 +532,7 @@ void ServiceDependency<T,I>::setupCallbacks() {
rc = dep->invokeCallback(dep->addFp, rawProps, rawSvc);
}
if (dep->addFpUsingSharedPtr) {
auto props = celix::Properties::wrap(rawProps);
auto props = std::make_shared<const celix::Properties>(celix::Properties::wrap(rawProps));
auto svc = std::shared_ptr<I>{static_cast<I*>(rawSvc), [](I*){/*nop*/}};
auto svcId = props->getAsLong(celix::SERVICE_ID, -1);
dep->addFpUsingSharedPtr(svc, props);
Expand Down
32 changes: 14 additions & 18 deletions libs/framework/src/celix_launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,15 @@ static void celixLauncher_printUsage(char* progName) {
}

static void celixLauncher_printProperties(celix_properties_t *embeddedProps, const char *configFile) {
const char *key = NULL;
celix_properties_t *keys = celix_properties_create(); //only to store the keys

printf("Embedded properties:\n");
if (embeddedProps == NULL || celix_properties_size(embeddedProps) == 0) {
printf("|- Empty!\n");
} else {
CELIX_PROPERTIES_FOR_EACH(embeddedProps, key) {
const char *val = celix_properties_get(embeddedProps, key, "!Error!");
printf("|- %s=%s\n", key, val);
celix_properties_set(keys, key, NULL);
CELIX_PROPERTIES_ITERATE(embeddedProps, visit) {
printf("|- %s=%s\n", visit.key, visit.entry.value);
celix_properties_set(keys, visit.key, NULL);
}
}
printf("\n");
Expand All @@ -216,11 +214,10 @@ static void celixLauncher_printProperties(celix_properties_t *embeddedProps, con
if (runtimeProps == NULL || celix_properties_size(runtimeProps) == 0) {
printf("|- Empty!\n");
} else {
CELIX_PROPERTIES_FOR_EACH(runtimeProps, key) {
const char *val = celix_properties_get(runtimeProps, key, "!Error!");
printf("|- %s=%s\n", key, val);
celix_properties_set(keys, key, NULL);
}
CELIX_PROPERTIES_ITERATE(runtimeProps, visit) {
printf("|- %s=%s\n", visit.key, visit.entry.value);
celix_properties_set(keys, visit.key, NULL);
}
}
printf("\n");

Expand All @@ -229,13 +226,13 @@ static void celixLauncher_printProperties(celix_properties_t *embeddedProps, con
if (celix_properties_size(keys) == 0) {
printf("|- Empty!\n");
} else {
CELIX_PROPERTIES_FOR_EACH(keys, key) {
const char *valEm = celix_properties_get(embeddedProps, key, NULL);
const char *valRt = celix_properties_get(runtimeProps, key, NULL);
const char *envVal = getenv(key);
CELIX_PROPERTIES_ITERATE(keys, visit) {
const char *valEm = celix_properties_get(embeddedProps, visit.key, NULL);
const char *valRt = celix_properties_get(runtimeProps, visit.key, NULL);
const char *envVal = getenv(visit.key);
const char *val = envVal != NULL ? envVal : valRt != NULL ? valRt : valEm;
const char *source = envVal != NULL ? "environment" : valRt != NULL ? "runtime" : "embedded";
printf("|- %s=%s (source %s)\n", key, val, source);
printf("|- %s=%s (source %s)\n", visit.key, val, source);
}
}
printf("\n");
Expand Down Expand Up @@ -279,9 +276,8 @@ static int celixLauncher_createBundleCache(celix_properties_t* embeddedPropertie

static void celixLauncher_combineProperties(celix_properties_t *original, const celix_properties_t *append) {
if (original != NULL && append != NULL) {
const char *key = NULL;
CELIX_PROPERTIES_FOR_EACH(append, key) {
celix_properties_set(original, key, celix_properties_get(append, key, NULL));
CELIX_PROPERTIES_ITERATE(append, visit) {
celix_properties_setEntry(original, visit.key, &visit.entry);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions libs/framework/src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ manifest_pt manifest_clone(manifest_pt manifest) {
celix_auto(manifest_pt) clone = NULL;
status = manifest_create(&clone);
if (status == CELIX_SUCCESS) {
const char* key = NULL;
CELIX_PROPERTIES_FOR_EACH(manifest->mainAttributes, key) {
celix_properties_set(clone->mainAttributes, key, celix_properties_get(manifest->mainAttributes, key, NULL));
CELIX_PROPERTIES_ITERATE(manifest->mainAttributes, visit) {
celix_properties_set(clone->mainAttributes, visit.key, visit.entry.value);
}
hash_map_iterator_t iter = hashMapIterator_construct(manifest->attributes);
while (hashMapIterator_hasNext(&iter)) {
Expand Down
43 changes: 16 additions & 27 deletions libs/rcm/src/celix_capability.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,19 @@ bool celix_capability_equals(const celix_capability_t* cap1, const celix_capabil

//compare attributes
bool equals = true;
const char* visit;
CELIX_PROPERTIES_FOR_EACH(cap1->attributes, visit) {
const char* value1 = celix_properties_get(cap1->attributes, visit, NULL);
const char* value2 = celix_properties_get(cap2->attributes, visit, NULL);
if (!celix_utils_stringEquals(value1, value2)) {
CELIX_PROPERTIES_ITERATE(cap1->attributes, visit) {
const char* value2 = celix_properties_get(cap2->attributes, visit.key, NULL);
if (!celix_utils_stringEquals(visit.entry.value, value2)) {
equals = false;
break;
}
}
if (!equals) {
return false;
}
CELIX_PROPERTIES_FOR_EACH(cap1->directives, visit) {
const char* value1 = celix_properties_get(cap1->directives, visit, NULL);
const char* value2 = celix_properties_get(cap2->directives, visit, NULL);
if (!celix_utils_stringEquals(value1, value2)) {
CELIX_PROPERTIES_ITERATE(cap1->directives, visit) {
const char* value2 = celix_properties_get(cap2->directives, visit.key, NULL);
if (!celix_utils_stringEquals(visit.entry.value, value2)) {
equals = false;
break;
}
Expand All @@ -108,17 +105,13 @@ bool celix_capability_equals(const celix_capability_t* cap1, const celix_capabil

unsigned int celix_capability_hashCode(const celix_capability_t* cap) {
unsigned int hash = celix_utils_stringHash(cap->ns);
const char* visit;

CELIX_PROPERTIES_FOR_EACH(cap->attributes, visit) {
const char* value = celix_properties_get(cap->attributes, visit, NULL);
hash += celix_utils_stringHash(visit);
hash += celix_utils_stringHash(value);
CELIX_PROPERTIES_ITERATE(cap->attributes, visit) {
hash += celix_utils_stringHash(visit.key);
hash += celix_utils_stringHash(visit.entry.value);
}
CELIX_PROPERTIES_FOR_EACH(cap->directives, visit) {
const char* value = celix_properties_get(cap->directives, visit, NULL);
hash += celix_utils_stringHash(visit);
hash += celix_utils_stringHash(value);
CELIX_PROPERTIES_ITERATE(cap->directives, visit) {
hash += celix_utils_stringHash(visit.key);
hash += celix_utils_stringHash(visit.entry.value);
}
return hash;
}
Expand Down Expand Up @@ -152,10 +145,8 @@ void celix_capability_addAttribute(celix_capability_t* cap, const char* key, con
}

void celix_capability_addAttributes(celix_capability_t* cap, const celix_properties_t* attributes) {
const char* visit;
CELIX_PROPERTIES_FOR_EACH(attributes, visit) {
const char* value = celix_properties_get(attributes, visit, NULL);
celix_properties_set(cap->attributes, visit, value);
CELIX_PROPERTIES_ITERATE(attributes, visit) {
celix_properties_set(cap->attributes, visit.key, visit.entry.value);
}
}

Expand All @@ -164,9 +155,7 @@ void celix_capability_addDirective(celix_capability_t* cap, const char* key, con
}

void celix_capability_addDirectives(celix_capability_t* cap, const celix_properties_t* directives) {
const char* visit;
CELIX_PROPERTIES_FOR_EACH(directives, visit) {
const char* value = celix_properties_get(directives, visit, NULL);
celix_properties_set(cap->directives, visit, value);
CELIX_PROPERTIES_ITERATE(directives, visit) {
celix_properties_set(cap->directives, visit.key, visit.entry.value);
}
}
56 changes: 20 additions & 36 deletions libs/rcm/src/celix_requirement.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,45 +89,33 @@ bool celix_requirement_equals(const celix_requirement_t* req1, const celix_requi
}

//compare attributes
bool equals = true;
const char* visit;
CELIX_PROPERTIES_FOR_EACH(req1->attributes, visit) {
const char* val1 = celix_properties_get(req1->attributes, visit, NULL);
const char* val2 = celix_properties_get(req2->attributes, visit, NULL);
if (!celix_utils_stringEquals(val1, val2)) {
equals = false;
break;
CELIX_PROPERTIES_ITERATE(req1->attributes, visit) {
const char* val2 = celix_properties_get(req2->attributes, visit.key, NULL);
if (!celix_utils_stringEquals(visit.entry.value, val2)) {
return false;
}
}
if (!equals) {
return false;
}

//compare directives
CELIX_PROPERTIES_FOR_EACH(req1->directives, visit) {
const char* val1 = celix_properties_get(req1->directives, visit, NULL);
const char* val2 = celix_properties_get(req2->directives, visit, NULL);
if (!celix_utils_stringEquals(val1, val2)) {
equals = false;
break;
CELIX_PROPERTIES_ITERATE(req1->directives, visit) {
const char* val2 = celix_properties_get(req2->directives, visit.key, NULL);
if (!celix_utils_stringEquals(visit.entry.value, val2)) {
return false;
}
}
return equals;

return true;
}

unsigned int celix_requirement_hashCode(const celix_requirement_t* req) {
unsigned int hash = celix_utils_stringHash(req->ns);
const char* visit;

CELIX_PROPERTIES_FOR_EACH(req->attributes, visit) {
const char* val = celix_properties_get(req->attributes, visit, NULL);
hash += celix_utils_stringHash(visit);
hash += celix_utils_stringHash(val);
CELIX_PROPERTIES_ITERATE(req->attributes, visit) {
hash += celix_utils_stringHash(visit.key);
hash += celix_utils_stringHash(visit.entry.value);
}
CELIX_PROPERTIES_FOR_EACH(req->directives, visit) {
const char* val = celix_properties_get(req->directives, visit, NULL);
hash += celix_utils_stringHash(visit);
hash += celix_utils_stringHash(val);
CELIX_PROPERTIES_ITERATE(req->directives, visit) {
hash += celix_utils_stringHash(visit.key);
hash += celix_utils_stringHash(visit.entry.value);
}
return hash;
}
Expand Down Expand Up @@ -169,17 +157,13 @@ void celix_requirement_addAttribute(celix_requirement_t* req, const char* key, c
}

void celix_requirement_addDirectives(celix_requirement_t* req, const celix_properties_t* directives) {
const char* visit;
CELIX_PROPERTIES_FOR_EACH(directives, visit) {
const char* val = celix_properties_get(directives, visit, NULL);
celix_requirement_addDirective(req, visit, val);
CELIX_PROPERTIES_ITERATE(directives, visit) {
celix_requirement_addDirective(req, visit.key, visit.entry.value);
}
}

void celix_requirement_addAttributes(celix_requirement_t* req, const celix_properties_t* attributes) {
const char* visit;
CELIX_PROPERTIES_FOR_EACH(attributes, visit) {
const char* val = celix_properties_get(attributes, visit, NULL);
celix_requirement_addAttribute(req, visit, val);
CELIX_PROPERTIES_ITERATE(attributes, visit) {
celix_requirement_addAttribute(req, visit.key, visit.entry.value);
}
}
19 changes: 17 additions & 2 deletions libs/utils/gtest/src/CxxPropertiesTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,23 @@ TEST_F(CxxPropertiesTestSuite, WrapTest) {
EXPECT_EQ(1, celix_properties_size(props));
{
auto cxxProps = celix::Properties::wrap(props);
EXPECT_EQ(1, cxxProps->size());
EXPECT_EQ(props, cxxProps->getCProperties());
EXPECT_EQ(1, cxxProps.size());
EXPECT_EQ(props, cxxProps.getCProperties());
} //NOTE cxxProps out of scope, but will not destroy celix_properties
EXPECT_EQ(1, celix_properties_size(props));

celix_properties_destroy(props);
}

TEST_F(CxxPropertiesTestSuite, CopyCPropsTest) {
auto *props = celix_properties_create();
celix_properties_set(props, "test", "test");

EXPECT_EQ(1, celix_properties_size(props));
{
auto cxxProps = celix::Properties::copy(props);
EXPECT_EQ(1, cxxProps.size());
EXPECT_NE(props, cxxProps.getCProperties());
} //NOTE cxxProps out of scope, but will not destroy celix_properties
EXPECT_EQ(1, celix_properties_size(props));

Expand Down
Loading

0 comments on commit 77f212a

Please sign in to comment.