Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 29F7F200D49 for ; Fri, 24 Nov 2017 12:27:34 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 2862A160BEE; Fri, 24 Nov 2017 11:27:34 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A72B9160BF2 for ; Fri, 24 Nov 2017 12:27:31 +0100 (CET) Received: (qmail 35686 invoked by uid 500); 24 Nov 2017 11:27:30 -0000 Mailing-List: contact commits-help@celix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@celix.apache.org Delivered-To: mailing list commits@celix.apache.org Received: (qmail 35670 invoked by uid 99); 24 Nov 2017 11:27:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Nov 2017 11:27:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AE7B7F159F; Fri, 24 Nov 2017 11:27:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pnoltes@apache.org To: commits@celix.apache.org Date: Fri, 24 Nov 2017 11:27:31 -0000 Message-Id: In-Reply-To: <0d428d4d565749388b472cada6997058@git.apache.org> References: <0d428d4d565749388b472cada6997058@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] celix git commit: CELIX-417: Refactors CMake usage for example embedded, dm and dm_cxx archived-at: Fri, 24 Nov 2017 11:27:34 -0000 CELIX-417: Refactors CMake usage for example embedded, dm and dm_cxx Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/1836cf84 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/1836cf84 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/1836cf84 Branch: refs/heads/feature/CELIX-417-cmake-refactor Commit: 1836cf84110367ae052f0fb5cbb3eb859d540275 Parents: 486d4f0 Author: Pepijn Noltes Authored: Fri Nov 24 12:27:20 2017 +0100 Committer: Pepijn Noltes Committed: Fri Nov 24 12:27:20 2017 +0100 ---------------------------------------------------------------------- examples/dm_example/CMakeLists.txt | 31 +++-- examples/dm_example/api/CMakeLists.txt | 19 +++ examples/dm_example/api/include/phase1.h | 44 +++++++ examples/dm_example/api/include/phase2.h | 41 +++++++ examples/dm_example/phase1/CMakeLists.txt | 18 ++- .../phase1/private/include/phase1_cmp.h | 43 ------- .../phase1/private/src/phase1_activator.c | 85 -------------- .../dm_example/phase1/private/src/phase1_cmp.c | 99 ---------------- .../dm_example/phase1/src/phase1_activator.c | 85 ++++++++++++++ examples/dm_example/phase1/src/phase1_cmp.c | 99 ++++++++++++++++ examples/dm_example/phase1/src/phase1_cmp.h | 43 +++++++ examples/dm_example/phase2a/CMakeLists.txt | 19 ++- .../phase2a/private/include/phase2a_cmp.h | 46 -------- .../phase2a/private/src/phase2a_activator.c | 95 --------------- .../phase2a/private/src/phase2a_cmp.c | 116 ------------------- .../dm_example/phase2a/src/phase2a_activator.c | 95 +++++++++++++++ examples/dm_example/phase2a/src/phase2a_cmp.c | 116 +++++++++++++++++++ examples/dm_example/phase2a/src/phase2a_cmp.h | 46 ++++++++ examples/dm_example/phase2b/CMakeLists.txt | 21 ++-- .../phase2b/private/include/phase2b_cmp.h | 46 -------- .../phase2b/private/src/phase2b_activator.c | 95 --------------- .../phase2b/private/src/phase2b_cmp.c | 115 ------------------ .../dm_example/phase2b/src/phase2b_activator.c | 95 +++++++++++++++ examples/dm_example/phase2b/src/phase2b_cmp.c | 115 ++++++++++++++++++ examples/dm_example/phase2b/src/phase2b_cmp.h | 46 ++++++++ examples/dm_example/phase3/CMakeLists.txt | 21 ++-- .../phase3/private/include/phase3_cmp.h | 45 ------- .../phase3/private/src/phase3_activator.c | 84 -------------- .../dm_example/phase3/private/src/phase3_cmp.c | 116 ------------------- .../dm_example/phase3/src/phase3_activator.c | 84 ++++++++++++++ examples/dm_example/phase3/src/phase3_cmp.c | 116 +++++++++++++++++++ examples/dm_example/phase3/src/phase3_cmp.h | 45 +++++++ examples/dm_example/services/phase1.h | 44 ------- examples/dm_example/services/phase2.h | 41 ------- examples/dm_example_cxx/CMakeLists.txt | 32 +++-- examples/dm_example_cxx/api/CMakeLists.txt | 19 +++ examples/dm_example_cxx/api/IName.h | 39 ------- examples/dm_example_cxx/api/IPhase1.h | 33 ------ examples/dm_example_cxx/api/IPhase2.h | 33 ------ examples/dm_example_cxx/api/include/IName.h | 39 +++++++ examples/dm_example_cxx/api/include/IPhase1.h | 33 ++++++ examples/dm_example_cxx/api/include/IPhase2.h | 33 ++++++ examples/dm_example_cxx/phase1/CMakeLists.txt | 17 +-- .../phase1/include/Phase1Activator.h | 36 ------ .../dm_example_cxx/phase1/include/Phase1Cmp.h | 44 ------- .../dm_example_cxx/phase1/src/Phase1Activator.h | 36 ++++++ examples/dm_example_cxx/phase1/src/Phase1Cmp.h | 44 +++++++ examples/dm_example_cxx/phase2/CMakeLists.txt | 51 ++++++++ .../phase2/include/Phase2Activator.h | 34 ------ .../dm_example_cxx/phase2/include/Phase2Cmp.h | 56 --------- .../dm_example_cxx/phase2/src/Phase2Activator.h | 34 ++++++ examples/dm_example_cxx/phase2/src/Phase2Cmp.h | 56 +++++++++ .../phase2/src/Phase2aActivator.cc | 57 +++++++++ .../dm_example_cxx/phase2/src/Phase2aCmp.cc | 45 +++++++ .../phase2/src/Phase2bActivator.cc | 50 ++++++++ .../dm_example_cxx/phase2/src/Phase2bCmp.cc | 45 +++++++ examples/dm_example_cxx/phase2a/CMakeLists.txt | 41 ------- .../phase2a/src/Phase2aActivator.cc | 57 --------- .../dm_example_cxx/phase2a/src/Phase2aCmp.cc | 45 ------- examples/dm_example_cxx/phase2b/CMakeLists.txt | 39 ------- .../phase2b/src/Phase2bActivator.cc | 50 -------- .../dm_example_cxx/phase2b/src/Phase2bCmp.cc | 45 ------- examples/dm_example_cxx/phase3/CMakeLists.txt | 17 +-- .../phase3/include/Phase3Activator.h | 33 ------ .../phase3/include/Phase3BaseActivator.h | 35 ------ .../dm_example_cxx/phase3/include/Phase3Cmp.h | 50 -------- .../dm_example_cxx/phase3/src/Phase3Activator.h | 33 ++++++ .../phase3/src/Phase3BaseActivator.h | 35 ++++++ examples/dm_example_cxx/phase3/src/Phase3Cmp.h | 50 ++++++++ .../phase3_locking/CMakeLists.txt | 16 +-- .../include/Phase3LockingActivator.h | 33 ------ .../phase3_locking/include/Phase3LockingCmp.h | 50 -------- .../phase3_locking/src/Phase3LockingActivator.h | 33 ++++++ .../phase3_locking/src/Phase3LockingCmp.h | 50 ++++++++ examples/embedding/CMakeLists.txt | 1 - 75 files changed, 1909 insertions(+), 1939 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/dm_example/CMakeLists.txt b/examples/dm_example/CMakeLists.txt index 9a9e69b..2cef7ec 100644 --- a/examples/dm_example/CMakeLists.txt +++ b/examples/dm_example/CMakeLists.txt @@ -15,11 +15,8 @@ # 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(api) add_subdirectory(phase1) add_subdirectory(phase2a) @@ -32,11 +29,11 @@ if (BUILD_DEPENDENCY_MANAGER) BUNDLES Celix::shell Celix::shell_tui - dm_shell - phase1 - phase2a - phase2b - phase3 + Celix::dm_shell + dm_example_phase1 + dm_example_phase2a + dm_example_phase2b + dm_example_phase3 PROPERTIES LOGHELPER_ENABLE_STDOUT_FALLBACK=true ) @@ -53,13 +50,13 @@ if (BUILD_DEPENDENCY_MANAGER) FROM dmbase GROUP examples BUNDLES - ${CELIX_SHELL_BUNDLE} - ${CELIX_SHELL_TUI_BUNDLE} - dm_shell - phase1 - phase2a - phase2b - phase3 + Celix::shell + Celix::shell_tui + Celix::dm_shell + dm_example_phase1 + dm_example_phase2a + dm_example_phase2b + dm_example_phase3 PROPERTIES LOGHELPER_ENABLE_STDOUT_FALLBACK=true ) http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/api/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/dm_example/api/CMakeLists.txt b/examples/dm_example/api/CMakeLists.txt new file mode 100644 index 0000000..900c8fb --- /dev/null +++ b/examples/dm_example/api/CMakeLists.txt @@ -0,0 +1,19 @@ +# 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. + +add_library(dm_example_api INTERFACE) +target_include_directories(dm_example_api INTERFACE include) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/api/include/phase1.h ---------------------------------------------------------------------- diff --git a/examples/dm_example/api/include/phase1.h b/examples/dm_example/api/include/phase1.h new file mode 100644 index 0000000..04e9da7 --- /dev/null +++ b/examples/dm_example/api/include/phase1.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 Aug 23, 2010 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#ifndef PHASE1_H_ +#define PHASE1_H_ + +#define PHASE1_NAME "PHASE1" +#define PHASE1_VERSION "1.2.2.0" +#define PHASE1_RANGE_ALL "[1.2.2.0,4.5.6.x)" +#define PHASE1_RANGE_EXACT "[1.2.2.0,1.2.2.0]" + + + +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/1836cf84/examples/dm_example/api/include/phase2.h ---------------------------------------------------------------------- diff --git a/examples/dm_example/api/include/phase2.h b/examples/dm_example/api/include/phase2.h new file mode 100644 index 0000000..2f4df86 --- /dev/null +++ b/examples/dm_example/api/include/phase2.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. + */ +/* + * publisher.h + * + * \date Aug 23, 2010 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#ifndef PHASE2_H +#define PHASE2_H + +#define PHASE2_NAME "PHASE2" +#define PHASE2_VERSION "1.0.0.0" + +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/1836cf84/examples/dm_example/phase1/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase1/CMakeLists.txt b/examples/dm_example/phase1/CMakeLists.txt index 6299688..5263bab 100644 --- a/examples/dm_example/phase1/CMakeLists.txt +++ b/examples/dm_example/phase1/CMakeLists.txt @@ -15,26 +15,24 @@ # specific language governing permissions and limitations # under the License. -include_directories( - private/include - ../services -) -add_bundle(phase1 +add_bundle(dm_example_phase1 SYMBOLIC_NAME phase1 VERSION 0.0.1 SOURCES - private/src/phase1_activator - private/src/phase1_cmp.c + src/phase1_activator + src/phase1_cmp.c ) +target_include_directories(dm_example_phase1 PRIVATE src) +target_link_libraries(dm_example_phase1 PRIVATE dm_example_api) IF(APPLE) - target_link_libraries(phase1 PRIVATE -Wl,-all_load dependency_manager_static) + target_link_libraries(dm_example_phase1 PRIVATE -Wl,-all_load Celix::dependency_manager_static) else() if(ENABLE_ADDRESS_SANITIZER) #With asan there can be undefined symbols - target_link_libraries(phase1 PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive) + target_link_libraries(dm_example_phase1 PRIVATE -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive) else() - target_link_libraries(phase1 PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive) + target_link_libraries(dm_example_phase1 PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive) endif() endif() http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/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 deleted file mode 100644 index 5715f6e..0000000 --- a/examples/dm_example/phase1/private/include/phase1_cmp.h +++ /dev/null @@ -1,43 +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. - */ -/* - * publisher.h - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \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); -int phase1_deinit(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/1836cf84/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 deleted file mode 100644 index 783e642..0000000 --- a/examples/dm_example/phase1/private/src/phase1_activator.c +++ /dev/null @@ -1,85 +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. - */ -/* - * activator.c - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include -#include - -#include "bundle_activator.h" -#include "dm_activator.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 = (void *)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_setCallbacksSafe(cmp, phase1_cmp_t *, phase1_init, phase1_start, phase1_stop, phase1_deinit); - component_addInterface(cmp, PHASE1_NAME, PHASE1_VERSION, &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/1836cf84/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 deleted file mode 100644 index 75de182..0000000 --- a/examples/dm_example/phase1/private/src/phase1_cmp.c +++ /dev/null @@ -1,99 +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. - */ -/* - * publisher.c - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include -#include -#include -#include -#include - -#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; -} - -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"); -} - -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; -} http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase1/src/phase1_activator.c ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase1/src/phase1_activator.c b/examples/dm_example/phase1/src/phase1_activator.c new file mode 100644 index 0000000..783e642 --- /dev/null +++ b/examples/dm_example/phase1/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 Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include +#include + +#include "bundle_activator.h" +#include "dm_activator.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 = (void *)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_setCallbacksSafe(cmp, phase1_cmp_t *, phase1_init, phase1_start, phase1_stop, phase1_deinit); + component_addInterface(cmp, PHASE1_NAME, PHASE1_VERSION, &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/1836cf84/examples/dm_example/phase1/src/phase1_cmp.c ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase1/src/phase1_cmp.c b/examples/dm_example/phase1/src/phase1_cmp.c new file mode 100644 index 0000000..75de182 --- /dev/null +++ b/examples/dm_example/phase1/src/phase1_cmp.c @@ -0,0 +1,99 @@ +/** + *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 Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include +#include +#include +#include +#include + +#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; +} + +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"); +} + +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; +} http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase1/src/phase1_cmp.h ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase1/src/phase1_cmp.h b/examples/dm_example/phase1/src/phase1_cmp.h new file mode 100644 index 0000000..5715f6e --- /dev/null +++ b/examples/dm_example/phase1/src/phase1_cmp.h @@ -0,0 +1,43 @@ +/** + *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 Apache Celix Project Team + * \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); +int phase1_deinit(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/1836cf84/examples/dm_example/phase2a/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase2a/CMakeLists.txt b/examples/dm_example/phase2a/CMakeLists.txt index d8f9165..cda4971 100644 --- a/examples/dm_example/phase2a/CMakeLists.txt +++ b/examples/dm_example/phase2a/CMakeLists.txt @@ -15,26 +15,23 @@ # specific language governing permissions and limitations # under the License. -include_directories( - private/include - ../services -) - -add_bundle(phase2a +add_bundle(dm_example_phase2a SYMBOLIC_NAME phase2a VERSION 0.0.1 SOURCES - private/src/phase2a_activator - private/src/phase2a_cmp + src/phase2a_activator + src/phase2a_cmp ) +target_include_directories(dm_example_phase2a PRIVATE src) +target_link_libraries(dm_example_phase2a PRIVATE dm_example_api) IF(APPLE) - target_link_libraries(phase2a PRIVATE -Wl,-all_load dependency_manager_static) + target_link_libraries(dm_example_phase2a PRIVATE -Wl,-all_load Celix::dependency_manager_static) else() if(ENABLE_ADDRESS_SANITIZER) #With asan there can be undefined symbols - target_link_libraries(phase2a PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive) + target_link_libraries(dm_example_phase2a PRIVATE -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive) else() - target_link_libraries(phase2a PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive) + target_link_libraries(dm_example_phase2a PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive) endif() ENDIF() http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/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 deleted file mode 100644 index 060b23d..0000000 --- a/examples/dm_example/phase2a/private/include/phase2a_cmp.h +++ /dev/null @@ -1,46 +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. - */ -/* - * publisher.h - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \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); -int phase2a_deinit(phase2a_cmp_t *cmp); -void phase2a_destroy(phase2a_cmp_t *cmp); - -int phase2a_setPhase1(phase2a_cmp_t *cmp, const 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/1836cf84/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 deleted file mode 100644 index 6416c68..0000000 --- a/examples/dm_example/phase2a/private/src/phase2a_activator.c +++ /dev/null @@ -1,95 +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. - */ -/* - * activator.c - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include -#include - -#include "bundle_activator.h" -#include "dm_activator.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_setCallbacksSafe(cmp, phase2a_cmp_t *, phase2a_init, phase2a_start, phase2a_stop, phase2a_deinit); - component_addInterface(cmp, PHASE2_NAME, PHASE2_VERSION, &act->phase2Serv, props); - - - dm_service_dependency_pt dep; - serviceDependency_create(&dep); - serviceDependency_setService(dep, PHASE1_NAME, PHASE1_RANGE_ALL, NULL); - serviceDependency_setCallbacksSafe(dep, phase2a_cmp_t*, const phase1_t*, phase2a_setPhase1, NULL, NULL, NULL, NULL); - serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING); - 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/1836cf84/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 deleted file mode 100644 index d115b69..0000000 --- a/examples/dm_example/phase2a/private/src/phase2a_cmp.c +++ /dev/null @@ -1,116 +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. - */ -/* - * publisher.c - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include -#include -#include -#include - -#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; - const 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; -} - -int phase2a_deinit(phase2a_cmp_t *cmp) { - printf("deinit phase2a\n"); - return 0; -} - -void phase2a_destroy(phase2a_cmp_t *cmp) { - celixThreadMutex_destroy(&cmp->mutex); - free(cmp); - printf("destroy phase2a\n"); -} - -int phase2a_setPhase1(phase2a_cmp_t *cmp, const phase1_t* phase1) { - printf("phase2a_setPhase1 called!\n\n"); - 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; -} http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2a/src/phase2a_activator.c ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase2a/src/phase2a_activator.c b/examples/dm_example/phase2a/src/phase2a_activator.c new file mode 100644 index 0000000..6416c68 --- /dev/null +++ b/examples/dm_example/phase2a/src/phase2a_activator.c @@ -0,0 +1,95 @@ +/** + *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 Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include +#include + +#include "bundle_activator.h" +#include "dm_activator.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_setCallbacksSafe(cmp, phase2a_cmp_t *, phase2a_init, phase2a_start, phase2a_stop, phase2a_deinit); + component_addInterface(cmp, PHASE2_NAME, PHASE2_VERSION, &act->phase2Serv, props); + + + dm_service_dependency_pt dep; + serviceDependency_create(&dep); + serviceDependency_setService(dep, PHASE1_NAME, PHASE1_RANGE_ALL, NULL); + serviceDependency_setCallbacksSafe(dep, phase2a_cmp_t*, const phase1_t*, phase2a_setPhase1, NULL, NULL, NULL, NULL); + serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING); + 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/1836cf84/examples/dm_example/phase2a/src/phase2a_cmp.c ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase2a/src/phase2a_cmp.c b/examples/dm_example/phase2a/src/phase2a_cmp.c new file mode 100644 index 0000000..d115b69 --- /dev/null +++ b/examples/dm_example/phase2a/src/phase2a_cmp.c @@ -0,0 +1,116 @@ +/** + *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 Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include +#include +#include +#include + +#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; + const 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; +} + +int phase2a_deinit(phase2a_cmp_t *cmp) { + printf("deinit phase2a\n"); + return 0; +} + +void phase2a_destroy(phase2a_cmp_t *cmp) { + celixThreadMutex_destroy(&cmp->mutex); + free(cmp); + printf("destroy phase2a\n"); +} + +int phase2a_setPhase1(phase2a_cmp_t *cmp, const phase1_t* phase1) { + printf("phase2a_setPhase1 called!\n\n"); + 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; +} http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2a/src/phase2a_cmp.h ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase2a/src/phase2a_cmp.h b/examples/dm_example/phase2a/src/phase2a_cmp.h new file mode 100644 index 0000000..060b23d --- /dev/null +++ b/examples/dm_example/phase2a/src/phase2a_cmp.h @@ -0,0 +1,46 @@ +/** + *Licensed to the Apache Software Foundation (ASF) under one + *or more contributor license agreements. See the NOTICE file + *distributed with this work for additional information + *regarding copyright ownership. The ASF licenses this file + *to you under the Apache License, Version 2.0 (the + *"License"); you may not use this file except in compliance + *with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + *Unless required by applicable law or agreed to in writing, + *software distributed under the License is distributed on an + *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + *specific language governing permissions and limitations + *under the License. + */ +/* + * publisher.h + * + * \date Oct 29, 2015 + * \author Apache Celix Project Team + * \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); +int phase2a_deinit(phase2a_cmp_t *cmp); +void phase2a_destroy(phase2a_cmp_t *cmp); + +int phase2a_setPhase1(phase2a_cmp_t *cmp, const 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/1836cf84/examples/dm_example/phase2b/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase2b/CMakeLists.txt b/examples/dm_example/phase2b/CMakeLists.txt index a65b422..9afb6c7 100644 --- a/examples/dm_example/phase2b/CMakeLists.txt +++ b/examples/dm_example/phase2b/CMakeLists.txt @@ -15,28 +15,23 @@ # specific language governing permissions and limitations # under the License. -include_directories( - private/include - ../services -) - -add_bundle(phase2b +add_bundle(dm_example_phase2b SYMBOLIC_NAME phase2b VERSION 0.0.1 SOURCES - private/src/phase2b_activator - private/src/phase2b_cmp + src/phase2b_activator + src/phase2b_cmp ) - -#bundle_private_libs(phase2b dependency_manager) +target_include_directories(dm_example_phase2b PRIVATE src) +target_link_libraries(dm_example_phase2b PRIVATE dm_example_api) IF(APPLE) - target_link_libraries(phase2b PRIVATE -Wl,-all_load dependency_manager_static) + target_link_libraries(dm_example_phase2b PRIVATE -Wl,-all_load Celix::dependency_manager_static) else() if(ENABLE_ADDRESS_SANITIZER) #With asan there can be undefined symbols - target_link_libraries(phase2b PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive) + target_link_libraries(dm_example_phase2b PRIVATE -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive) else() - target_link_libraries(phase2b PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive) + target_link_libraries(dm_example_phase2b PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive) endif() ENDIF() http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/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 deleted file mode 100644 index 7ae0358..0000000 --- a/examples/dm_example/phase2b/private/include/phase2b_cmp.h +++ /dev/null @@ -1,46 +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. - */ -/* - * publisher.h - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \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); -int phase2b_deinit(phase2b_cmp_t *cmp); -void phase2b_destroy(phase2b_cmp_t *cmp); - -int phase2b_setPhase1(phase2b_cmp_t *cmp, const 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/1836cf84/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 deleted file mode 100644 index c7692d4..0000000 --- a/examples/dm_example/phase2b/private/src/phase2b_activator.c +++ /dev/null @@ -1,95 +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. - */ -/* - * activator.c - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include -#include - -#include "bundle_activator.h" -#include "dm_activator.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_setCallbacksSafe(cmp, phase2b_cmp_t *, phase2b_init, phase2b_start, phase2b_stop, phase2b_deinit); - component_addInterface(cmp, PHASE2_NAME, PHASE2_VERSION, &act->phase2Serv, props); - - - dm_service_dependency_pt dep; - serviceDependency_create(&dep); - serviceDependency_setService(dep, PHASE1_NAME, PHASE1_RANGE_EXACT, NULL); - serviceDependency_setCallbacksSafe(dep, phase2b_cmp_t*, const phase1_t*, phase2b_setPhase1, NULL, NULL, NULL, NULL); - serviceDependency_setRequired(dep, true); - serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING); - 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/1836cf84/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 deleted file mode 100644 index a74dcfa..0000000 --- a/examples/dm_example/phase2b/private/src/phase2b_cmp.c +++ /dev/null @@ -1,115 +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. - */ -/* - * publisher.c - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include -#include -#include -#include - -#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; - const 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; -} - -int phase2b_deinit(phase2b_cmp_t *cmp) { - printf("deinit phase2b\n"); - return 0; -} - -void phase2b_destroy(phase2b_cmp_t *cmp) { - celixThreadMutex_destroy(&cmp->mutex); - free(cmp); - printf("destroy phase2b\n"); -} - -int phase2b_setPhase1(phase2b_cmp_t *cmp, const 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; -} http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2b/src/phase2b_activator.c ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase2b/src/phase2b_activator.c b/examples/dm_example/phase2b/src/phase2b_activator.c new file mode 100644 index 0000000..c7692d4 --- /dev/null +++ b/examples/dm_example/phase2b/src/phase2b_activator.c @@ -0,0 +1,95 @@ +/** + *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 Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include +#include + +#include "bundle_activator.h" +#include "dm_activator.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_setCallbacksSafe(cmp, phase2b_cmp_t *, phase2b_init, phase2b_start, phase2b_stop, phase2b_deinit); + component_addInterface(cmp, PHASE2_NAME, PHASE2_VERSION, &act->phase2Serv, props); + + + dm_service_dependency_pt dep; + serviceDependency_create(&dep); + serviceDependency_setService(dep, PHASE1_NAME, PHASE1_RANGE_EXACT, NULL); + serviceDependency_setCallbacksSafe(dep, phase2b_cmp_t*, const phase1_t*, phase2b_setPhase1, NULL, NULL, NULL, NULL); + serviceDependency_setRequired(dep, true); + serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING); + 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/1836cf84/examples/dm_example/phase2b/src/phase2b_cmp.c ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase2b/src/phase2b_cmp.c b/examples/dm_example/phase2b/src/phase2b_cmp.c new file mode 100644 index 0000000..a74dcfa --- /dev/null +++ b/examples/dm_example/phase2b/src/phase2b_cmp.c @@ -0,0 +1,115 @@ +/** + *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 Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include +#include +#include +#include + +#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; + const 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; +} + +int phase2b_deinit(phase2b_cmp_t *cmp) { + printf("deinit phase2b\n"); + return 0; +} + +void phase2b_destroy(phase2b_cmp_t *cmp) { + celixThreadMutex_destroy(&cmp->mutex); + free(cmp); + printf("destroy phase2b\n"); +} + +int phase2b_setPhase1(phase2b_cmp_t *cmp, const 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; +} http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase2b/src/phase2b_cmp.h ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase2b/src/phase2b_cmp.h b/examples/dm_example/phase2b/src/phase2b_cmp.h new file mode 100644 index 0000000..7ae0358 --- /dev/null +++ b/examples/dm_example/phase2b/src/phase2b_cmp.h @@ -0,0 +1,46 @@ +/** + *Licensed to the Apache Software Foundation (ASF) under one + *or more contributor license agreements. See the NOTICE file + *distributed with this work for additional information + *regarding copyright ownership. The ASF licenses this file + *to you under the Apache License, Version 2.0 (the + *"License"); you may not use this file except in compliance + *with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + *Unless required by applicable law or agreed to in writing, + *software distributed under the License is distributed on an + *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + *specific language governing permissions and limitations + *under the License. + */ +/* + * publisher.h + * + * \date Oct 29, 2015 + * \author Apache Celix Project Team + * \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); +int phase2b_deinit(phase2b_cmp_t *cmp); +void phase2b_destroy(phase2b_cmp_t *cmp); + +int phase2b_setPhase1(phase2b_cmp_t *cmp, const 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/1836cf84/examples/dm_example/phase3/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase3/CMakeLists.txt b/examples/dm_example/phase3/CMakeLists.txt index 9547e04..1784057 100644 --- a/examples/dm_example/phase3/CMakeLists.txt +++ b/examples/dm_example/phase3/CMakeLists.txt @@ -15,28 +15,23 @@ # specific language governing permissions and limitations # under the License. -include_directories( - private/include - ../services -) - -add_bundle(phase3 +add_bundle(dm_example_phase3 SYMBOLIC_NAME phase3 VERSION 0.0.1 SOURCES - private/src/phase3_activator - private/src/phase3_cmp + src/phase3_activator + src/phase3_cmp ) - -#bundle_private_libs(phase3 dependency_manager) +target_include_directories(dm_example_phase3 PRIVATE src) +target_link_libraries(dm_example_phase3 PRIVATE dm_example_api) IF(APPLE) - target_link_libraries(phase3 PRIVATE -Wl,-all_load dependency_manager_static) + target_link_libraries(dm_example_phase3 PRIVATE -Wl,-all_load dependency_manager_static) else() if(ENABLE_ADDRESS_SANITIZER) #With asan there can be undefined symbols - target_link_libraries(phase3 PRIVATE -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive) + target_link_libraries(dm_example_phase3 PRIVATE -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive) else() - target_link_libraries(phase3 PRIVATE -Wl,--no-undefined -Wl,--whole-archive dependency_manager_static -Wl,--no-whole-archive) + target_link_libraries(dm_example_phase3 PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_static -Wl,--no-whole-archive) endif() ENDIF() http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/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 deleted file mode 100644 index 9c63845..0000000 --- a/examples/dm_example/phase3/private/include/phase3_cmp.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. - */ -/* - * publisher.h - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \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(); -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, const phase2_t* phase2); -int phase3_removePhase2(phase3_cmp_t *cmp, const phase2_t* phase2); - - -#endif //PHASE3_CMP_H http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/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 deleted file mode 100644 index 64b7a0b..0000000 --- a/examples/dm_example/phase3/private/src/phase3_activator.c +++ /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. - */ -/* - * activator.c - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include - -#include "bundle_activator.h" -#include "dm_activator.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) { - - dm_component_pt cmp; - component_create(context, "PHASE3_PROCESSING_COMPONENT", &cmp); - component_setImplementation(cmp, act->phase3Cmp); - 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, NULL); - serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND); //SUSPEND Strategy is default - serviceDependency_setCallbacksSafe(dep, phase3_cmp_t*, const phase2_t*, NULL, phase3_addPhase2, NULL, 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/1836cf84/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 deleted file mode 100644 index 47cb720..0000000 --- a/examples/dm_example/phase3/private/src/phase3_cmp.c +++ /dev/null @@ -1,116 +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. - */ -/* - * publisher.c - * - * \date Oct 29, 2015 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include -#include -#include -#include - -#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; - array_list_pt phase2Services; //phase2_t * -}; - -static void *phase3_thread(void *data); - -phase3_cmp_t *phase3_create() { - phase3_cmp_t *cmp = calloc(1, sizeof(*cmp)); - if (cmp != NULL) { - cmp->currentValue = 0.0; - cmp->running = false; - 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; -} - -int phase3_deinit(phase3_cmp_t *cmp) { - printf("deinit phase3\n"); - return 0; -} - -void phase3_destroy(phase3_cmp_t *cmp) { - arrayList_destroy(cmp->phase2Services); - free(cmp); - printf("destroy phase3\n"); -} - -int phase3_addPhase2(phase3_cmp_t *cmp, const phase2_t* phase2) { - arrayList_add(cmp->phase2Services, (void*)phase2); - return 0; -} - -int phase3_removePhase2(phase3_cmp_t *cmp, const phase2_t *phase2) { - arrayList_removeElement(cmp->phase2Services, (void*)phase2); - return 0; -} - - -static void *phase3_thread(void *data) { - phase3_cmp_t *cmp = data; - int size; - int i; - double value; - - while (cmp->running) { - size = arrayList_size(cmp->phase2Services); - for (i = 0; i < size; i += 1) { - const phase2_t* serv = arrayList_get(cmp->phase2Services, i); - serv->getData(serv->handle, &value); - printf("PHASE3: Data from %p is %f\n", serv, value); - } - usleep(SLEEPTIME); - } - - celixThread_exit(NULL); - return NULL; -} http://git-wip-us.apache.org/repos/asf/celix/blob/1836cf84/examples/dm_example/phase3/src/phase3_activator.c ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase3/src/phase3_activator.c b/examples/dm_example/phase3/src/phase3_activator.c new file mode 100644 index 0000000..64b7a0b --- /dev/null +++ b/examples/dm_example/phase3/src/phase3_activator.c @@ -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. + */ +/* + * activator.c + * + * \date Oct 29, 2015 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include + +#include "bundle_activator.h" +#include "dm_activator.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) { + + dm_component_pt cmp; + component_create(context, "PHASE3_PROCESSING_COMPONENT", &cmp); + component_setImplementation(cmp, act->phase3Cmp); + 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, NULL); + serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND); //SUSPEND Strategy is default + serviceDependency_setCallbacksSafe(dep, phase3_cmp_t*, const phase2_t*, NULL, phase3_addPhase2, NULL, 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/1836cf84/examples/dm_example/phase3/src/phase3_cmp.c ---------------------------------------------------------------------- diff --git a/examples/dm_example/phase3/src/phase3_cmp.c b/examples/dm_example/phase3/src/phase3_cmp.c new file mode 100644 index 0000000..47cb720 --- /dev/null +++ b/examples/dm_example/phase3/src/phase3_cmp.c @@ -0,0 +1,116 @@ +/** + *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 Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include +#include +#include +#include + +#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; + array_list_pt phase2Services; //phase2_t * +}; + +static void *phase3_thread(void *data); + +phase3_cmp_t *phase3_create() { + phase3_cmp_t *cmp = calloc(1, sizeof(*cmp)); + if (cmp != NULL) { + cmp->currentValue = 0.0; + cmp->running = false; + 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; +} + +int phase3_deinit(phase3_cmp_t *cmp) { + printf("deinit phase3\n"); + return 0; +} + +void phase3_destroy(phase3_cmp_t *cmp) { + arrayList_destroy(cmp->phase2Services); + free(cmp); + printf("destroy phase3\n"); +} + +int phase3_addPhase2(phase3_cmp_t *cmp, const phase2_t* phase2) { + arrayList_add(cmp->phase2Services, (void*)phase2); + return 0; +} + +int phase3_removePhase2(phase3_cmp_t *cmp, const phase2_t *phase2) { + arrayList_removeElement(cmp->phase2Services, (void*)phase2); + return 0; +} + + +static void *phase3_thread(void *data) { + phase3_cmp_t *cmp = data; + int size; + int i; + double value; + + while (cmp->running) { + size = arrayList_size(cmp->phase2Services); + for (i = 0; i < size; i += 1) { + const phase2_t* serv = arrayList_get(cmp->phase2Services, i); + serv->getData(serv->handle, &value); + printf("PHASE3: Data from %p is %f\n", serv, value); + } + usleep(SLEEPTIME); + } + + celixThread_exit(NULL); + return NULL; +}