Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/509 remove cpputests #711

Merged
merged 21 commits into from
Jan 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8af7bff
Remove cpputest config, cpputest usage and linked list
pnoltes Dec 23, 2023
6a4d2a9
Remove cpputest from build config
pnoltes Dec 23, 2023
577551e
Remove cpputests for array and linked list
pnoltes Dec 23, 2023
daa0060
Remove deprecated array_list and its usage
pnoltes Dec 23, 2023
5d97401
Refactor hash_map cpputests to gtests
pnoltes Dec 30, 2023
d1f7d10
Refactor ip utils and ip utils tests
pnoltes Dec 30, 2023
bcfb6b2
Merge branch 'master' into feature/509-remove-cpputests
pnoltes Dec 30, 2023
8d113a3
Remove cpputest from build config
pnoltes Dec 30, 2023
01b3af1
Improve error handling of IP utils
pnoltes Dec 30, 2023
61c641a
Replace array_list with celix_array_list in rsa shm v2
pnoltes Dec 30, 2023
a851bf9
Replace array_list with celix_array_list in conan exmpl test
pnoltes Dec 30, 2023
f2317ed
Separate celix err ei test to prevent unintentionally init of tss
pnoltes Dec 31, 2023
4bb8990
Fix memleak in celix_utils_findIpInSubnet when calling getifaddrs
pnoltes Dec 31, 2023
1f8dea8
Fix invalid snprintf
pnoltes Dec 31, 2023
1a67dab
Replace EXPECT_EQ for pointer compare
pnoltes Dec 31, 2023
4de66c3
Merge branch 'master' into feature/509-remove-cpputests
pnoltes Jan 4, 2024
b4b26a3
Remove ip utils
pnoltes Jan 4, 2024
7a9bae9
Remove unused linked_list source files
pnoltes Jan 4, 2024
cd8bfd5
Refactor endpointDiscoveryPoller_poll for indent and error handling
pnoltes Jan 4, 2024
36d8c40
Remove unneeded export macros in hash_map_private.h
pnoltes Jan 4, 2024
2e2805b
Merge branch 'master' into feature/509-remove-cpputests
pnoltes Jan 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor endpointDiscoveryPoller_poll for indent and error handling
pnoltes committed Jan 4, 2024
commit cd8bfd54d6ca8cd022d98907d3750f7ae6e4e093
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
#include "celix_log_helper.h"
#include "celix_threads.h"
#include "hash_map.h"
#include "celix_array_list.h"

typedef struct endpoint_discovery_poller endpoint_discovery_poller_t;

Original file line number Diff line number Diff line change
@@ -252,89 +252,84 @@ celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discover

celix_status_t
endpointDiscoveryPoller_poll(endpoint_discovery_poller_t* poller, char* url, celix_array_list_t* currentEndpoints) {
celix_status_t status;
celix_array_list_t* updatedEndpoints = NULL;

// create an arraylist with a custom equality test to ensure we can find endpoints properly...
updatedEndpoints = celix_arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals);
status = endpointDiscoveryPoller_getEndpoints(poller, url, &updatedEndpoints);
celix_array_list_t* updatedEndpoints = celix_arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals);
if (!updatedEndpoints) {
return CELIX_ENOMEM;
}

if (updatedEndpoints && status == CELIX_SUCCESS) {
if (updatedEndpoints != NULL) {
for (int i = celix_arrayList_size(currentEndpoints); i > 0; i--) {
endpoint_description_t* endpoint = celix_arrayList_get(currentEndpoints, i - 1);
celix_status_t status = endpointDiscoveryPoller_getEndpoints(poller, url, &updatedEndpoints);
if (status == CELIX_SUCCESS) {
for (int i = celix_arrayList_size(currentEndpoints); i > 0; i--) {
endpoint_description_t* endpoint = celix_arrayList_get(currentEndpoints, i - 1);

celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
entry.voidPtrVal = endpoint;
celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
entry.voidPtrVal = endpoint;

if (celix_arrayList_indexOf(updatedEndpoints, entry) < 0) {
status = discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
celix_arrayList_removeAt(currentEndpoints, i - 1);
endpointDescription_destroy(endpoint);
}
if (celix_arrayList_indexOf(updatedEndpoints, entry) < 0) {
status = discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
celix_arrayList_removeAt(currentEndpoints, i - 1);
endpointDescription_destroy(endpoint);
}
}

for (int i = 0; i < celix_arrayList_size(updatedEndpoints); i++) {
endpoint_description_t* endpoint = celix_arrayList_get(updatedEndpoints, i);
celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
entry.voidPtrVal = endpoint;
if (celix_arrayList_indexOf(currentEndpoints, entry) < 0) {
celix_arrayList_add(currentEndpoints, endpoint);
status = discovery_addDiscoveredEndpoint(poller->discovery, endpoint);
} else {
endpointDescription_destroy(endpoint);
}
for (int i = 0; i < celix_arrayList_size(updatedEndpoints); i++) {
endpoint_description_t* endpoint = celix_arrayList_get(updatedEndpoints, i);
celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
entry.voidPtrVal = endpoint;
if (celix_arrayList_indexOf(currentEndpoints, entry) < 0) {
celix_arrayList_add(currentEndpoints, endpoint);
status = discovery_addDiscoveredEndpoint(poller->discovery, endpoint);
} else {
endpointDescription_destroy(endpoint);
}
celix_arrayList_clear(updatedEndpoints);
}
}

if (updatedEndpoints != NULL) {
if (updatedEndpoints) {
celix_arrayList_destroy(updatedEndpoints);
}

return status;
}

static void *endpointDiscoveryPoller_performPeriodicPoll(void *data) {
endpoint_discovery_poller_t *poller = (endpoint_discovery_poller_t *) data;
static void* endpointDiscoveryPoller_performPeriodicPoll(void* data) {
endpoint_discovery_poller_t* poller = (endpoint_discovery_poller_t*)data;

useconds_t interval = (useconds_t) (poller->poll_interval * 1000000L);
useconds_t interval = (useconds_t)(poller->poll_interval * 1000000L);

while (poller->running) {
usleep(interval);
celix_status_t status = celixThreadMutex_lock(&poller->pollerLock);
while (poller->running) {
usleep(interval);
celix_status_t status = celixThreadMutex_lock(&poller->pollerLock);

if (status != CELIX_SUCCESS) {
if (status != CELIX_SUCCESS) {
celix_logHelper_warning(*poller->loghelper, "ENDPOINT_POLLER: failed to obtain lock; retrying...");
} else {
hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
} else {
hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);

while (hashMapIterator_hasNext(iterator)) {
hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
while (hashMapIterator_hasNext(iterator)) {
hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);

char *url = hashMapEntry_getKey(entry);
celix_array_list_t* currentEndpoints = hashMapEntry_getValue(entry);
char* url = hashMapEntry_getKey(entry);
celix_array_list_t* currentEndpoints = hashMapEntry_getValue(entry);

endpointDiscoveryPoller_poll(poller, url, currentEndpoints);
}
endpointDiscoveryPoller_poll(poller, url, currentEndpoints);
}

hashMapIterator_destroy(iterator);
}
hashMapIterator_destroy(iterator);
}

status = celixThreadMutex_unlock(&poller->pollerLock);
if (status != CELIX_SUCCESS) {
status = celixThreadMutex_unlock(&poller->pollerLock);
if (status != CELIX_SUCCESS) {
celix_logHelper_warning(*poller->loghelper, "ENDPOINT_POLLER: failed to release lock; retrying...");
}
}
}
}

return NULL;
return NULL;
}



struct MemoryStruct {
char *memory;
size_t size;