Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/type_support_for_propert…
Browse files Browse the repository at this point in the history
…ies' into feature/type_support_for_properties
  • Loading branch information
pnoltes committed Oct 8, 2023
2 parents f8e95a5 + 77f212a commit 1856ced
Show file tree
Hide file tree
Showing 55 changed files with 3,363 additions and 1,422 deletions.
7 changes: 6 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ limitations under the License.
- Shell v2 api is removed and no longer supported.
- Logging v2 api is removed and no longer supported.
- Bonjour Shell bundle is removed and no longer supported.
- pubsub_serializer.h is removed and no longer supported. Use pubsub_message_serialization_service.h instead.
- pubsub_serializer.h is removed and no longer supported. Use pubsub_message_serialization_service.h instead.
- C Properties are no longer a direct typedef o `hashmap`.

## New Features

- Basic type support for value in celix Properties.

# Noteworthy Changes for 2.4.0 (2023-09-27)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ int pubsub_subscriber_recv(void* handle, const char* msgType, unsigned int msgTy
if (metadata == NULL || celix_properties_size(metadata) == 0) {
printf("No metadata\n");
} else {
const char *key;
CELIX_PROPERTIES_FOR_EACH(metadata, key) {
const char *val = celix_properties_get(metadata, key, "!Error!");
printf("%s=%s\n", key, val);
CELIX_PROPERTIES_ITERATE(metadata, iter) {
printf("%s=%s\n", iter.key, iter.entry.value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ class PubSubInterceptorTestSuite : public ::testing::Test {
const auto *msg = static_cast<const msg_t*>(rawMsg);
EXPECT_GE(msg->seqNr, 0);
EXPECT_STREQ(celix_properties_get(metadata, "test", nullptr), "preSend");
const char *key;
CELIX_PROPERTIES_FOR_EACH(metadata, key) {
printf("got property %s=%s\n", key, celix_properties_get(metadata, key, nullptr));
CELIX_PROPERTIES_ITERATE(metadata, iter) {
printf("got property %s=%s\n", iter.key, iter.entry.value);
}
fprintf(stdout, "Got message in postSend interceptor %s/%s for type %s and ser %s with seq nr %i\n", intProps->scope, intProps->topic, intProps->psaType, intProps->serializationType, msg->seqNr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,8 @@ static celix_status_t pubsub_websocketAdmin_connectEndpointToReceiver(pubsub_web

if (publisher && (sockAddress == NULL || sockPort < 0)) {
L_WARN("[PSA WEBSOCKET] Error got endpoint without websocket address/port or endpoint type. Properties:");
const char *key = NULL;
CELIX_PROPERTIES_FOR_EACH(endpoint, key) {
L_WARN("[PSA WEBSOCKET] |- %s=%s\n", key, celix_properties_get(endpoint, key, NULL));
CELIX_PROPERTIES_ITERATE(endpoint, iter) {
L_WARN("[PSA WEBSOCKET] |- %s=%s\n", iter.key, iter.entry.value);
}
status = CELIX_BUNDLE_EXCEPTION;
} else {
Expand Down Expand Up @@ -436,9 +435,8 @@ static celix_status_t pubsub_websocketAdmin_disconnectEndpointFromReceiver(pubsu

if (publisher && (sockAddress == NULL || sockPort < 0)) {
L_WARN("[PSA WEBSOCKET] Error got endpoint without websocket address/port or endpoint type. Properties:");
const char *key = NULL;
CELIX_PROPERTIES_FOR_EACH(endpoint, key) {
L_WARN("[PSA WEBSOCKET] |- %s=%s\n", key, celix_properties_get(endpoint, key, NULL));
CELIX_PROPERTIES_ITERATE(endpoint, iter) {
L_WARN("[PSA WEBSOCKET] |- %s=%s\n", iter.key, iter.entry.value);
}
status = CELIX_BUNDLE_EXCEPTION;
} else if (eTopic != NULL && strncmp(eTopic, topic, 1024 * 1024) == 0) {
Expand Down
6 changes: 2 additions & 4 deletions bundles/pubsub/pubsub_discovery/src/pubsub_discovery_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,8 @@ static char* pubsub_discovery_createJsonEndpoint(const celix_properties_t *props
//note props is already check for validity (pubsubEndpoint_isValid)

json_t *jsEndpoint = json_object();
const char* propKey = NULL;
PROPERTIES_FOR_EACH((celix_properties_t*)props, propKey) {
const char* val = celix_properties_get(props, propKey, NULL);
json_object_set_new(jsEndpoint, propKey, json_string(val));
CELIX_PROPERTIES_ITERATE(props, iter) {
json_object_set_new(jsEndpoint, iter.key, json_string(iter.entry.value));
}
char* str = json_dumps(jsEndpoint, JSON_COMPACT);
json_decref(jsEndpoint);
Expand Down
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 bundles/pubsub/pubsub_spi/src/pubsub_endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ static void pubsubEndpoint_setFields(celix_properties_t *ep, const char* fwUUID,

//copy topic properties
if (topic_props != NULL) {
const char *key = NULL;
CELIX_PROPERTIES_FOR_EACH((celix_properties_t *) topic_props, key) {
celix_properties_set(ep, key, celix_properties_get(topic_props, key, NULL));
CELIX_PROPERTIES_ITERATE((celix_properties_t *) topic_props, iter) {
celix_properties_set(ep, iter.key, iter.entry.value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,15 @@ static celix_status_t endpointDescriptorWriter_writeEndpoint(endpoint_descriptor
} else {
xmlTextWriterStartElement(writer->writer, ENDPOINT_DESCRIPTION);

hash_map_iterator_pt iter = hashMapIterator_create(endpoint->properties);
while (hashMapIterator_hasNext(iter)) {
hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);

void* propertyName = hashMapEntry_getKey(entry);
const xmlChar* propertyValue = (const xmlChar*) hashMapEntry_getValue(entry);

CELIX_PROPERTIES_ITERATE(endpoint->properties, iter) {
const xmlChar* propertyValue = (const xmlChar*) celix_properties_get(endpoint->properties, iter.key, "");
xmlTextWriterStartElement(writer->writer, PROPERTY);
xmlTextWriterWriteAttribute(writer->writer, NAME, propertyName);
xmlTextWriterWriteAttribute(writer->writer, NAME, (const xmlChar*)iter.key);

if (strcmp(OSGI_FRAMEWORK_OBJECTCLASS, (char*) propertyName) == 0) {
if (strcmp(OSGI_FRAMEWORK_OBJECTCLASS, (char*) iter.key) == 0) {
// objectClass *must* be represented as array of string values...
endpointDescriptorWriter_writeArrayValue(writer->writer, propertyValue);
} else if (strcmp(OSGI_RSA_ENDPOINT_SERVICE_ID, (char*) propertyName) == 0) {
} else if (strcmp(OSGI_RSA_ENDPOINT_SERVICE_ID, (char*) iter.key) == 0) {
// endpoint.service.id *must* be represented as long value...
endpointDescriptorWriter_writeTypedValue(writer->writer, VALUE_TYPE_LONG, propertyValue);
} else {
Expand All @@ -162,7 +157,6 @@ static celix_status_t endpointDescriptorWriter_writeEndpoint(endpoint_descriptor

xmlTextWriterEndElement(writer->writer);
}
hashMapIterator_destroy(iter);

xmlTextWriterEndElement(writer->writer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,10 @@ static void discoveryZeroconfAnnouncer_revokeEndpoints(discovery_zeroconf_announ
static bool discoveryZeroconfAnnouncer_copyPropertiesToTxtRecord(discovery_zeroconf_announcer_t *announcer, celix_properties_iterator_t *propIter, TXTRecordRef *txtRecord, uint16_t maxTxtLen, bool splitTxtRecord) {
const char *key;
const char *val;
celix_properties_t *props;
while (celix_propertiesIterator_hasNext(propIter)) {
key = celix_propertiesIterator_nextKey(propIter);
props = celix_propertiesIterator_properties(propIter);
val = celix_properties_get(props, key, "");
celix_propertiesIterator_next(propIter);
key = propIter->key;
val = propIter->entry.value;
if (key) {
DNSServiceErrorType err = TXTRecordSetValue(txtRecord, key, strlen(val), val);
if (err != kDNSServiceErr_NoError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,7 @@ static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_servic
}
}

hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);

char* key = hashMapEntry_getKey(entry);
char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
const char* serviceId = celix_properties_get(endpointProperties, CELIX_FRAMEWORK_SERVICE_ID, "-1");
const char *uuid = NULL;

char buf[512];
Expand All @@ -775,12 +772,9 @@ static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_servic
}

if (props != NULL) {
hash_map_iterator_pt propIter = hashMapIterator_create(props);
while (hashMapIterator_hasNext(propIter)) {
hash_map_entry_pt entry = hashMapIterator_nextEntry(propIter);
celix_properties_set(endpointProperties, (char*)hashMapEntry_getKey(entry), (char*)hashMapEntry_getValue(entry));
CELIX_PROPERTIES_ITERATE(props, iter) {
celix_properties_set(endpointProperties, iter.key, iter.entry.value);
}
hashMapIterator_destroy(propIter);
}

*endpoint = calloc(1, sizeof(**endpoint));
Expand All @@ -794,8 +788,6 @@ static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_servic
(*endpoint)->properties = endpointProperties;
}

free(key);
free(serviceId);
free(keys);

return status;
Expand Down Expand Up @@ -1002,14 +994,10 @@ static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description
} else {
struct curl_slist *metadataHeader = NULL;
if (metadata != NULL && celix_properties_size(metadata) > 0) {
const char *key = NULL;
CELIX_PROPERTIES_FOR_EACH(metadata, key) {
const char *val = celix_properties_get(metadata, key, "");
size_t length = strlen(key) + strlen(val) + 18; // "X-RSA-Metadata-key: val\0"

CELIX_PROPERTIES_ITERATE(metadata, iter) {
size_t length = strlen(iter.key) + strlen(iter.entry.value) + 18; // "X-RSA-Metadata-key: val\0"
char header[length];

snprintf(header, length, "X-RSA-Metadata-%s: %s", key, val);
snprintf(header, length, "X-RSA-Metadata-%s: %s", iter.key, iter.entry.value);
metadataHeader = curl_slist_append(metadataHeader, header);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ static void rsaShm_overlayProperties(celix_properties_t *additionalProperties, c
}
}
}
return;
}

static bool rsaShm_isConfigTypeMatched(celix_properties_t *properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ celix_status_t topologyManager_importScopeChanged(void *handle, char *service_na
hash_map_entry_pt entry = hashMapIterator_nextEntry(importedServicesIterator);
endpoint = hashMapEntry_getKey(entry);

entry = hashMap_getEntry(endpoint->properties, (void *) OSGI_FRAMEWORK_OBJECTCLASS);
char* name = (char *) hashMapEntry_getValue(entry);
const char* name = celix_properties_get(endpoint->properties, OSGI_FRAMEWORK_OBJECTCLASS, "");
// Test if a service with the same name is imported
if (strcmp(name, service_name) == 0) {
found = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ extern "C" {
for (unsigned int i = 0; i < arrayList_size(epList); i++) {
endpoint_description_t *ep = (endpoint_description_t *) arrayList_get(epList, i);
celix_properties_t *props = ep->properties;
hash_map_entry_pt entry = hashMap_getEntry(props, (void*)"key2");
char* value = (char*) hashMapEntry_getValue(entry);
const char* value = celix_properties_get(props, "key2", "");
EXPECT_STREQ("inaetics", value);
/*
printf("Service: %s ", ep->service);
Expand Down Expand Up @@ -433,8 +432,7 @@ extern "C" {
for (unsigned int i = 0; i < arrayList_size(epList); i++) {
endpoint_description_t *ep = (endpoint_description_t *) arrayList_get(epList, i);
celix_properties_t *props = ep->properties;
hash_map_entry_pt entry = hashMap_getEntry(props, (void*)"key2");
char* value = (char*) hashMapEntry_getValue(entry);
const char* value = celix_properties_get(props, "key2", "");
EXPECT_STREQ("inaetics", value);
}
printf("End: %s\n", __func__);
Expand All @@ -458,8 +456,7 @@ extern "C" {
for (unsigned int i = 0; i < arrayList_size(epList); i++) {
endpoint_description_t *ep = (endpoint_description_t *) arrayList_get(epList, i);
celix_properties_t *props = ep->properties;
hash_map_entry_pt entry = hashMap_getEntry(props, (void *)"key2");
char* value = (char*) hashMapEntry_getValue(entry);
const char* value = celix_properties_get(props, "key2", "");
EXPECT_STREQ("inaetics", value);
}
printf("End: %s\n", __func__);
Expand Down
6 changes: 2 additions & 4 deletions bundles/shell/shell/src/query_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ static void queryCommand_callback(void *handle, const celix_bundle_t *bnd) {
if (data->opts->verbose) {
fprintf(data->sout, " |- Is factory: %s\n", entry->factory ? "true" : "false");
fprintf(data->sout, " |- Properties:\n");
const char *key;
CELIX_PROPERTIES_FOR_EACH(entry->serviceProperties, key) {
const char *val = celix_properties_get(entry->serviceProperties, key, "!ERROR!");
fprintf(data->sout, " |- %20s = %s\n", key, val);
CELIX_PROPERTIES_ITERATE(entry->serviceProperties, iter) {
fprintf(data->sout, " |- %20s = %s\n", iter.key, iter.entry.value);
}
}
}
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
7 changes: 2 additions & 5 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 Expand Up @@ -210,7 +208,6 @@ inline celix::dm::DependencyManagerInfo DependencyManager::getInfo() const {
}
}


inline std::vector<celix::dm::DependencyManagerInfo> DependencyManager::getInfos() const {
std::vector<celix::dm::DependencyManagerInfo> result{};
auto* cInfos = celix_dependencyManager_createInfos(cDependencyManager());
Expand Down
Loading

0 comments on commit 1856ced

Please sign in to comment.