celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [1/2] celix git commit: CELIX-370: Initial drop of the C++ Dependency Manager
Date Wed, 20 Jul 2016 13:52:12 GMT
Repository: celix
Updated Branches:
  refs/heads/develop ffc2a9ad8 -> a9a75c515


http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase1/src/Phase1Activator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase1/src/Phase1Activator.cc b/examples/dm_example_cxx/phase1/src/Phase1Activator.cc
new file mode 100644
index 0000000..78af757
--- /dev/null
+++ b/examples/dm_example_cxx/phase1/src/Phase1Activator.cc
@@ -0,0 +1,59 @@
+/**
+ * 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 "Phase1Activator.h"
+
+using namespace celix::dm;
+
+/* This example create a C++ component providing a C++ and C service
+ * For the C service a service struct in initialized and registered
+ * For the C++ service the object itself is used
+ */
+
+DmActivator* DmActivator::create(DependencyManager& mng) {
+    return new Phase1Activator(mng);
+}
+
+void Phase1Activator::init(DependencyManager& manager) {
+    std::shared_ptr<Phase1Cmp> cmp {new Phase1Cmp()};
+
+    Properties cmdProps;
+    cmdProps[OSGI_SHELL_COMMAND_NAME] = "phase1_info";
+    cmdProps[OSGI_SHELL_COMMAND_USAGE] = "phase1_info";
+    cmdProps[OSGI_SHELL_COMMAND_DESCRIPTION] = "Print information about the Phase1Cmp";
+
+
+    cmd.handle = cmp.get();
+    cmd.executeCommand = [](void *handle, char* line, FILE* out, FILE *err) {
+        Phase1Cmp* cmp = (Phase1Cmp*)handle;
+        return cmp->infoCmd(line, out, err);
+    };
+
+    add(createComponent<Phase1Cmp>()
+        .setInstance(cmp) //using a pointer a instance. Also support is lazy initialization
(default constructor needed) or a rvalue reference (move)
+        .addInterface<IPhase1>(IPHASE1_VERSION, {})
+        .addCInterface(&cmd, OSGI_SHELL_COMMAND_SERVICE_NAME, "", cmdProps)
+        .setCallbacks(&Phase1Cmp::init, &Phase1Cmp::start, &Phase1Cmp::stop,
&Phase1Cmp::deinit)
+    );
+}
+
+void Phase1Activator::deinit(DependencyManager& manager) {
+    //nothing to do
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase1/src/Phase1Cmp.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase1/src/Phase1Cmp.cc b/examples/dm_example_cxx/phase1/src/Phase1Cmp.cc
new file mode 100644
index 0000000..998555f
--- /dev/null
+++ b/examples/dm_example_cxx/phase1/src/Phase1Cmp.cc
@@ -0,0 +1,49 @@
+/**
+ * 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 <iostream>
+#include <stdlib.h>
+#include <stdio.h>
+
+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 rand();
+};
+
+int Phase1Cmp::infoCmd(char * line, FILE *out, FILE *err) {
+    fprintf(out, "Phase1: number of getData calls: %u\n", counter);
+    return 0;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase2/include/Phase2Activator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/include/Phase2Activator.h b/examples/dm_example_cxx/phase2/include/Phase2Activator.h
new file mode 100644
index 0000000..9e89f0b
--- /dev/null
+++ b/examples/dm_example_cxx/phase2/include/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(DependencyManager& manager);
+    virtual void deinit(DependencyManager& manager);
+};
+
+#endif //CELIX_PHASE2AACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase2/include/Phase2Cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/include/Phase2Cmp.h b/examples/dm_example_cxx/phase2/include/Phase2Cmp.h
new file mode 100644
index 0000000..d0e4f6c
--- /dev/null
+++ b/examples/dm_example_cxx/phase2/include/Phase2Cmp.h
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef CELIX_PHASE2CMP_H
+#define CELIX_PHASE2CMP_H
+
+#include "IPhase1.h"
+#include "IPhase2.h"
+#include <stdint.h>
+#include <stdio.h>
+#include <thread>
+
+class Phase2Cmp : public IPhase2 {
+    IPhase1* phase1 {nullptr};
+public:
+    Phase2Cmp() = default;
+    virtual ~Phase2Cmp() = default;
+
+    void setPhase1(IPhase1* phase); //injector used by dependency manager
+
+    virtual double getData(); //implements IPhase2
+};
+
+#endif //CELIX_PHASE2CMP_H

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase2a/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2a/CMakeLists.txt b/examples/dm_example_cxx/phase2a/CMakeLists.txt
new file mode 100644
index 0000000..c423380
--- /dev/null
+++ b/examples/dm_example_cxx/phase2a/CMakeLists.txt
@@ -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.
+
+include_directories(
+        ../phase2/include
+        ../api
+)
+
+add_bundle(phase2a_cxx
+    SYMBOLIC_NAME phase2a_cxx
+    VERSION 0.0.1
+    SOURCES
+        src/Phase2aActivator.cc
+        src/Phase2aCmp.cc
+)
+
+
+IF(APPLE)
+    target_link_libraries(phase2a_cxx celix_framework -Wl,-all_load dependency_manager_cxx_static)
+else()
+    if(ENABLE_ADDRESS_SANITIZER)
+        #With asan there can be undefined symbols
+        target_link_libraries(phase2a_cxx -Wl,--whole-archive dependency_manager_cxx_static
-Wl,--no-whole-archive celix_framework)
+    else()
+        target_link_libraries(phase2a_cxx -Wl,--no-undefined -Wl,--whole-archive dependency_manager_cxx_static
-Wl,--no-whole-archive celix_framework)
+    endif()
+endif()

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc b/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc
new file mode 100644
index 0000000..d0e6c29
--- /dev/null
+++ b/examples/dm_example_cxx/phase2a/src/Phase2aActivator.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 "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(DependencyManager& manager) {
+
+    Properties props {};
+    props["name"] = "phase2a";
+
+    add(createComponent<Phase2Cmp>()
+        .setInstance(Phase2Cmp()) //NOTE using move initialization
+        .addInterface<IPhase2>(IPHASE2_VERSION, props)
+        .add(createServiceDependency<Phase2Cmp,IPhase1>()
+            .setRequired(true)
+            .setCallbacks(&Phase2Cmp::setPhase1)
+        )
+        .add(createCServiceDependency<Phase2Cmp>()
+            .setRequired(false)
+            .setCService(OSGI_LOGSERVICE_NAME, {}, {})
+        )
+    );
+}
+
+void Phase2Activator::deinit(DependencyManager& manager) {
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc b/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc
new file mode 100644
index 0000000..088c218
--- /dev/null
+++ b/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc
@@ -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.
+ */
+
+#include "Phase2Cmp.h"
+#include <iostream>
+#include <stdlib.h>
+#include <stdio.h>
+
+void Phase2Cmp::setPhase1(IPhase1* phase1) {
+    std::cout << "setting phase1 for phase2\n";
+    this->phase1 = phase1;
+}
+
+double Phase2Cmp::getData() {
+    return phase1->getData() * 42.0;
+};

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase2b/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2b/CMakeLists.txt b/examples/dm_example_cxx/phase2b/CMakeLists.txt
new file mode 100644
index 0000000..ae73563
--- /dev/null
+++ b/examples/dm_example_cxx/phase2b/CMakeLists.txt
@@ -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.
+
+include_directories(
+        ../phase2/include
+        include
+        ../api
+)
+
+add_bundle(phase2b_cxx
+    SYMBOLIC_NAME phase2b_cxx
+    VERSION 0.0.1
+    SOURCES
+        src/Phase2bActivator.cc
+        src/Phase2bCmp.cc
+)
+
+IF(APPLE)
+    target_link_libraries(phase2b_cxx celix_framework -Wl,-all_load dependency_manager_cxx_static)
+else()
+    if(ENABLE_ADDRESS_SANITIZER)
+        #With asan there can be undefined symbols
+        target_link_libraries(phase2b_cxx -Wl,--whole-archive dependency_manager_cxx_static
-Wl,--no-whole-archive celix_framework)
+    else()
+        target_link_libraries(phase2b_cxx -Wl,--no-undefined -Wl,--whole-archive dependency_manager_cxx_static
-Wl,--no-whole-archive celix_framework)
+    endif()
+endif()

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc b/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
new file mode 100644
index 0000000..f518581
--- /dev/null
+++ b/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
@@ -0,0 +1,52 @@
+/**
+ * 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(DependencyManager& manager) {
+
+    Properties props {};
+    props["name"] = "phase2b";
+
+    add(createComponent<Phase2Cmp>()
+        .addInterface<IPhase2>(IPHASE2_VERSION, props)
+        .add(createServiceDependency<Phase2Cmp,IPhase1>()
+            .setRequired(true)
+            .setCallbacks(&Phase2Cmp::setPhase1)
+        )
+        .add(createCServiceDependency<Phase2Cmp>()
+            .setRequired(false)
+            .setCService(OSGI_LOGSERVICE_NAME, {}, {})
+        )
+    );
+}
+
+void Phase2Activator::deinit(DependencyManager& manager) {
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc b/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc
new file mode 100644
index 0000000..fac2867
--- /dev/null
+++ b/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc
@@ -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.
+ */
+
+#include "Phase2Cmp.h"
+#include <iostream>
+#include <stdlib.h>
+#include <stdio.h>
+
+void Phase2Cmp::setPhase1(IPhase1* phase1) {
+    std::cout << "setting phase1 for phase2\n";
+    this->phase1 = phase1;
+}
+
+double Phase2Cmp::getData() {
+    return phase1->getData() * 24.0;
+};

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase3/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/CMakeLists.txt b/examples/dm_example_cxx/phase3/CMakeLists.txt
new file mode 100644
index 0000000..4fa498c
--- /dev/null
+++ b/examples/dm_example_cxx/phase3/CMakeLists.txt
@@ -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.
+
+include_directories(
+        include
+        ../api
+)
+
+add_bundle(phase3_cxx
+    SYMBOLIC_NAME phase3_cxx
+    VERSION 0.0.1
+    SOURCES
+        src/Phase3LockingActivator.cc
+        src/Phase3LockingCmp.cc
+)
+
+
+IF(APPLE)
+    target_link_libraries(phase3_cxx celix_framework -Wl,-all_load dependency_manager_cxx_static)
+else()
+    if(ENABLE_ADDRESS_SANITIZER)
+        #With asan there can be undefined symbols
+        target_link_libraries(phase3_cxx -Wl,--whole-archive dependency_manager_cxx_static
-Wl,--no-whole-archive celix_framework)
+    else()
+        target_link_libraries(phase3_cxx -Wl,--no-undefined -Wl,--whole-archive dependency_manager_cxx_static
-Wl,--no-whole-archive celix_framework)
+    endif()
+endif()

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase3/include/Phase3Activator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/include/Phase3Activator.h b/examples/dm_example_cxx/phase3/include/Phase3Activator.h
new file mode 100644
index 0000000..f058d46
--- /dev/null
+++ b/examples/dm_example_cxx/phase3/include/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 "celix/dm/DmActivator.h"
+
+using namespace celix::dm;
+
+class Phase3Activator : public DmActivator {
+public:
+    Phase3Activator(DependencyManager& mng) : DmActivator(mng) {}
+    virtual void init(DependencyManager& manager);
+};
+
+#endif //CELIX_PHASE2AACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase3/include/Phase3Cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/include/Phase3Cmp.h b/examples/dm_example_cxx/phase3/include/Phase3Cmp.h
new file mode 100644
index 0000000..a4d4bad
--- /dev/null
+++ b/examples/dm_example_cxx/phase3/include/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_PHASE2CMP_H
+#define CELIX_PHASE2CMP_H
+
+#include "IPhase1.h"
+#include "IPhase2.h"
+#include <stdint.h>
+#include <stdio.h>
+#include <thread>
+#include <iostream>
+#include <list>
+#include "celix/dm/Properties.h"
+
+class Phase3Cmp  {
+    std::map<IPhase2*,celix::dm::Properties> 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_PHASE2CMP_H

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase3/src/Phase3LockingActivator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/src/Phase3LockingActivator.cc b/examples/dm_example_cxx/phase3/src/Phase3LockingActivator.cc
new file mode 100644
index 0000000..43825e9
--- /dev/null
+++ b/examples/dm_example_cxx/phase3/src/Phase3LockingActivator.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 "Phase3Cmp.h"
+#include "Phase3Activator.h"
+
+using namespace celix::dm;
+
+
+DmActivator* DmActivator::create(DependencyManager& mng) {
+    return new Phase3Activator(mng);
+}
+
+void Phase3Activator::init(DependencyManager& manager) {
+    add(createComponent<Phase3Cmp>()
+        //NOTE no setInstance -> lazy initialization using the default constructor
+        .setCallbacks(nullptr, &Phase3Cmp::start, &Phase3Cmp::stop, nullptr)
+        .add(createServiceDependency<Phase3Cmp,IPhase2>()
+            .setRequired(true)
+            .setCallbacks(&Phase3Cmp::addPhase2, &Phase3Cmp::removePhase2)
+        )
+        .add(createServiceDependency<Phase3Cmp,IPhase2>()
+             .setRequired(false)
+             .setFilter("(&(name=phase2a)(non-existing=*))")
+             .setCallbacks(&Phase3Cmp::setPhase2a)
+        )
+    );
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase3/src/Phase3LockingCmp.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/src/Phase3LockingCmp.cc b/examples/dm_example_cxx/phase3/src/Phase3LockingCmp.cc
new file mode 100644
index 0000000..8eeafe6
--- /dev/null
+++ b/examples/dm_example_cxx/phase3/src/Phase3LockingCmp.cc
@@ -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.
+ */
+
+#include "Phase3Cmp.h"
+#include <iostream>
+#include <stdlib.h>
+#include <stdio.h>
+#include <thread>
+#include <chrono>
+
+void Phase3Cmp::start() {
+    std::cout << "start Phase3Cmp\n";
+    running = true;
+    pollThread = std::thread {&Phase3Cmp::poll, std::ref(*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<IPhase2*, celix::dm::Properties> pair : this->phases) {
+            std::string name = pair.second["name"];
+            std::cout << "current data for " << name << " is " <<
pair.first->getData() << "\n";
+        }
+        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<IPhase2*, celix::dm::Properties> pair {phase2, props};
+    this->phases[phase2] = props;
+}
+
+void Phase3Cmp::removePhase2(IPhase2* phase2, celix::dm::Properties&& props) {
+    std::cout << "adding Iphase2 for Phase3Cmp\n";
+    this->phases.erase(phase2);
+}
+
+void Phase3Cmp::setPhase2a(IPhase2* phase) {
+    std::cout << "setting phase2a\n";
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3_locking/CMakeLists.txt b/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
new file mode 100644
index 0000000..52b0f3a
--- /dev/null
+++ b/examples/dm_example_cxx/phase3_locking/CMakeLists.txt
@@ -0,0 +1,40 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+include_directories(
+        include
+        ../api
+)
+
+add_bundle(phase3_locking_cxx
+    SYMBOLIC_NAME phase3_locking_cxx
+    VERSION 0.0.1
+    SOURCES
+        src/Phase3LockingActivator.cc
+        src/Phase3LockingCmp.cc
+)
+
+IF(APPLE)
+    target_link_libraries(phase3_locking_cxx celix_framework -Wl,-all_load dependency_manager_cxx_static)
+else()
+    if(ENABLE_ADDRESS_SANITIZER)
+        #With asan there can be undefined symbols
+        target_link_libraries(phase3_locking_cxx -Wl,--whole-archive dependency_manager_cxx_static
-Wl,--no-whole-archive celix_framework)
+    else()
+        target_link_libraries(phase3_locking_cxx -Wl,--no-undefined -Wl,--whole-archive dependency_manager_cxx_static
-Wl,--no-whole-archive celix_framework)
+    endif()
+endif()

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase3_locking/include/Phase3LockingActivator.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3_locking/include/Phase3LockingActivator.h b/examples/dm_example_cxx/phase3_locking/include/Phase3LockingActivator.h
new file mode 100644
index 0000000..1b7f7a1
--- /dev/null
+++ b/examples/dm_example_cxx/phase3_locking/include/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_PHASE3ACTIVATOR_H
+#define CELIX_PHASE3ACTIVATOR_H
+
+#include "celix/dm/DmActivator.h"
+
+using namespace celix::dm;
+
+class Phase3LockingActivator : public DmActivator {
+public:
+    Phase3LockingActivator(DependencyManager& mng) : DmActivator(mng) {}
+    virtual void init(DependencyManager& manager);
+};
+
+#endif //CELIX_PHASE2AACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase3_locking/include/Phase3LockingCmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3_locking/include/Phase3LockingCmp.h b/examples/dm_example_cxx/phase3_locking/include/Phase3LockingCmp.h
new file mode 100644
index 0000000..c56fe60
--- /dev/null
+++ b/examples/dm_example_cxx/phase3_locking/include/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_PHASE2CMP_H
+#define CELIX_PHASE2CMP_H
+
+#include "IPhase2.h"
+#include <stdint.h>
+#include <stdio.h>
+#include <thread>
+#include <iostream>
+#include <mutex>
+#include <map>
+#include "celix/dm/Properties.h"
+
+class Phase3LockingCmp  {
+    std::map<IPhase2*,celix::dm::Properties> 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_PHASE2CMP_H

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc b/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
new file mode 100644
index 0000000..546807b
--- /dev/null
+++ b/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#include "Phase3LockingCmp.h"
+#include "Phase3LockingActivator.h"
+
+using namespace celix::dm;
+
+
+DmActivator* DmActivator::create(DependencyManager& mng) {
+    return new Phase3LockingActivator(mng);
+}
+
+void Phase3LockingActivator::init(DependencyManager& manager) {
+    add(createComponent<Phase3LockingCmp>()
+        //NOTE no setInstance -> lazy initialization using the default constructor
+        .setCallbacks(nullptr, &Phase3LockingCmp::start, &Phase3LockingCmp::stop,
nullptr)
+        .add(createServiceDependency<Phase3LockingCmp,IPhase2>()
+            .setStrategy(DependencyUpdateStrategy::locking)
+            .setCallbacks(&Phase3LockingCmp::addPhase2, &Phase3LockingCmp::removePhase2)
+        )
+    );
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a9a75c51/examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.cc b/examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.cc
new file mode 100644
index 0000000..382c112
--- /dev/null
+++ b/examples/dm_example_cxx/phase3_locking/src/Phase3LockingCmp.cc
@@ -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.
+ */
+
+#include "Phase3LockingCmp.h"
+#include <iostream>
+#include <stdlib.h>
+#include <stdio.h>
+#include <thread>
+#include <chrono>
+
+void Phase3LockingCmp::start() {
+    std::cout << "start Phase3LockingCmp\n";
+    running = true;
+    pollThread = std::thread {&Phase3LockingCmp::poll, std::ref(*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<IPhase2*, celix::dm::Properties> pair : this->phases) {
+            std::string name = pair.second["name"];
+            std::cout << "current data for " << name << " is " <<
pair.first->getData() << "\n";
+        }
+        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<std::mutex> lock(mutex);
+    std::pair<IPhase2*, celix::dm::Properties> pair {phase2, props};
+    this->phases[phase2] = props;
+}
+
+void Phase3LockingCmp::removePhase2(IPhase2* phase2, celix::dm::Properties&& props)
{
+    std::cout << "adding Iphase2 for Phase3LockingCmp\n";
+    std::lock_guard<std::mutex> lock(mutex);
+    this->phases.erase(phase2);
+}
\ No newline at end of file


Mime
View raw message