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 2018/05/29 17:33:07 UTC

[2/5] celix git commit: CELIX-446: Refactor the bundle activators of the service_example_c and best_practice_example_c to use the activator generation macro

CELIX-446: Refactor the bundle activators of the service_example_c and best_practice_example_c to use the activator generation macro


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/3e5a6a79
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/3e5a6a79
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/3e5a6a79

Branch: refs/heads/feature/CELIX-426-cxx-api
Commit: 3e5a6a797c190e5073b7260393a41fc70cf7ffb1
Parents: afcfea1
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon May 28 11:45:09 2018 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon May 28 11:45:09 2018 +0200

----------------------------------------------------------------------
 .../best_practice_example_c/bar/CMakeLists.txt  | 13 +--
 .../bar/private/src/bar_activator.c             | 53 +++++--------
 .../best_practice_example_c/foo1/CMakeLists.txt | 13 +--
 .../foo1/private/src/foo1_activator.c           | 83 +++++++++-----------
 .../best_practice_example_c/foo2/CMakeLists.txt | 13 +--
 .../foo2/private/src/foo2_activator.c           | 83 +++++++++-----------
 .../src/dynamic_consumer_example.c              | 41 +++-------
 .../src/dynamic_provider_example.c              | 51 ++++--------
 .../src/simple_consumer_example.c               | 29 ++-----
 .../src/simple_provider_example.c               | 39 +++------
 libs/framework/include/bundle_activator.h       | 39 +++++++++
 11 files changed, 177 insertions(+), 280 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/3e5a6a79/examples/celix-examples/best_practice_example_c/bar/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_c/bar/CMakeLists.txt b/examples/celix-examples/best_practice_example_c/bar/CMakeLists.txt
index 7df3051..38083ae 100644
--- a/examples/celix-examples/best_practice_example_c/bar/CMakeLists.txt
+++ b/examples/celix-examples/best_practice_example_c/bar/CMakeLists.txt
@@ -25,15 +25,4 @@ add_celix_bundle(bar
     SOURCES
         private/src/bar_activator
         private/src/bar.c
-)
-
-IF(APPLE)
-    target_link_libraries(bar PRIVATE Celix::framework  -Wl,-all_load dependency_manager_static)
-else()
-    if(ENABLE_ADDRESS_SANITIZER)
-        #With asan there can be undefined symbols
-        target_link_libraries(bar PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive Celix::framework )
-    else()
-        target_link_libraries(bar PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive Celix::framework )
-    endif()
-endif()
+)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/3e5a6a79/examples/celix-examples/best_practice_example_c/bar/private/src/bar_activator.c
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_c/bar/private/src/bar_activator.c b/examples/celix-examples/best_practice_example_c/bar/private/src/bar_activator.c
index 0fa7889..39d0164 100644
--- a/examples/celix-examples/best_practice_example_c/bar/private/src/bar_activator.c
+++ b/examples/celix-examples/best_practice_example_c/bar/private/src/bar_activator.c
@@ -22,49 +22,32 @@
 
 #include <stdlib.h>
 
-struct activator {
+typedef struct activator {
 	bar_t *bar;
 	example_t exampleService;
-};
+} activator_t;
 
