Skip to content

Commit

Permalink
#674 Refactor array list compare in ctx, reg and rsa
Browse files Browse the repository at this point in the history
  • Loading branch information
pnoltes committed Feb 4, 2024
1 parent b4df54c commit ba42e66
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_p
// Avoid memory leaks when adding an already existing URL...
celix_array_list_t* endpoints = hashMap_get(poller->entries, url);
if (endpoints == NULL) {
endpoints = celix_arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals);
celix_array_list_create_options_t opts = CELIX_EMPTY_ARRAY_LIST_CREATE_OPTIONS;
opts.equalsCallback = endpointDiscoveryPoller_endpointDescriptionEquals;
endpoints = celix_arrayList_createWithOptions(&opts);

if (endpoints) {
celix_logHelper_debug(*poller->loghelper, "ENDPOINT_POLLER: add new discovery endpoint with url %s", url);
Expand Down Expand Up @@ -253,7 +255,9 @@ celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discover
celix_status_t
endpointDiscoveryPoller_poll(endpoint_discovery_poller_t* poller, char* url, celix_array_list_t* currentEndpoints) {
// create an arraylist with a custom equality test to ensure we can find endpoints properly...
celix_array_list_t* updatedEndpoints = celix_arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals);
celix_array_list_create_options_t opts = CELIX_EMPTY_ARRAY_LIST_CREATE_OPTIONS;
opts.equalsCallback = endpointDiscoveryPoller_endpointDescriptionEquals;
celix_array_list_t* updatedEndpoints = celix_arrayList_createWithOptions(&opts);
if (!updatedEndpoints) {
return CELIX_ENOMEM;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct remote_interceptors_handler {
celix_thread_mutex_t lock;
};

static int referenceCompare(const void *a, const void *b);
static int referenceCompare(celix_array_list_entry_t a, celix_array_list_entry_t b);

static void remoteInterceptorsHandler_addInterceptor(void *handle, void *svc, const celix_properties_t *props);
static void remoteInterceptorsHandler_removeInterceptor(void *handle, void *svc, const celix_properties_t *props);
Expand Down Expand Up @@ -104,7 +104,7 @@ void remoteInterceptorsHandler_addInterceptor(void *handle, void *svc, const cel
entry->interceptor = svc;
celix_arrayList_add(handler->interceptors, entry);

celix_arrayList_sort(handler->interceptors, referenceCompare);
celix_arrayList_sortEntries(handler->interceptors, referenceCompare);
}

celixThreadMutex_unlock(&handler->lock);
Expand Down Expand Up @@ -197,9 +197,9 @@ void remoteInterceptorHandler_invokePostProxyCall(remote_interceptors_handler_t
celixThreadMutex_unlock(&handler->lock);
}

int referenceCompare(const void *a, const void *b) {
const entry_t *aEntry = a;
const entry_t *bEntry = b;
int referenceCompare(celix_array_list_entry_t a, celix_array_list_entry_t b) {
const entry_t *aEntry = a.voidPtrVal;
const entry_t *bEntry = b.voidPtrVal;

long servIdA = celix_properties_getAsLong(aEntry->properties, CELIX_FRAMEWORK_SERVICE_ID, 0);
long servIdB = celix_properties_getAsLong(bEntry->properties, CELIX_FRAMEWORK_SERVICE_ID, 0);
Expand Down
2 changes: 1 addition & 1 deletion libs/framework/include_deprecated/service_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ CELIX_FRAMEWORK_EXPORT char* celix_serviceRegistry_createFilterFor(
* Find services and return a array list of service ids (long).
* Caller is responsible for freeing the returned array list.
*/
CELIX_FRAMEWORK_EXPORT celix_array_list_t* celix_serviceRegisrty_findServices(celix_service_registry_t* registry, const char* filter);
CELIX_FRAMEWORK_EXPORT celix_array_list_t* celix_serviceRegistry_findServices(celix_service_registry_t* registry, const char* filterStr);


#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions libs/framework/src/bundle_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ long celix_bundleContext_findServiceWithOptions(celix_bundle_context_t *ctx, con
long result = -1L;
char* filter = celix_serviceRegistry_createFilterFor(ctx->framework->registry, opts->serviceName, opts->versionRange, opts->filter);
if (filter != NULL) {
celix_array_list_t *svcIds = celix_serviceRegisrty_findServices(ctx->framework->registry, filter);
celix_array_list_t *svcIds = celix_serviceRegistry_findServices(ctx->framework->registry, filter);
if (svcIds != NULL && celix_arrayList_size(svcIds) > 0) {
result = celix_arrayList_getLong(svcIds, 0);
}
Expand All @@ -1388,7 +1388,7 @@ celix_array_list_t* celix_bundleContext_findServicesWithOptions(celix_bundle_con
celix_array_list_t* result = NULL;
char* filter = celix_serviceRegistry_createFilterFor(ctx->framework->registry, opts->serviceName, opts->versionRange, opts->filter);
if (filter != NULL) {
result = celix_serviceRegisrty_findServices(ctx->framework->registry, filter);
result = celix_serviceRegistry_findServices(ctx->framework->registry, filter);
free(filter);
}
return result;
Expand Down
10 changes: 5 additions & 5 deletions libs/framework/src/service_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,9 @@ char* celix_serviceRegistry_createFilterFor(celix_service_registry_t* registry,
return filter;
}

static int celix_serviceRegistry_compareRegistrations(const void *a, const void *b) {
const service_registration_t* regA = a;
const service_registration_t* regB = b;
static int celix_serviceRegistry_compareRegistrations(celix_array_list_entry_t a, celix_array_list_entry_t b) {
const service_registration_t* regA = a.voidPtrVal;
const service_registration_t* regB = b.voidPtrVal;

celix_properties_t* propsA = NULL;
celix_properties_t* propsB = NULL;
Expand All @@ -861,7 +861,7 @@ static int celix_serviceRegistry_compareRegistrations(const void *a, const void
return celix_utils_compareServiceIdsAndRanking(servIdA, servRankingA, servIdB, servRankingB);
}

celix_array_list_t* celix_serviceRegisrty_findServices(
celix_array_list_t* celix_serviceRegistry_findServices(
celix_service_registry_t* registry,
const char* filterStr) {

Expand Down Expand Up @@ -892,7 +892,7 @@ celix_array_list_t* celix_serviceRegisrty_findServices(

//sort matched registration and add the svc id to the result list.
if (celix_arrayList_size(matchedRegistrations) > 1) {
celix_arrayList_sort(matchedRegistrations, celix_serviceRegistry_compareRegistrations);
celix_arrayList_sortEntries(matchedRegistrations, celix_serviceRegistry_compareRegistrations);
}
for (int i = 0; i < celix_arrayList_size(matchedRegistrations); ++i) {
service_registration_t* reg = celix_arrayList_get(matchedRegistrations, i);
Expand Down

0 comments on commit ba42e66

Please sign in to comment.