You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2015/11/03 12:09:38 UTC
[01/21] celix git commit: Fixed some issue with dm. Changed some
naming which reflects better with Celix (e.g. addInterface instead of
setItnterface). Add support for callbacks with refs.
Repository: celix
Updated Branches:
refs/heads/develop 2e480a297 -> 04b686237
Fixed some issue with dm. Changed some naming which reflects better with Celix (e.g. addInterface instead of setItnterface). Add support for callbacks with refs.
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/a135fad4
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/a135fad4
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/a135fad4
Branch: refs/heads/develop
Commit: a135fad4f28842ac61a30ef1f2a24c1a163b6419
Parents: 4fc908f
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Oct 9 14:11:55 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Oct 9 14:11:55 2015 +0200
----------------------------------------------------------------------
.../private/include/dm_component_impl.h | 13 +++--
.../include/dm_service_dependency_impl.h | 5 ++
.../private/src/dm_activator_base.c | 4 +-
.../private/src/dm_component_impl.c | 58 +++++++++++++++-----
.../private/src/dm_service_dependency.c | 45 +++++++++++++--
.../public/include/dm_activator_base.h | 1 +
.../public/include/dm_component.h | 2 +-
.../public/include/dm_service_dependency.h | 14 +++--
framework/private/src/service_registry.c | 2 +-
9 files changed, 113 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/private/include/dm_component_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/include/dm_component_impl.h b/dependency_manager_2/private/include/dm_component_impl.h
index e56a261..133ef06 100644
--- a/dependency_manager_2/private/include/dm_component_impl.h
+++ b/dependency_manager_2/private/include/dm_component_impl.h
@@ -42,15 +42,20 @@ typedef enum dm_component_state {
typedef struct dm_executor * dm_executor_pt;
+typedef struct dm_interface_struct {
+ char *serviceName;
+ void *service;
+ properties_pt properties;
+ service_registration_pt registration;
+} dm_interface;
+
struct dm_component {
bundle_context_pt context;
dm_dependency_manager_pt manager;
- char *serviceName;
- void *service;
+ array_list_pt dm_interface;
+
void *implementation;
- properties_pt properties;
- service_registration_pt registration;
init_fpt callbackInit;
start_fpt callbackStart;
http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/private/include/dm_service_dependency_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/include/dm_service_dependency_impl.h b/dependency_manager_2/private/include/dm_service_dependency_impl.h
index e4c0f6e..1396f31 100644
--- a/dependency_manager_2/private/include/dm_service_dependency_impl.h
+++ b/dependency_manager_2/private/include/dm_service_dependency_impl.h
@@ -46,6 +46,11 @@ struct dm_service_dependency {
service_remove_fpt remove;
service_swap_fpt swap;
+ service_add_with_ref_fpt add_with_ref;
+ service_change_with_ref_fpt change_with_ref;
+ service_remove_with_ref_fpt remove_with_ref;
+ service_swap_with_ref_fpt swap_with_ref;
+
void **autoConfigure;
celix_thread_mutex_t lock;
http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/private/src/dm_activator_base.c
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/src/dm_activator_base.c b/dependency_manager_2/private/src/dm_activator_base.c
index 7623780..a97194e 100644
--- a/dependency_manager_2/private/src/dm_activator_base.c
+++ b/dependency_manager_2/private/src/dm_activator_base.c
@@ -74,7 +74,7 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context _
celix_status_t status = CELIX_SUCCESS;
dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
- dm_destroy(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
+ dm_deinit(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
dependencyManager_destroy(&dependency_activator->manager);
@@ -88,6 +88,8 @@ celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt contex
celix_status_t status = CELIX_SUCCESS;
dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
+ dm_destroy(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
+
free(dependency_activator);
return status;
http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/src/dm_component_impl.c b/dependency_manager_2/private/src/dm_component_impl.c
index 7217c24..72fe7eb 100644
--- a/dependency_manager_2/private/src/dm_component_impl.c
+++ b/dependency_manager_2/private/src/dm_component_impl.c
@@ -26,6 +26,7 @@
#include <stdarg.h>
#include <stdlib.h>
+#include <string.h>
#include "dm_component_impl.h"
#include "../../../framework/private/include/framework_private.h"
@@ -101,11 +102,9 @@ celix_status_t component_create(bundle_context_pt context, dm_dependency_manager
(*component)->context = context;
(*component)->manager = manager;
- (*component)->serviceName = NULL;
- (*component)->service = NULL;
+ arrayList_create(&((*component)->dm_interface));
+
(*component)->implementation = NULL;
- (*component)->properties = NULL;
- (*component)->registration = NULL;
(*component)->callbackInit = NULL;
(*component)->callbackStart = NULL;
@@ -137,6 +136,15 @@ celix_status_t component_destroy(dm_component_pt *component_ptr) {
}
if (status == CELIX_SUCCESS) {
+ unsigned int i;
+
+ for (i = 0; i < arrayList_size((*component_ptr)->dm_interface); i++) {
+ dm_interface *interface = arrayList_get((*component_ptr)->dm_interface, i);
+
+ free (interface->serviceName);
+ }
+ arrayList_destroy((*component_ptr)->dm_interface);
+
// #TODO destroy dependencies?
executor_destroy(&(*component_ptr)->executor);
hashMap_destroy((*component_ptr)->dependencyEvents, false, false);
@@ -279,15 +287,27 @@ celix_status_t component_stopTask(dm_component_pt component, void *data __attrib
return status;
}
-celix_status_t component_setInterface(dm_component_pt component, char *serviceName, void *service, properties_pt properties) {
+celix_status_t component_addInterface(dm_component_pt component, char *serviceName, void *service, properties_pt properties) {
celix_status_t status = CELIX_SUCCESS;
if (component->active) {
return CELIX_ILLEGAL_STATE;
} else {
- component->serviceName = serviceName;
- component->service = service;
- component->properties = properties;
+ dm_interface *interface = (dm_interface *) malloc (sizeof (dm_interface));
+ char *name = strdup (serviceName);
+
+ if (interface && name) {
+ interface->serviceName = name;
+ interface->service = service;
+ interface->properties = properties;
+ interface->registration = NULL;
+ arrayList_add(component->dm_interface, interface);
+ }
+ else {
+ free (interface);
+ free (name);
+ status = CELIX_ENOMEM;
+ }
}
return status;
@@ -1063,7 +1083,7 @@ celix_status_t component_configureImplementation(dm_component_pt component, dm_s
celix_status_t component_destroyComponent(dm_component_pt component) {
celix_status_t status = CELIX_SUCCESS;
- component->implementation = NULL;
+// component->implementation = NULL;
return status;
}
@@ -1071,8 +1091,14 @@ celix_status_t component_destroyComponent(dm_component_pt component) {
celix_status_t component_registerService(dm_component_pt component) {
celix_status_t status = CELIX_SUCCESS;
- if (component->context && component->serviceName) {
- bundleContext_registerService(component->context, component->serviceName, component->service, component->properties, &component->registration);
+ if (component->context) {
+ unsigned int i;
+
+ for (i = 0; i < arrayList_size(component->dm_interface); i++) {
+ dm_interface *interface = arrayList_get(component->dm_interface, i);
+
+ bundleContext_registerService(component->context, interface->serviceName, interface->service, interface->properties, &interface->registration);
+ }
}
return status;
@@ -1081,9 +1107,13 @@ celix_status_t component_registerService(dm_component_pt component) {
celix_status_t component_unregisterService(dm_component_pt component) {
celix_status_t status = CELIX_SUCCESS;
- if (component->registration && component->serviceName) {
- serviceRegistration_unregister(component->registration);
- component->registration = NULL;
+ unsigned int i;
+
+ for (i = 0; i < arrayList_size(component->dm_interface); i++) {
+ dm_interface *interface = arrayList_get(component->dm_interface, i);
+
+ serviceRegistration_unregister(interface->registration);
+ interface->registration = NULL;
}
return status;
http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/src/dm_service_dependency.c b/dependency_manager_2/private/src/dm_service_dependency.c
index dbe5d70..8f65ddb 100644
--- a/dependency_manager_2/private/src/dm_service_dependency.c
+++ b/dependency_manager_2/private/src/dm_service_dependency.c
@@ -52,6 +52,12 @@ celix_status_t serviceDependency_create(dm_service_dependency_pt *dependency_ptr
(*dependency_ptr)->add = NULL;
(*dependency_ptr)->change = NULL;
(*dependency_ptr)->remove = NULL;
+ (*dependency_ptr)->swap = NULL;
+
+ (*dependency_ptr)->add_with_ref = NULL;
+ (*dependency_ptr)->change_with_ref = NULL;
+ (*dependency_ptr)->remove_with_ref = NULL;
+ (*dependency_ptr)->swap_with_ref = NULL;
(*dependency_ptr)->autoConfigure = NULL;
@@ -157,6 +163,23 @@ celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependenc
return status;
}
+celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ dependency->add_with_ref = add;
+ dependency->change_with_ref = change;
+ dependency->remove_with_ref = remove;
+ dependency->swap_with_ref = swap;
+ }
+
+ return status;
+}
+
celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t *service_lock, void **field) {
celix_status_t status = CELIX_SUCCESS;
@@ -295,7 +318,10 @@ celix_status_t serviceDependency_invokeAdd(dm_service_dependency_pt dependency,
if (status == CELIX_SUCCESS) {
if (dependency->add) {
- dependency->add(dependency->component->implementation, event->reference, event->service);
+ dependency->add(dependency->component->implementation, event->service);
+ }
+ if (dependency->add_with_ref) {
+ dependency->add_with_ref(dependency->component->implementation, event->reference, event->service);
}
}
@@ -311,7 +337,10 @@ celix_status_t serviceDependency_invokeChange(dm_service_dependency_pt dependenc
if (status == CELIX_SUCCESS) {
if (dependency->change) {
- dependency->change(dependency->component->implementation, event->reference, event->service);
+ dependency->change(dependency->component->implementation, event->service);
+ }
+ if (dependency->change_with_ref) {
+ dependency->change_with_ref(dependency->component->implementation, event->reference, event->service);
}
}
@@ -327,7 +356,10 @@ celix_status_t serviceDependency_invokeRemove(dm_service_dependency_pt dependenc
if (status == CELIX_SUCCESS) {
if (dependency->remove) {
- dependency->remove(dependency->component->implementation, event->reference, event->service);
+ dependency->remove(dependency->component->implementation, event->service);
+ }
+ if (dependency->remove_with_ref) {
+ dependency->remove_with_ref(dependency->component->implementation, event->reference, event->service);
}
}
@@ -343,9 +375,10 @@ celix_status_t serviceDependency_invokeSwap(dm_service_dependency_pt dependency,
if (status == CELIX_SUCCESS) {
if (dependency->swap) {
- dependency
- ->swap(dependency->component->implementation, event->reference, event->service, newEvent->reference,
- newEvent->service);
+ dependency->swap(dependency->component->implementation, event->service, newEvent->service);
+ }
+ if (dependency->swap_with_ref) {
+ dependency->swap_with_ref(dependency->component->implementation, event->reference, event->service, newEvent->reference, newEvent->service);
}
}
http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/public/include/dm_activator_base.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/public/include/dm_activator_base.h b/dependency_manager_2/public/include/dm_activator_base.h
index a439ee5..80196e2 100644
--- a/dependency_manager_2/public/include/dm_activator_base.h
+++ b/dependency_manager_2/public/include/dm_activator_base.h
@@ -35,6 +35,7 @@
celix_status_t dm_create(bundle_context_pt context, void ** userData);
celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager);
+celix_status_t dm_deinit(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager);
celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager);
#endif /* DM_ACTIVATOR_BASE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/public/include/dm_component.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/public/include/dm_component.h b/dependency_manager_2/public/include/dm_component.h
index 3471fdb..f98c3bb 100644
--- a/dependency_manager_2/public/include/dm_component.h
+++ b/dependency_manager_2/public/include/dm_component.h
@@ -43,7 +43,7 @@ typedef celix_status_t (*destroy_fpt)(void *userData);
celix_status_t component_create(bundle_context_pt context, dm_dependency_manager_pt manager, dm_component_pt *component);
celix_status_t component_destroy(dm_component_pt *component);
-celix_status_t component_setInterface(dm_component_pt component, char *serviceName, void *service, properties_pt properties);
+celix_status_t component_addInterface(dm_component_pt component, char *serviceName, void *service, properties_pt properties);
celix_status_t component_setImplementation(dm_component_pt component, void *implementation);
celix_status_t component_addServiceDependency(dm_component_pt component, ...);
http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/dependency_manager_2/public/include/dm_service_dependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/public/include/dm_service_dependency.h b/dependency_manager_2/public/include/dm_service_dependency.h
index f885336..e9a5513 100644
--- a/dependency_manager_2/public/include/dm_service_dependency.h
+++ b/dependency_manager_2/public/include/dm_service_dependency.h
@@ -33,10 +33,15 @@ typedef struct dm_service_dependency *dm_service_dependency_pt;
#include "dm_component.h"
-typedef celix_status_t (*service_add_fpt)(void *handle, service_reference_pt reference, void *service);
-typedef celix_status_t (*service_change_fpt)(void *handle, service_reference_pt reference, void *service);
-typedef celix_status_t (*service_remove_fpt)(void *handle, service_reference_pt reference, void *service);
-typedef celix_status_t (*service_swap_fpt)(void *handle, service_reference_pt oldReference, void *oldService, service_reference_pt newReference, void *newService);
+typedef celix_status_t (*service_add_fpt)(void *handle, void *service);
+typedef celix_status_t (*service_change_fpt)(void *handle, void *service);
+typedef celix_status_t (*service_remove_fpt)(void *handle, void *service);
+typedef celix_status_t (*service_swap_fpt)(void *handle, void *oldService, void *newService);
+
+typedef celix_status_t (*service_add_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
+typedef celix_status_t (*service_change_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
+typedef celix_status_t (*service_remove_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
+typedef celix_status_t (*service_swap_with_ref_fpt)(void *handle, service_reference_pt oldReference, void *oldService, service_reference_pt newReference, void *newService);
celix_status_t serviceDependency_create(dm_service_dependency_pt *dependency_ptr);
celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_ptr);
@@ -44,6 +49,7 @@ celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_pt
celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required);
celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName, char *filter);
celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap);
+celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap);
celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t *service_lock, void **field);
#endif /* DM_SERVICE_DEPENDENCY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a135fad4/framework/private/src/service_registry.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_registry.c b/framework/private/src/service_registry.c
index 85639b4..76c67f3 100644
--- a/framework/private/src/service_registry.c
+++ b/framework/private/src/service_registry.c
@@ -265,7 +265,7 @@ celix_status_t serviceRegistry_unregisterService(service_registry_pt registry, b
//TODO not needed, the registration is destroyed, any reference to the registration is invalid and will result in a segfault
serviceRegistration_invalidate(registration);
- serviceRegistration_destroy(registration);
+ // serviceRegistration_destroy(registration);
celixThreadMutex_unlock(®istry->mutex);
[15/21] celix git commit: CELIX-269: Merge branch 'develop' into
depman
Posted by pn...@apache.org.
CELIX-269: Merge branch 'develop' into depman
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/d040f001
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/d040f001
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/d040f001
Branch: refs/heads/develop
Commit: d040f001a4a23e03d314556c806c6864a730afce
Parents: 0ad3a1f c58615d
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Oct 29 16:24:13 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Oct 29 16:24:13 2015 +0100
----------------------------------------------------------------------
.gitignore | 3 +
.travis.yml | 45 +-
CMakeLists.txt | 15 +-
LICENSE | 26 +-
README.md | 2 +-
cmake/CMakeCelix.cmake | 2 +-
cmake/FindCppUTest.cmake | 34 +-
cmake/FindFFI.cmake | 57 +
cmake/cmake_celix/CodeCoverage.cmake | 48 +-
cmake/cmake_celix/Test.cmake | 52 -
deployment_admin/CMakeLists.txt | 2 +-
.../private/include/deployment_admin.h | 4 +-
deployment_admin/private/src/deployment_admin.c | 253 ++--
.../private/src/deployment_admin_activator.c | 2 +-
.../private/src/deployment_package.c | 19 +-
deployment_admin/private/src/log.c | 2 +-
framework/CMakeLists.txt | 62 +-
framework/private/include/framework_private.h | 2 +
framework/private/src/bundle_cache.c | 5 +-
framework/private/src/celix_launcher.c | 190 +++
framework/private/src/celix_log.c | 5 +-
framework/private/src/framework.c | 173 +--
framework/private/src/properties.c | 13 +-
framework/private/src/service_registration.c | 7 +-
framework/private/src/service_registry.c | 2 +-
framework/public/include/celix_launcher.h | 41 +
framework/public/include/properties.h | 3 +
framework/tst/CMakeLists.txt | 30 +
framework/tst/config.properties.in | 2 +
framework/tst/framework1.properties.in | 3 +
framework/tst/framework2.properties.in | 3 +
framework/tst/multiple_frameworks_test.cpp | 89 ++
framework/tst/run_tests.cpp | 9 +
framework/tst/single_framework_test.cpp | 69 ++
launcher/CMakeLists.txt | 10 +-
launcher/private/src/launcher.c | 204 ----
launcher/private/src/main.c | 88 ++
log_service/private/src/log_factory.c | 2 +-
remote_services/CMakeLists.txt | 11 +-
.../private/src/endpoint_discovery_poller.c | 5 +-
.../public/include/endpoint_listener.h | 48 -
.../examples/calculator_service/CMakeLists.txt | 5 +-
.../public/include/calculator_service.h | 6 +-
...apache.celix.calc.api.Calculator2.descriptor | 11 +
.../examples/calculator_shell/CMakeLists.txt | 4 +
.../calculator_shell/private/src/add_command.c | 2 +-
.../calculator_shell/private/src/sqrt_command.c | 2 +-
.../calculator_shell/private/src/sub_command.c | 2 +-
remote_services/examples/deploy.cmake | 4 +-
.../remote_service_admin/CMakeLists.txt | 8 +-
.../private/include/export_registration_impl.h | 3 -
.../private/include/remote_service_admin_impl.h | 17 -
.../private/src/export_registration_impl.c | 22 +-
.../private/src/import_registration_impl.c | 17 +
.../public/include/endpoint_listener.h | 48 +
.../public/include/export_registration.h | 22 +
.../public/include/import_registration.h | 22 +
.../public/include/remote_constants.h | 38 +
.../public/include/remote_service_admin.h | 6 +-
.../remote_service_admin_dfi/CMakeLists.txt | 31 +
.../dynamic_function_interface/CMakeLists.txt | 22 +
.../dynamic_function_interface/dfi_log_util.h | 48 +
.../dynamic_function_interface/dyn_common.c | 136 +++
.../dynamic_function_interface/dyn_common.h | 32 +
.../dynamic_function_interface/dyn_function.c | 320 +++++
.../dynamic_function_interface/dyn_function.h | 46 +
.../dynamic_function_interface/dyn_interface.c | 416 +++++++
.../dynamic_function_interface/dyn_interface.h | 48 +
.../dynamic_function_interface/dyn_type.c | 1129 ++++++++++++++++++
.../dynamic_function_interface/dyn_type.h | 142 +++
.../dynamic_function_interface/json_rpc.c | 318 +++++
.../dynamic_function_interface/json_rpc.h | 22 +
.../json_serializer.c | 452 +++++++
.../json_serializer.h | 22 +
.../memstream/README.md | 49 +
.../memstream/fmemopen.c | 78 ++
.../memstream/fmemopen.h | 52 +
.../memstream/open_memstream.c | 130 ++
.../memstream/open_memstream.h | 15 +
.../CMakeLists.txt | 27 +
.../avro_descriptor_translator_tests.cpp | 164 +++
.../descriptors/example1.descriptor | 13 +
.../descriptors/example2.descriptor | 9 +
.../descriptors/example3.descriptor | 11 +
.../descriptors/example4.descriptor | 8 +
.../dyn_closure_tests.cpp | 146 +++
.../dyn_function_tests.cpp | 237 ++++
.../dyn_interface_tests.cpp | 103 ++
.../dyn_type_tests.cpp | 281 +++++
.../json_rpc_tests.cpp | 413 +++++++
.../json_serializer_tests.cpp | 493 ++++++++
.../run_tests.cpp | 9 +
.../schemas/complex.avdl | 11 +
.../schemas/complex.avpr | 36 +
.../schemas/invalid1.avpr | 29 +
.../schemas/invalid2.avpr | 31 +
.../schemas/simple.avdl | 6 +
.../schemas/simple.avpr | 33 +
.../schemas/simple_min.avpr | 1 +
.../remote_service_admin_dfi/rsa/CMakeLists.txt | 47 +
.../private/include/export_registration_dfi.h | 21 +
.../private/include/import_registration_dfi.h | 26 +
.../private/include/remote_service_admin_dfi.h | 56 +
.../rsa/private/src/export_registration_dfi.c | 222 ++++
.../rsa/private/src/import_registration_dfi.c | 355 ++++++
.../src/remote_service_admin_activator.c | 124 ++
.../rsa/private/src/remote_service_admin_dfi.c | 737 ++++++++++++
.../rsa_tst/CMakeLists.txt | 45 +
.../rsa_tst/bundle/CMakeLists.txt | 24 +
.../rsa_tst/bundle/tst_activator.c | 137 +++
.../rsa_tst/bundle/tst_service.h | 17 +
.../rsa_tst/client.properties.in | 8 +
.../rsa_tst/config.properties.in | 3 +
.../rsa_tst/rsa_client_server_tests.cpp | 114 ++
.../rsa_tst/rsa_tests.cpp | 201 ++++
.../rsa_tst/run_tests.cpp | 9 +
.../rsa_tst/server.properties.in | 7 +
.../remote_service_admin_http/CMakeLists.txt | 6 +
.../private/src/remote_service_admin_impl.c | 129 +-
.../private/test/CMakeLists.txt | 46 +
.../private/test/client.properties.in | 9 +
.../private/test/rsa_client_server_tests.cpp | 112 ++
.../private/test/run_tests.cpp | 9 +
.../private/test/server.properties.in | 8 +
.../private/src/remote_service_admin_impl.c | 26 +-
.../private/include/topology_manager.h | 2 +
.../topology_manager/private/src/activator.c | 2 +-
.../private/src/topology_manager.c | 151 +--
.../utils/public/include/remote_constants.h | 38 -
shell/private/src/inspect_command.c | 5 +-
utils/CMakeLists.txt | 30 +-
utils/private/test/celix_threads_test.cpp | 7 +-
132 files changed, 9359 insertions(+), 824 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/d040f001/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/d040f001/framework/private/src/service_registry.c
----------------------------------------------------------------------
[14/21] celix git commit: CELIX-269: Added dependency manager
example. Addded phtread_kill support to celix threads.
Posted by pn...@apache.org.
CELIX-269: Added dependency manager example. Addded phtread_kill support to celix threads.
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/0ad3a1fb
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/0ad3a1fb
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/0ad3a1fb
Branch: refs/heads/develop
Commit: 0ad3a1fb05b467e45fe6c486926a9dd6c0beb17f
Parents: 2246174
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Oct 29 16:22:41 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Oct 29 16:22:41 2015 +0100
----------------------------------------------------------------------
examples/CMakeLists.txt | 1 +
examples/dm_example/CMakeLists.txt | 29 +++++
examples/dm_example/deploy.cmake | 29 +++++
examples/dm_example/phase1/CMakeLists.txt | 38 ++++++
.../phase1/private/include/phase1_cmp.h | 42 +++++++
.../phase1/private/src/phase1_activator.c | 85 +++++++++++++
.../dm_example/phase1/private/src/phase1_cmp.c | 94 +++++++++++++++
examples/dm_example/phase2a/CMakeLists.txt | 37 ++++++
.../phase2a/private/include/phase2a_cmp.h | 45 +++++++
.../phase2a/private/src/phase2a_activator.c | 94 +++++++++++++++
.../phase2a/private/src/phase2a_cmp.c | 111 +++++++++++++++++
examples/dm_example/phase2b/CMakeLists.txt | 37 ++++++
.../phase2b/private/include/phase2b_cmp.h | 45 +++++++
.../phase2b/private/src/phase2b_activator.c | 94 +++++++++++++++
.../phase2b/private/src/phase2b_cmp.c | 111 +++++++++++++++++
examples/dm_example/phase3/CMakeLists.txt | 37 ++++++
.../phase3/private/include/phase3_cmp.h | 44 +++++++
.../phase3/private/src/phase3_activator.c | 86 +++++++++++++
.../dm_example/phase3/private/src/phase3_cmp.c | 120 +++++++++++++++++++
examples/dm_example/services/phase1.h | 39 ++++++
examples/dm_example/services/phase2.h | 40 +++++++
utils/private/src/celix_threads.c | 5 +
utils/public/include/celix_threads.h | 1 +
23 files changed, 1264 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 25eac59..fc79400 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -26,6 +26,7 @@ if (EXAMPLES)
add_subdirectory(whiteboard)
add_subdirectory(echo_service)
add_subdirectory(producer_consumer)
+ add_subdirectory(dm_example)
add_subdirectory(osgi-in-action/chapter04-correct-lookup)
add_subdirectory(osgi-in-action/chapter04-correct-listener)
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/CMakeLists.txt b/examples/dm_example/CMakeLists.txt
new file mode 100644
index 0000000..a08e7b4
--- /dev/null
+++ b/examples/dm_example/CMakeLists.txt
@@ -0,0 +1,29 @@
+# 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.
+if (BUILD_DEPENDENCY_MANAGER)
+ include_directories(
+ ${PROJECT_SOURCE_DIR}/dependency_manager/public/include
+ ${PROJECT_SOURCE_DIR}/utils/public/include
+ services
+ )
+
+ add_subdirectory(phase1)
+ add_subdirectory(phase2a)
+ add_subdirectory(phase2b)
+ add_subdirectory(phase3)
+
+endif ()
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/deploy.cmake
----------------------------------------------------------------------
diff --git a/examples/dm_example/deploy.cmake b/examples/dm_example/deploy.cmake
new file mode 100644
index 0000000..9cf2c10
--- /dev/null
+++ b/examples/dm_example/deploy.cmake
@@ -0,0 +1,29 @@
+# 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.
+if (BUILD_DEPENDENCY_MANAGER AND BUILD_SHELL AND BUILD_SHELL_TUI)
+ deploy("dm_example"
+ BUNDLES
+ phase1
+ phase2a
+ phase2b
+ phase3
+ shell
+ shell_tui
+ dm_shell
+ )
+endif()
+
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase1/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/CMakeLists.txt b/examples/dm_example/phase1/CMakeLists.txt
new file mode 100644
index 0000000..6fc8c77
--- /dev/null
+++ b/examples/dm_example/phase1/CMakeLists.txt
@@ -0,0 +1,38 @@
+# 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.
+
+SET(BUNDLE_SYMBOLICNAME "phase1")
+SET(BUNDLE_VERSION "0.0.1")
+
+bundle(phase1
+ SOURCES
+ private/src/phase1_activator
+ private/src/phase1_cmp.c
+)
+
+include_directories(
+ private/include
+ ../services
+)
+
+# Use some magic to include all symbols of the static library
+IF(APPLE)
+target_link_libraries(phase1 celix_framework -Wl,-all_load dependency_manager)
+else()
+target_link_libraries(phase1 -Wl,--whole-archive dependency_manager -Wl,--no-whole-archive celix_framework)
+ENDIF()
+
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase1/private/include/phase1_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/private/include/phase1_cmp.h b/examples/dm_example/phase1/private/include/phase1_cmp.h
new file mode 100644
index 0000000..55e3f15
--- /dev/null
+++ b/examples/dm_example/phase1/private/include/phase1_cmp.h
@@ -0,0 +1,42 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE1_CMP_H
+#define PHASE1_CMP_H
+
+
+typedef struct phase1_cmp_struct phase1_cmp_t;
+
+phase1_cmp_t *phase1_create(void);
+int phase1_init(phase1_cmp_t *cmp);
+int phase1_start(phase1_cmp_t *cmp);
+int phase1_stop(phase1_cmp_t *cmp);
+void phase1_destroy(phase1_cmp_t *cmp);
+
+int phase1_getData(phase1_cmp_t *cmp, unsigned int *data);
+
+
+#endif //PHASE1_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase1/private/src/phase1_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/private/src/phase1_activator.c b/examples/dm_example/phase1/private/src/phase1_activator.c
new file mode 100644
index 0000000..60ab21d
--- /dev/null
+++ b/examples/dm_example/phase1/private/src/phase1_activator.c
@@ -0,0 +1,85 @@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <phase1_cmp.h>
+
+#include "bundle_activator.h"
+#include "dm_activator_base.h"
+
+#include "phase1.h"
+
+struct phase1_activator_struct {
+ phase1_cmp_t *phase1Cmp;
+ phase1_t phase1Serv;
+};
+
+celix_status_t dm_create(bundle_context_pt context, void **userData) {
+ printf("PHASE1: dm_create\n");
+ *userData = calloc(1, sizeof(struct phase1_activator_struct));
+ return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
+}
+
+celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("PHASE1: dm_init\n");
+ celix_status_t status = CELIX_SUCCESS;
+
+
+ struct phase1_activator_struct *act = (struct phase1_activator_struct *)userData;
+
+ act->phase1Cmp = phase1_create();
+ if (act->phase1Cmp != NULL) {
+
+ act->phase1Serv.handle = act->phase1Cmp;
+ act->phase1Serv.getData = phase1_getData;
+
+ properties_pt props = properties_create();
+ properties_set(props, "id", "phase1");
+
+ dm_component_pt cmp;
+ component_create(context, "PHASE1_PROCESSING_COMPONENT", &cmp);
+ component_setImplementation(cmp, act->phase1Cmp);
+ component_setCallbacks(cmp, phase1_init, phase1_start, phase1_stop, phase1_destroy);
+ component_addInterface(cmp, PHASE1_NAME, &act->phase1Serv, props);
+
+ dependencyManager_add(manager, cmp);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
+celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("PHASE1: dm-destroy\n");
+
+ struct phase1_activator_struct *act = (struct phase1_activator_struct *)userData;
+ if (act->phase1Cmp != NULL) {
+ phase1_destroy(act->phase1Cmp);
+ }
+ free(act);
+
+ return CELIX_SUCCESS;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase1/private/src/phase1_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/private/src/phase1_cmp.c b/examples/dm_example/phase1/private/src/phase1_cmp.c
new file mode 100644
index 0000000..ba9d46e
--- /dev/null
+++ b/examples/dm_example/phase1/private/src/phase1_cmp.c
@@ -0,0 +1,94 @@
+/**
+ *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.
+ */
+/*
+ * publisher.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+
+#include "celix_threads.h"
+#include "phase1_cmp.h"
+
+#define SLEEPTIME 1000
+
+struct phase1_cmp_struct {
+ celix_thread_t thread;
+ bool running;
+ unsigned int counter;
+};
+
+static void *phase1_thread(void *data);
+
+phase1_cmp_t *phase1_create(void) {
+ phase1_cmp_t *cmp = calloc(1, sizeof(*cmp));
+ if (cmp != NULL) {
+ cmp->counter = 0;
+ cmp->running = false;
+ }
+ return cmp;
+}
+
+int phase1_init(phase1_cmp_t *cmp) {
+ printf("init phase1\n");
+ return 0;
+}
+
+int phase1_start(phase1_cmp_t *cmp) {
+ printf("start phase1\n");
+ cmp->running = true;
+ celixThread_create(&cmp->thread, NULL, phase1_thread, cmp);
+ return 0;
+}
+
+int phase1_stop(phase1_cmp_t *cmp) {
+ printf("stop phase1\n");
+ cmp->running = false;
+ celixThread_kill(cmp->thread, SIGUSR1);
+ celixThread_join(cmp->thread, NULL);
+ return 0;
+}
+
+void phase1_destroy(phase1_cmp_t *cmp) {
+ free(cmp);
+ printf("destroy phase1\n");
+}
+
+static void *phase1_thread(void *data) {
+ phase1_cmp_t *cmp = data;
+
+ while (cmp->running) {
+ cmp->counter += 1;
+ usleep(SLEEPTIME);
+ }
+
+ celixThread_exit(NULL);
+ return NULL;
+}
+
+int phase1_getData(phase1_cmp_t *cmp, unsigned int *data) {
+ *data = cmp->counter;
+ return 0;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase2a/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/CMakeLists.txt b/examples/dm_example/phase2a/CMakeLists.txt
new file mode 100644
index 0000000..afe53cc
--- /dev/null
+++ b/examples/dm_example/phase2a/CMakeLists.txt
@@ -0,0 +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.
+
+SET(BUNDLE_SYMBOLICNAME "phase2a")
+SET(BUNDLE_VERSION "0.0.1")
+
+bundle(phase2a SOURCES
+ private/src/phase2a_activator
+ private/src/phase2a_cmp
+)
+
+include_directories(
+ private/include
+ ../services
+)
+
+#target_link_libraries(fase2_a -Wl,--whole-archive dependency_manager2 -Wl,--no-whole-archive celix_framework)
+#target_link_libraries(fase2_a celix_framework)
+IF(APPLE)
+target_link_libraries(phase2a celix_framework -Wl,-all_load dependency_manager)
+else()
+target_link_libraries(phase2a -Wl,--whole-archive dependency_manager -Wl,--no-whole-archive celix_framework)
+ENDIF()
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase2a/private/include/phase2a_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/private/include/phase2a_cmp.h b/examples/dm_example/phase2a/private/include/phase2a_cmp.h
new file mode 100644
index 0000000..ecfc0f0
--- /dev/null
+++ b/examples/dm_example/phase2a/private/include/phase2a_cmp.h
@@ -0,0 +1,45 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE2A_CMP_H
+#define PHASE2A_CMP_H
+
+#include "phase1.h"
+
+typedef struct phase2a_cmp_struct phase2a_cmp_t;
+
+phase2a_cmp_t *phase2a_create(void);
+int phase2a_init(phase2a_cmp_t *cmp);
+int phase2a_start(phase2a_cmp_t *cmp);
+int phase2a_stop(phase2a_cmp_t *cmp);
+void phase2a_destroy(phase2a_cmp_t *cmp);
+
+int phase2a_setPhase1(phase2a_cmp_t *cmp, phase1_t *phase1);
+
+int phase2a_getData(phase2a_cmp_t *cmp, double *data);
+
+
+#endif //PHASE2A_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase2a/private/src/phase2a_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/private/src/phase2a_activator.c b/examples/dm_example/phase2a/private/src/phase2a_activator.c
new file mode 100644
index 0000000..96f32ab
--- /dev/null
+++ b/examples/dm_example/phase2a/private/src/phase2a_activator.c
@@ -0,0 +1,94 @@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <phase2a_cmp.h>
+
+#include "bundle_activator.h"
+#include "dm_activator_base.h"
+
+#include "phase1.h"
+#include "phase2.h"
+#include "phase2a_cmp.h"
+
+struct phase2a_activator_struct {
+ phase2a_cmp_t *phase2aCmp;
+ phase2_t phase2Serv;
+};
+
+celix_status_t dm_create(bundle_context_pt context, void **userData) {
+ printf("phase2a: dm_create\n");
+ *userData = calloc(1, sizeof(struct phase2a_activator_struct));
+ return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
+}
+
+celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase2a: dm_init\n");
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct phase2a_activator_struct *act = (struct phase2a_activator_struct *)userData;
+
+ act->phase2aCmp = phase2a_create();
+ if (act->phase2aCmp != NULL) {
+
+ act->phase2Serv.handle = act->phase2aCmp;
+ act->phase2Serv.getData = (void *)phase2a_getData;
+
+ properties_pt props = properties_create();
+ properties_set(props, "id", "phase2a");
+
+ dm_component_pt cmp;
+ component_create(context, "PHASE2A_PROCESSING_COMPONENT", &cmp);
+ component_setImplementation(cmp, act->phase2aCmp);
+ component_setCallbacks(cmp, (void *)phase2a_init, (void *)phase2a_start, (void *)phase2a_stop, (void *)phase2a_destroy);
+ component_addInterface(cmp, PHASE2_NAME, &act->phase2Serv, props);
+
+
+ dm_service_dependency_pt dep;
+ serviceDependency_create(&dep);
+ serviceDependency_setService(dep, PHASE1_NAME, NULL);
+ serviceDependency_setCallbacks(dep, phase2a_setPhase1, NULL, NULL, NULL, NULL);
+ serviceDependency_setRequired(dep, true);
+ component_addServiceDependency(cmp, dep);
+
+ dependencyManager_add(manager, cmp);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
+celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase2a: dm-destroy\n");
+
+ struct phase2a_activator_struct *act = (struct phase2a_activator_struct *)userData;
+ if (act->phase2aCmp != NULL) {
+ phase2a_destroy(act->phase2aCmp);
+ }
+ free(act);
+
+ return CELIX_SUCCESS;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase2a/private/src/phase2a_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/private/src/phase2a_cmp.c b/examples/dm_example/phase2a/private/src/phase2a_cmp.c
new file mode 100644
index 0000000..2afa0d2
--- /dev/null
+++ b/examples/dm_example/phase2a/private/src/phase2a_cmp.c
@@ -0,0 +1,111 @@
+/**
+ *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.
+ */
+/*
+ * publisher.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include "celix_threads.h"
+#include "phase2a_cmp.h"
+
+#define SLEEPTIME 2000000
+
+struct phase2a_cmp_struct {
+ celix_thread_t thread;
+ bool running;
+ double currentValue;
+ celix_thread_mutex_t mutex;
+ phase1_t *phase1Serv;
+};
+
+static void *phase2a_thread(void *data);
+
+phase2a_cmp_t *phase2a_create(void) {
+ phase2a_cmp_t *cmp = calloc(1, sizeof(*cmp));
+ if (cmp != NULL) {
+ cmp->currentValue = 0.0;
+ cmp->running = false;
+ celixThreadMutex_create(&cmp->mutex, NULL);
+ }
+ return cmp;
+}
+
+int phase2a_init(phase2a_cmp_t *cmp) {
+ printf("init phase2a\n");
+ return 0;
+}
+
+int phase2a_start(phase2a_cmp_t *cmp) {
+ printf("start phase2a\n");
+ cmp->running = true;
+ celixThread_create(&cmp->thread, NULL, phase2a_thread, cmp);
+ return 0;
+}
+
+int phase2a_stop(phase2a_cmp_t *cmp) {
+ printf("stop phase2a\n");
+ cmp->running = false;
+ celixThread_kill(cmp->thread, SIGUSR1);
+ celixThread_join(cmp->thread, NULL);
+ return 0;
+}
+
+void phase2a_destroy(phase2a_cmp_t *cmp) {
+ celixThreadMutex_lock(&cmp->mutex);
+ celixThreadMutex_destroy(&cmp->mutex);
+ free(cmp);
+ printf("destroy phase2a\n");
+}
+
+int phase2a_setPhase1(phase2a_cmp_t *cmp, phase1_t *phase1) {
+ celixThreadMutex_lock(&cmp->mutex);
+ cmp->phase1Serv = phase1;
+ celixThreadMutex_unlock(&cmp->mutex);
+ return 0;
+}
+
+static void *phase2a_thread(void *data) {
+ phase2a_cmp_t *cmp = data;
+ unsigned int counter;
+
+ while (cmp->running) {
+ celixThreadMutex_lock(&cmp->mutex);
+ if (cmp->phase1Serv != NULL) {
+ cmp->phase1Serv->getData(cmp->phase1Serv->handle, &counter);
+ cmp->currentValue = 1.0 / counter;
+ }
+ celixThreadMutex_unlock(&cmp->mutex);
+ usleep(SLEEPTIME);
+ }
+
+ celixThread_exit(NULL);
+ return NULL;
+}
+
+int phase2a_getData(phase2a_cmp_t *cmp, double *data) {
+ *data = cmp->currentValue;
+ return 0;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase2b/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/CMakeLists.txt b/examples/dm_example/phase2b/CMakeLists.txt
new file mode 100644
index 0000000..820f6c9
--- /dev/null
+++ b/examples/dm_example/phase2b/CMakeLists.txt
@@ -0,0 +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.
+
+SET(BUNDLE_SYMBOLICNAME "phase2b")
+SET(BUNDLE_VERSION "0.0.1")
+
+bundle(phase2b SOURCES
+ private/src/phase2b_activator
+ private/src/phase2b_cmp
+)
+
+include_directories(
+ private/include
+ ../services
+)
+
+#target_link_libraries(fase2_a -Wl,--whole-archive dependency_manager2 -Wl,--no-whole-archive celix_framework)
+#target_link_libraries(fase2_a celix_framework)
+IF(APPLE)
+target_link_libraries(phase2b celix_framework -Wl,-all_load dependency_manager)
+else()
+target_link_libraries(phase2b -Wl,--whole-archive dependency_manager -Wl,--no-whole-archive celix_framework)
+ENDIF()
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase2b/private/include/phase2b_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/private/include/phase2b_cmp.h b/examples/dm_example/phase2b/private/include/phase2b_cmp.h
new file mode 100644
index 0000000..fedcd69
--- /dev/null
+++ b/examples/dm_example/phase2b/private/include/phase2b_cmp.h
@@ -0,0 +1,45 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE2B_CMP_H
+#define PHASE2B_CMP_H
+
+#include "phase1.h"
+
+typedef struct phase2b_cmp_struct phase2b_cmp_t;
+
+phase2b_cmp_t *phase2b_create(void);
+int phase2b_init(phase2b_cmp_t *cmp);
+int phase2b_start(phase2b_cmp_t *cmp);
+int phase2b_stop(phase2b_cmp_t *cmp);
+void phase2b_destroy(phase2b_cmp_t *cmp);
+
+int phase2b_setPhase1(phase2b_cmp_t *cmp, phase1_t *phase1);
+
+int phase2b_getData(phase2b_cmp_t *cmp, double *data);
+
+
+#endif //PHASE2B_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase2b/private/src/phase2b_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/private/src/phase2b_activator.c b/examples/dm_example/phase2b/private/src/phase2b_activator.c
new file mode 100644
index 0000000..82bfef1
--- /dev/null
+++ b/examples/dm_example/phase2b/private/src/phase2b_activator.c
@@ -0,0 +1,94 @@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <phase2b_cmp.h>
+
+#include "bundle_activator.h"
+#include "dm_activator_base.h"
+
+#include "phase1.h"
+#include "phase2.h"
+#include "phase2b_cmp.h"
+
+struct phase2b_activator_struct {
+ phase2b_cmp_t *phase2bCmp;
+ phase2_t phase2Serv;
+};
+
+celix_status_t dm_create(bundle_context_pt context, void **userData) {
+ printf("phase2b: dm_create\n");
+ *userData = calloc(1, sizeof(struct phase2b_activator_struct));
+ return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
+}
+
+celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase2b: dm_init\n");
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct phase2b_activator_struct *act = (struct phase2b_activator_struct *)userData;
+
+ act->phase2bCmp = phase2b_create();
+ if (act->phase2bCmp != NULL) {
+
+ act->phase2Serv.handle = act->phase2bCmp;
+ act->phase2Serv.getData = (void *)phase2b_getData;
+
+ properties_pt props = properties_create();
+ properties_set(props, "id", "phase2b");
+
+ dm_component_pt cmp;
+ component_create(context, "PHASE2B_PROCESSING_COMPONENT", &cmp);
+ component_setImplementation(cmp, act->phase2bCmp);
+ component_setCallbacks(cmp, (void *)phase2b_init, (void *)phase2b_start, (void *)phase2b_stop, (void *)phase2b_destroy);
+ component_addInterface(cmp, PHASE2_NAME, &act->phase2Serv, props);
+
+
+ dm_service_dependency_pt dep;
+ serviceDependency_create(&dep);
+ serviceDependency_setService(dep, PHASE1_NAME, NULL);
+ serviceDependency_setCallbacks(dep, phase2b_setPhase1, NULL, NULL, NULL, NULL);
+ serviceDependency_setRequired(dep, true);
+ component_addServiceDependency(cmp, dep);
+
+ dependencyManager_add(manager, cmp);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
+celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase2b: dm-destroy\n");
+
+ struct phase2b_activator_struct *act = (struct phase2b_activator_struct *)userData;
+ if (act->phase2bCmp != NULL) {
+ phase2b_destroy(act->phase2bCmp);
+ }
+ free(act);
+
+ return CELIX_SUCCESS;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase2b/private/src/phase2b_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/private/src/phase2b_cmp.c b/examples/dm_example/phase2b/private/src/phase2b_cmp.c
new file mode 100644
index 0000000..e1487b4
--- /dev/null
+++ b/examples/dm_example/phase2b/private/src/phase2b_cmp.c
@@ -0,0 +1,111 @@
+/**
+ *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.
+ */
+/*
+ * publisher.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include "celix_threads.h"
+#include "phase2b_cmp.h"
+
+#define SLEEPTIME 2000000
+
+struct phase2b_cmp_struct {
+ celix_thread_t thread;
+ bool running;
+ double currentValue;
+ celix_thread_mutex_t mutex;
+ phase1_t *phase1Serv;
+};
+
+static void *phase2b_thread(void *data);
+
+phase2b_cmp_t *phase2b_create(void) {
+ phase2b_cmp_t *cmp = calloc(1, sizeof(*cmp));
+ if (cmp != NULL) {
+ cmp->currentValue = 0.0;
+ cmp->running = false;
+ celixThreadMutex_create(&cmp->mutex, NULL);
+ }
+ return cmp;
+}
+
+int phase2b_init(phase2b_cmp_t *cmp) {
+ printf("init phase2b\n");
+ return 0;
+}
+
+int phase2b_start(phase2b_cmp_t *cmp) {
+ printf("start phase2b\n");
+ cmp->running = true;
+ celixThread_create(&cmp->thread, NULL, phase2b_thread, cmp);
+ return 0;
+}
+
+int phase2b_stop(phase2b_cmp_t *cmp) {
+ printf("stop phase2b\n");
+ cmp->running = false;
+ celixThread_kill(cmp->thread, SIGUSR1);
+ celixThread_join(cmp->thread, NULL);
+ return 0;
+}
+
+void phase2b_destroy(phase2b_cmp_t *cmp) {
+ celixThreadMutex_lock(&cmp->mutex);
+ celixThreadMutex_destroy(&cmp->mutex);
+ free(cmp);
+ printf("destroy phase2b\n");
+}
+
+int phase2b_setPhase1(phase2b_cmp_t *cmp, phase1_t *phase1) {
+ celixThreadMutex_lock(&cmp->mutex);
+ cmp->phase1Serv = phase1;
+ celixThreadMutex_unlock(&cmp->mutex);
+ return 0;
+}
+
+static void *phase2b_thread(void *data) {
+ phase2b_cmp_t *cmp = data;
+ unsigned int counter;
+
+ while (cmp->running) {
+ celixThreadMutex_lock(&cmp->mutex);
+ if (cmp->phase1Serv != NULL) {
+ cmp->phase1Serv->getData(cmp->phase1Serv->handle, &counter);
+ cmp->currentValue = counter / 1000;
+ }
+ celixThreadMutex_unlock(&cmp->mutex);
+ usleep(SLEEPTIME);
+ }
+
+ celixThread_exit(NULL);
+ return NULL;
+}
+
+int phase2b_getData(phase2b_cmp_t *cmp, double *data) {
+ *data = cmp->currentValue;
+ return 0;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase3/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/CMakeLists.txt b/examples/dm_example/phase3/CMakeLists.txt
new file mode 100644
index 0000000..22c3d95
--- /dev/null
+++ b/examples/dm_example/phase3/CMakeLists.txt
@@ -0,0 +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.
+
+SET(BUNDLE_SYMBOLICNAME "phase3")
+SET(BUNDLE_VERSION "0.0.1")
+
+bundle(phase3 SOURCES
+ private/src/phase3_activator
+ private/src/phase3_cmp
+)
+
+include_directories(
+ private/include
+ ../services
+)
+
+#target_link_libraries(fase2_a -Wl,--whole-archive dependency_manager2 -Wl,--no-whole-archive celix_framework)
+#target_link_libraries(fase2_a celix_framework)
+IF(APPLE)
+target_link_libraries(phase3 celix_framework -Wl,-all_load dependency_manager)
+else()
+target_link_libraries(phase3 -Wl,--whole-archive dependency_manager -Wl,--no-whole-archive celix_framework)
+ENDIF()
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase3/private/include/phase3_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/include/phase3_cmp.h b/examples/dm_example/phase3/private/include/phase3_cmp.h
new file mode 100644
index 0000000..1b32f04
--- /dev/null
+++ b/examples/dm_example/phase3/private/include/phase3_cmp.h
@@ -0,0 +1,44 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE3_CMP_H
+#define PHASE3_CMP_H
+
+#include "phase2.h"
+
+typedef struct phase3_cmp_struct phase3_cmp_t;
+
+phase3_cmp_t *phase3_create(void);
+int phase3_init(phase3_cmp_t *cmp);
+int phase3_start(phase3_cmp_t *cmp);
+int phase3_stop(phase3_cmp_t *cmp);
+void phase3_destroy(phase3_cmp_t *cmp);
+
+int phase3_addPhase2(phase3_cmp_t *cmp, phase2_t *phase2);
+int phase3_removePhase2(phase3_cmp_t *cmp, phase2_t *phase2);
+
+
+#endif //PHASE3_CMP_H
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase3/private/src/phase3_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/src/phase3_activator.c b/examples/dm_example/phase3/private/src/phase3_activator.c
new file mode 100644
index 0000000..2d8f3df
--- /dev/null
+++ b/examples/dm_example/phase3/private/src/phase3_activator.c
@@ -0,0 +1,86 @@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+
+#include "bundle_activator.h"
+#include "dm_activator_base.h"
+
+#include "phase2.h"
+#include "phase3_cmp.h"
+
+struct phase3_activator_struct {
+ phase3_cmp_t *phase3Cmp;
+};
+
+celix_status_t dm_create(bundle_context_pt context, void **userData) {
+ printf("phase3: dm_create\n");
+ *userData = calloc(1, sizeof(struct phase3_activator_struct));
+ return *userData != NULL ? CELIX_SUCCESS : CELIX_ENOMEM;
+}
+
+celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase3: dm_init\n");
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct phase3_activator_struct *act = (struct phase3_activator_struct *)userData;
+
+ act->phase3Cmp = phase3_create();
+ if (act->phase3Cmp != NULL) {
+
+ properties_pt props = properties_create();
+ properties_set(props, "id", "phase3");
+
+ dm_component_pt cmp;
+ component_create(context, "PHASE3_PROCESSING_COMPONENT", &cmp);
+ component_setImplementation(cmp, act->phase3Cmp);
+ component_setCallbacks(cmp, (void *)phase3_init, (void *)phase3_start, (void *)phase3_stop, (void *)phase3_destroy);
+
+ dm_service_dependency_pt dep;
+ serviceDependency_create(&dep);
+ serviceDependency_setService(dep, PHASE2_NAME, NULL);
+ serviceDependency_setCallbacks(dep, NULL, (void *)phase3_addPhase2, NULL, (void *)phase3_removePhase2, NULL);
+ serviceDependency_setRequired(dep, true);
+ component_addServiceDependency(cmp, dep);
+
+ dependencyManager_add(manager, cmp);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ return status;
+}
+
+celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
+ printf("phase3: dm-destroy\n");
+
+ struct phase3_activator_struct *act = (struct phase3_activator_struct *)userData;
+ if (act->phase3Cmp != NULL) {
+ phase3_destroy(act->phase3Cmp);
+ }
+ free(act);
+
+ return CELIX_SUCCESS;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/phase3/private/src/phase3_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/src/phase3_cmp.c b/examples/dm_example/phase3/private/src/phase3_cmp.c
new file mode 100644
index 0000000..5cd9f53
--- /dev/null
+++ b/examples/dm_example/phase3/private/src/phase3_cmp.c
@@ -0,0 +1,120 @@
+/**
+ *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.
+ */
+/*
+ * publisher.c
+ *
+ * \date Oct 29, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include "array_list.h"
+#include "celix_threads.h"
+#include "phase3_cmp.h"
+
+#define SLEEPTIME 2000000
+
+struct phase3_cmp_struct {
+ celix_thread_t thread;
+ bool running;
+ double currentValue;
+ celix_thread_mutex_t mutex;
+ array_list_pt phase2Services; //phase2_t *
+};
+
+static void *phase3_thread(void *data);
+
+phase3_cmp_t *phase3_create(void) {
+ phase3_cmp_t *cmp = calloc(1, sizeof(*cmp));
+ if (cmp != NULL) {
+ cmp->currentValue = 0.0;
+ cmp->running = false;
+ celixThreadMutex_create(&cmp->mutex, NULL);
+ arrayList_create(&cmp->phase2Services);
+ }
+ return cmp;
+}
+
+int phase3_init(phase3_cmp_t *cmp) {
+ printf("init phase3\n");
+ return 0;
+}
+
+int phase3_start(phase3_cmp_t *cmp) {
+ printf("start phase3\n");
+ cmp->running = true;
+ celixThread_create(&cmp->thread, NULL, phase3_thread, cmp);
+ return 0;
+}
+
+int phase3_stop(phase3_cmp_t *cmp) {
+ printf("stop phase3\n");
+ cmp->running = false;
+ celixThread_kill(cmp->thread, SIGUSR1);
+ celixThread_join(cmp->thread, NULL);
+ return 0;
+}
+
+void phase3_destroy(phase3_cmp_t *cmp) {
+ celixThreadMutex_lock(&cmp->mutex);
+ celixThreadMutex_destroy(&cmp->mutex);
+ free(cmp);
+ printf("destroy phase3\n");
+}
+
+int phase3_addPhase2(phase3_cmp_t *cmp, phase2_t *phase2) {
+ celixThreadMutex_lock(&cmp->mutex);
+ arrayList_add(cmp->phase2Services, phase2);
+ celixThreadMutex_unlock(&cmp->mutex);
+ return 0;
+}
+
+int phase3_removePhase2(phase3_cmp_t *cmp, phase2_t *phase2) {
+ celixThreadMutex_lock(&cmp->mutex);
+ arrayList_removeElement(cmp->phase2Services, phase2);
+ celixThreadMutex_unlock(&cmp->mutex);
+ return 0;
+}
+
+
+static void *phase3_thread(void *data) {
+ phase3_cmp_t *cmp = data;
+ int size;
+ int i;
+ double value;
+
+ while (cmp->running) {
+ celixThreadMutex_lock(&cmp->mutex);
+ size = arrayList_size(cmp->phase2Services);
+ for (i = 0; i < size; i += 1) {
+ phase2_t *serv = arrayList_get(cmp->phase2Services, i);
+ serv->getData(serv->handle, &value);
+ printf("PHASE3: Data from %p is %f\n", serv, value);
+ }
+ celixThreadMutex_unlock(&cmp->mutex);
+ usleep(SLEEPTIME);
+ }
+
+ celixThread_exit(NULL);
+ return NULL;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/services/phase1.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/services/phase1.h b/examples/dm_example/services/phase1.h
new file mode 100644
index 0000000..0261d14
--- /dev/null
+++ b/examples/dm_example/services/phase1.h
@@ -0,0 +1,39 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Aug 23, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE1_H_
+#define PHASE1_H_
+
+#define PHASE1_NAME "PHASE1"
+
+struct phase1_struct {
+ void *handle;
+ int (*getData)(void *handle, unsigned int *data);
+};
+
+typedef struct phase1_struct phase1_t;
+
+#endif /* PHASE1_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/examples/dm_example/services/phase2.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/services/phase2.h b/examples/dm_example/services/phase2.h
new file mode 100644
index 0000000..9318bc0
--- /dev/null
+++ b/examples/dm_example/services/phase2.h
@@ -0,0 +1,40 @@
+/**
+ *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.
+ */
+/*
+ * publisher.h
+ *
+ * \date Aug 23, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef PHASE2_H
+#define PHASE2_H
+
+#define PHASE2_NAME "PHASE2"
+
+struct phase2_struct {
+ void *handle;
+ void (*getData)(void *handle, double *data);
+};
+
+typedef struct phase2_struct phase2_t;
+
+
+#endif /* PHASE2_H */
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/utils/private/src/celix_threads.c
----------------------------------------------------------------------
diff --git a/utils/private/src/celix_threads.c b/utils/private/src/celix_threads.c
index 1efdf01..d460dd7 100644
--- a/utils/private/src/celix_threads.c
+++ b/utils/private/src/celix_threads.c
@@ -24,6 +24,7 @@
* \copyright Apache License, Version 2.0
*/
#include <stdlib.h>
+#include "signal.h"
#include "celix_threads.h"
@@ -62,6 +63,10 @@ celix_status_t celixThread_join(celix_thread_t thread, void **retVal) {
return status;
}
+celix_status_t celixThread_kill(celix_thread_t thread, int sig) {
+ return pthread_kill(thread.thread, sig);
+}
+
celix_thread_t celixThread_self() {
celix_thread_t thread;
http://git-wip-us.apache.org/repos/asf/celix/blob/0ad3a1fb/utils/public/include/celix_threads.h
----------------------------------------------------------------------
diff --git a/utils/public/include/celix_threads.h b/utils/public/include/celix_threads.h
index 253ebf8..2eed5df 100644
--- a/utils/public/include/celix_threads.h
+++ b/utils/public/include/celix_threads.h
@@ -51,6 +51,7 @@ celix_status_t celixThread_create(celix_thread_t *new_thread, celix_thread_attr_
void celixThread_exit(void *exitStatus);
celix_status_t celixThread_detach(celix_thread_t thread);
celix_status_t celixThread_join(celix_thread_t thread, void **status);
+celix_status_t celixThread_kill(celix_thread_t thread, int sig);
celix_thread_t celixThread_self();
int celixThread_equals(celix_thread_t thread1, celix_thread_t thread2);
bool celixThread_initalized(celix_thread_t thread);
[21/21] celix git commit: CELIX-269: Updated for shell refactoring
Posted by pn...@apache.org.
CELIX-269: Updated for shell refactoring
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/04b68623
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/04b68623
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/04b68623
Branch: refs/heads/develop
Commit: 04b686237ca75157a2f3039256cbe7c60d540478
Parents: 9af85ce
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Nov 3 10:37:51 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Nov 3 10:37:51 2015 +0100
----------------------------------------------------------------------
.../private/include/dm_shell_list_command.h | 7 ++--
.../private/src/dm_shell_activator.c | 31 ++++++++++++-----
.../private/src/dm_shell_list_command.c | 35 ++++----------------
examples/dm_example/deploy.cmake | 17 ++++++----
shell/CMakeLists.txt | 3 ++
shell/private/include/shell_private.h | 2 ++
shell/private/src/shell.c | 9 +++--
7 files changed, 54 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/dependency_manager/private/include/dm_shell_list_command.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_shell_list_command.h b/dependency_manager/private/include/dm_shell_list_command.h
index bbccdc1..01c5065 100644
--- a/dependency_manager/private/include/dm_shell_list_command.h
+++ b/dependency_manager/private/include/dm_shell_list_command.h
@@ -26,9 +26,6 @@
#include <stdlib.h>
#include <string.h>
-#include "command_impl.h"
+#include "command.h"
-char * dmListCommand_getName(command_pt command);
-char * dmListCommand_getUsage(command_pt command);
-char * dmListCommand_getShortDescription(command_pt command);
-void dmListCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *));
\ No newline at end of file
+void dmListCommand_execute(bundle_context_pt context, char * line, FILE *out, FILE *err);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/dependency_manager/private/src/dm_shell_activator.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_activator.c b/dependency_manager/private/src/dm_shell_activator.c
index 4adfd0a..178b460 100644
--- a/dependency_manager/private/src/dm_shell_activator.c
+++ b/dependency_manager/private/src/dm_shell_activator.c
@@ -32,7 +32,7 @@
struct bundle_instance {
service_registration_pt reg;
- command_pt dmListCmd;
+ command_service_pt dmCommand;
};
typedef struct bundle_instance * bundle_instance_pt;
@@ -66,13 +66,24 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
bundle_instance_pt bi = (bundle_instance_pt) userData;
command_service_pt commandService = calloc(1, sizeof(*commandService));
- commandService->getName = dmListCommand_getName;
- commandService->command = context;
- commandService->executeCommand = dmListCommand_execute;
- commandService->getShortDescription = dmListCommand_getShortDescription;
- commandService->getUsage = dmListCommand_getUsage;
+ if (commandService != NULL) {
+ commandService->handle = context;
+ commandService->executeCommand = dmListCommand_execute;
- bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, commandService, NULL, &bi->reg);
+ properties_pt props = properties_create();
+ properties_set(props, OSGI_SHELL_COMMAND_NAME, "dm");
+ properties_set(props, OSGI_SHELL_COMMAND_USAGE, "dm");
+ properties_set(props, OSGI_SHELL_COMMAND_DESCRIPTION,
+ "Gives an overview of the component managemend by a dependency manager.");
+
+ bi->dmCommand = commandService;
+
+ status = bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, commandService, props,
+ &bi->reg);
+ } else {
+ status = CELIX_ENOMEM;
+ free(commandService);
+ }
return status;
}
@@ -84,7 +95,11 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context)
}
celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- free(userData);
+ bundle_instance_pt bi = (bundle_instance_pt) userData;
+ if (bi != NULL) {
+ free(bi->dmCommand);
+ }
+ free(bi);
return CELIX_SUCCESS;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
index 1855664..fd7c5d9 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -28,7 +28,6 @@
#include <dm_dependency_manager.h>
#include "dm_info.h"
#include "service_reference.h"
-#include "command_impl.h"
#include "array_list.h"
#include "bundle_context.h"
#include "bundle.h"
@@ -40,23 +39,9 @@ static const char * const WARNING_COLOR = "\033[93m";
static const char * const NOK_COLOR = "\033[91m";
static const char * const END_COLOR = "\033[m";
-char * dmListCommand_getName(command_pt command) {
- return "dm";
-}
-
-char * dmListCommand_getUsage(command_pt command) {
- return "dm [overview|notavail]";
-}
-
-char * dmListCommand_getShortDescription(command_pt command) {
- return "\t overview: Get an overview of the dependency-managed components with their dependencies.\n\tnotavail: Get an overview of dependency-managed compononentes where required depencies are not available. ";
-}
-
-void dmListCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *)) {
- char outString[256];
+void dmListCommand_execute(bundle_context_pt context, char * line, FILE *out, FILE *err) {
array_list_pt servRefs = NULL;
int i;
- bundle_context_pt context = (void *)command;
bundleContext_getServiceReferences(context, DM_INFO_SERVICE_NAME ,NULL, &servRefs);
char *term = getenv("TERM");
bool colors = false;
@@ -81,22 +66,18 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
startColors = compInfo->active ? OK_COLOR : NOK_COLOR;
endColors = END_COLOR;
}
- sprintf(outString, "Component: Name=%s\n|- ID=%s, %sActive=%s%s, State=%s\n", compInfo->name, compInfo->id, startColors, compInfo->active ? "true " : "false", endColors, compInfo->state);
- out(outString);
+ fprintf(out, "Component: Name=%s\n|- ID=%s, %sActive=%s%s, State=%s\n", compInfo->name, compInfo->id, startColors, compInfo->active ? "true " : "false", endColors, compInfo->state);
int interfCnt;
- sprintf(outString, "|- Interfaces (%d):\n", arrayList_size(compInfo->interfaces));
- out(outString);
+ fprintf(out, "|- Interfaces (%d):\n", arrayList_size(compInfo->interfaces));
for(interfCnt = 0 ;interfCnt < arrayList_size(compInfo->interfaces); interfCnt++) {
char * interface;
interface = arrayList_get(compInfo->interfaces, interfCnt);
- sprintf(outString, " |- Interface: %s\n", interface);
- out(outString);
+ fprintf(out, " |- Interface: %s\n", interface);
}
int depCnt;
- sprintf(outString, "|- Dependencies (%d):\n", arrayList_size(compInfo->dependency_list));
- out(outString);
+ fprintf(out, "|- Dependencies (%d):\n", arrayList_size(compInfo->dependency_list));
for(depCnt = 0 ;depCnt < arrayList_size(compInfo->dependency_list); depCnt++) {
dm_service_dependency_info_pt dependency;
dependency = arrayList_get(compInfo->dependency_list, depCnt);
@@ -111,17 +92,15 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
endColors = END_COLOR;
}
- sprintf(outString, " |- Dependency: %sAvailable = %s%s, Required = %s, Filter = %s\n",
+ fprintf(out, " |- Dependency: %sAvailable = %s%s, Required = %s, Filter = %s\n",
startColors,
dependency->available ? "true " : "false" ,
endColors,
dependency->required ? "true " : "false",
dependency->filter
);
- out(outString);
}
- sprintf(outString, "\n");
- out(outString);
+ fprintf(out, "\n");
infoServ->destroyInfo(infoServ->handle, info);
}
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/examples/dm_example/deploy.cmake
----------------------------------------------------------------------
diff --git a/examples/dm_example/deploy.cmake b/examples/dm_example/deploy.cmake
index 47072f4..1def6fc 100644
--- a/examples/dm_example/deploy.cmake
+++ b/examples/dm_example/deploy.cmake
@@ -17,13 +17,16 @@
if (BUILD_EXAMPLES AND BUILD_DEPENDENCY_MANAGER AND BUILD_SHELL AND BUILD_SHELL_TUI)
deploy("dm_example"
BUNDLES
- phase1
- phase2a
- phase2b
- phase3
- shell
- shell_tui
- dm_shell
+ phase1
+ phase2a
+ phase2b
+ phase3
+ shell
+ shell_tui
+ dm_shell
+ PROPERTIES
+ LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+
)
endif ()
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/shell/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt
index 32aa08f..235f348 100644
--- a/shell/CMakeLists.txt
+++ b/shell/CMakeLists.txt
@@ -35,6 +35,9 @@ if (SHELL)
private/src/log_command
private/src/inspect_command
private/src/help_command
+
+ ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
+
)
install_bundle(shell
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/shell/private/include/shell_private.h
----------------------------------------------------------------------
diff --git a/shell/private/include/shell_private.h b/shell/private/include/shell_private.h
index 092f6e3..c3a3386 100644
--- a/shell/private/include/shell_private.h
+++ b/shell/private/include/shell_private.h
@@ -31,11 +31,13 @@
#include "shell.h"
#include "hash_map.h"
#include "command.h"
+#include "log_helper.h"
struct shell {
bundle_context_pt bundle_context_ptr;
hash_map_pt command_reference_map_ptr;
hash_map_pt command_name_map_ptr;
+ log_helper_pt logHelper;
};
celix_status_t shell_create(bundle_context_pt context_ptr, shell_service_pt *shell_service_ptr);
http://git-wip-us.apache.org/repos/asf/celix/blob/04b68623/shell/private/src/shell.c
----------------------------------------------------------------------
diff --git a/shell/private/src/shell.c b/shell/private/src/shell.c
index 8a37e88..d4fe9cc 100644
--- a/shell/private/src/shell.c
+++ b/shell/private/src/shell.c
@@ -25,6 +25,7 @@
*/
#include <stdlib.h>
#include <string.h>
+#include <log_helper.h>
#include "celix_errno.h"
@@ -67,6 +68,8 @@ celix_status_t shell_create(bundle_context_pt context_ptr, shell_service_pt *she
(*shell_service_ptr)->getCommandUsage = shell_getCommandUsage;
(*shell_service_ptr)->getCommandReference = shell_getCommandReference;
(*shell_service_ptr)->executeCommand = shell_executeCommand;
+
+ status = logHelper_create(context_ptr, &(*shell_service_ptr)->shell->logHelper);
}
if (status != CELIX_SUCCESS) {
@@ -120,6 +123,7 @@ celix_status_t shell_addCommand(shell_pt shell_ptr, service_reference_pt referen
if (status == CELIX_SUCCESS) {
status = serviceReference_getProperty(reference_ptr, "command.name", &name_str);
if (!name_str) {
+ logHelper_log(shell_ptr->logHelper, OSGI_LOGSERVICE_ERROR, "Command service must contain a 'command.name' property!");
status = CELIX_BUNDLE_EXCEPTION;
}
}
@@ -131,8 +135,9 @@ celix_status_t shell_addCommand(shell_pt shell_ptr, service_reference_pt referen
if (status != CELIX_SUCCESS) {
shell_removeCommand(shell_ptr, reference_ptr);
- fprintf(stderr, "Could not add Command. TODO\n");
- //TODO log to log service
+ char err[32];
+ celix_strerror(status, err, 32);
+ logHelper_log(shell_ptr->logHelper, OSGI_LOGSERVICE_ERROR, "Could not add command, got error %s\n", err);
}
return status;
[17/21] celix git commit: CELIX-269: Added marco for the callback
functions which can be used to prevent warning instead of casting to (void *)
Posted by pn...@apache.org.
CELIX-269: Added marco for the callback functions which can be used to prevent warning instead of casting to (void *)
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/e302c2d3
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/e302c2d3
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/e302c2d3
Branch: refs/heads/develop
Commit: e302c2d369c66c045b333088be0718b03c04bf15
Parents: 02c5631
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Oct 29 17:35:20 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Oct 29 17:35:20 2015 +0100
----------------------------------------------------------------------
.../private/src/dm_shell_list_command.c | 8 +++----
.../public/include/dm_component.h | 17 +++++++++++----
dependency_manager/public/include/dm_info.h | 2 +-
.../public/include/dm_service_dependency.h | 22 +++++++++++++++-----
.../phase1/private/include/phase1_cmp.h | 1 +
.../phase1/private/src/phase1_activator.c | 4 ++--
.../dm_example/phase1/private/src/phase1_cmp.c | 5 +++++
.../phase2a/private/include/phase2a_cmp.h | 1 +
.../phase2a/private/src/phase2a_activator.c | 4 ++--
.../phase2a/private/src/phase2a_cmp.c | 5 +++++
.../phase2b/private/include/phase2b_cmp.h | 1 +
.../phase2b/private/src/phase2b_activator.c | 4 ++--
.../phase2b/private/src/phase2b_cmp.c | 5 +++++
.../phase3/private/include/phase3_cmp.h | 1 +
.../phase3/private/src/phase3_activator.c | 4 ++--
.../dm_example/phase3/private/src/phase3_cmp.c | 5 +++++
16 files changed, 67 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
index 4d08068..1855664 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -75,8 +75,8 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
int cmpCnt;
for (cmpCnt = 0; cmpCnt < arrayList_size(info->components); cmpCnt++) {
dm_component_info_pt compInfo = arrayList_get(info->components, cmpCnt);
- char *startColors = "";
- char *endColors = "";
+ const char *startColors = "";
+ const char *endColors = "";
if (colors) {
startColors = compInfo->active ? OK_COLOR : NOK_COLOR;
endColors = END_COLOR;
@@ -100,8 +100,8 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
for(depCnt = 0 ;depCnt < arrayList_size(compInfo->dependency_list); depCnt++) {
dm_service_dependency_info_pt dependency;
dependency = arrayList_get(compInfo->dependency_list, depCnt);
- char *startColors = "";
- char *endColors = "";
+ const char *startColors = "";
+ const char *endColors = "";
if (colors) {
if (dependency->required) {
startColors = dependency->available ? OK_COLOR : NOK_COLOR;
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/dependency_manager/public/include/dm_component.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_component.h b/dependency_manager/public/include/dm_component.h
index cf709cd..b558aea 100644
--- a/dependency_manager/public/include/dm_component.h
+++ b/dependency_manager/public/include/dm_component.h
@@ -39,10 +39,10 @@ typedef struct dm_component *dm_component_pt;
#define DM_COMPONENT_MAX_ID_LENGTH 64
#define DM_COMPONENT_MAX_NAME_LENGTH 128
-typedef celix_status_t (*init_fpt)(void *userData);
-typedef celix_status_t (*start_fpt)(void *userData);
-typedef celix_status_t (*stop_fpt)(void *userData);
-typedef celix_status_t (*deinit_fpt)(void *userData);
+typedef int (*init_fpt)(void *userData);
+typedef int (*start_fpt)(void *userData);
+typedef int (*stop_fpt)(void *userData);
+typedef int (*deinit_fpt)(void *userData);
celix_status_t component_create(bundle_context_pt context, const char *name, dm_component_pt *component);
celix_status_t component_destroy(dm_component_pt *component);
@@ -58,6 +58,15 @@ celix_status_t component_getInterfaces(dm_component_pt component, array_list_pt
celix_status_t component_addServiceDependency(dm_component_pt component, dm_service_dependency_pt dep);
celix_status_t component_removeServiceDependency(dm_component_pt component, dm_service_dependency_pt dependency);
+#define component_setCallbacksSafe(dmCmp, type, init, start, stop, deinit) \
+ do { \
+ int (*tmp_init)(type) = (init); \
+ int (*tmp_start)(type) = (start); \
+ int (*tmp_stop)(type) = (stop); \
+ int (*tmp_deinit)(type) = (deinit); \
+ component_setCallbacks((dmCmp), (init_fpt)tmp_init, (start_fpt)tmp_start, (stop_fpt)tmp_stop, (deinit_fpt)tmp_deinit); \
+ } while(0)
+
celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt stop, deinit_fpt deinit);
/**
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/dependency_manager/public/include/dm_info.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_info.h b/dependency_manager/public/include/dm_info.h
index dd9947c..99bb46a 100644
--- a/dependency_manager/public/include/dm_info.h
+++ b/dependency_manager/public/include/dm_info.h
@@ -57,7 +57,7 @@ struct dm_info_service {
/*Note: dm_caller has the ownership of the result.*/
celix_status_t (*getInfo)(void *handle, dm_dependency_manager_info_pt *info);
- void (*destroyInfo)(void *handle, dm_service_dependency_info_pt info);
+ void (*destroyInfo)(void *handle, dm_dependency_manager_info_pt info);
};
typedef struct dm_info_service * dm_info_service_pt;
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/dependency_manager/public/include/dm_service_dependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_service_dependency.h b/dependency_manager/public/include/dm_service_dependency.h
index 337be01..1a98dea 100644
--- a/dependency_manager/public/include/dm_service_dependency.h
+++ b/dependency_manager/public/include/dm_service_dependency.h
@@ -33,11 +33,11 @@
typedef struct dm_service_dependency *dm_service_dependency_pt;
-typedef celix_status_t (*service_set_fpt)(void *handle, void *service);
-typedef celix_status_t (*service_add_fpt)(void *handle, void *service);
-typedef celix_status_t (*service_change_fpt)(void *handle, void *service);
-typedef celix_status_t (*service_remove_fpt)(void *handle, void *service);
-typedef celix_status_t (*service_swap_fpt)(void *handle, void *oldService, void *newService);
+typedef int (*service_set_fpt)(void *handle, void *service);
+typedef int (*service_add_fpt)(void *handle, void *service);
+typedef int (*service_change_fpt)(void *handle, void *service);
+typedef int (*service_remove_fpt)(void *handle, void *service);
+typedef int (*service_swap_fpt)(void *handle, void *oldService, void *newService);
typedef celix_status_t (*service_set_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
typedef celix_status_t (*service_add_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
@@ -51,10 +51,22 @@ celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_pt
celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required);
celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName, char *filter);
celix_status_t serviceDependency_getFilter(dm_service_dependency_pt dependency, char **filter);
+
celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_set_fpt set, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap);
celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_set_with_ref_fpt set, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap);
celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t *service_lock, void **field);
+#define serviceDependency_setCallbacksSafe(dep, cmpType, servType, set, add, change, remove, swap) \
+ do { \
+ int (*tmpSet)(cmpType, servType) = set; \
+ int (*tmpAdd)(cmpType, servType) = add; \
+ int (*tmpChange)(cmpType, servType) = change; \
+ int (*tmpRemove)(cmpType, servType) = remove; \
+ int (*tmpSwap)(cmpType, servType, servType) = swap; \
+ serviceDependency_setCallbacks((dep), (service_set_fpt)tmpSet, (service_add_fpt)tmpAdd, (service_change_fpt)tmpChange, (service_remove_fpt)tmpRemove, (service_swap_fpt)tmpSwap); \
+ } while(0)
+
+
/**
* Return a service dependency info. The caller is the owner
*/
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase1/private/include/phase1_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/private/include/phase1_cmp.h b/examples/dm_example/phase1/private/include/phase1_cmp.h
index 55e3f15..5715f6e 100644
--- a/examples/dm_example/phase1/private/include/phase1_cmp.h
+++ b/examples/dm_example/phase1/private/include/phase1_cmp.h
@@ -34,6 +34,7 @@ phase1_cmp_t *phase1_create(void);
int phase1_init(phase1_cmp_t *cmp);
int phase1_start(phase1_cmp_t *cmp);
int phase1_stop(phase1_cmp_t *cmp);
+int phase1_deinit(phase1_cmp_t *cmp);
void phase1_destroy(phase1_cmp_t *cmp);
int phase1_getData(phase1_cmp_t *cmp, unsigned int *data);
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase1/private/src/phase1_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/private/src/phase1_activator.c b/examples/dm_example/phase1/private/src/phase1_activator.c
index 60ab21d..4d20c97 100644
--- a/examples/dm_example/phase1/private/src/phase1_activator.c
+++ b/examples/dm_example/phase1/private/src/phase1_activator.c
@@ -53,7 +53,7 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
if (act->phase1Cmp != NULL) {
act->phase1Serv.handle = act->phase1Cmp;
- act->phase1Serv.getData = phase1_getData;
+ act->phase1Serv.getData = (void *)phase1_getData;
properties_pt props = properties_create();
properties_set(props, "id", "phase1");
@@ -61,7 +61,7 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
dm_component_pt cmp;
component_create(context, "PHASE1_PROCESSING_COMPONENT", &cmp);
component_setImplementation(cmp, act->phase1Cmp);
- component_setCallbacks(cmp, phase1_init, phase1_start, phase1_stop, phase1_destroy);
+ component_setCallbacksSafe(cmp, phase1_cmp_t *, phase1_init, phase1_start, phase1_stop, phase1_deinit);
component_addInterface(cmp, PHASE1_NAME, &act->phase1Serv, props);
dependencyManager_add(manager, cmp);
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase1/private/src/phase1_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase1/private/src/phase1_cmp.c b/examples/dm_example/phase1/private/src/phase1_cmp.c
index ba9d46e..e050ba2 100644
--- a/examples/dm_example/phase1/private/src/phase1_cmp.c
+++ b/examples/dm_example/phase1/private/src/phase1_cmp.c
@@ -71,6 +71,11 @@ int phase1_stop(phase1_cmp_t *cmp) {
return 0;
}
+int phase1_deinit(phase1_cmp_t *cmp) {
+ printf("deinit phase1\n");
+ return 0;
+}
+
void phase1_destroy(phase1_cmp_t *cmp) {
free(cmp);
printf("destroy phase1\n");
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase2a/private/include/phase2a_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/private/include/phase2a_cmp.h b/examples/dm_example/phase2a/private/include/phase2a_cmp.h
index ecfc0f0..5b8431a 100644
--- a/examples/dm_example/phase2a/private/include/phase2a_cmp.h
+++ b/examples/dm_example/phase2a/private/include/phase2a_cmp.h
@@ -35,6 +35,7 @@ phase2a_cmp_t *phase2a_create(void);
int phase2a_init(phase2a_cmp_t *cmp);
int phase2a_start(phase2a_cmp_t *cmp);
int phase2a_stop(phase2a_cmp_t *cmp);
+int phase2a_deinit(phase2a_cmp_t *cmp);
void phase2a_destroy(phase2a_cmp_t *cmp);
int phase2a_setPhase1(phase2a_cmp_t *cmp, phase1_t *phase1);
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase2a/private/src/phase2a_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/private/src/phase2a_activator.c b/examples/dm_example/phase2a/private/src/phase2a_activator.c
index 96f32ab..9202a1f 100644
--- a/examples/dm_example/phase2a/private/src/phase2a_activator.c
+++ b/examples/dm_example/phase2a/private/src/phase2a_activator.c
@@ -62,14 +62,14 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
dm_component_pt cmp;
component_create(context, "PHASE2A_PROCESSING_COMPONENT", &cmp);
component_setImplementation(cmp, act->phase2aCmp);
- component_setCallbacks(cmp, (void *)phase2a_init, (void *)phase2a_start, (void *)phase2a_stop, (void *)phase2a_destroy);
+ component_setCallbacksSafe(cmp, phase2a_cmp_t *, phase2a_init, phase2a_start, phase2a_stop, phase2a_deinit);
component_addInterface(cmp, PHASE2_NAME, &act->phase2Serv, props);
dm_service_dependency_pt dep;
serviceDependency_create(&dep);
serviceDependency_setService(dep, PHASE1_NAME, NULL);
- serviceDependency_setCallbacks(dep, phase2a_setPhase1, NULL, NULL, NULL, NULL);
+ serviceDependency_setCallbacksSafe(dep, phase2a_cmp_t *, phase1_t *, phase2a_setPhase1, NULL, NULL, NULL, NULL);
serviceDependency_setRequired(dep, true);
component_addServiceDependency(cmp, dep);
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase2a/private/src/phase2a_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/private/src/phase2a_cmp.c b/examples/dm_example/phase2a/private/src/phase2a_cmp.c
index 2afa0d2..27c610a 100644
--- a/examples/dm_example/phase2a/private/src/phase2a_cmp.c
+++ b/examples/dm_example/phase2a/private/src/phase2a_cmp.c
@@ -73,6 +73,11 @@ int phase2a_stop(phase2a_cmp_t *cmp) {
return 0;
}
+int phase2a_deinit(phase2a_cmp_t *cmp) {
+ printf("deinit phase1\n");
+ return 0;
+}
+
void phase2a_destroy(phase2a_cmp_t *cmp) {
celixThreadMutex_lock(&cmp->mutex);
celixThreadMutex_destroy(&cmp->mutex);
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase2b/private/include/phase2b_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/private/include/phase2b_cmp.h b/examples/dm_example/phase2b/private/include/phase2b_cmp.h
index fedcd69..527975b 100644
--- a/examples/dm_example/phase2b/private/include/phase2b_cmp.h
+++ b/examples/dm_example/phase2b/private/include/phase2b_cmp.h
@@ -35,6 +35,7 @@ phase2b_cmp_t *phase2b_create(void);
int phase2b_init(phase2b_cmp_t *cmp);
int phase2b_start(phase2b_cmp_t *cmp);
int phase2b_stop(phase2b_cmp_t *cmp);
+int phase2b_deinit(phase2b_cmp_t *cmp);
void phase2b_destroy(phase2b_cmp_t *cmp);
int phase2b_setPhase1(phase2b_cmp_t *cmp, phase1_t *phase1);
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase2b/private/src/phase2b_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/private/src/phase2b_activator.c b/examples/dm_example/phase2b/private/src/phase2b_activator.c
index 82bfef1..c715bf5 100644
--- a/examples/dm_example/phase2b/private/src/phase2b_activator.c
+++ b/examples/dm_example/phase2b/private/src/phase2b_activator.c
@@ -62,14 +62,14 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
dm_component_pt cmp;
component_create(context, "PHASE2B_PROCESSING_COMPONENT", &cmp);
component_setImplementation(cmp, act->phase2bCmp);
- component_setCallbacks(cmp, (void *)phase2b_init, (void *)phase2b_start, (void *)phase2b_stop, (void *)phase2b_destroy);
+ component_setCallbacksSafe(cmp, phase2b_cmp_t *, phase2b_init, phase2b_start, phase2b_stop, phase2b_deinit);
component_addInterface(cmp, PHASE2_NAME, &act->phase2Serv, props);
dm_service_dependency_pt dep;
serviceDependency_create(&dep);
serviceDependency_setService(dep, PHASE1_NAME, NULL);
- serviceDependency_setCallbacks(dep, phase2b_setPhase1, NULL, NULL, NULL, NULL);
+ serviceDependency_setCallbacksSafe(dep, phase2b_cmp_t *, phase1_t *, phase2b_setPhase1, NULL, NULL, NULL, NULL);
serviceDependency_setRequired(dep, true);
component_addServiceDependency(cmp, dep);
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase2b/private/src/phase2b_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/private/src/phase2b_cmp.c b/examples/dm_example/phase2b/private/src/phase2b_cmp.c
index e1487b4..9d6d3d5 100644
--- a/examples/dm_example/phase2b/private/src/phase2b_cmp.c
+++ b/examples/dm_example/phase2b/private/src/phase2b_cmp.c
@@ -73,6 +73,11 @@ int phase2b_stop(phase2b_cmp_t *cmp) {
return 0;
}
+int phase2b_deinit(phase2b_cmp_t *cmp) {
+ printf("deinit phase1\n");
+ return 0;
+}
+
void phase2b_destroy(phase2b_cmp_t *cmp) {
celixThreadMutex_lock(&cmp->mutex);
celixThreadMutex_destroy(&cmp->mutex);
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase3/private/include/phase3_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/include/phase3_cmp.h b/examples/dm_example/phase3/private/include/phase3_cmp.h
index 1b32f04..ec9282d 100644
--- a/examples/dm_example/phase3/private/include/phase3_cmp.h
+++ b/examples/dm_example/phase3/private/include/phase3_cmp.h
@@ -35,6 +35,7 @@ phase3_cmp_t *phase3_create(void);
int phase3_init(phase3_cmp_t *cmp);
int phase3_start(phase3_cmp_t *cmp);
int phase3_stop(phase3_cmp_t *cmp);
+int phase3_deinit(phase3_cmp_t *cmp);
void phase3_destroy(phase3_cmp_t *cmp);
int phase3_addPhase2(phase3_cmp_t *cmp, phase2_t *phase2);
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase3/private/src/phase3_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/src/phase3_activator.c b/examples/dm_example/phase3/private/src/phase3_activator.c
index 2d8f3df..d79b785 100644
--- a/examples/dm_example/phase3/private/src/phase3_activator.c
+++ b/examples/dm_example/phase3/private/src/phase3_activator.c
@@ -56,12 +56,12 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
dm_component_pt cmp;
component_create(context, "PHASE3_PROCESSING_COMPONENT", &cmp);
component_setImplementation(cmp, act->phase3Cmp);
- component_setCallbacks(cmp, (void *)phase3_init, (void *)phase3_start, (void *)phase3_stop, (void *)phase3_destroy);
+ component_setCallbacksSafe(cmp, phase3_cmp_t *, phase3_init, phase3_start, phase3_stop, phase3_deinit);
dm_service_dependency_pt dep;
serviceDependency_create(&dep);
serviceDependency_setService(dep, PHASE2_NAME, NULL);
- serviceDependency_setCallbacks(dep, NULL, (void *)phase3_addPhase2, NULL, (void *)phase3_removePhase2, NULL);
+ serviceDependency_setCallbacksSafe(dep, phase3_cmp_t *, phase2_t *, NULL, phase3_addPhase2, NULL, phase3_removePhase2, NULL);
serviceDependency_setRequired(dep, true);
component_addServiceDependency(cmp, dep);
http://git-wip-us.apache.org/repos/asf/celix/blob/e302c2d3/examples/dm_example/phase3/private/src/phase3_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/src/phase3_cmp.c b/examples/dm_example/phase3/private/src/phase3_cmp.c
index 5cd9f53..6f5b99b 100644
--- a/examples/dm_example/phase3/private/src/phase3_cmp.c
+++ b/examples/dm_example/phase3/private/src/phase3_cmp.c
@@ -75,6 +75,11 @@ int phase3_stop(phase3_cmp_t *cmp) {
return 0;
}
+int phase3_deinit(phase3_cmp_t *cmp) {
+ printf("deinit phase1\n");
+ return 0;
+}
+
void phase3_destroy(phase3_cmp_t *cmp) {
celixThreadMutex_lock(&cmp->mutex);
celixThreadMutex_destroy(&cmp->mutex);
[16/21] celix git commit: CELIX-269: Changed the component add
service dependency function from vararg to non vararg
Posted by pn...@apache.org.
CELIX-269: Changed the component add service dependency function from vararg to non vararg
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/02c56310
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/02c56310
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/02c56310
Branch: refs/heads/develop
Commit: 02c56310348cf341c0d4c2bf43c6a373fcb05246
Parents: d040f00
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Oct 29 16:43:50 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Oct 29 16:43:50 2015 +0100
----------------------------------------------------------------------
dependency_manager/private/src/dm_component_impl.c | 10 +++++++---
dependency_manager/public/include/dm_component.h | 2 +-
.../tracker_depman/private/src/dependency_activator.c | 4 ++--
3 files changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/02c56310/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index ec13933..a36e232 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -166,23 +166,25 @@ celix_status_t component_destroy(dm_component_pt *component_ptr) {
return status;
}
-celix_status_t component_addServiceDependency(dm_component_pt component, ...) {
+celix_status_t component_addServiceDependency(dm_component_pt component, dm_service_dependency_pt dep) {
celix_status_t status = CELIX_SUCCESS;
array_list_pt dependenciesList = NULL;
arrayList_create(&dependenciesList);
+ arrayList_add(dependenciesList, dep);
+ /*
va_list dependencies;
va_start(dependencies, component);
dm_service_dependency_pt dependency = va_arg(dependencies, dm_service_dependency_pt);
while (dependency != NULL) {
arrayList_add(dependenciesList, dependency);
-
dependency = va_arg(dependencies, dm_service_dependency_pt);
}
va_end(dependencies);
+ */
executor_executeTask(component->executor, component, component_addTask, dependenciesList);
// component_addTask(component, dependenciesList);
@@ -1351,12 +1353,14 @@ celix_status_t component_getComponentInfo(dm_component_pt component, dm_componen
celixThreadMutex_lock(&component->mutex);
size = arrayList_size(component->dependencies);
- for (i = 0; status == CELIX_SUCCESS && i < size; i += 1) {
+ for (i = 0; i < size; i += 1) {
dm_service_dependency_pt dep = arrayList_get(component->dependencies, i);
dm_service_dependency_info_pt depInfo= NULL;
status = serviceDependency_getServiceDependencyInfo(dep, &depInfo);
if (status == CELIX_SUCCESS) {
arrayList_add(info->dependency_list, depInfo);
+ } else {
+ break;
}
}
celixThreadMutex_unlock(&component->mutex);
http://git-wip-us.apache.org/repos/asf/celix/blob/02c56310/dependency_manager/public/include/dm_component.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_component.h b/dependency_manager/public/include/dm_component.h
index 12dbcca..cf709cd 100644
--- a/dependency_manager/public/include/dm_component.h
+++ b/dependency_manager/public/include/dm_component.h
@@ -55,7 +55,7 @@ celix_status_t component_setImplementation(dm_component_pt component, void *impl
*/
celix_status_t component_getInterfaces(dm_component_pt component, array_list_pt *servicesNames);
-celix_status_t component_addServiceDependency(dm_component_pt component, ...);
+celix_status_t component_addServiceDependency(dm_component_pt component, dm_service_dependency_pt dep);
celix_status_t component_removeServiceDependency(dm_component_pt component, dm_service_dependency_pt dependency);
celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt stop, deinit_fpt deinit);
http://git-wip-us.apache.org/repos/asf/celix/blob/02c56310/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
index 4e36321..2ce9bab 100644
--- a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
+++ b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
@@ -62,14 +62,14 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
serviceDependency_setRequired(dep1, true);
serviceDependency_setService(dep1, PUBLISHER_NAME, "(|(id=A)(id=B))");
serviceDependency_setCallbacksWithServiceReference(dep1, NULL /*tracker_setServ*/, tracker_addedServ, tracker_modifiedServ, tracker_removedServ, NULL);
- component_addServiceDependency(service, dep1, NULL);
+ component_addServiceDependency(service, dep1);
serviceDependency_create(&dep2);
serviceDependency_setRequired(dep2, false);
serviceDependency_setService(dep2, (char *) OSGI_LOGSERVICE_NAME, NULL);
serviceDependency_setCallbacksWithServiceReference(dep2, NULL /*tracker_setLog*/, tracker_addLog, tracker_modifiedLog, tracker_removeLog, NULL);
serviceDependency_setAutoConfigure(dep2, &data->logger_lock, (void **) &data->logger);
- component_addServiceDependency(service, dep2, NULL);
+ component_addServiceDependency(service, dep2);
data->service = service;
data->dep = dep1;
[12/21] celix git commit: CELIX-210: Added yellow color text instead
of red for not available optional dependencies
Posted by pn...@apache.org.
CELIX-210: Added yellow color text instead of red for not available optional dependencies
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/f48fee19
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/f48fee19
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/f48fee19
Branch: refs/heads/develop
Commit: f48fee19af8a0e06c5d74b5ceae0c74f783c5dd0
Parents: 2de2554
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Oct 22 21:37:03 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Oct 22 21:37:03 2015 +0200
----------------------------------------------------------------------
.../private/src/dm_shell_list_command.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/f48fee19/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
index 1e70513..030d909 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -35,6 +35,11 @@
#include "shell.h"
+static const char * const OK_COLOR = "\033[92m";
+static const char * const WARNING_COLOR = "\033[93m";
+static const char * const NOK_COLOR = "\033[91m";
+static const char * const END_COLOR = "\033[m";
+
char * dmListCommand_getName(command_pt command) {
return "dm";
}
@@ -73,8 +78,8 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
char *startColors = "";
char *endColors = "";
if (colors) {
- startColors = compInfo->active ? "\033[92m" : "\033[91m";
- endColors = "\033[m";
+ startColors = compInfo->active ? OK_COLOR : NOK_COLOR;
+ endColors = END_COLOR;
}
sprintf(outString, "Component: ID=%s, %sActive=%s%s, State=%s\n", compInfo->id, startColors, compInfo->active ? "true " : "false", endColors, compInfo->state);
out(outString);
@@ -98,8 +103,13 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
char *startColors = "";
char *endColors = "";
if (colors) {
- startColors = dependency->available ? "\033[92m" : "\033[91m";
- endColors = "\033[m";
+ if (dependency->required) {
+ startColors = dependency->available ? OK_COLOR : NOK_COLOR;
+ } else {
+ startColors = dependency->available ? OK_COLOR : WARNING_COLOR;
+ }
+
+ endColors = END_COLOR;
}
sprintf(outString, " |- Dependency: %sAvailable = %s%s, Required = %s, Filter = %s\n",
startColors,
[20/21] celix git commit: CELIX-269: Merge branch
'feature/CELIX-269_depman' into depman
Posted by pn...@apache.org.
CELIX-269: Merge branch 'feature/CELIX-269_depman' into depman
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/9af85cef
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/9af85cef
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/9af85cef
Branch: refs/heads/develop
Commit: 9af85cef5ca13c70aa46290850e0b7e9a9d436f4
Parents: f5a3cdd 2e480a2
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Nov 3 10:18:41 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Nov 3 10:18:41 2015 +0100
----------------------------------------------------------------------
framework/private/src/bundle_context.c | 3 +
framework/private/src/service_reference.c | 1 -
.../examples/calculator_shell/CMakeLists.txt | 1 -
.../private/include/add_command.h | 5 +-
.../private/include/sqrt_command.h | 5 +-
.../private/include/sub_command.h | 5 +-
.../calculator_shell/private/src/add_command.c | 46 +-
.../private/src/calculator_shell_activator.c | 55 ++-
.../calculator_shell/private/src/sqrt_command.c | 42 +-
.../calculator_shell/private/src/sub_command.c | 46 +-
remote_shell/private/include/shell_mediator.h | 2 +-
remote_shell/private/src/remote_shell.c | 46 +-
remote_shell/private/src/shell_mediator.c | 19 +-
shell/CMakeLists.txt | 38 +-
shell/private/include/help_command.h | 33 --
shell/private/include/inspect_command.h | 33 --
shell/private/include/install_command.h | 33 --
shell/private/include/log_command.h | 33 --
shell/private/include/ps_command.h | 33 --
shell/private/include/shell_private.h | 22 +-
shell/private/include/start_command.h | 33 --
shell/private/include/std_commands.h | 44 ++
shell/private/include/stop_command.h | 33 --
shell/private/include/uninstall_command.h | 33 --
shell/private/include/update_command.h | 35 --
shell/private/src/activator.c | 415 ++++++++++---------
shell/private/src/help_command.c | 135 +++---
shell/private/src/inspect_command.c | 121 ++----
shell/private/src/install_command.c | 49 +--
shell/private/src/lb_command.c | 181 ++++++++
shell/private/src/log_command.c | 48 +--
shell/private/src/ps_command.c | 162 --------
shell/private/src/shell.c | 340 ++++++++++-----
shell/private/src/start_command.c | 89 ++--
shell/private/src/stop_command.c | 93 ++---
shell/private/src/uninstall_command.c | 33 +-
shell/private/src/update_command.c | 42 +-
shell/public/include/command.h | 23 +-
shell/public/include/command_impl.h | 48 ---
shell/public/include/shell.h | 11 +-
shell/public/src/command.c | 45 --
shell_tui/private/src/shell_tui.c | 5 +-
42 files changed, 1074 insertions(+), 1445 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/9af85cef/framework/private/src/service_reference.c
----------------------------------------------------------------------
[18/21] celix git commit: CELIX-269: Fixed severial issues concering
the dependency manager. Removed the need for cleanup from the dm activator,
this will be done by the dm base activator.
Posted by pn...@apache.org.
CELIX-269: Fixed severial issues concering the dependency manager. Removed the need for cleanup from the dm activator, this will be done by the dm base activator.
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/59c8e5d8
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/59c8e5d8
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/59c8e5d8
Branch: refs/heads/develop
Commit: 59c8e5d87134d94135ddc92e5dc5ea0f82b9cee6
Parents: e302c2d
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Nov 2 14:07:07 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Nov 2 14:07:07 2015 +0100
----------------------------------------------------------------------
dependency_manager/private/include/dm_event.h | 2 +
.../private/src/dm_activator_base.c | 63 ++++++++------
.../private/src/dm_component_impl.c | 89 +++++---------------
.../private/src/dm_dependency_manager_impl.c | 28 +++---
dependency_manager/private/src/dm_event.c | 17 +++-
.../private/src/dm_service_dependency.c | 14 +--
.../public/include/dm_dependency_manager.h | 5 +-
.../private/src/dependency_activator.c | 9 --
framework/private/src/service_reference.c | 37 +++-----
framework/private/src/utils.c | 15 ++++
framework/public/include/utils.h | 2 +
11 files changed, 132 insertions(+), 149 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/include/dm_event.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_event.h b/dependency_manager/private/include/dm_event.h
index 8e23721..21f9831 100644
--- a/dependency_manager/private/include/dm_event.h
+++ b/dependency_manager/private/include/dm_event.h
@@ -42,6 +42,8 @@ typedef enum dm_event_type dm_event_type_e;
struct dm_event {
void *service;
+ long serviceId;
+ long ranking;
service_reference_pt reference;
bundle_context_pt context;
bundle_pt bundle;
http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/src/dm_activator_base.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_activator_base.c b/dependency_manager/private/src/dm_activator_base.c
index 25065a9..60a47ac 100644
--- a/dependency_manager/private/src/dm_activator_base.c
+++ b/dependency_manager/private/src/dm_activator_base.c
@@ -53,14 +53,22 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
dm_create(context, &dependency_activator->userData);
dependency_activator->info = serv;
- (*userData) = dependency_activator;;
-
- status = CELIX_SUCCESS;
+ status = dependencyManager_create(dependency_activator->context, &dependency_activator->manager);
} else {
- free(dependency_activator);
- free(serv);
+ status = CELIX_ENOMEM;
+
}
+ if (status == CELIX_SUCCESS) {
+ *userData = dependency_activator;
+ } else {
+ if (dependency_activator != NULL) {
+ dependencyManager_destroy(dependency_activator->manager);
+ }
+ free(dependency_activator);
+ free(serv);
+ }
+
return status;
}
@@ -68,42 +76,47 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
celix_status_t status;
dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
- status = dependencyManager_create(dependency_activator->context, &dependency_activator->manager);
- if (status == CELIX_SUCCESS) {
- dm_init(dependency_activator->userData, context, dependency_activator->manager);
- }
+ status = dm_init(dependency_activator->userData, context, dependency_activator->manager);
+
+ if (status == CELIX_SUCCESS) {
+ //Create the service
+ dependency_activator->info->handle = dependency_activator->manager;
+ dependency_activator->info->getInfo = (void *) dependencyManager_getInfo;
+ dependency_activator->info->destroyInfo = (void *) dependencyManager_destroyInfo;
- //Create the service
- dependency_activator->info->handle = dependency_activator->manager;
- dependency_activator->info->getInfo = (void *)dependencyManager_getInfo;
- dependency_activator->info->destroyInfo = (void *)dependencyManager_destroyInfo;
+ status = bundleContext_registerService(context, DM_INFO_SERVICE_NAME, dependency_activator->info, NULL,
+ &(dependency_activator->reg));
+ }
- bundleContext_registerService(context, DM_INFO_SERVICE_NAME, dependency_activator->info, NULL, &(dependency_activator->reg));
return status;
}
celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context __attribute__((unused))) {
celix_status_t status = CELIX_SUCCESS;
- dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
-
- dm_destroy(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
+ dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
- dependencyManager_destroy(&dependency_activator->manager);
+ // Remove the service
+ status = serviceRegistration_unregister(dependency_activator->reg);
+ depedencyManager_removeAllComponents(dependency_activator->manager);
- // Remove the service
- serviceRegistration_unregister(dependency_activator->reg);
-
- dependency_activator->userData = NULL;
- dependency_activator->manager = NULL;
-
- return status;
+ return status;
}
celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context __attribute__((unused))) {
celix_status_t status = CELIX_SUCCESS;
dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
+ status = dm_destroy(dependency_activator->userData, dependency_activator->context,
+ dependency_activator->manager);
+
+ if (status == CELIX_SUCCESS) {
+ dependencyManager_destroy(dependency_activator->manager);
+ }
+
+ dependency_activator->userData = NULL;
+ dependency_activator->manager = NULL;
+
if (dependency_activator != NULL) {
free(dependency_activator->info);
}
http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index a36e232..fb89b05 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -63,12 +63,11 @@ static celix_status_t executor_schedule(dm_executor_pt executor, dm_component_pt
static celix_status_t executor_create(dm_component_pt component __attribute__((unused)), dm_executor_pt *executor);
static celix_status_t executor_destroy(dm_executor_pt *executor);
-static celix_status_t component_destroyComponent(dm_component_pt component);
static celix_status_t component_invokeRemoveRequiredDependencies(dm_component_pt component);
static celix_status_t component_invokeRemoveInstanceBoundDependencies(dm_component_pt component);
static celix_status_t component_invokeRemoveOptionalDependencies(dm_component_pt component);
-static celix_status_t component_registerService(dm_component_pt component);
-static celix_status_t component_unregisterService(dm_component_pt component);
+static celix_status_t component_registerServices(dm_component_pt component);
+static celix_status_t component_unregisterServices(dm_component_pt component);
static celix_status_t component_invokeAddOptionalDependencies(dm_component_pt component);
static celix_status_t component_invokeAddRequiredInstanceBoundDependencies(dm_component_pt component);
static celix_status_t component_invokeAddRequiredDependencies(dm_component_pt component);
@@ -497,10 +496,10 @@ celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dep
dm_event_pt old = arrayList_remove(events, (unsigned int) index);
pthread_mutex_unlock(&component->mutex);
- serviceDependency_invokeSet(dependency, event);
switch (component->state) {
case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
+ serviceDependency_invokeSet(dependency, event);
bool instanceBound = false;
serviceDependency_isInstanceBound(dependency, &instanceBound);
if (!instanceBound) {
@@ -516,6 +515,7 @@ celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dep
break;
}
case DM_CMP_STATE_TRACKING_OPTIONAL:
+ serviceDependency_invokeSet(dependency, event);
serviceDependency_invokeRemove(dependency, event);
dm_event_pt hevent = NULL;
component_getDependencyEvent(component, dependency, &hevent);
@@ -729,85 +729,48 @@ celix_status_t component_calculateNewState(dm_component_pt component, dm_compone
celix_status_t component_performTransition(dm_component_pt component, dm_component_state_t oldState, dm_component_state_t newState, bool *transition) {
celix_status_t status = CELIX_SUCCESS;
- printf("performing transition from %i to %i\n", oldState, newState);
+ //printf("performing transition for %s in thread %i from %i to %i\n", component->name, pthread_self(), oldState, newState);
- if (oldState == DM_CMP_STATE_INACTIVE && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
+ if (oldState == newState) {
+ *transition = false;
+ } else if (oldState == DM_CMP_STATE_INACTIVE && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
component_startDependencies(component, component->dependencies);
-// #TODO Add listener support
-// notifyListeners(newState);
*transition = true;
- return status;
- }
-
- if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
- // #TODO Remove
-// component_instantiateComponent(component);
+ } else if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
component_invokeAddRequiredDependencies(component);
component_invokeAutoConfigDependencies(component);
- dm_component_state_t stateBeforeCallingInit = component->state;
if (component->callbackInit) {
- component->callbackInit(component->implementation);
- }
- if (stateBeforeCallingInit == component->state) {
-// #TODO Add listener support
-// notifyListeners(newState); // init did not change current state, we can notify about this new state
+ status = component->callbackInit(component->implementation);
}
*transition = true;
- return status;
- }
-
- if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_TRACKING_OPTIONAL) {
+ } else if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_TRACKING_OPTIONAL) {
component_invokeAddRequiredInstanceBoundDependencies(component);
component_invokeAutoConfigInstanceBoundDependencies(component);
if (component->callbackStart) {
- component->callbackStart(component->implementation);
+ status = component->callbackStart(component->implementation);
}
component_invokeAddOptionalDependencies(component);
- component_registerService(component);
-// #TODO Add listener support
-// notifyListeners(newState);
- return true;
- }
-
- if (oldState == DM_CMP_STATE_TRACKING_OPTIONAL && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
- component_unregisterService(component);
+ component_registerServices(component);
+ *transition = true;
+ } else if (oldState == DM_CMP_STATE_TRACKING_OPTIONAL && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
+ component_unregisterServices(component);
component_invokeRemoveOptionalDependencies(component);
if (component->callbackStop) {
- component->callbackStop(component->implementation);
+ status = component->callbackStop(component->implementation);
}
component_invokeRemoveInstanceBoundDependencies(component);
-// #TODO Add listener support
-// notifyListeners(newState);
*transition = true;
- return status;
- }
-
- if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
+ } else if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
if (component->callbackDeinit) {
- component->callbackDeinit(component->implementation);
+ status = component->callbackDeinit(component->implementation);
}
component_invokeRemoveRequiredDependencies(component);
-// #TODO Add listener support
-// notifyListeners(newState);
-// bool needInstance = false;
-// component_someDependenciesNeedInstance(component, &needInstance);
-// if (!needInstance) {
- component_destroyComponent(component);
-// }
*transition = true;
- return status;
- }
-
- if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INACTIVE) {
+ } else if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INACTIVE) {
component_stopDependencies(component);
- component_destroyComponent(component);
-// #TODO Add listener support
-// notifyListeners(newState);
*transition = true;
- return status;
}
- *transition = false;
return status;
}
@@ -1117,15 +1080,7 @@ celix_status_t component_configureImplementation(dm_component_pt component, dm_s
return status;
}
-celix_status_t component_destroyComponent(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
-// component->implementation = NULL;
-
- return status;
-}
-
-celix_status_t component_registerService(dm_component_pt component) {
+celix_status_t component_registerServices(dm_component_pt component) {
celix_status_t status = CELIX_SUCCESS;
if (component->context) {
@@ -1141,7 +1096,7 @@ celix_status_t component_registerService(dm_component_pt component) {
return status;
}
-celix_status_t component_unregisterService(dm_component_pt component) {
+celix_status_t component_unregisterServices(dm_component_pt component) {
celix_status_t status = CELIX_SUCCESS;
unsigned int i;
http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/src/dm_dependency_manager_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_dependency_manager_impl.c b/dependency_manager/private/src/dm_dependency_manager_impl.c
index 059ce54..7636121 100644
--- a/dependency_manager/private/src/dm_dependency_manager_impl.c
+++ b/dependency_manager/private/src/dm_dependency_manager_impl.c
@@ -50,15 +50,13 @@ celix_status_t dependencyManager_create(bundle_context_pt context __attribute__(
}
-celix_status_t dependencyManager_destroy(dm_dependency_manager_pt *manager) {
- celix_status_t status = CELIX_SUCCESS;
-
- arrayList_destroy((*manager)->components);
+void dependencyManager_destroy(dm_dependency_manager_pt manager) {
+ if (manager != NULL) {
+ //TODO destroy components
+ arrayList_destroy(manager->components);
- free(*manager);
- (*manager) = NULL;
-
- return status;
+ free(manager);
+ }
}
celix_status_t dependencyManager_add(dm_dependency_manager_pt manager, dm_component_pt component) {
@@ -70,11 +68,19 @@ celix_status_t dependencyManager_add(dm_dependency_manager_pt manager, dm_compon
return status;
}
-celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_component_pt component) {
+celix_status_t depedencyManager_removeAllComponents(dm_dependency_manager_pt manager) {
celix_status_t status;
- arrayList_removeElement(manager->components, component);
- status = component_stop(component);
+ while (!arrayList_isEmpty(manager->components)) {
+ dm_component_pt cmp = arrayList_remove(manager->components, 0);
+ printf("Removing comp %s\n", cmp->name);
+ status = component_stop(cmp);
+ //TODO component_destroy(&cmp);
+
+ if (status != CELIX_SUCCESS) {
+ break;
+ }
+ }
return status;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/src/dm_event.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_event.c b/dependency_manager/private/src/dm_event.c
index 60b7892..3fc7241 100644
--- a/dependency_manager/private/src/dm_event.c
+++ b/dependency_manager/private/src/dm_event.c
@@ -26,6 +26,8 @@
*/
#include <stdlib.h>
+#include <constants.h>
+#include <utils.h>
#include "dm_event.h"
@@ -37,12 +39,23 @@ celix_status_t event_create(dm_event_type_e event_type, bundle_pt bundle, bundle
status = CELIX_ENOMEM;
}
+ char *serviceIdStr = NULL;
+ serviceReference_getProperty(reference, (char *)OSGI_FRAMEWORK_SERVICE_ID, &serviceIdStr);
+ long servId = atol(serviceIdStr);
+
+ //FIXME service ranking can dynamicly change, but service reference can be removed at any time.
+ char *rankingStr = NULL;
+ serviceReference_getProperty(reference, (char *)OSGI_FRAMEWORK_SERVICE_RANKING, &rankingStr);
+ long ranking = rankingStr == NULL ? 0 : atol(rankingStr);
+
if (status == CELIX_SUCCESS) {
(*event)->bundle = bundle;
(*event)->event_type = event_type;
(*event)->context = context;
(*event)->reference = reference;
(*event)->service = service;
+ (*event)->serviceId = servId;
+ (*event)->ranking = ranking;
}
return status;
@@ -72,7 +85,7 @@ celix_status_t event_equals(void *a, void *b, bool *equals) {
dm_event_pt a_ptr = a;
dm_event_pt b_ptr = b;
- status = serviceReference_equals(a_ptr->reference, b_ptr->reference, equals);
+ *equals = a_ptr->serviceId == b_ptr->serviceId;
}
return status;
@@ -81,7 +94,7 @@ celix_status_t event_equals(void *a, void *b, bool *equals) {
celix_status_t event_compareTo(dm_event_pt event, dm_event_pt compareTo, int *compare) {
celix_status_t status;
- status = serviceReference_compareTo(event->reference, compareTo->reference, compare);
+ *compare = utils_compareServiceIdsAndRanking(event->serviceId, event->ranking, compareTo->serviceId, compareTo->ranking);
return status;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_service_dependency.c b/dependency_manager/private/src/dm_service_dependency.c
index e0bf489..b88f21d 100644
--- a/dependency_manager/private/src/dm_service_dependency.c
+++ b/dependency_manager/private/src/dm_service_dependency.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <assert.h>
#include "constants.h"
@@ -273,6 +274,10 @@ celix_status_t serviceDependency_stop(dm_service_dependency_pt dependency) {
}
if (status == CELIX_SUCCESS) {
+ dependency->isStarted = false;
+ }
+
+ if (status == CELIX_SUCCESS) {
if (dependency->tracker) {
tmp_status = serviceTracker_close(dependency->tracker);
if (tmp_status != CELIX_SUCCESS) {
@@ -285,10 +290,6 @@ celix_status_t serviceDependency_stop(dm_service_dependency_pt dependency) {
}
}
- if (status == CELIX_SUCCESS) {
- dependency->isStarted = false;
- }
-
return status;
}
@@ -319,8 +320,10 @@ celix_status_t serviceDependency_setAvailable(dm_service_dependency_pt dependenc
return status;
}
+
celix_status_t serviceDependency_invokeSet(dm_service_dependency_pt dependency, dm_event_pt event) {
celix_status_t status = CELIX_SUCCESS;
+ assert(dependency->isStarted == true);
array_list_pt serviceReferences = NULL;
int i;
int curRanking = INT_MIN;
@@ -329,7 +332,6 @@ celix_status_t serviceDependency_invokeSet(dm_service_dependency_pt dependency,
serviceReferences = serviceTracker_getServiceReferences(dependency->tracker);
- fprintf(stderr,"found %d servicereferences\n",arrayList_size(serviceReferences));
/* Find the service with the higest ranking */
for (i = 0; i < arrayList_size(serviceReferences); i++) {
service_reference_pt serviceReference = arrayList_get(serviceReferences, i);
@@ -364,8 +366,6 @@ celix_status_t serviceDependency_invokeSet(dm_service_dependency_pt dependency,
service = NULL;
}
- fprintf(stderr, "Ranking found: %d service %p\n", curRanking, service);
-
if (dependency->set) {
dependency->set(dependency->component->implementation, service);
}
http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/public/include/dm_dependency_manager.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_dependency_manager.h b/dependency_manager/public/include/dm_dependency_manager.h
index 44c1643..22b0ad6 100644
--- a/dependency_manager/public/include/dm_dependency_manager.h
+++ b/dependency_manager/public/include/dm_dependency_manager.h
@@ -36,10 +36,11 @@
typedef struct dm_dependency_manager *dm_dependency_manager_pt;
celix_status_t dependencyManager_create(bundle_context_pt context, dm_dependency_manager_pt *manager);
-celix_status_t dependencyManager_destroy(dm_dependency_manager_pt *manager);
+void dependencyManager_destroy(dm_dependency_manager_pt manager);
celix_status_t dependencyManager_add(dm_dependency_manager_pt manager, dm_component_pt component);
-celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_component_pt component);
+
+celix_status_t depedencyManager_removeAllComponents(dm_dependency_manager_pt manager);
/**
* returns a dm_ of dm_dependency_manager_info. Caller has ownership.
http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
index 2ce9bab..a5cf185 100644
--- a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
+++ b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
@@ -82,15 +82,6 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
struct data * data = (struct data *) userData;
- dependencyManager_remove(manager, data->service);
-
- component_removeServiceDependency(data->service, data->dep);
- serviceDependency_destroy(&data->dep);
-
- component_removeServiceDependency(data->service, data->dep2);
- serviceDependency_destroy(&data->dep2);
-
- component_destroy(&data->service);
arrayList_destroy(data->publishers);
data->publishers = NULL;
http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/framework/private/src/service_reference.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_reference.c b/framework/private/src/service_reference.c
index 778877c..1f473ea 100644
--- a/framework/private/src/service_reference.c
+++ b/framework/private/src/service_reference.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <constants.h>
#include <stdint.h>
+#include <utils.h>
#include "service_reference.h"
@@ -170,32 +171,16 @@ celix_status_t serviceReference_compareTo(service_reference_pt reference, servic
id = atol(id_str);
other_id = atol(other_id_str);
- if (id == other_id) {
- *compare = 0;
- } else {
- int rank, other_rank;
- char *rank_str, *other_rank_str;
- serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &rank_str);
- serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &other_rank_str);
-
- if (rank_str == NULL) {
- rank_str = "0";
- }
- if (other_rank_str == NULL) {
- other_rank_str = "0";
- }
-
- rank = atoi(rank_str);
- other_rank = atoi(other_rank_str);
-
- if (rank < other_rank) {
- *compare = -1;
- } else if (rank > other_rank) {
- *compare = 1;
- } else {
- *compare = id < other_id ? 1 : -1;
- }
- }
+
+ long rank, other_rank;
+ char *rank_str, *other_rank_str;
+ serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &rank_str);
+ serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &other_rank_str);
+
+ rank = rank_str == NULL ? 0 : atol(rank_str);
+ other_rank = other_rank_str == NULL ? 0 : atol(other_rank_str);
+
+ utils_compareServiceIdsAndRanking(id, rank, other_id, other_rank);
return status;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/framework/private/src/utils.c
----------------------------------------------------------------------
diff --git a/framework/private/src/utils.c b/framework/private/src/utils.c
index f679c1d..862fba9 100644
--- a/framework/private/src/utils.c
+++ b/framework/private/src/utils.c
@@ -103,3 +103,18 @@ celix_status_t utils_isNumeric(char *number, bool *ret) {
}
return status;
}
+
+
+FRAMEWORK_EXPORT int utils_compareServiceIdsAndRanking(long servId, long servRank, long otherServId, long otherServRank) {
+ int result;
+
+ if (servId == otherServId) {
+ result = 0;
+ } else if (servRank != otherServRank) {
+ result = servRank < otherServRank ? -1 : 1;
+ } else { //equal service rank, compare service ids
+ result = servId < otherServId ? 1 : -1;
+ }
+
+ return result;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/framework/public/include/utils.h
----------------------------------------------------------------------
diff --git a/framework/public/include/utils.h b/framework/public/include/utils.h
index 090daec..19788d3 100644
--- a/framework/public/include/utils.h
+++ b/framework/public/include/utils.h
@@ -39,6 +39,8 @@ FRAMEWORK_EXPORT int utils_stringEquals(void * string, void * toCompare);
FRAMEWORK_EXPORT char * string_ndup(const char *s, size_t n);
FRAMEWORK_EXPORT char * utils_stringTrim(char * string);
+FRAMEWORK_EXPORT int utils_compareServiceIdsAndRanking(long servId, long servRank, long otherServId, long otherServRank);
+
FRAMEWORK_EXPORT celix_status_t thread_equalsSelf(celix_thread_t thread, bool *equals);
FRAMEWORK_EXPORT celix_status_t utils_isNumeric(char *number, bool *ret);
[10/21] celix git commit: CELIX-210: Fixed an issue that state update
when to for a a instiated_waiting_for_required state. Added state info to dm
shell command
Posted by pn...@apache.org.
CELIX-210: Fixed an issue that state update when to for a a instiated_waiting_for_required state. Added state info to dm shell command
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/8f279cbc
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/8f279cbc
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/8f279cbc
Branch: refs/heads/develop
Commit: 8f279cbcfdc17119bade662b2a22e3beda7fb639
Parents: 664845c
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Oct 22 20:30:32 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Oct 22 20:30:32 2015 +0200
----------------------------------------------------------------------
.../private/include/dm_component_impl.h | 10 ++---
.../private/src/dm_component_impl.c | 45 ++++++++++++++------
.../private/src/dm_shell_list_command.c | 4 +-
dependency_manager/public/include/dm_info.h | 1 +
.../tracker_depman/private/src/tracker.c | 6 +--
5 files changed, 45 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/8f279cbc/dependency_manager/private/include/dm_component_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_component_impl.h b/dependency_manager/private/include/dm_component_impl.h
index 3e86d62..42857d2 100644
--- a/dependency_manager/private/include/dm_component_impl.h
+++ b/dependency_manager/private/include/dm_component_impl.h
@@ -35,10 +35,10 @@
typedef enum dm_component_state {
DM_CMP_STATE_INACTIVE = 1,
- DM_CMP_STATE_WAITING_FOR_REQUIRED,
- DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED,
- DM_CMP_STATE_TRACKING_OPTIONAL,
-} dm_component_state_pt;
+ DM_CMP_STATE_WAITING_FOR_REQUIRED = 2,
+ DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED = 3,
+ DM_CMP_STATE_TRACKING_OPTIONAL = 4,
+} dm_component_state_t;
typedef struct dm_executor * dm_executor_pt;
@@ -64,7 +64,7 @@ struct dm_component {
array_list_pt dependencies;
pthread_mutex_t mutex;
- dm_component_state_pt state;
+ dm_component_state_t state;
bool isStarted;
bool active;
http://git-wip-us.apache.org/repos/asf/celix/blob/8f279cbc/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index 9b8ee54..5aeae6b 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -77,8 +77,8 @@ static celix_status_t component_invokeAutoConfigDependencies(dm_component_pt com
static celix_status_t component_configureImplementation(dm_component_pt component, dm_service_dependency_pt dependency);
static celix_status_t component_allInstanceBoundAvailable(dm_component_pt component, bool *available);
static celix_status_t component_allRequiredAvailable(dm_component_pt component, bool *available);
-static celix_status_t component_performTransition(dm_component_pt component, dm_component_state_pt oldState, dm_component_state_pt newState, bool *transition);
-static celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_pt currentState, dm_component_state_pt *newState);
+static celix_status_t component_performTransition(dm_component_pt component, dm_component_state_t oldState, dm_component_state_t newState, bool *transition);
+static celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_t currentState, dm_component_state_t *newState);
static celix_status_t component_handleChange(dm_component_pt component);
static celix_status_t component_startDependencies(dm_component_pt component __attribute__((unused)), array_list_pt dependencies);
static celix_status_t component_getDependencyEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt *event_pptr);
@@ -645,21 +645,21 @@ celix_status_t component_stopDependencies(dm_component_pt component) {
celix_status_t component_handleChange(dm_component_pt component) {
celix_status_t status = CELIX_SUCCESS;
- dm_component_state_pt oldState;
- dm_component_state_pt newState;
+ dm_component_state_t oldState;
+ dm_component_state_t newState;
- bool cont = false;
+ bool transition = false;
do {
oldState = component->state;
component_calculateNewState(component, oldState, &newState);
component->state = newState;
- component_performTransition(component, oldState, newState, &cont);
- } while (cont);
+ component_performTransition(component, oldState, newState, &transition);
+ } while (transition);
return status;
}
-celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_pt currentState, dm_component_state_pt *newState) {
+celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_t currentState, dm_component_state_t *newState) {
celix_status_t status = CELIX_SUCCESS;
if (currentState == DM_CMP_STATE_INACTIVE) {
@@ -698,7 +698,9 @@ celix_status_t component_calculateNewState(dm_component_pt component, dm_compone
*newState = currentState;
return status;
}
- *newState = DM_CMP_STATE_WAITING_FOR_REQUIRED;
+
+ *newState = component->isStarted ? DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED :
+ DM_CMP_STATE_WAITING_FOR_REQUIRED;
return status;
}
if (currentState == DM_CMP_STATE_TRACKING_OPTIONAL) {
@@ -722,8 +724,9 @@ celix_status_t component_calculateNewState(dm_component_pt component, dm_compone
return status;
}
-celix_status_t component_performTransition(dm_component_pt component, dm_component_state_pt oldState, dm_component_state_pt newState, bool *transition) {
+celix_status_t component_performTransition(dm_component_pt component, dm_component_state_t oldState, dm_component_state_t newState, bool *transition) {
celix_status_t status = CELIX_SUCCESS;
+ printf("performing transition from %i to %i\n", oldState, newState);
if (oldState == DM_CMP_STATE_INACTIVE && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
component_startDependencies(component, component->dependencies);
@@ -738,7 +741,7 @@ celix_status_t component_performTransition(dm_component_pt component, dm_compone
// component_instantiateComponent(component);
component_invokeAddRequiredDependencies(component);
component_invokeAutoConfigDependencies(component);
- dm_component_state_pt stateBeforeCallingInit = component->state;
+ dm_component_state_t stateBeforeCallingInit = component->state;
if (component->callbackInit) {
component->callbackInit(component->implementation);
}
@@ -1318,8 +1321,26 @@ celix_status_t component_getComponentInfo(dm_component_pt component, dm_componen
if (info != NULL) {
arrayList_create(&info->dependency_list);
component_getInterfaces(component, &info->interfaces);
- info->active = component->active;
+ info->active = false;
info->id = strdup(component->id);
+ switch (component->state) {
+ case DM_CMP_STATE_INACTIVE :
+ info->state = strdup("INACTIVE");
+ break;
+ case DM_CMP_STATE_WAITING_FOR_REQUIRED :
+ info->state = strdup("WAITING_FOR_REQUIRED");
+ break;
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED :
+ info->state = strdup("INSTANTIATED_AND_WAITING_FOR_REQUIRED");
+ break;
+ case DM_CMP_STATE_TRACKING_OPTIONAL :
+ info->state = strdup("TRACKING_OPTIONAL");
+ info->active = true;
+ break;
+ default :
+ info->state = strdup("UNKNOWN");
+ break;
+ }
} else {
status = CELIX_ENOMEM;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/8f279cbc/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
index 3c2c43d..59f748f 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -76,7 +76,7 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
startColors = compInfo->active ? "\033[92m" : "\033[91m";
endColors = "\033[m";
}
- sprintf(outString, "Component: ID=%s, %sActive=%s%s\n", compInfo->id, startColors, compInfo->active ? "true " : "false", endColors);
+ sprintf(outString, "Component: ID=%s, %sActive=%s%s, State=%s\n", compInfo->id, startColors, compInfo->active ? "true " : "false", endColors, compInfo->state);
out(outString);
int interfCnt;
@@ -114,6 +114,8 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
free(dependency->filter);
free(dependency);
}
+
+ //TODO free compInfo
arrayList_destroy(compInfo->dependency_list);
}
}
http://git-wip-us.apache.org/repos/asf/celix/blob/8f279cbc/dependency_manager/public/include/dm_info.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_info.h b/dependency_manager/public/include/dm_info.h
index f010387..ee6a4d8 100644
--- a/dependency_manager/public/include/dm_info.h
+++ b/dependency_manager/public/include/dm_info.h
@@ -42,6 +42,7 @@ typedef struct dm_service_dependency_info {
typedef struct dm_component_info {
char *id;
bool active;
+ char * state;
array_list_pt interfaces; // type char*
array_list_pt dependency_list; // type interface_info_pt
} * dm_component_info_pt;
http://git-wip-us.apache.org/repos/asf/celix/blob/8f279cbc/examples/whiteboard/tracker_depman/private/src/tracker.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/tracker.c b/examples/whiteboard/tracker_depman/private/src/tracker.c
index 0ada638..5688810 100644
--- a/examples/whiteboard/tracker_depman/private/src/tracker.c
+++ b/examples/whiteboard/tracker_depman/private/src/tracker.c
@@ -62,7 +62,7 @@ celix_status_t service_init(void * userData) {
celix_status_t service_start(void * userData) {
struct data * data = (struct data *) userData;
- fprintf(stderr, "Service started");
+ fprintf(stderr, "Service started\n");
data->running = true;
pthread_create(&data->sender, NULL, dp_send, data);
return CELIX_SUCCESS;
@@ -70,14 +70,14 @@ celix_status_t service_start(void * userData) {
celix_status_t service_stop(void * userData) {
struct data * data = (struct data *) userData;
- fprintf(stderr, "Service stopped");
+ fprintf(stderr, "Service stopped\n");
data->running = false;
pthread_join(data->sender, NULL);
return CELIX_SUCCESS;
}
celix_status_t service_deinit(void * userData) {
- fprintf(stderr, "Service deinit");
+ fprintf(stderr, "Service deinit\n");
return CELIX_SUCCESS;
}
[07/21] celix git commit: CELIX-210: Added licence headers to source
files.
Posted by pn...@apache.org.
CELIX-210: Added licence headers to source files.
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/b12c40ff
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/b12c40ff
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/b12c40ff
Branch: refs/heads/develop
Commit: b12c40ff2cd93163e3cd6a93af8c799d6f2d7f44
Parents: b2ed188
Author: Erjan Altena <er...@nl.thalesgroup.com>
Authored: Fri Oct 16 16:44:27 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Oct 19 20:45:03 2015 +0200
----------------------------------------------------------------------
dependency_manager/public/include/dm_server.h | 26 +++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/b12c40ff/dependency_manager/public/include/dm_server.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_server.h b/dependency_manager/public/include/dm_server.h
index fa8da78..15c87d5 100644
--- a/dependency_manager/public/include/dm_server.h
+++ b/dependency_manager/public/include/dm_server.h
@@ -1,4 +1,28 @@
-
+/**
+ *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.
+ */
+/*
+ * dm_server.h
+ *
+ * \date 15 Oct 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
#ifndef CELIX_DM_SERVICE_H
#define CELIX_DM_SERVICE_H
[08/21] celix git commit: CELIX-210: Fixed typo
Posted by pn...@apache.org.
CELIX-210: Fixed typo
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/01c19680
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/01c19680
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/01c19680
Branch: refs/heads/develop
Commit: 01c19680a2a3dfdf65c9c10a2edc4d6491fc93cb
Parents: b12c40f
Author: Erjan Altena <er...@nl.thalesgroup.com>
Authored: Fri Oct 16 16:51:00 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Oct 19 20:45:08 2015 +0200
----------------------------------------------------------------------
dependency_manager/private/src/dm_component_impl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/01c19680/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index bac73eb..801d426 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -120,7 +120,7 @@ celix_status_t component_create(bundle_context_pt context, dm_dependency_manager
(*component)->state = DM_CMP_STATE_INACTIVE;
(*component)->isStarted = false;
- (*component)->active = a;
+ (*component)->active = false;
(*component)->dependencyEvents = hashMap_create(NULL, NULL, NULL, NULL);
[05/21] celix git commit: CELIX-210: Added Set fucntion to dependency
manager and added bundle with shell command to get overview of the
depenency-manages components
Posted by pn...@apache.org.
CELIX-210: Added Set fucntion to dependency manager and added bundle with shell command to get overview of the depenency-manages components
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/9203fddd
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/9203fddd
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/9203fddd
Branch: refs/heads/develop
Commit: 9203fdddd03ebc787544863841069e621bdf7edb
Parents: cc6fd43
Author: Erjan Altena <er...@nl.thalesgroup.com>
Authored: Fri Oct 16 14:09:42 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Oct 19 20:44:30 2015 +0200
----------------------------------------------------------------------
dependency_manager/CMakeLists.txt | 18 +++-
.../private/include/dm_component_impl.h | 2 +-
.../include/dm_dependency_manager_impl.h | 11 ++
.../private/include/dm_server_impl.h | 10 ++
.../include/dm_service_dependency_impl.h | 3 +
.../private/include/dm_shell_list_command.h | 34 +++++++
.../private/src/dm_activator_base.c | 20 +++-
.../private/src/dm_component_impl.c | 19 +++-
.../private/src/dm_dependency_manager_impl.c | 6 +-
dependency_manager/private/src/dm_server.c | 71 +++++++++++++
.../private/src/dm_service_dependency.c | 66 +++++++++++-
.../private/src/dm_shell_activator.c | 72 +++++++++++++
.../private/src/dm_shell_list_command.c | 101 +++++++++++++++++++
.../public/include/dm_component.h | 4 +-
dependency_manager/public/include/dm_server.h | 36 +++++++
.../public/include/dm_service_dependency.h | 6 +-
examples/deploy.cmake | 2 +-
.../publisherA/private/src/activator.c | 2 +
.../publisherB/private/src/activator.c | 2 +
.../tracker_depman/private/include/tracker.h | 4 +-
.../private/src/dependency_activator.c | 18 ++--
.../tracker_depman/private/src/tracker.c | 27 ++++-
22 files changed, 496 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dependency_manager/CMakeLists.txt b/dependency_manager/CMakeLists.txt
index 6b76658..931dd3c 100644
--- a/dependency_manager/CMakeLists.txt
+++ b/dependency_manager/CMakeLists.txt
@@ -16,7 +16,10 @@
# under the License.
celix_subproject(DEPENDENCY_MANAGER "Option to build the dependency manager static library" ON DEPS framework)
-if (DEPENDENCY_MANAGER)
+if (DEPENDENCY_MANAGER)
+ SET(BUNDLE_SYMBOLICNAME "apache_celix_dm_shell")
+ SET(BUNDLE_VERSION "0.0.1")
+ SET(BUNDLE_NAME "Apache Celix DM Shell commands")
# Add -fPIC for x86_64 Unix platforms; this lib will be linked to a shared lib
if(UNIX AND NOT WIN32)
find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
@@ -34,15 +37,22 @@ if (DEPENDENCY_MANAGER)
DESCRIPTION "The Apache Celix dependency manager (static) library"
GROUP all
)
-
+ bundle(dm_shell SOURCES
+ private/src/dm_shell_activator
+ private/src/dm_shell_list_command
+ )
add_library(dependency_manager STATIC
private/src/dm_activator_base
private/src/dm_component_impl
private/src/dm_service_dependency
private/src/dm_event
- private/src/dm_dependency_manager_impl)
+ private/src/dm_dependency_manager_impl
+ private/src/dm_server
+ )
+
include_directories("public/include")
include_directories("private/include")
+ include_directories("../shell/public/include")
include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
target_link_libraries(dependency_manager celix_framework)
@@ -52,10 +62,12 @@ if (DEPENDENCY_MANAGER)
public/include/dm_component.h
public/include/dm_dependency_manager.h
public/include/dm_service_dependency.h
+ public/include/dm_server.h
DESTINATION
include/celix/dependency_manager
COMPONENT
dependency_manager
)
+ install_bundle(dm_shell)
install(TARGETS dependency_manager DESTINATION lib COMPONENT dependency_manager)
endif (DEPENDENCY_MANAGER)
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/include/dm_component_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_component_impl.h b/dependency_manager/private/include/dm_component_impl.h
index 133ef06..ad742b8 100644
--- a/dependency_manager/private/include/dm_component_impl.h
+++ b/dependency_manager/private/include/dm_component_impl.h
@@ -60,7 +60,7 @@ struct dm_component {
init_fpt callbackInit;
start_fpt callbackStart;
stop_fpt callbackStop;
- destroy_fpt callbackDestroy;
+ deinit_fpt callbackDeinit;
array_list_pt dependencies;
pthread_mutex_t mutex;
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/include/dm_dependency_manager_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_dependency_manager_impl.h b/dependency_manager/private/include/dm_dependency_manager_impl.h
new file mode 100644
index 0000000..8a0cae8
--- /dev/null
+++ b/dependency_manager/private/include/dm_dependency_manager_impl.h
@@ -0,0 +1,11 @@
+
+#ifndef CELIX_DM_DEPENDENCY_MANAGER_IMPL_H
+#define CELIX_DM_DEPENDENCY_MANAGER_IMPL_H
+
+struct dm_dependency_manager {
+ array_list_pt components;
+
+ pthread_mutex_t mutex;
+};
+
+#endif //CELIX_DM_DEPENDENCY_MANAGER_IMPL_H
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/include/dm_server_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_server_impl.h b/dependency_manager/private/include/dm_server_impl.h
new file mode 100644
index 0000000..f54aece
--- /dev/null
+++ b/dependency_manager/private/include/dm_server_impl.h
@@ -0,0 +1,10 @@
+#include "dm_server.h"
+#include "dm_component.h"
+#include "dm_component_impl.h"
+#include "dm_dependency_manager_impl.h"
+
+celix_status_t dmServiceCreate(dm_server_pt * dmServ, bundle_context_pt context, struct dm_dependency_manager *manager);
+celix_status_t dmServiceAddComponent(dm_server_pt dmServ, dm_component_pt component);
+celix_status_t dmServiceDestroy(dm_server_pt dmServ);
+celix_status_t dmService_getInfo(dm_server_pt dmServ, dm_info_pt info);
+
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/include/dm_service_dependency_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_service_dependency_impl.h b/dependency_manager/private/include/dm_service_dependency_impl.h
index 1396f31..0f80cef 100644
--- a/dependency_manager/private/include/dm_service_dependency_impl.h
+++ b/dependency_manager/private/include/dm_service_dependency_impl.h
@@ -41,11 +41,13 @@ struct dm_service_dependency {
bool instanceBound;
bool required;
+ service_set_fpt set;
service_add_fpt add;
service_change_fpt change;
service_remove_fpt remove;
service_swap_fpt swap;
+ service_set_with_ref_fpt set_with_ref;
service_add_with_ref_fpt add_with_ref;
service_change_with_ref_fpt change_with_ref;
service_remove_with_ref_fpt remove_with_ref;
@@ -73,6 +75,7 @@ celix_status_t serviceDependency_setAvailable(dm_service_dependency_pt dependenc
celix_status_t serviceDependency_setComponent(dm_service_dependency_pt dependency, dm_component_pt component);
//celix_status_t serviceDependency_removeComponent(dm_service_dependency_pt dependency, dm_component_pt component);
+celix_status_t serviceDependency_invokeSet(dm_service_dependency_pt dependency, dm_event_pt event);
celix_status_t serviceDependency_invokeAdd(dm_service_dependency_pt dependency, dm_event_pt event);
celix_status_t serviceDependency_invokeChange(dm_service_dependency_pt dependency, dm_event_pt event);
celix_status_t serviceDependency_invokeRemove(dm_service_dependency_pt dependency, dm_event_pt event);
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/include/dm_shell_list_command.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_shell_list_command.h b/dependency_manager/private/include/dm_shell_list_command.h
new file mode 100644
index 0000000..28482e0
--- /dev/null
+++ b/dependency_manager/private/include/dm_shell_list_command.h
@@ -0,0 +1,34 @@
+/**
+ *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.
+ */
+/*
+ * help_command.c
+ *
+ * \date Aug 20, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#include "command_impl.h"
+
+char * dmListCommand_getName(command_pt command);
+char * dmListCommand_getUsage(command_pt command);
+char * dmListCommand_getShortDescription(command_pt command);
+void dmListCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *));
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/src/dm_activator_base.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_activator_base.c b/dependency_manager/private/src/dm_activator_base.c
index a97194e..1c00ab1 100644
--- a/dependency_manager/private/src/dm_activator_base.c
+++ b/dependency_manager/private/src/dm_activator_base.c
@@ -30,11 +30,14 @@
#include "bundle_activator.h"
#include "dm_activator_base.h"
-
+#include "dm_server.h"
+#include "dm_server_impl.h"
struct dm_dependency_activator_base {
dm_dependency_manager_pt manager;
bundle_context_pt context;
+ dm_service_pt dmService;
+ service_registration_pt reg;
void* userData;
};
@@ -67,6 +70,11 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
dm_init(dependency_activator->userData, context, dependency_activator->manager);
}
+ //Create the service
+ dependency_activator->dmService = calloc(sizeof(*(dependency_activator->dmService)), 1);
+ dependency_activator->dmService->getInfo = dmService_getInfo;
+ dmServiceCreate(&(dependency_activator->dmService->server), context, dependency_activator->manager);
+ bundleContext_registerService(context, DM_SERVICE_NAME, dependency_activator->dmService, NULL, &(dependency_activator->reg));
return status;
}
@@ -74,12 +82,18 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context _
celix_status_t status = CELIX_SUCCESS;
dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
- dm_deinit(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
+ dm_destroy(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
dependencyManager_destroy(&dependency_activator->manager);
+ // Remove the service
+ serviceRegistration_unregister(dependency_activator->reg);
+ dmServiceDestroy(dependency_activator->dmService->server);
+ free(dependency_activator->dmService);
+
dependency_activator->userData = NULL;
dependency_activator->manager = NULL;
+ dependency_activator->dmService = NULL;
return status;
}
@@ -88,8 +102,6 @@ celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt contex
celix_status_t status = CELIX_SUCCESS;
dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
- dm_destroy(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
-
free(dependency_activator);
return status;
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index 72fe7eb..801d426 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -27,7 +27,10 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
+#include "constants.h"
+#include "filter.h"
#include "dm_component_impl.h"
#include "../../../framework/private/include/framework_private.h"
@@ -109,7 +112,7 @@ celix_status_t component_create(bundle_context_pt context, dm_dependency_manager
(*component)->callbackInit = NULL;
(*component)->callbackStart = NULL;
(*component)->callbackStop = NULL;
- (*component)->callbackDestroy = NULL;
+ (*component)->callbackDeinit = NULL;
arrayList_create(&(*component)->dependencies);
@@ -362,6 +365,7 @@ celix_status_t component_handleAdded(dm_component_pt component, dm_service_depen
serviceDependency_setAvailable(dependency, true);
+ serviceDependency_invokeSet(dependency, event);
switch (component->state) {
case DM_CMP_STATE_WAITING_FOR_REQUIRED: {
bool required = false;
@@ -418,6 +422,7 @@ celix_status_t component_handleChanged(dm_component_pt component, dm_service_dep
arrayList_add(events, event);
pthread_mutex_unlock(&component->mutex);
+ serviceDependency_invokeSet(dependency, event);
switch (component->state) {
case DM_CMP_STATE_TRACKING_OPTIONAL:
serviceDependency_invokeChange(dependency, event);
@@ -467,6 +472,8 @@ celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dep
dm_event_pt old = arrayList_remove(events, (unsigned int) index);
pthread_mutex_unlock(&component->mutex);
+ serviceDependency_invokeSet(dependency, event);
+
switch (component->state) {
case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
bool instanceBound = false;
@@ -515,6 +522,8 @@ celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dep
arrayList_add(events, newEvent);
pthread_mutex_unlock(&component->mutex);
+ serviceDependency_invokeSet(dependency, event);
+
switch (component->state) {
case DM_CMP_STATE_WAITING_FOR_REQUIRED:
break;
@@ -746,8 +755,8 @@ celix_status_t component_performTransition(dm_component_pt component, dm_compone
}
if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
- if (component->callbackDestroy) {
- component->callbackDestroy(component->implementation);
+ if (component->callbackDeinit) {
+ component->callbackDeinit(component->implementation);
}
component_invokeRemoveRequiredDependencies(component);
// #TODO Add listener support
@@ -1119,14 +1128,14 @@ celix_status_t component_unregisterService(dm_component_pt component) {
return status;
}
-celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt stop, destroy_fpt destroy) {
+celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt stop, deinit_fpt deinit) {
if (component->active) {
return CELIX_ILLEGAL_STATE;
}
component->callbackInit = init;
component->callbackStart = start;
component->callbackStop = stop;
- component->callbackDestroy = destroy;
+ component->callbackDeinit = deinit;
return CELIX_SUCCESS;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/src/dm_dependency_manager_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_dependency_manager_impl.c b/dependency_manager/private/src/dm_dependency_manager_impl.c
index 28b49e9..265ecf0 100644
--- a/dependency_manager/private/src/dm_dependency_manager_impl.c
+++ b/dependency_manager/private/src/dm_dependency_manager_impl.c
@@ -31,12 +31,8 @@
#include "bundle_context.h"
#include "dm_component_impl.h"
+#include "dm_dependency_manager_impl.h"
-struct dm_dependency_manager {
- array_list_pt components;
-
- pthread_mutex_t mutex;
-};
celix_status_t dependencyManager_create(bundle_context_pt context __attribute__((unused)), dm_dependency_manager_pt *manager) {
celix_status_t status = CELIX_ENOMEM;
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/src/dm_server.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_server.c b/dependency_manager/private/src/dm_server.c
new file mode 100644
index 0000000..7f86d8d
--- /dev/null
+++ b/dependency_manager/private/src/dm_server.c
@@ -0,0 +1,71 @@
+#include <stdlib.h>
+
+#include "array_list.h"
+
+#include "dm_server.h"
+#include "dm_component.h"
+#include "dm_component_impl.h"
+#include "dm_dependency_manager_impl.h"
+
+struct dm_server {
+ struct dm_dependency_manager *manager;
+};
+
+celix_status_t dmServiceCreate(dm_server_pt * dmServ, bundle_context_pt context, struct dm_dependency_manager *manager) {
+ *dmServ = calloc(sizeof(struct dm_server), 1);
+ (*dmServ)->manager = manager;
+ return CELIX_SUCCESS;
+}
+
+celix_status_t dmServiceDestroy(dm_server_pt dmServ) {
+ free(dmServ);
+ return CELIX_SUCCESS;
+}
+
+celix_status_t dmService_getInfo(dm_server_pt dmServ, dm_info_pt info) {
+ int compCnt;
+ arrayList_create(&(info->components));
+ array_list_pt compList = dmServ->manager->components;
+
+ for (compCnt = 0; compCnt < arrayList_size(compList); compCnt++) {
+ int i;
+ struct dm_component *component = arrayList_get(compList, compCnt);
+
+ // Create a component info
+ dm_component_info_pt compInfo = calloc(sizeof(*compInfo),1);
+ arrayList_create(&(compInfo->interface_list));
+ arrayList_create(&(compInfo->dependency_list));
+
+ //Fill in the fields of the component
+ char *outstr;
+ asprintf(&outstr, "%p",component->implementation);
+ compInfo->id = outstr;
+ compInfo->active = component->active;
+
+ array_list_pt interfaces = component->dm_interface;
+ array_list_pt dependencies = component->dependencies;
+
+ for(i = 0; i < arrayList_size(interfaces); i++) {
+ dm_interface * interface = arrayList_get(interfaces, i);
+ arrayList_add(compInfo->interface_list, strdup(interface->serviceName));
+ }
+
+ for(i = 0; i < arrayList_size(dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(dependencies, i);
+
+ dependency_info_pt depInfo = calloc(sizeof(*depInfo), 1);
+ depInfo->available = dependency->available;
+ depInfo->required = dependency->required;
+ if(dependency->tracked_filter) {
+ depInfo->interface = strdup(dependency->tracked_filter);
+ } else {
+ depInfo->interface = strdup(dependency->tracked_service_name);
+ }
+ arrayList_add(compInfo->dependency_list, depInfo);
+ }
+
+ arrayList_add(info->components, compInfo);
+ }
+
+ return CELIX_SUCCESS;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_service_dependency.c b/dependency_manager/private/src/dm_service_dependency.c
index 8f65ddb..f89dc94 100644
--- a/dependency_manager/private/src/dm_service_dependency.c
+++ b/dependency_manager/private/src/dm_service_dependency.c
@@ -27,12 +27,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include "constants.h"
#include "dm_service_dependency_impl.h"
#include "dm_component_impl.h"
+#define DEFAULT_RANKING 0
+
static celix_status_t serviceDependency_addedService(void *_ptr, service_reference_pt reference, void *service);
static celix_status_t serviceDependency_modifiedService(void *_ptr, service_reference_pt reference, void *service);
static celix_status_t serviceDependency_removedService(void *_ptr, service_reference_pt reference, void *service);
@@ -49,6 +52,7 @@ celix_status_t serviceDependency_create(dm_service_dependency_pt *dependency_ptr
(*dependency_ptr)->instanceBound = false;
(*dependency_ptr)->required = false;
+ (*dependency_ptr)->set = NULL;
(*dependency_ptr)->add = NULL;
(*dependency_ptr)->change = NULL;
(*dependency_ptr)->remove = NULL;
@@ -146,7 +150,7 @@ celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency,
return status;
}
-celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap) {
+celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_set_fpt set, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap) {
celix_status_t status = CELIX_SUCCESS;
if (!dependency) {
@@ -154,6 +158,7 @@ celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependenc
}
if (status == CELIX_SUCCESS) {
+ dependency->set = set;
dependency->add = add;
dependency->change = change;
dependency->remove = remove;
@@ -163,7 +168,7 @@ celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependenc
return status;
}
-celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap) {
+celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_set_with_ref_fpt set, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap) {
celix_status_t status = CELIX_SUCCESS;
if (!dependency) {
@@ -171,6 +176,7 @@ celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dep
}
if (status == CELIX_SUCCESS) {
+ dependency->set_with_ref = set;
dependency->add_with_ref = add;
dependency->change_with_ref = change;
dependency->remove_with_ref = remove;
@@ -308,6 +314,62 @@ celix_status_t serviceDependency_setAvailable(dm_service_dependency_pt dependenc
return status;
}
+celix_status_t serviceDependency_invokeSet(dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+ array_list_pt serviceReferences = NULL;
+ int i;
+ int curRanking = INT_MIN;
+ service_reference_pt curServRef = NULL;
+ void *service = NULL;
+
+ serviceReferences = serviceTracker_getServiceReferences(dependency->tracker);
+
+ fprintf(stderr,"found %d servicereferences\n",arrayList_size(serviceReferences));
+ /* Find the service with the higest ranking */
+ for (i = 0; i < arrayList_size(serviceReferences); i++) {
+ service_reference_pt serviceReference = arrayList_get(serviceReferences, i);
+ char *ranking_value;
+ int ranking = 0;
+
+ status = serviceReference_getProperty(serviceReference, ((char *)OSGI_FRAMEWORK_SERVICE_RANKING), &ranking_value);
+
+ if(status == CELIX_SUCCESS) {
+ if (ranking_value == NULL) {
+ ranking = DEFAULT_RANKING;
+ } else {
+ char *end;
+ ranking = strtol(ranking_value, &end, 10);
+ if( end == ranking_value) {
+ ranking = DEFAULT_RANKING;
+ }
+ }
+
+ if (ranking > curRanking) {
+ curRanking = ranking;
+ curServRef = serviceReference;
+ }
+ } else {
+ return status;
+ }
+ }
+
+ if (curServRef) {
+ status = bundleContext_getService(event->context, curServRef, &service);
+ } else {
+ service = NULL;
+ }
+
+ fprintf(stderr, "Ranking found: %d service %p\n", curRanking, service);
+
+ if (dependency->set) {
+ dependency->set(dependency->component->implementation, service);
+ }
+ if (dependency->set_with_ref) {
+ dependency->set_with_ref(dependency->component->implementation, curServRef, service);
+ }
+
+ return status;
+}
celix_status_t serviceDependency_invokeAdd(dm_service_dependency_pt dependency, dm_event_pt event) {
celix_status_t status = CELIX_SUCCESS;
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/src/dm_shell_activator.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_activator.c b/dependency_manager/private/src/dm_shell_activator.c
new file mode 100644
index 0000000..28b4784
--- /dev/null
+++ b/dependency_manager/private/src/dm_shell_activator.c
@@ -0,0 +1,72 @@
+#include "bundle_context.h"
+#include "service_registration.h"
+#include "command.h"
+
+#include "dm_shell_list_command.h"
+
+struct bundle_instance {
+ service_registration_pt reg;
+ command_pt dmListCmd;
+};
+
+typedef struct bundle_instance * bundle_instance_pt;
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+
+ struct bundle_instance *bi = calloc(sizeof (struct bundle_instance), 1);
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!bi) {
+ status = CELIX_ENOMEM;
+ }
+ else if (userData == NULL) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ free(bi);
+ }
+ else {
+ if (status != CELIX_SUCCESS) {
+ printf("DM:LIST Create failed\n");
+ free(bi);
+ }
+
+ (*userData) = bi;
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status = CELIX_SUCCESS;
+ bundle_instance_pt bi = (bundle_instance_pt) userData;
+ command_service_pt commandService = calloc(1, sizeof(*commandService));
+
+ command_pt command = calloc(sizeof(*command),1);
+ command->executeCommand = dmListCommand_execute;
+ command->bundleContext = context;
+ command->handle = NULL;
+ command->name ="dm:list";
+ command->shortDescription ="not_used";
+ command->usage="not_used";
+
+ commandService->getName = dmListCommand_getName;
+ commandService->command = command;
+ commandService->executeCommand = dmListCommand_execute;
+ commandService->getShortDescription = dmListCommand_getShortDescription;
+ commandService->getUsage = dmListCommand_getUsage;
+
+ bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, commandService, NULL, &bi->reg);
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+ bundle_instance_pt bi = (bundle_instance_pt) userData;
+ serviceRegistration_unregister(bi->reg);
+ return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+ free(userData);
+ return CELIX_SUCCESS;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
new file mode 100644
index 0000000..06e5968
--- /dev/null
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -0,0 +1,101 @@
+/**
+ *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.
+ */
+/*
+ * help_command.c
+ *
+ * \date Aug 20, 2010
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <string.h>
+#include "dm_server.h"
+#include "service_reference.h"
+#include "command_impl.h"
+#include "array_list.h"
+#include "bundle_context.h"
+#include "bundle.h"
+#include "shell.h"
+
+
+void dmListCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *));
+
+
+char * dmListCommand_getName(command_pt command) {
+ return "dm:list";
+}
+
+char * dmListCommand_getUsage(command_pt command) {
+ return "dm:list";
+}
+
+char * dmListCommand_getShortDescription(command_pt command) {
+ return "Get an overview of the dependency-managed components with their dependencies.";
+}
+
+void dmListCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *)) {
+ char outString[256];
+ array_list_pt servRefs = NULL;
+ int i;
+ bundleContext_getServiceReferences(command->bundleContext, DM_SERVICE_NAME ,NULL, &servRefs);
+
+ for(i = 0; i < arrayList_size(servRefs); i++) {
+ struct dm_info info;
+ dm_service_pt dmService = NULL;
+ service_reference_pt servRef = NULL;
+ servRef = arrayList_get(servRefs, i);
+ bundleContext_getService(command->bundleContext, servRef, (void**)&dmService);
+ dmService->getInfo(dmService->server, &info);
+
+ int cmpCnt;
+ for (cmpCnt = 0; cmpCnt < arrayList_size(info.components); cmpCnt++) {
+ dm_component_info_pt compInfo = arrayList_get(info.components, cmpCnt);
+ sprintf(outString, "Component: ID=%s, Active=%s\n", compInfo->id, compInfo->active ? "true" : "false");
+ out(outString);
+
+ int interfCnt;
+ sprintf(outString, " Interfaces (%d):\n", arrayList_size(compInfo->interface_list));
+ out(outString);
+ for(interfCnt = 0 ;interfCnt < arrayList_size(compInfo->interface_list); interfCnt++) {
+ char * interface;
+ interface = arrayList_get(compInfo->interface_list, interfCnt);
+ sprintf(outString, " Interface: %s\n", interface);
+ out(outString);
+ free(interface);
+ }
+ arrayList_destroy(compInfo->interface_list);
+
+ int depCnt;
+ sprintf(outString, " Dependencies (%d):\n", arrayList_size(compInfo->dependency_list));
+ out(outString);
+ for(depCnt = 0 ;depCnt < arrayList_size(compInfo->dependency_list); depCnt++) {
+ dependency_info_pt dependency;
+ dependency = arrayList_get(compInfo->dependency_list, depCnt);
+ sprintf(outString, " Dependency: Available = %s, Required = %s, Filter = %s\n",
+ dependency->available? "true" : "false" ,
+ dependency->required ? "true" : "false",
+ dependency->interface);
+ out(outString);
+ free(dependency->interface);
+ free(dependency);
+ }
+ arrayList_destroy(compInfo->dependency_list);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/public/include/dm_component.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_component.h b/dependency_manager/public/include/dm_component.h
index f98c3bb..6b875b2 100644
--- a/dependency_manager/public/include/dm_component.h
+++ b/dependency_manager/public/include/dm_component.h
@@ -38,7 +38,7 @@ typedef struct dm_component *dm_component_pt;
typedef celix_status_t (*init_fpt)(void *userData);
typedef celix_status_t (*start_fpt)(void *userData);
typedef celix_status_t (*stop_fpt)(void *userData);
-typedef celix_status_t (*destroy_fpt)(void *userData);
+typedef celix_status_t (*deinit_fpt)(void *userData);
celix_status_t component_create(bundle_context_pt context, dm_dependency_manager_pt manager, dm_component_pt *component);
celix_status_t component_destroy(dm_component_pt *component);
@@ -49,6 +49,6 @@ celix_status_t component_setImplementation(dm_component_pt component, void *impl
celix_status_t component_addServiceDependency(dm_component_pt component, ...);
celix_status_t component_removeServiceDependency(dm_component_pt component, dm_service_dependency_pt dependency);
-celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt, destroy_fpt);
+celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt stop, deinit_fpt deinit);
#endif /* COMPONENT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/public/include/dm_server.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_server.h b/dependency_manager/public/include/dm_server.h
new file mode 100644
index 0000000..fa8da78
--- /dev/null
+++ b/dependency_manager/public/include/dm_server.h
@@ -0,0 +1,36 @@
+
+#ifndef CELIX_DM_SERVICE_H
+#define CELIX_DM_SERVICE_H
+
+#include "bundle_context.h"
+
+#define DM_SERVICE_NAME "dm_server"
+
+typedef struct dm_server * dm_server_pt;
+
+typedef struct dependency_info {
+ char *interface;
+ bool available;
+ bool required;
+} * dependency_info_pt;
+
+typedef struct dm_component_info {
+ char *id;
+ bool active;
+ array_list_pt interface_list; // type char*
+ array_list_pt dependency_list; // type interface_info_pt
+} * dm_component_info_pt;
+
+typedef struct dm_info {
+ array_list_pt components; // type dm_component_info
+} * dm_info_pt;
+
+struct dm_service {
+ dm_server_pt server;
+ celix_status_t (*getInfo)(dm_server_pt server, dm_info_pt info);
+};
+
+typedef struct dm_service * dm_service_pt;
+
+
+#endif //CELIX_DM_SERVICE_H
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/dependency_manager/public/include/dm_service_dependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_service_dependency.h b/dependency_manager/public/include/dm_service_dependency.h
index e9a5513..f267ab7 100644
--- a/dependency_manager/public/include/dm_service_dependency.h
+++ b/dependency_manager/public/include/dm_service_dependency.h
@@ -33,11 +33,13 @@ typedef struct dm_service_dependency *dm_service_dependency_pt;
#include "dm_component.h"
+typedef celix_status_t (*service_set_fpt)(void *handle, void *service);
typedef celix_status_t (*service_add_fpt)(void *handle, void *service);
typedef celix_status_t (*service_change_fpt)(void *handle, void *service);
typedef celix_status_t (*service_remove_fpt)(void *handle, void *service);
typedef celix_status_t (*service_swap_fpt)(void *handle, void *oldService, void *newService);
+typedef celix_status_t (*service_set_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
typedef celix_status_t (*service_add_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
typedef celix_status_t (*service_change_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
typedef celix_status_t (*service_remove_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
@@ -48,8 +50,8 @@ celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_pt
celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required);
celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName, char *filter);
-celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap);
-celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap);
+celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_set_fpt set, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap);
+celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_set_with_ref_fpt set, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap);
celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t *service_lock, void **field);
#endif /* DM_SERVICE_DEPENDENCY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/examples/deploy.cmake
----------------------------------------------------------------------
diff --git a/examples/deploy.cmake b/examples/deploy.cmake
index a8d97a1..24c7a11 100644
--- a/examples/deploy.cmake
+++ b/examples/deploy.cmake
@@ -22,7 +22,7 @@ if (EXAMPLES)
deploy("hello_world" BUNDLES shell shell_tui apache_celix_examples_hello_world hello_world_test log_service log_writer)
deploy("wb" BUNDLES tracker publisherA publisherB shell shell_tui log_service log_writer)
- deploy("wb_dp" BUNDLES tracker_depman publisherA publisherB shell shell_tui log_service log_writer)
+ deploy("wb_dp" BUNDLES tracker_depman publisherA publisherB shell shell_tui log_service log_writer dm_shell)
deploy("echo" BUNDLES echo_server echo_client shell shell_tui)
deploy("producer_consumer" BUNDLES producer consumer database shell shell_tui)
if (NOT ANDROID)
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/examples/whiteboard/publisherA/private/src/activator.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/publisherA/private/src/activator.c b/examples/whiteboard/publisherA/private/src/activator.c
index fd749d0..663b0b9 100644
--- a/examples/whiteboard/publisherA/private/src/activator.c
+++ b/examples/whiteboard/publisherA/private/src/activator.c
@@ -24,6 +24,7 @@
* \copyright Apache License, Version 2.0
*/
#include <stdlib.h>
+#include <constants.h>
#include "bundle_activator.h"
#include "publisher_private.h"
@@ -53,6 +54,7 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
props = properties_create();
properties_set(props, "id", "A");
+ properties_set(props,(char*)OSGI_FRAMEWORK_SERVICE_RANKING , "10");
status = bundleContext_registerService(context, PUBLISHER_NAME, data->ps, props, &data->reg);
if (status != CELIX_SUCCESS) {
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/examples/whiteboard/publisherB/private/src/activator.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/publisherB/private/src/activator.c b/examples/whiteboard/publisherB/private/src/activator.c
index 06fea8d..f5f1a2e 100644
--- a/examples/whiteboard/publisherB/private/src/activator.c
+++ b/examples/whiteboard/publisherB/private/src/activator.c
@@ -24,6 +24,7 @@
* \copyright Apache License, Version 2.0
*/
#include <stdlib.h>
+#include <constants.h>
#include "bundle_activator.h"
#include "publisher_private.h"
@@ -52,6 +53,7 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
data->reg = NULL;
properties_set(props, "id", "B");
+ properties_set(props,(char*)OSGI_FRAMEWORK_SERVICE_RANKING , "20");
bundleContext_registerService(context, PUBLISHER_NAME, data->ps, props, &data->reg);
return status;
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/examples/whiteboard/tracker_depman/private/include/tracker.h
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/include/tracker.h b/examples/whiteboard/tracker_depman/private/include/tracker.h
index 5918e91..3b078ca 100644
--- a/examples/whiteboard/tracker_depman/private/include/tracker.h
+++ b/examples/whiteboard/tracker_depman/private/include/tracker.h
@@ -44,10 +44,12 @@ struct data {
celix_thread_mutex_t publisher_lock;
};
+celix_status_t tracker_setServ(void * handle, service_reference_pt ref, void * service);
celix_status_t tracker_addedServ(void * handle, service_reference_pt ref, void * service);
celix_status_t tracker_modifiedServ(void * handle, service_reference_pt ref, void * service);
celix_status_t tracker_removedServ(void * handle, service_reference_pt ref, void * service);
+celix_status_t tracker_setLog(void * handle, service_reference_pt ref, void * service);
celix_status_t tracker_addLog(void * handle, service_reference_pt ref, void * service);
celix_status_t tracker_modifiedLog(void * handle, service_reference_pt ref, void * service);
celix_status_t tracker_removeLog(void * handle, service_reference_pt ref, void * service);
@@ -55,7 +57,7 @@ celix_status_t tracker_removeLog(void * handle, service_reference_pt ref, void *
celix_status_t service_init(void * userData);
celix_status_t service_start(void * userData);
celix_status_t service_stop(void * userData);
-celix_status_t service_destroy(void * userData);
+celix_status_t service_deinit(void * userData);
#endif /* TRACKER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
index 84194f8..5dd8d1e 100644
--- a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
+++ b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
@@ -49,30 +49,30 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
printf("Init\n");
struct data * data = (struct data *) userData;
dm_component_pt service = NULL;
- dm_service_dependency_pt dep = NULL;
+ dm_service_dependency_pt dep1 = NULL;
dm_service_dependency_pt dep2 = NULL;
data->context = context;
component_create(context, manager, &service);
component_setImplementation(service, data);
- component_setCallbacks(service, service_init, service_start, service_stop, service_destroy);
+ component_setCallbacks(service, service_init, service_start, service_stop, service_deinit);
- serviceDependency_create(&dep);
- serviceDependency_setRequired(dep, false);
- serviceDependency_setService(dep, PUBLISHER_NAME, "(|(id=A)(id=B))");
- serviceDependency_setCallbacksWithServiceReference(dep, tracker_addedServ, tracker_modifiedServ, tracker_removedServ, NULL);
- component_addServiceDependency(service, dep, NULL);
+ serviceDependency_create(&dep1);
+ serviceDependency_setRequired(dep1, true);
+ serviceDependency_setService(dep1, PUBLISHER_NAME, "(|(id=A)(id=B))");
+ serviceDependency_setCallbacksWithServiceReference(dep1, NULL /*tracker_setServ*/, tracker_addedServ, tracker_modifiedServ, tracker_removedServ, NULL);
+ component_addServiceDependency(service, dep1, NULL);
serviceDependency_create(&dep2);
serviceDependency_setRequired(dep2, false);
serviceDependency_setService(dep2, (char *) OSGI_LOGSERVICE_NAME, NULL);
- serviceDependency_setCallbacksWithServiceReference(dep2, tracker_addLog, tracker_modifiedLog, tracker_removeLog, NULL);
+ serviceDependency_setCallbacksWithServiceReference(dep2, NULL /*tracker_setLog*/, tracker_addLog, tracker_modifiedLog, tracker_removeLog, NULL);
serviceDependency_setAutoConfigure(dep2, &data->logger_lock, (void **) &data->logger);
component_addServiceDependency(service, dep2, NULL);
data->service = service;
- data->dep = dep;
+ data->dep = dep1;
data->dep2 = dep2;
dependencyManager_add(manager, service);
http://git-wip-us.apache.org/repos/asf/celix/blob/9203fddd/examples/whiteboard/tracker_depman/private/src/tracker.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/tracker.c b/examples/whiteboard/tracker_depman/private/src/tracker.c
index 2605609..0ada638 100644
--- a/examples/whiteboard/tracker_depman/private/src/tracker.c
+++ b/examples/whiteboard/tracker_depman/private/src/tracker.c
@@ -56,12 +56,13 @@ static void *dp_send(void *handle) {
}
celix_status_t service_init(void * userData) {
+ fprintf(stderr, "Service init");
return CELIX_SUCCESS;
}
celix_status_t service_start(void * userData) {
struct data * data = (struct data *) userData;
-
+ fprintf(stderr, "Service started");
data->running = true;
pthread_create(&data->sender, NULL, dp_send, data);
return CELIX_SUCCESS;
@@ -69,15 +70,23 @@ celix_status_t service_start(void * userData) {
celix_status_t service_stop(void * userData) {
struct data * data = (struct data *) userData;
+ fprintf(stderr, "Service stopped");
data->running = false;
pthread_join(data->sender, NULL);
return CELIX_SUCCESS;
}
-celix_status_t service_destroy(void * userData) {
+celix_status_t service_deinit(void * userData) {
+ fprintf(stderr, "Service deinit");
+ return CELIX_SUCCESS;
+}
+
+celix_status_t tracker_setServ(void * handle, service_reference_pt ref, void * service) {
+ printf("Service Set %p\n", service);
return CELIX_SUCCESS;
}
+
celix_status_t tracker_addedServ(void * handle, service_reference_pt ref, void * service) {
struct data * data = (struct data *) handle;
arrayList_add(data->publishers, service);
@@ -97,9 +106,21 @@ celix_status_t tracker_removedServ(void * handle, service_reference_pt ref, void
return CELIX_SUCCESS;
}
+celix_status_t tracker_setLog(void *handle, service_reference_pt ref, void *service) {
+ struct data * data = (struct data *) handle;
+
+ printf("SET log %p\n", service);
+ if(service) {
+ data->logger = service;
+ ((log_service_pt) service)->log(((log_service_pt) service)->logger, OSGI_LOGSERVICE_DEBUG, "SET log");
+ }
+ fprintf(stderr, "SET end %p\n", service);
+ return CELIX_SUCCESS;
+}
+
celix_status_t tracker_addLog(void *handle, service_reference_pt ref, void *service) {
struct data * data = (struct data *) handle;
- printf("Add log\n");
+ printf("Add log %p\n", service);
data->logger = service;
((log_service_pt) service)->log(((log_service_pt) service)->logger, OSGI_LOGSERVICE_DEBUG, "test");
return CELIX_SUCCESS;
[03/21] celix git commit: CELIX-210: renamed dep man 2 -> dep man 2.
Fixed whiteboard dep man example
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/public/include/dm_activator_base.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_activator_base.h b/dependency_manager/public/include/dm_activator_base.h
new file mode 100644
index 0000000..80196e2
--- /dev/null
+++ b/dependency_manager/public/include/dm_activator_base.h
@@ -0,0 +1,41 @@
+/**
+ * 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.
+ */
+
+/*
+ * dm_activator_base.h
+ *
+ * \date 26 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+
+#ifndef DM_ACTIVATOR_BASE_H_
+#define DM_ACTIVATOR_BASE_H_
+
+#include "bundle_context.h"
+#include "celix_errno.h"
+#include "dm_dependency_manager.h"
+
+celix_status_t dm_create(bundle_context_pt context, void ** userData);
+celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager);
+celix_status_t dm_deinit(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager);
+celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager);
+
+#endif /* DM_ACTIVATOR_BASE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/public/include/dm_component.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_component.h b/dependency_manager/public/include/dm_component.h
new file mode 100644
index 0000000..f98c3bb
--- /dev/null
+++ b/dependency_manager/public/include/dm_component.h
@@ -0,0 +1,54 @@
+/**
+ *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.
+ */
+/*
+ * dm_component.h
+ *
+ * \date 8 Oct 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef COMPONENT_H_
+#define COMPONENT_H_
+
+#include <bundle_context.h>
+#include <celix_errno.h>
+
+typedef struct dm_component *dm_component_pt;
+
+#include "dm_dependency_manager.h"
+#include "dm_service_dependency.h"
+
+typedef celix_status_t (*init_fpt)(void *userData);
+typedef celix_status_t (*start_fpt)(void *userData);
+typedef celix_status_t (*stop_fpt)(void *userData);
+typedef celix_status_t (*destroy_fpt)(void *userData);
+
+celix_status_t component_create(bundle_context_pt context, dm_dependency_manager_pt manager, dm_component_pt *component);
+celix_status_t component_destroy(dm_component_pt *component);
+
+celix_status_t component_addInterface(dm_component_pt component, char *serviceName, void *service, properties_pt properties);
+celix_status_t component_setImplementation(dm_component_pt component, void *implementation);
+
+celix_status_t component_addServiceDependency(dm_component_pt component, ...);
+celix_status_t component_removeServiceDependency(dm_component_pt component, dm_service_dependency_pt dependency);
+
+celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt, destroy_fpt);
+
+#endif /* COMPONENT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/public/include/dm_dependency_manager.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_dependency_manager.h b/dependency_manager/public/include/dm_dependency_manager.h
new file mode 100644
index 0000000..4311d3a
--- /dev/null
+++ b/dependency_manager/public/include/dm_dependency_manager.h
@@ -0,0 +1,45 @@
+/**
+ *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.
+ */
+/*
+ * dm_dependency_manager.h
+ *
+ * \date 22 Feb 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef DM_DEPENDENCY_MANAGER_H_
+#define DM_DEPENDENCY_MANAGER_H_
+
+#include "bundle_context.h"
+#include "celix_errno.h"
+#include "array_list.h"
+
+typedef struct dm_dependency_manager *dm_dependency_manager_pt;
+
+#include "dm_component.h"
+
+celix_status_t dependencyManager_create(bundle_context_pt context, dm_dependency_manager_pt *manager);
+celix_status_t dependencyManager_destroy(dm_dependency_manager_pt *manager);
+
+celix_status_t dependencyManager_add(dm_dependency_manager_pt manager, dm_component_pt component);
+celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_component_pt component);
+celix_status_t dependencyManager_getComponents(dm_dependency_manager_pt manager, array_list_pt* components);
+
+#endif /* DM_DEPENDENCY_MANAGER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/public/include/dm_service_dependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_service_dependency.h b/dependency_manager/public/include/dm_service_dependency.h
new file mode 100644
index 0000000..e9a5513
--- /dev/null
+++ b/dependency_manager/public/include/dm_service_dependency.h
@@ -0,0 +1,55 @@
+/**
+ *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.
+ */
+/*
+ * dm_service_dependency.h
+ *
+ * \date 8 Oct 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef DM_SERVICE_DEPENDENCY_H_
+#define DM_SERVICE_DEPENDENCY_H_
+
+#include "celix_errno.h"
+
+typedef struct dm_service_dependency *dm_service_dependency_pt;
+
+#include "dm_component.h"
+
+typedef celix_status_t (*service_add_fpt)(void *handle, void *service);
+typedef celix_status_t (*service_change_fpt)(void *handle, void *service);
+typedef celix_status_t (*service_remove_fpt)(void *handle, void *service);
+typedef celix_status_t (*service_swap_fpt)(void *handle, void *oldService, void *newService);
+
+typedef celix_status_t (*service_add_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
+typedef celix_status_t (*service_change_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
+typedef celix_status_t (*service_remove_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
+typedef celix_status_t (*service_swap_with_ref_fpt)(void *handle, service_reference_pt oldReference, void *oldService, service_reference_pt newReference, void *newService);
+
+celix_status_t serviceDependency_create(dm_service_dependency_pt *dependency_ptr);
+celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_ptr);
+
+celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required);
+celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName, char *filter);
+celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap);
+celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap);
+celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t *service_lock, void **field);
+
+#endif /* DM_SERVICE_DEPENDENCY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dependency_manager_2/CMakeLists.txt b/dependency_manager_2/CMakeLists.txt
deleted file mode 100644
index 373cd34..0000000
--- a/dependency_manager_2/CMakeLists.txt
+++ /dev/null
@@ -1,61 +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.
-
-celix_subproject(DEPENDENCY_MANAGER2 "Option to build the dependency manager static library" ON DEPS framework)
-if (DEPENDENCY_MANAGER2)
- # Add -fPIC for x86_64 Unix platforms; this lib will be linked to a shared lib
- if(UNIX AND NOT WIN32)
- find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
- if(CMAKE_UNAME)
- exec_program(uname ARGS -m OUTPUT_VARIABLE CMAKE_SYSTEM_PROCESSOR)
- set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR} CACHE INTERNAL "processor type (i386 and x86_64)")
- if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
- add_definitions(-fPIC)
- endif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
- endif(CMAKE_UNAME)
- endif(UNIX AND NOT WIN32)
-
- CELIX_ADD_COMPONENT(dependency_manager2
- DISPLAY_NAME Dependency Manager
- DESCRIPTION "The Apache Celix dependency manager (static) library"
- GROUP all
- )
-
- add_library(dependency_manager2 STATIC
- private/src/dm_activator_base
- private/src/dm_component_impl
- private/src/dm_service_dependency
- private/src/dm_event
- private/src/dm_dependency_manager_impl)
- include_directories("public/include")
- include_directories("private/include")
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- target_link_libraries(dependency_manager2 celix_framework)
-
- install(
- FILES
- public/include/dm_activator_base.h
- public/include/dm_component.h
- public/include/dm_dependency_manager.h
- public/include/dm_service_dependency.h
- DESTINATION
- include/celix/dependency_manager_2
- COMPONENT
- dependency_manager2
- )
- install(TARGETS dependency_manager2 DESTINATION lib COMPONENT dependency_manager2)
-endif (DEPENDENCY_MANAGER2)
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/private/include/dm_component_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/include/dm_component_impl.h b/dependency_manager_2/private/include/dm_component_impl.h
deleted file mode 100644
index 133ef06..0000000
--- a/dependency_manager_2/private/include/dm_component_impl.h
+++ /dev/null
@@ -1,84 +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.
- */
-/*
- * dm_component_impl.h
- *
- * \date 22 Feb 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef COMPONENT_IMPL_H_
-#define COMPONENT_IMPL_H_
-
-#include "dm_component.h"
-
-#include "dm_service_dependency_impl.h"
-
-#include "dm_event.h"
-
-typedef enum dm_component_state {
- DM_CMP_STATE_INACTIVE = 1,
- DM_CMP_STATE_WAITING_FOR_REQUIRED,
- DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED,
- DM_CMP_STATE_TRACKING_OPTIONAL,
-} dm_component_state_pt;
-
-typedef struct dm_executor * dm_executor_pt;
-
-typedef struct dm_interface_struct {
- char *serviceName;
- void *service;
- properties_pt properties;
- service_registration_pt registration;
-} dm_interface;
-
-struct dm_component {
- bundle_context_pt context;
- dm_dependency_manager_pt manager;
-
- array_list_pt dm_interface;
-
- void *implementation;
-
- init_fpt callbackInit;
- start_fpt callbackStart;
- stop_fpt callbackStop;
- destroy_fpt callbackDestroy;
-
- array_list_pt dependencies;
- pthread_mutex_t mutex;
-
- dm_component_state_pt state;
- bool isStarted;
- bool active;
-
- hash_map_pt dependencyEvents;
-
- dm_executor_pt executor;
-};
-
-celix_status_t component_start(dm_component_pt component);
-celix_status_t component_stop(dm_component_pt component);
-
-celix_status_t component_getBundleContext(dm_component_pt component, bundle_context_pt *context);
-
-celix_status_t component_handleEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
-
-#endif /* COMPONENT_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/private/include/dm_dependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/include/dm_dependency.h b/dependency_manager_2/private/include/dm_dependency.h
deleted file mode 100644
index e7ad5fb..0000000
--- a/dependency_manager_2/private/include/dm_dependency.h
+++ /dev/null
@@ -1,34 +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.
- */
-/*
- * dm_dependency.h
- *
- * \date 22 Feb 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef DM_DEPENDENCY_H_
-#define DM_DEPENDENCY_H_
-
-
-
-
-
-#endif /* DM_DEPENDENCY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/private/include/dm_event.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/include/dm_event.h b/dependency_manager_2/private/include/dm_event.h
deleted file mode 100644
index 8e23721..0000000
--- a/dependency_manager_2/private/include/dm_event.h
+++ /dev/null
@@ -1,63 +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.
- */
-/*
- * dm_event.h
- *
- * \date 17 Oct 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef DM_EVENT_H_
-#define DM_EVENT_H_
-
-#include "service_reference.h"
-#include "bundle_context.h"
-#include "bundle.h"
-
-enum dm_event_type {
- DM_EVENT_ADDED,
- DM_EVENT_CHANGED,
- DM_EVENT_REMOVED,
- DM_EVENT_SWAPPED,
-};
-
-typedef enum dm_event_type dm_event_type_e;
-
-struct dm_event {
- void *service;
- service_reference_pt reference;
- bundle_context_pt context;
- bundle_pt bundle;
- dm_event_type_e event_type;
-};
-
-typedef struct dm_event *dm_event_pt;
-
-
-celix_status_t event_create(dm_event_type_e event_type, bundle_pt bundle, bundle_context_pt context, service_reference_pt reference, void *service, dm_event_pt *event);
-celix_status_t event_destroy(dm_event_pt *event);
-
-celix_status_t event_equals(void *a, void *b, bool *equals);
-
-celix_status_t event_getService(dm_event_pt event, void **service);
-celix_status_t event_compareTo(dm_event_pt event, dm_event_pt compareTo, int *compare);
-
-
-#endif /* DM_EVENT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/private/include/dm_service_dependency_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/include/dm_service_dependency_impl.h b/dependency_manager_2/private/include/dm_service_dependency_impl.h
deleted file mode 100644
index 1396f31..0000000
--- a/dependency_manager_2/private/include/dm_service_dependency_impl.h
+++ /dev/null
@@ -1,90 +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.
- */
-/*
- * dm_service_dependency_impl.h
- *
- * \date 8 Oct 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef DM_SERVICE_DEPENDENCY_IMPL_H_
-#define DM_SERVICE_DEPENDENCY_IMPL_H_
-
-#include <stdbool.h>
-
-#include "dm_event.h"
-#include "service_tracker.h"
-#include "service_tracker_customizer.h"
-
-#include "dm_service_dependency.h"
-
-struct dm_service_dependency {
- dm_component_pt component;
- bool available;
- bool instanceBound;
- bool required;
-
- service_add_fpt add;
- service_change_fpt change;
- service_remove_fpt remove;
- service_swap_fpt swap;
-
- service_add_with_ref_fpt add_with_ref;
- service_change_with_ref_fpt change_with_ref;
- service_remove_with_ref_fpt remove_with_ref;
- service_swap_with_ref_fpt swap_with_ref;
-
- void **autoConfigure;
- celix_thread_mutex_t lock;
-
- bool isStarted;
-
- char *tracked_service_name;
- char *tracked_filter_unmodified;
- char *tracked_filter;
-
- service_tracker_pt tracker;
- service_tracker_customizer_pt tracker_customizer;
-};
-
-celix_status_t serviceDependency_start(dm_service_dependency_pt dependency);
-celix_status_t serviceDependency_stop(dm_service_dependency_pt dependency);
-celix_status_t serviceDependency_setInstanceBound(dm_service_dependency_pt dependency, bool instanceBound);
-celix_status_t serviceDependency_setAutoConfig(dm_service_dependency_pt dependency, void **autoConfigure);
-celix_status_t serviceDependency_setAvailable(dm_service_dependency_pt dependency, bool available);
-
-celix_status_t serviceDependency_setComponent(dm_service_dependency_pt dependency, dm_component_pt component);
-//celix_status_t serviceDependency_removeComponent(dm_service_dependency_pt dependency, dm_component_pt component);
-
-celix_status_t serviceDependency_invokeAdd(dm_service_dependency_pt dependency, dm_event_pt event);
-celix_status_t serviceDependency_invokeChange(dm_service_dependency_pt dependency, dm_event_pt event);
-celix_status_t serviceDependency_invokeRemove(dm_service_dependency_pt dependency, dm_event_pt event);
-celix_status_t serviceDependency_invokeSwap(dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent);
-celix_status_t serviceDependency_isAvailable(dm_service_dependency_pt dependency, bool *available);
-celix_status_t serviceDependency_isRequired(dm_service_dependency_pt dependency, bool *required);
-celix_status_t serviceDependency_isInstanceBound(dm_service_dependency_pt dependency, bool *instanceBound);
-celix_status_t serviceDependency_isAutoConfig(dm_service_dependency_pt dependency, bool *autoConfig);
-
-celix_status_t serviceDependency_getAutoConfig(dm_service_dependency_pt dependency, void ***autoConfigure);
-celix_status_t serviceDependency_unlock(dm_service_dependency_pt dependency);
-celix_status_t serviceDependency_lock(dm_service_dependency_pt dependency);
-
-
-#endif /* DM_SERVICE_DEPENDENCY_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/private/src/dm_activator_base.c
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/src/dm_activator_base.c b/dependency_manager_2/private/src/dm_activator_base.c
deleted file mode 100644
index a97194e..0000000
--- a/dependency_manager_2/private/src/dm_activator_base.c
+++ /dev/null
@@ -1,98 +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.
- */
-
-/*
- * dm_activator_base.c
- *
- * \date 26 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-
-#include <stdlib.h>
-
-#include "bundle_activator.h"
-#include "dm_activator_base.h"
-
-
-struct dm_dependency_activator_base {
- dm_dependency_manager_pt manager;
- bundle_context_pt context;
- void* userData;
-};
-
-typedef struct dm_dependency_activator_base * dependency_activator_base_pt;
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_ENOMEM;
-
- dependency_activator_base_pt dependency_activator = calloc(1, sizeof(struct dm_dependency_activator_base));
-
- if (dependency_activator) {
- dependency_activator->context = context;
- dm_create(context, &dependency_activator->userData);
-
- (*userData) = dependency_activator;
-
- status = CELIX_SUCCESS;
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status;
- dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
-
- status = dependencyManager_create(dependency_activator->context, &dependency_activator->manager);
-
- if (status == CELIX_SUCCESS) {
- dm_init(dependency_activator->userData, context, dependency_activator->manager);
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context __attribute__((unused))) {
- celix_status_t status = CELIX_SUCCESS;
- dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
-
- dm_deinit(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
-
- dependencyManager_destroy(&dependency_activator->manager);
-
- dependency_activator->userData = NULL;
- dependency_activator->manager = NULL;
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context __attribute__((unused))) {
- celix_status_t status = CELIX_SUCCESS;
- dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
-
- dm_destroy(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
-
- free(dependency_activator);
-
- return status;
-}
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/src/dm_component_impl.c b/dependency_manager_2/private/src/dm_component_impl.c
deleted file mode 100644
index 72fe7eb..0000000
--- a/dependency_manager_2/private/src/dm_component_impl.c
+++ /dev/null
@@ -1,1277 +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.
- */
-/*
- * dm_component_impl.c
- *
- * \date 9 Oct 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "dm_component_impl.h"
-#include "../../../framework/private/include/framework_private.h"
-
-struct dm_executor {
- pthread_t runningThread;
- bool runningThreadSet;
- linked_list_pt workQueue;
-
- pthread_mutex_t mutex;
-};
-
-struct dm_executor_task {
- dm_component_pt component;
- void (*command)(void *command_ptr, void *data);
- void *data;
-};
-
-struct dm_handle_event_type {
- dm_service_dependency_pt dependency;
- dm_event_pt event;
- dm_event_pt newEvent;
-};
-
-typedef struct dm_handle_event_type *dm_handle_event_type_pt;
-
-static celix_status_t executor_runTasks(dm_executor_pt executor, pthread_t currentThread __attribute__((unused)));
-static celix_status_t executor_execute(dm_executor_pt executor);
-static celix_status_t executor_executeTask(dm_executor_pt executor, dm_component_pt component, void (*command), void *data);
-static celix_status_t executor_schedule(dm_executor_pt executor, dm_component_pt component, void (*command), void *data);
-static celix_status_t executor_create(dm_component_pt component __attribute__((unused)), dm_executor_pt *executor);
-static celix_status_t executor_destroy(dm_executor_pt *executor);
-
-static celix_status_t component_destroyComponent(dm_component_pt component);
-static celix_status_t component_invokeRemoveRequiredDependencies(dm_component_pt component);
-static celix_status_t component_invokeRemoveInstanceBoundDependencies(dm_component_pt component);
-static celix_status_t component_invokeRemoveOptionalDependencies(dm_component_pt component);
-static celix_status_t component_registerService(dm_component_pt component);
-static celix_status_t component_unregisterService(dm_component_pt component);
-static celix_status_t component_invokeAddOptionalDependencies(dm_component_pt component);
-static celix_status_t component_invokeAddRequiredInstanceBoundDependencies(dm_component_pt component);
-static celix_status_t component_invokeAddRequiredDependencies(dm_component_pt component);
-static celix_status_t component_invokeAutoConfigInstanceBoundDependencies(dm_component_pt component);
-static celix_status_t component_invokeAutoConfigDependencies(dm_component_pt component);
-static celix_status_t component_configureImplementation(dm_component_pt component, dm_service_dependency_pt dependency);
-static celix_status_t component_allInstanceBoundAvailable(dm_component_pt component, bool *available);
-static celix_status_t component_allRequiredAvailable(dm_component_pt component, bool *available);
-static celix_status_t component_performTransition(dm_component_pt component, dm_component_state_pt oldState, dm_component_state_pt newState, bool *transition);
-static celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_pt currentState, dm_component_state_pt *newState);
-static celix_status_t component_handleChange(dm_component_pt component);
-static celix_status_t component_startDependencies(dm_component_pt component __attribute__((unused)), array_list_pt dependencies);
-static celix_status_t component_getDependencyEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt *event_pptr);
-static celix_status_t component_updateInstance(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, bool update, bool add);
-
-static celix_status_t component_addTask(dm_component_pt component, array_list_pt dependencies);
-static celix_status_t component_startTask(dm_component_pt component, void * data __attribute__((unused)));
-static celix_status_t component_stopTask(dm_component_pt component, void * data __attribute__((unused)));
-static celix_status_t component_removeTask(dm_component_pt component, dm_service_dependency_pt dependency);
-static celix_status_t component_handleEventTask(dm_component_pt component, dm_handle_event_type_pt data);
-
-static celix_status_t component_handleAdded(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
-static celix_status_t component_handleChanged(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
-static celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
-static celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent);
-
-celix_status_t component_create(bundle_context_pt context, dm_dependency_manager_pt manager, dm_component_pt *component) {
- celix_status_t status = CELIX_SUCCESS;
-
- *component = malloc(sizeof(**component));
- if (!*component) {
- status = CELIX_ENOMEM;
- } else {
- (*component)->context = context;
- (*component)->manager = manager;
-
- arrayList_create(&((*component)->dm_interface));
-
- (*component)->implementation = NULL;
-
- (*component)->callbackInit = NULL;
- (*component)->callbackStart = NULL;
- (*component)->callbackStop = NULL;
- (*component)->callbackDestroy = NULL;
-
-
- arrayList_create(&(*component)->dependencies);
- pthread_mutex_init(&(*component)->mutex, NULL);
-
- (*component)->state = DM_CMP_STATE_INACTIVE;
- (*component)->isStarted = false;
- (*component)->active = false;
-
- (*component)->dependencyEvents = hashMap_create(NULL, NULL, NULL, NULL);
-
- (*component)->executor = NULL;
- executor_create(*component, &(*component)->executor);
- }
-
- return status;
-}
-
-celix_status_t component_destroy(dm_component_pt *component_ptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!*component_ptr) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- unsigned int i;
-
- for (i = 0; i < arrayList_size((*component_ptr)->dm_interface); i++) {
- dm_interface *interface = arrayList_get((*component_ptr)->dm_interface, i);
-
- free (interface->serviceName);
- }
- arrayList_destroy((*component_ptr)->dm_interface);
-
- // #TODO destroy dependencies?
- executor_destroy(&(*component_ptr)->executor);
- hashMap_destroy((*component_ptr)->dependencyEvents, false, false);
- pthread_mutex_destroy(&(*component_ptr)->mutex);
- arrayList_destroy((*component_ptr)->dependencies);
-
- free(*component_ptr);
- *component_ptr = NULL;
- }
-
- return status;
-}
-
-celix_status_t component_addServiceDependency(dm_component_pt component, ...) {
- celix_status_t status = CELIX_SUCCESS;
-
- array_list_pt dependenciesList = NULL;
- arrayList_create(&dependenciesList);
-
- va_list dependencies;
- va_start(dependencies, component);
- dm_service_dependency_pt dependency = va_arg(dependencies, dm_service_dependency_pt);
- while (dependency != NULL) {
- arrayList_add(dependenciesList, dependency);
-
-
- dependency = va_arg(dependencies, dm_service_dependency_pt);
- }
-
- va_end(dependencies);
-
- executor_executeTask(component->executor, component, component_addTask, dependenciesList);
-// component_addTask(component, dependenciesList);
-
- return status;
-}
-
-
-celix_status_t component_addTask(dm_component_pt component, array_list_pt dependencies) {
- celix_status_t status = CELIX_SUCCESS;
-
- array_list_pt bounds = NULL;
- arrayList_create(&bounds);
- for (unsigned int i = 0; i < arrayList_size(dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(dependencies, i);
-
- pthread_mutex_lock(&component->mutex);
- array_list_pt events = NULL;
- arrayList_createWithEquals(event_equals, &events);
- hashMap_put(component->dependencyEvents, dependency, events);
-
- arrayList_add(component->dependencies, dependency);
- pthread_mutex_unlock(&component->mutex);
-
- serviceDependency_setComponent(dependency, component);
- if (component->state != DM_CMP_STATE_INACTIVE) {
- serviceDependency_setInstanceBound(dependency, true);
- arrayList_add(bounds, dependency);
- }
- component_startDependencies(component, bounds);
- component_handleChange(component);
- }
-
- arrayList_destroy(bounds);
- arrayList_destroy(dependencies);
-
- return status;
-}
-
-celix_status_t component_removeServiceDependency(dm_component_pt component, dm_service_dependency_pt dependency) {
- celix_status_t status = CELIX_SUCCESS;
-
- executor_executeTask(component->executor, component, component_removeTask, dependency);
-// component_removeTask(component, dependency);
-
- return status;
-}
-
-celix_status_t component_removeTask(dm_component_pt component, dm_service_dependency_pt dependency) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- arrayList_removeElement(component->dependencies, dependency);
- pthread_mutex_unlock(&component->mutex);
-
- if (component->state != DM_CMP_STATE_INACTIVE) {
- serviceDependency_stop(dependency);
- }
-
- pthread_mutex_lock(&component->mutex);
- array_list_pt events = hashMap_remove(component->dependencyEvents, dependency);
- for (unsigned int i = arrayList_size(events); i > 0; i--) {
- dm_event_pt event = arrayList_remove(events, i - 1);
- event_destroy(&event);
- }
- arrayList_destroy(events);
- pthread_mutex_unlock(&component->mutex);
-
- component_handleChange(component);
-
- return status;
-}
-
-celix_status_t component_start(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- component->active = true;
- executor_executeTask(component->executor, component, component_startTask, NULL);
-// component_startTask(component, NULL);
-
- return status;
-}
-
-celix_status_t component_startTask(dm_component_pt component, void *data __attribute__((unused))) {
- celix_status_t status = CELIX_SUCCESS;
-
- component->isStarted = true;
- component_handleChange(component);
-
- return status;
-}
-
-celix_status_t component_stop(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- component->active = false;
- executor_executeTask(component->executor, component, component_stopTask, NULL);
-// component_stopTask(component, NULL);
-
- return status;
-}
-
-celix_status_t component_stopTask(dm_component_pt component, void *data __attribute__((unused))) {
- celix_status_t status = CELIX_SUCCESS;
-
- component->isStarted = false;
- component_handleChange(component);
- component->active = false;
-
- return status;
-}
-
-celix_status_t component_addInterface(dm_component_pt component, char *serviceName, void *service, properties_pt properties) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (component->active) {
- return CELIX_ILLEGAL_STATE;
- } else {
- dm_interface *interface = (dm_interface *) malloc (sizeof (dm_interface));
- char *name = strdup (serviceName);
-
- if (interface && name) {
- interface->serviceName = name;
- interface->service = service;
- interface->properties = properties;
- interface->registration = NULL;
- arrayList_add(component->dm_interface, interface);
- }
- else {
- free (interface);
- free (name);
- status = CELIX_ENOMEM;
- }
- }
-
- return status;
-}
-
-celix_status_t component_handleEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
- celix_status_t status = CELIX_SUCCESS;
-
- dm_handle_event_type_pt data = calloc(1, sizeof(*data));
- data->dependency = dependency;
- data->event = event;
- data->newEvent = NULL;
-
- status = executor_executeTask(component->executor, component, component_handleEventTask, data);
-// component_handleEventTask(component, data);
-
- return status;
-}
-
-celix_status_t component_handleEventTask(dm_component_pt component, dm_handle_event_type_pt data) {
- celix_status_t status = CELIX_SUCCESS;
-
- switch (data->event->event_type) {
- case DM_EVENT_ADDED:
- component_handleAdded(component,data->dependency, data->event);
- break;
- case DM_EVENT_CHANGED:
- component_handleChanged(component,data->dependency, data->event);
- break;
- case DM_EVENT_REMOVED:
- component_handleRemoved(component,data->dependency, data->event);
- break;
- case DM_EVENT_SWAPPED:
- component_handleSwapped(component,data->dependency, data->event, data->newEvent);
- break;
- default:
- break;
- }
-
- free(data);
-
- return status;
-}
-
-celix_status_t component_handleAdded(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- arrayList_add(events, event);
- pthread_mutex_unlock(&component->mutex);
-
- serviceDependency_setAvailable(dependency, true);
-
- switch (component->state) {
- case DM_CMP_STATE_WAITING_FOR_REQUIRED: {
- bool required = false;
- serviceDependency_isRequired(dependency, &required);
- if (required) {
- component_handleChange(component);
- }
- break;
- }
- case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
- bool instanceBound = false;
- serviceDependency_isInstanceBound(dependency, &instanceBound);
- if (!instanceBound) {
- bool required = false;
- serviceDependency_isRequired(dependency, &required);
- if (required) {
- serviceDependency_invokeAdd(dependency, event);
- }
- dm_event_pt event = NULL;
- component_getDependencyEvent(component, dependency, &event);
- component_updateInstance(component, dependency, event, false, true);
- } else {
- bool required = false;
- serviceDependency_isRequired(dependency, &required);
- if (required) {
- component_handleChange(component);
- }
- }
- break;
- }
- case DM_CMP_STATE_TRACKING_OPTIONAL:
- serviceDependency_invokeAdd(dependency, event);
- dm_event_pt event = NULL;
- component_getDependencyEvent(component, dependency, &event);
- component_updateInstance(component, dependency, event, false, true);
- break;
- default:
- break;
- }
-
- return status;
-}
-
-celix_status_t component_handleChanged(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- int index = arrayList_indexOf(events, event);
- if (index < 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- dm_event_pt old = arrayList_remove(events, (unsigned int) index);
- arrayList_add(events, event);
- pthread_mutex_unlock(&component->mutex);
-
- switch (component->state) {
- case DM_CMP_STATE_TRACKING_OPTIONAL:
- serviceDependency_invokeChange(dependency, event);
- dm_event_pt hevent = NULL;
- component_getDependencyEvent(component, dependency, &hevent);
- component_updateInstance(component, dependency, hevent, true, false);
- break;
- case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
- bool instanceBound = false;
- serviceDependency_isInstanceBound(dependency, &instanceBound);
- if (!instanceBound) {
- serviceDependency_invokeChange(dependency, event);
- dm_event_pt hevent = NULL;
- component_getDependencyEvent(component, dependency, &hevent);
- component_updateInstance(component, dependency, hevent, true, false);
- }
- break;
- }
- default:
- break;
- }
-
- event_destroy(&old);
- }
-
- return status;
-}
-
-celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- int size = arrayList_size(events);
- if (arrayList_contains(events, event)) {
- size--;
- }
- pthread_mutex_unlock(&component->mutex);
- serviceDependency_setAvailable(dependency, size > 0);
- component_handleChange(component);
-
- pthread_mutex_lock(&component->mutex);
- int index = arrayList_indexOf(events, event);
- if (index < 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- dm_event_pt old = arrayList_remove(events, (unsigned int) index);
- pthread_mutex_unlock(&component->mutex);
-
- switch (component->state) {
- case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
- bool instanceBound = false;
- serviceDependency_isInstanceBound(dependency, &instanceBound);
- if (!instanceBound) {
- bool required = false;
- serviceDependency_isRequired(dependency, &required);
- if (required) {
- serviceDependency_invokeRemove(dependency, event);
- }
- dm_event_pt hevent = NULL;
- component_getDependencyEvent(component, dependency, &hevent);
- component_updateInstance(component, dependency, hevent, false, false);
- }
- break;
- }
- case DM_CMP_STATE_TRACKING_OPTIONAL:
- serviceDependency_invokeRemove(dependency, event);
- dm_event_pt hevent = NULL;
- component_getDependencyEvent(component, dependency, &hevent);
- component_updateInstance(component, dependency, hevent, false, false);
- break;
- default:
- break;
- }
-
- event_destroy(&event);
- if (old) {
- event_destroy(&old);
- }
- }
-
- return status;
-}
-
-celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- int index = arrayList_indexOf(events, event);
- if (index < 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- dm_event_pt old = arrayList_remove(events, (unsigned int) index);
- arrayList_add(events, newEvent);
- pthread_mutex_unlock(&component->mutex);
-
- switch (component->state) {
- case DM_CMP_STATE_WAITING_FOR_REQUIRED:
- break;
- case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
- bool instanceBound = false;
- serviceDependency_isInstanceBound(dependency, &instanceBound);
- if (!instanceBound) {
- bool required = false;
- serviceDependency_isRequired(dependency, &required);
- if (required) {
- serviceDependency_invokeSwap(dependency, event, newEvent);
- }
- }
- break;
- }
- case DM_CMP_STATE_TRACKING_OPTIONAL:
- serviceDependency_invokeSwap(dependency, event, newEvent);
- break;
- default:
- break;
- }
-
- event_destroy(&event);
- if (old) {
- event_destroy(&old);
- }
- }
-
- return status;
-}
-
-celix_status_t component_updateInstance(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, bool update, bool add) {
- celix_status_t status = CELIX_SUCCESS;
-
- bool autoConfig = false;
-
- serviceDependency_isAutoConfig(dependency, &autoConfig);
-
- if (autoConfig) {
- void *service = NULL;
- void **field = NULL;
-
- if (event != NULL) {
- event_getService(event, &service);
- }
- serviceDependency_getAutoConfig(dependency, &field);
- serviceDependency_lock(dependency);
- *field = service;
- serviceDependency_unlock(dependency);
- }
-
- return status;
-}
-
-celix_status_t component_startDependencies(dm_component_pt component __attribute__((unused)), array_list_pt dependencies) {
- celix_status_t status = CELIX_SUCCESS;
- array_list_pt required_dependencies = NULL;
- arrayList_create(&required_dependencies);
-
- for (unsigned int i = 0; i < arrayList_size(dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(dependencies, i);
- bool required = false;
- serviceDependency_isRequired(dependency, &required);
- if (required) {
- arrayList_add(required_dependencies, dependency);
- continue;
- }
-
- serviceDependency_start(dependency);
- }
-
- for (unsigned int i = 0; i < arrayList_size(required_dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(required_dependencies, i);
- serviceDependency_start(dependency);
- }
-
- arrayList_destroy(required_dependencies);
-
- return status;
-}
-
-celix_status_t component_stopDependencies(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
- pthread_mutex_unlock(&component->mutex);
- serviceDependency_stop(dependency);
- pthread_mutex_lock(&component->mutex);
- }
- pthread_mutex_unlock(&component->mutex);
-
- return status;
-}
-
-celix_status_t component_handleChange(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- dm_component_state_pt oldState;
- dm_component_state_pt newState;
-
- bool cont = false;
- do {
- oldState = component->state;
- component_calculateNewState(component, oldState, &newState);
- component->state = newState;
- component_performTransition(component, oldState, newState, &cont);
- } while (cont);
-
- return status;
-}
-
-celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_pt currentState, dm_component_state_pt *newState) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (currentState == DM_CMP_STATE_INACTIVE) {
- if (component->isStarted) {
- *newState = DM_CMP_STATE_WAITING_FOR_REQUIRED;
- return status;
- }
- }
- if (currentState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
- if (!component->isStarted) {
- *newState = DM_CMP_STATE_INACTIVE;
- return status;
- }
-
- bool available = false;
- component_allRequiredAvailable(component, &available);
-
- if (available) {
- *newState = DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED;
- return status;
- }
- }
- if (currentState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
- bool available = false;
- component_allRequiredAvailable(component, &available);
-
- if (component->isStarted && available) {
- bool instanceBoundAvailable = false;
- component_allInstanceBoundAvailable(component, &instanceBoundAvailable);
-
- if (instanceBoundAvailable) {
- *newState = DM_CMP_STATE_TRACKING_OPTIONAL;
- return status;
- }
-
- *newState = currentState;
- return status;
- }
- *newState = DM_CMP_STATE_WAITING_FOR_REQUIRED;
- return status;
- }
- if (currentState == DM_CMP_STATE_TRACKING_OPTIONAL) {
- bool instanceBoundAvailable = false;
- bool available = false;
-
- component_allInstanceBoundAvailable(component, &instanceBoundAvailable);
- component_allRequiredAvailable(component, &available);
-
- if (component->isStarted && available && instanceBoundAvailable) {
- *newState = currentState;
- return status;
- }
-
- *newState = DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED;
- return status;
- }
-
- *newState = currentState;
-
- return status;
-}
-
-celix_status_t component_performTransition(dm_component_pt component, dm_component_state_pt oldState, dm_component_state_pt newState, bool *transition) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (oldState == DM_CMP_STATE_INACTIVE && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
- component_startDependencies(component, component->dependencies);
-// #TODO Add listener support
-// notifyListeners(newState);
- *transition = true;
- return status;
- }
-
- if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
- // #TODO Remove
-// component_instantiateComponent(component);
- component_invokeAddRequiredDependencies(component);
- component_invokeAutoConfigDependencies(component);
- dm_component_state_pt stateBeforeCallingInit = component->state;
- if (component->callbackInit) {
- component->callbackInit(component->implementation);
- }
- if (stateBeforeCallingInit == component->state) {
-// #TODO Add listener support
-// notifyListeners(newState); // init did not change current state, we can notify about this new state
- }
- *transition = true;
- return status;
- }
-
- if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_TRACKING_OPTIONAL) {
- component_invokeAddRequiredInstanceBoundDependencies(component);
- component_invokeAutoConfigInstanceBoundDependencies(component);
- if (component->callbackStart) {
- component->callbackStart(component->implementation);
- }
- component_invokeAddOptionalDependencies(component);
- component_registerService(component);
-// #TODO Add listener support
-// notifyListeners(newState);
- return true;
- }
-
- if (oldState == DM_CMP_STATE_TRACKING_OPTIONAL && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
- component_unregisterService(component);
- component_invokeRemoveOptionalDependencies(component);
- if (component->callbackStop) {
- component->callbackStop(component->implementation);
- }
- component_invokeRemoveInstanceBoundDependencies(component);
-// #TODO Add listener support
-// notifyListeners(newState);
- *transition = true;
- return status;
- }
-
- if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
- if (component->callbackDestroy) {
- component->callbackDestroy(component->implementation);
- }
- component_invokeRemoveRequiredDependencies(component);
-// #TODO Add listener support
-// notifyListeners(newState);
-// bool needInstance = false;
-// component_someDependenciesNeedInstance(component, &needInstance);
-// if (!needInstance) {
- component_destroyComponent(component);
-// }
- *transition = true;
- return status;
- }
-
- if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INACTIVE) {
- component_stopDependencies(component);
- component_destroyComponent(component);
-// #TODO Add listener support
-// notifyListeners(newState);
- *transition = true;
- return status;
- }
-
- *transition = false;
- return status;
-}
-
-celix_status_t component_allRequiredAvailable(dm_component_pt component, bool *available) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- *available = true;
- for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
- bool required = false;
- bool instanceBound = false;
-
- serviceDependency_isRequired(dependency, &required);
- serviceDependency_isInstanceBound(dependency, &instanceBound);
-
- if (required && !instanceBound) {
- bool isAvailable = false;
- serviceDependency_isAvailable(dependency, &isAvailable);
- if (!isAvailable) {
- *available = false;
- break;
- }
- }
- }
- pthread_mutex_unlock(&component->mutex);
-
- return status;
-}
-
-celix_status_t component_allInstanceBoundAvailable(dm_component_pt component, bool *available) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- *available = true;
- for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
- bool required = false;
- bool instanceBound = false;
-
- serviceDependency_isRequired(dependency, &required);
- serviceDependency_isInstanceBound(dependency, &instanceBound);
-
- if (required && instanceBound) {
- bool isAvailable = false;
- serviceDependency_isAvailable(dependency, &isAvailable);
- if (!isAvailable) {
- *available = false;
- break;
- }
- }
- }
- pthread_mutex_unlock(&component->mutex);
-
- return status;
-}
-
-celix_status_t component_invokeAddRequiredDependencies(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
-
- bool required = false;
- bool instanceBound = false;
-
- serviceDependency_isRequired(dependency, &required);
- serviceDependency_isInstanceBound(dependency, &instanceBound);
-
- if (required && !instanceBound) {
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- if (events) {
- for (unsigned int j = 0; j < arrayList_size(events); j++) {
- dm_event_pt event = arrayList_get(events, j);
- serviceDependency_invokeAdd(dependency, event);
- }
- }
- }
- }
- pthread_mutex_unlock(&component->mutex);
-
- return status;
-}
-
-celix_status_t component_invokeAutoConfigDependencies(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
-
- bool autoConfig = false;
- bool instanceBound = false;
-
- serviceDependency_isAutoConfig(dependency, &autoConfig);
- serviceDependency_isInstanceBound(dependency, &instanceBound);
-
- if (autoConfig && !instanceBound) {
- component_configureImplementation(component, dependency);
- }
- }
- pthread_mutex_unlock(&component->mutex);
-
- return status;
-}
-
-celix_status_t component_invokeAutoConfigInstanceBoundDependencies(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
-
- bool autoConfig = false;
- bool instanceBound = false;
-
- serviceDependency_isAutoConfig(dependency, &autoConfig);
- serviceDependency_isInstanceBound(dependency, &instanceBound);
-
- if (autoConfig && instanceBound) {
- component_configureImplementation(component, dependency);
- }
- }
- pthread_mutex_unlock(&component->mutex);
-
- return status;
-}
-
-celix_status_t component_invokeAddRequiredInstanceBoundDependencies(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
-
- bool required = false;
- bool instanceBound = false;
-
- serviceDependency_isRequired(dependency, &required);
- serviceDependency_isInstanceBound(dependency, &instanceBound);
-
- if (instanceBound && required) {
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- if (events) {
- for (unsigned int j = 0; j < arrayList_size(events); j++) {
- dm_event_pt event = arrayList_get(events, j);
- serviceDependency_invokeAdd(dependency, event);
- }
- }
- }
- }
- pthread_mutex_unlock(&component->mutex);
-
- return status;
-}
-
-celix_status_t component_invokeAddOptionalDependencies(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
-
- bool required = false;
-
- serviceDependency_isRequired(dependency, &required);
-
- if (!required) {
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- if (events) {
- for (unsigned int j = 0; j < arrayList_size(events); j++) {
- dm_event_pt event = arrayList_get(events, j);
- serviceDependency_invokeAdd(dependency, event);
- }
- }
- }
- }
- pthread_mutex_unlock(&component->mutex);
-
- return status;
-}
-
-celix_status_t component_invokeRemoveOptionalDependencies(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
-
- bool required = false;
-
- serviceDependency_isRequired(dependency, &required);
-
- if (!required) {
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- if (events) {
- for (unsigned int j = 0; j < arrayList_size(events); j++) {
- dm_event_pt event = arrayList_get(events, j);
- serviceDependency_invokeRemove(dependency, event);
- }
- }
- }
- }
- pthread_mutex_unlock(&component->mutex);
-
- return status;
-}
-
-celix_status_t component_invokeRemoveInstanceBoundDependencies(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
-
- bool instanceBound = false;
-
- serviceDependency_isInstanceBound(dependency, &instanceBound);
-
- if (instanceBound) {
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- if (events) {
- for (unsigned int j = 0; j < arrayList_size(events); j++) {
- dm_event_pt event = arrayList_get(events, j);
- serviceDependency_invokeRemove(dependency, event);
- }
- }
- }
- }
- pthread_mutex_unlock(&component->mutex);
-
- return status;
-}
-
-celix_status_t component_invokeRemoveRequiredDependencies(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- pthread_mutex_lock(&component->mutex);
- for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
-
- bool required = false;
- bool instanceBound = false;
-
- serviceDependency_isRequired(dependency, &required);
- serviceDependency_isInstanceBound(dependency, &instanceBound);
-
- if (!instanceBound && required) {
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- if (events) {
- for (unsigned int j = 0; j < arrayList_size(events); j++) {
- dm_event_pt event = arrayList_get(events, j);
- serviceDependency_invokeRemove(dependency, event);
- }
- }
- }
- }
- pthread_mutex_unlock(&component->mutex);
-
- return status;
-}
-
-celix_status_t component_getDependencyEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt *event_pptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- *event_pptr = NULL;
-
- if (events) {
- for (unsigned int j = 0; j < arrayList_size(events); j++) {
- dm_event_pt event_ptr = arrayList_get(events, j);
- if (*event_pptr != NULL) {
- int compare = 0;
- event_compareTo(event_ptr, *event_pptr, &compare);
- if (compare > 0) {
- *event_pptr = event_ptr;
- }
- } else {
- *event_pptr = event_ptr;
- }
- }
- }
-
- return status;
-}
-
-celix_status_t component_configureImplementation(dm_component_pt component, dm_service_dependency_pt dependency) {
- celix_status_t status = CELIX_SUCCESS;
-
- void **field = NULL;
-
- array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
- if (events) {
- void *service = NULL;
- dm_event_pt event = NULL;
- component_getDependencyEvent(component, dependency, &event);
- if (event != NULL) {
- event_getService(event, &service);
- serviceDependency_getAutoConfig(dependency, &field);
- serviceDependency_lock(dependency);
- *field = service;
- serviceDependency_unlock(dependency);
- }
- }
-
- return status;
-}
-
-celix_status_t component_destroyComponent(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
-// component->implementation = NULL;
-
- return status;
-}
-
-celix_status_t component_registerService(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (component->context) {
- unsigned int i;
-
- for (i = 0; i < arrayList_size(component->dm_interface); i++) {
- dm_interface *interface = arrayList_get(component->dm_interface, i);
-
- bundleContext_registerService(component->context, interface->serviceName, interface->service, interface->properties, &interface->registration);
- }
- }
-
- return status;
-}
-
-celix_status_t component_unregisterService(dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- unsigned int i;
-
- for (i = 0; i < arrayList_size(component->dm_interface); i++) {
- dm_interface *interface = arrayList_get(component->dm_interface, i);
-
- serviceRegistration_unregister(interface->registration);
- interface->registration = NULL;
- }
-
- return status;
-}
-
-celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt stop, destroy_fpt destroy) {
- if (component->active) {
- return CELIX_ILLEGAL_STATE;
- }
- component->callbackInit = init;
- component->callbackStart = start;
- component->callbackStop = stop;
- component->callbackDestroy = destroy;
- return CELIX_SUCCESS;
-}
-
-celix_status_t component_isAvailable(dm_component_pt component, bool *available) {
- *available = component->state == DM_CMP_STATE_TRACKING_OPTIONAL;
- return CELIX_SUCCESS;
-}
-
-celix_status_t component_setImplementation(dm_component_pt component, void *implementation) {
- component->implementation = implementation;
- return CELIX_SUCCESS;
-}
-
-celix_status_t component_getBundleContext(dm_component_pt component, bundle_context_pt *context) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!component) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- *context = component->context;
- }
-
- return status;
-}
-
-
-celix_status_t executor_create(dm_component_pt component __attribute__((unused)), dm_executor_pt *executor) {
- celix_status_t status = CELIX_SUCCESS;
-
- *executor = malloc(sizeof(**executor));
- if (!*executor) {
- status = CELIX_ENOMEM;
- } else {
- linkedList_create(&(*executor)->workQueue);
- pthread_mutex_init(&(*executor)->mutex, NULL);
- (*executor)->runningThreadSet = false;
- }
-
- return status;
-}
-
-celix_status_t executor_destroy(dm_executor_pt *executor) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!*executor) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- pthread_mutex_destroy(&(*executor)->mutex);
- linkedList_destroy((*executor)->workQueue);
-
- free(*executor);
- *executor = NULL;
- }
-
- return status;
-}
-
-celix_status_t executor_schedule(dm_executor_pt executor, dm_component_pt component, void (*command), void *data) {
- celix_status_t status = CELIX_SUCCESS;
-
- struct dm_executor_task *task = NULL;
- task = malloc(sizeof(*task));
- if (!task) {
- status = CELIX_ENOMEM;
- } else {
- task->component = component;
- task->command = command;
- task->data = data;
-
- pthread_mutex_lock(&executor->mutex);
- linkedList_addLast(executor->workQueue, task);
- pthread_mutex_unlock(&executor->mutex);
- }
-
- return status;
-}
-
-celix_status_t executor_executeTask(dm_executor_pt executor, dm_component_pt component, void (*command), void *data) {
- celix_status_t status = CELIX_SUCCESS;
-
- // Check thread and executor thread, if the same, execute immediately.
-// bool execute = false;
-// pthread_mutex_lock(&executor->mutex);
-// pthread_t currentThread = pthread_self();
-// if (pthread_equal(executor->runningThread, currentThread)) {
-// execute = true;
-// }
-// pthread_mutex_unlock(&executor->mutex);
-
- // For now, just schedule.
- executor_schedule(executor, component, command, data);
- executor_execute(executor);
-
- return status;
-}
-
-celix_status_t executor_execute(dm_executor_pt executor) {
- celix_status_t status = CELIX_SUCCESS;
- pthread_t currentThread = pthread_self();
-
- pthread_mutex_lock(&executor->mutex);
- bool execute = false;
- if (!executor->runningThreadSet) {
- executor->runningThread = currentThread;
- executor->runningThreadSet = true;
- execute = true;
- }
- pthread_mutex_unlock(&executor->mutex);
- if (execute) {
- executor_runTasks(executor, currentThread);
- }
-
- return status;
-}
-
-celix_status_t executor_runTasks(dm_executor_pt executor, pthread_t currentThread __attribute__((unused))) {
- celix_status_t status = CELIX_SUCCESS;
-// bool execute = false;
-
- do {
- struct dm_executor_task *entry = NULL;
- pthread_mutex_lock(&executor->mutex);
- while ((entry = linkedList_removeFirst(executor->workQueue)) != NULL) {
- pthread_mutex_unlock(&executor->mutex);
-
- entry->command(entry->component, entry->data);
-
- pthread_mutex_lock(&executor->mutex);
-
- free(entry);
- }
- executor->runningThreadSet = false;
- pthread_mutex_unlock(&executor->mutex);
-
-// pthread_mutex_lock(&executor->mutex);
-// if (executor->runningThread == NULL) {
-// executor->runningThread = currentThread;
-// execute = true;
-// }
-// pthread_mutex_unlock(&executor->mutex);
- } while (!linkedList_isEmpty(executor->workQueue)); // && execute
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/private/src/dm_dependency_manager_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/src/dm_dependency_manager_impl.c b/dependency_manager_2/private/src/dm_dependency_manager_impl.c
deleted file mode 100644
index 28b49e9..0000000
--- a/dependency_manager_2/private/src/dm_dependency_manager_impl.c
+++ /dev/null
@@ -1,91 +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.
- */
-
-/*
- * dm_dependency_manager_impl.c
- *
- * \date 26 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-
-#include <pthread.h>
-#include <stdlib.h>
-
-#include "bundle_context.h"
-#include "dm_component_impl.h"
-
-struct dm_dependency_manager {
- array_list_pt components;
-
- pthread_mutex_t mutex;
-};
-
-celix_status_t dependencyManager_create(bundle_context_pt context __attribute__((unused)), dm_dependency_manager_pt *manager) {
- celix_status_t status = CELIX_ENOMEM;
-
- (*manager) = calloc(1, sizeof(**manager));
-
- if (*manager) {
- arrayList_create(&(*manager)->components);
-
- status = CELIX_SUCCESS;
- }
-
- return status;
-
-}
-
-celix_status_t dependencyManager_destroy(dm_dependency_manager_pt *manager) {
- celix_status_t status = CELIX_SUCCESS;
-
- arrayList_destroy((*manager)->components);
-
- free(*manager);
- (*manager) = NULL;
-
- return status;
-}
-
-celix_status_t dependencyManager_add(dm_dependency_manager_pt manager, dm_component_pt component) {
- celix_status_t status;
-
- arrayList_add(manager->components, component);
- status = component_start(component);
-
- return status;
-}
-
-celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_component_pt component) {
- celix_status_t status;
-
- arrayList_removeElement(manager->components, component);
- status = component_stop(component);
-
- return status;
-}
-
-celix_status_t dependencyManager_getComponents(dm_dependency_manager_pt manager, array_list_pt* components) {
- celix_status_t status = CELIX_SUCCESS;
-
- (*components) = manager->components;
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/private/src/dm_event.c
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/src/dm_event.c b/dependency_manager_2/private/src/dm_event.c
deleted file mode 100644
index 60b7892..0000000
--- a/dependency_manager_2/private/src/dm_event.c
+++ /dev/null
@@ -1,92 +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.
- */
-
-/*
- * dm_event.c
- *
- * \date 18 Dec 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-
-#include "dm_event.h"
-
-celix_status_t event_create(dm_event_type_e event_type, bundle_pt bundle, bundle_context_pt context, service_reference_pt reference, void *service, dm_event_pt *event) {
- celix_status_t status = CELIX_SUCCESS;
-
- *event = calloc(1, sizeof(**event));
- if (!*event) {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- (*event)->bundle = bundle;
- (*event)->event_type = event_type;
- (*event)->context = context;
- (*event)->reference = reference;
- (*event)->service = service;
- }
-
- return status;
-}
-
-celix_status_t event_destroy(dm_event_pt *event) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!*event) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- free(*event);
- *event = NULL;
- }
-
- return status;
-}
-
-celix_status_t event_equals(void *a, void *b, bool *equals) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!a || !b) {
- *equals = false;
- } else {
- dm_event_pt a_ptr = a;
- dm_event_pt b_ptr = b;
-
- status = serviceReference_equals(a_ptr->reference, b_ptr->reference, equals);
- }
-
- return status;
-}
-
-celix_status_t event_compareTo(dm_event_pt event, dm_event_pt compareTo, int *compare) {
- celix_status_t status;
-
- status = serviceReference_compareTo(event->reference, compareTo->reference, compare);
-
- return status;
-}
-
-celix_status_t event_getService(dm_event_pt event, void **service) {
- *service = event->service;
- return CELIX_SUCCESS;
-}
[19/21] celix git commit: CELIX-269: Fixed a warning and some cmake
issue under mac
Posted by pn...@apache.org.
CELIX-269: Fixed a warning and some cmake issue under mac
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/f5a3cdd1
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/f5a3cdd1
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/f5a3cdd1
Branch: refs/heads/develop
Commit: f5a3cdd1aca80378d0bde8df1398c8ab30eafa95
Parents: 59c8e5d
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Nov 2 19:40:57 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Nov 2 19:40:57 2015 +0100
----------------------------------------------------------------------
CMakeLists.txt | 5 ++++-
dependency_manager/CMakeLists.txt | 3 +++
dependency_manager/private/src/dm_event.c | 2 +-
examples/dm_example/deploy.cmake | 4 ++--
4 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/f5a3cdd1/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d91418d..2a390f8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,7 +35,10 @@ IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} EQUAL 3.3 AND ${CMAKE_GENERATO
ENDIF()
IF(UNIX)
- SET(CMAKE_C_FLAGS "-D_GNU_SOURCE -std=gnu99 -Wall -pthread ${CMAKE_C_FLAGS}")
+ SET(CMAKE_C_FLAGS "-D_GNU_SOURCE -std=gnu99 -Wall ${CMAKE_C_FLAGS}")
+ENDIF()
+IF(UNIX AND NOT APPLE)
+ SET(CMAKE_C_FLAGS "-pthread ${CMAKE_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-pthread ${CMAKE_EXE_LINKER_FLAGS}")
ENDIF()
IF(WIN32)
http://git-wip-us.apache.org/repos/asf/celix/blob/f5a3cdd1/dependency_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dependency_manager/CMakeLists.txt b/dependency_manager/CMakeLists.txt
index e4aeca1..7e86931 100644
--- a/dependency_manager/CMakeLists.txt
+++ b/dependency_manager/CMakeLists.txt
@@ -41,6 +41,9 @@ if (DEPENDENCY_MANAGER)
private/src/dm_shell_activator
private/src/dm_shell_list_command
)
+ target_link_libraries(dm_shell celix_framework celix_utils)
+
+
add_library(dependency_manager STATIC
private/src/dm_activator_base
private/src/dm_component_impl
http://git-wip-us.apache.org/repos/asf/celix/blob/f5a3cdd1/dependency_manager/private/src/dm_event.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_event.c b/dependency_manager/private/src/dm_event.c
index 3fc7241..491c69f 100644
--- a/dependency_manager/private/src/dm_event.c
+++ b/dependency_manager/private/src/dm_event.c
@@ -92,7 +92,7 @@ celix_status_t event_equals(void *a, void *b, bool *equals) {
}
celix_status_t event_compareTo(dm_event_pt event, dm_event_pt compareTo, int *compare) {
- celix_status_t status;
+ celix_status_t status = CELIX_SUCCESS;
*compare = utils_compareServiceIdsAndRanking(event->serviceId, event->ranking, compareTo->serviceId, compareTo->ranking);
http://git-wip-us.apache.org/repos/asf/celix/blob/f5a3cdd1/examples/dm_example/deploy.cmake
----------------------------------------------------------------------
diff --git a/examples/dm_example/deploy.cmake b/examples/dm_example/deploy.cmake
index 9cf2c10..47072f4 100644
--- a/examples/dm_example/deploy.cmake
+++ b/examples/dm_example/deploy.cmake
@@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-if (BUILD_DEPENDENCY_MANAGER AND BUILD_SHELL AND BUILD_SHELL_TUI)
+if (BUILD_EXAMPLES AND BUILD_DEPENDENCY_MANAGER AND BUILD_SHELL AND BUILD_SHELL_TUI)
deploy("dm_example"
BUNDLES
phase1
@@ -25,5 +25,5 @@ if (BUILD_DEPENDENCY_MANAGER AND BUILD_SHELL AND BUILD_SHELL_TUI)
shell_tui
dm_shell
)
-endif()
+endif ()
[06/21] celix git commit: CELIX-210: Added licence headers to source
files.
Posted by pn...@apache.org.
CELIX-210: Added licence headers to source files.
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/b2ed1882
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/b2ed1882
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/b2ed1882
Branch: refs/heads/develop
Commit: b2ed18827e6892bf5845a203fcaf7bab88c6eff2
Parents: 9203fdd
Author: Erjan Altena <er...@nl.thalesgroup.com>
Authored: Fri Oct 16 16:39:14 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Oct 19 20:44:59 2015 +0200
----------------------------------------------------------------------
.../include/dm_dependency_manager_impl.h | 25 +++++++++++++++++++
.../private/include/dm_server_impl.h | 26 ++++++++++++++++++++
.../include/dm_service_dependency_impl.h | 2 +-
.../private/include/dm_shell_list_command.h | 4 +--
.../private/src/dm_component_impl.c | 2 +-
dependency_manager/private/src/dm_server.c | 26 ++++++++++++++++++++
.../private/src/dm_shell_activator.c | 26 ++++++++++++++++++++
.../private/src/dm_shell_list_command.c | 4 +--
8 files changed, 109 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/b2ed1882/dependency_manager/private/include/dm_dependency_manager_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_dependency_manager_impl.h b/dependency_manager/private/include/dm_dependency_manager_impl.h
index 8a0cae8..3c9db01 100644
--- a/dependency_manager/private/include/dm_dependency_manager_impl.h
+++ b/dependency_manager/private/include/dm_dependency_manager_impl.h
@@ -1,3 +1,28 @@
+/**
+ *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.
+ */
+/*
+ * dm_dependency_manager_impl.h
+ *
+ * \date 15 Oct 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
#ifndef CELIX_DM_DEPENDENCY_MANAGER_IMPL_H
#define CELIX_DM_DEPENDENCY_MANAGER_IMPL_H
http://git-wip-us.apache.org/repos/asf/celix/blob/b2ed1882/dependency_manager/private/include/dm_server_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_server_impl.h b/dependency_manager/private/include/dm_server_impl.h
index f54aece..117c561 100644
--- a/dependency_manager/private/include/dm_server_impl.h
+++ b/dependency_manager/private/include/dm_server_impl.h
@@ -1,3 +1,29 @@
+/**
+ *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.
+ */
+/*
+ * dm_server_impl.h
+ *
+ * \date 16 Oct 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
#include "dm_server.h"
#include "dm_component.h"
#include "dm_component_impl.h"
http://git-wip-us.apache.org/repos/asf/celix/blob/b2ed1882/dependency_manager/private/include/dm_service_dependency_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_service_dependency_impl.h b/dependency_manager/private/include/dm_service_dependency_impl.h
index 0f80cef..7f2a736 100644
--- a/dependency_manager/private/include/dm_service_dependency_impl.h
+++ b/dependency_manager/private/include/dm_service_dependency_impl.h
@@ -19,7 +19,7 @@
/*
* dm_service_dependency_impl.h
*
- * \date 8 Oct 2014
+ * \date 16 Oct 2015
* \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
* \copyright Apache License, Version 2.0
*/
http://git-wip-us.apache.org/repos/asf/celix/blob/b2ed1882/dependency_manager/private/include/dm_shell_list_command.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_shell_list_command.h b/dependency_manager/private/include/dm_shell_list_command.h
index 28482e0..bbccdc1 100644
--- a/dependency_manager/private/include/dm_shell_list_command.h
+++ b/dependency_manager/private/include/dm_shell_list_command.h
@@ -17,9 +17,9 @@
*under the License.
*/
/*
- * help_command.c
+ * dm_shell_list_command.h
*
- * \date Aug 20, 2010
+ * \date Oct 16, 2015
* \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
* \copyright Apache License, Version 2.0
*/
http://git-wip-us.apache.org/repos/asf/celix/blob/b2ed1882/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index 801d426..bac73eb 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -120,7 +120,7 @@ celix_status_t component_create(bundle_context_pt context, dm_dependency_manager
(*component)->state = DM_CMP_STATE_INACTIVE;
(*component)->isStarted = false;
- (*component)->active = false;
+ (*component)->active = a;
(*component)->dependencyEvents = hashMap_create(NULL, NULL, NULL, NULL);
http://git-wip-us.apache.org/repos/asf/celix/blob/b2ed1882/dependency_manager/private/src/dm_server.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_server.c b/dependency_manager/private/src/dm_server.c
index 7f86d8d..2976cf6 100644
--- a/dependency_manager/private/src/dm_server.c
+++ b/dependency_manager/private/src/dm_server.c
@@ -1,3 +1,29 @@
+/**
+ *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.
+ */
+/*
+ * dm_component_impl.c
+ *
+ * \date 9 Oct 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
#include <stdlib.h>
#include "array_list.h"
http://git-wip-us.apache.org/repos/asf/celix/blob/b2ed1882/dependency_manager/private/src/dm_shell_activator.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_activator.c b/dependency_manager/private/src/dm_shell_activator.c
index 28b4784..7cdd561 100644
--- a/dependency_manager/private/src/dm_shell_activator.c
+++ b/dependency_manager/private/src/dm_shell_activator.c
@@ -1,3 +1,29 @@
+/**
+ *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.
+ */
+/*
+ * dm_shell_activator.c
+ *
+ * \date 16 Oct 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
#include "bundle_context.h"
#include "service_registration.h"
#include "command.h"
http://git-wip-us.apache.org/repos/asf/celix/blob/b2ed1882/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
index 06e5968..74460fa 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -17,9 +17,9 @@
*under the License.
*/
/*
- * help_command.c
+ * dm_shell_list_command.c
*
- * \date Aug 20, 2010
+ * \date Oct 16, 2015
* \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
* \copyright Apache License, Version 2.0
*/
[02/21] celix git commit: CELIX-210: renamed dep man 2 -> dep man 2.
Fixed whiteboard dep man example
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager_2/private/src/dm_service_dependency.c b/dependency_manager_2/private/src/dm_service_dependency.c
deleted file mode 100644
index 8f65ddb..0000000
--- a/dependency_manager_2/private/src/dm_service_dependency.c
+++ /dev/null
@@ -1,564 +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.
- */
-/*
- * dm_service_dependency.c
- *
- * \date 17 Oct 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "constants.h"
-
-#include "dm_service_dependency_impl.h"
-#include "dm_component_impl.h"
-
-static celix_status_t serviceDependency_addedService(void *_ptr, service_reference_pt reference, void *service);
-static celix_status_t serviceDependency_modifiedService(void *_ptr, service_reference_pt reference, void *service);
-static celix_status_t serviceDependency_removedService(void *_ptr, service_reference_pt reference, void *service);
-
-celix_status_t serviceDependency_create(dm_service_dependency_pt *dependency_ptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- *dependency_ptr = calloc(1, sizeof(**dependency_ptr));
- if (!*dependency_ptr) {
- status = CELIX_ENOMEM;
- } else {
- (*dependency_ptr)->component = NULL;
- (*dependency_ptr)->available = false;
- (*dependency_ptr)->instanceBound = false;
- (*dependency_ptr)->required = false;
-
- (*dependency_ptr)->add = NULL;
- (*dependency_ptr)->change = NULL;
- (*dependency_ptr)->remove = NULL;
- (*dependency_ptr)->swap = NULL;
-
- (*dependency_ptr)->add_with_ref = NULL;
- (*dependency_ptr)->change_with_ref = NULL;
- (*dependency_ptr)->remove_with_ref = NULL;
- (*dependency_ptr)->swap_with_ref = NULL;
-
- (*dependency_ptr)->autoConfigure = NULL;
-
- (*dependency_ptr)->isStarted = false;
-
- (*dependency_ptr)->tracked_service_name = NULL;
- (*dependency_ptr)->tracked_filter_unmodified = NULL;
- (*dependency_ptr)->tracked_filter = NULL;
-
- (*dependency_ptr)->tracker = NULL;
- (*dependency_ptr)->tracker_customizer = NULL;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_ptr) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!*dependency_ptr) {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- free((*dependency_ptr)->tracked_service_name);
- free((*dependency_ptr)->tracked_filter);
- free((*dependency_ptr)->tracked_filter_unmodified);
- free(*dependency_ptr);
- *dependency_ptr = NULL;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_lock(dm_service_dependency_pt dependency) {
- celixThreadMutex_lock(&dependency->lock);
- return CELIX_SUCCESS;
-}
-
-celix_status_t serviceDependency_unlock(dm_service_dependency_pt dependency) {
- celixThreadMutex_unlock(&dependency->lock);
- return CELIX_SUCCESS;
-}
-
-celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- dependency->required = required;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName, char *filter) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- if (serviceName != NULL) {
- dependency->tracked_service_name = strdup(serviceName);
- }
- if (filter != NULL) {
- dependency->tracked_filter_unmodified = strdup(filter);
- if (serviceName == NULL) {
- dependency->tracked_filter = strdup(filter);
- } else {
- size_t len = strlen(serviceName) + strlen(OSGI_FRAMEWORK_OBJECTCLASS) + strlen(filter) + 7;
- char new_filter[len];
- snprintf(new_filter, len, "(&(%s=%s)%s)", OSGI_FRAMEWORK_OBJECTCLASS, serviceName, filter);
- dependency->tracked_filter = strdup(new_filter);
- }
- } else {
- dependency->tracked_filter_unmodified = NULL;
- dependency->tracked_filter = NULL;
- }
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- dependency->add = add;
- dependency->change = change;
- dependency->remove = remove;
- dependency->swap = swap;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- dependency->add_with_ref = add;
- dependency->change_with_ref = change;
- dependency->remove_with_ref = remove;
- dependency->swap_with_ref = swap;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t *service_lock, void **field) {
- celix_status_t status = CELIX_SUCCESS;
-
- celix_thread_mutex_t lock;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- dependency->autoConfigure = field;
- celixThreadMutex_create(&lock, NULL);
- *service_lock = lock;
- dependency->lock = lock;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_setComponent(dm_service_dependency_pt dependency, dm_component_pt component) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- dependency->component = component;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_start(dm_service_dependency_pt dependency) {
- celix_status_t status = CELIX_SUCCESS;
- bundle_context_pt context = NULL;
-
- if (!dependency || !dependency->component || (!dependency->tracked_service_name && !dependency->tracked_filter)) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- status = component_getBundleContext(dependency->component, &context);
- if (!context) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- dependency->tracker_customizer = NULL;
- status = serviceTrackerCustomizer_create(dependency, NULL, serviceDependency_addedService, serviceDependency_modifiedService,
- serviceDependency_removedService, &dependency->tracker_customizer);
- }
-
- if (status == CELIX_SUCCESS) {
- if (dependency->tracked_filter) {
- status = serviceTracker_createWithFilter(context, dependency->tracked_filter, dependency->tracker_customizer, &dependency->tracker);
- } else if (dependency->tracked_service_name) {
- status = serviceTracker_create(context, dependency->tracked_service_name, dependency->tracker_customizer, &dependency->tracker);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_open(dependency->tracker);
- }
-
- if (status == CELIX_SUCCESS) {
- dependency->isStarted = true;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_stop(dm_service_dependency_pt dependency) {
- celix_status_t status = CELIX_SUCCESS;
- celix_status_t tmp_status;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- if (dependency->tracker) {
- tmp_status = serviceTracker_close(dependency->tracker);
- if (tmp_status != CELIX_SUCCESS) {
- status = tmp_status;
- }
- tmp_status = serviceTracker_destroy(dependency->tracker);
- if (tmp_status != CELIX_SUCCESS && status == CELIX_SUCCESS) {
- status = tmp_status;
- }
- }
- }
-
- if (status == CELIX_SUCCESS) {
- dependency->isStarted = false;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_setInstanceBound(dm_service_dependency_pt dependency, bool instanceBound) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- dependency->instanceBound = instanceBound;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_setAvailable(dm_service_dependency_pt dependency, bool available) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- dependency->available = available;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_invokeAdd(dm_service_dependency_pt dependency, dm_event_pt event) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- if (dependency->add) {
- dependency->add(dependency->component->implementation, event->service);
- }
- if (dependency->add_with_ref) {
- dependency->add_with_ref(dependency->component->implementation, event->reference, event->service);
- }
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_invokeChange(dm_service_dependency_pt dependency, dm_event_pt event) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- if (dependency->change) {
- dependency->change(dependency->component->implementation, event->service);
- }
- if (dependency->change_with_ref) {
- dependency->change_with_ref(dependency->component->implementation, event->reference, event->service);
- }
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_invokeRemove(dm_service_dependency_pt dependency, dm_event_pt event) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- if (dependency->remove) {
- dependency->remove(dependency->component->implementation, event->service);
- }
- if (dependency->remove_with_ref) {
- dependency->remove_with_ref(dependency->component->implementation, event->reference, event->service);
- }
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_invokeSwap(dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- if (dependency->swap) {
- dependency->swap(dependency->component->implementation, event->service, newEvent->service);
- }
- if (dependency->swap_with_ref) {
- dependency->swap_with_ref(dependency->component->implementation, event->reference, event->service, newEvent->reference, newEvent->service);
- }
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_isAvailable(dm_service_dependency_pt dependency, bool *available) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- *available = dependency->available;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_isRequired(dm_service_dependency_pt dependency, bool *required) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- *required = dependency->required;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_isInstanceBound(dm_service_dependency_pt dependency, bool *instanceBound) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- *instanceBound = dependency->instanceBound;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_isAutoConfig(dm_service_dependency_pt dependency, bool *autoConfig) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- *autoConfig = dependency->autoConfigure != NULL;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_getAutoConfig(dm_service_dependency_pt dependency, void ***autoConfigure) {
- celix_status_t status = CELIX_SUCCESS;
-
- if (!dependency) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- *autoConfigure = dependency->autoConfigure;
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_addedService(void *_ptr, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
- bundle_context_pt context = NULL;
- bundle_pt bundle = NULL;
- dm_event_pt event = NULL;
- dm_service_dependency_pt dependency = _ptr;
-
- if (!dependency || !reference || !service) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- status = component_getBundleContext(dependency->component, &context);
- if (!context) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- status = bundleContext_getBundle(context, &bundle);
- if (!bundle) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- status = event_create(DM_EVENT_ADDED, bundle, context, reference, service, &event);
- }
-
- if (status == CELIX_SUCCESS) {
- component_handleEvent(dependency->component, dependency, event);
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_modifiedService(void *_ptr, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
- bundle_context_pt context = NULL;
- bundle_pt bundle = NULL;
- dm_event_pt event = NULL;
- dm_service_dependency_pt dependency = _ptr;
-
- if (!dependency || !reference || !service) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- status = component_getBundleContext(dependency->component, &context);
- if (!context) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- status = bundleContext_getBundle(context, &bundle);
- if (!bundle) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- status = event_create(DM_EVENT_CHANGED, bundle, context, reference, service, &event);
- }
-
- if (status == CELIX_SUCCESS) {
- component_handleEvent(dependency->component, dependency, event);
- }
-
- return status;
-}
-
-celix_status_t serviceDependency_removedService(void *_ptr, service_reference_pt reference, void *service) {
- celix_status_t status = CELIX_SUCCESS;
- bundle_context_pt context = NULL;
- bundle_pt bundle = NULL;
- dm_event_pt event = NULL;
- dm_service_dependency_pt dependency = _ptr;
-
- if (!dependency || !reference || !service) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- status = component_getBundleContext(dependency->component, &context);
- if (!context) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- status = bundleContext_getBundle(context, &bundle);
- if (!bundle) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- status = event_create(DM_EVENT_REMOVED, bundle, context, reference, service, &event);
- }
-
- if (status == CELIX_SUCCESS) {
- component_handleEvent(dependency->component, dependency, event);
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/public/include/dm_activator_base.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/public/include/dm_activator_base.h b/dependency_manager_2/public/include/dm_activator_base.h
deleted file mode 100644
index 80196e2..0000000
--- a/dependency_manager_2/public/include/dm_activator_base.h
+++ /dev/null
@@ -1,41 +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.
- */
-
-/*
- * dm_activator_base.h
- *
- * \date 26 Jul 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-
-#ifndef DM_ACTIVATOR_BASE_H_
-#define DM_ACTIVATOR_BASE_H_
-
-#include "bundle_context.h"
-#include "celix_errno.h"
-#include "dm_dependency_manager.h"
-
-celix_status_t dm_create(bundle_context_pt context, void ** userData);
-celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager);
-celix_status_t dm_deinit(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager);
-celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt manager);
-
-#endif /* DM_ACTIVATOR_BASE_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/public/include/dm_component.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/public/include/dm_component.h b/dependency_manager_2/public/include/dm_component.h
deleted file mode 100644
index f98c3bb..0000000
--- a/dependency_manager_2/public/include/dm_component.h
+++ /dev/null
@@ -1,54 +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.
- */
-/*
- * dm_component.h
- *
- * \date 8 Oct 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef COMPONENT_H_
-#define COMPONENT_H_
-
-#include <bundle_context.h>
-#include <celix_errno.h>
-
-typedef struct dm_component *dm_component_pt;
-
-#include "dm_dependency_manager.h"
-#include "dm_service_dependency.h"
-
-typedef celix_status_t (*init_fpt)(void *userData);
-typedef celix_status_t (*start_fpt)(void *userData);
-typedef celix_status_t (*stop_fpt)(void *userData);
-typedef celix_status_t (*destroy_fpt)(void *userData);
-
-celix_status_t component_create(bundle_context_pt context, dm_dependency_manager_pt manager, dm_component_pt *component);
-celix_status_t component_destroy(dm_component_pt *component);
-
-celix_status_t component_addInterface(dm_component_pt component, char *serviceName, void *service, properties_pt properties);
-celix_status_t component_setImplementation(dm_component_pt component, void *implementation);
-
-celix_status_t component_addServiceDependency(dm_component_pt component, ...);
-celix_status_t component_removeServiceDependency(dm_component_pt component, dm_service_dependency_pt dependency);
-
-celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt, destroy_fpt);
-
-#endif /* COMPONENT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/public/include/dm_dependency_manager.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/public/include/dm_dependency_manager.h b/dependency_manager_2/public/include/dm_dependency_manager.h
deleted file mode 100644
index 4311d3a..0000000
--- a/dependency_manager_2/public/include/dm_dependency_manager.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.
- */
-/*
- * dm_dependency_manager.h
- *
- * \date 22 Feb 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef DM_DEPENDENCY_MANAGER_H_
-#define DM_DEPENDENCY_MANAGER_H_
-
-#include "bundle_context.h"
-#include "celix_errno.h"
-#include "array_list.h"
-
-typedef struct dm_dependency_manager *dm_dependency_manager_pt;
-
-#include "dm_component.h"
-
-celix_status_t dependencyManager_create(bundle_context_pt context, dm_dependency_manager_pt *manager);
-celix_status_t dependencyManager_destroy(dm_dependency_manager_pt *manager);
-
-celix_status_t dependencyManager_add(dm_dependency_manager_pt manager, dm_component_pt component);
-celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_component_pt component);
-celix_status_t dependencyManager_getComponents(dm_dependency_manager_pt manager, array_list_pt* components);
-
-#endif /* DM_DEPENDENCY_MANAGER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager_2/public/include/dm_service_dependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager_2/public/include/dm_service_dependency.h b/dependency_manager_2/public/include/dm_service_dependency.h
deleted file mode 100644
index e9a5513..0000000
--- a/dependency_manager_2/public/include/dm_service_dependency.h
+++ /dev/null
@@ -1,55 +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.
- */
-/*
- * dm_service_dependency.h
- *
- * \date 8 Oct 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef DM_SERVICE_DEPENDENCY_H_
-#define DM_SERVICE_DEPENDENCY_H_
-
-#include "celix_errno.h"
-
-typedef struct dm_service_dependency *dm_service_dependency_pt;
-
-#include "dm_component.h"
-
-typedef celix_status_t (*service_add_fpt)(void *handle, void *service);
-typedef celix_status_t (*service_change_fpt)(void *handle, void *service);
-typedef celix_status_t (*service_remove_fpt)(void *handle, void *service);
-typedef celix_status_t (*service_swap_fpt)(void *handle, void *oldService, void *newService);
-
-typedef celix_status_t (*service_add_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
-typedef celix_status_t (*service_change_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
-typedef celix_status_t (*service_remove_with_ref_fpt)(void *handle, service_reference_pt reference, void *service);
-typedef celix_status_t (*service_swap_with_ref_fpt)(void *handle, service_reference_pt oldReference, void *oldService, service_reference_pt newReference, void *newService);
-
-celix_status_t serviceDependency_create(dm_service_dependency_pt *dependency_ptr);
-celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_ptr);
-
-celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required);
-celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName, char *filter);
-celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap);
-celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap);
-celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t *service_lock, void **field);
-
-#endif /* DM_SERVICE_DEPENDENCY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/examples/whiteboard/tracker_depman/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/CMakeLists.txt b/examples/whiteboard/tracker_depman/CMakeLists.txt
index a9c3654..9cc1b07 100644
--- a/examples/whiteboard/tracker_depman/CMakeLists.txt
+++ b/examples/whiteboard/tracker_depman/CMakeLists.txt
@@ -25,15 +25,15 @@ bundle(tracker_depman SOURCES
private/include/tracker.h
)
include_directories("private/include")
-include_directories("${PROJECT_SOURCE_DIR}/dependency_manager_2/public/include")
-#include_directories("${PROJECT_SOURCE_DIR}/dependency_manager_2/private/include")
+include_directories("${PROJECT_SOURCE_DIR}/dependency_manager/public/include")
+#include_directories("${PROJECT_SOURCE_DIR}/dependency_manager/private/include")
include_directories("../publisherService/public/include")
include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
# Use some magic to include all symbols of the static library
IF(APPLE)
-target_link_libraries(tracker_depman celix_framework -Wl,-all_load dependency_manager2)
+target_link_libraries(tracker_depman celix_framework -Wl,-all_load dependency_manager)
else()
-target_link_libraries(tracker_depman -Wl,--whole-archive dependency_manager2 -Wl,--no-whole-archive celix_framework)
+target_link_libraries(tracker_depman -Wl,--whole-archive dependency_manager -Wl,--no-whole-archive celix_framework)
ENDIF()
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
index 1340751..84194f8 100644
--- a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
+++ b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
@@ -61,13 +61,13 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
serviceDependency_create(&dep);
serviceDependency_setRequired(dep, false);
serviceDependency_setService(dep, PUBLISHER_NAME, "(|(id=A)(id=B))");
- serviceDependency_setCallbacks(dep, tracker_addedServ, tracker_modifiedServ, tracker_removedServ, NULL);
+ serviceDependency_setCallbacksWithServiceReference(dep, tracker_addedServ, tracker_modifiedServ, tracker_removedServ, NULL);
component_addServiceDependency(service, dep, NULL);
serviceDependency_create(&dep2);
serviceDependency_setRequired(dep2, false);
serviceDependency_setService(dep2, (char *) OSGI_LOGSERVICE_NAME, NULL);
-// serviceDependency_setCallbacks(dep2, tracker_addLog, tracker_modifiedLog, tracker_removeLog, NULL);
+ serviceDependency_setCallbacksWithServiceReference(dep2, tracker_addLog, tracker_modifiedLog, tracker_removeLog, NULL);
serviceDependency_setAutoConfigure(dep2, &data->logger_lock, (void **) &data->logger);
component_addServiceDependency(service, dep2, NULL);
@@ -122,4 +122,4 @@ celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_depende
// } else {
// pthread_mutex_unlock(&lock);
// }
-//}
\ No newline at end of file
+//}
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/examples/whiteboard/tracker_depman/private/src/tracker.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/tracker.c b/examples/whiteboard/tracker_depman/private/src/tracker.c
index 0d26ad8..2605609 100644
--- a/examples/whiteboard/tracker_depman/private/src/tracker.c
+++ b/examples/whiteboard/tracker_depman/private/src/tracker.c
@@ -97,25 +97,25 @@ celix_status_t tracker_removedServ(void * handle, service_reference_pt ref, void
return CELIX_SUCCESS;
}
-//celix_status_t tracker_addLog(void *handle, service_reference_pt ref, void *service) {
-// struct data * data = (struct data *) handle;
-// printf("Add log\n");
-// data->logger = service;
-// ((log_service_pt) service)->log(((log_service_pt) service)->logger, OSGI_LOGSERVICE_DEBUG, "test");
-// return CELIX_SUCCESS;
-//}
-//
-//celix_status_t tracker_modifiedLog(void *handle, service_reference_pt ref, void *service) {
-// struct data * data = (struct data *) handle;
-// printf("Modify log\n");
-// data->logger = service;
-// ((log_service_pt) service)->log(((log_service_pt) service)->logger, OSGI_LOGSERVICE_DEBUG, "test");
-// return CELIX_SUCCESS;
-//}
-//
-//celix_status_t tracker_removeLog(void *handle, service_reference_pt ref, void *service) {
-// struct data * data = (struct data *) handle;
-// data->logger = NULL;
-// printf("Remove log\n");
-// return CELIX_SUCCESS;
-//}
+celix_status_t tracker_addLog(void *handle, service_reference_pt ref, void *service) {
+ struct data * data = (struct data *) handle;
+ printf("Add log\n");
+ data->logger = service;
+ ((log_service_pt) service)->log(((log_service_pt) service)->logger, OSGI_LOGSERVICE_DEBUG, "test");
+ return CELIX_SUCCESS;
+}
+
+celix_status_t tracker_modifiedLog(void *handle, service_reference_pt ref, void *service) {
+ struct data * data = (struct data *) handle;
+ printf("Modify log\n");
+ data->logger = service;
+ ((log_service_pt) service)->log(((log_service_pt) service)->logger, OSGI_LOGSERVICE_DEBUG, "test");
+ return CELIX_SUCCESS;
+}
+
+celix_status_t tracker_removeLog(void *handle, service_reference_pt ref, void *service) {
+ struct data * data = (struct data *) handle;
+ data->logger = NULL;
+ printf("Remove log\n");
+ return CELIX_SUCCESS;
+}
[04/21] celix git commit: CELIX-210: renamed dep man 2 -> dep man 2.
Fixed whiteboard dep man example
Posted by pn...@apache.org.
CELIX-210: renamed dep man 2 -> dep man 2. Fixed whiteboard dep man example
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/cc6fd432
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/cc6fd432
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/cc6fd432
Branch: refs/heads/develop
Commit: cc6fd432219484218bcb462e7974ee48c77930b4
Parents: a135fad
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Oct 12 10:45:10 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Oct 12 10:45:10 2015 +0200
----------------------------------------------------------------------
CMakeLists.txt | 2 +-
dependency_manager/CMakeLists.txt | 61 +
.../private/include/dm_component_impl.h | 84 ++
.../private/include/dm_dependency.h | 34 +
dependency_manager/private/include/dm_event.h | 63 +
.../include/dm_service_dependency_impl.h | 90 ++
.../private/src/dm_activator_base.c | 98 ++
.../private/src/dm_component_impl.c | 1277 ++++++++++++++++++
.../private/src/dm_dependency_manager_impl.c | 91 ++
dependency_manager/private/src/dm_event.c | 92 ++
.../private/src/dm_service_dependency.c | 564 ++++++++
.../public/include/dm_activator_base.h | 41 +
.../public/include/dm_component.h | 54 +
.../public/include/dm_dependency_manager.h | 45 +
.../public/include/dm_service_dependency.h | 55 +
dependency_manager_2/CMakeLists.txt | 61 -
.../private/include/dm_component_impl.h | 84 --
.../private/include/dm_dependency.h | 34 -
dependency_manager_2/private/include/dm_event.h | 63 -
.../include/dm_service_dependency_impl.h | 90 --
.../private/src/dm_activator_base.c | 98 --
.../private/src/dm_component_impl.c | 1277 ------------------
.../private/src/dm_dependency_manager_impl.c | 91 --
dependency_manager_2/private/src/dm_event.c | 92 --
.../private/src/dm_service_dependency.c | 564 --------
.../public/include/dm_activator_base.h | 41 -
.../public/include/dm_component.h | 54 -
.../public/include/dm_dependency_manager.h | 45 -
.../public/include/dm_service_dependency.h | 55 -
.../whiteboard/tracker_depman/CMakeLists.txt | 8 +-
.../private/src/dependency_activator.c | 6 +-
.../tracker_depman/private/src/tracker.c | 44 +-
32 files changed, 2679 insertions(+), 2679 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a885df5..6db8dd1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,7 +77,7 @@ add_subdirectory(log_writer)
add_subdirectory(log_service)
add_subdirectory(event_admin)
-add_subdirectory(dependency_manager_2)
+add_subdirectory(dependency_manager)
add_subdirectory(launcher)
add_subdirectory(framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dependency_manager/CMakeLists.txt b/dependency_manager/CMakeLists.txt
new file mode 100644
index 0000000..6b76658
--- /dev/null
+++ b/dependency_manager/CMakeLists.txt
@@ -0,0 +1,61 @@
+# 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.
+
+celix_subproject(DEPENDENCY_MANAGER "Option to build the dependency manager static library" ON DEPS framework)
+if (DEPENDENCY_MANAGER)
+ # Add -fPIC for x86_64 Unix platforms; this lib will be linked to a shared lib
+ if(UNIX AND NOT WIN32)
+ find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
+ if(CMAKE_UNAME)
+ exec_program(uname ARGS -m OUTPUT_VARIABLE CMAKE_SYSTEM_PROCESSOR)
+ set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR} CACHE INTERNAL "processor type (i386 and x86_64)")
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
+ add_definitions(-fPIC)
+ endif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
+ endif(CMAKE_UNAME)
+ endif(UNIX AND NOT WIN32)
+
+ CELIX_ADD_COMPONENT(dependency_manager
+ DISPLAY_NAME Dependency Manager
+ DESCRIPTION "The Apache Celix dependency manager (static) library"
+ GROUP all
+ )
+
+ add_library(dependency_manager STATIC
+ private/src/dm_activator_base
+ private/src/dm_component_impl
+ private/src/dm_service_dependency
+ private/src/dm_event
+ private/src/dm_dependency_manager_impl)
+ include_directories("public/include")
+ include_directories("private/include")
+ include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+ target_link_libraries(dependency_manager celix_framework)
+
+ install(
+ FILES
+ public/include/dm_activator_base.h
+ public/include/dm_component.h
+ public/include/dm_dependency_manager.h
+ public/include/dm_service_dependency.h
+ DESTINATION
+ include/celix/dependency_manager
+ COMPONENT
+ dependency_manager
+ )
+ install(TARGETS dependency_manager DESTINATION lib COMPONENT dependency_manager)
+endif (DEPENDENCY_MANAGER)
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/private/include/dm_component_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_component_impl.h b/dependency_manager/private/include/dm_component_impl.h
new file mode 100644
index 0000000..133ef06
--- /dev/null
+++ b/dependency_manager/private/include/dm_component_impl.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.
+ */
+/*
+ * dm_component_impl.h
+ *
+ * \date 22 Feb 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef COMPONENT_IMPL_H_
+#define COMPONENT_IMPL_H_
+
+#include "dm_component.h"
+
+#include "dm_service_dependency_impl.h"
+
+#include "dm_event.h"
+
+typedef enum dm_component_state {
+ DM_CMP_STATE_INACTIVE = 1,
+ DM_CMP_STATE_WAITING_FOR_REQUIRED,
+ DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED,
+ DM_CMP_STATE_TRACKING_OPTIONAL,
+} dm_component_state_pt;
+
+typedef struct dm_executor * dm_executor_pt;
+
+typedef struct dm_interface_struct {
+ char *serviceName;
+ void *service;
+ properties_pt properties;
+ service_registration_pt registration;
+} dm_interface;
+
+struct dm_component {
+ bundle_context_pt context;
+ dm_dependency_manager_pt manager;
+
+ array_list_pt dm_interface;
+
+ void *implementation;
+
+ init_fpt callbackInit;
+ start_fpt callbackStart;
+ stop_fpt callbackStop;
+ destroy_fpt callbackDestroy;
+
+ array_list_pt dependencies;
+ pthread_mutex_t mutex;
+
+ dm_component_state_pt state;
+ bool isStarted;
+ bool active;
+
+ hash_map_pt dependencyEvents;
+
+ dm_executor_pt executor;
+};
+
+celix_status_t component_start(dm_component_pt component);
+celix_status_t component_stop(dm_component_pt component);
+
+celix_status_t component_getBundleContext(dm_component_pt component, bundle_context_pt *context);
+
+celix_status_t component_handleEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
+
+#endif /* COMPONENT_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/private/include/dm_dependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_dependency.h b/dependency_manager/private/include/dm_dependency.h
new file mode 100644
index 0000000..e7ad5fb
--- /dev/null
+++ b/dependency_manager/private/include/dm_dependency.h
@@ -0,0 +1,34 @@
+/**
+ *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.
+ */
+/*
+ * dm_dependency.h
+ *
+ * \date 22 Feb 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef DM_DEPENDENCY_H_
+#define DM_DEPENDENCY_H_
+
+
+
+
+
+#endif /* DM_DEPENDENCY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/private/include/dm_event.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_event.h b/dependency_manager/private/include/dm_event.h
new file mode 100644
index 0000000..8e23721
--- /dev/null
+++ b/dependency_manager/private/include/dm_event.h
@@ -0,0 +1,63 @@
+/**
+ *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.
+ */
+/*
+ * dm_event.h
+ *
+ * \date 17 Oct 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef DM_EVENT_H_
+#define DM_EVENT_H_
+
+#include "service_reference.h"
+#include "bundle_context.h"
+#include "bundle.h"
+
+enum dm_event_type {
+ DM_EVENT_ADDED,
+ DM_EVENT_CHANGED,
+ DM_EVENT_REMOVED,
+ DM_EVENT_SWAPPED,
+};
+
+typedef enum dm_event_type dm_event_type_e;
+
+struct dm_event {
+ void *service;
+ service_reference_pt reference;
+ bundle_context_pt context;
+ bundle_pt bundle;
+ dm_event_type_e event_type;
+};
+
+typedef struct dm_event *dm_event_pt;
+
+
+celix_status_t event_create(dm_event_type_e event_type, bundle_pt bundle, bundle_context_pt context, service_reference_pt reference, void *service, dm_event_pt *event);
+celix_status_t event_destroy(dm_event_pt *event);
+
+celix_status_t event_equals(void *a, void *b, bool *equals);
+
+celix_status_t event_getService(dm_event_pt event, void **service);
+celix_status_t event_compareTo(dm_event_pt event, dm_event_pt compareTo, int *compare);
+
+
+#endif /* DM_EVENT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/private/include/dm_service_dependency_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_service_dependency_impl.h b/dependency_manager/private/include/dm_service_dependency_impl.h
new file mode 100644
index 0000000..1396f31
--- /dev/null
+++ b/dependency_manager/private/include/dm_service_dependency_impl.h
@@ -0,0 +1,90 @@
+/**
+ *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.
+ */
+/*
+ * dm_service_dependency_impl.h
+ *
+ * \date 8 Oct 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef DM_SERVICE_DEPENDENCY_IMPL_H_
+#define DM_SERVICE_DEPENDENCY_IMPL_H_
+
+#include <stdbool.h>
+
+#include "dm_event.h"
+#include "service_tracker.h"
+#include "service_tracker_customizer.h"
+
+#include "dm_service_dependency.h"
+
+struct dm_service_dependency {
+ dm_component_pt component;
+ bool available;
+ bool instanceBound;
+ bool required;
+
+ service_add_fpt add;
+ service_change_fpt change;
+ service_remove_fpt remove;
+ service_swap_fpt swap;
+
+ service_add_with_ref_fpt add_with_ref;
+ service_change_with_ref_fpt change_with_ref;
+ service_remove_with_ref_fpt remove_with_ref;
+ service_swap_with_ref_fpt swap_with_ref;
+
+ void **autoConfigure;
+ celix_thread_mutex_t lock;
+
+ bool isStarted;
+
+ char *tracked_service_name;
+ char *tracked_filter_unmodified;
+ char *tracked_filter;
+
+ service_tracker_pt tracker;
+ service_tracker_customizer_pt tracker_customizer;
+};
+
+celix_status_t serviceDependency_start(dm_service_dependency_pt dependency);
+celix_status_t serviceDependency_stop(dm_service_dependency_pt dependency);
+celix_status_t serviceDependency_setInstanceBound(dm_service_dependency_pt dependency, bool instanceBound);
+celix_status_t serviceDependency_setAutoConfig(dm_service_dependency_pt dependency, void **autoConfigure);
+celix_status_t serviceDependency_setAvailable(dm_service_dependency_pt dependency, bool available);
+
+celix_status_t serviceDependency_setComponent(dm_service_dependency_pt dependency, dm_component_pt component);
+//celix_status_t serviceDependency_removeComponent(dm_service_dependency_pt dependency, dm_component_pt component);
+
+celix_status_t serviceDependency_invokeAdd(dm_service_dependency_pt dependency, dm_event_pt event);
+celix_status_t serviceDependency_invokeChange(dm_service_dependency_pt dependency, dm_event_pt event);
+celix_status_t serviceDependency_invokeRemove(dm_service_dependency_pt dependency, dm_event_pt event);
+celix_status_t serviceDependency_invokeSwap(dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent);
+celix_status_t serviceDependency_isAvailable(dm_service_dependency_pt dependency, bool *available);
+celix_status_t serviceDependency_isRequired(dm_service_dependency_pt dependency, bool *required);
+celix_status_t serviceDependency_isInstanceBound(dm_service_dependency_pt dependency, bool *instanceBound);
+celix_status_t serviceDependency_isAutoConfig(dm_service_dependency_pt dependency, bool *autoConfig);
+
+celix_status_t serviceDependency_getAutoConfig(dm_service_dependency_pt dependency, void ***autoConfigure);
+celix_status_t serviceDependency_unlock(dm_service_dependency_pt dependency);
+celix_status_t serviceDependency_lock(dm_service_dependency_pt dependency);
+
+
+#endif /* DM_SERVICE_DEPENDENCY_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/private/src/dm_activator_base.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_activator_base.c b/dependency_manager/private/src/dm_activator_base.c
new file mode 100644
index 0000000..a97194e
--- /dev/null
+++ b/dependency_manager/private/src/dm_activator_base.c
@@ -0,0 +1,98 @@
+/**
+ * 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.
+ */
+
+/*
+ * dm_activator_base.c
+ *
+ * \date 26 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+
+#include <stdlib.h>
+
+#include "bundle_activator.h"
+#include "dm_activator_base.h"
+
+
+struct dm_dependency_activator_base {
+ dm_dependency_manager_pt manager;
+ bundle_context_pt context;
+ void* userData;
+};
+
+typedef struct dm_dependency_activator_base * dependency_activator_base_pt;
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ celix_status_t status = CELIX_ENOMEM;
+
+ dependency_activator_base_pt dependency_activator = calloc(1, sizeof(struct dm_dependency_activator_base));
+
+ if (dependency_activator) {
+ dependency_activator->context = context;
+ dm_create(context, &dependency_activator->userData);
+
+ (*userData) = dependency_activator;
+
+ status = CELIX_SUCCESS;
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+ celix_status_t status;
+ dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
+
+ status = dependencyManager_create(dependency_activator->context, &dependency_activator->manager);
+
+ if (status == CELIX_SUCCESS) {
+ dm_init(dependency_activator->userData, context, dependency_activator->manager);
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context __attribute__((unused))) {
+ celix_status_t status = CELIX_SUCCESS;
+ dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
+
+ dm_deinit(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
+
+ dependencyManager_destroy(&dependency_activator->manager);
+
+ dependency_activator->userData = NULL;
+ dependency_activator->manager = NULL;
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context __attribute__((unused))) {
+ celix_status_t status = CELIX_SUCCESS;
+ dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
+
+ dm_destroy(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
+
+ free(dependency_activator);
+
+ return status;
+}
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
new file mode 100644
index 0000000..72fe7eb
--- /dev/null
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -0,0 +1,1277 @@
+/**
+ *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.
+ */
+/*
+ * dm_component_impl.c
+ *
+ * \date 9 Oct 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "dm_component_impl.h"
+#include "../../../framework/private/include/framework_private.h"
+
+struct dm_executor {
+ pthread_t runningThread;
+ bool runningThreadSet;
+ linked_list_pt workQueue;
+
+ pthread_mutex_t mutex;
+};
+
+struct dm_executor_task {
+ dm_component_pt component;
+ void (*command)(void *command_ptr, void *data);
+ void *data;
+};
+
+struct dm_handle_event_type {
+ dm_service_dependency_pt dependency;
+ dm_event_pt event;
+ dm_event_pt newEvent;
+};
+
+typedef struct dm_handle_event_type *dm_handle_event_type_pt;
+
+static celix_status_t executor_runTasks(dm_executor_pt executor, pthread_t currentThread __attribute__((unused)));
+static celix_status_t executor_execute(dm_executor_pt executor);
+static celix_status_t executor_executeTask(dm_executor_pt executor, dm_component_pt component, void (*command), void *data);
+static celix_status_t executor_schedule(dm_executor_pt executor, dm_component_pt component, void (*command), void *data);
+static celix_status_t executor_create(dm_component_pt component __attribute__((unused)), dm_executor_pt *executor);
+static celix_status_t executor_destroy(dm_executor_pt *executor);
+
+static celix_status_t component_destroyComponent(dm_component_pt component);
+static celix_status_t component_invokeRemoveRequiredDependencies(dm_component_pt component);
+static celix_status_t component_invokeRemoveInstanceBoundDependencies(dm_component_pt component);
+static celix_status_t component_invokeRemoveOptionalDependencies(dm_component_pt component);
+static celix_status_t component_registerService(dm_component_pt component);
+static celix_status_t component_unregisterService(dm_component_pt component);
+static celix_status_t component_invokeAddOptionalDependencies(dm_component_pt component);
+static celix_status_t component_invokeAddRequiredInstanceBoundDependencies(dm_component_pt component);
+static celix_status_t component_invokeAddRequiredDependencies(dm_component_pt component);
+static celix_status_t component_invokeAutoConfigInstanceBoundDependencies(dm_component_pt component);
+static celix_status_t component_invokeAutoConfigDependencies(dm_component_pt component);
+static celix_status_t component_configureImplementation(dm_component_pt component, dm_service_dependency_pt dependency);
+static celix_status_t component_allInstanceBoundAvailable(dm_component_pt component, bool *available);
+static celix_status_t component_allRequiredAvailable(dm_component_pt component, bool *available);
+static celix_status_t component_performTransition(dm_component_pt component, dm_component_state_pt oldState, dm_component_state_pt newState, bool *transition);
+static celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_pt currentState, dm_component_state_pt *newState);
+static celix_status_t component_handleChange(dm_component_pt component);
+static celix_status_t component_startDependencies(dm_component_pt component __attribute__((unused)), array_list_pt dependencies);
+static celix_status_t component_getDependencyEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt *event_pptr);
+static celix_status_t component_updateInstance(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, bool update, bool add);
+
+static celix_status_t component_addTask(dm_component_pt component, array_list_pt dependencies);
+static celix_status_t component_startTask(dm_component_pt component, void * data __attribute__((unused)));
+static celix_status_t component_stopTask(dm_component_pt component, void * data __attribute__((unused)));
+static celix_status_t component_removeTask(dm_component_pt component, dm_service_dependency_pt dependency);
+static celix_status_t component_handleEventTask(dm_component_pt component, dm_handle_event_type_pt data);
+
+static celix_status_t component_handleAdded(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
+static celix_status_t component_handleChanged(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
+static celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
+static celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent);
+
+celix_status_t component_create(bundle_context_pt context, dm_dependency_manager_pt manager, dm_component_pt *component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *component = malloc(sizeof(**component));
+ if (!*component) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*component)->context = context;
+ (*component)->manager = manager;
+
+ arrayList_create(&((*component)->dm_interface));
+
+ (*component)->implementation = NULL;
+
+ (*component)->callbackInit = NULL;
+ (*component)->callbackStart = NULL;
+ (*component)->callbackStop = NULL;
+ (*component)->callbackDestroy = NULL;
+
+
+ arrayList_create(&(*component)->dependencies);
+ pthread_mutex_init(&(*component)->mutex, NULL);
+
+ (*component)->state = DM_CMP_STATE_INACTIVE;
+ (*component)->isStarted = false;
+ (*component)->active = false;
+
+ (*component)->dependencyEvents = hashMap_create(NULL, NULL, NULL, NULL);
+
+ (*component)->executor = NULL;
+ executor_create(*component, &(*component)->executor);
+ }
+
+ return status;
+}
+
+celix_status_t component_destroy(dm_component_pt *component_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!*component_ptr) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ unsigned int i;
+
+ for (i = 0; i < arrayList_size((*component_ptr)->dm_interface); i++) {
+ dm_interface *interface = arrayList_get((*component_ptr)->dm_interface, i);
+
+ free (interface->serviceName);
+ }
+ arrayList_destroy((*component_ptr)->dm_interface);
+
+ // #TODO destroy dependencies?
+ executor_destroy(&(*component_ptr)->executor);
+ hashMap_destroy((*component_ptr)->dependencyEvents, false, false);
+ pthread_mutex_destroy(&(*component_ptr)->mutex);
+ arrayList_destroy((*component_ptr)->dependencies);
+
+ free(*component_ptr);
+ *component_ptr = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t component_addServiceDependency(dm_component_pt component, ...) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ array_list_pt dependenciesList = NULL;
+ arrayList_create(&dependenciesList);
+
+ va_list dependencies;
+ va_start(dependencies, component);
+ dm_service_dependency_pt dependency = va_arg(dependencies, dm_service_dependency_pt);
+ while (dependency != NULL) {
+ arrayList_add(dependenciesList, dependency);
+
+
+ dependency = va_arg(dependencies, dm_service_dependency_pt);
+ }
+
+ va_end(dependencies);
+
+ executor_executeTask(component->executor, component, component_addTask, dependenciesList);
+// component_addTask(component, dependenciesList);
+
+ return status;
+}
+
+
+celix_status_t component_addTask(dm_component_pt component, array_list_pt dependencies) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ array_list_pt bounds = NULL;
+ arrayList_create(&bounds);
+ for (unsigned int i = 0; i < arrayList_size(dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(dependencies, i);
+
+ pthread_mutex_lock(&component->mutex);
+ array_list_pt events = NULL;
+ arrayList_createWithEquals(event_equals, &events);
+ hashMap_put(component->dependencyEvents, dependency, events);
+
+ arrayList_add(component->dependencies, dependency);
+ pthread_mutex_unlock(&component->mutex);
+
+ serviceDependency_setComponent(dependency, component);
+ if (component->state != DM_CMP_STATE_INACTIVE) {
+ serviceDependency_setInstanceBound(dependency, true);
+ arrayList_add(bounds, dependency);
+ }
+ component_startDependencies(component, bounds);
+ component_handleChange(component);
+ }
+
+ arrayList_destroy(bounds);
+ arrayList_destroy(dependencies);
+
+ return status;
+}
+
+celix_status_t component_removeServiceDependency(dm_component_pt component, dm_service_dependency_pt dependency) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ executor_executeTask(component->executor, component, component_removeTask, dependency);
+// component_removeTask(component, dependency);
+
+ return status;
+}
+
+celix_status_t component_removeTask(dm_component_pt component, dm_service_dependency_pt dependency) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ arrayList_removeElement(component->dependencies, dependency);
+ pthread_mutex_unlock(&component->mutex);
+
+ if (component->state != DM_CMP_STATE_INACTIVE) {
+ serviceDependency_stop(dependency);
+ }
+
+ pthread_mutex_lock(&component->mutex);
+ array_list_pt events = hashMap_remove(component->dependencyEvents, dependency);
+ for (unsigned int i = arrayList_size(events); i > 0; i--) {
+ dm_event_pt event = arrayList_remove(events, i - 1);
+ event_destroy(&event);
+ }
+ arrayList_destroy(events);
+ pthread_mutex_unlock(&component->mutex);
+
+ component_handleChange(component);
+
+ return status;
+}
+
+celix_status_t component_start(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ component->active = true;
+ executor_executeTask(component->executor, component, component_startTask, NULL);
+// component_startTask(component, NULL);
+
+ return status;
+}
+
+celix_status_t component_startTask(dm_component_pt component, void *data __attribute__((unused))) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ component->isStarted = true;
+ component_handleChange(component);
+
+ return status;
+}
+
+celix_status_t component_stop(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ component->active = false;
+ executor_executeTask(component->executor, component, component_stopTask, NULL);
+// component_stopTask(component, NULL);
+
+ return status;
+}
+
+celix_status_t component_stopTask(dm_component_pt component, void *data __attribute__((unused))) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ component->isStarted = false;
+ component_handleChange(component);
+ component->active = false;
+
+ return status;
+}
+
+celix_status_t component_addInterface(dm_component_pt component, char *serviceName, void *service, properties_pt properties) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (component->active) {
+ return CELIX_ILLEGAL_STATE;
+ } else {
+ dm_interface *interface = (dm_interface *) malloc (sizeof (dm_interface));
+ char *name = strdup (serviceName);
+
+ if (interface && name) {
+ interface->serviceName = name;
+ interface->service = service;
+ interface->properties = properties;
+ interface->registration = NULL;
+ arrayList_add(component->dm_interface, interface);
+ }
+ else {
+ free (interface);
+ free (name);
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ return status;
+}
+
+celix_status_t component_handleEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ dm_handle_event_type_pt data = calloc(1, sizeof(*data));
+ data->dependency = dependency;
+ data->event = event;
+ data->newEvent = NULL;
+
+ status = executor_executeTask(component->executor, component, component_handleEventTask, data);
+// component_handleEventTask(component, data);
+
+ return status;
+}
+
+celix_status_t component_handleEventTask(dm_component_pt component, dm_handle_event_type_pt data) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ switch (data->event->event_type) {
+ case DM_EVENT_ADDED:
+ component_handleAdded(component,data->dependency, data->event);
+ break;
+ case DM_EVENT_CHANGED:
+ component_handleChanged(component,data->dependency, data->event);
+ break;
+ case DM_EVENT_REMOVED:
+ component_handleRemoved(component,data->dependency, data->event);
+ break;
+ case DM_EVENT_SWAPPED:
+ component_handleSwapped(component,data->dependency, data->event, data->newEvent);
+ break;
+ default:
+ break;
+ }
+
+ free(data);
+
+ return status;
+}
+
+celix_status_t component_handleAdded(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ arrayList_add(events, event);
+ pthread_mutex_unlock(&component->mutex);
+
+ serviceDependency_setAvailable(dependency, true);
+
+ switch (component->state) {
+ case DM_CMP_STATE_WAITING_FOR_REQUIRED: {
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
+ if (required) {
+ component_handleChange(component);
+ }
+ break;
+ }
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
+ bool instanceBound = false;
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+ if (!instanceBound) {
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
+ if (required) {
+ serviceDependency_invokeAdd(dependency, event);
+ }
+ dm_event_pt event = NULL;
+ component_getDependencyEvent(component, dependency, &event);
+ component_updateInstance(component, dependency, event, false, true);
+ } else {
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
+ if (required) {
+ component_handleChange(component);
+ }
+ }
+ break;
+ }
+ case DM_CMP_STATE_TRACKING_OPTIONAL:
+ serviceDependency_invokeAdd(dependency, event);
+ dm_event_pt event = NULL;
+ component_getDependencyEvent(component, dependency, &event);
+ component_updateInstance(component, dependency, event, false, true);
+ break;
+ default:
+ break;
+ }
+
+ return status;
+}
+
+celix_status_t component_handleChanged(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ int index = arrayList_indexOf(events, event);
+ if (index < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ dm_event_pt old = arrayList_remove(events, (unsigned int) index);
+ arrayList_add(events, event);
+ pthread_mutex_unlock(&component->mutex);
+
+ switch (component->state) {
+ case DM_CMP_STATE_TRACKING_OPTIONAL:
+ serviceDependency_invokeChange(dependency, event);
+ dm_event_pt hevent = NULL;
+ component_getDependencyEvent(component, dependency, &hevent);
+ component_updateInstance(component, dependency, hevent, true, false);
+ break;
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
+ bool instanceBound = false;
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+ if (!instanceBound) {
+ serviceDependency_invokeChange(dependency, event);
+ dm_event_pt hevent = NULL;
+ component_getDependencyEvent(component, dependency, &hevent);
+ component_updateInstance(component, dependency, hevent, true, false);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ event_destroy(&old);
+ }
+
+ return status;
+}
+
+celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ int size = arrayList_size(events);
+ if (arrayList_contains(events, event)) {
+ size--;
+ }
+ pthread_mutex_unlock(&component->mutex);
+ serviceDependency_setAvailable(dependency, size > 0);
+ component_handleChange(component);
+
+ pthread_mutex_lock(&component->mutex);
+ int index = arrayList_indexOf(events, event);
+ if (index < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ dm_event_pt old = arrayList_remove(events, (unsigned int) index);
+ pthread_mutex_unlock(&component->mutex);
+
+ switch (component->state) {
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
+ bool instanceBound = false;
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+ if (!instanceBound) {
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
+ if (required) {
+ serviceDependency_invokeRemove(dependency, event);
+ }
+ dm_event_pt hevent = NULL;
+ component_getDependencyEvent(component, dependency, &hevent);
+ component_updateInstance(component, dependency, hevent, false, false);
+ }
+ break;
+ }
+ case DM_CMP_STATE_TRACKING_OPTIONAL:
+ serviceDependency_invokeRemove(dependency, event);
+ dm_event_pt hevent = NULL;
+ component_getDependencyEvent(component, dependency, &hevent);
+ component_updateInstance(component, dependency, hevent, false, false);
+ break;
+ default:
+ break;
+ }
+
+ event_destroy(&event);
+ if (old) {
+ event_destroy(&old);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ int index = arrayList_indexOf(events, event);
+ if (index < 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ dm_event_pt old = arrayList_remove(events, (unsigned int) index);
+ arrayList_add(events, newEvent);
+ pthread_mutex_unlock(&component->mutex);
+
+ switch (component->state) {
+ case DM_CMP_STATE_WAITING_FOR_REQUIRED:
+ break;
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
+ bool instanceBound = false;
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+ if (!instanceBound) {
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
+ if (required) {
+ serviceDependency_invokeSwap(dependency, event, newEvent);
+ }
+ }
+ break;
+ }
+ case DM_CMP_STATE_TRACKING_OPTIONAL:
+ serviceDependency_invokeSwap(dependency, event, newEvent);
+ break;
+ default:
+ break;
+ }
+
+ event_destroy(&event);
+ if (old) {
+ event_destroy(&old);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t component_updateInstance(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, bool update, bool add) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ bool autoConfig = false;
+
+ serviceDependency_isAutoConfig(dependency, &autoConfig);
+
+ if (autoConfig) {
+ void *service = NULL;
+ void **field = NULL;
+
+ if (event != NULL) {
+ event_getService(event, &service);
+ }
+ serviceDependency_getAutoConfig(dependency, &field);
+ serviceDependency_lock(dependency);
+ *field = service;
+ serviceDependency_unlock(dependency);
+ }
+
+ return status;
+}
+
+celix_status_t component_startDependencies(dm_component_pt component __attribute__((unused)), array_list_pt dependencies) {
+ celix_status_t status = CELIX_SUCCESS;
+ array_list_pt required_dependencies = NULL;
+ arrayList_create(&required_dependencies);
+
+ for (unsigned int i = 0; i < arrayList_size(dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(dependencies, i);
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
+ if (required) {
+ arrayList_add(required_dependencies, dependency);
+ continue;
+ }
+
+ serviceDependency_start(dependency);
+ }
+
+ for (unsigned int i = 0; i < arrayList_size(required_dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(required_dependencies, i);
+ serviceDependency_start(dependency);
+ }
+
+ arrayList_destroy(required_dependencies);
+
+ return status;
+}
+
+celix_status_t component_stopDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+ pthread_mutex_unlock(&component->mutex);
+ serviceDependency_stop(dependency);
+ pthread_mutex_lock(&component->mutex);
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_handleChange(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ dm_component_state_pt oldState;
+ dm_component_state_pt newState;
+
+ bool cont = false;
+ do {
+ oldState = component->state;
+ component_calculateNewState(component, oldState, &newState);
+ component->state = newState;
+ component_performTransition(component, oldState, newState, &cont);
+ } while (cont);
+
+ return status;
+}
+
+celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_pt currentState, dm_component_state_pt *newState) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (currentState == DM_CMP_STATE_INACTIVE) {
+ if (component->isStarted) {
+ *newState = DM_CMP_STATE_WAITING_FOR_REQUIRED;
+ return status;
+ }
+ }
+ if (currentState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
+ if (!component->isStarted) {
+ *newState = DM_CMP_STATE_INACTIVE;
+ return status;
+ }
+
+ bool available = false;
+ component_allRequiredAvailable(component, &available);
+
+ if (available) {
+ *newState = DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED;
+ return status;
+ }
+ }
+ if (currentState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
+ bool available = false;
+ component_allRequiredAvailable(component, &available);
+
+ if (component->isStarted && available) {
+ bool instanceBoundAvailable = false;
+ component_allInstanceBoundAvailable(component, &instanceBoundAvailable);
+
+ if (instanceBoundAvailable) {
+ *newState = DM_CMP_STATE_TRACKING_OPTIONAL;
+ return status;
+ }
+
+ *newState = currentState;
+ return status;
+ }
+ *newState = DM_CMP_STATE_WAITING_FOR_REQUIRED;
+ return status;
+ }
+ if (currentState == DM_CMP_STATE_TRACKING_OPTIONAL) {
+ bool instanceBoundAvailable = false;
+ bool available = false;
+
+ component_allInstanceBoundAvailable(component, &instanceBoundAvailable);
+ component_allRequiredAvailable(component, &available);
+
+ if (component->isStarted && available && instanceBoundAvailable) {
+ *newState = currentState;
+ return status;
+ }
+
+ *newState = DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED;
+ return status;
+ }
+
+ *newState = currentState;
+
+ return status;
+}
+
+celix_status_t component_performTransition(dm_component_pt component, dm_component_state_pt oldState, dm_component_state_pt newState, bool *transition) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (oldState == DM_CMP_STATE_INACTIVE && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
+ component_startDependencies(component, component->dependencies);
+// #TODO Add listener support
+// notifyListeners(newState);
+ *transition = true;
+ return status;
+ }
+
+ if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
+ // #TODO Remove
+// component_instantiateComponent(component);
+ component_invokeAddRequiredDependencies(component);
+ component_invokeAutoConfigDependencies(component);
+ dm_component_state_pt stateBeforeCallingInit = component->state;
+ if (component->callbackInit) {
+ component->callbackInit(component->implementation);
+ }
+ if (stateBeforeCallingInit == component->state) {
+// #TODO Add listener support
+// notifyListeners(newState); // init did not change current state, we can notify about this new state
+ }
+ *transition = true;
+ return status;
+ }
+
+ if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_TRACKING_OPTIONAL) {
+ component_invokeAddRequiredInstanceBoundDependencies(component);
+ component_invokeAutoConfigInstanceBoundDependencies(component);
+ if (component->callbackStart) {
+ component->callbackStart(component->implementation);
+ }
+ component_invokeAddOptionalDependencies(component);
+ component_registerService(component);
+// #TODO Add listener support
+// notifyListeners(newState);
+ return true;
+ }
+
+ if (oldState == DM_CMP_STATE_TRACKING_OPTIONAL && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED) {
+ component_unregisterService(component);
+ component_invokeRemoveOptionalDependencies(component);
+ if (component->callbackStop) {
+ component->callbackStop(component->implementation);
+ }
+ component_invokeRemoveInstanceBoundDependencies(component);
+// #TODO Add listener support
+// notifyListeners(newState);
+ *transition = true;
+ return status;
+ }
+
+ if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
+ if (component->callbackDestroy) {
+ component->callbackDestroy(component->implementation);
+ }
+ component_invokeRemoveRequiredDependencies(component);
+// #TODO Add listener support
+// notifyListeners(newState);
+// bool needInstance = false;
+// component_someDependenciesNeedInstance(component, &needInstance);
+// if (!needInstance) {
+ component_destroyComponent(component);
+// }
+ *transition = true;
+ return status;
+ }
+
+ if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INACTIVE) {
+ component_stopDependencies(component);
+ component_destroyComponent(component);
+// #TODO Add listener support
+// notifyListeners(newState);
+ *transition = true;
+ return status;
+ }
+
+ *transition = false;
+ return status;
+}
+
+celix_status_t component_allRequiredAvailable(dm_component_pt component, bool *available) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ *available = true;
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+ bool required = false;
+ bool instanceBound = false;
+
+ serviceDependency_isRequired(dependency, &required);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (required && !instanceBound) {
+ bool isAvailable = false;
+ serviceDependency_isAvailable(dependency, &isAvailable);
+ if (!isAvailable) {
+ *available = false;
+ break;
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_allInstanceBoundAvailable(dm_component_pt component, bool *available) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ *available = true;
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+ bool required = false;
+ bool instanceBound = false;
+
+ serviceDependency_isRequired(dependency, &required);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (required && instanceBound) {
+ bool isAvailable = false;
+ serviceDependency_isAvailable(dependency, &isAvailable);
+ if (!isAvailable) {
+ *available = false;
+ break;
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeAddRequiredDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool required = false;
+ bool instanceBound = false;
+
+ serviceDependency_isRequired(dependency, &required);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (required && !instanceBound) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeAdd(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeAutoConfigDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool autoConfig = false;
+ bool instanceBound = false;
+
+ serviceDependency_isAutoConfig(dependency, &autoConfig);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (autoConfig && !instanceBound) {
+ component_configureImplementation(component, dependency);
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeAutoConfigInstanceBoundDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool autoConfig = false;
+ bool instanceBound = false;
+
+ serviceDependency_isAutoConfig(dependency, &autoConfig);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (autoConfig && instanceBound) {
+ component_configureImplementation(component, dependency);
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeAddRequiredInstanceBoundDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool required = false;
+ bool instanceBound = false;
+
+ serviceDependency_isRequired(dependency, &required);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (instanceBound && required) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeAdd(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeAddOptionalDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool required = false;
+
+ serviceDependency_isRequired(dependency, &required);
+
+ if (!required) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeAdd(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeRemoveOptionalDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool required = false;
+
+ serviceDependency_isRequired(dependency, &required);
+
+ if (!required) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeRemove(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeRemoveInstanceBoundDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool instanceBound = false;
+
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (instanceBound) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeRemove(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_invokeRemoveRequiredDependencies(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ pthread_mutex_lock(&component->mutex);
+ for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+ dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+ bool required = false;
+ bool instanceBound = false;
+
+ serviceDependency_isRequired(dependency, &required);
+ serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+ if (!instanceBound && required) {
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event = arrayList_get(events, j);
+ serviceDependency_invokeRemove(dependency, event);
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&component->mutex);
+
+ return status;
+}
+
+celix_status_t component_getDependencyEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt *event_pptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ *event_pptr = NULL;
+
+ if (events) {
+ for (unsigned int j = 0; j < arrayList_size(events); j++) {
+ dm_event_pt event_ptr = arrayList_get(events, j);
+ if (*event_pptr != NULL) {
+ int compare = 0;
+ event_compareTo(event_ptr, *event_pptr, &compare);
+ if (compare > 0) {
+ *event_pptr = event_ptr;
+ }
+ } else {
+ *event_pptr = event_ptr;
+ }
+ }
+ }
+
+ return status;
+}
+
+celix_status_t component_configureImplementation(dm_component_pt component, dm_service_dependency_pt dependency) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ void **field = NULL;
+
+ array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+ if (events) {
+ void *service = NULL;
+ dm_event_pt event = NULL;
+ component_getDependencyEvent(component, dependency, &event);
+ if (event != NULL) {
+ event_getService(event, &service);
+ serviceDependency_getAutoConfig(dependency, &field);
+ serviceDependency_lock(dependency);
+ *field = service;
+ serviceDependency_unlock(dependency);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t component_destroyComponent(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+// component->implementation = NULL;
+
+ return status;
+}
+
+celix_status_t component_registerService(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (component->context) {
+ unsigned int i;
+
+ for (i = 0; i < arrayList_size(component->dm_interface); i++) {
+ dm_interface *interface = arrayList_get(component->dm_interface, i);
+
+ bundleContext_registerService(component->context, interface->serviceName, interface->service, interface->properties, &interface->registration);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t component_unregisterService(dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ unsigned int i;
+
+ for (i = 0; i < arrayList_size(component->dm_interface); i++) {
+ dm_interface *interface = arrayList_get(component->dm_interface, i);
+
+ serviceRegistration_unregister(interface->registration);
+ interface->registration = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt stop, destroy_fpt destroy) {
+ if (component->active) {
+ return CELIX_ILLEGAL_STATE;
+ }
+ component->callbackInit = init;
+ component->callbackStart = start;
+ component->callbackStop = stop;
+ component->callbackDestroy = destroy;
+ return CELIX_SUCCESS;
+}
+
+celix_status_t component_isAvailable(dm_component_pt component, bool *available) {
+ *available = component->state == DM_CMP_STATE_TRACKING_OPTIONAL;
+ return CELIX_SUCCESS;
+}
+
+celix_status_t component_setImplementation(dm_component_pt component, void *implementation) {
+ component->implementation = implementation;
+ return CELIX_SUCCESS;
+}
+
+celix_status_t component_getBundleContext(dm_component_pt component, bundle_context_pt *context) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!component) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *context = component->context;
+ }
+
+ return status;
+}
+
+
+celix_status_t executor_create(dm_component_pt component __attribute__((unused)), dm_executor_pt *executor) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *executor = malloc(sizeof(**executor));
+ if (!*executor) {
+ status = CELIX_ENOMEM;
+ } else {
+ linkedList_create(&(*executor)->workQueue);
+ pthread_mutex_init(&(*executor)->mutex, NULL);
+ (*executor)->runningThreadSet = false;
+ }
+
+ return status;
+}
+
+celix_status_t executor_destroy(dm_executor_pt *executor) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!*executor) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ pthread_mutex_destroy(&(*executor)->mutex);
+ linkedList_destroy((*executor)->workQueue);
+
+ free(*executor);
+ *executor = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t executor_schedule(dm_executor_pt executor, dm_component_pt component, void (*command), void *data) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ struct dm_executor_task *task = NULL;
+ task = malloc(sizeof(*task));
+ if (!task) {
+ status = CELIX_ENOMEM;
+ } else {
+ task->component = component;
+ task->command = command;
+ task->data = data;
+
+ pthread_mutex_lock(&executor->mutex);
+ linkedList_addLast(executor->workQueue, task);
+ pthread_mutex_unlock(&executor->mutex);
+ }
+
+ return status;
+}
+
+celix_status_t executor_executeTask(dm_executor_pt executor, dm_component_pt component, void (*command), void *data) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ // Check thread and executor thread, if the same, execute immediately.
+// bool execute = false;
+// pthread_mutex_lock(&executor->mutex);
+// pthread_t currentThread = pthread_self();
+// if (pthread_equal(executor->runningThread, currentThread)) {
+// execute = true;
+// }
+// pthread_mutex_unlock(&executor->mutex);
+
+ // For now, just schedule.
+ executor_schedule(executor, component, command, data);
+ executor_execute(executor);
+
+ return status;
+}
+
+celix_status_t executor_execute(dm_executor_pt executor) {
+ celix_status_t status = CELIX_SUCCESS;
+ pthread_t currentThread = pthread_self();
+
+ pthread_mutex_lock(&executor->mutex);
+ bool execute = false;
+ if (!executor->runningThreadSet) {
+ executor->runningThread = currentThread;
+ executor->runningThreadSet = true;
+ execute = true;
+ }
+ pthread_mutex_unlock(&executor->mutex);
+ if (execute) {
+ executor_runTasks(executor, currentThread);
+ }
+
+ return status;
+}
+
+celix_status_t executor_runTasks(dm_executor_pt executor, pthread_t currentThread __attribute__((unused))) {
+ celix_status_t status = CELIX_SUCCESS;
+// bool execute = false;
+
+ do {
+ struct dm_executor_task *entry = NULL;
+ pthread_mutex_lock(&executor->mutex);
+ while ((entry = linkedList_removeFirst(executor->workQueue)) != NULL) {
+ pthread_mutex_unlock(&executor->mutex);
+
+ entry->command(entry->component, entry->data);
+
+ pthread_mutex_lock(&executor->mutex);
+
+ free(entry);
+ }
+ executor->runningThreadSet = false;
+ pthread_mutex_unlock(&executor->mutex);
+
+// pthread_mutex_lock(&executor->mutex);
+// if (executor->runningThread == NULL) {
+// executor->runningThread = currentThread;
+// execute = true;
+// }
+// pthread_mutex_unlock(&executor->mutex);
+ } while (!linkedList_isEmpty(executor->workQueue)); // && execute
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/private/src/dm_dependency_manager_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_dependency_manager_impl.c b/dependency_manager/private/src/dm_dependency_manager_impl.c
new file mode 100644
index 0000000..28b49e9
--- /dev/null
+++ b/dependency_manager/private/src/dm_dependency_manager_impl.c
@@ -0,0 +1,91 @@
+/**
+ * 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.
+ */
+
+/*
+ * dm_dependency_manager_impl.c
+ *
+ * \date 26 Jul 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+
+#include <pthread.h>
+#include <stdlib.h>
+
+#include "bundle_context.h"
+#include "dm_component_impl.h"
+
+struct dm_dependency_manager {
+ array_list_pt components;
+
+ pthread_mutex_t mutex;
+};
+
+celix_status_t dependencyManager_create(bundle_context_pt context __attribute__((unused)), dm_dependency_manager_pt *manager) {
+ celix_status_t status = CELIX_ENOMEM;
+
+ (*manager) = calloc(1, sizeof(**manager));
+
+ if (*manager) {
+ arrayList_create(&(*manager)->components);
+
+ status = CELIX_SUCCESS;
+ }
+
+ return status;
+
+}
+
+celix_status_t dependencyManager_destroy(dm_dependency_manager_pt *manager) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ arrayList_destroy((*manager)->components);
+
+ free(*manager);
+ (*manager) = NULL;
+
+ return status;
+}
+
+celix_status_t dependencyManager_add(dm_dependency_manager_pt manager, dm_component_pt component) {
+ celix_status_t status;
+
+ arrayList_add(manager->components, component);
+ status = component_start(component);
+
+ return status;
+}
+
+celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_component_pt component) {
+ celix_status_t status;
+
+ arrayList_removeElement(manager->components, component);
+ status = component_stop(component);
+
+ return status;
+}
+
+celix_status_t dependencyManager_getComponents(dm_dependency_manager_pt manager, array_list_pt* components) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ (*components) = manager->components;
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/private/src/dm_event.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_event.c b/dependency_manager/private/src/dm_event.c
new file mode 100644
index 0000000..60b7892
--- /dev/null
+++ b/dependency_manager/private/src/dm_event.c
@@ -0,0 +1,92 @@
+/**
+ * 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.
+ */
+
+/*
+ * dm_event.c
+ *
+ * \date 18 Dec 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdlib.h>
+
+#include "dm_event.h"
+
+celix_status_t event_create(dm_event_type_e event_type, bundle_pt bundle, bundle_context_pt context, service_reference_pt reference, void *service, dm_event_pt *event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *event = calloc(1, sizeof(**event));
+ if (!*event) {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ (*event)->bundle = bundle;
+ (*event)->event_type = event_type;
+ (*event)->context = context;
+ (*event)->reference = reference;
+ (*event)->service = service;
+ }
+
+ return status;
+}
+
+celix_status_t event_destroy(dm_event_pt *event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!*event) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ free(*event);
+ *event = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t event_equals(void *a, void *b, bool *equals) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!a || !b) {
+ *equals = false;
+ } else {
+ dm_event_pt a_ptr = a;
+ dm_event_pt b_ptr = b;
+
+ status = serviceReference_equals(a_ptr->reference, b_ptr->reference, equals);
+ }
+
+ return status;
+}
+
+celix_status_t event_compareTo(dm_event_pt event, dm_event_pt compareTo, int *compare) {
+ celix_status_t status;
+
+ status = serviceReference_compareTo(event->reference, compareTo->reference, compare);
+
+ return status;
+}
+
+celix_status_t event_getService(dm_event_pt event, void **service) {
+ *service = event->service;
+ return CELIX_SUCCESS;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/cc6fd432/dependency_manager/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_service_dependency.c b/dependency_manager/private/src/dm_service_dependency.c
new file mode 100644
index 0000000..8f65ddb
--- /dev/null
+++ b/dependency_manager/private/src/dm_service_dependency.c
@@ -0,0 +1,564 @@
+/**
+ *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.
+ */
+/*
+ * dm_service_dependency.c
+ *
+ * \date 17 Oct 2014
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "constants.h"
+
+#include "dm_service_dependency_impl.h"
+#include "dm_component_impl.h"
+
+static celix_status_t serviceDependency_addedService(void *_ptr, service_reference_pt reference, void *service);
+static celix_status_t serviceDependency_modifiedService(void *_ptr, service_reference_pt reference, void *service);
+static celix_status_t serviceDependency_removedService(void *_ptr, service_reference_pt reference, void *service);
+
+celix_status_t serviceDependency_create(dm_service_dependency_pt *dependency_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *dependency_ptr = calloc(1, sizeof(**dependency_ptr));
+ if (!*dependency_ptr) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*dependency_ptr)->component = NULL;
+ (*dependency_ptr)->available = false;
+ (*dependency_ptr)->instanceBound = false;
+ (*dependency_ptr)->required = false;
+
+ (*dependency_ptr)->add = NULL;
+ (*dependency_ptr)->change = NULL;
+ (*dependency_ptr)->remove = NULL;
+ (*dependency_ptr)->swap = NULL;
+
+ (*dependency_ptr)->add_with_ref = NULL;
+ (*dependency_ptr)->change_with_ref = NULL;
+ (*dependency_ptr)->remove_with_ref = NULL;
+ (*dependency_ptr)->swap_with_ref = NULL;
+
+ (*dependency_ptr)->autoConfigure = NULL;
+
+ (*dependency_ptr)->isStarted = false;
+
+ (*dependency_ptr)->tracked_service_name = NULL;
+ (*dependency_ptr)->tracked_filter_unmodified = NULL;
+ (*dependency_ptr)->tracked_filter = NULL;
+
+ (*dependency_ptr)->tracker = NULL;
+ (*dependency_ptr)->tracker_customizer = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_ptr) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!*dependency_ptr) {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ free((*dependency_ptr)->tracked_service_name);
+ free((*dependency_ptr)->tracked_filter);
+ free((*dependency_ptr)->tracked_filter_unmodified);
+ free(*dependency_ptr);
+ *dependency_ptr = NULL;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_lock(dm_service_dependency_pt dependency) {
+ celixThreadMutex_lock(&dependency->lock);
+ return CELIX_SUCCESS;
+}
+
+celix_status_t serviceDependency_unlock(dm_service_dependency_pt dependency) {
+ celixThreadMutex_unlock(&dependency->lock);
+ return CELIX_SUCCESS;
+}
+
+celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ dependency->required = required;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName, char *filter) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if (serviceName != NULL) {
+ dependency->tracked_service_name = strdup(serviceName);
+ }
+ if (filter != NULL) {
+ dependency->tracked_filter_unmodified = strdup(filter);
+ if (serviceName == NULL) {
+ dependency->tracked_filter = strdup(filter);
+ } else {
+ size_t len = strlen(serviceName) + strlen(OSGI_FRAMEWORK_OBJECTCLASS) + strlen(filter) + 7;
+ char new_filter[len];
+ snprintf(new_filter, len, "(&(%s=%s)%s)", OSGI_FRAMEWORK_OBJECTCLASS, serviceName, filter);
+ dependency->tracked_filter = strdup(new_filter);
+ }
+ } else {
+ dependency->tracked_filter_unmodified = NULL;
+ dependency->tracked_filter = NULL;
+ }
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ dependency->add = add;
+ dependency->change = change;
+ dependency->remove = remove;
+ dependency->swap = swap;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ dependency->add_with_ref = add;
+ dependency->change_with_ref = change;
+ dependency->remove_with_ref = remove;
+ dependency->swap_with_ref = swap;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t *service_lock, void **field) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ celix_thread_mutex_t lock;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ dependency->autoConfigure = field;
+ celixThreadMutex_create(&lock, NULL);
+ *service_lock = lock;
+ dependency->lock = lock;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_setComponent(dm_service_dependency_pt dependency, dm_component_pt component) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ dependency->component = component;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_start(dm_service_dependency_pt dependency) {
+ celix_status_t status = CELIX_SUCCESS;
+ bundle_context_pt context = NULL;
+
+ if (!dependency || !dependency->component || (!dependency->tracked_service_name && !dependency->tracked_filter)) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = component_getBundleContext(dependency->component, &context);
+ if (!context) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ dependency->tracker_customizer = NULL;
+ status = serviceTrackerCustomizer_create(dependency, NULL, serviceDependency_addedService, serviceDependency_modifiedService,
+ serviceDependency_removedService, &dependency->tracker_customizer);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if (dependency->tracked_filter) {
+ status = serviceTracker_createWithFilter(context, dependency->tracked_filter, dependency->tracker_customizer, &dependency->tracker);
+ } else if (dependency->tracked_service_name) {
+ status = serviceTracker_create(context, dependency->tracked_service_name, dependency->tracker_customizer, &dependency->tracker);
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_open(dependency->tracker);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ dependency->isStarted = true;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_stop(dm_service_dependency_pt dependency) {
+ celix_status_t status = CELIX_SUCCESS;
+ celix_status_t tmp_status;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if (dependency->tracker) {
+ tmp_status = serviceTracker_close(dependency->tracker);
+ if (tmp_status != CELIX_SUCCESS) {
+ status = tmp_status;
+ }
+ tmp_status = serviceTracker_destroy(dependency->tracker);
+ if (tmp_status != CELIX_SUCCESS && status == CELIX_SUCCESS) {
+ status = tmp_status;
+ }
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ dependency->isStarted = false;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_setInstanceBound(dm_service_dependency_pt dependency, bool instanceBound) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ dependency->instanceBound = instanceBound;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_setAvailable(dm_service_dependency_pt dependency, bool available) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ dependency->available = available;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_invokeAdd(dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if (dependency->add) {
+ dependency->add(dependency->component->implementation, event->service);
+ }
+ if (dependency->add_with_ref) {
+ dependency->add_with_ref(dependency->component->implementation, event->reference, event->service);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_invokeChange(dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if (dependency->change) {
+ dependency->change(dependency->component->implementation, event->service);
+ }
+ if (dependency->change_with_ref) {
+ dependency->change_with_ref(dependency->component->implementation, event->reference, event->service);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_invokeRemove(dm_service_dependency_pt dependency, dm_event_pt event) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if (dependency->remove) {
+ dependency->remove(dependency->component->implementation, event->service);
+ }
+ if (dependency->remove_with_ref) {
+ dependency->remove_with_ref(dependency->component->implementation, event->reference, event->service);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_invokeSwap(dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ if (dependency->swap) {
+ dependency->swap(dependency->component->implementation, event->service, newEvent->service);
+ }
+ if (dependency->swap_with_ref) {
+ dependency->swap_with_ref(dependency->component->implementation, event->reference, event->service, newEvent->reference, newEvent->service);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_isAvailable(dm_service_dependency_pt dependency, bool *available) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *available = dependency->available;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_isRequired(dm_service_dependency_pt dependency, bool *required) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *required = dependency->required;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_isInstanceBound(dm_service_dependency_pt dependency, bool *instanceBound) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *instanceBound = dependency->instanceBound;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_isAutoConfig(dm_service_dependency_pt dependency, bool *autoConfig) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *autoConfig = dependency->autoConfigure != NULL;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_getAutoConfig(dm_service_dependency_pt dependency, void ***autoConfigure) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ if (!dependency) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *autoConfigure = dependency->autoConfigure;
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_addedService(void *_ptr, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ bundle_context_pt context = NULL;
+ bundle_pt bundle = NULL;
+ dm_event_pt event = NULL;
+ dm_service_dependency_pt dependency = _ptr;
+
+ if (!dependency || !reference || !service) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = component_getBundleContext(dependency->component, &context);
+ if (!context) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_getBundle(context, &bundle);
+ if (!bundle) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = event_create(DM_EVENT_ADDED, bundle, context, reference, service, &event);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ component_handleEvent(dependency->component, dependency, event);
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_modifiedService(void *_ptr, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ bundle_context_pt context = NULL;
+ bundle_pt bundle = NULL;
+ dm_event_pt event = NULL;
+ dm_service_dependency_pt dependency = _ptr;
+
+ if (!dependency || !reference || !service) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = component_getBundleContext(dependency->component, &context);
+ if (!context) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_getBundle(context, &bundle);
+ if (!bundle) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = event_create(DM_EVENT_CHANGED, bundle, context, reference, service, &event);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ component_handleEvent(dependency->component, dependency, event);
+ }
+
+ return status;
+}
+
+celix_status_t serviceDependency_removedService(void *_ptr, service_reference_pt reference, void *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ bundle_context_pt context = NULL;
+ bundle_pt bundle = NULL;
+ dm_event_pt event = NULL;
+ dm_service_dependency_pt dependency = _ptr;
+
+ if (!dependency || !reference || !service) {
+ status = CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = component_getBundleContext(dependency->component, &context);
+ if (!context) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = bundleContext_getBundle(context, &bundle);
+ if (!bundle) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = event_create(DM_EVENT_REMOVED, bundle, context, reference, service, &event);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ component_handleEvent(dependency->component, dependency, event);
+ }
+
+ return status;
+}
[11/21] celix git commit: CELIX-210: Fixed an issue to trigger a
state change when required services reapear. Started creating destroy
functions for dm info (used in shell command).
Posted by pn...@apache.org.
CELIX-210: Fixed an issue to trigger a state change when required services reapear. Started creating destroy functions for dm info (used in shell command).
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/2de2554a
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/2de2554a
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/2de2554a
Branch: refs/heads/develop
Commit: 2de2554aebf9093ed037a23589389542cc7563ec
Parents: 8f279cb
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Oct 22 21:04:06 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Oct 22 21:04:06 2015 +0200
----------------------------------------------------------------------
.../private/src/dm_activator_base.c | 1 +
.../private/src/dm_component_impl.c | 42 +++++++++++++++-----
.../private/src/dm_dependency_manager_impl.c | 19 +++++++++
.../private/src/dm_service_dependency.c | 7 ++++
.../private/src/dm_shell_list_command.c | 7 +---
.../public/include/dm_component.h | 1 +
.../public/include/dm_dependency_manager.h | 1 +
dependency_manager/public/include/dm_info.h | 1 +
.../public/include/dm_service_dependency.h | 1 +
9 files changed, 65 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/2de2554a/dependency_manager/private/src/dm_activator_base.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_activator_base.c b/dependency_manager/private/src/dm_activator_base.c
index 2928c25..25065a9 100644
--- a/dependency_manager/private/src/dm_activator_base.c
+++ b/dependency_manager/private/src/dm_activator_base.c
@@ -77,6 +77,7 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
//Create the service
dependency_activator->info->handle = dependency_activator->manager;
dependency_activator->info->getInfo = (void *)dependencyManager_getInfo;
+ dependency_activator->info->destroyInfo = (void *)dependencyManager_destroyInfo;
bundleContext_registerService(context, DM_INFO_SERVICE_NAME, dependency_activator->info, NULL, &(dependency_activator->reg));
return status;
http://git-wip-us.apache.org/repos/asf/celix/blob/2de2554a/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index 5aeae6b..500d613 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -400,21 +400,19 @@ celix_status_t component_handleAdded(dm_component_pt component, dm_service_depen
case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
bool instanceBound = false;
serviceDependency_isInstanceBound(dependency, &instanceBound);
+ bool required = false;
+ serviceDependency_isRequired(dependency, &required);
if (!instanceBound) {
- bool required = false;
- serviceDependency_isRequired(dependency, &required);
if (required) {
serviceDependency_invokeAdd(dependency, event);
}
dm_event_pt event = NULL;
component_getDependencyEvent(component, dependency, &event);
component_updateInstance(component, dependency, event, false, true);
- } else {
- bool required = false;
- serviceDependency_isRequired(dependency, &required);
- if (required) {
- component_handleChange(component);
- }
+ }
+
+ if (required) {
+ component_handleChange(component);
}
break;
}
@@ -1361,8 +1359,34 @@ celix_status_t component_getComponentInfo(dm_component_pt component, dm_componen
if (status == CELIX_SUCCESS) {
*out = info;
} else if (info != NULL) {
- //TODO cleanup
+ component_destroyComponentInfo(info);
}
return status;
+}
+
+void component_destroyComponentInfo(dm_component_info_pt info) {
+ int i;
+ int size;
+ if (info != NULL) {
+ free(info->state);
+
+ if (info->interfaces != NULL) {
+ size = arrayList_size(info->interfaces);
+ for (i = 0; i < size; i += 1) {
+ char *intf = arrayList_get(info->interfaces, i);
+ free(intf);
+ }
+ arrayList_destroy(info->interfaces);
+ }
+ if (info->dependency_list != NULL) {
+ size = arrayList_size(info->dependency_list);
+ for (i = 0; i < size; i += 1) {
+ dm_service_dependency_info_pt depInfo = arrayList_get(info->dependency_list, i);
+ dependency_destroyDependencyInfo(depInfo);
+ }
+ arrayList_destroy(info->dependency_list);
+ }
+ }
+ free(info);
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/2de2554a/dependency_manager/private/src/dm_dependency_manager_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_dependency_manager_impl.c b/dependency_manager/private/src/dm_dependency_manager_impl.c
index 59ba677..059ce54 100644
--- a/dependency_manager/private/src/dm_dependency_manager_impl.c
+++ b/dependency_manager/private/src/dm_dependency_manager_impl.c
@@ -109,3 +109,22 @@ celix_status_t dependencyManager_getInfo(dm_dependency_manager_pt manager, dm_de
return status;
}
+
+void dependencyManager_destroyInfo(dm_dependency_manager_pt manager, dm_dependency_manager_info_pt info) {
+ return;
+ /*
+ * TODO
+
+ int i;
+ int size;
+ if (info != NULL) {
+ size = arrayList_size(info->components);
+ for (i = 0; i < size; i += 1) {
+ dm_component_info_pt cmpInfo = arrayList_get(info->components, i);
+ component_destroyComponentInfo(cmpInfo);
+ }
+ arrayList_destroy(info->components);
+ }
+ free(info);
+ */
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/2de2554a/dependency_manager/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_service_dependency.c b/dependency_manager/private/src/dm_service_dependency.c
index 61daa07..e0bf489 100644
--- a/dependency_manager/private/src/dm_service_dependency.c
+++ b/dependency_manager/private/src/dm_service_dependency.c
@@ -657,4 +657,11 @@ celix_status_t serviceDependency_getServiceDependencyInfo(dm_service_dependency_
}
return status;
+}
+
+void dependency_destroyDependencyInfo(dm_service_dependency_info_pt info) {
+ if (info != NULL) {
+ free(info->filter);
+ }
+ free(info);
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/2de2554a/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
index 59f748f..1e70513 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -87,9 +87,7 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
interface = arrayList_get(compInfo->interfaces, interfCnt);
sprintf(outString, " |- Interface: %s\n", interface);
out(outString);
- free(interface);
}
- arrayList_destroy(compInfo->interfaces);
int depCnt;
sprintf(outString, "|- Dependencies (%d):\n", arrayList_size(compInfo->dependency_list));
@@ -111,12 +109,9 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
dependency->filter
);
out(outString);
- free(dependency->filter);
- free(dependency);
}
- //TODO free compInfo
- arrayList_destroy(compInfo->dependency_list);
+ infoServ->destroyInfo(infoServ->handle, info);
}
}
}
http://git-wip-us.apache.org/repos/asf/celix/blob/2de2554a/dependency_manager/public/include/dm_component.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_component.h b/dependency_manager/public/include/dm_component.h
index ab8ac80..c26cc05 100644
--- a/dependency_manager/public/include/dm_component.h
+++ b/dependency_manager/public/include/dm_component.h
@@ -61,5 +61,6 @@ celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init,
* returns a dm_component_info_pt. Caller has ownership.
*/
celix_status_t component_getComponentInfo(dm_component_pt component, dm_component_info_pt *info);
+void component_destroyComponentInfo(dm_component_info_pt info);
#endif /* COMPONENT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2de2554a/dependency_manager/public/include/dm_dependency_manager.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_dependency_manager.h b/dependency_manager/public/include/dm_dependency_manager.h
index ab6e27f..44c1643 100644
--- a/dependency_manager/public/include/dm_dependency_manager.h
+++ b/dependency_manager/public/include/dm_dependency_manager.h
@@ -45,5 +45,6 @@ celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_com
* returns a dm_ of dm_dependency_manager_info. Caller has ownership.
*/
celix_status_t dependencyManager_getInfo(dm_dependency_manager_pt manager, dm_dependency_manager_info_pt *info);
+void dependencyManager_destroyInfo(dm_dependency_manager_pt manager, dm_dependency_manager_info_pt info);
#endif /* DM_DEPENDENCY_MANAGER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/2de2554a/dependency_manager/public/include/dm_info.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_info.h b/dependency_manager/public/include/dm_info.h
index ee6a4d8..16ee0f8 100644
--- a/dependency_manager/public/include/dm_info.h
+++ b/dependency_manager/public/include/dm_info.h
@@ -56,6 +56,7 @@ struct dm_info_service {
/*Note: dm_caller has the ownership of the result.*/
celix_status_t (*getInfo)(void *handle, dm_dependency_manager_info_pt *info);
+ void (*destroyInfo)(void *handle, dm_service_dependency_info_pt info);
};
typedef struct dm_info_service * dm_info_service_pt;
http://git-wip-us.apache.org/repos/asf/celix/blob/2de2554a/dependency_manager/public/include/dm_service_dependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_service_dependency.h b/dependency_manager/public/include/dm_service_dependency.h
index 4a9c991..337be01 100644
--- a/dependency_manager/public/include/dm_service_dependency.h
+++ b/dependency_manager/public/include/dm_service_dependency.h
@@ -59,5 +59,6 @@ celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt depen
* Return a service dependency info. The caller is the owner
*/
celix_status_t serviceDependency_getServiceDependencyInfo(dm_service_dependency_pt, dm_service_dependency_info_pt *info);
+void dependency_destroyDependencyInfo(dm_service_dependency_info_pt info);
#endif /* DM_SERVICE_DEPENDENCY_H_ */
[09/21] celix git commit: CELIX-210: Some refactoring to move the
dm_info service as part of the dep man component. Also added colors for the
dm shell command, to easily stop issues.
Posted by pn...@apache.org.
CELIX-210: Some refactoring to move the dm_info service as part of the dep man component. Also added colors for the dm shell command, to easily stop issues.
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/664845ca
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/664845ca
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/664845ca
Branch: refs/heads/develop
Commit: 664845cac42f48a83e865a5c8bb87c160b8dec8b
Parents: 01c1968
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Oct 21 17:06:54 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Oct 21 17:06:54 2015 +0200
----------------------------------------------------------------------
dependency_manager/CMakeLists.txt | 3 +-
.../private/include/dm_component_impl.h | 3 +-
.../private/include/dm_server_impl.h | 36 --------
.../include/dm_service_dependency_impl.h | 1 +
.../private/src/dm_activator_base.c | 28 +++---
.../private/src/dm_component_impl.c | 65 ++++++++++++-
.../private/src/dm_dependency_manager_impl.c | 28 +++++-
dependency_manager/private/src/dm_server.c | 97 --------------------
.../private/src/dm_service_dependency.c | 34 +++++++
.../private/src/dm_shell_activator.c | 10 +-
.../private/src/dm_shell_list_command.c | 73 +++++++++------
.../public/include/dm_component.h | 17 +++-
.../public/include/dm_dependency_manager.h | 10 +-
dependency_manager/public/include/dm_info.h | 63 +++++++++++++
dependency_manager/public/include/dm_server.h | 60 ------------
.../public/include/dm_service_dependency.h | 10 +-
.../private/src/dependency_activator.c | 2 +-
17 files changed, 282 insertions(+), 258 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dependency_manager/CMakeLists.txt b/dependency_manager/CMakeLists.txt
index 931dd3c..e4aeca1 100644
--- a/dependency_manager/CMakeLists.txt
+++ b/dependency_manager/CMakeLists.txt
@@ -47,7 +47,6 @@ if (DEPENDENCY_MANAGER)
private/src/dm_service_dependency
private/src/dm_event
private/src/dm_dependency_manager_impl
- private/src/dm_server
)
include_directories("public/include")
@@ -62,7 +61,7 @@ if (DEPENDENCY_MANAGER)
public/include/dm_component.h
public/include/dm_dependency_manager.h
public/include/dm_service_dependency.h
- public/include/dm_server.h
+ public/include/dm_info.h
DESTINATION
include/celix/dependency_manager
COMPONENT
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/include/dm_component_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_component_impl.h b/dependency_manager/private/include/dm_component_impl.h
index ad742b8..3e86d62 100644
--- a/dependency_manager/private/include/dm_component_impl.h
+++ b/dependency_manager/private/include/dm_component_impl.h
@@ -50,9 +50,8 @@ typedef struct dm_interface_struct {
} dm_interface;
struct dm_component {
+ char *id;
bundle_context_pt context;
- dm_dependency_manager_pt manager;
-
array_list_pt dm_interface;
void *implementation;
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/include/dm_server_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_server_impl.h b/dependency_manager/private/include/dm_server_impl.h
deleted file mode 100644
index 117c561..0000000
--- a/dependency_manager/private/include/dm_server_impl.h
+++ /dev/null
@@ -1,36 +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.
- */
-/*
- * dm_server_impl.h
- *
- * \date 16 Oct 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include "dm_server.h"
-#include "dm_component.h"
-#include "dm_component_impl.h"
-#include "dm_dependency_manager_impl.h"
-
-celix_status_t dmServiceCreate(dm_server_pt * dmServ, bundle_context_pt context, struct dm_dependency_manager *manager);
-celix_status_t dmServiceAddComponent(dm_server_pt dmServ, dm_component_pt component);
-celix_status_t dmServiceDestroy(dm_server_pt dmServ);
-celix_status_t dmService_getInfo(dm_server_pt dmServ, dm_info_pt info);
-
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/include/dm_service_dependency_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_service_dependency_impl.h b/dependency_manager/private/include/dm_service_dependency_impl.h
index 7f2a736..bde435f 100644
--- a/dependency_manager/private/include/dm_service_dependency_impl.h
+++ b/dependency_manager/private/include/dm_service_dependency_impl.h
@@ -34,6 +34,7 @@
#include "service_tracker_customizer.h"
#include "dm_service_dependency.h"
+#include "dm_component.h"
struct dm_service_dependency {
dm_component_pt component;
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_activator_base.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_activator_base.c b/dependency_manager/private/src/dm_activator_base.c
index 1c00ab1..2928c25 100644
--- a/dependency_manager/private/src/dm_activator_base.c
+++ b/dependency_manager/private/src/dm_activator_base.c
@@ -30,14 +30,13 @@
#include "bundle_activator.h"
#include "dm_activator_base.h"
-#include "dm_server.h"
-#include "dm_server_impl.h"
+#include "dm_info.h"
struct dm_dependency_activator_base {
dm_dependency_manager_pt manager;
bundle_context_pt context;
- dm_service_pt dmService;
service_registration_pt reg;
+ dm_info_service_pt info;
void* userData;
};
@@ -47,14 +46,19 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
celix_status_t status = CELIX_ENOMEM;
dependency_activator_base_pt dependency_activator = calloc(1, sizeof(struct dm_dependency_activator_base));
+ dm_info_service_pt serv = calloc(1, sizeof(*serv));
- if (dependency_activator) {
+ if (dependency_activator != NULL && serv != NULL) {
dependency_activator->context = context;
dm_create(context, &dependency_activator->userData);
+ dependency_activator->info = serv;
- (*userData) = dependency_activator;
+ (*userData) = dependency_activator;;
status = CELIX_SUCCESS;
+ } else {
+ free(dependency_activator);
+ free(serv);
}
return status;
@@ -71,10 +75,10 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
}
//Create the service
- dependency_activator->dmService = calloc(sizeof(*(dependency_activator->dmService)), 1);
- dependency_activator->dmService->getInfo = dmService_getInfo;
- dmServiceCreate(&(dependency_activator->dmService->server), context, dependency_activator->manager);
- bundleContext_registerService(context, DM_SERVICE_NAME, dependency_activator->dmService, NULL, &(dependency_activator->reg));
+ dependency_activator->info->handle = dependency_activator->manager;
+ dependency_activator->info->getInfo = (void *)dependencyManager_getInfo;
+
+ bundleContext_registerService(context, DM_INFO_SERVICE_NAME, dependency_activator->info, NULL, &(dependency_activator->reg));
return status;
}
@@ -88,12 +92,9 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context _
// Remove the service
serviceRegistration_unregister(dependency_activator->reg);
- dmServiceDestroy(dependency_activator->dmService->server);
- free(dependency_activator->dmService);
dependency_activator->userData = NULL;
dependency_activator->manager = NULL;
- dependency_activator->dmService = NULL;
return status;
}
@@ -102,6 +103,9 @@ celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt contex
celix_status_t status = CELIX_SUCCESS;
dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
+ if (dependency_activator != NULL) {
+ free(dependency_activator->info);
+ }
free(dependency_activator);
return status;
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index 801d426..9b8ee54 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -95,15 +95,17 @@ static celix_status_t component_handleChanged(dm_component_pt component, dm_serv
static celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
static celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent);
-celix_status_t component_create(bundle_context_pt context, dm_dependency_manager_pt manager, dm_component_pt *component) {
+celix_status_t component_create(bundle_context_pt context, dm_component_pt *component) {
celix_status_t status = CELIX_SUCCESS;
*component = malloc(sizeof(**component));
if (!*component) {
status = CELIX_ENOMEM;
} else {
+ char id[16];
+ snprintf(id, 16, "%p", *component);
+ (*component)->id = strdup(id);
(*component)->context = context;
- (*component)->manager = manager;
arrayList_create(&((*component)->dm_interface));
@@ -316,6 +318,26 @@ celix_status_t component_addInterface(dm_component_pt component, char *serviceNa
return status;
}
+celix_status_t component_getInterfaces(dm_component_pt component, array_list_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ array_list_pt names = NULL;
+ arrayList_create(&names);
+ celixThreadMutex_lock(&component->mutex);
+ int size = arrayList_size(component->dm_interface);
+ int i;
+ for (i = 0; i < size; i += 1) {
+ dm_interface *interface = arrayList_get(component->dm_interface, i);
+ arrayList_add(names, strdup(interface->serviceName));
+ }
+ celixThreadMutex_unlock(&component->mutex);
+
+ if (status == CELIX_SUCCESS) {
+ *out = names;
+ }
+
+ return status;
+}
+
celix_status_t component_handleEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event) {
celix_status_t status = CELIX_SUCCESS;
@@ -1284,3 +1306,42 @@ celix_status_t executor_runTasks(dm_executor_pt executor, pthread_t currentThrea
return status;
}
+
+celix_status_t component_getComponentInfo(dm_component_pt component, dm_component_info_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ int i;
+ int size;
+ dm_component_info_pt info = NULL;
+ info = calloc(1, sizeof(*info));
+
+
+ if (info != NULL) {
+ arrayList_create(&info->dependency_list);
+ component_getInterfaces(component, &info->interfaces);
+ info->active = component->active;
+ info->id = strdup(component->id);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+
+ celixThreadMutex_lock(&component->mutex);
+ size = arrayList_size(component->dependencies);
+ for (i = 0; status == CELIX_SUCCESS && i < size; i += 1) {
+ dm_service_dependency_pt dep = arrayList_get(component->dependencies, i);
+ dm_service_dependency_info_pt depInfo= NULL;
+ status = serviceDependency_getServiceDependencyInfo(dep, &depInfo);
+ if (status == CELIX_SUCCESS) {
+ arrayList_add(info->dependency_list, depInfo);
+ }
+ }
+ celixThreadMutex_unlock(&component->mutex);
+
+ if (status == CELIX_SUCCESS) {
+ *out = info;
+ } else if (info != NULL) {
+ //TODO cleanup
+ }
+
+ return status;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_dependency_manager_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_dependency_manager_impl.c b/dependency_manager/private/src/dm_dependency_manager_impl.c
index 265ecf0..59ba677 100644
--- a/dependency_manager/private/src/dm_dependency_manager_impl.c
+++ b/dependency_manager/private/src/dm_dependency_manager_impl.c
@@ -28,6 +28,7 @@
#include <pthread.h>
#include <stdlib.h>
+#include <dm_dependency_manager.h>
#include "bundle_context.h"
#include "dm_component_impl.h"
@@ -78,10 +79,33 @@ celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_com
return status;
}
-celix_status_t dependencyManager_getComponents(dm_dependency_manager_pt manager, array_list_pt* components) {
+celix_status_t dependencyManager_getInfo(dm_dependency_manager_pt manager, dm_dependency_manager_info_pt *out) {
celix_status_t status = CELIX_SUCCESS;
+ int i;
+ int size;
+ dm_component_info_pt cmpInfo = NULL;
+ dm_dependency_manager_info_pt info = calloc(1, sizeof(*info));
+
+ celixThreadMutex_lock(&manager->mutex);
+
+ if (info != NULL) {
+ arrayList_create(&info->components);
+ size = arrayList_size(manager->components);
+ for (i = 0; i < size; i += 1) {
+ dm_component_pt cmp = arrayList_get(manager->components, i);
+ cmpInfo = NULL;
+ component_getComponentInfo(cmp, &cmpInfo);
+ arrayList_add(info->components, cmpInfo);
+ }
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ celixThreadMutex_unlock(&manager->mutex);
- (*components) = manager->components;
+ if (status == CELIX_SUCCESS) {
+ *out = info;
+ }
return status;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_server.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_server.c b/dependency_manager/private/src/dm_server.c
deleted file mode 100644
index 2976cf6..0000000
--- a/dependency_manager/private/src/dm_server.c
+++ /dev/null
@@ -1,97 +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.
- */
-/*
- * dm_component_impl.c
- *
- * \date 9 Oct 2014
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-
-#include "array_list.h"
-
-#include "dm_server.h"
-#include "dm_component.h"
-#include "dm_component_impl.h"
-#include "dm_dependency_manager_impl.h"
-
-struct dm_server {
- struct dm_dependency_manager *manager;
-};
-
-celix_status_t dmServiceCreate(dm_server_pt * dmServ, bundle_context_pt context, struct dm_dependency_manager *manager) {
- *dmServ = calloc(sizeof(struct dm_server), 1);
- (*dmServ)->manager = manager;
- return CELIX_SUCCESS;
-}
-
-celix_status_t dmServiceDestroy(dm_server_pt dmServ) {
- free(dmServ);
- return CELIX_SUCCESS;
-}
-
-celix_status_t dmService_getInfo(dm_server_pt dmServ, dm_info_pt info) {
- int compCnt;
- arrayList_create(&(info->components));
- array_list_pt compList = dmServ->manager->components;
-
- for (compCnt = 0; compCnt < arrayList_size(compList); compCnt++) {
- int i;
- struct dm_component *component = arrayList_get(compList, compCnt);
-
- // Create a component info
- dm_component_info_pt compInfo = calloc(sizeof(*compInfo),1);
- arrayList_create(&(compInfo->interface_list));
- arrayList_create(&(compInfo->dependency_list));
-
- //Fill in the fields of the component
- char *outstr;
- asprintf(&outstr, "%p",component->implementation);
- compInfo->id = outstr;
- compInfo->active = component->active;
-
- array_list_pt interfaces = component->dm_interface;
- array_list_pt dependencies = component->dependencies;
-
- for(i = 0; i < arrayList_size(interfaces); i++) {
- dm_interface * interface = arrayList_get(interfaces, i);
- arrayList_add(compInfo->interface_list, strdup(interface->serviceName));
- }
-
- for(i = 0; i < arrayList_size(dependencies); i++) {
- dm_service_dependency_pt dependency = arrayList_get(dependencies, i);
-
- dependency_info_pt depInfo = calloc(sizeof(*depInfo), 1);
- depInfo->available = dependency->available;
- depInfo->required = dependency->required;
- if(dependency->tracked_filter) {
- depInfo->interface = strdup(dependency->tracked_filter);
- } else {
- depInfo->interface = strdup(dependency->tracked_service_name);
- }
- arrayList_add(compInfo->dependency_list, depInfo);
- }
-
- arrayList_add(info->components, compInfo);
- }
-
- return CELIX_SUCCESS;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_service_dependency.c b/dependency_manager/private/src/dm_service_dependency.c
index f89dc94..61daa07 100644
--- a/dependency_manager/private/src/dm_service_dependency.c
+++ b/dependency_manager/private/src/dm_service_dependency.c
@@ -150,6 +150,11 @@ celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency,
return status;
}
+celix_status_t serviceDependency_getFilter(dm_service_dependency_pt dependency, char **filter) {
+ *filter = dependency->tracked_filter;
+ return CELIX_SUCCESS;
+}
+
celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_set_fpt set, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap) {
celix_status_t status = CELIX_SUCCESS;
@@ -624,3 +629,32 @@ celix_status_t serviceDependency_removedService(void *_ptr, service_reference_pt
return status;
}
+
+celix_status_t serviceDependency_getServiceDependencyInfo(dm_service_dependency_pt dep, dm_service_dependency_info_pt *out) {
+ celix_status_t status = CELIX_SUCCESS;
+ dm_service_dependency_info_pt info = calloc(1, sizeof(*info));
+ if (info != NULL) {
+ celixThreadMutex_lock(&dep->lock);
+ info->available = dep->available;
+ info->filter = dep->tracked_filter != NULL ? strdup(dep->tracked_filter) : NULL;
+ if (info->filter == NULL) {
+ info->filter = dep->tracked_service_name != NULL ? strdup(dep->tracked_service_name) : NULL;
+ }
+ info->required = dep->required;
+
+ array_list_pt refs = serviceTracker_getServiceReferences(dep->tracker);
+ if (refs != NULL) {
+ info->count = arrayList_size(refs);
+ }
+
+ celixThreadMutex_unlock(&dep->lock);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+
+ if (status == CELIX_SUCCESS) {
+ *out = info;
+ }
+
+ return status;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_shell_activator.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_activator.c b/dependency_manager/private/src/dm_shell_activator.c
index 7cdd561..4adfd0a 100644
--- a/dependency_manager/private/src/dm_shell_activator.c
+++ b/dependency_manager/private/src/dm_shell_activator.c
@@ -66,16 +66,8 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
bundle_instance_pt bi = (bundle_instance_pt) userData;
command_service_pt commandService = calloc(1, sizeof(*commandService));
- command_pt command = calloc(sizeof(*command),1);
- command->executeCommand = dmListCommand_execute;
- command->bundleContext = context;
- command->handle = NULL;
- command->name ="dm:list";
- command->shortDescription ="not_used";
- command->usage="not_used";
-
commandService->getName = dmListCommand_getName;
- commandService->command = command;
+ commandService->command = context;
commandService->executeCommand = dmListCommand_execute;
commandService->getShortDescription = dmListCommand_getShortDescription;
commandService->getUsage = dmListCommand_getUsage;
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
index 74460fa..3c2c43d 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -25,7 +25,8 @@
*/
#include <stdlib.h>
#include <string.h>
-#include "dm_server.h"
+#include <dm_dependency_manager.h>
+#include "dm_info.h"
#include "service_reference.h"
#include "command_impl.h"
#include "array_list.h"
@@ -34,65 +35,83 @@
#include "shell.h"
-void dmListCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *));
-
-
char * dmListCommand_getName(command_pt command) {
- return "dm:list";
+ return "dm";
}
char * dmListCommand_getUsage(command_pt command) {
- return "dm:list";
+ return "dm [overview|notavail]";
}
char * dmListCommand_getShortDescription(command_pt command) {
- return "Get an overview of the dependency-managed components with their dependencies.";
+ return "\t overview: Get an overview of the dependency-managed components with their dependencies.\n\tnotavail: Get an overview of dependency-managed compononentes where required depencies are not available. ";
}
void dmListCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *)) {
char outString[256];
array_list_pt servRefs = NULL;
int i;
- bundleContext_getServiceReferences(command->bundleContext, DM_SERVICE_NAME ,NULL, &servRefs);
+ bundle_context_pt context = (void *)command;
+ bundleContext_getServiceReferences(context, DM_INFO_SERVICE_NAME ,NULL, &servRefs);
+ char *term = getenv("TERM");
+ bool colors = false;
+ if (strcmp("xterm-256color", term) == 0) {
+ colors = true;
+ }
for(i = 0; i < arrayList_size(servRefs); i++) {
- struct dm_info info;
- dm_service_pt dmService = NULL;
+ dm_dependency_manager_info_pt info = NULL;
+ dm_info_service_pt infoServ = NULL;
service_reference_pt servRef = NULL;
servRef = arrayList_get(servRefs, i);
- bundleContext_getService(command->bundleContext, servRef, (void**)&dmService);
- dmService->getInfo(dmService->server, &info);
+ bundleContext_getService(context, servRef, (void**)&infoServ);
+ infoServ->getInfo(infoServ->handle, &info);
int cmpCnt;
- for (cmpCnt = 0; cmpCnt < arrayList_size(info.components); cmpCnt++) {
- dm_component_info_pt compInfo = arrayList_get(info.components, cmpCnt);
- sprintf(outString, "Component: ID=%s, Active=%s\n", compInfo->id, compInfo->active ? "true" : "false");
+ for (cmpCnt = 0; cmpCnt < arrayList_size(info->components); cmpCnt++) {
+ dm_component_info_pt compInfo = arrayList_get(info->components, cmpCnt);
+ char *startColors = "";
+ char *endColors = "";
+ if (colors) {
+ startColors = compInfo->active ? "\033[92m" : "\033[91m";
+ endColors = "\033[m";
+ }
+ sprintf(outString, "Component: ID=%s, %sActive=%s%s\n", compInfo->id, startColors, compInfo->active ? "true " : "false", endColors);
out(outString);
int interfCnt;
- sprintf(outString, " Interfaces (%d):\n", arrayList_size(compInfo->interface_list));
+ sprintf(outString, "|- Interfaces (%d):\n", arrayList_size(compInfo->interfaces));
out(outString);
- for(interfCnt = 0 ;interfCnt < arrayList_size(compInfo->interface_list); interfCnt++) {
+ for(interfCnt = 0 ;interfCnt < arrayList_size(compInfo->interfaces); interfCnt++) {
char * interface;
- interface = arrayList_get(compInfo->interface_list, interfCnt);
- sprintf(outString, " Interface: %s\n", interface);
+ interface = arrayList_get(compInfo->interfaces, interfCnt);
+ sprintf(outString, " |- Interface: %s\n", interface);
out(outString);
free(interface);
}
- arrayList_destroy(compInfo->interface_list);
+ arrayList_destroy(compInfo->interfaces);
int depCnt;
- sprintf(outString, " Dependencies (%d):\n", arrayList_size(compInfo->dependency_list));
+ sprintf(outString, "|- Dependencies (%d):\n", arrayList_size(compInfo->dependency_list));
out(outString);
for(depCnt = 0 ;depCnt < arrayList_size(compInfo->dependency_list); depCnt++) {
- dependency_info_pt dependency;
+ dm_service_dependency_info_pt dependency;
dependency = arrayList_get(compInfo->dependency_list, depCnt);
- sprintf(outString, " Dependency: Available = %s, Required = %s, Filter = %s\n",
- dependency->available? "true" : "false" ,
- dependency->required ? "true" : "false",
- dependency->interface);
+ char *startColors = "";
+ char *endColors = "";
+ if (colors) {
+ startColors = dependency->available ? "\033[92m" : "\033[91m";
+ endColors = "\033[m";
+ }
+ sprintf(outString, " |- Dependency: %sAvailable = %s%s, Required = %s, Filter = %s\n",
+ startColors,
+ dependency->available ? "true " : "false" ,
+ endColors,
+ dependency->required ? "true " : "false",
+ dependency->filter
+ );
out(outString);
- free(dependency->interface);
+ free(dependency->filter);
free(dependency);
}
arrayList_destroy(compInfo->dependency_list);
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/public/include/dm_component.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_component.h b/dependency_manager/public/include/dm_component.h
index 6b875b2..ab8ac80 100644
--- a/dependency_manager/public/include/dm_component.h
+++ b/dependency_manager/public/include/dm_component.h
@@ -30,25 +30,36 @@
#include <bundle_context.h>
#include <celix_errno.h>
+#include "dm_service_dependency.h"
+
typedef struct dm_component *dm_component_pt;
-#include "dm_dependency_manager.h"
-#include "dm_service_dependency.h"
+#include "dm_component.h"
typedef celix_status_t (*init_fpt)(void *userData);
typedef celix_status_t (*start_fpt)(void *userData);
typedef celix_status_t (*stop_fpt)(void *userData);
typedef celix_status_t (*deinit_fpt)(void *userData);
-celix_status_t component_create(bundle_context_pt context, dm_dependency_manager_pt manager, dm_component_pt *component);
+celix_status_t component_create(bundle_context_pt context, dm_component_pt *component);
celix_status_t component_destroy(dm_component_pt *component);
celix_status_t component_addInterface(dm_component_pt component, char *serviceName, void *service, properties_pt properties);
celix_status_t component_setImplementation(dm_component_pt component, void *implementation);
+/**
+ * Returns an arraylist of service names. The caller owns the arraylist and strings (char *)
+ */
+celix_status_t component_getInterfaces(dm_component_pt component, array_list_pt *servicesNames);
+
celix_status_t component_addServiceDependency(dm_component_pt component, ...);
celix_status_t component_removeServiceDependency(dm_component_pt component, dm_service_dependency_pt dependency);
celix_status_t component_setCallbacks(dm_component_pt component, init_fpt init, start_fpt start, stop_fpt stop, deinit_fpt deinit);
+/**
+ * returns a dm_component_info_pt. Caller has ownership.
+ */
+celix_status_t component_getComponentInfo(dm_component_pt component, dm_component_info_pt *info);
+
#endif /* COMPONENT_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/public/include/dm_dependency_manager.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_dependency_manager.h b/dependency_manager/public/include/dm_dependency_manager.h
index 4311d3a..ab6e27f 100644
--- a/dependency_manager/public/include/dm_dependency_manager.h
+++ b/dependency_manager/public/include/dm_dependency_manager.h
@@ -30,16 +30,20 @@
#include "bundle_context.h"
#include "celix_errno.h"
#include "array_list.h"
+#include "dm_info.h"
+#include "dm_component.h"
typedef struct dm_dependency_manager *dm_dependency_manager_pt;
-#include "dm_component.h"
-
celix_status_t dependencyManager_create(bundle_context_pt context, dm_dependency_manager_pt *manager);
celix_status_t dependencyManager_destroy(dm_dependency_manager_pt *manager);
celix_status_t dependencyManager_add(dm_dependency_manager_pt manager, dm_component_pt component);
celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_component_pt component);
-celix_status_t dependencyManager_getComponents(dm_dependency_manager_pt manager, array_list_pt* components);
+
+/**
+ * returns a dm_ of dm_dependency_manager_info. Caller has ownership.
+ */
+celix_status_t dependencyManager_getInfo(dm_dependency_manager_pt manager, dm_dependency_manager_info_pt *info);
#endif /* DM_DEPENDENCY_MANAGER_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/public/include/dm_info.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_info.h b/dependency_manager/public/include/dm_info.h
new file mode 100644
index 0000000..f010387
--- /dev/null
+++ b/dependency_manager/public/include/dm_info.h
@@ -0,0 +1,63 @@
+/**
+ *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.
+ */
+/*
+ * dm_server.h
+ *
+ * \date 15 Oct 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+#ifndef CELIX_DM_INFO_SERVICE_H
+#define CELIX_DM_INFO_SERVICE_H
+
+#include <stdbool.h>
+#include "array_list.h"
+
+#define DM_INFO_SERVICE_NAME "dm_info"
+
+
+typedef struct dm_service_dependency_info {
+ char *filter;
+ bool available;
+ bool required;
+ size_t count;
+} * dm_service_dependency_info_pt;
+
+typedef struct dm_component_info {
+ char *id;
+ bool active;
+ array_list_pt interfaces; // type char*
+ array_list_pt dependency_list; // type interface_info_pt
+} * dm_component_info_pt;
+
+typedef struct dm_dependency_manager_info {
+ array_list_pt components; // type dm_component_info
+} * dm_dependency_manager_info_pt;
+
+struct dm_info_service {
+ void *handle;
+
+ /*Note: dm_caller has the ownership of the result.*/
+ celix_status_t (*getInfo)(void *handle, dm_dependency_manager_info_pt *info);
+};
+
+typedef struct dm_info_service * dm_info_service_pt;
+
+
+#endif //CELIX_DM_INFO_SERVICE_H
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/public/include/dm_server.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_server.h b/dependency_manager/public/include/dm_server.h
deleted file mode 100644
index 15c87d5..0000000
--- a/dependency_manager/public/include/dm_server.h
+++ /dev/null
@@ -1,60 +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.
- */
-/*
- * dm_server.h
- *
- * \date 15 Oct 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#ifndef CELIX_DM_SERVICE_H
-#define CELIX_DM_SERVICE_H
-
-#include "bundle_context.h"
-
-#define DM_SERVICE_NAME "dm_server"
-
-typedef struct dm_server * dm_server_pt;
-
-typedef struct dependency_info {
- char *interface;
- bool available;
- bool required;
-} * dependency_info_pt;
-
-typedef struct dm_component_info {
- char *id;
- bool active;
- array_list_pt interface_list; // type char*
- array_list_pt dependency_list; // type interface_info_pt
-} * dm_component_info_pt;
-
-typedef struct dm_info {
- array_list_pt components; // type dm_component_info
-} * dm_info_pt;
-
-struct dm_service {
- dm_server_pt server;
- celix_status_t (*getInfo)(dm_server_pt server, dm_info_pt info);
-};
-
-typedef struct dm_service * dm_service_pt;
-
-
-#endif //CELIX_DM_SERVICE_H
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/dependency_manager/public/include/dm_service_dependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_service_dependency.h b/dependency_manager/public/include/dm_service_dependency.h
index f267ab7..4a9c991 100644
--- a/dependency_manager/public/include/dm_service_dependency.h
+++ b/dependency_manager/public/include/dm_service_dependency.h
@@ -28,10 +28,10 @@
#define DM_SERVICE_DEPENDENCY_H_
#include "celix_errno.h"
+#include "dm_info.h"
-typedef struct dm_service_dependency *dm_service_dependency_pt;
-#include "dm_component.h"
+typedef struct dm_service_dependency *dm_service_dependency_pt;
typedef celix_status_t (*service_set_fpt)(void *handle, void *service);
typedef celix_status_t (*service_add_fpt)(void *handle, void *service);
@@ -50,8 +50,14 @@ celix_status_t serviceDependency_destroy(dm_service_dependency_pt *dependency_pt
celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required);
celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName, char *filter);
+celix_status_t serviceDependency_getFilter(dm_service_dependency_pt dependency, char **filter);
celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_set_fpt set, service_add_fpt add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap);
celix_status_t serviceDependency_setCallbacksWithServiceReference(dm_service_dependency_pt dependency, service_set_with_ref_fpt set, service_add_with_ref_fpt add, service_change_with_ref_fpt change, service_remove_with_ref_fpt remove, service_swap_with_ref_fpt swap);
celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t *service_lock, void **field);
+/**
+ * Return a service dependency info. The caller is the owner
+ */
+celix_status_t serviceDependency_getServiceDependencyInfo(dm_service_dependency_pt, dm_service_dependency_info_pt *info);
+
#endif /* DM_SERVICE_DEPENDENCY_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/664845ca/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
index 5dd8d1e..51e22d6 100644
--- a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
+++ b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
@@ -54,7 +54,7 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
data->context = context;
- component_create(context, manager, &service);
+ component_create(context, &service);
component_setImplementation(service, data);
component_setCallbacks(service, service_init, service_start, service_stop, service_deinit);
[13/21] celix git commit: CELIX-210: Added optional name for dm
component. This should help in keeping an overview of the components. Note
that in C we cannot use the runtime available classname for info purpose.
Posted by pn...@apache.org.
CELIX-210: Added optional name for dm component. This should help in keeping an overview of the components. Note that in C we cannot use the runtime available classname for info purpose.
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/22461748
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/22461748
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/22461748
Branch: refs/heads/develop
Commit: 224617488a2137935d7013b49cf46a77eb494ad2
Parents: f48fee1
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Oct 23 09:41:29 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Oct 23 09:41:29 2015 +0200
----------------------------------------------------------------------
.../private/include/dm_component_impl.h | 3 ++-
dependency_manager/private/src/dm_component_impl.c | 15 ++++++++++-----
.../private/src/dm_shell_list_command.c | 4 +++-
dependency_manager/public/include/dm_component.h | 5 ++++-
dependency_manager/public/include/dm_info.h | 3 ++-
.../private/src/dependency_activator.c | 2 +-
6 files changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/dependency_manager/private/include/dm_component_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_component_impl.h b/dependency_manager/private/include/dm_component_impl.h
index 42857d2..4963b44 100644
--- a/dependency_manager/private/include/dm_component_impl.h
+++ b/dependency_manager/private/include/dm_component_impl.h
@@ -50,7 +50,8 @@ typedef struct dm_interface_struct {
} dm_interface;
struct dm_component {
- char *id;
+ char id[DM_COMPONENT_MAX_ID_LENGTH];
+ char name[DM_COMPONENT_MAX_NAME_LENGTH];
bundle_context_pt context;
array_list_pt dm_interface;
http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index 500d613..ec13933 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -95,16 +95,19 @@ static celix_status_t component_handleChanged(dm_component_pt component, dm_serv
static celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event);
static celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt event, dm_event_pt newEvent);
-celix_status_t component_create(bundle_context_pt context, dm_component_pt *component) {
+celix_status_t component_create(bundle_context_pt context, const char *name, dm_component_pt *component) {
celix_status_t status = CELIX_SUCCESS;
*component = malloc(sizeof(**component));
if (!*component) {
status = CELIX_ENOMEM;
} else {
- char id[16];
- snprintf(id, 16, "%p", *component);
- (*component)->id = strdup(id);
+ snprintf((*component)->id, DM_COMPONENT_MAX_ID_LENGTH, "%p", *component);
+ if (name == NULL) {
+ snprintf((*component)->name, DM_COMPONENT_MAX_NAME_LENGTH, "%s", "n/a");
+ } else {
+ snprintf((*component)->name, DM_COMPONENT_MAX_NAME_LENGTH, "%s", name);
+ }
(*component)->context = context;
arrayList_create(&((*component)->dm_interface));
@@ -1320,7 +1323,9 @@ celix_status_t component_getComponentInfo(dm_component_pt component, dm_componen
arrayList_create(&info->dependency_list);
component_getInterfaces(component, &info->interfaces);
info->active = false;
- info->id = strdup(component->id);
+ memcpy(info->id, component->id, DM_COMPONENT_MAX_ID_LENGTH);
+ memcpy(info->name, component->name, DM_COMPONENT_MAX_NAME_LENGTH);
+
switch (component->state) {
case DM_CMP_STATE_INACTIVE :
info->state = strdup("INACTIVE");
http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
index 030d909..4d08068 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -81,7 +81,7 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
startColors = compInfo->active ? OK_COLOR : NOK_COLOR;
endColors = END_COLOR;
}
- sprintf(outString, "Component: ID=%s, %sActive=%s%s, State=%s\n", compInfo->id, startColors, compInfo->active ? "true " : "false", endColors, compInfo->state);
+ sprintf(outString, "Component: Name=%s\n|- ID=%s, %sActive=%s%s, State=%s\n", compInfo->name, compInfo->id, startColors, compInfo->active ? "true " : "false", endColors, compInfo->state);
out(outString);
int interfCnt;
@@ -120,6 +120,8 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
);
out(outString);
}
+ sprintf(outString, "\n");
+ out(outString);
infoServ->destroyInfo(infoServ->handle, info);
}
http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/dependency_manager/public/include/dm_component.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_component.h b/dependency_manager/public/include/dm_component.h
index c26cc05..12dbcca 100644
--- a/dependency_manager/public/include/dm_component.h
+++ b/dependency_manager/public/include/dm_component.h
@@ -36,12 +36,15 @@ typedef struct dm_component *dm_component_pt;
#include "dm_component.h"
+#define DM_COMPONENT_MAX_ID_LENGTH 64
+#define DM_COMPONENT_MAX_NAME_LENGTH 128
+
typedef celix_status_t (*init_fpt)(void *userData);
typedef celix_status_t (*start_fpt)(void *userData);
typedef celix_status_t (*stop_fpt)(void *userData);
typedef celix_status_t (*deinit_fpt)(void *userData);
-celix_status_t component_create(bundle_context_pt context, dm_component_pt *component);
+celix_status_t component_create(bundle_context_pt context, const char *name, dm_component_pt *component);
celix_status_t component_destroy(dm_component_pt *component);
celix_status_t component_addInterface(dm_component_pt component, char *serviceName, void *service, properties_pt properties);
http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/dependency_manager/public/include/dm_info.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_info.h b/dependency_manager/public/include/dm_info.h
index 16ee0f8..dd9947c 100644
--- a/dependency_manager/public/include/dm_info.h
+++ b/dependency_manager/public/include/dm_info.h
@@ -40,7 +40,8 @@ typedef struct dm_service_dependency_info {
} * dm_service_dependency_info_pt;
typedef struct dm_component_info {
- char *id;
+ char id[64];
+ char name[128];
bool active;
char * state;
array_list_pt interfaces; // type char*
http://git-wip-us.apache.org/repos/asf/celix/blob/22461748/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
index 51e22d6..4e36321 100644
--- a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
+++ b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
@@ -54,7 +54,7 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
data->context = context;
- component_create(context, &service);
+ component_create(context, "ExampleCmp", &service);
component_setImplementation(service, data);
component_setCallbacks(service, service_init, service_start, service_stop, service_deinit);