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/feature/CELIX-269_depman
Commit: 0ad3a1fb05b467e45fe6c486926a9dd6c0beb17f
Parents: 2246174
Author: Pepijn Noltes <pepijnnol...@gmail.com>
Authored: Thu Oct 29 16:22:41 2015 +0100
Committer: Pepijn Noltes <pepijnnol...@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:d...@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:d...@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:d...@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:d...@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:d...@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:d...@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:d...@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:d...@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:d...@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:d...@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:d...@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:d...@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:d...@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:d...@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);

Reply via email to