diff --git a/bundles/http_admin/http_admin/CMakeLists.txt b/bundles/http_admin/http_admin/CMakeLists.txt index cb0bd29ef..931d3ffc4 100644 --- a/bundles/http_admin/http_admin/CMakeLists.txt +++ b/bundles/http_admin/http_admin/CMakeLists.txt @@ -31,9 +31,6 @@ target_include_directories(http_admin PRIVATE src) target_link_libraries(http_admin PUBLIC Celix::http_admin_api) -celix_deprecated_utils_headers(http_admin) - - install_celix_bundle(http_admin EXPORT celix COMPONENT http_admin) #Setup target aliases to match external usage add_library(Celix::http_admin ALIAS http_admin) diff --git a/bundles/http_admin/http_admin/src/http_admin.c b/bundles/http_admin/http_admin/src/http_admin.c index ee303022c..7db8e1ea5 100755 --- a/bundles/http_admin/http_admin/src/http_admin.c +++ b/bundles/http_admin/http_admin/src/http_admin.c @@ -29,8 +29,8 @@ #include "civetweb.h" -#include "celix_utils_api.h" #include "celix_compiler.h" +#include "celix_threads.h" struct http_admin_manager { diff --git a/bundles/http_admin/http_admin/src/websocket_admin.c b/bundles/http_admin/http_admin/src/websocket_admin.c index 287796835..cd8923e03 100644 --- a/bundles/http_admin/http_admin/src/websocket_admin.c +++ b/bundles/http_admin/http_admin/src/websocket_admin.c @@ -28,7 +28,7 @@ #include "celix_compiler.h" #include "celix_stdlib_cleanup.h" -#include "celix_utils_api.h" +#include "celix_threads.h" struct websocket_admin_manager { bundle_context_pt context; diff --git a/bundles/logging/log_helper/CMakeLists.txt b/bundles/logging/log_helper/CMakeLists.txt index 50fd467a5..d32099012 100644 --- a/bundles/logging/log_helper/CMakeLists.txt +++ b/bundles/logging/log_helper/CMakeLists.txt @@ -29,8 +29,6 @@ if (LOG_HELPER) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/log_helper COMPONENT logging) celix_target_hide_symbols(log_helper) - celix_deprecated_utils_headers(log_helper) - celix_deprecated_framework_headers(log_helper) add_library(Celix::log_helper ALIAS log_helper) diff --git a/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_tests.cc b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_tests.cc index ad29905d8..6b97a505e 100644 --- a/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_tests.cc +++ b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_tests.cc @@ -156,26 +156,9 @@ extern "C" { } static void testBundles(void) { - celix_array_list_t* bundles = nullptr; - - int rc = bundleContext_getBundles(context, &bundles); - ASSERT_EQ(0, rc); + celix_array_list_t* bundles = celix_bundleContext_listBundles(context); + ASSERT_NE(nullptr, bundles); ASSERT_EQ(3, celix_arrayList_size(bundles)); //framework, rsa_dfi & calc - - /* - int size = arrayList_size(bundles); - int i; - for (i = 0; i < size; i += 1) { - celix_bundle_t *bundle = nullptr; - module_pt module = nullptr; - char *name = nullptr; - - bundle = (celix_bundle_t *) arrayList_get(bundles, i); - bundle_getCurrentModule(bundle, &module); - module_getSymbolicName(module, &name); - printf("got bundle with symbolic name '%s'", name); - }*/ - celix_arrayList_destroy(bundles); } diff --git a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c index 425800611..d1d4fd924 100644 --- a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c +++ b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c @@ -28,6 +28,7 @@ #include "export_registration_dfi.h" #include "dfi_utils.h" #include "remote_interceptors_handler.h" +#include "celix_threads.h" #include diff --git a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c index 35e5bf3d9..486b7516a 100644 --- a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c +++ b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c @@ -32,6 +32,8 @@ #include "remote_interceptors_handler.h" #include "remote_service_admin_dfi.h" #include "remote_service_admin_dfi_constants.h" +#include "hash_map.h" +#include "celix_threads.h" struct import_registration { celix_bundle_context_t *context; diff --git a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c index aa4224758..ee4400c95 100644 --- a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c +++ b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c @@ -35,6 +35,7 @@ #include "utils.h" #include "celix_utils.h" #include "celix_ref.h" +#include "hash_map.h" #include "import_registration_dfi.h" #include "export_registration_dfi.h" diff --git a/bundles/remote_services/rsa_common/src/export_registration_impl.c b/bundles/remote_services/rsa_common/src/export_registration_impl.c index ad541e5fb..7925275dc 100644 --- a/bundles/remote_services/rsa_common/src/export_registration_impl.c +++ b/bundles/remote_services/rsa_common/src/export_registration_impl.c @@ -32,6 +32,7 @@ #include "export_registration_impl.h" #include "remote_service_admin_impl.h" +#include "bundle.h" struct export_reference { diff --git a/bundles/remote_services/rsa_common/src/import_registration_impl.c b/bundles/remote_services/rsa_common/src/import_registration_impl.c index 3e377b57e..3288489dd 100644 --- a/bundles/remote_services/rsa_common/src/import_registration_impl.c +++ b/bundles/remote_services/rsa_common/src/import_registration_impl.c @@ -33,6 +33,7 @@ #include "import_registration_impl.h" #include "remote_service_admin_impl.h" +#include "bundle.h" struct import_reference { endpoint_description_t *endpoint; diff --git a/bundles/remote_services/rsa_spi/include/remote_proxy.h b/bundles/remote_services/rsa_spi/include/remote_proxy.h index 78239d68e..a24211541 100644 --- a/bundles/remote_services/rsa_spi/include/remote_proxy.h +++ b/bundles/remote_services/rsa_spi/include/remote_proxy.h @@ -29,6 +29,7 @@ #include "endpoint_listener.h" #include "remote_service_admin.h" +#include "hash_map.h" #define CELIX_RSA_REMOTE_PROXY_FACTORY "remote_proxy_factory" #define CELIX_RSA_REMOTE_PROXY_TIMEOUT "remote_proxy_timeout" diff --git a/bundles/remote_services/topology_manager/src/topology_manager.c b/bundles/remote_services/topology_manager/src/topology_manager.c index 877280684..799017b8a 100644 --- a/bundles/remote_services/topology_manager/src/topology_manager.c +++ b/bundles/remote_services/topology_manager/src/topology_manager.c @@ -38,7 +38,7 @@ #include "bundle_context.h" #include "celix_compiler.h" #include "celix_constants.h" -#include "bundle.h" +#include "celix_bundle.h" #include "remote_service_admin.h" #include "remote_constants.h" #include "filter.h" diff --git a/bundles/remote_services/topology_manager/tms_tst/tms_tests.cpp b/bundles/remote_services/topology_manager/tms_tst/tms_tests.cpp index 235afb20c..ba6469201 100644 --- a/bundles/remote_services/topology_manager/tms_tst/tms_tests.cpp +++ b/bundles/remote_services/topology_manager/tms_tst/tms_tests.cpp @@ -81,18 +81,18 @@ extern "C" { static endpoint_listener_t *eplService = nullptr; // actually this is the topology manager static void setupFm() { + celix_status_t rc; celix_properties_t* config; ASSERT_EQ(CELIX_SUCCESS, celix_properties_load("config.properties", 0, &config)); framework = celix_frameworkFactory_createFramework(config); ASSERT_NE(nullptr, framework); - celix_bundle_t *bundle = nullptr; - celix_status_t rc = framework_getFrameworkBundle(framework, &bundle); - EXPECT_EQ(CELIX_SUCCESS, rc); + celix_bundle_t *bundle = celix_framework_getFrameworkBundle(framework); + EXPECT_NE(nullptr, bundle); - rc = bundle_getContext(bundle, &context); - EXPECT_EQ(CELIX_SUCCESS, rc); + context = celix_framework_getFrameworkContext(framework); + EXPECT_NE(nullptr, context); rc = bundleContext_getServiceReference(context, (char *)CELIX_RSA_REMOTE_SERVICE_ADMIN, &rsaRef); EXPECT_EQ(CELIX_SUCCESS, rc); @@ -172,18 +172,18 @@ extern "C" { } static void setupFmImport() { + celix_status_t rc; celix_properties_t* config; ASSERT_EQ(CELIX_SUCCESS, celix_properties_load("config_import.properties", 0, &config)); framework = celix_frameworkFactory_createFramework(config); ASSERT_NE(nullptr, framework); - celix_bundle_t *bundle = nullptr; - celix_status_t rc = framework_getFrameworkBundle(framework, &bundle); - EXPECT_EQ(CELIX_SUCCESS, rc); + celix_bundle_t *bundle = celix_framework_getFrameworkBundle(framework); + ASSERT_NE(nullptr, bundle); - rc = bundle_getContext(bundle, &context); - EXPECT_EQ(CELIX_SUCCESS, rc); + context = celix_framework_getFrameworkContext(framework); + ASSERT_NE(nullptr, context); celix_array_list_t* bundles = celix_bundleContext_listBundles(context); EXPECT_EQ(celix_arrayList_size(bundles), 4); //rsa, calculator, topman, test bundle diff --git a/bundles/shell/remote_shell/CMakeLists.txt b/bundles/shell/remote_shell/CMakeLists.txt index 51bc5e9ed..54a8912ac 100644 --- a/bundles/shell/remote_shell/CMakeLists.txt +++ b/bundles/shell/remote_shell/CMakeLists.txt @@ -37,7 +37,7 @@ if (REMOTE_SHELL) include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include") target_link_libraries(remote_shell PRIVATE Celix::shell_api) - celix_deprecated_utils_headers(remote_shell) + #celix_deprecated_utils_headers(remote_shell) celix_deprecated_framework_headers(remote_shell) install_celix_bundle(remote_shell EXPORT celix COMPONENT remote_shell) diff --git a/bundles/shell/remote_shell/src/remote_shell.c b/bundles/shell/remote_shell/src/remote_shell.c index cdff97b30..44bc96a09 100644 --- a/bundles/shell/remote_shell/src/remote_shell.c +++ b/bundles/shell/remote_shell/src/remote_shell.c @@ -16,18 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -/** - * remote_shell.c - * - * \date Nov 4, 2012 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ #include #include -#include -#include #include #include "celix_log_helper.h" diff --git a/bundles/shell/remote_shell/src/shell_mediator.c b/bundles/shell/remote_shell/src/shell_mediator.c index 636296031..c4ae07ced 100644 --- a/bundles/shell/remote_shell/src/shell_mediator.c +++ b/bundles/shell/remote_shell/src/shell_mediator.c @@ -16,120 +16,110 @@ * specific language governing permissions and limitations * under the License. */ -/** - * shell_mediator.c - * - * \date Nov 4, 2012 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ #include #include -#include -#include -#include #include #include "celix_log_helper.h" +#include "celix_shell.h" +#include "service_tracker.h" #include "shell_mediator.h" -static celix_status_t shellMediator_addedService(void *handler, service_reference_pt reference, void * service); -static celix_status_t shellMediator_removedService(void *handler, service_reference_pt reference, void * service); - -celix_status_t shellMediator_create(bundle_context_pt context, shell_mediator_pt *instance) { - celix_status_t status = CELIX_SUCCESS; - service_tracker_customizer_pt customizer = NULL; +static celix_status_t shellMediator_addedService(void* handler, service_reference_pt reference, void* service); +static celix_status_t shellMediator_removedService(void* handler, service_reference_pt reference, void* service); - (*instance) = (shell_mediator_pt) calloc(1, sizeof(**instance)); - if ((*instance) != NULL) { +celix_status_t shellMediator_create(bundle_context_pt context, shell_mediator_pt* instance) { + celix_status_t status = CELIX_SUCCESS; + service_tracker_customizer_pt customizer = NULL; - (*instance)->context = context; - (*instance)->tracker = NULL; - (*instance)->shellService = NULL; + (*instance) = (shell_mediator_pt)calloc(1, sizeof(**instance)); + if ((*instance) != NULL) { + (*instance)->context = context; + (*instance)->tracker = NULL; + (*instance)->shellService = NULL; (*instance)->loghelper = celix_logHelper_create(context, "celix_shell"); - status = CELIX_DO_IF(status, celixThreadMutex_create(&(*instance)->mutex, NULL)); - - status = CELIX_DO_IF(status, serviceTrackerCustomizer_create((*instance), NULL, shellMediator_addedService, - NULL, shellMediator_removedService, &customizer)); - status = CELIX_DO_IF(status, serviceTracker_create(context, (char * )CELIX_SHELL_SERVICE_NAME, customizer, &(*instance)->tracker)); - - if (status == CELIX_SUCCESS) { - serviceTracker_open((*instance)->tracker); - } - } else { - status = CELIX_ENOMEM; - } - - if ((status != CELIX_SUCCESS) && ((*instance) != NULL)){ - celix_logHelper_log((*instance)->loghelper, CELIX_LOG_LEVEL_ERROR, "Error creating shell_mediator, error code is %i\n", status); - } - return status; + status = CELIX_DO_IF(status, celixThreadMutex_create(&(*instance)->mutex, NULL)); + + status = CELIX_DO_IF( + status, + serviceTrackerCustomizer_create( + (*instance), NULL, shellMediator_addedService, NULL, shellMediator_removedService, &customizer)); + status = CELIX_DO_IF( + status, serviceTracker_create(context, (char*)CELIX_SHELL_SERVICE_NAME, customizer, &(*instance)->tracker)); + + if (status == CELIX_SUCCESS) { + serviceTracker_open((*instance)->tracker); + } + } else { + status = CELIX_ENOMEM; + } + + if ((status != CELIX_SUCCESS) && ((*instance) != NULL)) { + celix_logHelper_log( + (*instance)->loghelper, CELIX_LOG_LEVEL_ERROR, "Error creating shell_mediator, error code is %i\n", status); + } + return status; } celix_status_t shellMediator_stop(shell_mediator_pt instance) { - service_tracker_pt tracker; - celixThreadMutex_lock(&instance->mutex); - tracker = instance->tracker; - celixThreadMutex_unlock(&instance->mutex); + service_tracker_pt tracker; + celixThreadMutex_lock(&instance->mutex); + tracker = instance->tracker; + celixThreadMutex_unlock(&instance->mutex); - if (tracker != NULL) { - serviceTracker_close(tracker); - } + if (tracker != NULL) { + serviceTracker_close(tracker); + } return CELIX_SUCCESS; } celix_status_t shellMediator_destroy(shell_mediator_pt instance) { - celix_status_t status = CELIX_SUCCESS; + celix_status_t status = CELIX_SUCCESS; - celixThreadMutex_lock(&instance->mutex); + celixThreadMutex_lock(&instance->mutex); - instance->shellService = NULL; - serviceTracker_destroy(instance->tracker); + instance->shellService = NULL; + serviceTracker_destroy(instance->tracker); celix_logHelper_destroy(instance->loghelper); - celixThreadMutex_destroy(&instance->mutex); + celixThreadMutex_destroy(&instance->mutex); + free(instance); - free(instance); - - - return status; + return status; } -celix_status_t shellMediator_executeCommand(shell_mediator_pt instance, char *command, FILE *out, FILE *err) { - celix_status_t status = CELIX_SUCCESS; - - celixThreadMutex_lock(&instance->mutex); +celix_status_t shellMediator_executeCommand(shell_mediator_pt instance, char* command, FILE* out, FILE* err) { + celix_status_t status = CELIX_SUCCESS; + celixThreadMutex_lock(&instance->mutex); - if (instance->shellService != NULL) { - instance->shellService->executeCommand(instance->shellService->handle, command, out, err); - } + if (instance->shellService != NULL) { + instance->shellService->executeCommand(instance->shellService->handle, command, out, err); + } - celixThreadMutex_unlock(&instance->mutex); + celixThreadMutex_unlock(&instance->mutex); - return status; + return status; } -static celix_status_t shellMediator_addedService(void *handler, service_reference_pt reference, void * service) { - celix_status_t status = CELIX_SUCCESS; - shell_mediator_pt instance = (shell_mediator_pt) handler; - celixThreadMutex_lock(&instance->mutex); - instance->shellService = (celix_shell_t*) service; - celixThreadMutex_unlock(&instance->mutex); - return status; +static celix_status_t shellMediator_addedService(void* handler, service_reference_pt reference, void* service) { + celix_status_t status = CELIX_SUCCESS; + shell_mediator_pt instance = (shell_mediator_pt)handler; + celixThreadMutex_lock(&instance->mutex); + instance->shellService = (celix_shell_t*)service; + celixThreadMutex_unlock(&instance->mutex); + return status; } - -static celix_status_t shellMediator_removedService(void *handler, service_reference_pt reference, void * service) { - celix_status_t status = CELIX_SUCCESS; - shell_mediator_pt instance = (shell_mediator_pt) handler; - celixThreadMutex_lock(&instance->mutex); - instance->shellService = NULL; - celixThreadMutex_unlock(&instance->mutex); - return status; +static celix_status_t shellMediator_removedService(void* handler, service_reference_pt reference, void* service) { + celix_status_t status = CELIX_SUCCESS; + shell_mediator_pt instance = (shell_mediator_pt)handler; + celixThreadMutex_lock(&instance->mutex); + instance->shellService = NULL; + celixThreadMutex_unlock(&instance->mutex); + return status; } - diff --git a/bundles/shell/remote_shell/src/shell_mediator.h b/bundles/shell/remote_shell/src/shell_mediator.h index b8fdd4291..1e09924b4 100644 --- a/bundles/shell/remote_shell/src/shell_mediator.h +++ b/bundles/shell/remote_shell/src/shell_mediator.h @@ -33,7 +33,8 @@ #include #include "celix_log_helper.h" -#include +#include "celix_shell.h" +#include "celix_threads.h" struct shell_mediator { celix_log_helper_t *loghelper; diff --git a/bundles/shell/shell/CMakeLists.txt b/bundles/shell/shell/CMakeLists.txt index e9320e011..ed915e460 100644 --- a/bundles/shell/shell/CMakeLists.txt +++ b/bundles/shell/shell/CMakeLists.txt @@ -49,7 +49,6 @@ if (SHELL) src/bundle_command.c) target_include_directories(shell_commands PRIVATE src) target_link_libraries(shell_commands PRIVATE Celix::shell_api Celix::log_helper) - celix_deprecated_utils_headers(shell_commands) add_celix_bundle(shell SYMBOLIC_NAME "apache_celix_c_shell" diff --git a/bundles/shell/shell_tui/CMakeLists.txt b/bundles/shell/shell_tui/CMakeLists.txt index d51f36b9f..aca16ebb1 100644 --- a/bundles/shell/shell_tui/CMakeLists.txt +++ b/bundles/shell/shell_tui/CMakeLists.txt @@ -31,7 +31,6 @@ if (SHELL_TUI) target_include_directories(shell_tui PRIVATE src) target_link_libraries(shell_tui PRIVATE Celix::shell_api Celix::utils) - celix_deprecated_utils_headers(shell_tui) install_celix_bundle(shell_tui EXPORT celix) diff --git a/bundles/shell/shell_tui/src/shell_tui.c b/bundles/shell/shell_tui/src/shell_tui.c index a370ec93f..1d8e78f83 100644 --- a/bundles/shell/shell_tui/src/shell_tui.c +++ b/bundles/shell/shell_tui/src/shell_tui.c @@ -23,14 +23,13 @@ #include #include #include +#include +#include #include "celix_array_list.h" #include "celix_shell.h" #include "celix_utils.h" #include "shell_tui.h" -#include "utils.h" -#include -#include #include "history.h" #define LINE_SIZE 256 diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake index 0bdf0f654..33327dff5 100644 --- a/cmake/cmake_celix/BundlePackaging.cmake +++ b/cmake/cmake_celix/BundlePackaging.cmake @@ -450,7 +450,7 @@ function(celix_bundle_libs) list(GET ARGN 0 ADD_TO_MANIFEST) list(REMOVE_AT ARGN 0) - #check if arg 0 is corrent + #check if arg 0 is correct _check_bundle(${BUNDLE}) get_target_property(BUNDLE_DIR ${BUNDLE} "BUNDLE_CONTENT_DIR") get_target_property(BUNDLE_GEN_DIR ${BUNDLE} "BUNDLE_GEN_DIR") @@ -461,6 +461,10 @@ function(celix_bundle_libs) get_target_property(LIB_TARGETS ${BUNDLE} "BUNDLE_LIB_TARGETS") foreach (LIB IN ITEMS ${ARGN}) + if (TYPE STREQUAL "EXPORT" OR TYPE STREQUAL "IMPORT") + message(WARNING "Adding bundle lib ${LIB} with type ${TYPE}. Export and Import libs in Celix is yet supported.") + endif () + string(MAKE_C_IDENTIFIER ${LIB} LIBID) if (IS_ABSOLUTE ${LIB} AND EXISTS ${LIB}) get_filename_component(LIB_NAME ${LIB} NAME) diff --git a/libs/dfi/gtest/CMakeLists.txt b/libs/dfi/gtest/CMakeLists.txt index 7e23890f9..2f61b6355 100644 --- a/libs/dfi/gtest/CMakeLists.txt +++ b/libs/dfi/gtest/CMakeLists.txt @@ -32,7 +32,6 @@ add_executable(test_dfi target_include_directories(test_dfi PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../src) target_link_libraries(test_dfi PRIVATE dfi_cut Celix::utils libffi::libffi jansson::jansson GTest::gtest GTest::gtest_main) -celix_deprecated_utils_headers(test_dfi) file(COPY ${CMAKE_CURRENT_LIST_DIR}/descriptors DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt index 3e5fff719..94e031c78 100644 --- a/libs/framework/CMakeLists.txt +++ b/libs/framework/CMakeLists.txt @@ -25,8 +25,8 @@ if (FRAMEWORK) set(FRAMEWORK_SRC src/bundle.c src/bundle_archive.c src/celix_bundle_cache.c src/bundle_context.c src/bundle_revision.c - src/framework.c src/manifest.c - src/manifest_parser.c src/module.c + src/framework.c + src/module.c src/service_reference.c src/service_registration.c src/service_registry.c src/service_tracker.c src/service_tracker_customizer.c src/celix_log.c src/celix_launcher.c @@ -54,6 +54,7 @@ if (FRAMEWORK) target_include_directories(framework PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include_deprecated) target_compile_options(framework PRIVATE -DUSE_FILE32API) target_compile_options(framework PRIVATE -Wno-deprecated-declarations) #note part of the api is deprecated, ignore this warning on own api + target_compile_options(framework PRIVATE -DCELIX_FRAMEWORK_VERSION="${CELIX_MAJOR}.${CELIX_MINOR}.${CELIX_MICRO}") if (NOT FRAMEWORK_CURLINIT) target_compile_definitions(framework PRIVATE CELIX_NO_CURLINIT) endif () diff --git a/libs/framework/gtest/src/BundleArchiveTestSuite.cc b/libs/framework/gtest/src/BundleArchiveTestSuite.cc index 59cc1c1c5..1f3dd5401 100644 --- a/libs/framework/gtest/src/BundleArchiveTestSuite.cc +++ b/libs/framework/gtest/src/BundleArchiveTestSuite.cc @@ -28,8 +28,7 @@ //including private headers, which should only be used for testing #include "bundle_archive_private.h" -#include "bundle_private.h" - +#include "celix_bundle_private.h" class CxxBundleArchiveTestSuite : public ::testing::Test { public: diff --git a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc index 2aeb425c3..a8ba50661 100644 --- a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc @@ -36,7 +36,7 @@ #include "bundle_revision_private.h" #include "framework_private.h" #include "malloc_ei.h" -#include "manifest.h" +#include "celix_bundle_manifest.h" #include "stat_ei.h" #include "unistd_ei.h" @@ -111,7 +111,7 @@ TEST_F(BundleArchiveWithErrorInjectionTestSuite, BundleArchiveCreatedFailedTest) teardownErrorInjectors(); // Given a mocked malloc which returns NULL from a call from manifest_create - celix_ei_expect_malloc((void*)manifest_create, 0, nullptr); + celix_ei_expect_calloc((void*)celix_bundleManifest_create, 0, nullptr); installBundleAndExpectFailure(); teardownErrorInjectors(); diff --git a/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc b/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc index 9745da35f..44a9c1d18 100644 --- a/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc @@ -36,7 +36,7 @@ #include "bundle_revision_private.h" #include "framework_private.h" #include "malloc_ei.h" -#include "manifest.h" +#include "celix_bundle_manifest.h" #include "unistd_ei.h" class CelixBundleCacheErrorInjectionTestSuite : public ::testing::Test { @@ -144,7 +144,7 @@ TEST_F(CelixBundleCacheErrorInjectionTestSuite, SystemArchiveCreateErrorTest) { EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive)); EXPECT_EQ(nullptr, archive); - celix_ei_expect_malloc((void*)manifest_create, 0, nullptr); + celix_ei_expect_celix_properties_create((void*)celix_bundleManifest_createFrameworkManifest, 0, nullptr); EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive)); EXPECT_EQ(nullptr, archive); diff --git a/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc b/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc index 01616065b..d6b7ae35e 100644 --- a/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc +++ b/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc @@ -57,7 +57,7 @@ class CelixBundleContextBundlesTestSuite : public ::testing::Test { fw = celix_frameworkFactory_createFramework(properties); - ctx = framework_getContext(fw); + ctx = celix_framework_getFrameworkContext(fw); } ~CelixBundleContextBundlesTestSuite() override { @@ -883,7 +883,7 @@ class CelixBundleContextTempBundlesTestSuite : public ::testing::Test { celix_properties_setBool(properties, CELIX_FRAMEWORK_CACHE_USE_TMP_DIR, true); fw = celix_frameworkFactory_createFramework(properties); EXPECT_NE(fw, nullptr); - ctx = framework_getContext(fw); + ctx = celix_framework_getFrameworkContext(fw); EXPECT_NE(ctx, nullptr); } diff --git a/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc b/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc index 529c176ce..43689eaa9 100644 --- a/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc +++ b/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc @@ -50,7 +50,7 @@ class CelixBundleContextServicesTestSuite : public ::testing::Test { celix_properties_setLong(properties, CELIX_FRAMEWORK_STATIC_EVENT_QUEUE_SIZE, 256); //ensure that the floodEventLoopTest overflows the static event queue size fw = celix_frameworkFactory_createFramework(properties); - ctx = framework_getContext(fw); + ctx = celix_framework_getFrameworkContext(fw); celix_err_resetErrors(); } diff --git a/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc b/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc index ae64656b4..ab7114e08 100644 --- a/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc @@ -19,158 +19,32 @@ */ #include -#include -#include #include "celix_err.h" #include "celix_properties_ei.h" -#include "celix_stdio_cleanup.h" -#include "celix_utils_ei.h" -#include "hmap_ei.h" #include "malloc_ei.h" -#include "manifest.h" -#include "stdio_ei.h" -#include "string_ei.h" +#include "celix_bundle_manifest.h" class ManifestErrorInjectionTestSuite : public ::testing::Test { public: - ManifestErrorInjectionTestSuite() { - } + ManifestErrorInjectionTestSuite() = default; ~ManifestErrorInjectionTestSuite() override { teardownErrorInjectors(); } - void teardownErrorInjectors() { - celix_ei_expect_malloc(nullptr, 0, nullptr); - celix_ei_expect_celix_properties_create(nullptr, 0, nullptr); - celix_ei_expect_celix_properties_copy(nullptr, 0, nullptr); - celix_ei_expect_hashMap_create(nullptr, 0, nullptr); - celix_ei_expect_celix_utils_strdup(nullptr, 0, nullptr); - celix_ei_expect_fseek(nullptr, 0, -1); - celix_ei_expect_ftell(nullptr, 0, -1); - celix_ei_expect_fread(nullptr, 0, 0); - celix_ei_expect_strndup(nullptr, 0, nullptr); + + static void teardownErrorInjectors() { + celix_ei_expect_calloc(nullptr, 0, nullptr); } }; TEST_F(ManifestErrorInjectionTestSuite, NoMemoryForManifestCreateTest) { - manifest_pt manifest = nullptr; - celix_ei_expect_malloc((void*)manifest_create, 0, nullptr); - celix_status_t status = manifest_create(&manifest); - EXPECT_EQ(CELIX_ENOMEM, status); - EXPECT_EQ(nullptr, manifest); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); - teardownErrorInjectors(); - - manifest = nullptr; - celix_ei_expect_celix_properties_create((void*)manifest_create, 0, nullptr); - status = manifest_create(&manifest); - EXPECT_EQ(CELIX_ENOMEM, status); - EXPECT_EQ(nullptr, manifest); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); - teardownErrorInjectors(); - - manifest = nullptr; - celix_ei_expect_hashMap_create((void*)manifest_create, 0, nullptr); - status = manifest_create(&manifest); + celix_bundle_manifest_t* manifest = nullptr; + celix_ei_expect_calloc((void*)celix_bundleManifest_create, 0, nullptr); + celix_properties_t* attributes = celix_properties_create(); + ASSERT_NE(nullptr, attributes); + celix_status_t status = celix_bundleManifest_create(attributes, &manifest); EXPECT_EQ(CELIX_ENOMEM, status); EXPECT_EQ(nullptr, manifest); celix_err_printErrors(stdout, "Errors are expected[", "]\n"); - teardownErrorInjectors(); -} - -TEST_F(ManifestErrorInjectionTestSuite, NoMemoryForManifestCloneTest) { - std::string content = "Manifest-Version: 1.0\n" - "DeploymentPackage-Icon: %icon\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "\n" - "Name: bundles/3dlib.jar\n" - "SHA1-Digest: MOez1l4gXHBo8ycYdAxstK3UvEg=\n" - "Bundle-SymbolicName: com.third._3d\n" - "Bundle-Version: 2.3.1\n" - "\n" - "Name: bundles/3dnative.jar\n" - "SHA1-Digest: N8Ow2UY4yjnHZv5zeq2I1Uv/+uE=\n" - "Bundle-SymbolicName: com.third._3d.native\n" - "Bundle-Version: 1.5.3\n" - "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - celix_auto(manifest_pt) manifest = nullptr; - manifest_create(&manifest); - EXPECT_EQ(CELIX_SUCCESS, manifest_readFromStream(manifest, manifestFile)); - celix_ei_expect_malloc((void*)manifest_create, 0, nullptr); - EXPECT_EQ(nullptr, manifest_clone(manifest)); - teardownErrorInjectors(); - - celix_ei_expect_celix_utils_strdup((void*)manifest_clone, 0, nullptr); - EXPECT_EQ(nullptr, manifest_clone(manifest)); - teardownErrorInjectors(); - - celix_ei_expect_celix_properties_copy((void*)manifest_clone, 0, nullptr); - EXPECT_EQ(nullptr, manifest_clone(manifest)); - teardownErrorInjectors(); } - -TEST_F(ManifestErrorInjectionTestSuite, ReadFromStreamErrorTest) { - std::string content = "Manifest-Version: 1.0\n" - "DeploymentPackage-Icon: %icon\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "\n" - "Name: bundles/3dlib.jar\n" - "SHA1-Digest: MOez1l4gXHBo8ycYdAxstK3UvEg=\n" - "Bundle-SymbolicName: com.third._3d\n" - "Bundle-Version: 2.3.1\n" - "\n" - "Name: bundles/3dnative.jar\n" - "SHA1-Digest: N8Ow2UY4yjnHZv5zeq2I1Uv/+uE=\n" - "Bundle-SymbolicName: com.third._3d.native\n" - "Bundle-Version: 1.5.3\n" - "\n" - "Name: bundles/3dnative1.jar\n" - "SHA1-Digest: N8Ow2UY4yjnHZv5zeq2I1Uv/+uF=\n" - "Bundle-SymbolicName: com.third._3d.native1\n" - "Bundle-Version: 1.5.4\n" - "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - celix_auto(manifest_pt) manifest = nullptr; - manifest_create(&manifest); - celix_ei_expect_fseek((void*)manifest_readFromStream, 0, -1); - EXPECT_EQ(EACCES, manifest_readFromStream(manifest, manifestFile)); - teardownErrorInjectors(); - - celix_ei_expect_ftell((void*)manifest_readFromStream, 0, -1); - EXPECT_EQ(EACCES, manifest_readFromStream(manifest, manifestFile)); - teardownErrorInjectors(); - - celix_ei_expect_ftell((void*)manifest_readFromStream, 0, (long)INT_MAX+1); - EXPECT_EQ(CELIX_BUNDLE_EXCEPTION, manifest_readFromStream(manifest, manifestFile)); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); - teardownErrorInjectors(); - - celix_ei_expect_malloc((void*)manifest_readFromStream, 0, nullptr); - EXPECT_EQ(CELIX_ENOMEM, manifest_readFromStream(manifest, manifestFile)); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); - teardownErrorInjectors(); - - celix_ei_expect_fread((void*)manifest_readFromStream, 0, 1); - EXPECT_EQ(CELIX_FILE_IO_EXCEPTION, manifest_readFromStream(manifest, manifestFile)); - teardownErrorInjectors(); - - for (int i = 0; i < 3; ++i) { - celix_auto(manifest_pt) mfs = nullptr; - manifest_create(&mfs); - celix_ei_expect_celix_utils_strdup((void*)manifest_readFromStream, 0, nullptr, i+1); - EXPECT_EQ(CELIX_ENOMEM, manifest_readFromStream(mfs, manifestFile)); - teardownErrorInjectors(); - } - - for (int i = 0; i < 3; ++i) { - celix_auto(manifest_pt) mfs = nullptr; - manifest_create(&mfs); - celix_ei_expect_celix_properties_create((void*)manifest_readFromStream, 0, nullptr, i+1); - EXPECT_EQ(CELIX_ENOMEM, manifest_readFromStream(mfs, manifestFile)); - teardownErrorInjectors(); - } -} \ No newline at end of file diff --git a/libs/framework/gtest/src/ManifestTestSuite.cc b/libs/framework/gtest/src/ManifestTestSuite.cc index 7053cd634..8f10dfa16 100644 --- a/libs/framework/gtest/src/ManifestTestSuite.cc +++ b/libs/framework/gtest/src/ManifestTestSuite.cc @@ -154,7 +154,7 @@ TEST_F(ManifestTestSuite, GetBuiltinAttributes) { //And the manifest contains the mandatory attributes EXPECT_EQ(4, celix_properties_size(celix_bundleManifest_getAttributes(manifest))); EXPECT_STREQ("my_bundle", celix_bundleManifest_getBundleName(manifest)); - EXPECT_STREQ("celix_my_bundle", celix_bundleManifest_getSymbolicName(manifest)); + EXPECT_STREQ("celix_my_bundle", celix_bundleManifest_getBundleSymbolicName(manifest)); const auto* mv = celix_bundleManifest_getManifestVersion(manifest); const auto* bv = celix_bundleManifest_getBundleVersion(manifest); @@ -176,6 +176,7 @@ TEST_F(ManifestTestSuite, GetBuiltinAttributes) { celix_properties_set(properties, "CELIX_BUNDLE_ACTIVATOR_LIBRARY", "my_activator"); celix_properties_set(properties, "CELIX_BUNDLE_PRIVATE_LIBRARIES", "lib1,lib2"); celix_properties_set(properties, "CELIX_BUNDLE_GROUP", "my_group"); + celix_properties_set(properties, "CELIX_BUNDLE_DESCRIPTION", "my_description"); //When creating a manifest from the attributes celix_autoptr(celix_bundle_manifest_t) manifest2 = nullptr; @@ -193,4 +194,5 @@ TEST_F(ManifestTestSuite, GetBuiltinAttributes) { EXPECT_STREQ("lib1", celix_arrayList_getString(privateLibraries, 0)); EXPECT_STREQ("lib2", celix_arrayList_getString(privateLibraries, 1)); EXPECT_STREQ("my_group", celix_bundleManifest_getBundleGroup(manifest2)); + EXPECT_STREQ("my_description", celix_bundleManifest_getBundleDescription(manifest2)); } diff --git a/libs/framework/include_deprecated/bundle.h b/libs/framework/include_deprecated/bundle.h index 44bf3c491..66261e093 100644 --- a/libs/framework/include_deprecated/bundle.h +++ b/libs/framework/include_deprecated/bundle.h @@ -1,112 +1,37 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ #ifndef BUNDLE_H_ #define BUNDLE_H_ -#include "celix_types.h" - #include "celix_errno.h" -#include "celix_bundle_state.h" -#include "bundle_archive.h" -#include "framework.h" -#include "module.h" -#include "service_reference.h" -#include "celix_log.h" -#include "celix_threads.h" -#include "bundle_context.h" #include "celix_framework_export.h" +#include "celix_bundle.h" #ifdef __cplusplus extern "C" { #endif -struct celix_bundle_activator; -typedef struct celix_bundle_activator celix_bundle_activator_t; - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_isSystemBundle(const celix_bundle_t *bundle, bool *systemBundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getArchive(const celix_bundle_t *bundle, bundle_archive_pt *archive); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getCurrentModule(const celix_bundle_t *bundle, module_pt *module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_array_list_t *bundle_getModules(const celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void *bundle_getHandle(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void bundle_setHandle(celix_bundle_t *bundle, void *handle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_bundle_activator_t *bundle_getActivator(const celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_setActivator(celix_bundle_t *bundle, celix_bundle_activator_t *activator); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getContext(const celix_bundle_t *bundle, celix_bundle_context_t **context); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_setContext(celix_bundle_t *bundle, celix_bundle_context_t *context); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getEntry(const celix_bundle_t *bundle, const char *name, char **entry); - CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_start(celix_bundle_t *bundle); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_update(celix_bundle_t *bundle, const char *inputFile); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_stop(celix_bundle_t *bundle); - CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_uninstall(celix_bundle_t *bundle); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_setState(celix_bundle_t *bundle, bundle_state_e state); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_setPersistentStateInactive(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_setPersistentStateUninstalled(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void uninstallBundle(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_revise(celix_bundle_t *bundle, const char *location, const char *inputFile); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_addModule(celix_bundle_t *bundle, module_pt module); - -// Service Reference Functions -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_array_list_t *getUsingBundles(service_reference_pt reference); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT int compareTo(service_reference_pt a, service_reference_pt b); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getState(const celix_bundle_t *bundle, bundle_state_e *state); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_closeAndDelete(const celix_bundle_t *bundle); - -CELIX_FRAMEWORK_EXPORT celix_status_t bundle_close(const celix_bundle_t *bundle) - __attribute__((deprecated("bundle_close is deprecated and does nothing"))); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_refresh(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getBundleId(const celix_bundle_t *bundle, long *id); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getRegisteredServices(celix_bundle_t *bundle, celix_array_list_t **list); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getServicesInUse(celix_bundle_t *bundle, celix_array_list_t **list); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getFramework(const celix_bundle_t *bundle, celix_framework_t **framework); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getBundleLocation(const celix_bundle_t *bundle, const char **location); - - #ifdef __cplusplus } #endif diff --git a/libs/framework/include_deprecated/bundle_context.h b/libs/framework/include_deprecated/bundle_context.h index b12c84ab8..9a6f63bd3 100644 --- a/libs/framework/include_deprecated/bundle_context.h +++ b/libs/framework/include_deprecated/bundle_context.h @@ -26,8 +26,11 @@ * Framework. */ -#include "celix_types.h" +#include +#include "bundle_context.h" + +#include "celix_types.h" #include "celix_cleanup.h" #include "service_factory.h" #include "celix_service_factory.h" @@ -35,13 +38,10 @@ #include "bundle_listener.h" #include "framework_listener.h" #include "celix_service_listener.h" - #include "dm_dependency_manager.h" -#include - -#include "bundle_context.h" #include "celix_bundle_context.h" #include "celix_framework_export.h" +#include "celix_log.h" #ifdef __cplusplus extern "C" { diff --git a/libs/framework/include_deprecated/framework.h b/libs/framework/include_deprecated/framework.h index 3ef46bc9a..98ceafaf4 100644 --- a/libs/framework/include_deprecated/framework.h +++ b/libs/framework/include_deprecated/framework.h @@ -21,7 +21,7 @@ #define FRAMEWORK_H_ #include "celix_errno.h" -#include "bundle.h" +#include "celix_bundle.h" #include "celix_properties.h" #include "bundle_context.h" #include "celix_framework_export.h" diff --git a/libs/framework/include_deprecated/framework_event.h b/libs/framework/include_deprecated/framework_event.h index 58bf77d30..ccbb59911 100644 --- a/libs/framework/include_deprecated/framework_event.h +++ b/libs/framework/include_deprecated/framework_event.h @@ -52,7 +52,7 @@ typedef struct framework_event framework_event_t; #endif #include "service_reference.h" -#include "bundle.h" +#include "celix_bundle.h" #ifdef __cplusplus extern "C" { diff --git a/libs/framework/include_deprecated/manifest.h b/libs/framework/include_deprecated/manifest.h deleted file mode 100644 index 60da8dedf..000000000 --- a/libs/framework/include_deprecated/manifest.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * manifest.h - * - * \date Jul 5, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef MANIFEST_H_ -#define MANIFEST_H_ - -#include -#include - -#include "celix_cleanup.h" -#include "celix_errno.h" -#include "celix_framework_export.h" -#include "celix_properties.h" -#include "hash_map.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct manifest { - celix_properties_t *mainAttributes; - hash_map_pt attributes; -}; - -typedef struct manifest *manifest_pt; - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_create(manifest_pt *manifest); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT manifest_pt manifest_clone(manifest_pt manifest); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_createFromFile(const char *filename, manifest_pt *manifest); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_destroy(manifest_pt manifest); - -CELIX_DEFINE_AUTO_CLEANUP_FREE_FUNC(manifest_pt, manifest_destroy, NULL) - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void manifest_clear(manifest_pt manifest); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_properties_t *manifest_getMainAttributes(manifest_pt manifest); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_getEntries(manifest_pt manifest, hash_map_pt *map); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_read(manifest_pt manifest, const char *filename); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_readFromStream(manifest_pt manifest, FILE* stream); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void manifest_write(manifest_pt manifest, const char *filename); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT const char *manifest_getValue(manifest_pt manifest, const char *name); - -#ifdef __cplusplus -} -#endif - -#endif /* MANIFEST_H_ */ diff --git a/libs/framework/include_deprecated/module.h b/libs/framework/include_deprecated/module.h deleted file mode 100644 index 4cef2d970..000000000 --- a/libs/framework/include_deprecated/module.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * module.h - * - * \date Jul 12, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef MODULE_H_ -#define MODULE_H_ - -typedef struct module *module_pt; -typedef struct module celix_module_t; - -#include - -#include "manifest.h" -#include "bundle.h" -#include "celix_framework_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -CELIX_FRAMEWORK_DEPRECATED_EXPORT module_pt module_create(manifest_pt headerMap, const char *moduleId, celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT module_pt module_createFrameworkModule(celix_framework_t* fw, celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_destroy(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT unsigned int module_hash(void *module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT int module_equals(void *module, void *compare); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_version_t* module_getVersion(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t module_getSymbolicName(module_pt module, const char **symbolicName); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT char *module_getId(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT bool module_isResolved(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_setResolved(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_bundle_t *module_getBundle(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_array_list_t *module_getDependentImporters(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_addDependentImporter(module_pt module, module_pt importer); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_removeDependentImporter(module_pt module, module_pt importer); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_array_list_t *module_getDependentRequirers(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_addDependentRequirer(module_pt module, module_pt requirer); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_removeDependentRequirer(module_pt module, module_pt requirer); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_array_list_t *module_getDependents(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t module_getGroup(module_pt module, const char **group); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t module_getName(module_pt module, const char **name); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t module_getDescription(module_pt module, const char **description); - -#ifdef __cplusplus -} -#endif - -#endif /* MODULE_H_ */ diff --git a/libs/framework/include_deprecated/service_factory.h b/libs/framework/include_deprecated/service_factory.h index 494f81f1b..8265153d1 100644 --- a/libs/framework/include_deprecated/service_factory.h +++ b/libs/framework/include_deprecated/service_factory.h @@ -23,7 +23,7 @@ #include "celix_types.h" #include "celix_errno.h" #include "service_registration.h" -#include "bundle.h" +#include "celix_bundle.h" #ifdef __cplusplus extern "C" { diff --git a/libs/framework/include_deprecated/service_reference.h b/libs/framework/include_deprecated/service_reference.h index 35068cca5..c3acec020 100644 --- a/libs/framework/include_deprecated/service_reference.h +++ b/libs/framework/include_deprecated/service_reference.h @@ -24,7 +24,7 @@ #include "celix_types.h" #include "service_registration.h" -#include "bundle.h" +#include "celix_bundle.h" #include "celix_framework_export.h" #ifdef __cplusplus diff --git a/libs/framework/include_deprecated/service_registration.h b/libs/framework/include_deprecated/service_registration.h index 256d7db03..cf648c05b 100644 --- a/libs/framework/include_deprecated/service_registration.h +++ b/libs/framework/include_deprecated/service_registration.h @@ -23,7 +23,7 @@ #include #include "celix_types.h" -#include "bundle.h" +#include "celix_properties_type.h" #include "celix_framework_export.h" #ifdef __cplusplus diff --git a/libs/framework/include_deprecated/service_registry.h b/libs/framework/include_deprecated/service_registry.h index 7cdb785d7..155c8ee72 100644 --- a/libs/framework/include_deprecated/service_registry.h +++ b/libs/framework/include_deprecated/service_registry.h @@ -28,7 +28,7 @@ #include "service_registration.h" #include "celix_service_factory.h" #include "celix_framework_export.h" - +#include "celix_service_listener.h" #ifdef __cplusplus extern "C" { diff --git a/libs/framework/src/bundle.c b/libs/framework/src/bundle.c index 97a4f6e29..7f8342328 100644 --- a/libs/framework/src/bundle.c +++ b/libs/framework/src/bundle.c @@ -17,7 +17,7 @@ * under the License. */ -#include "bundle_private.h" +#include "celix_bundle_private.h" #include #include @@ -26,6 +26,7 @@ #include #include +#include "celix_module.h" #include "framework_private.h" #include "utils.h" #include "celix_file_utils.h" @@ -35,7 +36,7 @@ static char* celix_bundle_getBundleOrPersistentStoreEntry(const celix_bundle_t* bnd, bool bundleEntry, const char* name); -celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module); +celix_status_t bundle_createModule(bundle_pt bundle, celix_module_t** module); celix_status_t bundle_closeRevisions(const_bundle_pt bundle); celix_status_t celix_bundle_createFromArchive(celix_framework_t *framework, bundle_archive_pt archive, celix_bundle_t **bundleOut) { @@ -67,7 +68,7 @@ celix_status_t celix_bundle_createFromArchive(celix_framework_t *framework, bund return status; } - module_pt module; + celix_module_t* module; status = bundle_createModule(bundle, &module); if (status != CELIX_SUCCESS) { fw_logCode(framework->logger, CELIX_LOG_LEVEL_ERROR, status, "Cannot create bundle from archive, cannot create module."); @@ -84,7 +85,7 @@ celix_status_t celix_bundle_createFromArchive(celix_framework_t *framework, bund celix_status_t bundle_destroy(bundle_pt bundle) { for (int i = 0; i < celix_arrayList_size(bundle->modules); ++i) { - module_pt module = celix_arrayList_get(bundle->modules, i); + celix_module_t* module = celix_arrayList_get(bundle->modules, i); module_destroy(module); } celix_arrayList_destroy(bundle->modules); @@ -108,7 +109,7 @@ celix_status_t bundle_getArchive(const_bundle_pt bundle, bundle_archive_pt *arch return status; } -celix_status_t bundle_getCurrentModule(const_bundle_pt bundle, module_pt *module) { +celix_status_t bundle_getCurrentModule(const_bundle_pt bundle, celix_module_t** module) { celix_status_t status = CELIX_SUCCESS; if (bundle == NULL || celix_arrayList_size(bundle->modules)==0 ) { @@ -141,15 +142,9 @@ celix_status_t bundle_setActivator(bundle_pt bundle, celix_bundle_activator_t *a return CELIX_SUCCESS; } -celix_status_t bundle_getContext(const_bundle_pt bundle, bundle_context_pt *context) { - *context = bundle->context; - return CELIX_SUCCESS; -} +celix_bundle_context_t* celix_bundle_getContext(const_bundle_pt bundle) { return bundle->context; } -celix_status_t bundle_setContext(bundle_pt bundle, bundle_context_pt context) { - bundle->context = context; - return CELIX_SUCCESS; -} +void celix_bundle_setContext(bundle_pt bundle, bundle_context_pt context) { bundle->context = context; } celix_status_t bundle_getEntry(const_bundle_pt bundle, const char* name, char** entry) { *entry = celix_bundle_getBundleOrPersistentStoreEntry(bundle, true, name); @@ -170,16 +165,16 @@ celix_status_t bundle_setState(bundle_pt bundle, bundle_state_e state) { return CELIX_SUCCESS; } -celix_status_t bundle_createModule(bundle_pt bundle, module_pt* moduleOut) { +celix_status_t bundle_createModule(bundle_pt bundle, celix_module_t** moduleOut) { celix_status_t status = CELIX_SUCCESS; bundle_archive_pt archive = NULL; bundle_revision_pt revision = NULL; - manifest_pt headerMap = NULL; + celix_bundle_manifest_t* manifest = NULL; long bundleId = 0; status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive)); status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision)); - status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &headerMap)); + status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &manifest)); status = bundleArchive_getId(bundle->archive, &bundleId); if (status != CELIX_SUCCESS) { @@ -187,14 +182,11 @@ celix_status_t bundle_createModule(bundle_pt bundle, module_pt* moduleOut) { return status; } - module_pt module = NULL; + celix_module_t* module = NULL; if (bundleId == CELIX_FRAMEWORK_BUNDLE_ID) { module = module_createFrameworkModule(bundle->framework, bundle); } else { - int revision_no = 0; - char moduleId[512]; - snprintf(moduleId, sizeof(moduleId), "%ld.%d", bundleId, revision_no); - module = module_create(headerMap, moduleId, bundle); + module = module_create(manifest, bundle); } if (!module) { status = CELIX_BUNDLE_EXCEPTION; @@ -281,7 +273,7 @@ celix_status_t bundle_revise(bundle_pt bundle, const char * location, const char return CELIX_SUCCESS; } -celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) { +celix_status_t bundle_addModule(bundle_pt bundle, celix_module_t* module) { celix_arrayList_add(bundle->modules, module); //free previous module info @@ -342,7 +334,7 @@ celix_status_t bundle_closeRevisions(const_bundle_pt bundle) { } celix_status_t bundle_refresh(bundle_pt bundle) { - module_pt module; + celix_module_t* module; celix_arrayList_clear(bundle->modules); celix_status_t status = bundle_createModule(bundle, &module); if (status == CELIX_SUCCESS) { @@ -503,10 +495,11 @@ const char* celix_bundle_getManifestValue(const celix_bundle_t* bnd, const char* bundle_revision_t* rev = NULL; bundleArchive_getCurrentRevision(arch, &rev); if (rev != NULL) { - manifest_pt man = NULL; + celix_bundle_manifest_t* man = NULL; bundleRevision_getManifest(rev, &man); if (man != NULL ) { - header = manifest_getValue(man, attribute); + const celix_properties_t* attr = celix_bundleManifest_getAttributes(man); + header = celix_properties_getAsString(attr, attribute, NULL); } } } @@ -539,7 +532,7 @@ char* celix_bundle_getLocation(const celix_bundle_t *bnd) { } const celix_version_t* celix_bundle_getVersion(const celix_bundle_t *bnd) { - celix_version_t* result = NULL; + const celix_version_t* result = NULL; celix_module_t* mod = NULL; bundle_getCurrentModule(bnd, &mod); if (mod != NULL) { diff --git a/libs/framework/src/bundle_archive.c b/libs/framework/src/bundle_archive.c index 239ef9412..df594991b 100644 --- a/libs/framework/src/bundle_archive.c +++ b/libs/framework/src/bundle_archive.c @@ -184,7 +184,8 @@ celix_bundleArchive_extractBundle(bundle_archive_t* archive, const char* bundleU * Initialize archive by creating the bundle cache directory, optionally extracting the bundle from the bundle file, * reading the bundle state properties, reading the bundle manifest and updating the bundle state properties. */ -static celix_status_t celix_bundleArchive_createCacheDirectory(bundle_archive_pt archive, manifest_pt* manifestOut) { +static celix_status_t celix_bundleArchive_createCacheDirectory(bundle_archive_pt archive, celix_bundle_manifest_t** manifestOut) { + *manifestOut = NULL; if (celix_utils_fileExists(archive->archiveRoot)) { fw_log(archive->fw->logger, CELIX_LOG_LEVEL_TRACE, "Bundle archive root for bundle id %li already exists.", archive->id); @@ -213,14 +214,14 @@ static celix_status_t celix_bundleArchive_createCacheDirectory(bundle_archive_pt } //read manifest from extracted bundle zip - *manifestOut = NULL; + celix_autoptr(celix_bundle_manifest_t) manifest = NULL; char pathBuffer[512]; char* manifestPath = celix_utils_writeOrCreateString(pathBuffer, sizeof(pathBuffer), "%s/%s", archive->resourceCacheRoot, CELIX_BUNDLE_MANIFEST_REL_PATH); if (manifestPath == NULL) { fw_log(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to initialize archive. Failed to create manifest path."); return CELIX_ENOMEM; } - status = manifest_createFromFile(manifestPath, manifestOut); + status = celix_bundleManifest_createFromFile(manifestPath, &manifest); celix_utils_freeStringIfNotEqual(pathBuffer, manifestPath); if (status != CELIX_SUCCESS) { celix_framework_logTssErrors(archive->fw->logger, CELIX_LOG_LEVEL_ERROR); @@ -229,19 +230,18 @@ static celix_status_t celix_bundleArchive_createCacheDirectory(bundle_archive_pt } //populate bundle symbolic name and version from manifest - archive->bundleSymbolicName = celix_utils_strdup(manifest_getValue(*manifestOut, CELIX_FRAMEWORK_BUNDLE_SYMBOLICNAME)); + archive->bundleSymbolicName = celix_utils_strdup(celix_bundleManifest_getBundleSymbolicName(manifest)); if (archive->bundleSymbolicName == NULL) { fw_log(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to initialize archive. Cannot read bundle symbolic name."); - manifest_destroy(*manifestOut); return CELIX_BUNDLE_EXCEPTION; } - archive->bundleVersion = celix_utils_strdup(manifest_getValue(*manifestOut, CELIX_FRAMEWORK_BUNDLE_VERSION)); + archive->bundleVersion = celix_version_toString(celix_bundleManifest_getBundleVersion(manifest)); if (archive->bundleVersion == NULL) { fw_log(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to initialize archive. Cannot read bundle version."); - manifest_destroy(*manifestOut); return CELIX_BUNDLE_EXCEPTION; } + *manifestOut = celix_steal_ptr(manifest); return status; } @@ -249,7 +249,7 @@ celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *arc celix_status_t status = CELIX_SUCCESS; const char* error = NULL; bundle_archive_pt archive = calloc(1, sizeof(*archive)); - bool isSystemBundle = id == CELIX_FRAMEWORK_BUNDLE_ID; + bool isFrameworkBundle = id == CELIX_FRAMEWORK_BUNDLE_ID; if (archive == NULL) { status = CELIX_ENOMEM; @@ -259,7 +259,7 @@ celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *arc archive->fw = fw; archive->id = id; - if (isSystemBundle) { + if (isFrameworkBundle) { archive->resourceCacheRoot = getcwd(NULL, 0); archive->storeRoot = getcwd(NULL, 0); if (archive->resourceCacheRoot == NULL || archive->storeRoot == NULL) { @@ -294,9 +294,9 @@ celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *arc goto init_failed; } - manifest_pt manifest = NULL; - if (isSystemBundle) { - status = manifest_create(&manifest); + celix_bundle_manifest_t* manifest = NULL; + if (isFrameworkBundle) { + status = celix_bundleManifest_createFrameworkManifest(&manifest); } else { status = celix_bundleArchive_createCacheDirectory(archive, &manifest); } @@ -311,7 +311,7 @@ celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *arc goto revision_failed; } - if (!isSystemBundle) { + if (!isFrameworkBundle) { status = celix_bundleArchive_storeBundleStateProperties(archive); if (status != CELIX_SUCCESS) { error = "Could not store properties."; @@ -325,7 +325,7 @@ celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *arc store_prop_failed: revision_failed: dir_failed: - if (!isSystemBundle) { + if (!isFrameworkBundle) { celix_utils_deleteDirectory(archive->archiveRoot, NULL); } init_failed: diff --git a/libs/framework/include_deprecated/bundle_archive.h b/libs/framework/src/bundle_archive.h similarity index 61% rename from libs/framework/include_deprecated/bundle_archive.h rename to libs/framework/src/bundle_archive.h index d53518a1d..d6ceffd4f 100644 --- a/libs/framework/include_deprecated/bundle_archive.h +++ b/libs/framework/src/bundle_archive.h @@ -46,7 +46,7 @@ extern "C" { #endif -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getId(bundle_archive_pt archive, long *id); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getId(bundle_archive_pt archive, long *id); /** * Return the current location of the bundle. @@ -56,36 +56,36 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getId(bundle_arch CELIX_FRAMEWORK_EXPORT celix_status_t bundleArchive_getLocation(bundle_archive_pt archive, const char **location) __attribute__((deprecated("use celix_bundle_getLocation instead"))); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getArchiveRoot(bundle_archive_pt archive, const char **archiveRoot); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getArchiveRoot(bundle_archive_pt archive, const char **archiveRoot); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_revise(bundle_archive_pt archive, const char *location, const char *inputFile); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_rollbackRevise(bundle_archive_pt archive, bool *rolledback); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_rollbackRevise(bundle_archive_pt archive, bool *rolledback); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getRevision(bundle_archive_pt archive, long revNr, bundle_revision_pt *revision); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getCurrentRevision(bundle_archive_pt archive, bundle_revision_pt *revision); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getCurrentRevisionNumber(bundle_archive_pt archive, long *revisionNumber) __attribute__((deprecated)); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getCurrentRevisionNumber(bundle_archive_pt archive, long *revisionNumber) __attribute__((deprecated)); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getRefreshCount(bundle_archive_pt archive, long *refreshCount); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getRefreshCount(bundle_archive_pt archive, long *refreshCount); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_close(bundle_archive_pt archive); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_close(bundle_archive_pt archive); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_closeAndDelete(bundle_archive_pt archive); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_closeAndDelete(bundle_archive_pt archive); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_setLastModified(bundle_archive_pt archive, time_t lastModifiedTime); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_setLastModified(bundle_archive_pt archive, time_t lastModifiedTime); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getLastModified(bundle_archive_pt archive, time_t *lastModified); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getLastModified(bundle_archive_pt archive, time_t *lastModified); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_setPersistentState(bundle_archive_pt archive, bundle_state_e state); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_setPersistentState(bundle_archive_pt archive, bundle_state_e state); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getPersistentState(bundle_archive_pt archive, bundle_state_e *state); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getPersistentState(bundle_archive_pt archive, bundle_state_e *state); /** * @brief Return the last modified time of the bundle archive. @@ -102,14 +102,14 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getPersistentStat * Check errno for more specific error information.when root of the archive is not a directory. * - CELIX_ENOMEM not enough memory for manifest file path. */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t celix_bundleArchive_getLastModified(bundle_archive_pt archive, struct timespec* lastModified); +CELIX_FRAMEWORK_DEPRECATED celix_status_t celix_bundleArchive_getLastModified(bundle_archive_pt archive, struct timespec* lastModified); /** * @brief Return the location of the bundle archive.b * @param[in] archive The bundle archive. * @return The location of the bundle archive. The caller is responsible for freeing the returned string. */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT char* celix_bundleArchive_getLocation(bundle_archive_pt archive); +CELIX_FRAMEWORK_DEPRECATED char* celix_bundleArchive_getLocation(bundle_archive_pt archive); #ifdef __cplusplus diff --git a/libs/framework/src/bundle_context.c b/libs/framework/src/bundle_context.c index 261e7b36b..1a9fd0fe0 100644 --- a/libs/framework/src/bundle_context.c +++ b/libs/framework/src/bundle_context.c @@ -26,22 +26,21 @@ #include #include -#include "celix_utils.h" -#include "celix_constants.h" #include "bundle_context_private.h" -#include "framework_private.h" -#include "bundle.h" +#include "celix_bundle_private.h" +#include "celix_array_list.h" #include "celix_bundle.h" -#include "celix_log.h" -#include "service_tracker.h" +#include "celix_constants.h" +#include "celix_convert_utils.h" #include "celix_dependency_manager.h" +#include "celix_log.h" +#include "celix_module.h" +#include "celix_utils.h" #include "dm_dependency_manager_impl.h" -#include "celix_array_list.h" -#include "module.h" -#include "service_tracker_private.h" +#include "framework_private.h" #include "service_reference_private.h" -#include "celix_array_list.h" -#include "celix_convert_utils.h" +#include "service_tracker.h" +#include "service_tracker_private.h" #define TRACKER_WARN_THRESHOLD_SEC 5 @@ -729,7 +728,7 @@ bool celix_bundleContext_useBundle( } static void bundleContext_cleanupBundleTrackers(bundle_context_t* ctx) { - module_pt module; + celix_module_t* module; const char* symbolicName; bundle_getCurrentModule(ctx->bundle, &module); module_getSymbolicName(module, &symbolicName); @@ -762,7 +761,7 @@ static void bundleContext_cleanupBundleTrackers(bundle_context_t* ctx) { } static void bundleContext_cleanupServiceTrackers(bundle_context_t* ctx) { - module_pt module; + celix_module_t* module; const char* symbolicName; bundle_getCurrentModule(ctx->bundle, &module); module_getSymbolicName(module, &symbolicName); @@ -797,7 +796,7 @@ static void bundleContext_cleanupServiceTrackers(bundle_context_t* ctx) { } static void bundleContext_cleanupServiceTrackerTrackers(bundle_context_t* ctx) { - module_pt module; + celix_module_t* module; const char* symbolicName; bundle_getCurrentModule(ctx->bundle, &module); module_getSymbolicName(module, &symbolicName); @@ -832,7 +831,7 @@ static void bundleContext_cleanupServiceTrackerTrackers(bundle_context_t* ctx) { } static void bundleContext_cleanupServiceRegistration(bundle_context_t* ctx) { - module_pt module; + celix_module_t* module; const char *symbolicName; bundle_getCurrentModule(ctx->bundle, &module); module_getSymbolicName(module, &symbolicName); diff --git a/libs/framework/src/bundle_context_private.h b/libs/framework/src/bundle_context_private.h index 0bc1b5ea3..fcd41d44d 100644 --- a/libs/framework/src/bundle_context_private.h +++ b/libs/framework/src/bundle_context_private.h @@ -29,6 +29,7 @@ #include "celix_long_hash_map.h" #include "listener_hook_service.h" #include "service_tracker.h" +#include "celix_threads.h" #ifdef __cplusplus extern "C" { diff --git a/libs/framework/src/bundle_private.h b/libs/framework/src/bundle_private.h deleted file mode 100644 index f061a9015..000000000 --- a/libs/framework/src/bundle_private.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef BUNDLE_PRIVATE_H_ -#define BUNDLE_PRIVATE_H_ - -#include "bundle.h" -#include "celix_bundle.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct celix_bundle { - bundle_context_pt context; - char *symbolicName; - char *name; - char *group; - char *description; - struct celix_bundle_activator *activator; - bundle_state_e state; - void *handle; - bundle_archive_pt archive; - celix_array_list_t* modules; - - celix_framework_t *framework; -}; - -/** - * Creates a bundle from the given archive. - * @param[in] framework The framework. - * @param[in] archive The archive. - * @param[out] bundleOut The created bundle. - * @return CELIX_SUCCESS if the bundle is created successfully. - */ -celix_status_t -celix_bundle_createFromArchive(celix_framework_t *framework, bundle_archive_pt archive, celix_bundle_t **bundleOut); - -/** - * @brief Get the bundle archive. - * - * @param[in] bundle The bundle. - * @return The bundle archive. - */ -bundle_archive_t *celix_bundle_getArchive(const celix_bundle_t *bundle); - -/** - * Destroys the bundle. - * @param[in] bundle The bundle to destroy. - * @return CELIX_SUCCESS if the bundle is destroyed successfully. - */ -celix_status_t bundle_destroy(celix_bundle_t *bundle); - -#ifdef __cplusplus -} -#endif - -#endif /* BUNDLE_PRIVATE_H_ */ diff --git a/libs/framework/src/bundle_revision.c b/libs/framework/src/bundle_revision.c index a8e76ff28..77e980bb4 100644 --- a/libs/framework/src/bundle_revision.c +++ b/libs/framework/src/bundle_revision.c @@ -24,7 +24,7 @@ #include "bundle_revision_private.h" #include "framework_private.h" -celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *root, const char *location, manifest_pt manifest, bundle_revision_pt *bundle_revision) { +celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *root, const char *location, celix_bundle_manifest_t* manifest, bundle_revision_pt *bundle_revision) { celix_status_t status = CELIX_SUCCESS; bundle_revision_pt revision = calloc(1, sizeof(*revision)); if (revision != NULL) { @@ -44,7 +44,7 @@ celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *ro if (revision != NULL) { bundleRevision_destroy(revision); } else { - manifest_destroy(manifest); + celix_bundleManifest_destroy(manifest); } return status; } @@ -55,7 +55,7 @@ celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *ro celix_status_t bundleRevision_destroy(bundle_revision_pt revision) { if (revision != NULL) { - manifest_destroy(revision->manifest); + celix_bundleManifest_destroy(revision->manifest); free(revision->root); free(revision->location); free(revision); @@ -63,7 +63,7 @@ celix_status_t bundleRevision_destroy(bundle_revision_pt revision) { return CELIX_SUCCESS; } -celix_status_t bundleRevision_getManifest(const bundle_revision_t* revision, manifest_pt* manifest) { +celix_status_t bundleRevision_getManifest(const bundle_revision_t* revision, celix_bundle_manifest_t** manifest) { *manifest = revision->manifest; return CELIX_SUCCESS; } diff --git a/libs/framework/include_deprecated/bundle_revision.h b/libs/framework/src/bundle_revision.h similarity index 83% rename from libs/framework/include_deprecated/bundle_revision.h rename to libs/framework/src/bundle_revision.h index 372b9f9ef..50f41fe85 100644 --- a/libs/framework/include_deprecated/bundle_revision.h +++ b/libs/framework/src/bundle_revision.h @@ -25,7 +25,7 @@ #include "celix_types.h" #include "celix_errno.h" -#include "manifest.h" +#include "celix_bundle_manifest.h" #include "celix_log.h" #include "celix_array_list.h" #include "celix_framework_export.h" @@ -54,7 +54,7 @@ extern "C" { * - CELIX_SUCCESS when no errors are encountered. * - CELIX_ILLEGAL_ARGUMENT If revision is illegal. */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getNumber(const bundle_revision_t* revision, long *revisionNr) __attribute__((deprecated)); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleRevision_getNumber(const bundle_revision_t* revision, long *revisionNr) __attribute__((deprecated)); /** * Retrieves the location of the given revision. @@ -66,7 +66,7 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getNumber(const * - CELIX_SUCCESS when no errors are encountered. * - CELIX_ILLEGAL_ARGUMENT If revision is illegal. */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getLocation(const bundle_revision_t* revision, const char **location); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleRevision_getLocation(const bundle_revision_t* revision, const char **location); /** * Retrieves the root of the given revision. @@ -78,7 +78,7 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getLocation(cons * - CELIX_SUCCESS when no errors are encountered. * - CELIX_ILLEGAL_ARGUMENT If revision is illegal. */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getRoot(const bundle_revision_t* revision, const char **root); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleRevision_getRoot(const bundle_revision_t* revision, const char **root); /** * Retrieves the manifest of the given revision. @@ -90,7 +90,8 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getRoot(const bu * - CELIX_SUCCESS when no errors are encountered. * - CELIX_ILLEGAL_ARGUMENT If revision is illegal. */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getManifest(const bundle_revision_t* revision, manifest_pt *manifest); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleRevision_getManifest(const bundle_revision_t* revision, + celix_bundle_manifest_t** manifest); /** * Originally retrieved the handles of the installed libraries for this revision. diff --git a/libs/framework/src/bundle_revision_private.h b/libs/framework/src/bundle_revision_private.h index 0eb2106a5..f0e18073f 100644 --- a/libs/framework/src/bundle_revision_private.h +++ b/libs/framework/src/bundle_revision_private.h @@ -39,11 +39,11 @@ extern "C" { * A bundle can have multiple revisions. A bundle revision is immutable. */ struct bundleRevision { - celix_framework_t *fw; + celix_framework_t* fw; long revisionNr; - char *root; - char *location; - manifest_pt manifest; + char* root; + char* location; + celix_bundle_manifest_t* manifest; }; /** @@ -60,7 +60,11 @@ struct bundleRevision { * - CELIX_SUCCESS when no errors are encountered. * - CELIX_ENOMEM If allocating memory for bundle_revision failed. */ -celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *root, const char *location, manifest_pt manifest, bundle_revision_pt *bundle_revision); +celix_status_t celix_bundleRevision_create(celix_framework_t* fw, + const char* root, + const char* location, + celix_bundle_manifest_t* manifest, + bundle_revision_pt* bundle_revision); bundle_revision_t* bundleRevision_revise(const bundle_revision_t* revision, const char* updatedBundleUrl); diff --git a/libs/framework/src/celix_bundle_manifest.c b/libs/framework/src/celix_bundle_manifest.c index 2d4c8c2d9..c0e98b75f 100644 --- a/libs/framework/src/celix_bundle_manifest.c +++ b/libs/framework/src/celix_bundle_manifest.c @@ -36,6 +36,7 @@ // Optional manifest attributes #define CELIX_BUNDLE_ACTIVATOR_LIBRARY "CELIX_BUNDLE_ACTIVATOR_LIBRARY" #define CELIX_BUNDLE_PRIVATE_LIBRARIES "CELIX_BUNDLE_PRIVATE_LIBRARIES" +#define CELIX_BUNDLE_DESCRIPTION "CELIX_BUNDLE_DESCRIPTION" #define CELIX_BUNDLE_GROUP "CELIX_BUNDLE_GROUP" struct celix_bundle_manifest { @@ -49,6 +50,7 @@ struct celix_bundle_manifest { //Optional fields char* bundleGroup; + char* description; char* activatorLibrary; celix_array_list_t* privateLibraries; }; @@ -81,7 +83,6 @@ celix_status_t celix_bundleManifest_create(celix_properties_t* attributes, celix return CELIX_SUCCESS; } - celix_status_t celix_bundleManifest_createFromFile(const char* filename, celix_bundle_manifest_t** manifestOut) { celix_properties_t* properties = NULL; celix_status_t status = celix_properties_load(filename, 0, &properties); @@ -91,6 +92,30 @@ celix_status_t celix_bundleManifest_createFromFile(const char* filename, celix_b return celix_bundleManifest_create(properties, manifestOut); } +celix_status_t celix_bundleManifest_createFrameworkManifest(celix_bundle_manifest_t** manifest) { + celix_properties_t* properties = celix_properties_create(); + if (!properties) { + celix_err_push("Failed to create properties for framework manifest"); + return ENOMEM; + } + + celix_status_t status = celix_properties_set(properties, CELIX_BUNDLE_MANIFEST_VERSION, "2.0.0"); + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_SYMBOLIC_NAME, "celix.framework")); + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_NAME, "Celix Framework")); + //status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_VERSION, CELIX_FRAMEWORK_VERSION)); + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_VERSION, "3.0.0")); //TODO + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_GROUP, "Celix")); + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_DESCRIPTION, "Celix Framework")); + + if (status != CELIX_SUCCESS) { + celix_err_push("Failed to set properties for framework manifest"); + celix_properties_destroy(properties); + return status; + } + + return celix_bundleManifest_create(properties, manifest); +} + void celix_bundleManifest_destroy(celix_bundle_manifest_t* manifest) { if (manifest) { celix_properties_destroy(manifest->attributes); @@ -102,6 +127,7 @@ void celix_bundleManifest_destroy(celix_bundle_manifest_t* manifest) { free(manifest->activatorLibrary); free(manifest->bundleGroup); + free(manifest->description); celix_arrayList_destroy(manifest->privateLibraries); free(manifest); @@ -186,6 +212,13 @@ static celix_status_t celix_bundleManifest_setOptionalAttributes(celix_bundle_ma CELIX_ERR_RET_IF_NULL(bundleGroup); } + const char* desc = celix_properties_getAsString(manifest->attributes, CELIX_BUNDLE_DESCRIPTION, NULL); + celix_autofree char* description = NULL; + if (desc) { + description = celix_utils_strdup(desc); + CELIX_ERR_RET_IF_NULL(description); + } + celix_autoptr(celix_array_list_t) privateLibraries = NULL; celix_status_t getStatus = celix_properties_getAsStringArrayList( manifest->attributes, CELIX_BUNDLE_PRIVATE_LIBRARIES, NULL, &privateLibraries); @@ -215,7 +248,7 @@ const char* celix_bundleManifest_getBundleName(celix_bundle_manifest_t* manifest return manifest->bundleName; } -const char* celix_bundleManifest_getSymbolicName(celix_bundle_manifest_t* manifest) { +const char* celix_bundleManifest_getBundleSymbolicName(celix_bundle_manifest_t* manifest) { return manifest->symbolicName; } @@ -235,6 +268,10 @@ const celix_array_list_t* celix_bundleManifest_getBundlePrivateLibraries(celix_b return manifest->privateLibraries; } +const char* celix_bundleManifest_getBundleDescription(celix_bundle_manifest_t* manifest) { + return manifest->description; +} + const char* celix_bundleManifest_getBundleGroup(celix_bundle_manifest_t* manifest) { return manifest->bundleGroup; } diff --git a/libs/framework/src/celix_bundle_manifest.h b/libs/framework/src/celix_bundle_manifest.h index 662f2804d..21b1c8679 100644 --- a/libs/framework/src/celix_bundle_manifest.h +++ b/libs/framework/src/celix_bundle_manifest.h @@ -82,6 +82,23 @@ celix_status_t celix_bundleManifest_create(celix_properties_t* attributes, celix */ celix_status_t celix_bundleManifest_createFromFile(const char* filename, celix_bundle_manifest_t** manifest); +/** + * @brief Create a new framework manifest. + * + * The framework manifest is a special manifest that contains the following manifest attributes: + * - CELIX_BUNDLE_SYMBOLIC_NAME="celix.framework" + * - CELIX_BUNDLE_NAME="Celix Framework" + * - CELIX_BUNDLE_VERSION=CELIX_FRAMEWORK_VERSION + * - CELIX_BUNDLE_MANIFEST_VERSION="2.0.0" + * - CELIX_BUNDLE_GROUP="Celix" + * - CELIX_BUNDLE_DESCRIPTION="Celix Framework" + * + * @param manifest The created framework manifest. + * @return CELIX_SUCCESS if no errors occurred, ENOMEM if memory allocation failed. If an error occurs, an error message + * is logged on celix_err. + */ +celix_status_t celix_bundleManifest_createFrameworkManifest(celix_bundle_manifest_t** manifest); + /** * @brief Destroy the provided manifest. */ @@ -115,7 +132,7 @@ const char* celix_bundleManifest_getBundleName(celix_bundle_manifest_t* manifest * @param[in] manifest The bundle manifest to get the manifest version from. Cannot be NULL. * @return The bundle symbolic name. Will never be NULL. */ -const char* celix_bundleManifest_getSymbolicName(celix_bundle_manifest_t* manifest); +const char* celix_bundleManifest_getBundleSymbolicName(celix_bundle_manifest_t* manifest); /** * @brief Get the bundle version. Returned value is valid as long as the manifest is valid. @@ -150,6 +167,14 @@ const char* celix_bundleManifest_getBundleActivatorLibrary(celix_bundle_manifest */ const celix_array_list_t* celix_bundleManifest_getBundlePrivateLibraries(celix_bundle_manifest_t* manifest); +/** + * @brief Get the bundle description. Returned value is valid as long as the manifest is valid. + * + * @param[in] manifest The bundle manifest to get the manifest version from. Cannot be NULL. + * @return The bundle description. Will be NULL if the manifest does not contain the attribute. + */ +const char* celix_bundleManifest_getBundleDescription(celix_bundle_manifest_t* manifest); + /** * @brief Get the bundle group. Returned value is valid as long as the manifest is valid. * diff --git a/libs/framework/src/celix_bundle_private.h b/libs/framework/src/celix_bundle_private.h new file mode 100644 index 000000000..d866f3119 --- /dev/null +++ b/libs/framework/src/celix_bundle_private.h @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef BUNDLE_PRIVATE_H_ +#define BUNDLE_PRIVATE_H_ + +#include "celix_bundle.h" +#include "celix_module.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct celix_bundle { + bundle_context_pt context; + char *symbolicName; + char *name; + char *group; + char *description; + struct celix_bundle_activator *activator; + bundle_state_e state; + void *handle; + bundle_archive_pt archive; + celix_array_list_t* modules; + + celix_framework_t *framework; +}; + +typedef struct celix_bundle_activator celix_bundle_activator_t; + + + +/** + * Creates a bundle from the given archive. + * @param[in] framework The framework. + * @param[in] archive The archive. + * @param[out] bundleOut The created bundle. + * @return CELIX_SUCCESS if the bundle is created successfully. + */ +celix_status_t +celix_bundle_createFromArchive(celix_framework_t *framework, bundle_archive_pt archive, celix_bundle_t **bundleOut); + +/** + * @brief Get the bundle archive. + * + * @param[in] bundle The bundle. + * @return The bundle archive. + */ +bundle_archive_t *celix_bundle_getArchive(const celix_bundle_t *bundle); + +/** + * Destroys the bundle. + * @param[in] bundle The bundle to destroy. + * @return CELIX_SUCCESS if the bundle is destroyed successfully. + */ +celix_status_t bundle_destroy(celix_bundle_t *bundle); + +/** + * @brief Get the bundle symbolic name. + */ +celix_bundle_context_t* celix_bundle_getContext(const celix_bundle_t *bundle); + +/** + * @brief Set the bundle context. + */ +void celix_bundle_setContext(celix_bundle_t *bundle, celix_bundle_context_t *context); + + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_isSystemBundle(const celix_bundle_t *bundle, bool *systemBundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getArchive(const celix_bundle_t *bundle, bundle_archive_pt *archive); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getCurrentModule(const celix_bundle_t *bundle, celix_module_t** module); + +CELIX_FRAMEWORK_DEPRECATED celix_array_list_t *bundle_getModules(const celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED void *bundle_getHandle(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED void bundle_setHandle(celix_bundle_t *bundle, void *handle); + +CELIX_FRAMEWORK_DEPRECATED celix_bundle_activator_t *bundle_getActivator(const celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setActivator(celix_bundle_t *bundle, celix_bundle_activator_t *activator); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getEntry(const celix_bundle_t *bundle, const char *name, char **entry); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_update(celix_bundle_t *bundle, const char *inputFile); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_stop(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setState(celix_bundle_t *bundle, bundle_state_e state); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setPersistentStateInactive(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setPersistentStateUninstalled(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED void uninstallBundle(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_revise(celix_bundle_t *bundle, const char *location, const char *inputFile); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_addModule(celix_bundle_t *bundle, celix_module_t* celix_module); + +// Service Reference Functions +CELIX_FRAMEWORK_DEPRECATED celix_array_list_t *getUsingBundles(service_reference_pt reference); + +CELIX_FRAMEWORK_DEPRECATED int compareTo(service_reference_pt a, service_reference_pt b); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getState(const celix_bundle_t *bundle, bundle_state_e *state); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_closeAndDelete(const celix_bundle_t *bundle); + +CELIX_FRAMEWORK_EXPORT celix_status_t bundle_close(const celix_bundle_t *bundle) + __attribute__((deprecated("bundle_close is deprecated and does nothing"))); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_refresh(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getBundleId(const celix_bundle_t *bundle, long *id); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getRegisteredServices(celix_bundle_t *bundle, celix_array_list_t **list); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getServicesInUse(celix_bundle_t *bundle, celix_array_list_t **list); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getFramework(const celix_bundle_t *bundle, celix_framework_t **framework); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getBundleLocation(const celix_bundle_t *bundle, const char **location); + +#ifdef __cplusplus +} +#endif + +#endif /* BUNDLE_PRIVATE_H_ */ diff --git a/libs/framework/src/celix_module.h b/libs/framework/src/celix_module.h new file mode 100644 index 000000000..af83623b2 --- /dev/null +++ b/libs/framework/src/celix_module.h @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef CELIX_MODULE_H_ +#define CELIX_MODULE_H_ + +typedef struct celix_module celix_module_t; + +#include + +#include "celix_bundle_manifest.h" +#include "celix_framework_export.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a new module based on the provided manifest. + * @return A new module or NULL if the module could not be created. If NULL is returned, an error log is written to + * celix err. + */ +celix_module_t* module_create(celix_bundle_manifest_t* manifest, celix_bundle_t* bundle); + +celix_module_t* module_createFrameworkModule(celix_framework_t* fw, celix_bundle_t *bundle); + +void module_destroy(celix_module_t* module); + +/** + * Define the cleanup function for a celix_bundleManifest_t, so that it can be used with celix_autoptr. + */ +CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_module_t, module_destroy) + +unsigned int module_hash(void *module); + +int module_equals(void *module, void *compare); + +const celix_version_t* module_getVersion(celix_module_t* module); + +celix_status_t module_getSymbolicName(celix_module_t* module, const char **symbolicName); + +char *module_getId(celix_module_t* module); + +bool module_isResolved(celix_module_t* module); + +void module_setResolved(celix_module_t* module); + +celix_bundle_t *module_getBundle(celix_module_t* module); + +celix_array_list_t *module_getDependents(celix_module_t* module); + +celix_status_t module_getGroup(celix_module_t* module, const char **group); + +celix_status_t module_getName(celix_module_t* module, const char **name); + +celix_status_t module_getDescription(celix_module_t* module, const char **description); + +#ifdef __cplusplus +} +#endif + +#endif /* CELIX_MODULE_H_ */ diff --git a/libs/framework/src/celix_module_private.h b/libs/framework/src/celix_module_private.h index 10756d83b..d56ae22ef 100644 --- a/libs/framework/src/celix_module_private.h +++ b/libs/framework/src/celix_module_private.h @@ -20,7 +20,7 @@ #ifndef CELIX_CELIX_MODULE_PRIVATE_H #define CELIX_CELIX_MODULE_PRIVATE_H -#include "module.h" +#include "celix_module.h" #ifdef __cplusplus extern "C" { @@ -31,8 +31,6 @@ celix_status_t celix_module_loadLibraries(celix_module_t *module); celix_status_t celix_module_closeLibraries(celix_module_t *module); -void *celix_module_getBundleActivatorHandler(celix_module_t *module); - #ifdef __cplusplus } #endif diff --git a/libs/framework/src/dm_component_impl.c b/libs/framework/src/dm_component_impl.c index 7c204e04d..f41c0f7f0 100644 --- a/libs/framework/src/dm_component_impl.c +++ b/libs/framework/src/dm_component_impl.c @@ -29,6 +29,7 @@ #include "celix_filter.h" #include "dm_component_impl.h" #include "celix_framework.h" +#include "hash_map.h" static const char * const CELIX_DM_PRINT_OK_COLOR = "\033[92m"; static const char * const CELIX_DM_PRINT_WARNING_COLOR = "\033[93m"; diff --git a/libs/framework/src/dm_dependency_manager_impl.c b/libs/framework/src/dm_dependency_manager_impl.c index d4e40f465..4c27305c4 100644 --- a/libs/framework/src/dm_dependency_manager_impl.c +++ b/libs/framework/src/dm_dependency_manager_impl.c @@ -23,14 +23,15 @@ #include #include -#include "bundle_context.h" -#include "dm_component_impl.h" -#include "dm_dependency_manager_impl.h" -#include "celix_dependency_manager.h" +#include "celix_bundle_context.h" +#include "celix_array_list.h" #include "celix_bundle.h" +#include "celix_bundle_private.h" #include "celix_compiler.h" +#include "celix_dependency_manager.h" #include "celix_framework.h" -#include "celix_array_list.h" +#include "dm_component_impl.h" +#include "dm_dependency_manager_impl.h" celix_dependency_manager_t* celix_private_dependencyManager_create(celix_bundle_context_t *context) { celix_dependency_manager_t *manager = calloc(1, sizeof(*manager)); @@ -184,8 +185,7 @@ celix_status_t celix_dependencyManager_removeAllComponentsAsync(celix_dependency static void celix_dm_getInfoCallback(void *handle, const celix_bundle_t *bnd) { celix_dependency_manager_info_t **out = handle; - celix_bundle_context_t *context = NULL; - bundle_getContext((celix_bundle_t*)bnd, &context); + celix_bundle_context_t *context = celix_bundle_getContext(bnd); celix_dependency_manager_t *mng = celix_bundleContext_getDependencyManager(context); celix_dependency_manager_info_t *info = calloc(1, sizeof(*info)); @@ -218,8 +218,7 @@ celix_dependency_manager_info_t* celix_dependencyManager_createInfo(celix_depend static void celix_dm_getInfosCallback(void* handle, const celix_bundle_t* bnd) { celix_array_list_t* infos = handle; - celix_bundle_context_t* context = NULL; - bundle_getContext((celix_bundle_t*)bnd, &context); + celix_bundle_context_t* context = celix_bundle_getContext(bnd); celix_dependency_manager_t* mng = celix_bundleContext_getDependencyManager(context); celix_dependency_manager_info_t* info = calloc(1, sizeof(*info)); @@ -265,8 +264,7 @@ static void celix_dm_allComponentsActiveCallback(void *handle, const celix_bundl return; } - celix_bundle_context_t *context = NULL; - bundle_getContext((celix_bundle_t*)bnd, &context); + celix_bundle_context_t *context = celix_bundle_getContext(bnd); celix_dependency_manager_t *mng = celix_bundleContext_getDependencyManager(context); bool allActive = celix_dependencyManager_areComponentsActive(mng); if (!allActive) { diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c index 5d2044a8b..1aff73adb 100644 --- a/libs/framework/src/framework.c +++ b/libs/framework/src/framework.c @@ -41,7 +41,7 @@ #include "bundle_archive_private.h" #include "bundle_context_private.h" -#include "bundle_private.h" +#include "celix_bundle_private.h" #include "celix_err.h" #include "celix_scheduled_event.h" #include "celix_stdlib_cleanup.h" @@ -146,7 +146,7 @@ static inline bool fw_bundleEntry_removeBundleEntry(celix_framework_t *fw, celix return found; } -static celix_status_t framework_markBundleResolved(framework_pt framework, module_pt module); +static celix_status_t framework_markBundleResolved(framework_pt framework, celix_module_t* module); long framework_getNextBundleId(framework_pt framework); @@ -262,7 +262,7 @@ celix_status_t framework_create(framework_pt *out, celix_properties_t* config) { framework->registry = celix_serviceRegistry_create(framework); bundle_context_t *context = NULL; status = CELIX_DO_IF(status, bundleContext_create(framework, framework->logger, framework->bundle, &context)); - status = CELIX_DO_IF(status, bundle_setContext(framework->bundle, context)); + CELIX_DO_IF(status, celix_bundle_setContext(framework->bundle, context)); //create framework bundle entry celix_framework_bundle_entry_t *entry = fw_bundleEntry_create(framework->bundle); @@ -317,8 +317,7 @@ celix_status_t framework_destroy(framework_pt framework) { bool systemBundle = false; bundle_isSystemBundle(bnd, &systemBundle); if (systemBundle) { - bundle_context_t *context = NULL; - bundle_getContext(framework->bundle, &context); + bundle_context_t *context = celix_bundle_getContext(framework->bundle); bundleContext_destroy(context); } @@ -408,7 +407,9 @@ celix_status_t fw_init(framework_pt framework) { activator->stop = celix_frameworkBundle_stop; activator->destroy = celix_frameworkBundle_destroy; status = CELIX_DO_IF(status, bundle_setActivator(framework->bundle, activator)); - status = CELIX_DO_IF(status, bundle_getContext(framework->bundle, &validateContext)); + if (status == CELIX_SUCCESS) { + validateContext = celix_bundle_getContext(framework->bundle); + } status = CELIX_DO_IF(status, activator->create(validateContext, &activator->userData)); bool fwBundleCreated = status == CELIX_SUCCESS; status = CELIX_DO_IF(status, activator->start(activator->userData, validateContext)); @@ -729,61 +730,61 @@ bool celix_framework_isBundleAlreadyInstalled(celix_framework_t* fw, const char* return alreadyExists; } -celix_status_t fw_getDependentBundles(framework_pt framework, bundle_pt exporter, celix_array_list_t** list) { - celix_status_t status = CELIX_SUCCESS; - - if (*list != NULL || exporter == NULL || framework == NULL) { - return CELIX_ILLEGAL_ARGUMENT; - } - - celix_array_list_t* modules; - unsigned int modIdx = 0; - *list = celix_arrayList_create(); - - modules = bundle_getModules(exporter); - for (modIdx = 0; modIdx < celix_arrayList_size(modules); modIdx++) { - module_pt module = (module_pt)celix_arrayList_get(modules, modIdx); - celix_array_list_t* dependents = module_getDependents(module); - if (dependents != NULL) { - unsigned int depIdx = 0; - for (depIdx = 0; depIdx < celix_arrayList_size(dependents); depIdx++) { - module_pt dependent = (module_pt)celix_arrayList_get(dependents, depIdx); - celix_arrayList_add(*list, module_getBundle(dependent)); - } - celix_arrayList_destroy(dependents); - } - } - - framework_logIfError(framework->logger, status, NULL, "Cannot get dependent bundles"); - - return status; -} - -celix_status_t fw_populateDependentGraph(framework_pt framework, bundle_pt exporter, hash_map_pt* map) { - celix_status_t status = CELIX_SUCCESS; - - if (framework == NULL || exporter == NULL) { - return CELIX_ILLEGAL_ARGUMENT; - } - - celix_array_list_t* dependents = NULL; - if ((status = fw_getDependentBundles(framework, exporter, &dependents)) == CELIX_SUCCESS) { - if (dependents != NULL) { - unsigned int depIdx = 0; - for (depIdx = 0; depIdx < celix_arrayList_size(dependents); depIdx++) { - if (!hashMap_containsKey(*map, celix_arrayList_get(dependents, depIdx))) { - hashMap_put(*map, celix_arrayList_get(dependents, depIdx), celix_arrayList_get(dependents, depIdx)); - fw_populateDependentGraph(framework, (bundle_pt)celix_arrayList_get(dependents, depIdx), map); - } - } - celix_arrayList_destroy(dependents); - } - } - - framework_logIfError(framework->logger, status, NULL, "Cannot populate dependent graph"); - - return status; -} +//celix_status_t fw_getDependentBundles(framework_pt framework, bundle_pt exporter, celix_array_list_t** list) { +// celix_status_t status = CELIX_SUCCESS; +// +// if (*list != NULL || exporter == NULL || framework == NULL) { +// return CELIX_ILLEGAL_ARGUMENT; +// } +// +// celix_array_list_t* modules; +// unsigned int modIdx = 0; +// *list = celix_arrayList_create(); +// +// modules = bundle_getModules(exporter); +// for (modIdx = 0; modIdx < celix_arrayList_size(modules); modIdx++) { +// celix_module_t* module = celix_arrayList_get(modules, modIdx); +// celix_array_list_t* dependents = module_getDependents(module); +// if (dependents != NULL) { +// unsigned int depIdx = 0; +// for (depIdx = 0; depIdx < celix_arrayList_size(dependents); depIdx++) { +// celix_module_t* dependent = celix_arrayList_get(dependents, depIdx); +// celix_arrayList_add(*list, module_getBundle(dependent)); +// } +// celix_arrayList_destroy(dependents); +// } +// } +// +// framework_logIfError(framework->logger, status, NULL, "Cannot get dependent bundles"); +// +// return status; +//} + +//celix_status_t fw_populateDependentGraph(framework_pt framework, bundle_pt exporter, hash_map_pt* map) { +// celix_status_t status = CELIX_SUCCESS; +// +// if (framework == NULL || exporter == NULL) { +// return CELIX_ILLEGAL_ARGUMENT; +// } +// +// celix_array_list_t* dependents = NULL; +// if ((status = fw_getDependentBundles(framework, exporter, &dependents)) == CELIX_SUCCESS) { +// if (dependents != NULL) { +// unsigned int depIdx = 0; +// for (depIdx = 0; depIdx < celix_arrayList_size(dependents); depIdx++) { +// if (!hashMap_containsKey(*map, celix_arrayList_get(dependents, depIdx))) { +// hashMap_put(*map, celix_arrayList_get(dependents, depIdx), celix_arrayList_get(dependents, depIdx)); +// fw_populateDependentGraph(framework, (bundle_pt)celix_arrayList_get(dependents, depIdx), map); +// } +// } +// celix_arrayList_destroy(dependents); +// } +// } +// +// framework_logIfError(framework->logger, status, NULL, "Cannot populate dependent graph"); +// +// return status; +//} celix_status_t fw_registerService(framework_pt framework, service_registration_pt *registration, long bndId, const char* serviceName, const void* svcObj, celix_properties_t *properties) { celix_status_t status = CELIX_SUCCESS; @@ -1012,7 +1013,7 @@ long framework_getNextBundleId(framework_pt framework) { return nextId; } -static celix_status_t framework_markBundleResolved(framework_pt framework, module_pt module) { +static celix_status_t framework_markBundleResolved(framework_pt framework, celix_module_t* module) { celix_status_t status = CELIX_SUCCESS; bundle_pt bundle = module_getBundle(module); bundle_state_e state; @@ -2106,8 +2107,8 @@ static celix_status_t celix_framework_stopBundleEntryInternal(celix_framework_t* CELIX_DO_IF(status, fw_fireBundleEvent(framework, OSGI_FRAMEWORK_BUNDLE_EVENT_STOPPING, bndEntry)); activator = bundle_getActivator(bndEntry->bnd); - status = CELIX_DO_IF(status, bundle_getContext(bndEntry->bnd, &context)); if (status == CELIX_SUCCESS) { + context = celix_bundle_getContext(bndEntry->bnd); if (activator->stop != NULL) { status = CELIX_DO_IF(status, activator->stop(activator->userData, context)); if (status == CELIX_SUCCESS) { @@ -2130,7 +2131,7 @@ static celix_status_t celix_framework_stopBundleEntryInternal(celix_framework_t* if (bndEntry->bndId > CELIX_FRAMEWORK_BUNDLE_ID) { //"normal" bundle if (status == CELIX_SUCCESS) { - module_pt module = NULL; + celix_module_t* module = NULL; const char *symbolicName = NULL; long id = 0; bundle_getCurrentModule(bndEntry->bnd, &module); @@ -2140,7 +2141,7 @@ static celix_status_t celix_framework_stopBundleEntryInternal(celix_framework_t* if (context != NULL) { status = CELIX_DO_IF(status, bundleContext_destroy(context)); - status = CELIX_DO_IF(status, bundle_setContext(bndEntry->bnd, NULL)); + CELIX_DO_IF(status, celix_bundle_setContext(bndEntry->bnd, NULL)); } status = CELIX_DO_IF(status, bundle_setState(bndEntry->bnd, CELIX_BUNDLE_STATE_RESOLVED)); @@ -2158,7 +2159,7 @@ static celix_status_t celix_framework_stopBundleEntryInternal(celix_framework_t* } if (status != CELIX_SUCCESS) { - module_pt module = NULL; + celix_module_t* module = NULL; const char *symbolicName = NULL; long id = 0; bundle_getCurrentModule(bndEntry->bnd, &module); @@ -2230,7 +2231,7 @@ celix_status_t celix_framework_startBundleEntry(celix_framework_t* framework, ce celix_status_t status = CELIX_SUCCESS; const char* error = ""; const char* name = ""; - module_pt module = NULL; + celix_module_t* module = NULL; celix_bundle_context_t* context = NULL; celix_bundle_activator_t* activator = NULL; @@ -2274,7 +2275,7 @@ celix_status_t celix_framework_startBundleEntry(celix_framework_t* framework, ce bundle_getCurrentModule(bndEntry->bnd, &module); module_getSymbolicName(module, &name); status = CELIX_DO_IF(status, bundleContext_create(framework, framework->logger, bndEntry->bnd, &context)); - status = CELIX_DO_IF(status, bundle_setContext(bndEntry->bnd, context)); + CELIX_DO_IF(status, celix_bundle_setContext(bndEntry->bnd, context)); if (status == CELIX_SUCCESS) { activator = calloc(1,(sizeof(*activator))); @@ -2294,9 +2295,8 @@ celix_status_t celix_framework_startBundleEntry(celix_framework_t* framework, ce status = CELIX_DO_IF(status, bundle_setState(bndEntry->bnd, CELIX_BUNDLE_STATE_STARTING)); CELIX_DO_IF(status, fw_fireBundleEvent(framework, OSGI_FRAMEWORK_BUNDLE_EVENT_STARTING, bndEntry)); - status = CELIX_DO_IF(status, bundle_getContext(bndEntry->bnd, &context)); - if (status == CELIX_SUCCESS) { + context = celix_bundle_getContext(bndEntry->bnd); if (activator->create != NULL) { status = CELIX_DO_IF(status, activator->create(context, &userData)); if (status == CELIX_SUCCESS) { @@ -2320,7 +2320,7 @@ celix_status_t celix_framework_startBundleEntry(celix_framework_t* framework, ce if (createCalled && activator->destroy) { activator->destroy(activator->userData, context); } - bundle_setContext(bndEntry->bnd, NULL); + celix_bundle_setContext(bndEntry->bnd, NULL); bundle_setActivator(bndEntry->bnd, NULL); bundleContext_destroy(context); free(activator); diff --git a/libs/framework/src/framework_bundle_lifecycle_handler.c b/libs/framework/src/framework_bundle_lifecycle_handler.c index 40caeb283..1686e7340 100644 --- a/libs/framework/src/framework_bundle_lifecycle_handler.c +++ b/libs/framework/src/framework_bundle_lifecycle_handler.c @@ -17,11 +17,11 @@ * under the License. */ -#include +#include "celix_bundle_private.h" +#include "celix_log.h" #include "celix_utils.h" #include "framework_private.h" -#include "celix_log.h" -#include "bundle.h" +#include static void celix_framework_cleanupBundleLifecycleHandler(celix_framework_t* fw, celix_framework_bundle_lifecycle_handler_t *handler) { celixThreadMutex_lock(&fw->bundleLifecycleHandling.mutex); diff --git a/libs/framework/src/framework_private.h b/libs/framework/src/framework_private.h index a00d6d8c6..572cab485 100644 --- a/libs/framework/src/framework_private.h +++ b/libs/framework/src/framework_private.h @@ -24,7 +24,7 @@ #include "celix_framework.h" #include "framework.h" -#include "manifest.h" +#include "celix_bundle_manifest.h" #include "hash_map.h" #include "celix_array_list.h" #include "celix_errno.h" diff --git a/libs/framework/src/manifest.c b/libs/framework/src/manifest.c deleted file mode 100644 index 709d94351..000000000 --- a/libs/framework/src/manifest.c +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * manifest.c - * - * \date Jul 5, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include -#include -#include - -#include "celix_err.h" -#include "celix_errno.h" -#include "celix_stdio_cleanup.h" -#include "celix_stdlib_cleanup.h" -#include "celix_utils.h" -#include "manifest.h" -#include "utils.h" - -celix_status_t manifest_create(manifest_pt *manifest) { - celix_status_t status = CELIX_SUCCESS; - do { - celix_autofree manifest_pt manifestPtr = NULL; - manifestPtr = malloc(sizeof(**manifest)); - if (manifestPtr == NULL) { - status = CELIX_ENOMEM; - break; - } - celix_autoptr(celix_properties_t) mainAttributes = celix_properties_create(); - if (mainAttributes == NULL) { - status = CELIX_ENOMEM; - break; - } - manifestPtr->attributes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - if (manifestPtr->attributes == NULL) { - status = CELIX_ENOMEM; - break; - } - manifestPtr->mainAttributes = celix_steal_ptr(mainAttributes); - *manifest = celix_steal_ptr(manifestPtr); - } while(false); - - if (status != CELIX_SUCCESS) { - celix_err_pushf("Cannot create manifest: %s", celix_strerror(status)); - } - return status; -} - -manifest_pt manifest_clone(manifest_pt manifest) { - celix_status_t status = CELIX_SUCCESS; - - celix_auto(manifest_pt) clone = NULL; - status = manifest_create(&clone); - if (status == CELIX_SUCCESS) { - CELIX_PROPERTIES_ITERATE(manifest->mainAttributes, visit) { - celix_properties_set(clone->mainAttributes, visit.key, visit.entry.value); - } - hash_map_iterator_t iter = hashMapIterator_construct(manifest->attributes); - while (hashMapIterator_hasNext(&iter)) { - hash_map_entry_pt entry = hashMapIterator_nextEntry(&iter); - celix_autofree char* attrKey = celix_utils_strdup(hashMapEntry_getKey(entry)); - if (attrKey == NULL) { - return NULL; - } - celix_properties_t* value = hashMapEntry_getValue(entry); - celix_properties_t* cloneValue = celix_properties_copy(value); - if (cloneValue == NULL) { - return NULL; - } - hashMap_put(clone->attributes, celix_steal_ptr(attrKey), cloneValue); - } - } - - return celix_steal_ptr(clone); -} - -celix_status_t manifest_destroy(manifest_pt manifest) { - if (manifest != NULL) { - celix_properties_destroy(manifest->mainAttributes); - hash_map_iterator_t iter = hashMapIterator_construct(manifest->attributes); - while (hashMapIterator_hasNext(&iter)) { - hash_map_entry_pt entry = hashMapIterator_nextEntry(&iter); - celix_properties_t* value = hashMapEntry_getValue(entry); - celix_properties_destroy(value); - } - hashMap_destroy(manifest->attributes, true, false); - manifest->mainAttributes = NULL; - manifest->attributes = NULL; - free(manifest); - manifest = NULL; - } - return CELIX_SUCCESS; -} - -celix_status_t manifest_createFromFile(const char *filename, manifest_pt *manifest) { - celix_status_t status; - - celix_auto(manifest_pt) manifestNew = NULL; - status = manifest_create(&manifestNew); - - status = CELIX_DO_IF(status, manifest_read(manifestNew, filename)); - if (status == CELIX_SUCCESS) { - *manifest = celix_steal_ptr(manifestNew); - } else { - celix_err_pushf("Cannot create manifest from file: %s", celix_strerror(status)); - } - return status; -} - -//LCOV_EXCL_START -void manifest_clear(manifest_pt manifest) { - -} -//LCOV_EXCL_STOP - - celix_properties_t* manifest_getMainAttributes(manifest_pt manifest) { - return manifest->mainAttributes; -} - -celix_status_t manifest_getEntries(manifest_pt manifest, hash_map_pt *map) { - *map = manifest->attributes; - return CELIX_SUCCESS; -} - -celix_status_t manifest_read(manifest_pt manifest, const char *filename) { - celix_status_t status = CELIX_SUCCESS; - - celix_autoptr(FILE) file = fopen(filename, "r"); - if (file != NULL) { - status = manifest_readFromStream(manifest, file); - } else { - status = CELIX_ERROR_MAKE(CELIX_FACILITY_CERRNO,errno); - } - - if (status != CELIX_SUCCESS) { - celix_err_pushf("Cannot read manifest %s: %s", filename, celix_strerror(status)); - } - - return status; -} - -celix_status_t manifest_readFromStream(manifest_pt manifest, FILE* stream) { - char stackBuf[512]; - char *bytes = stackBuf; - - // get file size - if (fseek(stream, 0L, SEEK_END) == -1) { - return CELIX_ERROR_MAKE(CELIX_FACILITY_CERRNO, errno); - } - long int size = ftell(stream); - if (size < 0) { - return CELIX_ERROR_MAKE(CELIX_FACILITY_CERRNO,errno); - } else if (size >= INT_MAX) { - celix_err_pushf("Manifest error: file too large - %ld", size); - return CELIX_BUNDLE_EXCEPTION; - } - rewind(stream); - - celix_autofree char* heapBuf = NULL; - if (size+1 > sizeof(stackBuf)) { - heapBuf = bytes = malloc(size+1); - if (heapBuf == NULL) { - celix_err_pushf("Manifest error: failed to allocate %ld bytes", size); - return CELIX_ENOMEM; - } - } - - if(fread(bytes, 1, size, stream) != (size_t)size) { - return CELIX_FILE_IO_EXCEPTION; - } - // Force a new line at the end of the manifest to deal with broken manifest without any line-ending - bytes[size++] = '\n'; - - const char* key = NULL; - int last = 0; - int current = 0; - celix_properties_t *headers = manifest->mainAttributes; - for (int i = 0; i < size; i++) - { - // skip \r and \n if it is followed by another \n - // (we catch the blank line case in the next iteration) - if (bytes[i] == '\r') - { - if ((i + 1 < size) && (bytes[i + 1] == '\n')) - { - continue; - } - } - if (bytes[i] == '\n') - { - if ((i + 1 < size) && (bytes[i + 1] == ' ')) - { - i++; - continue; - } - } - // If we don't have a key yet and see the first : we parse it as the key - // and skip the : that follows it. - if ((key == NULL) && (bytes[i] == ':')) - { - key = &bytes[last]; - // precondition: current <= i - bytes[current++] = '\0'; - if ((i + 1 < size) && (bytes[i + 1] == ' ')) - { - last = current + 1; - continue; - } - else - { - celix_err_pushf("Manifest error: Missing space separator - %s", key); - return CELIX_INVALID_SYNTAX; - } - } - // if we are at the end of a line - if (bytes[i] == '\n') - { - // and it is a blank line stop parsing (main attributes are done) - if ((last == current) && (key == NULL)) - { - headers = NULL; - continue; - } - // Otherwise, parse the value and add it to the map (we return - // if we don't have a key or the key already exist). - const char* value = &bytes[last]; - // precondition: current <= i - bytes[current++] = '\0'; - - if (key == NULL) - { - celix_err_pushf("Manifest error: Missing attribute name - %s", value); - return CELIX_INVALID_SYNTAX; - } - else if (headers != NULL && celix_properties_get(headers, key, NULL) != NULL) - { - celix_err_pushf("Manifest error: Duplicate attribute name - %s", key); - return CELIX_INVALID_SYNTAX; - } - if (headers == NULL) { - // beginning of individual-section - if (strcasecmp(key, "Name")) { - celix_err_push("Manifest error: individual-section missing Name attribute"); - return CELIX_INVALID_SYNTAX; - } - headers = hashMap_get(manifest->attributes, value); - if (headers == NULL) { - celix_autofree char* name = celix_utils_strdup(value); - if (name == NULL) { - return CELIX_ENOMEM; - } - headers = celix_properties_create(); - if (headers == NULL) { - return CELIX_ENOMEM; - } - hashMap_put(manifest->attributes, (void*)celix_steal_ptr(name), headers); - } - } else if (headers == manifest->mainAttributes && celix_properties_size(headers) == 0) { - // beginning of main-section - if (strcasecmp(key, "Manifest-Version")) { - celix_err_push("Manifest error: main-section must start with Manifest-Version"); - return CELIX_INVALID_SYNTAX; - } - } - celix_properties_set(headers, key, value); - last = current; - key = NULL; - } - else - { - // precondition: current <= i - // write back the byte if it needs to be included in the key or the value. - bytes[current++] = bytes[i]; - } - } - if (celix_properties_size(manifest->mainAttributes) == 0) { - celix_err_push("Manifest error: Empty"); - return CELIX_INVALID_SYNTAX; - } - return CELIX_SUCCESS; -} - -//LCOV_EXCL_START -void manifest_write(manifest_pt manifest, const char * filename) { - -} -//LCOV_EXCL_STOP - -const char* manifest_getValue(manifest_pt manifest, const char* name) { - const char* val = celix_properties_get(manifest->mainAttributes, name, NULL); - bool isEmpty = utils_isStringEmptyOrNull(val); - return isEmpty ? NULL : val; -} diff --git a/libs/framework/src/manifest_parser.c b/libs/framework/src/manifest_parser.c deleted file mode 100644 index 1b1e38954..000000000 --- a/libs/framework/src/manifest_parser.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * manifest_parser.c - * - * \date Jul 12, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include - -#include "celix_utils.h" -#include "celix_constants.h" -#include "manifest_parser.h" -#include "celix_errno.h" -#include "celix_log.h" - -struct manifestParser { - module_pt owner; - manifest_pt manifest; - celix_version_t* bundleVersion; - // TODO: Implement Requirement-Capability-Model using RCM library -}; - -celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, manifest_parser_pt *manifest_parser) { - celix_status_t status; - manifest_parser_pt parser; - - status = CELIX_SUCCESS; - parser = (manifest_parser_pt) malloc(sizeof(*parser)); - if (parser) { - const char * bundleVersion = NULL; - parser->manifest = manifest; - parser->owner = owner; - - bundleVersion = manifest_getValue(manifest, CELIX_FRAMEWORK_BUNDLE_VERSION); - if (bundleVersion != NULL) { - parser->bundleVersion = celix_version_createVersionFromString(bundleVersion); - } else { - parser->bundleVersion = celix_version_createEmptyVersion(); - } - - *manifest_parser = parser; - - status = CELIX_SUCCESS; - } else { - status = CELIX_ENOMEM; - } - - framework_logIfError(celix_frameworkLogger_globalLogger(), status, NULL, "Cannot create manifest parser"); - - return status; -} - -celix_status_t manifestParser_destroy(manifest_parser_pt mp) { - celix_version_destroy(mp->bundleVersion); - mp->bundleVersion = NULL; - mp->manifest = NULL; - mp->owner = NULL; - - free(mp); - - return CELIX_SUCCESS; -} - -static celix_status_t manifestParser_getDuplicateEntry(manifest_parser_pt parser, const char* entryName, char **result) { - const char *val = manifest_getValue(parser->manifest, entryName); - if (result != NULL && val == NULL) { - *result = NULL; - } else if (result != NULL) { - *result = celix_utils_strdup(val); - } - return CELIX_SUCCESS; -} - -celix_status_t manifestParser_getAndDuplicateGroup(manifest_parser_pt parser, char **group) { - return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_GROUP, group); -} - -celix_status_t manifestParser_getAndDuplicateSymbolicName(manifest_parser_pt parser, char **symbolicName) { - return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_SYMBOLICNAME, symbolicName); -} - -celix_status_t manifestParser_getAndDuplicateName(manifest_parser_pt parser, char **name) { - return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_NAME, name); -} - -celix_status_t manifestParser_getAndDuplicateDescription(manifest_parser_pt parser, char **description) { - return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_DESCRIPTION, description); -} - -celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, celix_version_t **version) { - *version = celix_version_copy(parser->bundleVersion); - return *version == NULL ? CELIX_ENOMEM : CELIX_SUCCESS; -} \ No newline at end of file diff --git a/libs/framework/src/manifest_parser.h b/libs/framework/src/manifest_parser.h deleted file mode 100644 index 0f9954067..000000000 --- a/libs/framework/src/manifest_parser.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * manifest_parser.h - * - * \date Jul 13, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef MANIFEST_PARSER_H_ -#define MANIFEST_PARSER_H_ - -#include "module.h" -#include "celix_version.h" -#include "manifest.h" - -typedef struct manifestParser * manifest_parser_pt; - -celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, manifest_parser_pt *manifest_parser); -celix_status_t manifestParser_destroy(manifest_parser_pt mp); - -celix_status_t manifestParser_getAndDuplicateSymbolicName(manifest_parser_pt parser, char **symbolicName); -celix_status_t manifestParser_getAndDuplicateName(manifest_parser_pt parser, char **name); -celix_status_t manifestParser_getAndDuplicateDescription(manifest_parser_pt parser, char **description); -celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, celix_version_t **version); -celix_status_t manifestParser_getAndDuplicateGroup(manifest_parser_pt parser, char **group); - -#endif /* MANIFEST_PARSER_H_ */ diff --git a/libs/framework/src/module.c b/libs/framework/src/module.c index 33b888312..a389a9130 100644 --- a/libs/framework/src/module.c +++ b/libs/framework/src/module.c @@ -17,21 +17,22 @@ * under the License. */ +#include #include #include #include #include -#include "celix_utils.h" -#include "utils.h" -#include "module.h" -#include "manifest_parser.h" -#include "celix_libloader.h" -#include "celix_framework.h" +#include "bundle_archive_private.h" +#include "celix_bundle_manifest.h" #include "celix_constants.h" +#include "celix_framework.h" +#include "celix_libloader.h" +#include "celix_module.h" +#include "celix_utils.h" #include "framework_private.h" -#include "bundle_archive_private.h" - +#include "utils.h" +#include "celix_bundle_private.h" #ifdef __linux__ #define CELIX_LIBRARY_PREFIX "lib" @@ -44,183 +45,142 @@ #define CELIX_LIBRARY_EXTENSION = ".dll"; #endif -struct module { +struct celix_module { celix_framework_t* fw; - - celix_version_t* version; - char* symbolicName; - char* group; - char* name; - char* description; bool resolved; - - char* id; - celix_bundle_t* bundle; - + celix_bundle_manifest_t* manifest; celix_thread_mutex_t handlesLock; // protects libraryHandles and bundleActivatorHandle celix_array_list_t* libraryHandles; void* bundleActivatorHandle; }; -module_pt module_create(manifest_pt headerMap, const char * moduleId, bundle_pt bundle) { - module_pt module = NULL; - manifest_parser_pt mp; - celix_framework_t* fw = NULL; - bundle_getFramework(bundle, &fw); - - if (headerMap != NULL && fw != NULL) { - module = (module_pt) calloc(1, sizeof(*module)); - module->fw = fw; - module->id = strdup(moduleId); - module->bundle = bundle; - module->resolved = false; - celixThreadMutex_create(&module->handlesLock, NULL); - module->libraryHandles = celix_arrayList_create(); +celix_module_t* module_create(celix_bundle_manifest_t* manifest, celix_bundle_t* bundle) { + assert(manifest != NULL); + assert(bundle != NULL); + celix_framework_t* fw; + bundle_getFramework(bundle, &fw); - if (manifestParser_create(module, headerMap, &mp) == CELIX_SUCCESS) { - module->symbolicName = NULL; - manifestParser_getAndDuplicateSymbolicName(mp, &module->symbolicName); + celix_autoptr(celix_module_t) module = calloc(1, sizeof(*module)); + celix_autoptr(celix_array_list_t) libraryHandles = celix_arrayList_createStringArray(); + if (!module || !libraryHandles) { + fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to create module, out of memory"); + return NULL; + } - module->group = NULL; - manifestParser_getAndDuplicateGroup(mp, &module->group); + celix_status_t status = celixThreadMutex_create(&module->handlesLock, NULL); + if (!status) { + fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to create module, error creating mutex"); + celix_framework_logTssErrors(fw->logger, CELIX_LOG_LEVEL_ERROR); + return NULL; + } - module->name = NULL; - manifestParser_getAndDuplicateName(mp, &module->name); + module->fw = fw; + module->bundle = bundle; + module->resolved = false; + module->manifest = manifest; + module->libraryHandles = celix_steal_ptr(libraryHandles); - module->description = NULL; - manifestParser_getAndDuplicateDescription(mp, &module->description); + return celix_steal_ptr(module); +} - module->version = NULL; - manifestParser_getBundleVersion(mp, &module->version); +celix_module_t* module_createFrameworkModule(celix_framework_t* fw, bundle_pt bundle) { + celix_autoptr(celix_bundle_manifest_t) manifest = NULL; + celix_status_t status = celix_bundleManifest_createFrameworkManifest(&manifest); + if (status != CELIX_SUCCESS) { + celix_framework_logTssErrors(fw->logger, CELIX_LOG_LEVEL_ERROR); + return NULL; + } - manifestParser_destroy(mp); - } + celix_autoptr(celix_module_t) module = calloc(1, sizeof(*module)); + celix_autoptr(celix_array_list_t) libraryHandles = celix_arrayList_createStringArray(); + if (!module || !libraryHandles) { + fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to create module, out of memory"); + return NULL; } - return module; -} + status = celixThreadMutex_create(&module->handlesLock, NULL); + if (!status) { + fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to create module, error creating mutex"); + celix_framework_logTssErrors(fw->logger, CELIX_LOG_LEVEL_ERROR); + return NULL; + } -module_pt module_createFrameworkModule(celix_framework_t* fw, bundle_pt bundle) { - module_pt module; + module->fw = fw; + module->bundle = bundle; + module->resolved = false; + module->manifest = celix_steal_ptr(manifest); + module->libraryHandles = celix_steal_ptr(libraryHandles); - module = (module_pt)calloc(1, sizeof(*module)); - char modId[2]; - snprintf(modId, 2, "%li", CELIX_FRAMEWORK_BUNDLE_ID); - if (module) { - module->fw = fw; - module->id = celix_utils_strdup(modId); - module->symbolicName = celix_utils_strdup("celix_framework"); - module->group = celix_utils_strdup("Celix/Framework"); - module->name = celix_utils_strdup("Celix Framework"); - module->description = celix_utils_strdup("The Celix Framework System Bundle"); - module->version = celix_version_create(1, 0, 0, ""); - module->resolved = false; - module->bundle = bundle; - celixThreadMutex_create(&module->handlesLock, NULL); - module->libraryHandles = celix_arrayList_create(); - } return module; } -void module_destroy(module_pt module) { - celix_version_destroy(module->version); - free(module->id); - free(module->symbolicName); - free(module->name); - free(module->group); - free(module->description); +void module_destroy(celix_module_t* module) { + if (module) { + celix_bundleManifest_destroy(module->manifest); celix_arrayList_destroy(module->libraryHandles); celixThreadMutex_destroy(&module->handlesLock); free(module); + } } -celix_version_t* module_getVersion(module_pt module) { return module->version; } - -celix_status_t module_getSymbolicName(module_pt module, const char **symbolicName) { - celix_status_t status = CELIX_SUCCESS; - if (module == NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - } else { - *symbolicName = module->symbolicName; - } - return status; +const celix_version_t* module_getVersion(celix_module_t* module) { + return celix_bundleManifest_getBundleVersion(module->manifest); } -celix_status_t module_getName(module_pt module, const char **symbolicName) { +celix_status_t module_getSymbolicName(celix_module_t* module, const char** symbolicName) { celix_status_t status = CELIX_SUCCESS; if (module == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { - *symbolicName = module->name; + *symbolicName = celix_bundleManifest_getBundleSymbolicName(module->manifest); } return status; } -celix_status_t module_getGroup(module_pt module, const char **symbolicName) { +celix_status_t module_getName(celix_module_t* module, const char **name) { celix_status_t status = CELIX_SUCCESS; if (module == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { - *symbolicName = module->group; + *name = celix_bundleManifest_getBundleName(module->manifest); } return status; } -celix_status_t module_getDescription(module_pt module, const char **description) { +celix_status_t module_getGroup(celix_module_t* module, const char **group) { celix_status_t status = CELIX_SUCCESS; if (module == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { - *description = module->description; + *group = celix_bundleManifest_getBundleGroup(module->manifest); } return status; } -char * module_getId(module_pt module) { - return module->id; +celix_status_t module_getDescription(celix_module_t* module, const char **description) { + celix_status_t status = CELIX_SUCCESS; + if (module == NULL) { + status = CELIX_ILLEGAL_ARGUMENT; + } else { + *description = celix_bundleManifest_getBundleDescription(module->manifest); + } + return status; } -bool module_isResolved(module_pt module) { +bool module_isResolved(celix_module_t* module) { return module->resolved; } -void module_setResolved(module_pt module) { +void module_setResolved(celix_module_t* module) { module->resolved = true; } -bundle_pt module_getBundle(module_pt module) { +bundle_pt module_getBundle(celix_module_t* module) { return module->bundle; } -celix_array_list_t* module_getDependentImporters(module_pt module) { - return NULL; -} - -void module_addDependentImporter(module_pt module, module_pt importer) { -} - -void module_removeDependentImporter(module_pt module, module_pt importer) { -} - -//---------------------------------------------------- -//TODO add implementation (functions not implemented but already exported) -celix_array_list_t* module_getDependentRequirers(module_pt module) { - return NULL; -} - -void module_addDependentRequirer(module_pt module, module_pt requirer) { -} - -void module_removeDependentRequirer(module_pt module, module_pt requirer) { -} -//---------------------------------------------------- - -celix_array_list_t* module_getDependents(module_pt module) { - return NULL; -} - celix_status_t celix_module_closeLibraries(celix_module_t* module) { celix_status_t status = CELIX_SUCCESS; celix_bundle_context_t *fwCtx = celix_framework_getFrameworkContext(module->fw); @@ -253,11 +213,13 @@ static celix_status_t celix_module_loadLibrary(celix_module_t* module, const cha return status; } - -static celix_status_t celix_module_loadLibraryForManifestEntry(celix_module_t* module, const char *library, bundle_archive_pt archive, void **handle) { +static celix_status_t celix_module_loadLibraryForManifestEntry(celix_module_t* module, + const char* library, + bundle_archive_pt archive, + void** handle) { celix_status_t status = CELIX_SUCCESS; - const char *error = NULL; + const char* error = NULL; char libraryPath[512]; const char* revRoot = celix_bundleArchive_getCurrentRevisionRoot(archive); @@ -270,7 +232,13 @@ static celix_status_t celix_module_loadLibraryForManifestEntry(celix_module_t* m if (strstr(library, CELIX_LIBRARY_EXTENSION)) { path = celix_utils_writeOrCreateString(libraryPath, sizeof(libraryPath), "%s/%s", revRoot, library); } else { - path = celix_utils_writeOrCreateString(libraryPath, sizeof(libraryPath), "%s/%s%s%s", revRoot, CELIX_LIBRARY_PREFIX, library, CELIX_LIBRARY_EXTENSION); + path = celix_utils_writeOrCreateString(libraryPath, + sizeof(libraryPath), + "%s/%s%s%s", + revRoot, + CELIX_LIBRARY_PREFIX, + library, + CELIX_LIBRARY_EXTENSION); } if (!path) { @@ -284,34 +252,26 @@ static celix_status_t celix_module_loadLibraryForManifestEntry(celix_module_t* m return status; } -static celix_status_t celix_module_loadLibrariesInManifestEntry(celix_module_t* module, const char *librariesIn, const char *activator, bundle_archive_pt archive, void **activatorHandle) { +static celix_status_t celix_module_loadLibrariesInManifestEntry(celix_module_t* module, + const celix_array_list_t* libraries, + const char* activator, + bundle_archive_pt archive, + void** activatorHandle) { + assert(libraries != NULL); + assert(celix_arrayList_getElementType(libraries) == CELIX_ARRAY_LIST_ELEMENT_TYPE_STRING); celix_status_t status = CELIX_SUCCESS; - char* libraries = strndup(librariesIn, 1024*10); - char* saveptr1; - for (char* str1 = libraries; status == CELIX_SUCCESS; str1 = NULL) { - char* token = strtok_r(str1, ",", &saveptr1); - char* saveptr2; - if (token == NULL) { + for (int i = 0; i < celix_arrayList_size(libraries); i++) { + const char* library = celix_arrayList_get(libraries, i); + void* handle = NULL; + status = celix_module_loadLibraryForManifestEntry(module, library, archive, &handle); + if (status != CELIX_SUCCESS) { break; } - char *pathToken = strtok_r(token, ";", &saveptr2); - if (pathToken == NULL) { - continue; - } - - void *handle = NULL; - char lib[128]; - lib[127] = '\0'; - strncpy(lib, pathToken, 127); - char *trimmedLib = celix_utils_trimInPlace(lib); - status = celix_module_loadLibraryForManifestEntry(module, trimmedLib, archive, &handle); - - if ( (status == CELIX_SUCCESS) && (activator != NULL) && (strcmp(trimmedLib, activator) == 0) ) { + if (activator != NULL && strcmp(library, activator) == 0) { *activatorHandle = handle; } } - free(libraries); return status; } @@ -320,51 +280,37 @@ celix_status_t celix_module_loadLibraries(celix_module_t* module) { celix_library_handle_t* activatorHandle = NULL; bundle_archive_pt archive = NULL; bundle_revision_pt revision = NULL; - manifest_pt manifest = NULL; + celix_bundle_manifest_t* manifest = NULL; status = CELIX_DO_IF(status, bundle_getArchive(module->bundle, &archive)); status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision)); status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &manifest)); if (status == CELIX_SUCCESS) { - const char *privateLibraries = NULL; - const char *exportLibraries = NULL; - const char *activator = NULL; - - privateLibraries = manifest_getValue(manifest, CELIX_FRAMEWORK_PRIVATE_LIBRARY); - exportLibraries = manifest_getValue(manifest, CELIX_FRAMEWORK_EXPORT_LIBRARY); - //@note not import yet - activator = manifest_getValue(manifest, CELIX_FRAMEWORK_BUNDLE_ACTIVATOR); - - if (exportLibraries != NULL) { - status = CELIX_DO_IF(status, celix_module_loadLibrariesInManifestEntry(module, exportLibraries, activator, archive, &activatorHandle)); - } + const char* activator = celix_bundleManifest_getBundleActivatorLibrary(manifest); + const celix_array_list_t* privateLibraries = celix_bundleManifest_getBundlePrivateLibraries(manifest); if (privateLibraries != NULL) { status = CELIX_DO_IF(status, - celix_module_loadLibrariesInManifestEntry(module, privateLibraries, activator, archive, &activatorHandle)); + celix_module_loadLibrariesInManifestEntry( + module, privateLibraries, activator, archive, &activatorHandle)); } if (status == CELIX_SUCCESS) { - bundle_setHandle(module->bundle, activatorHandle); //note deprecated + bundle_setHandle(module->bundle, activatorHandle); // note deprecated celixThreadMutex_lock(&module->handlesLock); module->bundleActivatorHandle = activatorHandle; celixThreadMutex_unlock(&module->handlesLock); } } - if (status != CELIX_SUCCESS) { - fw_logCode(module->fw->logger, CELIX_LOG_LEVEL_ERROR, status, "Could not load libraries for bundle %s", + fw_logCode(module->fw->logger, + CELIX_LOG_LEVEL_ERROR, + status, + "Could not load libraries for bundle %s", celix_bundle_getSymbolicName(module->bundle)); (void)celix_module_closeLibraries(module); } return status; } - -void* celix_module_getBundleActivatorHandler(celix_module_t* module) { - celixThreadMutex_lock(&module->handlesLock); - void* handle = module->bundleActivatorHandle; - celixThreadMutex_unlock(&module->handlesLock); - return handle; -} diff --git a/libs/framework/src/service_reference.c b/libs/framework/src/service_reference.c index 58557f70e..9a8b52a7d 100644 --- a/libs/framework/src/service_reference.c +++ b/libs/framework/src/service_reference.c @@ -16,27 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -/** - * service_reference.c - * - * \date Jul 20, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ #include #include -#include "celix_compiler.h" -#include "celix_constants.h" #include #include #include #include "service_reference.h" - +#include "celix_compiler.h" +#include "celix_constants.h" +#include "celix_build_assert.h" +#include "celix_log.h" #include "service_reference_private.h" #include "service_registration_private.h" -#include "celix_build_assert.h" static bool serviceReference_doRelease(struct celix_ref *); static void serviceReference_destroy(service_reference_pt); diff --git a/libs/framework/src/service_reference_private.h b/libs/framework/src/service_reference_private.h index 79b11152d..14cee2fce 100644 --- a/libs/framework/src/service_reference_private.h +++ b/libs/framework/src/service_reference_private.h @@ -30,7 +30,7 @@ #include "registry_callback_private.h" #include "service_reference.h" #include "celix_ref.h" - +#include "celix_threads.h" struct serviceReference { struct celix_ref refCount; diff --git a/libs/framework/src/service_registration.c b/libs/framework/src/service_registration.c index 5744bd1e3..40364964e 100644 --- a/libs/framework/src/service_registration.c +++ b/libs/framework/src/service_registration.c @@ -18,13 +18,14 @@ */ #include -#include #include #include "celix_build_assert.h" #include "celix_constants.h" #include "celix_err.h" #include "service_registration_private.h" +#include "celix_log.h" +#include "service_factory.h" static bool serviceRegistration_destroy(struct celix_ref *); static celix_status_t serviceRegistration_initializeProperties(service_registration_t*registration, diff --git a/libs/framework/src/service_registration_private.h b/libs/framework/src/service_registration_private.h index 8f00b7541..34a561138 100644 --- a/libs/framework/src/service_registration_private.h +++ b/libs/framework/src/service_registration_private.h @@ -24,6 +24,8 @@ #include "registry_callback_private.h" #include "service_registration.h" #include "celix_ref.h" +#include "celix_service_factory.h" +#include "celix_threads.h" enum celix_service_type { CELIX_PLAIN_SERVICE, diff --git a/libs/framework/src/service_registry.c b/libs/framework/src/service_registry.c index 0afcd4ae4..b7e8e7dd7 100644 --- a/libs/framework/src/service_registry.c +++ b/libs/framework/src/service_registry.c @@ -23,14 +23,15 @@ #include #include -#include "service_registry_private.h" -#include "service_registration_private.h" -#include "listener_hook_service.h" +#include "celix_bundle_private.h" #include "celix_constants.h" #include "celix_stdlib_cleanup.h" #include "celix_version_range.h" -#include "service_reference_private.h" #include "framework_private.h" +#include "listener_hook_service.h" +#include "service_reference_private.h" +#include "service_registration_private.h" +#include "service_registry_private.h" static celix_status_t serviceRegistry_registerServiceInternal(service_registry_pt registry, bundle_pt bundle, const char* serviceName, const void * serviceObject, celix_properties_t* dictionary, long reservedId, enum celix_service_type svcType, service_registration_pt *registration); static celix_status_t serviceRegistry_unregisterService(service_registry_pt registry, bundle_pt bundle, service_registration_pt registration); @@ -570,7 +571,7 @@ static celix_status_t serviceRegistry_addHooks(service_registry_pt registry, con for (int i = 0; i < celix_arrayList_size(listeners); ++i) { celix_service_registry_service_listener_entry_t *listenerEntry = celix_arrayList_get(listeners, i); - bundle_getContext(listenerEntry->bundle, &info.context); + info.context = celix_bundle_getContext(listenerEntry->bundle); info.filter = celix_filter_getFilterString(listenerEntry->filter); entry->hook->added(entry->hook->handle, infos); celix_decreaseCountServiceListener(listenerEntry); @@ -617,7 +618,7 @@ static celix_status_t serviceRegistry_removeHook(service_registry_pt registry, s if (removedEntry != NULL) { for (int i = 0; i < celix_arrayList_size(listeners); ++i) { celix_service_registry_service_listener_entry_t *listenerEntry = celix_arrayList_get(listeners, i); - bundle_getContext(listenerEntry->bundle, &info.context); + info.context = celix_bundle_getContext(listenerEntry->bundle); info.filter = celix_filter_getFilterString(listenerEntry->filter); removedEntry->hook->removed(removedEntry->hook->handle, infos); celix_decreaseCountServiceListener(listenerEntry); @@ -633,8 +634,7 @@ static celix_status_t serviceRegistry_removeHook(service_registry_pt registry, s } static void serviceRegistry_callHooksForListenerFilter(service_registry_pt registry, celix_bundle_t *owner, const celix_filter_t *filter, bool removed) { - celix_bundle_context_t *ctx; - bundle_getContext(owner, &ctx); + celix_bundle_context_t *ctx = celix_bundle_getContext(owner); struct listener_hook_info info; info.context = ctx; diff --git a/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_factory.h b/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_factory.h index 34ca59470..89e9cae26 100644 --- a/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_factory.h +++ b/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_factory.h @@ -30,12 +30,12 @@ #include /* celix.framework */ -#include "bundle.h" #include "bundle_context.h" +#include "bundle_private.h" #include "celix_errno.h" -#include "service_reference.h" -#include "service_factory.h" #include "properties.h" +#include "service_factory.h" +#include "service_reference.h" /* celix.config_admin.public*/ #include "configuration_admin.h" diff --git a/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_impl.h b/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_impl.h index aa129937d..c5a1c6304 100644 --- a/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_impl.h +++ b/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_impl.h @@ -32,7 +32,7 @@ #include "configuration_admin.h" /* celix.framework */ -#include "bundle.h" +#include "bundle_private.h" /* celix.config_admin.public */ #include "configuration.h" /* celix.config_admin.private */ diff --git a/misc/experimental/bundles/config_admin/service/private/include/configuration_store.h b/misc/experimental/bundles/config_admin/service/private/include/configuration_store.h index b3e0dfb9d..3bd9091da 100644 --- a/misc/experimental/bundles/config_admin/service/private/include/configuration_store.h +++ b/misc/experimental/bundles/config_admin/service/private/include/configuration_store.h @@ -31,8 +31,8 @@ /* celix.utils.public*/ #include "array_list.h" /* celix.framework */ -#include "bundle.h" #include "bundle_context.h" +#include "bundle_private.h" #include "filter.h" /* celix.config_admin.public */ #include "configuration.h" diff --git a/misc/experimental/bundles/config_admin/service/private/include/framework_patch.h b/misc/experimental/bundles/config_admin/service/private/include/framework_patch.h index 450eb5840..b16e69ee7 100644 --- a/misc/experimental/bundles/config_admin/service/private/include/framework_patch.h +++ b/misc/experimental/bundles/config_admin/service/private/include/framework_patch.h @@ -28,8 +28,8 @@ #define BUNDLE_PATCH_H_ /* celix.framework.public */ +#include "bundle_private.h" #include "celix_errno.h" -#include "bundle.h" #include "service_reference.h" celix_status_t bundle_getBundleLocation(bundle_pt bundle, const char **location);