(celix) 03/04: #674 Add initial element type support for array list
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/674-add-element-type-to-array-list in repository https://gitbox.apache.org/repos/asf/celix.git commit 21f379de8a0ef8923e64453b851747add74ebdc6 Author: Pepijn Noltes AuthorDate: Sun Feb 4 19:07:44 2024 +0100 #674 Add initial element type support for array list --- bundles/logging/log_admin/src/celix_log_admin.c | 14 +- libs/utils/gtest/src/ArrayListTestSuite.cc | 2 +- libs/utils/include/celix_array_list.h | 453 --- libs/utils/src/array_list.c | 465 libs/utils/src/array_list_private.h | 41 --- 5 files changed, 813 insertions(+), 162 deletions(-) diff --git a/bundles/logging/log_admin/src/celix_log_admin.c b/bundles/logging/log_admin/src/celix_log_admin.c index 5b983ef1..6b1be0f5 100644 --- a/bundles/logging/log_admin/src/celix_log_admin.c +++ b/bundles/logging/log_admin/src/celix_log_admin.c @@ -429,12 +429,12 @@ 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(>lock); hash_map_iterator_t iter = hashMapIterator_construct(admin->loggers); while (hashMapIterator_hasNext()) { celix_log_service_entry_t* visit = hashMapIterator_nextValue(); -celix_arrayList_add(loggers, celix_utils_strdup(visit->name)); +celix_arrayList_addString(loggers, visit->name); } celixThreadRwlock_unlock(>lock); return loggers; @@ -442,12 +442,12 @@ static celix_array_list_t* celix_logAdmin_currentLogServices(void *handle) { 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(>lock); hash_map_iterator_t iter = hashMapIterator_construct(admin->sinks); while (hashMapIterator_hasNext()) { celix_log_sink_entry_t* entry = hashMapIterator_nextValue(); -celix_arrayList_add(sinks, celix_utils_strdup(entry->name)); +celix_arrayList_addString(sinks, entry->name); } celixThreadRwlock_unlock(>lock); return sinks; @@ -539,8 +539,8 @@ 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) { @@ -552,7 +552,6 @@ static void celix_logAdmin_InfoCmd(celix_log_admin_t* admin, FILE* outStream, FI 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); @@ -565,7 +564,6 @@ static void celix_logAdmin_InfoCmd(celix_log_admin_t* admin, FILE* outStream, FI 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"); diff --git a/libs/utils/gtest/src/ArrayListTestSuite.cc b/libs/utils/gtest/src/ArrayListTestSuite.cc index 5a0e60c3..488f069f 100644 --- a/libs/utils/gtest/src/ArrayListTestSuite.cc +++ b/libs/utils/gtest/src/ArrayListTestSuite.cc @@ -219,7 +219,7 @@ TEST_F(ArrayListTestSuite, TestSortForArrayList) { EXPECT_EQ(celix_arrayList_getInt(list, 3), 4); -celix_array_list_sort_entries_fp sort = [](celix_array_list_entry_t a, celix_array_list_entry_t b) -> int { +celix_array_list_compare_entries_fp sort = [](celix_array_list_entry_t a, celix_array_list_entry_t b) -> int { return a.intVal - b.intVal; }; celix_arrayList_sortEntries(list, sort); diff --git a/libs/utils/include/celix_array_list.h b/libs/utils/include/celix_array_list.h index b38772b8..25925c89 100644 --- a/libs/utils/include/celix_array_list.h +++ b/libs/utils/include/celix_array_list.h @@ -22,6 +22,7 @@ #include "celix_cleanup.h" #include "celix_errno.h" #include "celix_utils_export.h"
(celix) 02/04: #674 Refactor array list compare in ctx, reg and rsa
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/674-add-element-type-to-array-list in repository https://gitbox.apache.org/repos/asf/celix.git commit ba42e664ca5eff9e43a2d0df1400538161cac2d7 Author: Pepijn Noltes AuthorDate: Sun Feb 4 19:07:24 2024 +0100 #674 Refactor array list compare in ctx, reg and rsa --- .../discovery_common/src/endpoint_discovery_poller.c | 8 ++-- .../rsa_common/src/remote_interceptors_handler.c | 10 +- libs/framework/include_deprecated/service_registry.h | 2 +- libs/framework/src/bundle_context.c| 4 ++-- libs/framework/src/service_registry.c | 10 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/bundles/remote_services/discovery_common/src/endpoint_discovery_poller.c b/bundles/remote_services/discovery_common/src/endpoint_discovery_poller.c index edf560fc..567ff84b 100644 --- a/bundles/remote_services/discovery_common/src/endpoint_discovery_poller.c +++ b/bundles/remote_services/discovery_common/src/endpoint_discovery_poller.c @@ -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(); if (endpoints) { celix_logHelper_debug(*poller->loghelper, "ENDPOINT_POLLER: add new discovery endpoint with url %s", url); @@ -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(); if (!updatedEndpoints) { return CELIX_ENOMEM; } diff --git a/bundles/remote_services/rsa_common/src/remote_interceptors_handler.c b/bundles/remote_services/rsa_common/src/remote_interceptors_handler.c index 65c25207..591e7322 100644 --- a/bundles/remote_services/rsa_common/src/remote_interceptors_handler.c +++ b/bundles/remote_services/rsa_common/src/remote_interceptors_handler.c @@ -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); @@ -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(>lock); @@ -197,9 +197,9 @@ void remoteInterceptorHandler_invokePostProxyCall(remote_interceptors_handler_t celixThreadMutex_unlock(>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); diff --git a/libs/framework/include_deprecated/service_registry.h b/libs/framework/include_deprecated/service_registry.h index 84a55104..7cdb785d 100644 --- a/libs/framework/include_deprecated/service_registry.h +++ b/libs/framework/include_deprecated/service_registry.h @@ -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
(celix) branch feature/674-add-element-type-to-array-list created (now f0ff9d94)
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a change to branch feature/674-add-element-type-to-array-list in repository https://gitbox.apache.org/repos/asf/celix.git at f0ff9d94 #674 Add array list element type testing This branch includes the following new commits: new b4df54cc #674 Fix in push stream for gcc 13 new ba42e664 #674 Refactor array list compare in ctx, reg and rsa new 21f379de #674 Add initial element type support for array list new f0ff9d94 #674 Add array list element type testing The 4 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
(celix) 01/04: #674 Fix in push stream for gcc 13
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/674-add-element-type-to-array-list in repository https://gitbox.apache.org/repos/asf/celix.git commit b4df54cc4626309d11b6e4337f9581d35c07dfac Author: Pepijn Noltes AuthorDate: Sun Feb 4 19:05:47 2024 +0100 #674 Fix in push stream for gcc 13 --- libs/pushstreams/api/celix/impl/BufferedPushStream.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/pushstreams/api/celix/impl/BufferedPushStream.h b/libs/pushstreams/api/celix/impl/BufferedPushStream.h index 5172f42e..6a2d1e6f 100644 --- a/libs/pushstreams/api/celix/impl/BufferedPushStream.h +++ b/libs/pushstreams/api/celix/impl/BufferedPushStream.h @@ -98,10 +98,10 @@ void celix::BufferedPushStream::startWorker() { std::weak_ptr>>> weak{queue}; auto lk = weak.lock(); if (lk) { -std::unique_ptr> event = std::move(popQueue()); +std::unique_ptr> event = popQueue(); while (event != nullptr) { this->nextEvent.accept(*event); -event = std::move(popQueue()); +event = popQueue(); } cv.notify_all(); }
(celix) 04/04: #674 Add array list element type testing
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/674-add-element-type-to-array-list in repository https://gitbox.apache.org/repos/asf/celix.git commit f0ff9d94eb83ba3589e644988c338086db251b18 Author: Pepijn Noltes AuthorDate: Sun Feb 4 23:32:00 2024 +0100 #674 Add array list element type testing --- .../log_admin/gtest/src/LogAdminTestSuite.cc | 8 - bundles/logging/log_admin/src/celix_log_admin.c| 4 +- .../log_service_api/include/celix_log_control.h| 12 + libs/utils/gtest/CMakeLists.txt| 2 +- libs/utils/gtest/src/ArrayListTestSuite.cc | 351 - libs/utils/include/celix_array_list.h | 10 +- libs/utils/src/array_list.c| 40 ++- 7 files changed, 330 insertions(+), 97 deletions(-) diff --git a/bundles/logging/log_admin/gtest/src/LogAdminTestSuite.cc b/bundles/logging/log_admin/gtest/src/LogAdminTestSuite.cc index 859a24a7..fe11a78f 100644 --- a/bundles/logging/log_admin/gtest/src/LogAdminTestSuite.cc +++ b/bundles/logging/log_admin/gtest/src/LogAdminTestSuite.cc @@ -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); @@ -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); diff --git a/bundles/logging/log_admin/src/celix_log_admin.c b/bundles/logging/log_admin/src/celix_log_admin.c index 6b1be0f5..5ed38d53 100644 --- a/bundles/logging/log_admin/src/celix_log_admin.c +++ b/bundles/logging/log_admin/src/celix_log_admin.c @@ -544,7 +544,7 @@ static void celix_logAdmin_InfoCmd(celix_log_admin_t* admin, FILE* outStream, FI 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, , ); @@ -558,7 +558,7 @@ static void celix_logAdmin_InfoCmd(celix_log_admin_t* admin, FILE* outStream, FI 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, ); if (found) { diff --git a/bundles/logging/log_service_api/include/celix_log_control.h b/bundles/logging/log_service_api/include/celix_log_control.h index 5f3d82f3..98c9a31d 100644 --- a/bundles/logging/log_service_api/include/celix_log_control.h +++ b/bundles/logging/log_service_api/include/celix_log_control.h @@ -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); diff --git a/libs/utils/gtest/CMakeLists.txt b/libs/utils/gtest/CMakeLists.txt index e1e22ef7..db39b903 100644 --- a/libs/utils/gtest/CMakeLists.txt +++ b/libs/utils/gtest/CMakeLists.txt @@ -34,6 +34,7 @@ add_executable(test_utils src/ThreadsTestSuite.cc src/CelixErrnoTestSuite.cc src/CelixUtilsAutoCleanupTestSuite.cc +src/ArrayListTestSuite.cc src/DeprecatedHashmapTestSuite.cc ) @@ -45,7 +46,6 @@ configure_file(resources/properties.txt ${CMAKE_CURRENT_BINARY_DIR}/resources-te if (CELIX_CXX17)