Repository: celix Updated Branches: refs/heads/develop 3391d88d0 -> 03df0edc9
CELIX-446: Moves updated API to celix_ headers (e.g. celix_bundle_context.h) Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/03df0edc Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/03df0edc Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/03df0edc Branch: refs/heads/develop Commit: 03df0edc9ccb53eb4c006ae71b84acf8330e5376 Parents: 3391d88 Author: Pepijn Noltes <[email protected]> Authored: Sun May 13 21:12:55 2018 +0200 Committer: Pepijn Noltes <[email protected]> Committed: Sun May 13 21:12:55 2018 +0200 ---------------------------------------------------------------------- framework/include/bundle.h | 13 - framework/include/bundle_activator.h | 1 + framework/include/bundle_context.h | 553 ---------------- framework/include/celix/dm/DependencyManager.h | 7 +- framework/include/celix_api.h | 13 + framework/include/celix_bundle.h | 46 ++ framework/include/celix_bundle_context.h | 691 ++++++++++++++++++++ framework/include/celix_service_factory.h | 7 +- framework/include/service_tracker.h | 1 + framework/private/mock/bundle_context_mock.c | 3 +- framework/src/bundle.c | 8 +- framework/src/bundle_context.c | 10 +- framework/src/bundle_context_private.h | 3 +- framework/src/bundle_private.h | 9 +- framework/src/framework.c | 1 + framework/src/service_tracker.c | 3 +- framework/tst/bundle_context_bundles_tests.cpp | 4 +- framework/tst/bundle_context_services_test.cpp | 4 +- shell/src/dm_shell_list_command.c | 2 +- utils/include/array_list.h | 52 -- utils/include/celix_array_list.h | 84 +++ utils/include/celix_properties.h | 78 +++ utils/include/properties.h | 40 -- utils/src/array_list.c | 1 + utils/src/properties.c | 1 + 25 files changed, 943 insertions(+), 692 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/include/bundle.h ---------------------------------------------------------------------- diff --git a/framework/include/bundle.h b/framework/include/bundle.h index 9cccd0c..b105615 100644 --- a/framework/include/bundle.h +++ b/framework/include/bundle.h @@ -133,19 +133,6 @@ FRAMEWORK_EXPORT celix_status_t bundle_getFramework(bundle_pt bundle, framework_ FRAMEWORK_EXPORT celix_status_t bundle_getBundleLocation(bundle_pt bundle, const char **location); - -/********************************************************************************************************************** - ********************************************************************************************************************** - * Updated API - ********************************************************************************************************************** - **********************************************************************************************************************/ - -long celix_bundle_getId(const bundle_t *bnd); - -celix_bundle_state_e celix_bundle_getState(const bundle_t *bnd); - - - #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/include/bundle_activator.h ---------------------------------------------------------------------- diff --git a/framework/include/bundle_activator.h b/framework/include/bundle_activator.h index a03fbb1..8c91957 100644 --- a/framework/include/bundle_activator.h +++ b/framework/include/bundle_activator.h @@ -38,6 +38,7 @@ #define BUNDLE_ACTIVATOR_H_ #include "bundle_context.h" +#include "celix_bundle_context.h" #include "framework_exports.h" #ifdef __cplusplus http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/include/bundle_context.h ---------------------------------------------------------------------- diff --git a/framework/include/bundle_context.h b/framework/include/bundle_context.h index 93840b7..cf42314 100644 --- a/framework/include/bundle_context.h +++ b/framework/include/bundle_context.h @@ -164,559 +164,6 @@ FRAMEWORK_EXPORT celix_status_t bundleContext_getPropertyWithDefault(bundle_context_pt context, const char *name, const char *defaultValue, const char **value); - - - - - - - - - - - - - - - - - - - -/********************************************************************************************************************** - ********************************************************************************************************************** - * Updated API - ********************************************************************************************************************** - **********************************************************************************************************************/ - -/** - * Gets the dependency manager for this bundle context. - * - * @return the dependency manager or NULL if unsuccessful. - */ -dm_dependency_manager_t* celix_bundleContext_getDependencyManager(celix_bundle_context_t *ctx); - - -typedef struct celix_service_registration_options { - /** - * The service pointer. The actual pointer to the service. For C this is normally a pointer to a struct - * with function pointers, but theoretically this can be a pointer to anything (e.g. a pointer to a single function, - * or a pointer to a C++ interface implementation, or just a pointer to a data structure). - * - * The bundle is responsible to keep the service pointer valid as long as it is registered in the Celix framework. - */ - void *svc; - - /** - * The service factory pointer. - * Note if the factory service is set, the svc field will not be used. - * - * The service factory will be called for every bundle requesting/de-requesting a service. This gives the provider the - * option to create bundle specific service instances. - * - * When a service is requested for a bundle the getService of the factory service will be called. This function must - * return a valid pointer to a service conform the registered service name or NULL. - * When a service in no longer needed for a bundle (e.g. ending the useService(s) calls when a service tacker is stopped) - * the ungetService function of the service factory will be called. - * - * The bundle is responsible to keep the service factory pointer valid as long as it is registered in the Celix framework. - */ - celix_service_factory_t *factory; - - /** - * The required service name. This is used to identify the service. A fully qualified name with a namespace is - * advisable to prevent name collision. (e.g. EXAMPLE_PRESURE_SENSOR). - */ - const char *serviceName; - - /** - * The optional service properties. These contain meta information about the service in the - * form of string key/values. (e.g. the location of a pressure sensor: location=left-tire). - * - * When a service is registered the Celix framework will take ownership of the provided properties. - * If a registration fails, the properties will be destroyed (freed) by the Celix framework. - */ - celix_properties_t *properties; - - /** - * The optional service language. If this is NULL, CELIX_FRAMEWORK_SERVICE_LANGUAGE_C is used. - */ - const char *serviceLanguage; - - /** - * The optional service version (in the form of <MAJOR>.<MINOR>.<MICRO>.<QUALIFIER>). - * If present consumer of the service can specific which service version range of - * a specific service they are interested in. Note that it is the responsibility of the users to ensure that - * service in those version range are compatible (binary of source). It is advisable to use semantic versioning - * for this. - */ - const char *serviceVersion; -} celix_service_registration_options_t; - -#define CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS { .svc = NULL, \ - .serviceName = NULL, \ - .properties = NULL, \ - .serviceLanguage = NULL, \ - .serviceVersion = NULL } - -/** - * Register a C lang service to the framework. - * - * @param ctx The bundle context - * @param svc the service object. Normally a pointer to a service struct (e.g. a struct with function pointers) - * @param serviceName the service name, cannot be NULL - * @param properties The meta properties associated with the service. The service registration will take ownership of the properties (e.g. no destroy needed) - * @return The serviceId, which should be >= 0. If < 0 then the registration was unsuccessful. - */ -long celix_bundleContext_registerService(celix_bundle_context_t *ctx, void *svc, const char *serviceName, celix_properties_t *properties); - -/** - * Register a service factory in the framework (for the C language). - * The service factory will be called for every bundle requesting/de-requesting a service. This gives the provider the - * option to create bundle specific service instances. - * - * When a service is requested for a bundle the getService of the factory service will be called. This function must - * return a valid pointer to a service conform the registered service name or NULL. - * When a service in no longer needed for a bundle (e.g. ending the useService(s) calls when a service tacker is stopped) - * the ungetService function of the service factory will be called. - * - * @param ctx The bundle context - * @param factory The pointer to the factory service. - * @param serviceName The required service name of the services this factory will produce. - * @param properties The optional service factory properties. For a service consumer this will be seen as the service properties. - * @return The service id of the service factory or < 0 if the registration was unsuccessful. - */ -long celix_bundleContext_registerServiceFactory(celix_bundle_context_t *ctx, celix_service_factory_t *factory, const char *serviceName, celix_properties_t *props); - -/** -* Register a service Celix to the framework using the provded registration options. -* -* @param ctx The bundle context -* @param opts The pointer to the registration options. The options are only in the during registration call. -* @return The serviceId, which should >= 0. If < 0 then the registration was unsuccessful. -*/ -long celix_bundleContext_registerServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_registration_options_t *opts); - - -/** - * Unregister the service or service factory with service id. - * The service will only be unregistered if the bundle of the bundle context is the owner of the service. - * - * Will log an error if service id is unknown. Will silently ignore services ids < 0. - * - * @param ctx The bundle context - * @param serviceId The service id - */ -void celix_bundleContext_unregisterService(celix_bundle_context_t *ctx, long serviceId); - - -typedef struct celix_service_filter_options { - const char* serviceName; //REQUIRED - const char* versionRange; - const char* filter; - const char* lang; //NULL -> 'CELIX_LANG_C' -} celix_service_filter_options_t; - -#define CELIX_EMPTY_SERVICE_FILTER_OPTIONS {.serviceName = NULL, .versionRange = NULL, .filter = NULL, .lang = NULL} - - -/** - * Finds the highest ranking service and returns the service id. - * - * @param ctx The bundle context - * @param serviceName The required service name - * @return If found a valid service id (>= 0) if not found -1. - */ -long celix_bundleContext_findService(celix_bundle_context_t *ctx, const char *serviceName); - -/** - * Finds the highest ranking service and returns the service id. - * - * @param ctx The bundle context - * @param opts The pointer to the filter options. - * @return If found a valid service id (>= 0) if not found -1. - */ -long celix_bundleContext_findServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_filter_options_t *opts); - -/** - * Finds the services with the provided service name and returns a list of the found service ids. - * - * @param ctx The bundle context - * @param serviceName The required service name - * @return A array list with as value a long int. - */ -celix_array_list_t* celix_bundleContext_findServices(celix_bundle_context_t *ctx, const char *serviceName); - -/** - * Finds the services conform the provider filter options and returns a list of the found service ids. - * - * @param ctx The bundle context - * @param opts The pointer to the filter options. - * @return A array list with as value a long int. - */ -celix_array_list_t* celix_bundleContext_findServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_filter_options_t *opts); - - -/** - * track service for the provided serviceName and/or filter. - * The highest ranking services will used for the callback. - * If a new and higher ranking services the callback with be called again with the new service. - * If a service is removed a the callback with be called with next highest ranking service or NULL as service. - * - * @param ctx The bundle context. - * @param serviceName The required service name to track - * @param serviceVersionRange Optional the service version range to track - * @param filter Optional the LDAP filter to use - * @param callbackHandle The data pointer, which will be used in the callbacks - * @param set is a required callback, which will be called when a new highest ranking service is set. - * @return the tracker id or < 0 if unsuccessful. - */ -long celix_bundleContext_trackService( - celix_bundle_context_t* ctx, - const char* serviceName, - void* callbackHandle, - void (*set)(void* handle, void* svc) -); - -/** - * track services for the provided serviceName and/or filter. - * - * @param ctx The bundle context. - * @param serviceName The required service name to track - * @param serviceVersionRange Optional the service version range to track - * @param filter Optional the LDAP filter to use - * @param callbackHandle The data pointer, which will be used in the callbacks - * @param add is a required callback, which will be called when a service is added and initially for the existing service. - * @param remove is a required callback, which will be called when a service is removed - * @return the tracker id or < 0 if unsuccessful. - */ -long celix_bundleContext_trackServices( - celix_bundle_context_t* ctx, - const char* serviceName, - void* callbackHandle, - void (*add)(void* handle, void* svc), - void (*remove)(void* handle, void* svc) -); - -typedef struct celix_service_tracker_options { - celix_service_filter_options_t filter; - - //callback options - void* callbackHandle; - - void (*set)(void *handle, void *svc); //highest ranking - void (*add)(void *handle, void *svc); - void (*remove)(void *handle, void *svc); - - void (*setWithProperties)(void *handle, void *svc, const celix_properties_t *props); //highest ranking - void (*addWithProperties)(void *handle, void *svc, const celix_properties_t *props); - void (*removeWithProperties)(void *handle, void *svc, const celix_properties_t *props); - - void (*setWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner); //highest ranking - void (*addWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner); - void (*removeWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner); -} celix_service_tracking_options_t; - -#define CELIX_EMPTY_SERVICE_TRACKING_OPTIONS { .filter.serviceName = NULL, \ - .filter.versionRange = NULL, \ - .filter.filter = NULL, \ - .filter.lang = NULL, \ - .callbackHandle = NULL, \ - .set = NULL, \ - .add = NULL, \ - .remove = NULL, \ - .setWithProperties = NULL, \ - .addWithProperties = NULL, \ - .removeWithProperties = NULL, \ - .setWithOwner = NULL, \ - .addWithOwner = NULL, \ - .removeWithOwner = NULL} - -/** - * Tracks services using the provided tracker options. - * The tracker options are only using during this call and can safely be freed/reused after this call returns. - * - * @param ctx The bundle context. - * @param opts The pointer to the tracker options. - * @return the tracker id or < 0 if unsuccessful. - */ -long celix_bundleContext_trackServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_tracking_options_t *opts); - - - -/** - * Get and lock the service with the provided service id - * Invokes the provided callback with the found service. - * The svc, props and owner in the callback are only valid during the callback. - * If no service is found the callback will not be invoked - * - * This function will block till the callback is finished. As result it is possible to provide callback data from the - * stack. - * - * @param ctx The bundle context - * @param serviceId the service id. - * @param serviceName the service name of the service. Should match with the registered service name of the provided service id (sanity check) - * @param callbackHandle The data pointer, which will be used in the callbacks - * @param use The callback, which will be called when service is retrieved. - * @param bool returns true if a service was found. - */ -bool celix_bundleContext_useServiceWithId( - celix_bundle_context_t *ctx, - long serviceId, - const char *serviceName /*sanity check*/, - void *callbackHandle, - void (*use)(void *handle, void* svc) -); - -/** - * Get and lock the current highest ranking service conform serviceName, versionRange an filter. - * Invokes the provided callback with the found service. - * The svc, props and owner in the callback are only valid during the callback. - * If no service is found the callback will not be invoked. - * - * This function will block till the callback is finished. As result it is possible to provide callback data from the - * stack. - * - * @param ctx The bundle context - * @param serviceName the required service name. - * @param callbackHandle The data pointer, which will be used in the callbacks - * @param use The callback, which will be called when service is retrieved. - * @return True if a service was found. - */ -bool celix_bundleContext_useService( - celix_bundle_context_t *ctx, - const char* serviceName, - void *callbackHandle, - void (*use)(void *handle, void *svc) -); - -/** - * Get and lock the current services conform serviceName, versionRange an filter. - * Invokes the provided callback with the found services. - * The svc, props and owner in the callback are only valid during the callback. - * If no services are found the callback will not be invoked. - * - * This function will block till the callback is finished. As result it is possible to provide callback data from the - * stack. - * - * @param ctx The bundle context - * @param serviceName the required service name. - * @param serviceRange the optional service version range (e.g. '[1.0.0,2.0.0)' ) - * @param filter the optional filter. - * @param callbackHandle The data pointer, which will be used in the callbacks - * @param use The callback, which will be called for every service found. - */ -void celix_bundleContext_useServices( - celix_bundle_context_t *ctx, - const char* serviceName, - void *callbackHandle, - void (*use)(void *handle, void *svc) -); - - -typedef struct celix_service_use_options { - celix_service_filter_options_t filter; - - /** - * Callback info - */ - void *callbackHandle; - - void (*use)(void *handle, void *svc); - void (*useWithProperties)(void *handle, void *svc, const celix_properties_t *props); - void (*useWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner); -} celix_service_use_options_t; - -#define CELIX_EMPTY_SERVICE_USE_OPTIONS {.filter.serviceName = NULL, \ - .filter.versionRange = NULL, \ - .filter.filter = NULL, \ - .filter.lang = NULL, \ - .callbackHandle = NULL, \ - .use = NULL, \ - .useWithProperties = NULL, \ - .useWithOwner = NULL} - -/** - * Get and lock the current highest ranking service conform the service filter info from the provided options. - * - * Invokes the provided callback with the found service. - * The svc, props and owner in the callback are only valid during the callback. - * If no service is found the callback will not be invoked. - * - * This function will block till the callback is finished. As result it is possible to provide callback data from the - * stack. - * - * @param ctx The bundle context. - * @param serviceName the required service name. - * @param opts The required options. Note that the serviceName is required. - * @return True if a service was found. - */ -bool celix_bundleContext_useServiceWithOptions( - celix_bundle_context_t *ctx, - const celix_service_use_options_t *opts); - - -/** - * Get and lock the current services conform the service filter info from the provided options. - * - * Invokes the provided callback with the found services. - * The svc, props and owner in the callback are only valid during the callback. - * If no services are found the callback will not be invoked. - * At least a serviceName needs to be provided, if not the callback is not invoked. - * - * This function will block till all the callbacks are finished. As result it is possible to provide callback data from the - * stack. - * - * @param ctx The bundle context. - * @param serviceName the required service name. - * @param opts The required options. Note that the serviceName is required. - * @param callbackHandle The data pointer, which will be used in the callbacks. - * @param use The callback, which will be called for every service found. - */ -void celix_bundleContext_useServicesWithOptions( - celix_bundle_context_t *ctx, - const celix_service_use_options_t *opts); - - -/** - * Install and optional start a bundle. - * - * @param ctx The bundle context - * @param bundleLoc The bundle location to the bundle zip file. - * @param autoStart If the bundle should also be started. - * @return the bundleId >= 0 or < 0 if the bundle could not be installed and possibly started. - */ -long celix_bundleContext_installBundle(celix_bundle_context_t *ctx, const char *bundleLoc, bool autoStart); - -/** - * Uninstall the bundle with the provided bundle id. If needed the bundle will be stopped first. - * - * @param ctx The bundle context - * @param bundleId The bundle id to stop - * @return true if the bundle is correctly uninstalled. False if not. - */ -bool celix_bundleContext_uninstallBundle(celix_bundle_context_t *ctx, long bundleId); - - -/** - * Service tracker options. This struct can be used to fine grained tune the - * requested bundle tracker ootions. - */ -typedef struct celix_bundle_tracker_options { - /** - * Handle used in the tracker callbacks. - */ - void* callbackHandle; - - /** - * Tracker callback when a bundle is installed. - * @param handle The handle, contains the value of the callbackHandle. - * @param bundle The bundle which has been started. - * The bundle pointer is only guaranteed to be valid during the callback. - */ - void (*onStarted)(void *handle, const celix_bundle_t *bundle); //highest ranking - - /** - * Tracker callback when a bundle is removed. - * @param handle The handle, contains the value of the callbackHandle. - * @param bundle The bundle which has been started. - * The bundle pointer is only guaranteed to be valid during the callback. - */ - void (*onStopped)(void *handle, const celix_bundle_t *bundle); - - //TODO callback for on installed, resolved, uninstalled ?? - - /** - * - * @param handle The handle, contains the value of the callbackHandle. - * @param event The bundle event. Is only valid during the callback. - */ - void (*onBundleEvent)(void *handle, const celix_bundle_event_t *event); -} celix_bundle_tracker_options_t; - -/** - * Tracks bundles using the provided bundle tracker options. - * The tracker options are only using during this call and can safely be freed/reused after this call returns. - * (i.e. can be on the stack) - * - * @param ctx The bundle context. - * @param opts The pointer to the bundle tracker options. - * @return The bundle tracker id or < 0 if unsuccessful. - */ -long celix_bundleContext_trackBundlesWithOptions( - celix_bundle_context_t* ctx, - const celix_bundle_tracker_options_t *opts -); - -/** - * track bundles - * The add bundle callback will also be called for already installed bundles. - * - * @param ctx The bundle context. - * @param callbackHandle The data pointer, which will be used in the callbacks - * @param add The callback which will be called for started bundles. - * @param remove The callback which will be called when bundles are stopped. - * @return The bundle tracker id or < 0 if unsuccessful. - */ -long celix_bundleContext_trackBundles( - celix_bundle_context_t* ctx, - void* callbackHandle, - void (*onStarted)(void* handle, const celix_bundle_t *bundle), - void (*onStopped)(void *handle, const celix_bundle_t *bundle) -); - -/** - * Use the bundle with the provided bundle id if it is in the active (started) state - * The provided callback will be called if the bundle is found and in the active (started) state. - * - * @param ctx The bundle context. - * @param bundleId The bundle id. - * @param callbackHandle The data pointer, which will be used in the callbacks - * @param use The callback which will be called for the currently started bundles. - * The bundle pointers are only guaranteed to be valid during the callback. - */ -void celix_bundleContext_useBundle( - celix_bundle_context_t *ctx, - long bundleId, - void *callbackHandle, - void (*use)(void *handle, const celix_bundle_t *bundle) -); - -//TODO add useBundleWithOptions (e.g. which state) - - -//TODO findBundles - - -/** - * Use the currently active (started) bundles. - * The provided callback will be called for all the currently started bundles. - * - * @param ctx The bundle context. - * @param callbackHandle The data pointer, which will be used in the callbacks - * @param use The callback which will be called for the currently started bundles. - * The bundle pointers are only guaranteed to be valid during the callback. - */ -void celix_bundleContext_useBundles( - celix_bundle_context_t *ctx, - void *callbackHandle, - void (*use)(void *handle, const celix_bundle_t *bundle) -); - - -//TODO trackServiceTracker - -/** - * Stop the tracker with the provided track id. - * Could be a service tracker, bundle tracker or service tracker tracker. - * Only works for the trackers owned by the bundle of the bundle context. - * - * Will log a error if the provided tracker id is unknown. Will silently ignore trackerId < 0. - */ -void celix_bundleContext_stopTracker(celix_bundle_context_t *ctx, long trackerId); - - - #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/include/celix/dm/DependencyManager.h ---------------------------------------------------------------------- diff --git a/framework/include/celix/dm/DependencyManager.h b/framework/include/celix/dm/DependencyManager.h index 258a311..f90a03c 100644 --- a/framework/include/celix/dm/DependencyManager.h +++ b/framework/include/celix/dm/DependencyManager.h @@ -17,20 +17,21 @@ * under the License. */ -#ifndef CELIX_DM_DEPENDENCYMANAGER_H -#define CELIX_DM_DEPENDENCYMANAGER_H - #include "celix/dm/types.h" #include "celix/dm/Component.h" #include "celix/dm/ServiceDependency.h" #include "bundle_context.h" +#include "celix_bundle_context.h" #include "dm_dependency_manager.h" #include <vector> #include <mutex> +#ifndef CELIX_DM_DEPENDENCYMANAGER_H +#define CELIX_DM_DEPENDENCYMANAGER_H + namespace celix { namespace dm { class DependencyManager { http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/include/celix_api.h ---------------------------------------------------------------------- diff --git a/framework/include/celix_api.h b/framework/include/celix_api.h index b770876..5129a65 100644 --- a/framework/include/celix_api.h +++ b/framework/include/celix_api.h @@ -20,15 +20,28 @@ #ifndef CELIX_CELIX_API_H_ #define CELIX_CELIX_API_H_ +#include "properties.h" + +#include "array_list.h" +#include "celix_array_list.h" + +#include "constants.h" + #include "celix_utils_api.h" + #include "bundle.h" +#include "celix_bundle.h" + #include "bundle_context.h" +#include "celix_bundle_context.h" + #include "service_registration.h" #include "service_factory.h" #include "service_reference.h" #include "service_tracker.h" #include "service_tracker_customizer.h" #include "listener_hook_service.h" + #include "framework.h" #include "celix_framework_factory.h" #include "celix_launcher.h" http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/include/celix_bundle.h ---------------------------------------------------------------------- diff --git a/framework/include/celix_bundle.h b/framework/include/celix_bundle.h new file mode 100644 index 0000000..74ea9bf --- /dev/null +++ b/framework/include/celix_bundle.h @@ -0,0 +1,46 @@ +/** + *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. + */ + +#include "celix_types.h" +#include "bundle_state.h" + +#ifndef CELIX_BUNDLE_H_ +#define CELIX_BUNDLE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/********************************************************************************************************************** + ********************************************************************************************************************** + * Updated API + ********************************************************************************************************************** + **********************************************************************************************************************/ + +long celix_bundle_getId(const bundle_t *bnd); + +celix_bundle_state_e celix_bundle_getState(const bundle_t *bnd); + + + +#ifdef __cplusplus +} +#endif + +#endif /* CELIX_BUNDLE_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/include/celix_bundle_context.h ---------------------------------------------------------------------- diff --git a/framework/include/celix_bundle_context.h b/framework/include/celix_bundle_context.h new file mode 100644 index 0000000..1e8dff5 --- /dev/null +++ b/framework/include/celix_bundle_context.h @@ -0,0 +1,691 @@ +/** + *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. + */ + +#include "celix_types.h" +#include "celix_service_factory.h" +#include "celix_properties.h" +#include "celix_array_list.h" + +#ifndef CELIX_BUNDLE_CONTEXT_H_ +#define CELIX_BUNDLE_CONTEXT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/********************************************************************************************************************** + ********************************************************************************************************************** + * Updated API + ********************************************************************************************************************** + **********************************************************************************************************************/ + +/** +* Register a service to the Celix framework. +* +* @param ctx The bundle context +* @param svc the service object. Normally a pointer to a service struct (i.e. a struct with function pointers) +* @param serviceName the service name, cannot be NULL +* @param properties The meta properties associated with the service. The service registration will take ownership of the properties (e.g. no destroy needed) +* @return The serviceId (>= 0) or < 0 if the registration was unsuccessful. +*/ +long celix_bundleContext_registerService(celix_bundle_context_t *ctx, void *svc, const char *serviceName, celix_properties_t *properties); + +/** + * Register a service factory in the framework (for the C language). + * The service factory will be called for every bundle requesting/de-requesting a service. This gives the provider the + * option to create bundle specific service instances. + * + * When a service is requested for a bundle the getService of the factory service will be called. This function must + * return a valid pointer to a service conform the registered service name or NULL. + * When a service in no longer needed for a bundle (e.g. ending the useService(s) calls when a service tacker is stopped) + * the ungetService function of the service factory will be called. + * + * @param ctx The bundle context + * @param factory The pointer to the factory service. + * @param serviceName The required service name of the services this factory will produce. + * @param properties The optional service factory properties. For a service consumer this will be seen as the service properties. + * @return The serviceId (>= 0) or < 0 if the registration was unsuccessful. + */ +long celix_bundleContext_registerServiceFactory(celix_bundle_context_t *ctx, celix_service_factory_t *factory, const char *serviceName, celix_properties_t *props); + +/** + * Service Registration Options when registering services to the Celix framework. + */ +typedef struct celix_service_registration_options { + /** + * The service pointer. The actual pointer to the service. For C this is normally a pointer to a struct + * with function pointers, but theoretically this can be a pointer to anything (e.g. a pointer to a single function, + * or a pointer to a C++ interface implementation, or just a pointer to a data structure). + * + * The bundle is responsible to keep the service pointer valid as long as it is registered in the Celix framework. + */ + void *svc; + + /** + * The service factory pointer. + * Note if the factory service is set, the svc field will not be used. + * + * The service factory will be called for every bundle requesting/de-requesting a service. This gives the provider the + * option to create bundle specific service instances. + * + * When a service is requested for a bundle the getService of the factory service will be called. This function must + * return a valid pointer to a service conform the registered service name or NULL. + * When a service in no longer needed for a bundle (e.g. ending the useService(s) calls when a service tacker is stopped) + * the ungetService function of the service factory will be called. + * + * The bundle is responsible to keep the service factory pointer valid as long as it is registered in the Celix framework. + */ + celix_service_factory_t *factory; + + /** + * The required service name. This is used to identify the service. A fully qualified name with a namespace is + * advisable to prevent name collision. (e.g. EXAMPLE_PRESURE_SENSOR). + */ + const char *serviceName; + + /** + * The optional service properties. These contain meta information about the service in the + * form of string key/values. (e.g. the location of a pressure sensor: location=left-tire). + * + * When a service is registered the Celix framework will take ownership of the provided properties. + * If a registration fails, the properties will be destroyed (freed) by the Celix framework. + */ + celix_properties_t *properties; + + /** + * The optional service language. If this is NULL, CELIX_FRAMEWORK_SERVICE_LANGUAGE_C is used. + */ + const char *serviceLanguage; + + /** + * The optional service version (in the form of <MAJOR>.<MINOR>.<MICRO>.<QUALIFIER>). + * If present consumer of the service can specific which service version range of + * a specific service they are interested in. Note that it is the responsibility of the users to ensure that + * service in those version range are compatible (binary of source). It is advisable to use semantic versioning + * for this. + */ + const char *serviceVersion; +} celix_service_registration_options_t; + +/** + * Macro to create a empty celix_service_registration_options_t type. + */ +#define CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS { .svc = NULL, \ + .serviceName = NULL, \ + .properties = NULL, \ + .serviceLanguage = NULL, \ + .serviceVersion = NULL } + + +/** +* Register a service to the Celix framework using the provided service registration options. +* +* @param ctx The bundle context +* @param opts The pointer to the registration options. The options are only in the during registration call. +* @return The serviceId (>= 0) or < 0 if the registration was unsuccessful. +*/ +long celix_bundleContext_registerServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_registration_options_t *opts); + + +/** + * Unregister the service or service factory with service id. + * The service will only be unregistered if the bundle of the bundle context is the owner of the service. + * + * Will log an error if service id is unknown. Will silently ignore services ids < 0. + * + * @param ctx The bundle context + * @param serviceId The service id + */ +void celix_bundleContext_unregisterService(celix_bundle_context_t *ctx, long serviceId); + + + + + + + + +/** + * Finds the highest ranking service and returns the service id. + * + * @param ctx The bundle context + * @param serviceName The required service name + * @return If found a valid service id (>= 0) if not found -1. + */ +long celix_bundleContext_findService(celix_bundle_context_t *ctx, const char *serviceName); + +/** + * Finds the services with the provided service name and returns a list of the found service ids. + * + * @param ctx The bundle context + * @param serviceName The required service name + * @return A array list with as value a long int. + */ +celix_array_list_t* celix_bundleContext_findServices(celix_bundle_context_t *ctx, const char *serviceName); + +/** + * Service filter options which can be used to query for certain services. + */ +typedef struct celix_service_filter_options { + /** + * The required service name. + */ + const char* serviceName; + + /** + * The optional version range. If service are registerd with a service version this attribute can be used to + * only select service with a version in the version range. + * It uses the maven version range format, e.g. [1.0.0,2.0.0) or [1.1.1], etc. + */ + const char* versionRange; + + /** + * LDAP filter to use for fine tuning the filtering, e.g. (|(location=middle)(location=front)) + * The filter will be applied to all the user provided and framework provided service properties. + */ + const char* filter; + + /** + * The optional service language to filter for. If this is NULL or "" the C language will be used. + */ + const char* serviceLanguage; +} celix_service_filter_options_t; + +/** + * Macro to create a empty celix_service_filter_options_t type. + */ +#define CELIX_EMPTY_SERVICE_FILTER_OPTIONS {.serviceName = NULL, .versionRange = NULL, .filter = NULL, .serviceLanguage = NULL} + + +/** + * Finds the highest ranking service and returns the service id. + * + * @param ctx The bundle context + * @param opts The pointer to the filter options. + * @return If found a valid service id (>= 0) if not found -1. + */ +long celix_bundleContext_findServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_filter_options_t *opts); + +/** + * Finds the services conform the provider filter options and returns a list of the found service ids. + * + * @param ctx The bundle context + * @param opts The pointer to the filter options. + * @return A array list with as value a long int. + */ +celix_array_list_t* celix_bundleContext_findServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_filter_options_t *opts); + + +/** + * track the highest ranking service with the provided serviceName. + * The highest ranking services will used for the callback. + * If a new and higher ranking services the callback with be called again with the new service. + * If a service is removed a the callback with be called with next highest ranking service or NULL as service. + * + * @param ctx The bundle context. + * @param serviceName The required service name to track + * @param callbackHandle The data pointer, which will be used in the callbacks + * @param set is a required callback, which will be called when a new highest ranking service is set. + * @return the tracker id (>=0) or < 0 if unsuccessful. + */ +long celix_bundleContext_trackService( + celix_bundle_context_t* ctx, + const char* serviceName, + void* callbackHandle, + void (*set)(void* handle, void* svc) +); + +/** + * track services with the provided serviceName. + * + * @param ctx The bundle context. + * @param serviceName The required service name to track + * @param callbackHandle The data pointer, which will be used in the callbacks + * @param add is a required callback, which will be called when a service is added and initially for the existing service. + * @param remove is a required callback, which will be called when a service is removed + * @return the tracker id (>=0) or < 0 if unsuccessful. + */ +long celix_bundleContext_trackServices( + celix_bundle_context_t* ctx, + const char* serviceName, + void* callbackHandle, + void (*add)(void* handle, void* svc), + void (*remove)(void* handle, void* svc) +); + +/** + * Service Tracker Options used to fine tune which services to track and the callback to be used for the tracked services. + */ +typedef struct celix_service_tracker_options { + /** + * The service filter options, used to setup the filter for the service to track. + */ + celix_service_filter_options_t filter; + + /** + * The optional callback pointer used in all the provided callback function (set, add, remove, setWithProperties, etc). + */ + void* callbackHandle; + + /** + * The optional set callback will be called when a new highest ranking service is available conform the provided + * service filter options. + * @param handle The callbackHandle pointer as provided in the service tracker options. + * @param svc The service pointer of the highest ranking service. + */ + void (*set)(void *handle, void *svc); + + /** + * The optional setWithProperties callback is handled as the set callback, but with the addition that the service properties + * will also be provided to the callback. + */ + void (*setWithProperties)(void *handle, void *svc, const celix_properties_t *props); //highest ranking + + /** + * The optional setWithOwner callback is handled as the set callback, but with the addition that the service properties + * and the bundle owning the service will also be provided to the callback. + */ + void (*setWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner); //highest ranking + + /** + * The optional add callback will be called for every current and future service found conform the provided service filter + * options as long as the tracker is active. + * @param handle The callbackHandle pointer as provided in the service tracker options. + * @param svc The service pointer of a service matching the provided service filter options. + */ + void (*add)(void *handle, void *svc); + + /** + * The optional addWithProperties callback is handled as the add callback, but with the addition that the service properties + * will also be provided to the callback. + */ + void (*addWithProperties)(void *handle, void *svc, const celix_properties_t *props); + + /** + * The optional addWithOwner callback is handled as the add callback, but with the addition that the service properties + * and the bundle owning the service will also be provided to the callback. + */ + void (*addWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner); + + /** + * The optional remove callback will be called for every service conform the provided service filter options that is + * unregistered. When the remove call is finished the removed services should be considered invalid. This means + * that the callback provider should ensure that the removed service is not in use or going to be used after the + * remove callback is finished. + * + * @param handle The callbackHandle pointer as provided in the service tracker options. + * @param svc The service pointer of a service matching the provided service filter options. + */ + void (*remove)(void *handle, void *svc); + + /** + * The optional removeWithProperties callback is handled as the remove callback, but with the addition that the service properties + * will also be provided to the callback. + */ + void (*removeWithProperties)(void *handle, void *svc, const celix_properties_t *props); + + /** + * The optional removeWithOwner callback is handled as the remove callback, but with the addition that the service properties + * and the bundle owning the service will also be provided to the callback. + */ + void (*removeWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner); +} celix_service_tracking_options_t; + +/** + * Macro to create a empty celix_service_tracking_options_t type. + */ +#define CELIX_EMPTY_SERVICE_TRACKING_OPTIONS { .filter.serviceName = NULL, \ + .filter.versionRange = NULL, \ + .filter.filter = NULL, \ + .filter.serviceLanguage = NULL, \ + .callbackHandle = NULL, \ + .set = NULL, \ + .add = NULL, \ + .remove = NULL, \ + .setWithProperties = NULL, \ + .addWithProperties = NULL, \ + .removeWithProperties = NULL, \ + .setWithOwner = NULL, \ + .addWithOwner = NULL, \ + .removeWithOwner = NULL} + +/** + * Tracks services using the provided tracker options. + * The tracker options are only using during this call and can safely be freed/reused after this call returns. + * + * @param ctx The bundle context. + * @param opts The pointer to the tracker options. + * @return the tracker id (>=0) or < 0 if unsuccessful. + */ +long celix_bundleContext_trackServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_tracking_options_t *opts); + +/** + * Stop the tracker with the provided track id. + * Could be a service tracker, bundle tracker or service tracker tracker. + * Only works for the trackers owned by the bundle of the bundle context. + * + * Will log a error if the provided tracker id is unknown. Will silently ignore trackerId < 0. + */ +void celix_bundleContext_stopTracker(celix_bundle_context_t *ctx, long trackerId); + + + + + + +/** + * Use the service with the provided service id using the provided callback. The Celix framework will ensure that + * the targeted service cannot be removed during the callback. + * + * The svc is should only be considered valid during the callback. + * If no service is found the callback will not be invoked. + * + * This function will block till the callback is finished. As result it is possible to provide callback data from the + * stack. + * + * @param ctx The bundle context + * @param serviceId the service id. + * @param serviceName the service name of the service. Should match with the registered service name of the provided service id (sanity check) + * @param callbackHandle The data pointer, which will be used in the callbacks + * @param use The callback, which will be called when service is retrieved. + * @param bool returns true if a service was found. + */ +bool celix_bundleContext_useServiceWithId( + celix_bundle_context_t *ctx, + long serviceId, + const char *serviceName /*sanity check*/, + void *callbackHandle, + void (*use)(void *handle, void* svc) +); + +/** + * Use the highest ranking service with the provided service name using the provided callback. The Celix framework will + * ensure that the targeted service cannot be removed during the callback. + * + * The svc is should only be considered valid during the callback. + * If no service is found the callback will not be invoked. + * + * This function will block till the callback is finished. As result it is possible to provide callback data from the + * stack. + * + * @param ctx The bundle context + * @param serviceName the required service name. + * @param callbackHandle The data pointer, which will be used in the callbacks + * @param use The callback, which will be called when service is retrieved. + * @return True if a service was found. + */ +bool celix_bundleContext_useService( + celix_bundle_context_t *ctx, + const char* serviceName, + void *callbackHandle, + void (*use)(void *handle, void *svc) +); + +/** + * Use the services with the provided service name using the provided callback. The Celix framework will + * ensure that the targeted service cannot be removed during the callback. + * + * The svc is should only be considered valid during the callback. + * If no service is found the callback will not be invoked. + * + * This function will block till the callback is finished. As result it is possible to provide callback data from the + * stack. + * + * @param ctx The bundle context + * @param serviceName the required service name. + * @param callbackHandle The data pointer, which will be used in the callbacks + * @param use The callback, which will be called for every service found. + */ +void celix_bundleContext_useServices( + celix_bundle_context_t *ctx, + const char* serviceName, + void *callbackHandle, + void (*use)(void *handle, void *svc) +); + +/** + * Service Use Options used to fine tune which services to use and which callbacks to use. + */ +typedef struct celix_service_use_options { + /** + * The service filter options, used to setup the filter for the service to track. + */ + celix_service_filter_options_t filter; + + /** + * The optional callback pointer used in all the provided callback function (set, add, remove, setWithProperties, etc). + */ + void *callbackHandle; + + /** + * The optional use callback will be called when for every services found conform the service filter options + * - in case of findServices - or only for the highest ranking service found - in case of findService -. + * + * @param handle The callbackHandle pointer as provided in the service tracker options. + * @param svc The service pointer of the highest ranking service. + */ + void (*use)(void *handle, void *svc); + + /** + * The optional useWithProperties callback is handled as the use callback, but with the addition that the service properties + * will also be provided to the callback. + */ + void (*useWithProperties)(void *handle, void *svc, const celix_properties_t *props); + + /** + * The optional useWithOwner callback is handled as the yse callback, but with the addition that the service properties + * and the bundle owning the service will also be provided to the callback. + */ + void (*useWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner); +} celix_service_use_options_t; + +/** + * Macro to create a empty celix_service_use_options_t type. + */ +#define CELIX_EMPTY_SERVICE_USE_OPTIONS {.filter.serviceName = NULL, \ + .filter.versionRange = NULL, \ + .filter.filter = NULL, \ + .filter.serviceLanguage = NULL, \ + .callbackHandle = NULL, \ + .use = NULL, \ + .useWithProperties = NULL, \ + .useWithOwner = NULL} + +/** + * Use the services with the provided service filter optons using the provided callback. The Celix framework will + * ensure that the targeted service cannot be removed during the callback. + * + * The svc is should only be considered valid during the callback. + * If no service is found the callback will not be invoked. + * + * This function will block till the callback is finished. As result it is possible to provide callback data from the + * stack. + * + * @param ctx The bundle context. + * @param opts The required options. Note that the serviceName is required. + * @return True if a service was found. + */ +bool celix_bundleContext_useServiceWithOptions( + celix_bundle_context_t *ctx, + const celix_service_use_options_t *opts); + + +/** + * Use the services with the provided service filter optons using the provided callback. The Celix framework will + * ensure that the targeted service cannot be removed during the callback. + * + * The svc is should only be considered valid during the callback. + * If no service is found the callback will not be invoked. + * + * This function will block till the callback is finished. As result it is possible to provide callback data from the + * stack. + * + * @param ctx The bundle context. + * @param opts The required options. Note that the serviceName is required. + */ +void celix_bundleContext_useServicesWithOptions( + celix_bundle_context_t *ctx, + const celix_service_use_options_t *opts); + + + + + + + +/** + * Install and optional start a bundle. + * + * @param ctx The bundle context + * @param bundleLoc The bundle location to the bundle zip file. + * @param autoStart If the bundle should also be started. + * @return the bundleId (>= 0) or < 0 if the bundle could not be installed and possibly started. + */ +long celix_bundleContext_installBundle(celix_bundle_context_t *ctx, const char *bundleLoc, bool autoStart); + +/** + * Uninstall the bundle with the provided bundle id. If needed the bundle will be stopped first. + * + * @param ctx The bundle context + * @param bundleId The bundle id to stop + * @return true if the bundle is correctly uninstalled. False if not. + */ +bool celix_bundleContext_uninstallBundle(celix_bundle_context_t *ctx, long bundleId); + +/** + * track bundles + * The add bundle callback will also be called for already installed bundles. + * + * @param ctx The bundle context. + * @param callbackHandle The data pointer, which will be used in the callbacks + * @param add The callback which will be called for started bundles. + * @param remove The callback which will be called when bundles are stopped. + * @return The bundle tracker id or < 0 if unsuccessful. + */ +long celix_bundleContext_trackBundles( + celix_bundle_context_t* ctx, + void* callbackHandle, + void (*onStarted)(void* handle, const celix_bundle_t *bundle), + void (*onStopped)(void *handle, const celix_bundle_t *bundle) +); + + +/** + * The Service Bundle Tracking options can be used to fine tune the requested bundle tracker options. + */ +typedef struct celix_bundle_tracker_options { + /** + * The optional callback pointer used in all the provided callback function (set, add, remove, setWithProperties, etc). + */ + void* callbackHandle; + + /** + * Tracker callback when a bundle is installed. + * @param handle The handle, contains the value of the callbackHandle. + * @param bundle The bundle which has been started. + * The bundle pointer is only guaranteed to be valid during the callback. + */ + void (*onStarted)(void *handle, const celix_bundle_t *bundle); //highest ranking + + /** + * Tracker callback when a bundle is removed. + * @param handle The handle, contains the value of the callbackHandle. + * @param bundle The bundle which has been started. + * The bundle pointer is only guaranteed to be valid during the callback. + */ + void (*onStopped)(void *handle, const celix_bundle_t *bundle); + + //TODO callback for on installed, resolved, uninstalled ?? + + /** + * + * @param handle The handle, contains the value of the callbackHandle. + * @param event The bundle event. Is only valid during the callback. + */ + void (*onBundleEvent)(void *handle, const celix_bundle_event_t *event); +} celix_bundle_tracking_options_t; + +/** + * Macro to create a empty celix_service_filter_options_t type. + */ +#define CELIX_EMPTY_BUNDLE_TRACKING_OPTIONS {.callbackHandle = NULL, .onStarted = NULL, .onStopped = NULL, .onBundleEvent = NULL} + +/** + * Tracks bundles using the provided bundle tracker options. + * The tracker options are only using during this call and can safely be freed/reused after this call returns. + * (i.e. can be on the stack) + * + * @param ctx The bundle context. + * @param opts The pointer to the bundle tracker options. + * @return The bundle tracker id (>=0) or < 0 if unsuccessful. + */ +long celix_bundleContext_trackBundlesWithOptions( + celix_bundle_context_t* ctx, + const celix_bundle_tracking_options_t *opts +); + +/** + * Use the bundle with the provided bundle id if it is in the active (started) state + * The provided callback will be called if the bundle is found and in the active (started) state. + * + * @param ctx The bundle context. + * @param bundleId The bundle id. + * @param callbackHandle The data pointer, which will be used in the callbacks + * @param use The callback which will be called for the currently started bundles. + * The bundle pointers are only guaranteed to be valid during the callback. + */ +void celix_bundleContext_useBundle( + celix_bundle_context_t *ctx, + long bundleId, + void *callbackHandle, + void (*use)(void *handle, const celix_bundle_t *bundle) +); + +/** + * Use the currently active (started) bundles. + * The provided callback will be called for all the currently started bundles. + * + * @param ctx The bundle context. + * @param callbackHandle The data pointer, which will be used in the callbacks + * @param use The callback which will be called for the currently started bundles. + * The bundle pointers are only guaranteed to be valid during the callback. + */ +void celix_bundleContext_useBundles( + celix_bundle_context_t *ctx, + void *callbackHandle, + void (*use)(void *handle, const celix_bundle_t *bundle) +); + + +//TODO add useBundleWithOptions (e.g. which state) +//TODO findBundles +//TODO trackServiceTracker + +/** + * Gets the dependency manager for this bundle context. + * + * @return the dependency manager or NULL if unsuccessful. + */ +dm_dependency_manager_t* celix_bundleContext_getDependencyManager(celix_bundle_context_t *ctx); + +#ifdef __cplusplus +} +#endif + +#endif //CELIX_BUNDLE_CONTEXT_H_ http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/include/celix_service_factory.h ---------------------------------------------------------------------- diff --git a/framework/include/celix_service_factory.h b/framework/include/celix_service_factory.h index 4373db6..90d2c73 100644 --- a/framework/include/celix_service_factory.h +++ b/framework/include/celix_service_factory.h @@ -16,12 +16,13 @@ *specific language governing permissions and limitations *under the License. */ -#ifndef CELIX_SERVICE_FACTORY_H_ -#define CELIX_SERVICE_FACTORY_H_ -#include "properties.h" +#include "celix_properties.h" #include "bundle.h" +#ifndef CELIX_SERVICE_FACTORY_H_ +#define CELIX_SERVICE_FACTORY_H_ + #ifdef __cplusplus extern "C" { #endif http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/include/service_tracker.h ---------------------------------------------------------------------- diff --git a/framework/include/service_tracker.h b/framework/include/service_tracker.h index baf2a00..db65776 100644 --- a/framework/include/service_tracker.h +++ b/framework/include/service_tracker.h @@ -32,6 +32,7 @@ #include "service_tracker_customizer.h" #include "framework_exports.h" #include "bundle_context.h" +#include "celix_bundle_context.h" #ifdef __cplusplus http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/private/mock/bundle_context_mock.c ---------------------------------------------------------------------- diff --git a/framework/private/mock/bundle_context_mock.c b/framework/private/mock/bundle_context_mock.c index 9d3fe85..7c0b6e6 100644 --- a/framework/private/mock/bundle_context_mock.c +++ b/framework/private/mock/bundle_context_mock.c @@ -27,6 +27,7 @@ #include "CppUTestExt/MockSupport_c.h" #include "bundle_context.h" +#include "celix_bundle_context.h" celix_status_t bundleContext_create(framework_pt framework, framework_logger_pt logger, bundle_pt bundle, bundle_context_pt *bundle_context) { mock_c()->actualCall("bundleContext_create") @@ -239,7 +240,7 @@ dm_dependency_manager_t* celix_bundleContext_getDependencyManager(bundle_context long celix_bundleContext_trackBundlesWithOptions( bundle_context_t* ctx, - const celix_bundle_tracker_options_t *opts) { + const celix_bundle_tracking_options_t *opts) { mock_c()->actualCall("celix_bundleContext_trackBundlesWithOptions") ->withPointerParameters("ctx", ctx) ->withConstPointerParameters("opts", opts); http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/src/bundle.c ---------------------------------------------------------------------- diff --git a/framework/src/bundle.c b/framework/src/bundle.c index 5feb729..fc4cd08 100644 --- a/framework/src/bundle.c +++ b/framework/src/bundle.c @@ -16,13 +16,7 @@ *specific language governing permissions and limitations *under the License. */ -/* - * bundle.c - * - * \date Mar 23, 2010 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ + #include <stdlib.h> #include <string.h> http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/src/bundle_context.c ---------------------------------------------------------------------- diff --git a/framework/src/bundle_context.c b/framework/src/bundle_context.c index f79d101..2407e2d 100644 --- a/framework/src/bundle_context.c +++ b/framework/src/bundle_context.c @@ -26,9 +26,11 @@ #include "bundle_context_private.h" #include "framework_private.h" #include "bundle.h" +#include "celix_bundle.h" #include "celix_log.h" #include "service_tracker.h" #include "dm_dependency_manager.h" +#include "celix_array_list.h" static celix_status_t bundleContext_bundleChanged(void *handle, bundle_event_t *event); static void bundleContext_cleanupBundleTracker(bundle_context_t *ct); @@ -545,7 +547,7 @@ static celix_status_t bundleContext_bundleChanged(void *listenerSvc, bundle_even long celix_bundleContext_trackBundlesWithOptions( bundle_context_t* ctx, - const celix_bundle_tracker_options_t *opts) { + const celix_bundle_tracking_options_t *opts) { long trackId = -1; struct celix_bundle_context_bundle_tracker *tracker = calloc(1, sizeof(*tracker)); if (tracker != NULL) { @@ -580,7 +582,7 @@ long celix_bundleContext_trackBundles( void* callbackHandle, void (*onStarted)(void* handle, const bundle_t *bundle), void (*onStopped)(void *handle, const bundle_t *bundle)) { - celix_bundle_tracker_options_t opts; + celix_bundle_tracking_options_t opts; memset(&opts, 0, sizeof(opts)); opts.callbackHandle = callbackHandle; opts.onStarted = onStarted; @@ -739,7 +741,7 @@ bool celix_bundleContext_useServiceWithOptions( trkOpts.filter.serviceName = opts->filter.serviceName; trkOpts.filter = opts->filter; trkOpts.filter.versionRange = opts->filter.versionRange; - trkOpts.filter.lang = opts->filter.lang; + trkOpts.filter.serviceLanguage = opts->filter.serviceLanguage; service_tracker_t *trk = celix_serviceTracker_createWithOptions(ctx, &trkOpts); if (trk != NULL) { @@ -770,7 +772,7 @@ void celix_bundleContext_useServicesWithOptions( trkOpts.filter.serviceName = opts->filter.serviceName; trkOpts.filter.filter = opts->filter.filter; trkOpts.filter.versionRange = opts->filter.versionRange; - trkOpts.filter.lang = opts->filter.lang; + trkOpts.filter.serviceLanguage = opts->filter.serviceLanguage; service_tracker_t *trk = celix_serviceTracker_createWithOptions(ctx, &trkOpts); if (trk != NULL) { http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/src/bundle_context_private.h ---------------------------------------------------------------------- diff --git a/framework/src/bundle_context_private.h b/framework/src/bundle_context_private.h index 43533f8..fc3077f 100644 --- a/framework/src/bundle_context_private.h +++ b/framework/src/bundle_context_private.h @@ -31,12 +31,13 @@ #include "bundle_context.h" #include "celix_log.h" #include "bundle_listener.h" +#include "celix_bundle_context.h" typedef struct celix_bundle_context_bundle_tracker { bundle_context_t *ctx; long trackId; bundle_listener_t listener; - celix_bundle_tracker_options_t opts; + celix_bundle_tracking_options_t opts; } celix_bundle_context_bundle_tracker_t; struct bundleContext { http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/src/bundle_private.h ---------------------------------------------------------------------- diff --git a/framework/src/bundle_private.h b/framework/src/bundle_private.h index 8085609..ea0a06e 100644 --- a/framework/src/bundle_private.h +++ b/framework/src/bundle_private.h @@ -16,18 +16,13 @@ *specific language governing permissions and limitations *under the License. */ -/* - * bundle_private.h - * - * \date Feb 18, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ + #ifndef BUNDLE_PRIVATE_H_ #define BUNDLE_PRIVATE_H_ #include "bundle.h" +#include "celix_bundle.h" struct bundle { bundle_context_pt context; http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/src/framework.c ---------------------------------------------------------------------- diff --git a/framework/src/framework.c b/framework/src/framework.c index 952392c..2460434 100644 --- a/framework/src/framework.c +++ b/framework/src/framework.c @@ -41,6 +41,7 @@ #include "listener_hook_service.h" #include "service_registration_private.h" #include "bundle_private.h" +#include "celix_bundle_context.h" typedef celix_status_t (*create_function_fp)(bundle_context_t *context, void **userData); typedef celix_status_t (*start_function_fp)(void *userData, bundle_context_t *context); http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/src/service_tracker.c ---------------------------------------------------------------------- diff --git a/framework/src/service_tracker.c b/framework/src/service_tracker.c index 56ad199..e718874 100644 --- a/framework/src/service_tracker.c +++ b/framework/src/service_tracker.c @@ -30,6 +30,7 @@ #include "celix_log.h" #include "service_tracker_customizer_private.h" #include "bundle_context_private.h" +#include "celix_array_list.h" static celix_status_t serviceTracker_track(service_tracker_pt tracker, service_reference_pt reference, service_event_pt event); static celix_status_t serviceTracker_untrack(service_tracker_pt tracker, service_reference_pt reference, service_event_pt event); @@ -597,7 +598,7 @@ celix_service_tracker_t* celix_serviceTracker_createWithOptions( tracker->currentHighestServiceId = -1; //setting lang - const char *lang = opts->filter.lang; + const char *lang = opts->filter.serviceLanguage; if (lang == NULL || strncmp("", lang, 1) == 0) { lang = CELIX_FRAMEWORK_SERVICE_C_LANGUAGE; } http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/tst/bundle_context_bundles_tests.cpp ---------------------------------------------------------------------- diff --git a/framework/tst/bundle_context_bundles_tests.cpp b/framework/tst/bundle_context_bundles_tests.cpp index 39fdb6c..d71d748 100644 --- a/framework/tst/bundle_context_bundles_tests.cpp +++ b/framework/tst/bundle_context_bundles_tests.cpp @@ -26,9 +26,7 @@ #include <CppUTest/CommandLineTestRunner.h> #include <zconf.h> -#include "bundle.h" -#include "properties.h" -#include "celix_framework_factory.h" +#include "celix_api.h" TEST_GROUP(CelixBundleContextBundlesTests) { http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/framework/tst/bundle_context_services_test.cpp ---------------------------------------------------------------------- diff --git a/framework/tst/bundle_context_services_test.cpp b/framework/tst/bundle_context_services_test.cpp index 9162212..1302f0a 100644 --- a/framework/tst/bundle_context_services_test.cpp +++ b/framework/tst/bundle_context_services_test.cpp @@ -25,9 +25,7 @@ #include <string.h> #include <map> -#include "constants.h" -#include "bundle.h" -#include "properties.h" +#include "celix_api.h" #include "celix_framework_factory.h" #include "celix_service_factory.h" http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/shell/src/dm_shell_list_command.c ---------------------------------------------------------------------- diff --git a/shell/src/dm_shell_list_command.c b/shell/src/dm_shell_list_command.c index 8a0778f..d2a0dbb 100644 --- a/shell/src/dm_shell_list_command.c +++ b/shell/src/dm_shell_list_command.c @@ -20,7 +20,7 @@ #include <stdlib.h> #include <string.h> #include <shell_constants.h> -#include "bundle_context.h" +#include "celix_bundle_context.h" #include "dm_dependency_manager.h" http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/utils/include/array_list.h ---------------------------------------------------------------------- diff --git a/utils/include/array_list.h b/utils/include/array_list.h index 7003501..bdf9547 100644 --- a/utils/include/array_list.h +++ b/utils/include/array_list.h @@ -48,8 +48,6 @@ typedef union celix_array_list_entry { size_t sizeVal; } celix_array_list_entry_t; -typedef struct celix_arrayList celix_array_list_t; - typedef struct celix_arrayList *array_list_pt; typedef struct celix_arrayList array_list_t; @@ -112,56 +110,6 @@ UTILS_EXPORT void *arrayListIterator_previous(array_list_iterator_pt iterator); UTILS_EXPORT void arrayListIterator_remove(array_list_iterator_pt iterator); - - -/********************************************************************************************************************** - ********************************************************************************************************************** - * Updated API - ********************************************************************************************************************** - **********************************************************************************************************************/ - - -celix_array_list_t* celix_arrayList_create(); - -celix_array_list_t* celix_arrayList_createWithEquals(celix_arrayList_equals_fp equals); - -void celix_arrayList_destroy(celix_array_list_t *list); - -size_t celix_arrayList_size(const celix_array_list_t *list); - -void* celix_arrayList_get(const celix_array_list_t *list, int index); - -//more of the same for the different entry types -int celix_arrayList_getInt(const celix_array_list_t *list, int index); -long int celix_arrayList_getLong(const celix_array_list_t *list, int index); -unsigned int celix_arrayList_getUInt(const celix_array_list_t *list, int index); -unsigned long int celix_arrayList_getULong(const celix_array_list_t *list, int index); -float celix_arrayList_getFloat(const celix_array_list_t *list, int index); -double celix_arrayList_getDouble(const celix_array_list_t *list, int index); -bool celix_arrayList_getBool(const celix_array_list_t *list, int index); -size_t celix_arrayList_getSize(const celix_array_list_t *list, int index); - -void celix_arrayList_add(celix_array_list_t *list, void* val); - -//more of the same for the different entry types -void celix_arrayList_addInt(celix_array_list_t *list, int val); -void celix_arrayList_addLong(celix_array_list_t *list, long val); -void celix_arrayList_addUInt(celix_array_list_t *list, unsigned int val); -void celix_arrayList_addULong(celix_array_list_t *list, unsigned long val); -void celix_arrayList_addFloat(celix_array_list_t *list, float val); -void celix_arrayList_addDouble(celix_array_list_t *list, double val); -void celix_arrayList_addBool(celix_array_list_t *list, bool val); -void celix_arrayList_addSize(celix_array_list_t *list, size_t val); - -int celix_arrayList_indexOf(celix_array_list_t *list, celix_array_list_entry_t entry); -void celix_arrayList_remove(celix_array_list_t *list, int index); - -/** - * Remove entry from array list. To use this first memset the entry to null to ensure it completely initialized or - * ensure that the array list is created with a custom equals which matches the used entry. - */ -void celix_arrayList_removeEntry(celix_array_list_t *list, celix_array_list_entry_t entry); - #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/utils/include/celix_array_list.h ---------------------------------------------------------------------- diff --git a/utils/include/celix_array_list.h b/utils/include/celix_array_list.h new file mode 100644 index 0000000..550004c --- /dev/null +++ b/utils/include/celix_array_list.h @@ -0,0 +1,84 @@ +/** + *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. + */ + +#include "celixbool.h" +#include "exports.h" +#include "celix_errno.h" +#include "stdbool.h" + +#ifndef CELIX_ARRAY_LIST_H_ +#define CELIX_ARRAY_LIST_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/********************************************************************************************************************** + ********************************************************************************************************************** + * Updated API + ********************************************************************************************************************** + **********************************************************************************************************************/ + +typedef struct celix_arrayList celix_array_list_t; + +celix_array_list_t* celix_arrayList_create(); + +celix_array_list_t* celix_arrayList_createWithEquals(celix_arrayList_equals_fp equals); + +void celix_arrayList_destroy(celix_array_list_t *list); + +size_t celix_arrayList_size(const celix_array_list_t *list); + +void* celix_arrayList_get(const celix_array_list_t *list, int index); + +//more of the same for the different entry types +int celix_arrayList_getInt(const celix_array_list_t *list, int index); +long int celix_arrayList_getLong(const celix_array_list_t *list, int index); +unsigned int celix_arrayList_getUInt(const celix_array_list_t *list, int index); +unsigned long int celix_arrayList_getULong(const celix_array_list_t *list, int index); +float celix_arrayList_getFloat(const celix_array_list_t *list, int index); +double celix_arrayList_getDouble(const celix_array_list_t *list, int index); +bool celix_arrayList_getBool(const celix_array_list_t *list, int index); +size_t celix_arrayList_getSize(const celix_array_list_t *list, int index); + +void celix_arrayList_add(celix_array_list_t *list, void* val); + +//more of the same for the different entry types +void celix_arrayList_addInt(celix_array_list_t *list, int val); +void celix_arrayList_addLong(celix_array_list_t *list, long val); +void celix_arrayList_addUInt(celix_array_list_t *list, unsigned int val); +void celix_arrayList_addULong(celix_array_list_t *list, unsigned long val); +void celix_arrayList_addFloat(celix_array_list_t *list, float val); +void celix_arrayList_addDouble(celix_array_list_t *list, double val); +void celix_arrayList_addBool(celix_array_list_t *list, bool val); +void celix_arrayList_addSize(celix_array_list_t *list, size_t val); + +int celix_arrayList_indexOf(celix_array_list_t *list, celix_array_list_entry_t entry); +void celix_arrayList_remove(celix_array_list_t *list, int index); + +/** + * Remove entry from array list. To use this first memset the entry to null to ensure it completely initialized or + * ensure that the array list is created with a custom equals which matches the used entry. + */ +void celix_arrayList_removeEntry(celix_array_list_t *list, celix_array_list_entry_t entry); + +#ifdef __cplusplus +} +#endif +#endif /* CELIX_ARRAY_LIST_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/utils/include/celix_properties.h ---------------------------------------------------------------------- diff --git a/utils/include/celix_properties.h b/utils/include/celix_properties.h new file mode 100644 index 0000000..fcb2aec --- /dev/null +++ b/utils/include/celix_properties.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. + */ + +#include <stdio.h> + +#include "hash_map.h" +#include "exports.h" +#include "celix_errno.h" + +#ifndef CELIX_PROPERTIES_H_ +#define CELIX_PROPERTIES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef hash_map_t celix_properties_t; + + +/********************************************************************************************************************** + ********************************************************************************************************************** + * Updated API + ********************************************************************************************************************** + **********************************************************************************************************************/ + +celix_properties_t* celix_properties_create(void); + +void celix_properties_destroy(celix_properties_t *properties); + +celix_properties_t* celix_properties_load(const char *filename); + +celix_properties_t* celix_properties_loadWithStream(FILE *stream); + +celix_properties_t* celix_properties_loadFromString(const char *input); + +void celix_properties_store(celix_properties_t *properties, const char *file, const char *header); + +const char* celix_properties_get(const celix_properties_t *properties, const char *key); + +const char* celix_properties_getWithDefault(const celix_properties_t *properties, const char *key, const char *defaultValue); + +void celix_properties_set(celix_properties_t *properties, const char *key, const char *value); + +void celix_properties_unset(celix_properties_t *properties, const char *key); + +celix_properties_t* celix_properties_copy(celix_properties_t *properties); + +long celix_properties_getAsLong(const celix_properties_t *props, const char *key, long defaultValue); + +void celix_properties_setLong(celix_properties_t *props, const char *key, long value); + +#define CELIX_PROPERTIES_FOR_EACH(props, key) \ + for(hash_map_iterator_t iter = hashMapIterator_construct(props); \ + hashMapIterator_hasNext(&iter), (key) = (const char*)hashMapIterator_nextKey(&iter);) + + + +#ifdef __cplusplus +} +#endif + +#endif /* CELIX_PROPERTIES_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/utils/include/properties.h ---------------------------------------------------------------------- diff --git a/utils/include/properties.h b/utils/include/properties.h index 5a19cb7..0efe0c4 100644 --- a/utils/include/properties.h +++ b/utils/include/properties.h @@ -38,8 +38,6 @@ extern "C" { typedef hash_map_pt properties_pt; typedef hash_map_t properties_t; -typedef hash_map_t celix_properties_t; - UTILS_EXPORT properties_pt properties_create(void); UTILS_EXPORT void properties_destroy(properties_pt properties); @@ -67,44 +65,6 @@ UTILS_EXPORT celix_status_t properties_copy(properties_pt properties, properties hashMapIterator_hasNext(&iter), (key) = (const char*)hashMapIterator_nextKey(&iter);) -/********************************************************************************************************************** - ********************************************************************************************************************** - * Updated API - ********************************************************************************************************************** - **********************************************************************************************************************/ - -celix_properties_t* celix_properties_create(void); - -void celix_properties_destroy(celix_properties_t *properties); - -celix_properties_t* celix_properties_load(const char *filename); - -celix_properties_t* celix_properties_loadWithStream(FILE *stream); - -celix_properties_t* celix_properties_loadFromString(const char *input); - -void celix_properties_store(celix_properties_t *properties, const char *file, const char *header); - -const char* celix_properties_get(const celix_properties_t *properties, const char *key); - -const char* celix_properties_getWithDefault(const celix_properties_t *properties, const char *key, const char *defaultValue); - -void celix_properties_set(celix_properties_t *properties, const char *key, const char *value); - -void celix_properties_unset(celix_properties_t *properties, const char *key); - -celix_properties_t* celix_properties_copy(celix_properties_t *properties); - -long celix_properties_getAsLong(const celix_properties_t *props, const char *key, long defaultValue); - -void celix_properties_setLong(celix_properties_t *props, const char *key, long value); - -#define CELIX_PROPERTIES_FOR_EACH(props, key) \ - for(hash_map_iterator_t iter = hashMapIterator_construct(props); \ - hashMapIterator_hasNext(&iter), (key) = (const char*)hashMapIterator_nextKey(&iter);) - - - #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/utils/src/array_list.c ---------------------------------------------------------------------- diff --git a/utils/src/array_list.c b/utils/src/array_list.c index 6a48c7a..e66a3c8 100644 --- a/utils/src/array_list.c +++ b/utils/src/array_list.c @@ -28,6 +28,7 @@ #include <string.h> #include "array_list.h" +#include "celix_array_list.h" #include "array_list_private.h" static celix_status_t arrayList_elementEquals(const void *a, const void *b, bool *equals); http://git-wip-us.apache.org/repos/asf/celix/blob/03df0edc/utils/src/properties.c ---------------------------------------------------------------------- diff --git a/utils/src/properties.c b/utils/src/properties.c index 5af5646..c8b59a2 100644 --- a/utils/src/properties.c +++ b/utils/src/properties.c @@ -29,6 +29,7 @@ #include <ctype.h> #include "celixbool.h" #include "properties.h" +#include "celix_properties.h" #include "utils.h" #define MALLOC_BLOCK_SIZE 5
