From commits-return-4626-archive-asf-public=cust-asf.ponee.io@celix.apache.org Wed Jan 31 21:05:30 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id C3BF5180671 for ; Wed, 31 Jan 2018 21:05:29 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id ADD80160C42; Wed, 31 Jan 2018 20:05:29 +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 6B1A2160C59 for ; Wed, 31 Jan 2018 21:05:27 +0100 (CET) Received: (qmail 36427 invoked by uid 500); 31 Jan 2018 20:05:26 -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 36298 invoked by uid 99); 31 Jan 2018 20:05:26 -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; Wed, 31 Jan 2018 20:05:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7B00DF1747; Wed, 31 Jan 2018 20:05:25 +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: Wed, 31 Jan 2018 20:05:31 -0000 Message-Id: In-Reply-To: <258321dfc0644cc38fece51b238b9c43@git.apache.org> References: <258321dfc0644cc38fece51b238b9c43@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [7/8] celix git commit: CELIX-413: Moves the example to an additional dir, so that examples can also be build outside the celix project http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Cmp.cc ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Cmp.cc b/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Cmp.cc new file mode 100644 index 0000000..e82f381 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Cmp.cc @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "Phase1Cmp.h" +#include +#include +#include + +void Phase1Cmp::init() { + std::cout << "init Phase1Cmp\n"; +} + +void Phase1Cmp::start() { + std::cout << "start Phase1Cmp\n"; +} + +void Phase1Cmp::stop() { + std::cout << "stop Phase1Cmp\n"; +} + +void Phase1Cmp::deinit() { + std::cout << "deinit Phase1Cmp\n"; +} + +int Phase1Cmp::getData() { + counter += 1; + return (int)random(); +}; + +std::string Phase1Cmp::getName() { + return std::string {"IPhase"}; +} + +int Phase1Cmp::infoCmd([[gnu::unused]] char * line, FILE *out, [[gnu::unused]] FILE* err) { + fprintf(out, "Phase1: number of getData calls: %u\n", counter); + return 0; +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Cmp.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Cmp.h b/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Cmp.h new file mode 100644 index 0000000..f475c41 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Cmp.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. + */ + +#ifndef CELIX_PHASE1CMP_H +#define CELIX_PHASE1CMP_H + +#include "IPhase1.h" +#include "IName.h" +#include +#include + +class Phase1Cmp : public srv::info::IName, public IPhase1 { + uint32_t counter = 0; +public: + Phase1Cmp() = default; + virtual ~Phase1Cmp() = default; + + void init(); + void start(); + void stop(); + void deinit(); + + int getData() override; //implements IPhase1 + int infoCmd(char* line, FILE *out, FILE* err); //implements cmd service + std::string getName() override; +}; + +#endif //CELIX_PHASE1CMP_H http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase2/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase2/CMakeLists.txt b/examples/celix-examples/dm_example_cxx/phase2/CMakeLists.txt new file mode 100644 index 0000000..f2b3813 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase2/CMakeLists.txt @@ -0,0 +1,51 @@ +# 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_celix_bundle(dm_example_cxx_phase2a + SYMBOLIC_NAME phase2a_cxx + VERSION 0.0.1 + SOURCES + src/Phase2aActivator.cc + src/Phase2aCmp.cc +) +target_include_directories(dm_example_cxx_phase2a PRIVATE src) +target_link_libraries(dm_example_cxx_phase2a PRIVATE Celix::log_service_api dm_example_cxx_api) + +add_celix_bundle(dm_example_cxx_phase2b + SYMBOLIC_NAME phase2b_cxx + VERSION 0.0.1 + SOURCES + src/Phase2bActivator.cc + src/Phase2bCmp.cc + ) +target_include_directories(dm_example_cxx_phase2b PRIVATE src) +target_link_libraries(dm_example_cxx_phase2b PRIVATE Celix::log_service_api dm_example_cxx_api) + +IF(APPLE) + target_link_libraries(dm_example_cxx_phase2a PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static) + target_link_libraries(dm_example_cxx_phase2b PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static) +else() + if(ENABLE_ADDRESS_SANITIZER) + #With asan there can be undefined symbols + target_link_libraries(dm_example_cxx_phase2a PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive) + target_link_libraries(dm_example_cxx_phase2b PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive) + else() + target_link_libraries(dm_example_cxx_phase2a PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive) + target_link_libraries(dm_example_cxx_phase2b PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive) + + endif() +endif() http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Activator.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Activator.h b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Activator.h new file mode 100644 index 0000000..069b2ae --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Activator.h @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef CELIX_PHASE2AACTIVATOR_H +#define CELIX_PHASE2AACTIVATOR_H + +#include "celix/dm/DmActivator.h" + +using namespace celix::dm; + +class Phase2Activator : public DmActivator { +public: + Phase2Activator(DependencyManager& mng) : DmActivator(mng) {} + virtual void init(); + virtual void deinit(); +}; + +#endif //CELIX_PHASE2AACTIVATOR_H http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Cmp.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Cmp.h b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Cmp.h new file mode 100644 index 0000000..87b6e8e --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Cmp.h @@ -0,0 +1,56 @@ +/** + * 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. + */ + +#ifndef CELIX_PHASE2CMP_H +#define CELIX_PHASE2CMP_H + +#include "IName.h" +#include "IPhase1.h" +#include "IPhase2.h" +#include +#include +#include +#include + +extern "C" { +#include "log_service.h" +}; + +class Phase2Cmp : public IPhase2 { +public: + Phase2Cmp() = default; + virtual ~Phase2Cmp() { std::cout << "Destroying Phase2\n"; }; + + Phase2Cmp(Phase2Cmp&& other) noexcept; + Phase2Cmp& operator=(Phase2Cmp&&) = default; + + Phase2Cmp(const Phase2Cmp& other) = delete; + Phase2Cmp operator=(const Phase2Cmp&) = delete; + + void setPhase1(IPhase1* phase); //injector used by dependency manager + void setName(srv::info::IName* name) { std::cout << "Setting IName with name: " << (name != nullptr ? name->getName() : "null") << std::endl; } + void setLogService(const log_service_t* logSrv); + + double getData() override; //implements IPhase2 +private: + IPhase1* phase1 {nullptr}; + const log_service_t* logSrv {nullptr}; +}; + +#endif //CELIX_PHASE2CMP_H http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aActivator.cc ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aActivator.cc b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aActivator.cc new file mode 100644 index 0000000..e33ae0e --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aActivator.cc @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include +#include "Phase2Cmp.h" +#include "Phase2Activator.h" +#include "log_service.h" + +using namespace celix::dm; + + +DmActivator* DmActivator::create(DependencyManager& mng) { + return new Phase2Activator(mng); +} + + +void Phase2Activator::init() { + + Properties props {}; + props["name"] = "phase2a"; + + Component& cmp = mng.createComponent() + .setInstance(Phase2Cmp()) + .addInterface(IPHASE2_VERSION, props); + + cmp.createServiceDependency() + .setRequired(true) + .setCallbacks(&Phase2Cmp::setPhase1); + + cmp.createServiceDependency() + .setVersionRange("[1.0.0,2)") + .setCallbacks(&Phase2Cmp::setName); + + cmp.createCServiceDependency(OSGI_LOGSERVICE_NAME) + .setRequired(false) + .setCallbacks(&Phase2Cmp::setLogService); +} + +void Phase2Activator::deinit() { + +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aCmp.cc ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aCmp.cc b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aCmp.cc new file mode 100644 index 0000000..4f68679 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aCmp.cc @@ -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. + */ + +#include "Phase2Cmp.h" +#include +#include +#include + +Phase2Cmp::Phase2Cmp(Phase2Cmp&& other) noexcept : phase1(other.phase1), logSrv{other.logSrv} { + std::cout << "Move constructor Phase2aCmp called\n"; + other.phase1 = nullptr; + other.logSrv = nullptr; +} + +void Phase2Cmp::setPhase1(IPhase1* phase1) { + std::cout << "setting phase1 for phase2\n"; + this->phase1 = phase1; +} + +void Phase2Cmp::setLogService(const log_service_t* logSrv) { + this->logSrv = logSrv; +} + +double Phase2Cmp::getData() { + if (this->logSrv != NULL) { + this->logSrv->log(this->logSrv->logger, OSGI_LOGSERVICE_DEBUG, (char *) "getting data from phase2cmp A\n"); + } + return phase1->getData() * 42.0; +}; http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bActivator.cc ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bActivator.cc b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bActivator.cc new file mode 100644 index 0000000..4fba8c0 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bActivator.cc @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "Phase2Cmp.h" +#include "Phase2Activator.h" +#include "log_service.h" + +using namespace celix::dm; + + +DmActivator* DmActivator::create(DependencyManager& mng) { + return new Phase2Activator(mng); +} + +void Phase2Activator::init() { + + Properties props {}; + props["name"] = "phase2b"; + + Component& cmp = mng.createComponent() + .addInterface(IPHASE2_VERSION, props); + + cmp.createServiceDependency() + .setRequired(true) + .setCallbacks(&Phase2Cmp::setPhase1); + + cmp.createCServiceDependency(OSGI_LOGSERVICE_NAME) + .setRequired(false) + .setCallbacks(&Phase2Cmp::setLogService); +} + +void Phase2Activator::deinit() { + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bCmp.cc ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bCmp.cc b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bCmp.cc new file mode 100644 index 0000000..2f420a0 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bCmp.cc @@ -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. + */ + +#include "Phase2Cmp.h" +#include +#include +#include + +Phase2Cmp::Phase2Cmp(Phase2Cmp&& other) noexcept : phase1(other.phase1), logSrv{other.logSrv} { + std::cout << "Move constructor Phase2bCmp called\n"; + other.phase1 = nullptr; + other.logSrv = nullptr; +} + +void Phase2Cmp::setPhase1(IPhase1* phase1) { + std::cout << "setting phase1 for phase2\n"; + this->phase1 = phase1; +} + +void Phase2Cmp::setLogService(const log_service_t* logSrv) { + this->logSrv = logSrv; +} + +double Phase2Cmp::getData() { + if (this->logSrv != NULL) { + this->logSrv->log(this->logSrv->logger, OSGI_LOGSERVICE_DEBUG, (char *) "getting data from phase2cmp B\n"); + } + return phase1->getData() * 24.0; +}; http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3/CMakeLists.txt b/examples/celix-examples/dm_example_cxx/phase3/CMakeLists.txt new file mode 100644 index 0000000..c583f25 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3/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. + +add_celix_bundle(dm_example_cxx_phase3 + SYMBOLIC_NAME phase3_cxx + VERSION 0.0.1 + SOURCES + src/Phase3Activator.cc + src/Phase3BaseActivator.cc + src/Phase3Cmp.cc +) +target_include_directories(dm_example_cxx_phase3 PRIVATE src) +target_link_libraries(dm_example_cxx_phase3 PRIVATE dm_example_cxx_api pthread) + +IF(APPLE) + target_link_libraries(dm_example_cxx_phase3 PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static) +else() + if(ENABLE_ADDRESS_SANITIZER) + #With asan there can be undefined symbols + target_link_libraries(dm_example_cxx_phase3 PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive) + else() + target_link_libraries(dm_example_cxx_phase3 PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive) + endif() +endif() http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.cc ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.cc b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.cc new file mode 100644 index 0000000..f5aa178 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.cc @@ -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. + */ + + +#include "Phase3Cmp.h" +#include "Phase3Activator.h" + +using namespace celix::dm; + + +DmActivator* DmActivator::create(DependencyManager& mng) { + return new Phase3Activator(mng); +} + +void Phase3Activator::init() { + Phase3BaseActivator::init(); + cmp.createServiceDependency() + .setRequired(false) + .setFilter("(&(name=phase2a)(non-existing=*))") + .setCallbacks(&Phase3Cmp::setPhase2a); +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.h b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.h new file mode 100644 index 0000000..e02cd61 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.h @@ -0,0 +1,33 @@ +/** + * 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. + */ + +#ifndef CELIX_PHASE3ACTIVATOR_H +#define CELIX_PHASE3ACTIVATOR_H + +#include "Phase3BaseActivator.h" + +using namespace celix::dm; + +class Phase3Activator : public Phase3BaseActivator { +public: + Phase3Activator(DependencyManager& mng) : Phase3BaseActivator(mng) {} + virtual void init(); +}; + +#endif //CELIX_PHASE2AACTIVATOR_H http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.cc ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.cc b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.cc new file mode 100644 index 0000000..37746dc --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.cc @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "Phase3Cmp.h" +#include "Phase3BaseActivator.h" + +using namespace celix::dm; + +void Phase3BaseActivator::init() { + cmp.setCallbacks(nullptr, &Phase3Cmp::start, &Phase3Cmp::stop, nullptr); + + cmp.createServiceDependency() + .setRequired(true) + .setCallbacks(&Phase3Cmp::addPhase2, &Phase3Cmp::removePhase2); +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h new file mode 100644 index 0000000..0f3d813 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h @@ -0,0 +1,35 @@ +/** + * 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. + */ + +#ifndef CELIX_PHASE3BASEACTIVATOR_H +#define CELIX_PHASE3BASEACTIVATOR_H + +#include "celix/dm/DmActivator.h" + +using namespace celix::dm; + +class Phase3BaseActivator : public DmActivator { +public: + Phase3BaseActivator(DependencyManager& mng) : DmActivator(mng), cmp(mng.createComponent()) {} + void init(); +protected: + celix::dm::Component& cmp; +}; + +#endif //CELIX_PHASE3BASEACTIVATOR_H http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Cmp.cc ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Cmp.cc b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Cmp.cc new file mode 100644 index 0000000..dba5942 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Cmp.cc @@ -0,0 +1,65 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "Phase3Cmp.h" +#include +#include +#include +#include +#include +#include + +void Phase3Cmp::start() { + std::cout << "start Phase3Cmp\n"; + running = true; + pollThread = std::thread {&Phase3Cmp::poll, this}; +} + +void Phase3Cmp::stop() { + std::cout << "stop Phase3Cmp\n"; + running = false; + pollThread.join(); +} + +void Phase3Cmp::poll() { + while (running) { + std::cout << "polling Phase3Cmp\n"; + for (std::pair pair : this->phases) { + std::ostringstream oss {}; + oss << "current data for " << pair.second["name"] << " is " << pair.first->getData() << "\n"; + std::cout << oss.str(); + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } +} + +void Phase3Cmp::addPhase2(IPhase2* phase2, celix::dm::Properties&& props) { + std::cout << "adding Iphase2 for Phase3Cmp\n"; + std::pair pair {phase2, props}; + this->phases[phase2] = props; +} + +void Phase3Cmp::removePhase2(IPhase2* phase2, [[gnu::unused]] celix::dm::Properties&& props) { + std::cout << "adding Iphase2 for Phase3Cmp\n"; + this->phases.erase(phase2); +} + +void Phase3Cmp::setPhase2a([[gnu::unused]] IPhase2* phase) { + std::cout << "setting phase2a\n"; +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Cmp.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Cmp.h b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Cmp.h new file mode 100644 index 0000000..8b7e974 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Cmp.h @@ -0,0 +1,50 @@ +/** + * 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. + */ + +#ifndef CELIX_PHASE3CMP_H +#define CELIX_PHASE3CMP_H + +#include "IPhase1.h" +#include "IPhase2.h" +#include +#include +#include +#include +#include +#include "celix/dm/Properties.h" + +class Phase3Cmp { + std::map phases {}; + bool running {false}; + std::thread pollThread {}; +public: + Phase3Cmp() { std::cout << "Constructing Phase3Cmp\n"; } + virtual ~Phase3Cmp() = default; + + void start(); + void stop(); + + void poll(); + + void addPhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager + void removePhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager + void setPhase2a(IPhase2* phase); +}; + +#endif //CELIX_PHASE3CMP_H http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3_locking/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3_locking/CMakeLists.txt b/examples/celix-examples/dm_example_cxx/phase3_locking/CMakeLists.txt new file mode 100644 index 0000000..7a6823a --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3_locking/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. + + +add_celix_bundle(dm_example_cxx_phase3_locking + SYMBOLIC_NAME phase3_locking_cxx + VERSION 0.0.1 + SOURCES + src/Phase3LockingActivator.cc + src/Phase3LockingCmp.cc +) +target_include_directories(dm_example_cxx_phase3_locking PRIVATE src) +target_link_libraries(dm_example_cxx_phase3_locking PRIVATE dm_example_cxx_api pthread) + +IF(APPLE) + target_link_libraries(dm_example_cxx_phase3_locking PRIVATE -Wl,-all_load Celix::dependency_manager_cxx_static) +else() + if(ENABLE_ADDRESS_SANITIZER) + #With asan there can be undefined symbols + target_link_libraries(dm_example_cxx_phase3_locking PRIVATE -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive) + else() + target_link_libraries(dm_example_cxx_phase3_locking PRIVATE -Wl,--no-undefined -Wl,--whole-archive Celix::dependency_manager_cxx_static -Wl,--no-whole-archive) + endif() +endif() http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc new file mode 100644 index 0000000..29d178e --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc @@ -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. + */ + + +#include "Phase3LockingCmp.h" +#include "Phase3LockingActivator.h" + +#include + +using namespace celix::dm; + + +DmActivator* DmActivator::create(DependencyManager& mng) { + return new Phase3LockingActivator(mng); +} + +void Phase3LockingActivator::init() { + auto inst = std::shared_ptr {new Phase3LockingCmp {}}; + + Component& cmp = mng.createComponent(inst) //set inst using a shared ptr + .setCallbacks(nullptr, &Phase3LockingCmp::start, &Phase3LockingCmp::stop, nullptr); + + cmp.createServiceDependency() + .setStrategy(DependencyUpdateStrategy::locking) + .setCallbacks(&Phase3LockingCmp::addPhase2, &Phase3LockingCmp::removePhase2); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h new file mode 100644 index 0000000..78d1748 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h @@ -0,0 +1,33 @@ +/** + * 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. + */ + +#ifndef CELIX_PHASE3LOCKINGACTIVATOR_H +#define CELIX_PHASE3LOCKINGACTIVATOR_H + +#include "celix/dm/DmActivator.h" + +using namespace celix::dm; + +class Phase3LockingActivator : public DmActivator { +public: + Phase3LockingActivator(DependencyManager& mng) : DmActivator(mng) {} + virtual void init(); +}; + +#endif //CELIX_PHASE3LOCKINGAACTIVATOR_H http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.cc ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.cc b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.cc new file mode 100644 index 0000000..b0f5e3e --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.cc @@ -0,0 +1,66 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "Phase3LockingCmp.h" +#include +#include +#include +#include +#include +#include + +void Phase3LockingCmp::start() { + std::cout << "start Phase3LockingCmp\n"; + running = true; + //pollThread = std::thread {&Phase3LockingCmp::poll, std::ref(*this)}; + pollThread = std::thread {&Phase3LockingCmp::poll, this}; +} + +void Phase3LockingCmp::stop() { + std::cout << "stop Phase3LockingCmp\n"; + running = false; + pollThread.join(); +} + +void Phase3LockingCmp::poll() { + while (running) { + std::cout << "polling Phase3LockingCmp\n"; + mutex.lock(); + for (std::pair pair : this->phases) { + std::ostringstream oss {}; + oss << "current data for " << pair.second["name"] << " is " << pair.first->getData() << "\n"; + std::cout << oss.str(); + } + mutex.unlock(); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } +} + +void Phase3LockingCmp::addPhase2(IPhase2* phase2, celix::dm::Properties&& props) { + std::cout << "adding Iphase2 for Phase3LockingCmp\n"; + std::lock_guard lock(mutex); + std::pair pair {phase2, props}; + this->phases[phase2] = props; +} + +void Phase3LockingCmp::removePhase2(IPhase2* phase2, [[gnu::unused]] celix::dm::Properties&& props) { + std::cout << "adding Iphase2 for Phase3LockingCmp\n"; + std::lock_guard lock(mutex); + this->phases.erase(phase2); +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.h b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.h new file mode 100644 index 0000000..678fa80 --- /dev/null +++ b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.h @@ -0,0 +1,50 @@ +/** + * 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. + */ + +#ifndef CELIX_PHASE3LOCKINGCMP_H +#define CELIX_PHASE3LOCKINGCMP_H + +#include "IPhase2.h" +#include +#include +#include +#include +#include +#include +#include "celix/dm/Properties.h" + +class Phase3LockingCmp { + std::map phases {}; + bool running {false}; + std::thread pollThread {}; + std::mutex mutex {}; +public: + Phase3LockingCmp() = default; + virtual ~Phase3LockingCmp() = default; + + void start(); + void stop(); + + void poll(); + + void addPhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager + void removePhase2(IPhase2* phase, celix::dm::Properties&& props); //injector used by dependency manager +}; + +#endif //CELIX_PHASE3LOCKINGCMP_H http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/embedding/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/celix-examples/embedding/CMakeLists.txt b/examples/celix-examples/embedding/CMakeLists.txt new file mode 100644 index 0000000..9c96948 --- /dev/null +++ b/examples/celix-examples/embedding/CMakeLists.txt @@ -0,0 +1,20 @@ +# 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_executable(embedding private/src/main) +target_link_libraries(embedding Celix::framework ) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/embedding/private/src/main.c ---------------------------------------------------------------------- diff --git a/examples/celix-examples/embedding/private/src/main.c b/examples/celix-examples/embedding/private/src/main.c new file mode 100644 index 0000000..b77cb22 --- /dev/null +++ b/examples/celix-examples/embedding/private/src/main.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. + */ +/* + * main.c + * + * \date May 22, 2013 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include + +#include "celix_launcher.h" +#include "celix_errno.h" +#include "framework.h" +#include "bundle_context.h" + +struct foo { + +}; + +struct fooSrv { + struct foo *handle; + celix_status_t (*foo)(struct foo *handle); +}; + +celix_status_t embedded_foo(); + +int main(void) { + + framework_pt framework = NULL; + + properties_pt config = properties_create(); + int rc = celixLauncher_launchWithProperties(config, &framework); + + if (rc == 0) { + bundle_pt fwBundle = NULL; + if(framework_getFrameworkBundle(framework, &fwBundle) == CELIX_SUCCESS){ + + if(bundle_start(fwBundle) == CELIX_SUCCESS){ + + bundle_context_pt context = NULL; + bundle_getContext(fwBundle, &context); + + struct foo *f = calloc(1, sizeof(*f)); + struct fooSrv *fs = calloc(1, sizeof(*fs)); + + fs->handle = f; + fs->foo = embedded_foo; + + service_registration_pt reg = NULL; + + if(bundleContext_registerService(context, "foo", fs, NULL, ®) == CELIX_SUCCESS){ + + service_reference_pt ref = NULL; + if(bundleContext_getServiceReference(context, "foo", &ref) == CELIX_SUCCESS){ + + void *fs2 = NULL; + bundleContext_getService(context, ref, &fs2); + + ((struct fooSrv*) fs2)->foo(((struct fooSrv*) fs2)->handle); + + bundleContext_ungetService(context, ref, NULL); + bundleContext_ungetServiceReference(context, ref); + serviceRegistration_unregister(reg); + } + } + + free(f); + free(fs); + } + } + celixLauncher_destroy(framework); + } + + return rc; + +} + +celix_status_t embedded_foo() { + printf("foo\n"); + return CELIX_SUCCESS; +} + http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/hello_world/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/celix-examples/hello_world/CMakeLists.txt b/examples/celix-examples/hello_world/CMakeLists.txt new file mode 100644 index 0000000..130cef0 --- /dev/null +++ b/examples/celix-examples/hello_world/CMakeLists.txt @@ -0,0 +1,63 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +if(NOT APPLE) +#Importing and exporting libraries not (yet) work under OSX. + +include_directories("${PROJECT_SOURCE_DIR}/utils/public/include") +include_directories("public/include") + +add_library(hello_testlib SHARED + private/src/test +) +set_library_version(hello_testlib "4.3.2") # sets target propery VERSION to 4.3.2 and SOVERSION to 4 + + +add_library(hello_test2lib SHARED + private/src/test2 +) +set_library_version(hello_test2lib "3.3.3") + +add_celix_bundle(hello_bundle + VERSION "1.2" + SOURCES + private/src/activator.c + IMPORT_LIBRARIES hello_test2lib +) + +add_celix_bundle(hello_export + VERSION "1.0" + NO_ACTIVATOR + EXPORT_LIBRARIES hello_test2lib +) + +celix_bundle_private_libs(hello_bundle + hello_testlib +) + +add_celix_container(helloworld_byref + GROUP hello + BUNDLES hello_export hello_bundle ${CELIX_SHELL_BUNDLE} ${CELIX_SHELL_TUI_BUNDLE} +) + +add_celix_container(helloworld_withcopy + GROUP hello + COPY #Ensures that bundles are copied in the deploy location + BUNDLES hello_export hello_bundle ${SHELL_BUNDLE} ${SHELL_TUI_BUNDLE} +) + +endif() http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/hello_world/private/src/activator.c ---------------------------------------------------------------------- diff --git a/examples/celix-examples/hello_world/private/src/activator.c b/examples/celix-examples/hello_world/private/src/activator.c new file mode 100644 index 0000000..37cf782 --- /dev/null +++ b/examples/celix-examples/hello_world/private/src/activator.c @@ -0,0 +1,68 @@ +/** + *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 Aug 20, 2010 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include +#include + +#include "bundle_activator.h" + +#include "test.h" +#include "test2.h" + +struct userData { + char * word; +}; + +celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) { + celix_status_t status = CELIX_SUCCESS; + *userData = malloc(sizeof(struct userData)); + if (*userData != NULL) { + ((struct userData *)(*userData))->word = "World"; + } else { + status = CELIX_START_ERROR; + } + return status; +} + +celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { + struct userData * data = (struct userData *) userData; + printf("Hello %s\n", data->word); + + doo(); + bar(); + + return CELIX_SUCCESS; +} + +celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) { + struct userData * data = (struct userData *) userData; + printf("Goodbye %s\n", data->word); + return CELIX_SUCCESS; +} + +celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { + free(userData); + return CELIX_SUCCESS; +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/hello_world/private/src/test.c ---------------------------------------------------------------------- diff --git a/examples/celix-examples/hello_world/private/src/test.c b/examples/celix-examples/hello_world/private/src/test.c new file mode 100644 index 0000000..280fc61 --- /dev/null +++ b/examples/celix-examples/hello_world/private/src/test.c @@ -0,0 +1,32 @@ +/** + *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. + */ +/* + * test.c + * + * \date 12 Feb 2014 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#include + +void doo() +{ + printf("Hello from second lib\n"); +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/hello_world/private/src/test2.c ---------------------------------------------------------------------- diff --git a/examples/celix-examples/hello_world/private/src/test2.c b/examples/celix-examples/hello_world/private/src/test2.c new file mode 100644 index 0000000..9beb1bc --- /dev/null +++ b/examples/celix-examples/hello_world/private/src/test2.c @@ -0,0 +1,32 @@ +/** + *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. + */ +/* + * test.c + * + * \date 12 Feb 2014 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#include + +void bar() +{ + printf("Hello from (imported) third lib\n"); +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/hello_world/public/include/test.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/hello_world/public/include/test.h b/examples/celix-examples/hello_world/public/include/test.h new file mode 100644 index 0000000..cdbd05d --- /dev/null +++ b/examples/celix-examples/hello_world/public/include/test.h @@ -0,0 +1,34 @@ +/** + *Licensed to the Apache Software Foundation (ASF) under one + *or more contributor license agreements. See the NOTICE file + *distributed with this work for additional information + *regarding copyright ownership. The ASF licenses this file + *to you under the Apache License, Version 2.0 (the + *"License"); you may not use this file except in compliance + *with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + *Unless required by applicable law or agreed to in writing, + *software distributed under the License is distributed on an + *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + *specific language governing permissions and limitations + *under the License. + */ +/* + * test.h + * + * \date 12 Feb 2014 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#ifndef TEST_H_ +#define TEST_H_ + + +void doo(void); + + +#endif /* TEST_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/hello_world/public/include/test2.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/hello_world/public/include/test2.h b/examples/celix-examples/hello_world/public/include/test2.h new file mode 100644 index 0000000..bff9048 --- /dev/null +++ b/examples/celix-examples/hello_world/public/include/test2.h @@ -0,0 +1,34 @@ +/** + *Licensed to the Apache Software Foundation (ASF) under one + *or more contributor license agreements. See the NOTICE file + *distributed with this work for additional information + *regarding copyright ownership. The ASF licenses this file + *to you under the Apache License, Version 2.0 (the + *"License"); you may not use this file except in compliance + *with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + *Unless required by applicable law or agreed to in writing, + *software distributed under the License is distributed on an + *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + *specific language governing permissions and limitations + *under the License. + */ +/* + * test.h + * + * \date 12 Feb 2014 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#ifndef TEST2_H_ +#define TEST2_H_ + + +void bar(void); + + +#endif /* TEST2_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/hello_world_test/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/celix-examples/hello_world_test/CMakeLists.txt b/examples/celix-examples/hello_world_test/CMakeLists.txt new file mode 100644 index 0000000..41045b2 --- /dev/null +++ b/examples/celix-examples/hello_world_test/CMakeLists.txt @@ -0,0 +1,90 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +############################################################################# +## NOTE Examples of using add_celix_bundle and add_celix_container and assorted commands ## +############################################################################# + +add_celix_bundle(hellotest1 + VERSION "1.2" + SOURCES + private/src/activator +) + +target_include_directories(hellotest1 PRIVATE + ${PROJECT_SOURCE_DIR}/utils/public/include + public/include +) + + +celix_bundle_headers(hellotest1 + "X-WebContent: web" + "X-MediaType: application/json" +) + +add_library(tlib SHARED + private/src/test +) +set_library_version(tlib "4.3.2") # sets target propery VERSION to 4.3.2 and SOVERSION to 4 + +#celix_bundle_private_libs(hellotest1 +# #/usr/local/lib/libjansson.4.dylib +# /usr/lib64/libjansson.so.4 +#) +celix_bundle_private_libs(hellotest1 + tlib + #/usr/lib/libcurl.4.dylib + # /usr/lib64/libcurl.so.4 +) + + +add_celix_container(hello_test_deploy + BUNDLES hellotest1 hellotest2 #NOTE hellotest2 is still a unknown target + PROPERTIES + "Test=true" +) + +#add_celix_container(hello_test_deploy_fail +# BUNDLES nonexisting +#) + +#NOTE: Gives error: +#Error evaluating generator expression: +# +# $ +# +# Target "nonexisting" not found. + + + +add_library(hello2act SHARED + private/src/activator +) +set_library_version(hello2act "3.2.4") #sets VERSION prop to 3.2.4 and SOVERSION to 3 +target_link_libraries(hello2act PRIVATE Celix::framework ) +add_celix_bundle(hellotest2 + VERSION "1.0.0" #can be the same as activator lib, but does not have to be + ACTIVATOR hello2act +) + +#add_celix_bundle(hellotest3 +# VERSION "2.1.2" + #ACTIVATOR /usr/local/lib/libjansson.4.dylib + #ACTIVATOR /usr/lib64/libjansson.so.4 + #) + + http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/hello_world_test/private/src/activator.c ---------------------------------------------------------------------- diff --git a/examples/celix-examples/hello_world_test/private/src/activator.c b/examples/celix-examples/hello_world_test/private/src/activator.c new file mode 100644 index 0000000..2185e16 --- /dev/null +++ b/examples/celix-examples/hello_world_test/private/src/activator.c @@ -0,0 +1,63 @@ +/** + *Licensed to the Apache Software Foundation (ASF) under one + *or more contributor license agreements. See the NOTICE file + *distributed with this work for additional information + *regarding copyright ownership. The ASF licenses this file + *to you under the Apache License, Version 2.0 (the + *"License"); you may not use this file except in compliance + *with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + *Unless required by applicable law or agreed to in writing, + *software distributed under the License is distributed on an + *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + *specific language governing permissions and limitations + *under the License. + */ +/* + * activator.c + * + * \date Aug 20, 2010 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include +#include + +#include "bundle_activator.h" + + +struct userData { + char * word; +}; + +celix_status_t bundleActivator_create(bundle_context_pt __attribute__((unused)) context, void **userData) { + celix_status_t status = CELIX_SUCCESS; + *userData = malloc(sizeof(struct userData)); + if (*userData != NULL) { + ((struct userData *)(*userData))->word = "Import"; + } else { + status = CELIX_START_ERROR; + } + return status; +} + +celix_status_t bundleActivator_start(void * userData, bundle_context_pt __attribute__((unused)) context) { + struct userData * data = (struct userData *) userData; + printf("Hello %s\n", data->word); + + return CELIX_SUCCESS; +} + +celix_status_t bundleActivator_stop(void * userData, bundle_context_pt __attribute__((unused)) context) { + struct userData * data = (struct userData *) userData; + printf("Goodbye %s\n", data->word); + return CELIX_SUCCESS; +} + +celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt __attribute__((unused)) context) { + free(userData); + return CELIX_SUCCESS; +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/hello_world_test/private/src/test.c ---------------------------------------------------------------------- diff --git a/examples/celix-examples/hello_world_test/private/src/test.c b/examples/celix-examples/hello_world_test/private/src/test.c new file mode 100644 index 0000000..280fc61 --- /dev/null +++ b/examples/celix-examples/hello_world_test/private/src/test.c @@ -0,0 +1,32 @@ +/** + *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. + */ +/* + * test.c + * + * \date 12 Feb 2014 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#include + +void doo() +{ + printf("Hello from second lib\n"); +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/hello_world_test/public/include/test.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/hello_world_test/public/include/test.h b/examples/celix-examples/hello_world_test/public/include/test.h new file mode 100644 index 0000000..cdbd05d --- /dev/null +++ b/examples/celix-examples/hello_world_test/public/include/test.h @@ -0,0 +1,34 @@ +/** + *Licensed to the Apache Software Foundation (ASF) under one + *or more contributor license agreements. See the NOTICE file + *distributed with this work for additional information + *regarding copyright ownership. The ASF licenses this file + *to you under the Apache License, Version 2.0 (the + *"License"); you may not use this file except in compliance + *with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + *Unless required by applicable law or agreed to in writing, + *software distributed under the License is distributed on an + *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + *specific language governing permissions and limitations + *under the License. + */ +/* + * test.h + * + * \date 12 Feb 2014 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#ifndef TEST_H_ +#define TEST_H_ + + +void doo(void); + + +#endif /* TEST_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/log_service_example/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/celix-examples/log_service_example/CMakeLists.txt b/examples/celix-examples/log_service_example/CMakeLists.txt new file mode 100644 index 0000000..31f6fc8 --- /dev/null +++ b/examples/celix-examples/log_service_example/CMakeLists.txt @@ -0,0 +1,31 @@ +# 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. + +#Importing and exporting libraries not (yet) work under OSX. + +add_celix_bundle(log_service_example + VERSION "1.0" + SOURCES + src/activator.c +) +target_include_directories(log_service_example PRIVATE src) +target_link_libraries(log_service_example PRIVATE Celix::log_service_api Celix::log_helper) + +add_celix_container(log_example + GROUP log_service + BUNDLES log_service_example Celix::log_service Celix::shell Celix::shell_tui +) http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/log_service_example/src/activator.c ---------------------------------------------------------------------- diff --git a/examples/celix-examples/log_service_example/src/activator.c b/examples/celix-examples/log_service_example/src/activator.c new file mode 100644 index 0000000..75eaf59 --- /dev/null +++ b/examples/celix-examples/log_service_example/src/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 Sep 11, 2017 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include +#include +#include +#include "bundle_activator.h" +#include "log_helper.h" + +struct userData { + pthread_t logger_thread; + bool running; + log_helper_pt log_helper; +}; + +static void *loggerThread(void *userData); + +celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) { + celix_status_t status = CELIX_SUCCESS; + *userData = calloc(1, sizeof(struct userData)); + if (*userData != NULL) { + struct userData * data = (struct userData *) *userData; + status = logHelper_create(context, &data->log_helper); + } else { + status = CELIX_START_ERROR; + } + return status; +} + + +celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { + struct userData * data = (struct userData *) userData; + printf("Started log example\n"); + logHelper_start(data->log_helper); + data->running = true; + pthread_create(&data->logger_thread, NULL, loggerThread, data); + return CELIX_SUCCESS; +} + +celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) { + struct userData * data = (struct userData *) userData; + printf("Stopping logger example\n"); + data->running = false; + pthread_join(data->logger_thread, NULL); + logHelper_stop(data->log_helper); + return CELIX_SUCCESS; +} + +celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { + struct userData * data = (struct userData *) userData; + logHelper_destroy(&data->log_helper); + free(userData); + return CELIX_SUCCESS; +} + +static void *loggerThread(void *userData) { + struct userData * data = (struct userData *) userData; + while (data->running) { + logHelper_log(data->log_helper, OSGI_LOGSERVICE_INFO, "My log message"); + sleep(1); + } + return NULL; +} http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/mongoose/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/celix-examples/mongoose/CMakeLists.txt b/examples/celix-examples/mongoose/CMakeLists.txt new file mode 100644 index 0000000..d0e94ae --- /dev/null +++ b/examples/celix-examples/mongoose/CMakeLists.txt @@ -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. + +add_library(mongooselib STATIC private/src/mongoose.c) +SET_TARGET_PROPERTIES(mongooselib PROPERTIES COMPILE_FLAGS -fPIC) + +SET(BUNDLE_SYMBOLICNAME "apache_celix_examples_mongoose") +SET(BUNDLE_VERSION "0.0.1") + +include_directories("private/include") +include_directories("${PROJECT_SOURCE_DIR}/utils/public/include") + +if(WIN32) + set(LIBS wsock32) +endif(WIN32) + +add_celix_bundle(mongoose + VERSION 0.0.1 + SOURCES + private/src/activator + private/include/mongoose.h +) + +celix_bundle_files(mongoose ${CMAKE_CURRENT_LIST_DIR}/root) + +target_link_libraries(mongoose PRIVATE mongooselib ${LIBS}) + +add_celix_container("mongoose_deploy" BUNDLES Celix::shell Celix::shell_tui Celix::log_service mongoose) http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/mongoose/private/include/mongoose.h ---------------------------------------------------------------------- diff --git a/examples/celix-examples/mongoose/private/include/mongoose.h b/examples/celix-examples/mongoose/private/include/mongoose.h new file mode 100644 index 0000000..a846df4 --- /dev/null +++ b/examples/celix-examples/mongoose/private/include/mongoose.h @@ -0,0 +1,218 @@ +// Copyright (c) 2004-2010 Sergey Lyubka +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#ifndef MONGOOSE_HEADER_INCLUDED +#define MONGOOSE_HEADER_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +struct mg_context; // Handle for the HTTP service itself +struct mg_connection; // Handle for the individual connection + + +// This structure contains information about the HTTP request. +struct mg_request_info { + char *request_method; // "GET", "POST", etc + char *uri; // URL-decoded URI + char *http_version; // E.g. "1.0", "1.1" + char *query_string; // \0 - terminated + char *remote_user; // Authenticated user + char *log_message; // Mongoose error log message + long remote_ip; // Client's IP address + int remote_port; // Client's port + int status_code; // HTTP reply status code + int is_ssl; // 1 if SSL-ed, 0 if not + int num_headers; // Number of headers + struct mg_header { + char *name; // HTTP header name + char *value; // HTTP header value + } http_headers[64]; // Maximum 64 headers +}; + +// Various events on which user-defined function is called by Mongoose. +enum mg_event { + MG_NEW_REQUEST, // New HTTP request has arrived from the client + MG_HTTP_ERROR, // HTTP error must be returned to the client + MG_EVENT_LOG, // Mongoose logs an event, request_info.log_message + MG_INIT_SSL, // Mongoose initializes SSL. Instead of mg_connection *, + // SSL context is passed to the callback function. +}; + +// Prototype for the user-defined function. Mongoose calls this function +// on every event mentioned above. +// +// Parameters: +// event: which event has been triggered. +// conn: opaque connection handler. Could be used to read, write data to the +// client, etc. See functions below that accept "mg_connection *". +// request_info: Information about HTTP request. +// +// Return: +// If handler returns non-NULL, that means that handler has processed the +// request by sending appropriate HTTP reply to the client. Mongoose treats +// the request as served. +// If callback returns NULL, that means that callback has not processed +// the request. Handler must not send any data to the client in this case. +// Mongoose proceeds with request handling as if nothing happened. +typedef void * (*mg_callback_pt)(enum mg_event event, + struct mg_connection *conn, + const struct mg_request_info *request_info); + + +// Start web server. +// +// Parameters: +// callback: user defined event handling function or NULL. +// options: NULL terminated list of option_name, option_value pairs that +// specify Mongoose configuration parameters. +// +// Example: +// const char *options[] = { +// "document_root", "/var/www", +// "listening_ports", "80,443s", +// NULL +// }; +// struct mg_context *ctx = mg_start(&my_func, options); +// +// Please refer to http://code.google.com/p/mongoose/wiki/MongooseManual +// for the list of valid option and their possible values. +// +// Return: +// web server context, or NULL on error. +struct mg_context *mg_start(mg_callback_pt callback, const char **options); + + +// Stop the web server. +// +// Must be called last, when an application wants to stop the web server and +// release all associated resources. This function blocks until all Mongoose +// threads are stopped. Context pointer becomes invalid. +void mg_stop(struct mg_context *); + + +// Get the value of particular configuration parameter. +// The value returned is read-only. Mongoose does not allow changing +// configuration at run time. +// If given parameter name is not valid, NULL is returned. For valid +// names, return value is guaranteed to be non-NULL. If parameter is not +// set, zero-length string is returned. +const char *mg_get_option(const struct mg_context *ctx, const char *name); + + +// Return array of strings that represent valid configuration options. +// For each option, a short name, long name, and default value is returned. +// Array is NULL terminated. +const char **mg_get_valid_option_names(void); + + +// Add, edit or delete the entry in the passwords file. +// +// This function allows an application to manipulate .htpasswd files on the +// fly by adding, deleting and changing user records. This is one of the +// several ways of implementing authentication on the server side. For another, +// cookie-based way please refer to the examples/chat.c in the source tree. +// +// If password is not NULL, entry is added (or modified if already exists). +// If password is NULL, entry is deleted. +// +// Return: +// 1 on success, 0 on error. +int mg_modify_passwords_file(struct mg_context *ctx, + const char *passwords_file_name, const char *user, const char *password); + +// Send data to the client. +int mg_write(struct mg_connection *, const void *buf, size_t len); + + +// Send data to the browser using printf() semantics. +// +// Works exactly like mg_write(), but allows to do message formatting. +// Note that mg_printf() uses internal buffer of size IO_BUF_SIZE +// (8 Kb by default) as temporary message storage for formatting. Do not +// print data that is bigger than that, otherwise it will be truncated. +int mg_printf(struct mg_connection *, const char *fmt, ...); + + +// Read data from the remote end, return number of bytes read. +int mg_read(struct mg_connection *, void *buf, size_t len); + + +// Get the value of particular HTTP header. +// +// This is a helper function. It traverses request_info->http_headers array, +// and if the header is present in the array, returns its value. If it is +// not present, NULL is returned. +const char *mg_get_header(const struct mg_connection *, const char *name); + + +// Get a value of particular form variable. +// +// Parameters: +// data: pointer to form-uri-encoded buffer. This could be either POST data, +// or request_info.query_string. +// data_len: length of the encoded data. +// var_name: variable name to decode from the buffer +// buf: destination buffer for the decoded variable +// buf_len: length of the destination buffer +// +// Return: +// On success, length of the decoded variable. +// On error, -1 (variable not found, or destination buffer is too small). +// +// Destination buffer is guaranteed to be '\0' - terminated. In case of +// failure, dst[0] == '\0'. +int mg_get_var(const char *data, size_t data_len, + const char *var_name, char *buf, size_t buf_len); + +// Fetch value of certain cookie variable into the destination buffer. +// +// Destination buffer is guaranteed to be '\0' - terminated. In case of +// failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same +// parameter. This function returns only first occurrence. +// +// Return: +// On success, value length. +// On error, -1 (either "Cookie:" header is not present at all, or the +// requested parameter is not found, or destination buffer is too small +// to hold the value). +int mg_get_cookie(const struct mg_connection *, + const char *cookie_name, char *buf, size_t buf_len); + + +// Return Mongoose version. +const char *mg_version(void); + + +// MD5 hash given strings. +// Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of +// asciiz strings. When function returns, buf will contain human-readable +// MD5 hash. Example: +// char buf[33]; +// mg_md5(buf, "aa", "bb", NULL); +void mg_md5(char *buf, ...); + + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // MONGOOSE_HEADER_INCLUDED http://git-wip-us.apache.org/repos/asf/celix/blob/a8b8410f/examples/celix-examples/mongoose/private/src/activator.c ---------------------------------------------------------------------- diff --git a/examples/celix-examples/mongoose/private/src/activator.c b/examples/celix-examples/mongoose/private/src/activator.c new file mode 100644 index 0000000..beea9df --- /dev/null +++ b/examples/celix-examples/mongoose/private/src/activator.c @@ -0,0 +1,79 @@ +/** + *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 Aug 20, 2010 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include +#include + +#include "bundle_activator.h" +#include "mongoose.h" + +struct userData { + struct mg_context *ctx; + char* entry; +}; + +celix_status_t bundleActivator_create(bundle_context_pt __attribute__((unused)) context, void **userData) { + *userData = calloc(1, sizeof(struct userData)); + return CELIX_SUCCESS; +} + +celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { + bundle_pt bundle; + celix_status_t status = CELIX_SUCCESS; + struct userData * data = (struct userData *) userData; + + if (bundleContext_getBundle(context, &bundle) == CELIX_SUCCESS) { + bundle_getEntry(bundle, "root", &data->entry); + const char *options[] = { + "document_root", data->entry, + "listening_ports", "8081", + NULL + }; + + data->ctx = mg_start(NULL, options); + + if (data->ctx) { + printf("Mongoose started on: %s\n", mg_get_option(data->ctx, "listening_ports")); + } + } else { + status = CELIX_START_ERROR; + } + + return status; +} + +celix_status_t bundleActivator_stop(void * userData, bundle_context_pt __attribute__((unused)) context) { + struct userData * data = (struct userData *) userData; + mg_stop(data->ctx); + printf("Mongoose stopped\n"); + return CELIX_SUCCESS; +} + +celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt __attribute__((unused)) context) { + struct userData * data = (struct userData *) userData; + free(data->entry); + free(data); + return CELIX_SUCCESS; +}