Skip to content

Commit

Permalink
Merge pull request #727 from apache/feature/674-add-element-type-to-a…
Browse files Browse the repository at this point in the history
…rray-list
  • Loading branch information
pnoltes authored Feb 26, 2024
2 parents 423abb8 + 9ae479e commit e6dc3ca
Show file tree
Hide file tree
Showing 21 changed files with 1,213 additions and 549 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ limitations under the License.
- linked_list.h is removed and no longer supported. Use celix_array_list.h instead.
- ip_utils.h is removed and no longer supported.
- array_list.h is removed and no longer supported. Use celix_array_list.h instead.
- the celix_arrayList_add function no longer accepts a NULL value.
- version.h and version_range.h are removed and no longer supported. Use celix_version.h and celix_version_range.h
instead.

Expand Down
8 changes: 0 additions & 8 deletions bundles/logging/log_admin/gtest/src/LogAdminTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ TEST_F(LogBundleTestSuite, SinkLogControl) {

auto *list = control->currentSinks(control->handle);
EXPECT_EQ(3, celix_arrayList_size(list));
for (int i = 0; i < celix_arrayList_size(list); ++i) {
auto *item = celix_arrayList_get(list, i);
free(item);
}
celix_arrayList_destroy(list);


Expand Down Expand Up @@ -277,10 +273,6 @@ TEST_F(LogBundleTestSuite, LogServiceControl) {

auto *list = control->currentLogServices(control->handle);
EXPECT_EQ(4, celix_arrayList_size(list));
for (int i = 0; i < celix_arrayList_size(list); ++i) {
auto *item = celix_arrayList_get(list, i);
free(item);
}
celix_arrayList_destroy(list);

celix_bundleContext_stopTracker(ctx.get(), trkId1);
Expand Down
18 changes: 8 additions & 10 deletions bundles/logging/log_admin/src/celix_log_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,25 +429,25 @@ static size_t celix_logAdmin_setSinkEnabled(void *handle, const char* select, bo

static celix_array_list_t* celix_logAdmin_currentLogServices(void *handle) {
celix_log_admin_t* admin = handle;
celix_array_list_t* loggers = celix_arrayList_create();
celix_array_list_t* loggers = celix_arrayList_createStringArray();
celixThreadRwlock_readLock(&admin->lock);
hash_map_iterator_t iter = hashMapIterator_construct(admin->loggers);
while (hashMapIterator_hasNext(&iter)) {
celix_log_service_entry_t* visit = hashMapIterator_nextValue(&iter);
celix_arrayList_add(loggers, celix_utils_strdup(visit->name));
celix_arrayList_addString(loggers, visit->name);
}
celixThreadRwlock_unlock(&admin->lock);
return loggers;
}

static celix_array_list_t* celix_logAdmin_currentSinks(void *handle) {
celix_log_admin_t* admin = handle;
celix_array_list_t* sinks = celix_arrayList_create();
celix_array_list_t* sinks = celix_arrayList_createStringArray();
celixThreadRwlock_readLock(&admin->lock);
hash_map_iterator_t iter = hashMapIterator_construct(admin->sinks);
while (hashMapIterator_hasNext(&iter)) {
celix_log_sink_entry_t* entry = hashMapIterator_nextValue(&iter);
celix_arrayList_add(sinks, celix_utils_strdup(entry->name));
celix_arrayList_addString(sinks, entry->name);
}
celixThreadRwlock_unlock(&admin->lock);
return sinks;
Expand Down Expand Up @@ -539,33 +539,31 @@ static void celix_logAdmin_setSinkEnabledCmd(celix_log_admin_t* admin, const cha
static void celix_logAdmin_InfoCmd(celix_log_admin_t* admin, FILE* outStream, FILE* errorStream CELIX_UNUSED) {
celix_array_list_t* logServices = celix_logAdmin_currentLogServices(admin);
celix_array_list_t* sinks = celix_logAdmin_currentSinks(admin);
celix_arrayList_sort(logServices, (void*)strcmp);
celix_arrayList_sort(sinks, (void*)strcmp);
celix_arrayList_sort(logServices);
celix_arrayList_sort(sinks);

fprintf(outStream, "Log Admin provided log services:\n");
for (int i = 0 ; i < celix_arrayList_size(logServices); ++i) {
char *name = celix_arrayList_get(logServices, i);
const char *name = celix_arrayList_getString(logServices, i);
celix_log_level_e level;
bool detailed;
bool found = celix_logAdmin_logServiceInfoEx(admin, name, &level, &detailed);
if (found) {
fprintf(outStream, " |- %i) Log Service %20s, active log level %s, %s\n",
i+1, name, celix_logUtils_logLevelToString(level), detailed ? "detailed" : "brief");
}
free(name);
}
celix_arrayList_destroy(logServices);

if (celix_arrayList_size(sinks) > 0) {
fprintf(outStream, "Log Admin found log sinks:\n");
for (int i = 0 ; i < celix_arrayList_size(sinks); ++i) {
char *name = celix_arrayList_get(sinks, i);
const char *name = celix_arrayList_getString(sinks, i);
bool enabled;
bool found = celix_logAdmin_sinkInfo(admin, name, &enabled);
if (found) {
fprintf(outStream, " |- %i) Log Sink %20s, %s\n", i+1, name, enabled ? "enabled" : "disabled");
}
free(name);
}
} else {
fprintf(outStream, "Log Admin has found 0 log sinks\n");
Expand Down
12 changes: 12 additions & 0 deletions bundles/logging/log_service_api/include/celix_log_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,20 @@ typedef struct celix_log_control {

size_t (*setSinkEnabled)(void *handle, const char* select, bool enabled);

/**
* @brief Get a list of names for the log service provided by the log service.
* @param handle The service handle.
* @return A string array list.
* The array list is owned by the caller and should be destroyed by calling celix_arrayList_destroy.
*/
celix_array_list_t* (*currentLogServices)(void *handle);

/**
* @brief Get a list of sinks names used by the log service.
* @param handle The service handle.
* @return A string array list.
* The array list is owned by the caller and should be destroyed by calling celix_arrayList_destroy.
*/
celix_array_list_t* (*currentSinks)(void *handle);

bool (*logServiceInfo)(void *handle, const char* loggerName, celix_log_level_e* outActiveLogLevel);
Expand Down
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
4 changes: 2 additions & 2 deletions libs/pushstreams/api/celix/impl/BufferedPushStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ void celix::BufferedPushStream<T>::startWorker() {
std::weak_ptr<std::queue<std::unique_ptr<PushEvent<T>>>> weak{queue};
auto lk = weak.lock();
if (lk) {
std::unique_ptr<celix::PushEvent<T>> event = std::move(popQueue());
std::unique_ptr<celix::PushEvent<T>> event = popQueue();
while (event != nullptr) {
this->nextEvent.accept(*event);
event = std::move(popQueue());
event = popQueue();
}
cv.notify_all();
}
Expand Down
7 changes: 3 additions & 4 deletions libs/utils/error_injector/celix_array_list/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ target_link_libraries(array_list_ei PUBLIC Celix::error_injector Celix::utils)
target_link_options(array_list_ei INTERFACE
LINKER:--wrap,celix_arrayList_create
LINKER:--wrap,celix_arrayList_createWithOptions
LINKER:--wrap,celix_arrayList_createStringArray
LINKER:--wrap,celix_arrayList_add
LINKER:--wrap,celix_arrayList_addInt
LINKER:--wrap,celix_arrayList_addLong
LINKER:--wrap,celix_arrayList_addUInt
LINKER:--wrap,celix_arrayList_addULong
LINKER:--wrap,celix_arrayList_addFloat
LINKER:--wrap,celix_arrayList_addDouble
LINKER:--wrap,celix_arrayList_addBool
LINKER:--wrap,celix_arrayList_addSize
LINKER:--wrap,celix_arrayList_addString
LINKER:--wrap,celix_arrayList_assignString
)
add_library(Celix::array_list_ei ALIAS array_list_ei)
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,20 @@ CELIX_EI_DECLARE(celix_arrayList_create, celix_array_list_t*);

CELIX_EI_DECLARE(celix_arrayList_createWithOptions, celix_array_list_t*);

CELIX_EI_DECLARE(celix_arrayList_add, celix_status_t);
CELIX_EI_DECLARE(celix_arrayList_createStringArray, celix_array_list_t*);

CELIX_EI_DECLARE(celix_arrayList_addInt, celix_status_t);
CELIX_EI_DECLARE(celix_arrayList_add, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addLong, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addUInt, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addULong, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addFloat, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addDouble, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addBool, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addSize, celix_status_t);
CELIX_EI_DECLARE(celix_arrayList_addString, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_assignString, celix_status_t);


#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "celix_array_list_ei.h"
#include "celix_stdlib_cleanup.h"

extern "C" {

Expand All @@ -35,48 +36,27 @@ void *__wrap_celix_arrayList_createWithOptions(const celix_array_list_create_opt
return __real_celix_arrayList_createWithOptions(opts);
}

void *__real_celix_arrayList_createStringArray();
CELIX_EI_DEFINE(celix_arrayList_createStringArray, celix_array_list_t*)
void *__wrap_celix_arrayList_createStringArray() {
CELIX_EI_IMPL(celix_arrayList_createStringArray);
return __real_celix_arrayList_createStringArray();
}

celix_status_t __real_celix_arrayList_add(celix_array_list_t* list, void* value);
CELIX_EI_DEFINE(celix_arrayList_add, celix_status_t)
celix_status_t __wrap_celix_arrayList_add(celix_array_list_t* list, void* value) {
CELIX_EI_IMPL(celix_arrayList_add);
return __real_celix_arrayList_add(list, value);
}

celix_status_t __real_celix_arrayList_addInt(celix_array_list_t* list, int value);
CELIX_EI_DEFINE(celix_arrayList_addInt, celix_status_t)
celix_status_t __wrap_celix_arrayList_addInt(celix_array_list_t* list, int value) {
CELIX_EI_IMPL(celix_arrayList_addInt);
return __real_celix_arrayList_addInt(list, value);
}

celix_status_t __real_celix_arrayList_addLong(celix_array_list_t* list, long value);
CELIX_EI_DEFINE(celix_arrayList_addLong, celix_status_t)
celix_status_t __wrap_celix_arrayList_addLong(celix_array_list_t* list, long value) {
CELIX_EI_IMPL(celix_arrayList_addLong);
return __real_celix_arrayList_addLong(list, value);
}

celix_status_t __real_celix_arrayList_addUInt(celix_array_list_t* list, unsigned int value);
CELIX_EI_DEFINE(celix_arrayList_addUInt, celix_status_t)
celix_status_t __wrap_celix_arrayList_addUInt(celix_array_list_t* list, unsigned int value) {
CELIX_EI_IMPL(celix_arrayList_addUInt);
return __real_celix_arrayList_addUInt(list, value);
}

celix_status_t __real_celix_arrayList_addULong(celix_array_list_t* list, unsigned long value);
CELIX_EI_DEFINE(celix_arrayList_addULong, celix_status_t)
celix_status_t __wrap_celix_arrayList_addULong(celix_array_list_t* list, unsigned long value) {
CELIX_EI_IMPL(celix_arrayList_addULong);
return __real_celix_arrayList_addULong(list, value);
}

celix_status_t __real_celix_arrayList_addFloat(celix_array_list_t* list, float value);
CELIX_EI_DEFINE(celix_arrayList_addFloat, celix_status_t)
celix_status_t __wrap_celix_arrayList_addFloat(celix_array_list_t* list, float value) {
CELIX_EI_IMPL(celix_arrayList_addFloat);
return __real_celix_arrayList_addFloat(list, value);
}

celix_status_t __real_celix_arrayList_addDouble(celix_array_list_t* list, double value);
CELIX_EI_DEFINE(celix_arrayList_addDouble, celix_status_t)
celix_status_t __wrap_celix_arrayList_addDouble(celix_array_list_t* list, double value) {
Expand All @@ -91,11 +71,20 @@ celix_status_t __wrap_celix_arrayList_addBool(celix_array_list_t* list, bool val
return __real_celix_arrayList_addBool(list, value);
}

celix_status_t __real_celix_arrayList_addSize(celix_array_list_t* list, size_t value);
CELIX_EI_DEFINE(celix_arrayList_addSize, celix_status_t)
celix_status_t __wrap_celix_arrayList_addSize(celix_array_list_t* list, size_t value) {
CELIX_EI_IMPL(celix_arrayList_addSize);
return __real_celix_arrayList_addSize(list, value);
celix_status_t __real_celix_arrayList_addString(celix_array_list_t* list, const char* value);
CELIX_EI_DEFINE(celix_arrayList_addString, celix_status_t)
celix_status_t __wrap_celix_arrayList_addString(celix_array_list_t* list, const char* value) {
CELIX_EI_IMPL(celix_arrayList_addString);
return __real_celix_arrayList_addString(list, value);
}

celix_status_t __real_celix_arrayList_assignString(celix_array_list_t* list, char* value);
CELIX_EI_DEFINE(celix_arrayList_assignString, celix_status_t)
celix_status_t __wrap_celix_arrayList_assignString(celix_array_list_t* list, char* value) {
celix_autofree char* tmp = value; //ensure that the value is freed when an error is injected
CELIX_EI_IMPL(celix_arrayList_assignString);
celix_steal_ptr(tmp);
return __real_celix_arrayList_assignString(list, value);
}

}
Loading

0 comments on commit e6dc3ca

Please sign in to comment.