-celix_status_t dm_create(bundle_context_pt context, void **userData) {
+static celix_status_t activator_start(activator_t *act, celix_bundle_context_t *ctx) {
 	celix_status_t status = CELIX_SUCCESS;
-	struct activator *act = calloc(1, sizeof(*act));
-	if (act != NULL) {
-
-		act->bar = bar_create();
-		act->exampleService.handle = act->bar;
-		act->exampleService.method = (void*) bar_method;
-
-		if (act->bar != NULL) {
-            *userData = act;
-        } else {
-            free(act);
-        }
-	} else {
+	act->bar = bar_create();
+	act->exampleService.handle = act->bar;
+	act->exampleService.method = (void*) bar_method;
+	if (act->bar == NULL) {
 		status = CELIX_ENOMEM;
+	} else {
+		dm_component_pt cmp = NULL;
+		component_create(ctx, "BAR", &cmp);
+		component_setImplementation(cmp, act->bar);
+		component_addInterface(cmp, EXAMPLE_NAME, EXAMPLE_VERSION, &act->exampleService, NULL);
+		dependencyManager_add(celix_bundleContext_getDependencyManager(ctx), cmp);
 	}
 	return status;
 }
 
-celix_status_t dm_init(void *userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
-    celix_status_t status = CELIX_SUCCESS;
-	struct activator *activator = userData;
-
-	dm_component_pt cmp = NULL;
-	component_create(context, "BAR", &cmp);
-	component_setImplementation(cmp, activator->bar);
-	component_addInterface(cmp, EXAMPLE_NAME, EXAMPLE_VERSION, &activator->exampleService, NULL);
-
-	dependencyManager_add(manager, cmp);
-    return status;
+static celix_status_t activator_stop(activator_t *act, celix_bundle_context_t *ctx) {
+	dependencyManager_removeAllComponents(celix_bundleContext_getDependencyManager(ctx));
+	bar_destroy(act->bar);
+	return CELIX_SUCCESS;
 }
 
-celix_status_t dm_destroy(void *userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
-	celix_status_t status = CELIX_SUCCESS;
-	struct activator *activator = userData;
-	bar_destroy(activator->bar);
-	free(activator);
-	return status;
-};
-
+CELIX_GEN_BUNDLE_ACTIVATOR(activator_t, activator_start, activator_stop)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/3e5a6a79/examples/celix-examples/best_practice_example_c/foo1/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_c/foo1/CMakeLists.txt b/examples/celix-examples/best_practice_example_c/foo1/CMakeLists.txt
index d732c76..b3cdb53 100644
--- a/examples/celix-examples/best_practice_example_c/foo1/CMakeLists.txt
+++ b/examples/celix-examples/best_practice_example_c/foo1/CMakeLists.txt
@@ -25,15 +25,4 @@ add_celix_bundle(foo1
     SOURCES
         private/src/foo1_activator
         private/src/foo1.c
-)
-
-IF(APPLE)
-    target_link_libraries(foo1 PRIVATE -Wl,-all_load dependency_manager_static)
-else()
-    if(ENABLE_ADDRESS_SANITIZER)
-        #With asan there can be undefined symbols
-        target_link_libraries(foo1 PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
-    else()
-        target_link_libraries(foo1 PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
-    endif()
-endif()
+)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/3e5a6a79/examples/celix-examples/best_practice_example_c/foo1/private/src/foo1_activator.c
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_c/foo1/private/src/foo1_activator.c b/examples/celix-examples/best_practice_example_c/foo1/private/src/foo1_activator.c
index f94888b..6b2f578 100644
--- a/examples/celix-examples/best_practice_example_c/foo1/private/src/foo1_activator.c
+++ b/examples/celix-examples/best_practice_example_c/foo1/private/src/foo1_activator.c
@@ -26,63 +26,50 @@ struct activator {
 	foo1_t *foo;
 };
 
-celix_status_t dm_create(bundle_context_pt context, void **userData) {
+static celix_status_t activator_start(activator_t *act, celix_bundle_context_t *ctx) {
 	celix_status_t status = CELIX_SUCCESS;
-	struct activator *act = calloc(1, sizeof(*act));
-	if (act != NULL) {
-		act->foo = foo1_create();
-        if (act->foo != NULL) {
-            *userData = act;
-        } else {
-            free(act);
-        }
-	} else {
+	act->foo = foo1_create();
+	if (act->foo == NULL) {
 		status = CELIX_ENOMEM;
-	}
-	return status;
-}
-
-celix_status_t dm_init(void *userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
-    celix_status_t status = CELIX_SUCCESS;
-	struct activator *activator = userData;
+	} else {
+		dm_component_pt cmp = NULL;
+		component_create(ctx, "FOO1", &cmp);
+		component_setImplementation(cmp, act->foo);
 
-	dm_component_pt cmp = NULL;
-	component_create(context, "FOO1", &cmp);
-	component_setImplementation(cmp, activator->foo);
+		/*
+        With the component_setCallbacksSafe we register callbacks when a component is started / stopped using a component
+         with type foo1_t*
+        */
+		component_setCallbacksSafe(cmp, foo1_t*, NULL, foo1_start, foo1_stop, NULL);
 
-	/*
-	With the component_setCallbacksSafe we register callbacks when a component is started / stopped using a component
-	 with type foo1_t*
-	*/
-    component_setCallbacksSafe(cmp, foo1_t*, NULL, foo1_start, foo1_stop, NULL);
+		dm_service_dependency_pt dep = NULL;
+		serviceDependency_create(&dep);
+		serviceDependency_setRequired(dep, true);
+		serviceDependency_setService(dep, EXAMPLE_NAME, EXAMPLE_CONSUMER_RANGE, NULL);
+		serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING);
 
-	dm_service_dependency_pt dep = NULL;
-	serviceDependency_create(&dep);
-	serviceDependency_setRequired(dep, true);
-	serviceDependency_setService(dep, EXAMPLE_NAME, EXAMPLE_CONSUMER_RANGE, NULL);
-	serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING);
+		/*
+        With the serviceDependency_setCallbacksSafe we register callbacks when a service
+        is added and about to be removed for the component type foo1_t* and service type example_t*.
 
-	/*
-	With the serviceDependency_setCallbacksSafe we register callbacks when a service
-	is added and about to be removed for the component type foo1_t* and service type example_t*.
+        We should protect the usage of the
+         service because after removal of the service the memory location of that service
+        could be freed
+        */
+		serviceDependency_setCallbacksSafe(dep, foo1_t*, const example_t*, foo1_setExample, NULL, NULL, NULL, NULL);
+		component_addServiceDependency(cmp, dep);
 
-	We should protect the usage of the
- 	service because after removal of the service the memory location of that service
-	could be freed
-	*/
-    serviceDependency_setCallbacksSafe(dep, foo1_t*, const example_t*, foo1_setExample, NULL, NULL, NULL, NULL);
-	component_addServiceDependency(cmp, dep);
+		dependencyManager_add(celix_bundleContext_getDependencyManager(ctx), cmp);
 
-	dependencyManager_add(manager, cmp);
+	}
+	return status;
+}
 
-    return status;
+static celix_status_t activator_stop(activator_t *act, celix_bundle_context_t *ctx) {
+	dependencyManager_removeAllComponents(celix_bundleContext_getDependencyManager(ctx));
+	foo1_destroy(act->foo);
+	return CELIX_SUCCESS;
 }
 
-celix_status_t dm_destroy(void *userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
-	celix_status_t status = CELIX_SUCCESS;
-	struct activator *activator = userData;
-	foo1_destroy(activator->foo);
-	free(activator);
-	return status;
-};
 
+CELIX_GEN_BUNDLE_ACTIVATOR(activator_t, activator_start, activator_stop)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/3e5a6a79/examples/celix-examples/best_practice_example_c/foo2/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_c/foo2/CMakeLists.txt b/examples/celix-examples/best_practice_example_c/foo2/CMakeLists.txt
index adb8f64..f3dd0f3 100644
--- a/examples/celix-examples/best_practice_example_c/foo2/CMakeLists.txt
+++ b/examples/celix-examples/best_practice_example_c/foo2/CMakeLists.txt
@@ -25,15 +25,4 @@ add_celix_bundle(foo2
     SOURCES
         private/src/foo2_activator
         private/src/foo2.c
-)
-
-IF(APPLE)
-    target_link_libraries(foo2 PRIVATE -Wl,-all_load dependency_manager_static)
-else()
-    if(ENABLE_ADDRESS_SANITIZER)
-        #With asan there can be undefined symbols
-        target_link_libraries(foo2 PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
-    else()
-        target_link_libraries(foo2 PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive)
-    endif()
-endif()
+)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/3e5a6a79/examples/celix-examples/best_practice_example_c/foo2/private/src/foo2_activator.c
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_c/foo2/private/src/foo2_activator.c b/examples/celix-examples/best_practice_example_c/foo2/private/src/foo2_activator.c
index 5c047da..309b8c1 100644
--- a/examples/celix-examples/best_practice_example_c/foo2/private/src/foo2_activator.c
+++ b/examples/celix-examples/best_practice_example_c/foo2/private/src/foo2_activator.c
@@ -26,63 +26,52 @@ struct activator {
 	foo2_t *foo;
 };
 
-celix_status_t dm_create(bundle_context_pt context, void **userData) {
+static celix_status_t activator_start(struct activator *act, celix_bundle_context_t *ctx) {
 	celix_status_t status = CELIX_SUCCESS;
-	struct activator *act = calloc(1, sizeof(*act));
-	if (act != NULL) {
-		act->foo = foo2_create();
-        if (act->foo != NULL) {
-            *userData = act;
-        } else {
-            free(act);
-        }
-	} else {
+	act->foo = foo2_create();
+	if (act->foo == NULL) {
 		status = CELIX_ENOMEM;
-	}
-	return status;
-}
+	} else {
 
-celix_status_t dm_init(void *userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
-    celix_status_t status = CELIX_SUCCESS;
-	struct activator *activator = userData;
+		dm_component_pt cmp = NULL;
+		component_create(ctx, "FOO2", &cmp);
+		component_setImplementation(cmp, act->foo);
 
-	dm_component_pt cmp = NULL;
-	component_create(context, "FOO2", &cmp);
-	component_setImplementation(cmp, activator->foo);
+		/*
+		With the component_setCallbacksSafe we register callbacks when a component is started / stopped using a component
+		 with type foo1_t*
+		*/
+		component_setCallbacksSafe(cmp, foo2_t*, NULL, foo2_start, foo2_stop, NULL);
 
-	/*
-	With the component_setCallbacksSafe we register callbacks when a component is started / stopped using a component
-	 with type foo1_t*
-	*/
-    component_setCallbacksSafe(cmp, foo2_t*, NULL, foo2_start, foo2_stop, NULL);
+		dm_service_dependency_pt dep = NULL;
+		serviceDependency_create(&dep);
+		serviceDependency_setRequired(dep, false);
+		serviceDependency_setService(dep, EXAMPLE_NAME, EXAMPLE_CONSUMER_RANGE, NULL);
+		serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND);
 
-	dm_service_dependency_pt dep = NULL;
-	serviceDependency_create(&dep);
-	serviceDependency_setRequired(dep, false);
-	serviceDependency_setService(dep, EXAMPLE_NAME, EXAMPLE_CONSUMER_RANGE, NULL);
-	serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND);
+		/*
+		With the serviceDependency_setCallbacksSafe we register callbacks when a service
+		is added and about to be removed for the component type foo1_t* and service type example_t*.
 
-	/*
-	With the serviceDependency_setCallbacksSafe we register callbacks when a service
-	is added and about to be removed for the component type foo1_t* and service type example_t*.
+		We should protect the usage of the
+		service because after removal of the service the memory location of that service
+		could be freed
+		*/
+		serviceDependency_setCallbacksSafe(dep, foo2_t*, const example_t*, NULL, foo2_addExample, NULL,
+										   foo2_removeExample, NULL);
+		component_addServiceDependency(cmp, dep);
 
-	We should protect the usage of the
- 	service because after removal of the service the memory location of that service
-	could be freed
-	*/
-    serviceDependency_setCallbacksSafe(dep, foo2_t*, const example_t*, NULL, foo2_addExample, NULL, foo2_removeExample, NULL);
-	component_addServiceDependency(cmp, dep);
+		dependencyManager_add(celix_bundleContext_getDependencyManager(ctx), cmp);
+	}
 
-	dependencyManager_add(manager, cmp);
+	return status;
+}
 
-    return status;
+static celix_status_t activator_stop(struct activator *act, celix_bundle_context_t *ctx) {
+	dependencyManager_removeAllComponents(celix_bundleContext_getDependencyManager(ctx));
+	foo2_destroy(act->foo);
+	return CELIX_SUCCESS;
 }
 
-celix_status_t dm_destroy(void *userData, bundle_context_pt context, dm_dependency_manager_pt manager) {
-	celix_status_t status = CELIX_SUCCESS;
-	struct activator *activator = userData;
-	foo2_destroy(activator->foo);
-	free(activator);
-	return status;
-};
 
+CELIX_GEN_BUNDLE_ACTIVATOR(struct activator, activator_start, activator_stop)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/3e5a6a79/examples/celix-examples/services_example_c/src/dynamic_consumer_example.c
----------------------------------------------------------------------
diff --git a/examples/celix-examples/services_example_c/src/dynamic_consumer_example.c b/examples/celix-examples/services_example_c/src/dynamic_consumer_example.c
index b935271..cef384c 100644
--- a/examples/celix-examples/services_example_c/src/dynamic_consumer_example.c
+++ b/examples/celix-examples/services_example_c/src/dynamic_consumer_example.c
@@ -149,39 +149,24 @@ void * run(void *handle) {
     return NULL;
 }
 
-celix_status_t bundleActivator_create(celix_bundle_context_t *ctx, void **out) {
-	celix_status_t status = CELIX_SUCCESS;
-    activator_data_t *data = calloc(1, sizeof(*data));
+static celix_status_t activator_start(activator_data_t *data, celix_bundle_context_t *ctx) {
     if (data != NULL) {
-       data->ctx = ctx;
-       data->trackCount = 0;
-       data->running = true;
-       pthread_mutex_init(&data->mutex, NULL);
-       *out = data;
-	} else {
-		status = CELIX_ENOMEM;
-	}
-	return status;
-}
-
-celix_status_t bundleActivator_start(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
-    pthread_create(&data->thread, NULL, run, data);
-	return CELIX_SUCCESS;
-}
-
-celix_status_t bundleActivator_stop(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
-    setRunning(data, false);
-    pthread_join(data->thread, NULL);
+        data->ctx = ctx;
+        data->trackCount = 0;
+        data->running = true;
+        pthread_mutex_init(&data->mutex, NULL);
+        pthread_create(&data->thread, NULL, run, data);
+    }
     return CELIX_SUCCESS;
 }
 
-celix_status_t bundleActivator_destroy(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
+static celix_status_t activator_stop(activator_data_t *data, celix_bundle_context_t *ctx __attribute__((unused))) {
     if (data != NULL) {
+        setRunning(data, false);
+        pthread_join(data->thread, NULL);
         pthread_mutex_destroy(&data->mutex);
-        free(data);
     }
-	return CELIX_SUCCESS;
+    return CELIX_SUCCESS;
 }
+
+CELIX_GEN_BUNDLE_ACTIVATOR(activator_data_t, activator_start, activator_stop)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/3e5a6a79/examples/celix-examples/services_example_c/src/dynamic_provider_example.c
----------------------------------------------------------------------
diff --git a/examples/celix-examples/services_example_c/src/dynamic_provider_example.c b/examples/celix-examples/services_example_c/src/dynamic_provider_example.c
index 7a7d9d9..4756718 100644
--- a/examples/celix-examples/services_example_c/src/dynamic_provider_example.c
+++ b/examples/celix-examples/services_example_c/src/dynamic_provider_example.c
@@ -41,7 +41,7 @@ static int calc(void *handle __attribute__((unused)), int input) {
 }
 
 static bool isRunning(activator_data_t *data) {
-    bool result = false;
+    bool result;
     pthread_mutex_lock(&data->mutex);
     result = data->running;
     pthread_mutex_unlock(&data->mutex);
@@ -68,7 +68,7 @@ void * run(void *handle) {
             data->svcIds[i++] = celix_bundleContext_registerService(data->ctx, &data->svc, EXAMPLE_CALC_NAME, props);
         } else { //down
             celix_bundleContext_unregisterService(data->ctx, data->svcIds[i]);
-            data->svcIds[--i] = -1L;
+            data->svcIds[i--] = -1L;
         }
         if (i == 99) {
             up = false;
@@ -89,45 +89,26 @@ void * run(void *handle) {
     return NULL;
 }
 
-celix_status_t bundleActivator_create(celix_bundle_context_t *ctx, void **out) {
-	celix_status_t status = CELIX_SUCCESS;
-    activator_data_t *data = calloc(1, sizeof(*data));
-    if (data != NULL) {
-       data->svc.handle = data;
-       data->svc.calc = calc;
-       data->ctx = ctx;
-       data->running = true;
-       pthread_mutex_init(&data->mutex, NULL);
-
-       for (int i = 0; i < 100; ++i) {
-           data->svcIds[i] = -1L;
-       }
-
-       *out = data;
-	} else {
-		status = CELIX_ENOMEM;
-	}
-	return status;
-}
+static celix_status_t activator_start(activator_data_t *data, celix_bundle_context_t *ctx) {
+    data->svc.handle = data;
+    data->svc.calc = calc;
+    data->ctx = ctx;
+    data->running = true;
+    pthread_mutex_init(&data->mutex, NULL);
+
+    for (int i = 0; i < 100; ++i) {
+        data->svcIds[i] = -1L;
+    }
 
-celix_status_t bundleActivator_start(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
     pthread_create(&data->thread, NULL, run ,data);
 	return CELIX_SUCCESS;
 }
 
-celix_status_t bundleActivator_stop(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
+static celix_status_t activator_stop(activator_data_t *data, celix_bundle_context_t *ctx __attribute__((unused))) {
     setRunning(data, false);
     pthread_join(data->thread, NULL);
-    return CELIX_SUCCESS;
-}
-
-celix_status_t bundleActivator_destroy(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
-    if (data != NULL) {
-        pthread_mutex_destroy(&data->mutex);
-        free(data);
-    }
+    pthread_mutex_destroy(&data->mutex);
 	return CELIX_SUCCESS;
 }
+
+CELIX_GEN_BUNDLE_ACTIVATOR(activator_data_t, activator_start, activator_stop)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/3e5a6a79/examples/celix-examples/services_example_c/src/simple_consumer_example.c
----------------------------------------------------------------------
diff --git a/examples/celix-examples/services_example_c/src/simple_consumer_example.c b/examples/celix-examples/services_example_c/src/simple_consumer_example.c
index edf88c6..1204036 100644
--- a/examples/celix-examples/services_example_c/src/simple_consumer_example.c
+++ b/examples/celix-examples/services_example_c/src/simple_consumer_example.c
@@ -47,21 +47,9 @@ static void useCalc(activator_data_t *data __attribute__((unused)), example_calc
     printf("Called highest ranking service. Result is %i\n", result);
 }
 
-celix_status_t bundleActivator_create(celix_bundle_context_t *ctx, void **out) {
-	celix_status_t status = CELIX_SUCCESS;
-    activator_data_t *data = calloc(1, sizeof(*data));
-    if (data != NULL) {
-       data->ctx = ctx;
-       data->trkId = -1L;
-       *out = data;
-	} else {
-		status = CELIX_ENOMEM;
-	}
-	return status;
-}
-
-celix_status_t bundleActivator_start(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
+static celix_status_t activator_start(activator_data_t *data, celix_bundle_context_t *ctx) {
+    data->ctx = ctx;
+    data->trkId = -1L;
 
     printf("Starting service tracker\n");
     data->trkId = celix_bundleContext_trackServices(data->ctx, EXAMPLE_CALC_NAME, data, (void*)addSvc, (void*)removeSvc);
@@ -69,17 +57,12 @@ celix_status_t bundleActivator_start(void * handle, celix_bundle_context_t *ctx)
     printf("Trying to use calc service\n");
     celix_bundleContext_useService(data->ctx, EXAMPLE_CALC_NAME, data, (void*)useCalc);
 
-	return CELIX_SUCCESS;
+    return CELIX_SUCCESS;
 }
 
-celix_status_t bundleActivator_stop(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
+static celix_status_t activator_stop(activator_data_t *data, celix_bundle_context_t *ctx) {
     celix_bundleContext_stopTracker(data->ctx, data->trkId);
     return CELIX_SUCCESS;
 }
 
-celix_status_t bundleActivator_destroy(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
-    free(data);
-	return CELIX_SUCCESS;
-}
+CELIX_GEN_BUNDLE_ACTIVATOR(activator_data_t, activator_start, activator_stop)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/3e5a6a79/examples/celix-examples/services_example_c/src/simple_provider_example.c
----------------------------------------------------------------------
diff --git a/examples/celix-examples/services_example_c/src/simple_provider_example.c b/examples/celix-examples/services_example_c/src/simple_provider_example.c
index 3358903..486225a 100644
--- a/examples/celix-examples/services_example_c/src/simple_provider_example.c
+++ b/examples/celix-examples/services_example_c/src/simple_provider_example.c
@@ -25,7 +25,6 @@
 #include "constants.h"
 
 typedef struct activator_data {
-    celix_bundle_context_t *ctx;
     example_calc_t svc;
     int seed;
     long svcId;
@@ -36,38 +35,22 @@ static int calc(activator_data_t *data, int input) {
     return data->seed * input;
 }
 
-celix_status_t bundleActivator_create(celix_bundle_context_t *ctx, void **out) {
-	celix_status_t status = CELIX_SUCCESS;
-    activator_data_t *data = calloc(1, sizeof(*data));
-    if (data != NULL) {
-       data->svc.handle = data;
-       data->svc.calc = (void*)calc;
-       data->ctx = ctx;
-       data->seed = 42;
-       data->svcId = -1L;
-       *out = data;
-	} else {
-		status = CELIX_ENOMEM;
-	}
-	return status;
-}
+static celix_status_t activator_start(activator_data_t *data, celix_bundle_context_t *ctx) {
+    data->svc.handle = data;
+    data->svc.calc = (void*)calc;
+    data->seed = 42;
+    data->svcId = -1L;
 
-celix_status_t bundleActivator_start(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
-    data->svcId = celix_bundleContext_registerService(data->ctx, &data->svc, EXAMPLE_CALC_NAME, NULL);
+    data->svcId = celix_bundleContext_registerService(ctx, &data->svc, EXAMPLE_CALC_NAME, NULL);
     printf("Registered calc service with service id %li\n", data->svcId);
-	return CELIX_SUCCESS;
+
+    return CELIX_SUCCESS;
 }
 
-celix_status_t bundleActivator_stop(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
-    celix_bundleContext_unregisterService(data->ctx, data->svcId);
+static celix_status_t activator_stop(activator_data_t *data, celix_bundle_context_t *ctx) {
+    celix_bundleContext_unregisterService(ctx, data->svcId);
     printf("Unregistered calc service with service id %li\n", data->svcId);
     return CELIX_SUCCESS;
 }
 
-celix_status_t bundleActivator_destroy(void * handle, celix_bundle_context_t *ctx) {
-    activator_data_t *data = handle;
-    free(data);
-	return CELIX_SUCCESS;
-}
+CELIX_GEN_BUNDLE_ACTIVATOR(activator_data_t, activator_start, activator_stop)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/3e5a6a79/libs/framework/include/bundle_activator.h
----------------------------------------------------------------------
diff --git a/libs/framework/include/bundle_activator.h b/libs/framework/include/bundle_activator.h
index 8c91957..3265f65 100644
--- a/libs/framework/include/bundle_activator.h
+++ b/libs/framework/include/bundle_activator.h
@@ -116,6 +116,45 @@ ACTIVATOR_EXPORT celix_status_t bundleActivator_stop(void *userData, bundle_cont
 ACTIVATOR_EXPORT celix_status_t
 bundleActivator_destroy(void *userData, bundle_context_t* context);
 
+
+/**
+ * This macro generated the required bundle activator functions. These can be used to more type safe bundle activator
+ * entries.
+ *
+ * The macro will create the following bundlea activator functions:
+ * - bundleActivator_create which allocates a pointer to the provided type.
+ * - bundleActivator_start/stop which will call the respectively provided typed start/stop functions.
+ * - bundleActivator_destroy will free the allocated for the provided type.
+ *
+ * @param type The activator type (e.g. 'struct shell_activator').
+ * @param start the activator actStart function with the following signature: celix_status_t (*)(<actType>*, celix_bundle_context_t*).
+ * @param stop the activator actStop function with the following signature: celix_status_t (*)(<actType>*, celix_bundle_context_t*).
+ */
+#define CELIX_GEN_BUNDLE_ACTIVATOR(actType, actStart, actStop)                                                         \
+celix_status_t bundleActivator_create(celix_bundle_context_t *ctx __attribute__((unused)), void **userData) {          \
+    celix_status_t status = CELIX_SUCCESS;                                                                             \
+    actType *data = calloc(1, sizeof(*data));                                                                          \
+    if (data != NULL) {                                                                                                \
+        *userData = data;                                                                                              \
+    } else {                                                                                                           \
+        status = CELIX_ENOMEM;                                                                                         \
+    }                                                                                                                  \
+    return status;                                                                                                     \
+}                                                                                                                      \
+                                                                                                                       \
+celix_status_t bundleActivator_start(void *userData, celix_bundle_context_t *ctx) {                                    \
+    return actStart((actType*)userData, ctx);                                                                          \
+}                                                                                                                      \
+                                                                                                                       \
+celix_status_t bundleActivator_stop(void *userData, celix_bundle_context_t *ctx) {                                     \
+    return actStop((actType*)userData, ctx);                                                                           \
+}                                                                                                                      \
+                                                                                                                       \
+celix_status_t bundleActivator_destroy(void *userData, celix_bundle_context_t *ctx __attribute__((unused))) {          \
+    free(userData);                                                                                                    \
+    return CELIX_SUCCESS;                                                                                              \
+}
+
 #ifdef __cplusplus
 }
 #endif