From 4d8df637ae1d5292a87d21bd5c4c2c9ee61a397a Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Mon, 14 Aug 2017 16:24:15 +0200 Subject: [PATCH 01/71] Rename to test_npv.cpp --- nest_python_vis/tests/src/{test-npv.cpp => test_npv.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename nest_python_vis/tests/src/{test-npv.cpp => test_npv.cpp} (100%) diff --git a/nest_python_vis/tests/src/test-npv.cpp b/nest_python_vis/tests/src/test_npv.cpp similarity index 100% rename from nest_python_vis/tests/src/test-npv.cpp rename to nest_python_vis/tests/src/test_npv.cpp From 14bf591b39b4b267cb753462c8a62c24e7e6033d Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Mon, 14 Aug 2017 16:30:39 +0200 Subject: [PATCH 02/71] Create NestPythonVis class --- nest_python_vis/include/npv/npv.hpp | 5 ++++- nest_python_vis/src/npv.cpp | 3 +-- nest_python_vis/tests/src/test_npv.cpp | 10 +++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/nest_python_vis/include/npv/npv.hpp b/nest_python_vis/include/npv/npv.hpp index bf75323..a27070e 100644 --- a/nest_python_vis/include/npv/npv.hpp +++ b/nest_python_vis/include/npv/npv.hpp @@ -26,7 +26,10 @@ namespace npv { -std::string Greet(); +class NestPythonVis { + public: + std::string Greet() const; +}; } // namespace npv diff --git a/nest_python_vis/src/npv.cpp b/nest_python_vis/src/npv.cpp index 472b09d..cabe228 100644 --- a/nest_python_vis/src/npv.cpp +++ b/nest_python_vis/src/npv.cpp @@ -25,6 +25,5 @@ namespace npv { -std::string Greet() { return "G'day!"; } - +std::string NestPythonVis::Greet() const { return "G'day!"; } } // namespace npv diff --git a/nest_python_vis/tests/src/test_npv.cpp b/nest_python_vis/tests/src/test_npv.cpp index ea04254..3adfa23 100644 --- a/nest_python_vis/tests/src/test_npv.cpp +++ b/nest_python_vis/tests/src/test_npv.cpp @@ -23,4 +23,12 @@ #include "npv/npv.hpp" -TEST_CASE("NPV shall greet.", "[npv]") { CHECK(npv::Greet() == "G'day!"); } +SCENARIO("An npv object shall greet", "[npv][npv::NestPythonVis]") { + GIVEN("A NestPythonVis object") { + npv::NestPythonVis vis; + WHEN("i call its greet function") { + auto ret_val = vis.Greet(); + THEN("it yields 'G'day!'") { CHECK(ret_val == "G'day!"); } + } + } +} From 912796bb0375794d5e4618b0ad3a5be5490bd624 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Mon, 14 Aug 2017 16:53:38 +0200 Subject: [PATCH 03/71] Add binding to double and querying its string representation. --- nest_python_vis/include/npv/npv.hpp | 8 ++++++- nest_python_vis/src/npv.cpp | 12 ++++++++++- nest_python_vis/tests/src/test_npv.cpp | 30 ++++++++++++++++++++------ 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/nest_python_vis/include/npv/npv.hpp b/nest_python_vis/include/npv/npv.hpp index a27070e..55b798d 100644 --- a/nest_python_vis/include/npv/npv.hpp +++ b/nest_python_vis/include/npv/npv.hpp @@ -28,7 +28,13 @@ namespace npv { class NestPythonVis { public: - std::string Greet() const; + explicit NestPythonVis(double* value) : value_(value) {} + + std::string ValueString() const; + + private: + std::string FormatValue() const; + double* value_{nullptr}; }; } // namespace npv diff --git a/nest_python_vis/src/npv.cpp b/nest_python_vis/src/npv.cpp index cabe228..b89def8 100644 --- a/nest_python_vis/src/npv.cpp +++ b/nest_python_vis/src/npv.cpp @@ -21,9 +21,19 @@ #include "npv/npv.hpp" +#include #include namespace npv { -std::string NestPythonVis::Greet() const { return "G'day!"; } +std::string NestPythonVis::ValueString() const { + return value_ == nullptr ? "nullptr" : FormatValue(); +} + +std::string NestPythonVis::FormatValue() const { + std::ostringstream sstr; + sstr << *value_; + return sstr.str(); +} + } // namespace npv diff --git a/nest_python_vis/tests/src/test_npv.cpp b/nest_python_vis/tests/src/test_npv.cpp index 3adfa23..b509e42 100644 --- a/nest_python_vis/tests/src/test_npv.cpp +++ b/nest_python_vis/tests/src/test_npv.cpp @@ -23,12 +23,30 @@ #include "npv/npv.hpp" -SCENARIO("An npv object shall greet", "[npv][npv::NestPythonVis]") { - GIVEN("A NestPythonVis object") { - npv::NestPythonVis vis; - WHEN("i call its greet function") { - auto ret_val = vis.Greet(); - THEN("it yields 'G'day!'") { CHECK(ret_val == "G'day!"); } +SCENARIO("An npv object shall visualize the double it is bound to", + "[npv][npv::NestPythonVis") { + GIVEN("A double and A NestPythonVis object") { + double value = 0.0; + npv::NestPythonVis vis(&value); + + WHEN("I ask for a string representing the value") { + auto ret_val = vis.ValueString(); + THEN("it shall represent the bound value.") { REQUIRE(ret_val == "0"); } + } + + WHEN("the bound value is changed by some external code") { + value = 42.0; + THEN("its string representation shall be updated accordingly.") { + REQUIRE(vis.ValueString() == "42"); + } + } + } + + GIVEN("A NestPythonVis object bound to nullptr") { + npv::NestPythonVis vis(nullptr); + WHEN("I ask for a string representing tha value") { + auto ret_val = vis.ValueString(); + THEN("it shall read 'nullptr'.") { REQUIRE(ret_val == "nullptr"); } } } } From 3f53d8995ede95ecab3ea0dde5fb0358b6d0e926 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Mon, 14 Aug 2017 17:02:53 +0200 Subject: [PATCH 04/71] Add CoutCapture support to tests --- nest_python_vis/tests/CMakeLists.txt | 9 ++- .../tests/test_utilities/cout_capture.hpp | 62 ++++++++++++++++ .../tests/src/test_cout_capture.cpp | 73 +++++++++++++++++++ 3 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 nest_python_vis/tests/test_utilities/cout_capture.hpp create mode 100644 nest_python_vis/tests/test_utilities/tests/src/test_cout_capture.cpp diff --git a/nest_python_vis/tests/CMakeLists.txt b/nest_python_vis/tests/CMakeLists.txt index 81bb9dc..6875481 100644 --- a/nest_python_vis/tests/CMakeLists.txt +++ b/nest_python_vis/tests/CMakeLists.txt @@ -21,10 +21,13 @@ file(GLOB NPV_TEST_SOURCES src/*.cpp) file(GLOB NPV_TEST_HEADERS src/*.hpp) +file(GLOB NPV_TEST_UTILITIES_TEST_SOURCES test_utilities/tests/src/*.cpp) +file(GLOB NPV_TEST_UTILITIES_HEADERS test_utilities/*.hpp) + add_test_catch(NAME "NPV-tests" - SOURCES ${NPV_TEST_SOURCES} - HEADERS ${NPV_TEST_HEADERS} + SOURCES ${NPV_TEST_SOURCES} ${NPV_TEST_UTILITIES_TEST_SOURCES} + HEADERS ${NPV_TEST_HEADERS} ${NPV_TEST_UTILITIES_HEADERS} CATCH_MAIN src/tests.cpp INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} LINK_LIBRARIES npv @@ -33,5 +36,7 @@ add_test_catch(NAME "NPV-tests" add_test_cpplint(NAME "npv-tests--cpplint" ${NPV_TEST_SOURCES} ${NPV_TEST_HEADERS} + ${NPV_TEST_UTILITIES_TEST_SOURCES} + ${NPV_TEST_UTILITIES_HEADERS} ) diff --git a/nest_python_vis/tests/test_utilities/cout_capture.hpp b/nest_python_vis/tests/test_utilities/cout_capture.hpp new file mode 100644 index 0000000..0a91d97 --- /dev/null +++ b/nest_python_vis/tests/test_utilities/cout_capture.hpp @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// nest python vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 NEST_PYTHON_VIS_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ +#define NEST_PYTHON_VIS_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ + +#include +#include +#include + +#include "catch/catch.hpp" + +namespace test_utilities { + +class CoutCapture { + public: + CoutCapture() { original_rdbuf_ = std::cout.rdbuf(cout_stream_.rdbuf()); } + ~CoutCapture() { std::cout.rdbuf(original_rdbuf_); } + + bool operator==(const std::string& other) const { + return cout_stream_.str() == other; + } + + std::string ToString() const { return "\"" + cout_stream_.str() + "\""; } + + private: + std::streambuf* original_rdbuf_; + std::stringstream cout_stream_; +}; + +} // namespace test_utilities + +namespace Catch { + +template <> +struct StringMaker { + static std::string convert(const test_utilities::CoutCapture& cout_capture) { + return cout_capture.ToString(); + } +}; + +} // namespace Catch + +#endif // NEST_PYTHON_VIS_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ diff --git a/nest_python_vis/tests/test_utilities/tests/src/test_cout_capture.cpp b/nest_python_vis/tests/test_utilities/tests/src/test_cout_capture.cpp new file mode 100644 index 0000000..ae70b70 --- /dev/null +++ b/nest_python_vis/tests/test_utilities/tests/src/test_cout_capture.cpp @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// nest python vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "catch/catch.hpp" + +#include "test_utilities/cout_capture.hpp" + +SCENARIO("CoutCapture captures standard output", "[tests][test::utils]") { + GIVEN("a CoutCapture") { + test_utilities::CoutCapture cout_capture; + + WHEN("I print something to cout") { + std::cout << "something"; + THEN("'something' is captured") { REQUIRE(cout_capture == "something"); } + WHEN("I add else to cout") { + std::cout << " else"; + THEN("'something else' is captures") { + REQUIRE(cout_capture == "something else"); + } + } + WHEN("I then use another CoutCapture and print foo") { + test_utilities::CoutCapture another_cout_capture; + std::cout << "foo"; + THEN("only 'foo' should be captured") { + REQUIRE(another_cout_capture == "foo"); + } + } + } + WHEN("I print two lines to cout") { + std::cout << "two" << std::endl; + std::cout << "lines"; + THEN("two lines are captured") { REQUIRE(cout_capture == "two\nlines"); } + } + } +} + +SCENARIO( + "CoutCapture captures standard output respecting the scope of the " + "CoutCapture", + "[tests][test::utils]") { + WHEN("I use CoutCapture in different scopes") { + test_utilities::CoutCapture cout_capture; + std::cout << "something"; + { + test_utilities::CoutCapture another_cout_capture; + std::cout << "foo"; + } + std::cout << " else"; + THEN("the scope is respected") { + REQUIRE(cout_capture == "something else"); + } + } +} From 178c4ec8ae97333a0ed2298100e2bab9156578f4 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Mon, 14 Aug 2017 17:03:13 +0200 Subject: [PATCH 05/71] Add basic NestPythonVis::Run --- nest_python_vis/include/npv/npv.hpp | 2 ++ nest_python_vis/src/npv.cpp | 3 +++ nest_python_vis/tests/src/test_npv.cpp | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/nest_python_vis/include/npv/npv.hpp b/nest_python_vis/include/npv/npv.hpp index 55b798d..c0dd756 100644 --- a/nest_python_vis/include/npv/npv.hpp +++ b/nest_python_vis/include/npv/npv.hpp @@ -32,6 +32,8 @@ class NestPythonVis { std::string ValueString() const; + void Run(); + private: std::string FormatValue() const; double* value_{nullptr}; diff --git a/nest_python_vis/src/npv.cpp b/nest_python_vis/src/npv.cpp index b89def8..61ed8af 100644 --- a/nest_python_vis/src/npv.cpp +++ b/nest_python_vis/src/npv.cpp @@ -21,6 +21,7 @@ #include "npv/npv.hpp" +#include #include #include @@ -36,4 +37,6 @@ std::string NestPythonVis::FormatValue() const { return sstr.str(); } +void NestPythonVis::Run() { std::cout << ValueString() << std::endl; } + } // namespace npv diff --git a/nest_python_vis/tests/src/test_npv.cpp b/nest_python_vis/tests/src/test_npv.cpp index b509e42..2dd34ab 100644 --- a/nest_python_vis/tests/src/test_npv.cpp +++ b/nest_python_vis/tests/src/test_npv.cpp @@ -23,6 +23,8 @@ #include "npv/npv.hpp" +#include "test_utilities/cout_capture.hpp" + SCENARIO("An npv object shall visualize the double it is bound to", "[npv][npv::NestPythonVis") { GIVEN("A double and A NestPythonVis object") { @@ -40,6 +42,14 @@ SCENARIO("An npv object shall visualize the double it is bound to", REQUIRE(vis.ValueString() == "42"); } } + + WHEN("I run the visualization") { + test_utilities::CoutCapture cout_capture; + vis.Run(); + THEN("I will find the string representation of value on cout") { + REQUIRE(cout_capture == "0\n"); + } + } } GIVEN("A NestPythonVis object bound to nullptr") { From 0977999e956c967f588a19357812d9d7f22b5426 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 15 Aug 2017 07:28:37 +0200 Subject: [PATCH 06/71] Disable cpplint's c++11 warnings. --- CPPLINT.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CPPLINT.cfg b/CPPLINT.cfg index 76cc427..9c180f6 100644 --- a/CPPLINT.cfg +++ b/CPPLINT.cfg @@ -1,5 +1,5 @@ set noparent -filter=-readability/check +filter=-readability/check,-build/c++ linelength=80 extensions=c,cpp,h,hpp headers=h,hpp From 7b83c8bebbf08e2f191d8e7d21d9f313ed17fef1 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 15 Aug 2017 07:29:23 +0200 Subject: [PATCH 07/71] Make NestPythonVis threaded --- nest_python_vis/include/npv/npv.hpp | 26 ++++++++++++++++++++++++-- nest_python_vis/src/npv.cpp | 13 +++++++++++-- nest_python_vis/tests/src/test_npv.cpp | 22 ++++++++++++++++++---- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/nest_python_vis/include/npv/npv.hpp b/nest_python_vis/include/npv/npv.hpp index c0dd756..36f6b3b 100644 --- a/nest_python_vis/include/npv/npv.hpp +++ b/nest_python_vis/include/npv/npv.hpp @@ -22,21 +22,43 @@ #ifndef NEST_PYTHON_VIS_INCLUDE_NPV_NPV_HPP_ #define NEST_PYTHON_VIS_INCLUDE_NPV_NPV_HPP_ +#include +#include #include +#include + +using std::chrono_literals::operator""ms; namespace npv { class NestPythonVis { public: explicit NestPythonVis(double* value) : value_(value) {} + ~NestPythonVis() { + if (thread_ != nullptr) { + thread_->join(); + } + } - std::string ValueString() const; + void Start() { + sleep_in_use_ = configured_sleep_; + thread_ = std::make_unique(&NestPythonVis::Run, this); + } + void Stop() { sleep_in_use_ = 0ms; } - void Run(); + std::string ValueString() const; private: + void PrintValue() const; std::string FormatValue() const; + bool IsRunning() const { return sleep_in_use_ != 0ms; } + void Run(); + void Sleep() { std::this_thread::sleep_for(sleep_in_use_); } + double* value_{nullptr}; + std::unique_ptr thread_{nullptr}; + std::chrono::duration sleep_in_use_{0ms}; + std::chrono::duration configured_sleep_{10ms}; }; } // namespace npv diff --git a/nest_python_vis/src/npv.cpp b/nest_python_vis/src/npv.cpp index 61ed8af..3928397 100644 --- a/nest_python_vis/src/npv.cpp +++ b/nest_python_vis/src/npv.cpp @@ -27,6 +27,17 @@ namespace npv { +void NestPythonVis::Run() { + while (IsRunning()) { + PrintValue(); + Sleep(); + } +} + +void NestPythonVis::PrintValue() const { + std::cout << ValueString() << std::endl; +} + std::string NestPythonVis::ValueString() const { return value_ == nullptr ? "nullptr" : FormatValue(); } @@ -37,6 +48,4 @@ std::string NestPythonVis::FormatValue() const { return sstr.str(); } -void NestPythonVis::Run() { std::cout << ValueString() << std::endl; } - } // namespace npv diff --git a/nest_python_vis/tests/src/test_npv.cpp b/nest_python_vis/tests/src/test_npv.cpp index 2dd34ab..e3be5dc 100644 --- a/nest_python_vis/tests/src/test_npv.cpp +++ b/nest_python_vis/tests/src/test_npv.cpp @@ -19,12 +19,19 @@ // limitations under the License. //------------------------------------------------------------------------------ +#include +#include +#include +#include + #include "catch/catch.hpp" #include "npv/npv.hpp" #include "test_utilities/cout_capture.hpp" +using std::chrono_literals::operator""ms; + SCENARIO("An npv object shall visualize the double it is bound to", "[npv][npv::NestPythonVis") { GIVEN("A double and A NestPythonVis object") { @@ -43,11 +50,18 @@ SCENARIO("An npv object shall visualize the double it is bound to", } } - WHEN("I run the visualization") { + WHEN("I run the visualization for 30 ms") { test_utilities::CoutCapture cout_capture; - vis.Run(); - THEN("I will find the string representation of value on cout") { - REQUIRE(cout_capture == "0\n"); + vis.Start(); + std::this_thread::sleep_for(30ms); + vis.Stop(); + THEN( + "I will find more than one linebreak in printed the string " + "representation") { + const std::string cout_string = cout_capture.ToString(); + auto num_linebreaks = + std::count(cout_string.begin(), cout_string.end(), '\n'); + REQUIRE(num_linebreaks > 1); } } } From 9cd762e87a57c53e5428192ab641b8776c7dd98a Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 15 Aug 2017 07:32:25 +0200 Subject: [PATCH 08/71] Rename to npv subdirectory --- CMakeLists.txt | 2 +- {nest_python_vis => npv}/CMakeLists.txt | 0 {nest_python_vis => npv}/include/npv/npv.hpp | 6 +++--- {nest_python_vis => npv}/src/npv.cpp | 0 {nest_python_vis => npv}/tests/CMakeLists.txt | 0 {nest_python_vis => npv}/tests/catch/LICENSE.txt | 0 {nest_python_vis => npv}/tests/catch/catch.hpp | 0 {nest_python_vis => npv}/tests/src/test_npv.cpp | 0 {nest_python_vis => npv}/tests/src/tests.cpp | 0 .../tests/test_utilities/cout_capture.hpp | 6 +++--- .../tests/test_utilities/tests/src/test_cout_capture.cpp | 0 11 files changed, 7 insertions(+), 7 deletions(-) rename {nest_python_vis => npv}/CMakeLists.txt (100%) rename {nest_python_vis => npv}/include/npv/npv.hpp (93%) rename {nest_python_vis => npv}/src/npv.cpp (100%) rename {nest_python_vis => npv}/tests/CMakeLists.txt (100%) rename {nest_python_vis => npv}/tests/catch/LICENSE.txt (100%) rename {nest_python_vis => npv}/tests/catch/catch.hpp (100%) rename {nest_python_vis => npv}/tests/src/test_npv.cpp (100%) rename {nest_python_vis => npv}/tests/src/tests.cpp (100%) rename {nest_python_vis => npv}/tests/test_utilities/cout_capture.hpp (90%) rename {nest_python_vis => npv}/tests/test_utilities/tests/src/test_cout_capture.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e69078..90931d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,4 +39,4 @@ include(GenerateExportHeader) include(WarningLevels) -add_subdirectory(nest_python_vis) +add_subdirectory(npv) diff --git a/nest_python_vis/CMakeLists.txt b/npv/CMakeLists.txt similarity index 100% rename from nest_python_vis/CMakeLists.txt rename to npv/CMakeLists.txt diff --git a/nest_python_vis/include/npv/npv.hpp b/npv/include/npv/npv.hpp similarity index 93% rename from nest_python_vis/include/npv/npv.hpp rename to npv/include/npv/npv.hpp index 36f6b3b..4e64128 100644 --- a/nest_python_vis/include/npv/npv.hpp +++ b/npv/include/npv/npv.hpp @@ -19,8 +19,8 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef NEST_PYTHON_VIS_INCLUDE_NPV_NPV_HPP_ -#define NEST_PYTHON_VIS_INCLUDE_NPV_NPV_HPP_ +#ifndef NPV_INCLUDE_NPV_NPV_HPP_ +#define NPV_INCLUDE_NPV_NPV_HPP_ #include #include @@ -63,4 +63,4 @@ class NestPythonVis { } // namespace npv -#endif // NEST_PYTHON_VIS_INCLUDE_NPV_NPV_HPP_ +#endif // NPV_INCLUDE_NPV_NPV_HPP_ diff --git a/nest_python_vis/src/npv.cpp b/npv/src/npv.cpp similarity index 100% rename from nest_python_vis/src/npv.cpp rename to npv/src/npv.cpp diff --git a/nest_python_vis/tests/CMakeLists.txt b/npv/tests/CMakeLists.txt similarity index 100% rename from nest_python_vis/tests/CMakeLists.txt rename to npv/tests/CMakeLists.txt diff --git a/nest_python_vis/tests/catch/LICENSE.txt b/npv/tests/catch/LICENSE.txt similarity index 100% rename from nest_python_vis/tests/catch/LICENSE.txt rename to npv/tests/catch/LICENSE.txt diff --git a/nest_python_vis/tests/catch/catch.hpp b/npv/tests/catch/catch.hpp similarity index 100% rename from nest_python_vis/tests/catch/catch.hpp rename to npv/tests/catch/catch.hpp diff --git a/nest_python_vis/tests/src/test_npv.cpp b/npv/tests/src/test_npv.cpp similarity index 100% rename from nest_python_vis/tests/src/test_npv.cpp rename to npv/tests/src/test_npv.cpp diff --git a/nest_python_vis/tests/src/tests.cpp b/npv/tests/src/tests.cpp similarity index 100% rename from nest_python_vis/tests/src/tests.cpp rename to npv/tests/src/tests.cpp diff --git a/nest_python_vis/tests/test_utilities/cout_capture.hpp b/npv/tests/test_utilities/cout_capture.hpp similarity index 90% rename from nest_python_vis/tests/test_utilities/cout_capture.hpp rename to npv/tests/test_utilities/cout_capture.hpp index 0a91d97..a52a9cf 100644 --- a/nest_python_vis/tests/test_utilities/cout_capture.hpp +++ b/npv/tests/test_utilities/cout_capture.hpp @@ -19,8 +19,8 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef NEST_PYTHON_VIS_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ -#define NEST_PYTHON_VIS_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ +#ifndef NPV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ +#define NPV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ #include #include @@ -59,4 +59,4 @@ struct StringMaker { } // namespace Catch -#endif // NEST_PYTHON_VIS_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ +#endif // NPV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ diff --git a/nest_python_vis/tests/test_utilities/tests/src/test_cout_capture.cpp b/npv/tests/test_utilities/tests/src/test_cout_capture.cpp similarity index 100% rename from nest_python_vis/tests/test_utilities/tests/src/test_cout_capture.cpp rename to npv/tests/test_utilities/tests/src/test_cout_capture.cpp From bc4128e9afbcfa9151399d66155852b9ecda9d86 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 15 Aug 2017 15:53:19 +0200 Subject: [PATCH 09/71] Update license of cpplint.cmake to BSD --- cmake/cpplint.cmake | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmake/cpplint.cmake b/cmake/cpplint.cmake index 0e214fe..87ddd6a 100644 --- a/cmake/cpplint.cmake +++ b/cmake/cpplint.cmake @@ -1,17 +1,16 @@ #------------------------------------------------------------------------------- -# Project Phoenix +# nest python vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. #------------------------------------------------------------------------------- -# License -# only for this file +# License # -# Licensed under the 3-Clause BSD License (the "License"); +# Licensed 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 # -# https://opensource.org/licenses/BSD-3-Clause +# 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, From adbe4c50d39bebd861b97f92ea64559bb3ce6054 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 15 Aug 2017 15:53:38 +0200 Subject: [PATCH 10/71] Add cmake/py.test.cmake --- cmake/py.test.cmake | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 cmake/py.test.cmake diff --git a/cmake/py.test.cmake b/cmake/py.test.cmake new file mode 100644 index 0000000..9cafb32 --- /dev/null +++ b/cmake/py.test.cmake @@ -0,0 +1,54 @@ +#------------------------------------------------------------------------------- +# nest python vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed 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(FindPythonInterp) +if(NOT PYTHON_EXECUTABLE) + message(SEND_ERROR + " ERROR: Could not find any python interpreter. + Having a python interpreter is a mandatory requirement for cpplint. + CMake will not generate the project without it. ") +endif() + +find_file(PY_TEST_COMMAND py.test + PATHS $ENV{PATH} $ENV{PY_TEST_DIR} +) +if(NOT PY_TEST_COMMAND) + message(SEND_ERROR + " ERROR: Could not find py.test. + Having py.test is a mandatory requirement. + CMake will not generate the project without it. + Add its location to the environments variables PATH or CPPLINT_DIR.") +endif() + +function(ADD_TEST_PY_TEST) + set(options ) + set(oneValueArgs NAME) + set(multiValueArgs ) + cmake_parse_arguments(ADD_TEST_PY_TEST + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + + add_test(NAME "${ADD_TEST_PY_TEST_NAME}" + COMMAND ${PYTHON_EXECUTABLE} -B ${PY_TEST_COMMAND} -p no:cacheprovider + ${ADD_TEST_PY_TEST_UNPARSED_ARGUMENTS} + ) +endfunction() From 3852fcc4c326b0b522dce6f01e35fea4bfea3341 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 15 Aug 2017 15:54:57 +0200 Subject: [PATCH 11/71] Add pynpv and first dummy test --- CMakeLists.txt | 3 +++ pynpv/CMakeLists.txt | 22 ++++++++++++++++++++++ pynpv/tests/CMakeLists.txt | 26 ++++++++++++++++++++++++++ pynpv/tests/src/test_pynpv.py | 23 +++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 pynpv/CMakeLists.txt create mode 100644 pynpv/tests/CMakeLists.txt create mode 100644 pynpv/tests/src/test_pynpv.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 90931d4..ef55aa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,9 @@ enable_testing() include(GenerateExportHeader) +include(py.test) + include(WarningLevels) add_subdirectory(npv) +add_subdirectory(pynpv) diff --git a/pynpv/CMakeLists.txt b/pynpv/CMakeLists.txt new file mode 100644 index 0000000..09be9dc --- /dev/null +++ b/pynpv/CMakeLists.txt @@ -0,0 +1,22 @@ +#------------------------------------------------------------------------------- +# nest python vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed 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_subdirectory(tests) diff --git a/pynpv/tests/CMakeLists.txt b/pynpv/tests/CMakeLists.txt new file mode 100644 index 0000000..59c3dd6 --- /dev/null +++ b/pynpv/tests/CMakeLists.txt @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------- +# nest python vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed 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. +#------------------------------------------------------------------------------- + +file(GLOB PYNPV_TEST_SOURCES src/*.py) + +add_test_py_test(NAME "pynpv" + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/pynpv/tests/src/test_pynpv.py b/pynpv/tests/src/test_pynpv.py new file mode 100644 index 0000000..59d75bb --- /dev/null +++ b/pynpv/tests/src/test_pynpv.py @@ -0,0 +1,23 @@ +#------------------------------------------------------------------------------- +# nest python vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed 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. +#------------------------------------------------------------------------------- + +def test_pypvt(): + assert True From bff982f04e6e8c861b13c21869638119b9f12671 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 15 Aug 2017 16:02:06 +0200 Subject: [PATCH 12/71] Add a test to pynpv to demonstrate cout capturing --- pynpv/tests/src/test_pynpv.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pynpv/tests/src/test_pynpv.py b/pynpv/tests/src/test_pynpv.py index 59d75bb..ce70e4d 100644 --- a/pynpv/tests/src/test_pynpv.py +++ b/pynpv/tests/src/test_pynpv.py @@ -19,5 +19,17 @@ # limitations under the License. #------------------------------------------------------------------------------- +import sys + def test_pypvt(): assert True + +def test_cout_capture(capsys): + print("hello") + sys.stderr.write("world\n") + out, err = capsys.readouterr() + assert out == "hello\n" + assert err == "world\n" + print ("next") + out, err = capsys.readouterr() + assert out == "next\n" From 2422f348b2a3c505ceed8e34d6472cff7f3b8d61 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 16 Aug 2017 06:59:01 +0200 Subject: [PATCH 13/71] Add parameter for setting PYTHONPATH in py.test.cmake --- cmake/py.test.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/py.test.cmake b/cmake/py.test.cmake index 9cafb32..e07be20 100644 --- a/cmake/py.test.cmake +++ b/cmake/py.test.cmake @@ -42,7 +42,7 @@ endif() function(ADD_TEST_PY_TEST) set(options ) - set(oneValueArgs NAME) + set(oneValueArgs NAME PYTHONPATH) set(multiValueArgs ) cmake_parse_arguments(ADD_TEST_PY_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) @@ -50,5 +50,9 @@ function(ADD_TEST_PY_TEST) add_test(NAME "${ADD_TEST_PY_TEST_NAME}" COMMAND ${PYTHON_EXECUTABLE} -B ${PY_TEST_COMMAND} -p no:cacheprovider ${ADD_TEST_PY_TEST_UNPARSED_ARGUMENTS} + ) + set_property(TEST ${ADD_TEST_PY_TEST_NAME} PROPERTY ENVIRONMENT + "PYTHONPATH=${ADD_TEST_PY_TEST_PYTHONPATH}:$PYTHONPATH" + ) endfunction() From 294b5fa3df8a53d078c9e9c0b0d7a158fcd4ea92 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 16 Aug 2017 07:01:23 +0200 Subject: [PATCH 14/71] Add Python module pynpv --- npv/include/npv/npv.hpp | 2 ++ npv/src/npv.cpp | 2 ++ pynpv/CMakeLists.txt | 17 +++++++++++++++++ pynpv/src/npv.cpp | 29 +++++++++++++++++++++++++++++ pynpv/tests/CMakeLists.txt | 3 ++- pynpv/tests/src/test_pynpv.py | 5 +++++ 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 pynpv/src/npv.cpp diff --git a/npv/include/npv/npv.hpp b/npv/include/npv/npv.hpp index 4e64128..f31b285 100644 --- a/npv/include/npv/npv.hpp +++ b/npv/include/npv/npv.hpp @@ -61,6 +61,8 @@ class NestPythonVis { std::chrono::duration configured_sleep_{10ms}; }; +char const* Greet(); + } // namespace npv #endif // NPV_INCLUDE_NPV_NPV_HPP_ diff --git a/npv/src/npv.cpp b/npv/src/npv.cpp index 3928397..02347e8 100644 --- a/npv/src/npv.cpp +++ b/npv/src/npv.cpp @@ -48,4 +48,6 @@ std::string NestPythonVis::FormatValue() const { return sstr.str(); } +char const* Greet() { return "G'day!"; } + } // namespace npv diff --git a/pynpv/CMakeLists.txt b/pynpv/CMakeLists.txt index 09be9dc..00274ff 100644 --- a/pynpv/CMakeLists.txt +++ b/pynpv/CMakeLists.txt @@ -19,4 +19,21 @@ # limitations under the License. #------------------------------------------------------------------------------- +file(GLOB PYNPV_SOURCES src/*.cpp) + +find_package(Boost REQUIRED COMPONENTS python) +find_package(PythonInterp) +find_package(PythonLibs) + +python_add_module(pynpv + ${PYNPV_SOURCES} +) +target_link_libraries(pynpv npv) + +target_include_directories(pynpv PRIVATE ${Boost_INCLUDE_DIRS}) +target_link_libraries(pynpv ${Boost_LIBRARIES}) + +target_include_directories(pynpv PRIVATE ${PYTHON_INCLUDE_DIRS}) +target_link_libraries(pynpv ${PYTHON_LIBRARIES}) + add_subdirectory(tests) diff --git a/pynpv/src/npv.cpp b/pynpv/src/npv.cpp new file mode 100644 index 0000000..42970ab --- /dev/null +++ b/pynpv/src/npv.cpp @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +// nest python vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "boost/python.hpp" + +#include "npv/npv.hpp" + +BOOST_PYTHON_MODULE(pynpv) { + using namespace boost::python; + def("Greet", npv::Greet); +} diff --git a/pynpv/tests/CMakeLists.txt b/pynpv/tests/CMakeLists.txt index 59c3dd6..a4c042d 100644 --- a/pynpv/tests/CMakeLists.txt +++ b/pynpv/tests/CMakeLists.txt @@ -21,6 +21,7 @@ file(GLOB PYNPV_TEST_SOURCES src/*.py) -add_test_py_test(NAME "pynpv" +add_test_py_test(NAME test_pynpv ${CMAKE_CURRENT_SOURCE_DIR} + PYTHONPATH $ ) diff --git a/pynpv/tests/src/test_pynpv.py b/pynpv/tests/src/test_pynpv.py index ce70e4d..db9a6c6 100644 --- a/pynpv/tests/src/test_pynpv.py +++ b/pynpv/tests/src/test_pynpv.py @@ -21,6 +21,8 @@ import sys +import pynpv + def test_pypvt(): assert True @@ -33,3 +35,6 @@ def test_cout_capture(capsys): print ("next") out, err = capsys.readouterr() assert out == "next\n" + +def test_pynpv_greet(): + assert pynpv.Greet() == "G'day!" From 41d267bf3f9497a81f843cda5e6047bc7455cb6d Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 16 Aug 2017 07:26:12 +0200 Subject: [PATCH 15/71] Add warning levels, cpplint to pynpv; apply fixes --- cmake/suppress_warnings.hpp.in | 9 +++++---- pynpv/CMakeLists.txt | 8 ++++++++ pynpv/src/npv.cpp | 16 ++++++++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/cmake/suppress_warnings.hpp.in b/cmake/suppress_warnings.hpp.in index ff289aa..ed997f4 100644 --- a/cmake/suppress_warnings.hpp.in +++ b/cmake/suppress_warnings.hpp.in @@ -23,10 +23,11 @@ #define PROJECT_PHOENIX_SUPPRESS_WARNINGS_ #if defined __clang__ -#define SUPPRESS_WARNINGS_BEGIN \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Wall\"") \ - _Pragma("clang diagnostic ignored \"-Wextra\"") +#define SUPPRESS_WARNINGS_BEGIN \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wall\"") \ + _Pragma("clang diagnostic ignored \"-Wextra\"") \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat-pedantic\"") #define SUPPRESS_WARNINGS_END _Pragma("clang diagnostic pop") #elif defined _MSC_VER diff --git a/pynpv/CMakeLists.txt b/pynpv/CMakeLists.txt index 00274ff..c05cc92 100644 --- a/pynpv/CMakeLists.txt +++ b/pynpv/CMakeLists.txt @@ -36,4 +36,12 @@ target_link_libraries(pynpv ${Boost_LIBRARIES}) target_include_directories(pynpv PRIVATE ${PYTHON_INCLUDE_DIRS}) target_link_libraries(pynpv ${PYTHON_LIBRARIES}) +set_warning_levels_RWTH(pynpv + SUPPRESS_WARNINGS_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/pynpv/suppress_warnings.hpp +) + +add_test_cpplint(NAME "pynpv--cpplint" + ${PYNPV_SOURCES} +) + add_subdirectory(tests) diff --git a/pynpv/src/npv.cpp b/pynpv/src/npv.cpp index 42970ab..0048418 100644 --- a/pynpv/src/npv.cpp +++ b/pynpv/src/npv.cpp @@ -19,11 +19,19 @@ // limitations under the License. //------------------------------------------------------------------------------ +SUPPRESS_WARNINGS_BEGIN #include "boost/python.hpp" +SUPPRESS_WARNINGS_END #include "npv/npv.hpp" -BOOST_PYTHON_MODULE(pynpv) { - using namespace boost::python; - def("Greet", npv::Greet); -} +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-prototypes" +#endif + +BOOST_PYTHON_MODULE(pynpv) { boost::python::def("Greet", npv::Greet); } + +#if defined __clang__ +#pragma clang diagnostic pop +#endif From a61972419ea5985e2675d329f5769c9c597c2d84 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 16 Aug 2017 08:06:35 +0200 Subject: [PATCH 16/71] Expose NestPythonVis and NestPythonVis::ValueString --- npv/include/npv/npv.hpp | 3 +++ pynpv/src/npv.cpp | 12 +++++++++++- pynpv/tests/src/test_pynpv.py | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/npv/include/npv/npv.hpp b/npv/include/npv/npv.hpp index f31b285..b1b641f 100644 --- a/npv/include/npv/npv.hpp +++ b/npv/include/npv/npv.hpp @@ -34,11 +34,14 @@ namespace npv { class NestPythonVis { public: explicit NestPythonVis(double* value) : value_(value) {} + explicit NestPythonVis(std::size_t ptr_to_value) + : NestPythonVis(reinterpret_cast(ptr_to_value)) {} ~NestPythonVis() { if (thread_ != nullptr) { thread_->join(); } } + NestPythonVis(const NestPythonVis&) = delete; void Start() { sleep_in_use_ = configured_sleep_; diff --git a/pynpv/src/npv.cpp b/pynpv/src/npv.cpp index 0048418..f9004e9 100644 --- a/pynpv/src/npv.cpp +++ b/pynpv/src/npv.cpp @@ -30,7 +30,17 @@ SUPPRESS_WARNINGS_END #pragma clang diagnostic ignored "-Wmissing-prototypes" #endif -BOOST_PYTHON_MODULE(pynpv) { boost::python::def("Greet", npv::Greet); } +BOOST_PYTHON_MODULE(pynpv) { + using boost::python::class_; + using boost::python::def; + using boost::python::init; + + def("Greet", npv::Greet); + + class_("NestPythonVis", + init()) + .def("ValueString", &npv::NestPythonVis::ValueString); +} #if defined __clang__ #pragma clang diagnostic pop diff --git a/pynpv/tests/src/test_pynpv.py b/pynpv/tests/src/test_pynpv.py index db9a6c6..a0fa860 100644 --- a/pynpv/tests/src/test_pynpv.py +++ b/pynpv/tests/src/test_pynpv.py @@ -19,6 +19,7 @@ # limitations under the License. #------------------------------------------------------------------------------- +import ctypes import sys import pynpv @@ -38,3 +39,9 @@ def test_cout_capture(capsys): def test_pynpv_greet(): assert pynpv.Greet() == "G'day!" + +def test_pynpv_npv_ValueString(): + d = ctypes.c_double(42.0); + ptr = ctypes.c_void_p.from_buffer(ctypes.pointer(d)).value + v = pynpv.NestPythonVis(ptr); + assert v.ValueString() == "42" From 2f89940feeb4d6582ec61c3bc62e0655a3fc9af7 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 16 Aug 2017 23:16:41 +0200 Subject: [PATCH 17/71] Add python module exposing CoutCapture --- CMakeLists.txt | 1 + pytest_utilities/CMakeLists.txt | 44 ++++++++++++++++++ pytest_utilities/src/cout_capture.cpp | 65 +++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 pytest_utilities/CMakeLists.txt create mode 100644 pytest_utilities/src/cout_capture.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ef55aa0..38fe7ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,3 +43,4 @@ include(WarningLevels) add_subdirectory(npv) add_subdirectory(pynpv) +add_subdirectory(pytest_utilities) diff --git a/pytest_utilities/CMakeLists.txt b/pytest_utilities/CMakeLists.txt new file mode 100644 index 0000000..2d65de4 --- /dev/null +++ b/pytest_utilities/CMakeLists.txt @@ -0,0 +1,44 @@ +#------------------------------------------------------------------------------- +# nest python vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed 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. +#------------------------------------------------------------------------------- + +file(GLOB PYTEST_UTILITIES_SOURCES src/*.cpp) + +find_package(Boost REQUIRED COMPONENTS python) +find_package(PythonInterp) +find_package(PythonLibs) + +python_add_module(pytest_utilities + ${PYTEST_UTILITIES_SOURCES} +) + +target_include_directories(pytest_utilities PRIVATE ${Boost_INCLUDE_DIRS}) +target_link_libraries(pytest_utilities ${Boost_LIBRARIES}) + +target_include_directories(pytest_utilities PRIVATE ${PYTHON_INCLUDE_DIRS}) +target_link_libraries(pytest_utilities ${PYTHON_LIBRARIES}) + +set_warning_levels_RWTH(pytest_utilities + SUPPRESS_WARNINGS_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/pytest_utilities/suppress_warnings.hpp +) + +add_test_cpplint(NAME "pytest_utilities--cpplint" + ${PYTEST_UTILITIES_SOURCES} +) diff --git a/pytest_utilities/src/cout_capture.cpp b/pytest_utilities/src/cout_capture.cpp new file mode 100644 index 0000000..0d6f77f --- /dev/null +++ b/pytest_utilities/src/cout_capture.cpp @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// nest python vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 + +SUPPRESS_WARNINGS_BEGIN +#include "boost/python.hpp" +SUPPRESS_WARNINGS_END + +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-prototypes" +#endif + +namespace test_utilities { + +class CoutCapture { + public: + CoutCapture() { original_rdbuf_ = std::cout.rdbuf(cout_stream_.rdbuf()); } + ~CoutCapture() { std::cout.rdbuf(original_rdbuf_); } + + bool operator==(const std::string& other) const { + return cout_stream_.str() == other; + } + + std::string ToString() const { return "\"" + cout_stream_.str() + "\""; } + + private: + std::streambuf* original_rdbuf_; + std::stringstream cout_stream_; +}; + +} // namespace test_utilities + +BOOST_PYTHON_MODULE(pytest_utilities) { + using boost::python::class_; + using boost::python::def; + using boost::python::init; + + class_("CoutCapture") + .def("ToString", &test_utilities::CoutCapture::ToString); +} + +#if defined __clang__ +#pragma clang diagnostic pop +#endif From 2a80348fb0619f46201532ab6d77c41f2d702c6f Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 16 Aug 2017 23:17:04 +0200 Subject: [PATCH 18/71] Exposing Start/Stop from NestPythonVis --- pynpv/src/npv.cpp | 4 +++- pynpv/tests/CMakeLists.txt | 2 +- pynpv/tests/src/test_pynpv.py | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pynpv/src/npv.cpp b/pynpv/src/npv.cpp index f9004e9..d59ad87 100644 --- a/pynpv/src/npv.cpp +++ b/pynpv/src/npv.cpp @@ -39,7 +39,9 @@ BOOST_PYTHON_MODULE(pynpv) { class_("NestPythonVis", init()) - .def("ValueString", &npv::NestPythonVis::ValueString); + .def("ValueString", &npv::NestPythonVis::ValueString) + .def("Start", &npv::NestPythonVis::Start) + .def("Stop", &npv::NestPythonVis::Stop); } #if defined __clang__ diff --git a/pynpv/tests/CMakeLists.txt b/pynpv/tests/CMakeLists.txt index a4c042d..7b62c46 100644 --- a/pynpv/tests/CMakeLists.txt +++ b/pynpv/tests/CMakeLists.txt @@ -23,5 +23,5 @@ file(GLOB PYNPV_TEST_SOURCES src/*.py) add_test_py_test(NAME test_pynpv ${CMAKE_CURRENT_SOURCE_DIR} - PYTHONPATH $ + PYTHONPATH "$:$" ) diff --git a/pynpv/tests/src/test_pynpv.py b/pynpv/tests/src/test_pynpv.py index a0fa860..221a6f8 100644 --- a/pynpv/tests/src/test_pynpv.py +++ b/pynpv/tests/src/test_pynpv.py @@ -21,9 +21,12 @@ import ctypes import sys +import time import pynpv +import pytest_utilities + def test_pypvt(): assert True @@ -45,3 +48,16 @@ def test_pynpv_npv_ValueString(): ptr = ctypes.c_void_p.from_buffer(ctypes.pointer(d)).value v = pynpv.NestPythonVis(ptr); assert v.ValueString() == "42" + +def test_pynpv_npv_StartStop(): + d = ctypes.c_double(42.0); + ptr = ctypes.c_void_p.from_buffer(ctypes.pointer(d)).value + v = pynpv.NestPythonVis(ptr); + + c = pytest_utilities.CoutCapture() + + v.Start() + time.sleep(0.03) + v.Stop() + + assert len(c.ToString().split('\n')) > 2 From 8c606f97145f5acac1b4b8edca16c395f81701e5 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 22 Aug 2017 17:15:50 +0200 Subject: [PATCH 19/71] Successfully include conduit --- CMakeLists.txt | 4 ++ cmake/FindConduit.cmake | 90 +++++++++++++++++++++++++++++++++++++++++ npv/CMakeLists.txt | 5 ++- 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 cmake/FindConduit.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 38fe7ef..cc846df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,10 @@ include(py.test) include(WarningLevels) +find_package(conduit) +set_target_properties(conduit + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CONDUIT_INCLUDE_DIRS}/..") + add_subdirectory(npv) add_subdirectory(pynpv) add_subdirectory(pytest_utilities) diff --git a/cmake/FindConduit.cmake b/cmake/FindConduit.cmake new file mode 100644 index 0000000..362f318 --- /dev/null +++ b/cmake/FindConduit.cmake @@ -0,0 +1,90 @@ +############################################################################### +# Copyright (c) 2014-2017, Lawrence Livermore National Security, LLC. +# +# Produced at the Lawrence Livermore National Laboratory +# +# LLNL-CODE-666778 +# +# All rights reserved. +# +# This file is part of Conduit. +# +# For details, see https://lc.llnl.gov/conduit/. +# +# Please also read conduit/LICENSE +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the disclaimer below. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the disclaimer (as noted below) in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the LLNS/LLNL nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, +# LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################### +# +# Setup Conduit +# +############################################################################### +# +# Expects CONDUIT_DIR to point to a Conduit installations. +# +# This file defines the following CMake variables: +# CONDUIT_FOUND - If Conduit was found +# CONDUIT_INCLUDE_DIRS - The Conduit include directories +# +# If found, the conduit CMake targets will also be imported. +# The main conduit library targets are: +# conduit +# conduit_relay +# conduit_relay_mpi (if conduit was built with mpi support) +# conduit_blueprint +# +############################################################################### + +############################################################################### +# Check for CONDUIT_DIR +############################################################################### +if(NOT CONDUIT_DIR) + MESSAGE(FATAL_ERROR "Could not find Conduit. Conduit requires explicit CONDUIT_DIR.") +endif() + +if(NOT EXISTS ${CONDUIT_DIR}/lib/cmake/conduit.cmake) + MESSAGE(FATAL_ERROR "Could not find Conduit CMake include file (${CONDUIT_DIR}/lib/cmake/conduit.cmake)") +endif() + +############################################################################### +# Import Conduit's CMake targets +############################################################################### +include(${CONDUIT_DIR}/lib/cmake/conduit.cmake) + +############################################################################### +# Set remaning CMake variables +############################################################################### +# we found Conduit +set(CONDUIT_FOUND TRUE) +# provide location of the headers in CONDUIT_INCLUDE_DIRS +set(CONDUIT_INCLUDE_DIRS ${CONDUIT_DIR}/include/conduit) + + + + diff --git a/npv/CMakeLists.txt b/npv/CMakeLists.txt index 6b4ba38..d8fee85 100644 --- a/npv/CMakeLists.txt +++ b/npv/CMakeLists.txt @@ -31,7 +31,10 @@ add_library(npv target_include_directories(npv PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include PUBLIC ${CMAKE_CURRENT_BINARY_DIR} -) + ) +target_link_libraries(npv + conduit + ) generate_export_header(npv EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/include/npv/export.hpp From d267fc5c528d96971de592ff621eb39f0a56b310 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 22 Aug 2017 17:18:35 +0200 Subject: [PATCH 20/71] Fix/silence gcc-5 compiler warnings --- cmake/WarningLevels.cmake | 1 - npv/include/npv/npv.hpp | 3 ++- pynpv/src/npv.cpp | 1 + pytest_utilities/src/cout_capture.cpp | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/WarningLevels.cmake b/cmake/WarningLevels.cmake index 4df9c09..c52cdd6 100644 --- a/cmake/WarningLevels.cmake +++ b/cmake/WarningLevels.cmake @@ -40,7 +40,6 @@ set(WARNING_LEVELS_RWTH_GCC -Wmissing-braces -pedantic -pedantic-errors - -Wno-c++98-compat ) set(WARNING_LEVELS_RWTH_MSVC diff --git a/npv/include/npv/npv.hpp b/npv/include/npv/npv.hpp index b1b641f..03dd280 100644 --- a/npv/include/npv/npv.hpp +++ b/npv/include/npv/npv.hpp @@ -27,7 +27,8 @@ #include #include -using std::chrono_literals::operator""ms; +// gcc-5 does not accept using std::chrono_literals::operator""ms; +using namespace std::literals::chrono_literals; // NOLINT namespace npv { diff --git a/pynpv/src/npv.cpp b/pynpv/src/npv.cpp index d59ad87..7f2760e 100644 --- a/pynpv/src/npv.cpp +++ b/pynpv/src/npv.cpp @@ -20,6 +20,7 @@ //------------------------------------------------------------------------------ SUPPRESS_WARNINGS_BEGIN +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #include "boost/python.hpp" SUPPRESS_WARNINGS_END diff --git a/pytest_utilities/src/cout_capture.cpp b/pytest_utilities/src/cout_capture.cpp index 0d6f77f..cdceb05 100644 --- a/pytest_utilities/src/cout_capture.cpp +++ b/pytest_utilities/src/cout_capture.cpp @@ -23,6 +23,7 @@ #include SUPPRESS_WARNINGS_BEGIN +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #include "boost/python.hpp" SUPPRESS_WARNINGS_END From 0e911952a34ba15d043d753424f58cac04fe3859 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 22 Aug 2017 17:19:08 +0200 Subject: [PATCH 21/71] Access conduit node, read membrane potential, print --- npv/include/npv/npv.hpp | 13 ++++++++++--- npv/src/npv.cpp | 12 +++++++++++- npv/tests/src/test_npv.cpp | 21 +++++++++++++++++---- pynpv/CMakeLists.txt | 13 ++++++++----- pynpv/src/npv.cpp | 4 ++-- pynpv/tests/src/test_pynpv.py | 4 ++-- 6 files changed, 50 insertions(+), 17 deletions(-) diff --git a/npv/include/npv/npv.hpp b/npv/include/npv/npv.hpp index 03dd280..b40962b 100644 --- a/npv/include/npv/npv.hpp +++ b/npv/include/npv/npv.hpp @@ -27,6 +27,8 @@ #include #include +#include "conduit/conduit.hpp" + // gcc-5 does not accept using std::chrono_literals::operator""ms; using namespace std::literals::chrono_literals; // NOLINT @@ -34,9 +36,11 @@ namespace npv { class NestPythonVis { public: - explicit NestPythonVis(double* value) : value_(value) {} - explicit NestPythonVis(std::size_t ptr_to_value) - : NestPythonVis(reinterpret_cast(ptr_to_value)) {} + explicit NestPythonVis(double* value, conduit::Node* node = nullptr) + : value_(value), node_(node) {} + explicit NestPythonVis(std::size_t ptr_to_value, std::size_t ptr_to_node) + : NestPythonVis(reinterpret_cast(ptr_to_value), + reinterpret_cast(ptr_to_node)) {} ~NestPythonVis() { if (thread_ != nullptr) { thread_->join(); @@ -51,15 +55,18 @@ class NestPythonVis { void Stop() { sleep_in_use_ = 0ms; } std::string ValueString() const; + std::string NodeString() const; private: void PrintValue() const; std::string FormatValue() const; + std::string FormatNode() const; bool IsRunning() const { return sleep_in_use_ != 0ms; } void Run(); void Sleep() { std::this_thread::sleep_for(sleep_in_use_); } double* value_{nullptr}; + conduit::Node* node_{nullptr}; std::unique_ptr thread_{nullptr}; std::chrono::duration sleep_in_use_{0ms}; std::chrono::duration configured_sleep_{10ms}; diff --git a/npv/src/npv.cpp b/npv/src/npv.cpp index 02347e8..2ca69f9 100644 --- a/npv/src/npv.cpp +++ b/npv/src/npv.cpp @@ -35,19 +35,29 @@ void NestPythonVis::Run() { } void NestPythonVis::PrintValue() const { - std::cout << ValueString() << std::endl; + std::cout << ValueString() << " " << NodeString() << std::endl; } std::string NestPythonVis::ValueString() const { return value_ == nullptr ? "nullptr" : FormatValue(); } +std::string NestPythonVis::NodeString() const { + return node_ == nullptr ? "nullptr" : FormatNode(); +} + std::string NestPythonVis::FormatValue() const { std::ostringstream sstr; sstr << *value_; return sstr.str(); } +std::string NestPythonVis::FormatNode() const { + std::ostringstream sstr; + sstr << (*node_)["V_m"].as_double(); + return sstr.str(); +} + char const* Greet() { return "G'day!"; } } // namespace npv diff --git a/npv/tests/src/test_npv.cpp b/npv/tests/src/test_npv.cpp index e3be5dc..19204a5 100644 --- a/npv/tests/src/test_npv.cpp +++ b/npv/tests/src/test_npv.cpp @@ -26,27 +26,40 @@ #include "catch/catch.hpp" +#include "conduit/conduit.hpp" + #include "npv/npv.hpp" #include "test_utilities/cout_capture.hpp" -using std::chrono_literals::operator""ms; +// gcc-5 does not accept using std::chrono_literals::operator""ms; +using namespace std::literals::chrono_literals; // NOLINT SCENARIO("An npv object shall visualize the double it is bound to", "[npv][npv::NestPythonVis") { - GIVEN("A double and A NestPythonVis object") { + GIVEN( + "A double, a membrane potenial in a conduit node and A NestPythonVis " + "object") { double value = 0.0; - npv::NestPythonVis vis(&value); + conduit::Node node; + node["V_m"] = 0.0; + npv::NestPythonVis vis(&value, &node); WHEN("I ask for a string representing the value") { auto ret_val = vis.ValueString(); - THEN("it shall represent the bound value.") { REQUIRE(ret_val == "0"); } + auto ret_node = vis.NodeString(); + THEN("it shall represent the bound value.") { + REQUIRE(ret_val == "0"); + REQUIRE(ret_node == "0"); + } } WHEN("the bound value is changed by some external code") { value = 42.0; + node["V_m"] = 42.0; THEN("its string representation shall be updated accordingly.") { REQUIRE(vis.ValueString() == "42"); + REQUIRE(vis.NodeString() == "42"); } } diff --git a/pynpv/CMakeLists.txt b/pynpv/CMakeLists.txt index c05cc92..a20be62 100644 --- a/pynpv/CMakeLists.txt +++ b/pynpv/CMakeLists.txt @@ -30,11 +30,14 @@ python_add_module(pynpv ) target_link_libraries(pynpv npv) -target_include_directories(pynpv PRIVATE ${Boost_INCLUDE_DIRS}) -target_link_libraries(pynpv ${Boost_LIBRARIES}) - -target_include_directories(pynpv PRIVATE ${PYTHON_INCLUDE_DIRS}) -target_link_libraries(pynpv ${PYTHON_LIBRARIES}) +target_include_directories(pynpv + PRIVATE ${Boost_INCLUDE_DIRS} + PRIVATE ${PYTHON_INCLUDE_DIRS} + ) +target_link_libraries(pynpv + ${Boost_LIBRARIES} + ${PYTHON_LIBRARIES} + ) set_warning_levels_RWTH(pynpv SUPPRESS_WARNINGS_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/pynpv/suppress_warnings.hpp diff --git a/pynpv/src/npv.cpp b/pynpv/src/npv.cpp index 7f2760e..a59e3f7 100644 --- a/pynpv/src/npv.cpp +++ b/pynpv/src/npv.cpp @@ -38,8 +38,8 @@ BOOST_PYTHON_MODULE(pynpv) { def("Greet", npv::Greet); - class_("NestPythonVis", - init()) + class_( + "NestPythonVis", init()) .def("ValueString", &npv::NestPythonVis::ValueString) .def("Start", &npv::NestPythonVis::Start) .def("Stop", &npv::NestPythonVis::Stop); diff --git a/pynpv/tests/src/test_pynpv.py b/pynpv/tests/src/test_pynpv.py index 221a6f8..f16f665 100644 --- a/pynpv/tests/src/test_pynpv.py +++ b/pynpv/tests/src/test_pynpv.py @@ -46,13 +46,13 @@ def test_pynpv_greet(): def test_pynpv_npv_ValueString(): d = ctypes.c_double(42.0); ptr = ctypes.c_void_p.from_buffer(ctypes.pointer(d)).value - v = pynpv.NestPythonVis(ptr); + v = pynpv.NestPythonVis(ptr, 0); assert v.ValueString() == "42" def test_pynpv_npv_StartStop(): d = ctypes.c_double(42.0); ptr = ctypes.c_void_p.from_buffer(ctypes.pointer(d)).value - v = pynpv.NestPythonVis(ptr); + v = pynpv.NestPythonVis(ptr, 0); c = pytest_utilities.CoutCapture() From 599e38b51cba6f17f49580707c611d1373d96d0e Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 23 Aug 2017 07:05:33 +0200 Subject: [PATCH 22/71] Remove ptr to double from npv, clean up. --- npv/include/npv/npv.hpp | 35 +++++++++++++++++++---------------- npv/src/npv.cpp | 16 +++------------- npv/tests/src/test_npv.cpp | 16 +++++----------- pynpv/src/npv.cpp | 6 +++--- 4 files changed, 30 insertions(+), 43 deletions(-) diff --git a/npv/include/npv/npv.hpp b/npv/include/npv/npv.hpp index b40962b..0ec9a34 100644 --- a/npv/include/npv/npv.hpp +++ b/npv/include/npv/npv.hpp @@ -36,36 +36,39 @@ namespace npv { class NestPythonVis { public: - explicit NestPythonVis(double* value, conduit::Node* node = nullptr) - : value_(value), node_(node) {} - explicit NestPythonVis(std::size_t ptr_to_value, std::size_t ptr_to_node) - : NestPythonVis(reinterpret_cast(ptr_to_value), - reinterpret_cast(ptr_to_node)) {} - ~NestPythonVis() { - if (thread_ != nullptr) { - thread_->join(); - } - } + explicit NestPythonVis(conduit::Node* node = nullptr) : node_(node) {} + explicit NestPythonVis(std::size_t ptr_to_node) + : NestPythonVis(reinterpret_cast(ptr_to_node)) {} + ~NestPythonVis() { JoinAndDeleteThread(); } NestPythonVis(const NestPythonVis&) = delete; void Start() { sleep_in_use_ = configured_sleep_; - thread_ = std::make_unique(&NestPythonVis::Run, this); + SpawnThread(); + } + void Stop() { + sleep_in_use_ = 0ms; + JoinAndDeleteThread(); } - void Stop() { sleep_in_use_ = 0ms; } - std::string ValueString() const; std::string NodeString() const; private: - void PrintValue() const; - std::string FormatValue() const; + void PrintNode() const; std::string FormatNode() const; bool IsRunning() const { return sleep_in_use_ != 0ms; } void Run(); void Sleep() { std::this_thread::sleep_for(sleep_in_use_); } + void SpawnThread() { + thread_ = std::make_unique(&NestPythonVis::Run, this); + } + void JoinAndDeleteThread() { + if (thread_ != nullptr) { + thread_->join(); + thread_.reset(); + } + } - double* value_{nullptr}; conduit::Node* node_{nullptr}; std::unique_ptr thread_{nullptr}; std::chrono::duration sleep_in_use_{0ms}; diff --git a/npv/src/npv.cpp b/npv/src/npv.cpp index 2ca69f9..c4094e0 100644 --- a/npv/src/npv.cpp +++ b/npv/src/npv.cpp @@ -29,29 +29,19 @@ namespace npv { void NestPythonVis::Run() { while (IsRunning()) { - PrintValue(); + PrintNode(); Sleep(); } } -void NestPythonVis::PrintValue() const { - std::cout << ValueString() << " " << NodeString() << std::endl; -} - -std::string NestPythonVis::ValueString() const { - return value_ == nullptr ? "nullptr" : FormatValue(); +void NestPythonVis::PrintNode() const { + std::cout << NodeString() << std::endl; } std::string NestPythonVis::NodeString() const { return node_ == nullptr ? "nullptr" : FormatNode(); } -std::string NestPythonVis::FormatValue() const { - std::ostringstream sstr; - sstr << *value_; - return sstr.str(); -} - std::string NestPythonVis::FormatNode() const { std::ostringstream sstr; sstr << (*node_)["V_m"].as_double(); diff --git a/npv/tests/src/test_npv.cpp b/npv/tests/src/test_npv.cpp index 19204a5..e277167 100644 --- a/npv/tests/src/test_npv.cpp +++ b/npv/tests/src/test_npv.cpp @@ -1,3 +1,4 @@ + //------------------------------------------------------------------------------ // nest python vis // @@ -38,27 +39,20 @@ using namespace std::literals::chrono_literals; // NOLINT SCENARIO("An npv object shall visualize the double it is bound to", "[npv][npv::NestPythonVis") { GIVEN( - "A double, a membrane potenial in a conduit node and A NestPythonVis " + "A membrane potenial in a conduit node and A NestPythonVis " "object") { - double value = 0.0; conduit::Node node; node["V_m"] = 0.0; - npv::NestPythonVis vis(&value, &node); + npv::NestPythonVis vis(&node); WHEN("I ask for a string representing the value") { - auto ret_val = vis.ValueString(); auto ret_node = vis.NodeString(); - THEN("it shall represent the bound value.") { - REQUIRE(ret_val == "0"); - REQUIRE(ret_node == "0"); - } + THEN("it shall represent the bound value.") { REQUIRE(ret_node == "0"); } } WHEN("the bound value is changed by some external code") { - value = 42.0; node["V_m"] = 42.0; THEN("its string representation shall be updated accordingly.") { - REQUIRE(vis.ValueString() == "42"); REQUIRE(vis.NodeString() == "42"); } } @@ -82,7 +76,7 @@ SCENARIO("An npv object shall visualize the double it is bound to", GIVEN("A NestPythonVis object bound to nullptr") { npv::NestPythonVis vis(nullptr); WHEN("I ask for a string representing tha value") { - auto ret_val = vis.ValueString(); + auto ret_val = vis.NodeString(); THEN("it shall read 'nullptr'.") { REQUIRE(ret_val == "nullptr"); } } } diff --git a/pynpv/src/npv.cpp b/pynpv/src/npv.cpp index a59e3f7..ecc7220 100644 --- a/pynpv/src/npv.cpp +++ b/pynpv/src/npv.cpp @@ -38,9 +38,9 @@ BOOST_PYTHON_MODULE(pynpv) { def("Greet", npv::Greet); - class_( - "NestPythonVis", init()) - .def("ValueString", &npv::NestPythonVis::ValueString) + class_("NestPythonVis", + init()) + .def("NodeString", &npv::NestPythonVis::NodeString) .def("Start", &npv::NestPythonVis::Start) .def("Stop", &npv::NestPythonVis::Stop); } From 1d8042df260312da92eea43190d9889615418bbc Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 23 Aug 2017 07:20:18 +0200 Subject: [PATCH 23/71] Move NestPythonVis to separate file --- npv/include/npv/nest_python_vis.hpp | 80 +++++++++++++++++++ npv/include/npv/npv.hpp | 51 ------------ npv/src/nest_python_vis.cpp | 51 ++++++++++++ npv/src/npv.cpp | 25 ------ ...{test_npv.cpp => test_nest_python_vis.cpp} | 2 +- pynpv/src/{npv.cpp => pynpv.cpp} | 1 + 6 files changed, 133 insertions(+), 77 deletions(-) create mode 100644 npv/include/npv/nest_python_vis.hpp create mode 100644 npv/src/nest_python_vis.cpp rename npv/tests/src/{test_npv.cpp => test_nest_python_vis.cpp} (98%) rename pynpv/src/{npv.cpp => pynpv.cpp} (98%) diff --git a/npv/include/npv/nest_python_vis.hpp b/npv/include/npv/nest_python_vis.hpp new file mode 100644 index 0000000..48cf4d4 --- /dev/null +++ b/npv/include/npv/nest_python_vis.hpp @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// nest python vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 NPV_INCLUDE_NPV_NEST_PYTHON_VIS_HPP_ +#define NPV_INCLUDE_NPV_NEST_PYTHON_VIS_HPP_ + +#include +#include +#include +#include + +#include "conduit/conduit.hpp" + +// gcc-5 does not accept using std::chrono_literals::operator""ms; +using namespace std::literals::chrono_literals; // NOLINT + +namespace npv { + +class NestPythonVis { + public: + explicit NestPythonVis(conduit::Node* node = nullptr) : node_(node) {} + explicit NestPythonVis(std::size_t ptr_to_node) + : NestPythonVis(reinterpret_cast(ptr_to_node)) {} + ~NestPythonVis() { JoinAndDeleteThread(); } + NestPythonVis(const NestPythonVis&) = delete; + + void Start() { + sleep_in_use_ = configured_sleep_; + SpawnThread(); + } + void Stop() { + sleep_in_use_ = 0ms; + JoinAndDeleteThread(); + } + + std::string NodeString() const; + + private: + void PrintNode() const; + std::string FormatNode() const; + bool IsRunning() const { return sleep_in_use_ != 0ms; } + void Run(); + void Sleep() { std::this_thread::sleep_for(sleep_in_use_); } + void SpawnThread() { + thread_ = std::make_unique(&NestPythonVis::Run, this); + } + void JoinAndDeleteThread() { + if (thread_ != nullptr) { + thread_->join(); + thread_.reset(); + } + } + + conduit::Node* node_{nullptr}; + std::unique_ptr thread_{nullptr}; + std::chrono::duration sleep_in_use_{0ms}; + std::chrono::duration configured_sleep_{10ms}; +}; + +} // namespace npv + +#endif // NPV_INCLUDE_NPV_NEST_PYTHON_VIS_HPP_ diff --git a/npv/include/npv/npv.hpp b/npv/include/npv/npv.hpp index 0ec9a34..e899831 100644 --- a/npv/include/npv/npv.hpp +++ b/npv/include/npv/npv.hpp @@ -22,59 +22,8 @@ #ifndef NPV_INCLUDE_NPV_NPV_HPP_ #define NPV_INCLUDE_NPV_NPV_HPP_ -#include -#include -#include -#include - -#include "conduit/conduit.hpp" - -// gcc-5 does not accept using std::chrono_literals::operator""ms; -using namespace std::literals::chrono_literals; // NOLINT - namespace npv { -class NestPythonVis { - public: - explicit NestPythonVis(conduit::Node* node = nullptr) : node_(node) {} - explicit NestPythonVis(std::size_t ptr_to_node) - : NestPythonVis(reinterpret_cast(ptr_to_node)) {} - ~NestPythonVis() { JoinAndDeleteThread(); } - NestPythonVis(const NestPythonVis&) = delete; - - void Start() { - sleep_in_use_ = configured_sleep_; - SpawnThread(); - } - void Stop() { - sleep_in_use_ = 0ms; - JoinAndDeleteThread(); - } - - std::string NodeString() const; - - private: - void PrintNode() const; - std::string FormatNode() const; - bool IsRunning() const { return sleep_in_use_ != 0ms; } - void Run(); - void Sleep() { std::this_thread::sleep_for(sleep_in_use_); } - void SpawnThread() { - thread_ = std::make_unique(&NestPythonVis::Run, this); - } - void JoinAndDeleteThread() { - if (thread_ != nullptr) { - thread_->join(); - thread_.reset(); - } - } - - conduit::Node* node_{nullptr}; - std::unique_ptr thread_{nullptr}; - std::chrono::duration sleep_in_use_{0ms}; - std::chrono::duration configured_sleep_{10ms}; -}; - char const* Greet(); } // namespace npv diff --git a/npv/src/nest_python_vis.cpp b/npv/src/nest_python_vis.cpp new file mode 100644 index 0000000..dbf542c --- /dev/null +++ b/npv/src/nest_python_vis.cpp @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// nest python vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "npv/nest_python_vis.hpp" + +#include +#include +#include + +namespace npv { + +void NestPythonVis::Run() { + while (IsRunning()) { + PrintNode(); + Sleep(); + } +} + +void NestPythonVis::PrintNode() const { + std::cout << NodeString() << std::endl; +} + +std::string NestPythonVis::NodeString() const { + return node_ == nullptr ? "nullptr" : FormatNode(); +} + +std::string NestPythonVis::FormatNode() const { + std::ostringstream sstr; + sstr << (*node_)["V_m"].as_double(); + return sstr.str(); +} + +} // namespace npv diff --git a/npv/src/npv.cpp b/npv/src/npv.cpp index c4094e0..61e7b6e 100644 --- a/npv/src/npv.cpp +++ b/npv/src/npv.cpp @@ -21,33 +21,8 @@ #include "npv/npv.hpp" -#include -#include -#include - namespace npv { -void NestPythonVis::Run() { - while (IsRunning()) { - PrintNode(); - Sleep(); - } -} - -void NestPythonVis::PrintNode() const { - std::cout << NodeString() << std::endl; -} - -std::string NestPythonVis::NodeString() const { - return node_ == nullptr ? "nullptr" : FormatNode(); -} - -std::string NestPythonVis::FormatNode() const { - std::ostringstream sstr; - sstr << (*node_)["V_m"].as_double(); - return sstr.str(); -} - char const* Greet() { return "G'day!"; } } // namespace npv diff --git a/npv/tests/src/test_npv.cpp b/npv/tests/src/test_nest_python_vis.cpp similarity index 98% rename from npv/tests/src/test_npv.cpp rename to npv/tests/src/test_nest_python_vis.cpp index e277167..b0e4df6 100644 --- a/npv/tests/src/test_npv.cpp +++ b/npv/tests/src/test_nest_python_vis.cpp @@ -29,7 +29,7 @@ #include "conduit/conduit.hpp" -#include "npv/npv.hpp" +#include "npv/nest_python_vis.hpp" #include "test_utilities/cout_capture.hpp" diff --git a/pynpv/src/npv.cpp b/pynpv/src/pynpv.cpp similarity index 98% rename from pynpv/src/npv.cpp rename to pynpv/src/pynpv.cpp index ecc7220..b7f547e 100644 --- a/pynpv/src/npv.cpp +++ b/pynpv/src/pynpv.cpp @@ -24,6 +24,7 @@ SUPPRESS_WARNINGS_BEGIN #include "boost/python.hpp" SUPPRESS_WARNINGS_END +#include "npv/nest_python_vis.hpp" #include "npv/npv.hpp" #if defined __clang__ From 1170451c5587e610740caed224d37056b0fd1c99 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 23 Aug 2017 07:31:40 +0200 Subject: [PATCH 24/71] Restrcture pynpv exporting --- pynpv/src/nest_python_vis.hpp | 42 ++++++++++++++++++++++++++++++++ pynpv/src/pynpv.cpp | 19 +++------------ pynpv/src/pynpv.hpp | 46 +++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 pynpv/src/nest_python_vis.hpp create mode 100644 pynpv/src/pynpv.hpp diff --git a/pynpv/src/nest_python_vis.hpp b/pynpv/src/nest_python_vis.hpp new file mode 100644 index 0000000..f3da947 --- /dev/null +++ b/pynpv/src/nest_python_vis.hpp @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// nest python vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 PYNPV_SRC_NEST_PYTHON_VIS_HPP_ +#define PYNPV_SRC_NEST_PYTHON_VIS_HPP_ + +#include "npv/nest_python_vis.hpp" + +#include "pynpv.hpp" + +namespace pynpv { + +template <> +void expose() { + class_("NestPythonVis", + init()) + .def("NodeString", &npv::NestPythonVis::NodeString) + .def("Start", &npv::NestPythonVis::Start) + .def("Stop", &npv::NestPythonVis::Stop); +} + +} // namespace pynpv + +#endif // PYNPV_SRC_NEST_PYTHON_VIS_HPP_ diff --git a/pynpv/src/pynpv.cpp b/pynpv/src/pynpv.cpp index b7f547e..a3230ef 100644 --- a/pynpv/src/pynpv.cpp +++ b/pynpv/src/pynpv.cpp @@ -19,31 +19,20 @@ // limitations under the License. //------------------------------------------------------------------------------ +#include "pynpv.hpp" + SUPPRESS_WARNINGS_BEGIN #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #include "boost/python.hpp" SUPPRESS_WARNINGS_END -#include "npv/nest_python_vis.hpp" #include "npv/npv.hpp" -#if defined __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wmissing-prototypes" -#endif +#include "nest_python_vis.hpp" BOOST_PYTHON_MODULE(pynpv) { - using boost::python::class_; - using boost::python::def; - using boost::python::init; - def("Greet", npv::Greet); - - class_("NestPythonVis", - init()) - .def("NodeString", &npv::NestPythonVis::NodeString) - .def("Start", &npv::NestPythonVis::Start) - .def("Stop", &npv::NestPythonVis::Stop); + pynpv::expose(); } #if defined __clang__ diff --git a/pynpv/src/pynpv.hpp b/pynpv/src/pynpv.hpp new file mode 100644 index 0000000..f134c71 --- /dev/null +++ b/pynpv/src/pynpv.hpp @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// nest python vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 PYNPV_SRC_PYNPV_HPP_ +#define PYNPV_SRC_PYNPV_HPP_ + +SUPPRESS_WARNINGS_BEGIN +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#include "boost/python.hpp" +SUPPRESS_WARNINGS_END + +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-prototypes" +#endif + +using boost::python::class_; +using boost::python::def; +using boost::python::init; + +namespace pynpv { + +template +void expose(); + +} // namespace pynpv + +#endif // PYNPV_SRC_PYNPV_HPP_ From 9d782193ae808cf60c006267ed1b17245c5ef2ec Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 23 Aug 2017 07:55:45 +0200 Subject: [PATCH 25/71] Add, expose ConduitData This is a dummy generating the conduit nodes that used in the nest RecordingBackend. That way the pipeline can be tested without having to include nest here. --- pynpv/src/conduit_data.hpp | 55 ++++++++++++++++++++++++++++++++++++++ pynpv/src/pynpv.cpp | 2 ++ 2 files changed, 57 insertions(+) create mode 100644 pynpv/src/conduit_data.hpp diff --git a/pynpv/src/conduit_data.hpp b/pynpv/src/conduit_data.hpp new file mode 100644 index 0000000..65876e1 --- /dev/null +++ b/pynpv/src/conduit_data.hpp @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// nest python vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 PYNPV_SRC_CONDUIT_DATA_HPP_ +#define PYNPV_SRC_CONDUIT_DATA_HPP_ + +#include "conduit/conduit.hpp" + +namespace pynpv { + +class ConduitData { + public: + ConduitData() { + node_["V_m"] = 0.0; + std::cout << "Ptr. to conduit node: " << Pointer() << std::endl; + } + ~ConduitData() = default; + ConduitData(const ConduitData&) = default; + ConduitData(ConduitData&&) = default; + + void Set(const char* attribute, double value) { node_[attribute] = value; } + std::size_t Pointer() const { return reinterpret_cast(&node_); } + + private: + conduit::Node node_; +}; + +template <> +void expose() { + class_("ConduitData") + .def("Set", &ConduitData::Set) + .def("Pointer", &ConduitData::Pointer); +} + +} // namespace pynpv + +#endif // PYNPV_SRC_CONDUIT_DATA_HPP_ diff --git a/pynpv/src/pynpv.cpp b/pynpv/src/pynpv.cpp index a3230ef..9cf74f5 100644 --- a/pynpv/src/pynpv.cpp +++ b/pynpv/src/pynpv.cpp @@ -28,10 +28,12 @@ SUPPRESS_WARNINGS_END #include "npv/npv.hpp" +#include "conduit_data.hpp" #include "nest_python_vis.hpp" BOOST_PYTHON_MODULE(pynpv) { def("Greet", npv::Greet); + pynpv::expose(); pynpv::expose(); } From 35c25d5f7170cd3fa3ed4dd1917c2988d56065ae Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 23 Aug 2017 07:55:58 +0200 Subject: [PATCH 26/71] Update python tests. --- pynpv/tests/src/test_pynpv.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pynpv/tests/src/test_pynpv.py b/pynpv/tests/src/test_pynpv.py index f16f665..e1fbf71 100644 --- a/pynpv/tests/src/test_pynpv.py +++ b/pynpv/tests/src/test_pynpv.py @@ -43,17 +43,22 @@ def test_cout_capture(capsys): def test_pynpv_greet(): assert pynpv.Greet() == "G'day!" -def test_pynpv_npv_ValueString(): - d = ctypes.c_double(42.0); - ptr = ctypes.c_void_p.from_buffer(ctypes.pointer(d)).value - v = pynpv.NestPythonVis(ptr, 0); - assert v.ValueString() == "42" +def test_pynpv_npv_NodeString_zero_on_creation(): + d = pynpv.ConduitData(); + v = pynpv.NestPythonVis(d.Pointer()); + assert v.NodeString() == "0" -def test_pynpv_npv_StartStop(): - d = ctypes.c_double(42.0); - ptr = ctypes.c_void_p.from_buffer(ctypes.pointer(d)).value - v = pynpv.NestPythonVis(ptr, 0); +def test_pynpv_npv_NodeString_correct_after_set(): + d = pynpv.ConduitData(); + v = pynpv.NestPythonVis(d.Pointer()); + d.Set("V_m", 42.0) + assert v.NodeString() == "42" +def test_pynpv_npv_StartStop(): + d = pynpv.ConduitData(); + v = pynpv.NestPythonVis(d.Pointer()); + d.Set("V_m", 42.0) + c = pytest_utilities.CoutCapture() v.Start() From 9832474c6d98497377aa2595e839720cd4cda499 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 29 Aug 2017 07:03:38 +0200 Subject: [PATCH 27/71] Add check for existence of Qt Moc files in WarningLevels --- cmake/WarningLevels.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmake/WarningLevels.cmake b/cmake/WarningLevels.cmake index c52cdd6..7261b96 100644 --- a/cmake/WarningLevels.cmake +++ b/cmake/WarningLevels.cmake @@ -103,26 +103,32 @@ macro(SET_WARNING_LEVELS_RWTH TARGET) if(IS_CLANG) target_compile_options(${TARGET} PRIVATE ${WARNING_LEVELS_RWTH_CLANG}) if (CMAKE_AUTOMOC) + if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_autogen/moc_compilation.cpp) set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_autogen/moc_compilation.cpp PROPERTIES COMPILE_FLAGS ${WARNING_LEVELS_RWTH_CLANG_QT_MOC_OVERRIDE}) endif () + endif() target_compile_options(${TARGET} PRIVATE "-include${SUPPRESS_WARNING_HEADER_FILE}") elseif(IS_GCC) target_compile_options(${TARGET} PRIVATE ${WARNING_LEVELS_RWTH_GCC}) if (CMAKE_AUTOMOC) + if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_autogen/moc_compilation.cpp) set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_autogen/moc_compilation.cpp PROPERTIES COMPILE_FLAGS ${WARNING_LEVELS_RWTH_GCC_QT_MOC_OVERRIDE}) endif () + endif() target_compile_options(${TARGET} PRIVATE "-include${SUPPRESS_WARNING_HEADER_FILE}") elseif(IS_MSVC) target_compile_options(${TARGET} PRIVATE ${WARNING_LEVELS_RWTH_MSVC}) if (CMAKE_AUTOMOC) + if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_autogen/moc_compilation.cpp) set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/${target}_autogen/moc_compilation.cpp PROPERTIES COMPILE_FLAGS ${WARNING_LEVELS_RWTH_MSVC_QT_MOC_OVERRIDE}) endif () + endif() target_compile_options(${TARGET} PRIVATE "/FI ${SUPPRESS_WARNING_HEADER_FILE}") else() message(WARNING "SET_WARNING_LEVELS_RWTH not implemented for your compiler. " From 6c684341dee920ac4dea2154d542817bdff24f1b Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 29 Aug 2017 07:07:04 +0200 Subject: [PATCH 28/71] Refactor --- npv/include/npv/nest_python_vis.hpp | 23 +++++++++----------- npv/src/nest_python_vis.cpp | 33 +++++++++++++++++++++++++++-- pynpv/src/pynpv.hpp | 1 + 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/npv/include/npv/nest_python_vis.hpp b/npv/include/npv/nest_python_vis.hpp index 48cf4d4..f71ac12 100644 --- a/npv/include/npv/nest_python_vis.hpp +++ b/npv/include/npv/nest_python_vis.hpp @@ -37,27 +37,23 @@ namespace npv { class NestPythonVis { public: explicit NestPythonVis(conduit::Node* node = nullptr) : node_(node) {} - explicit NestPythonVis(std::size_t ptr_to_node) - : NestPythonVis(reinterpret_cast(ptr_to_node)) {} - ~NestPythonVis() { JoinAndDeleteThread(); } + explicit NestPythonVis(std::size_t ptr_to_node); + ~NestPythonVis(); NestPythonVis(const NestPythonVis&) = delete; - void Start() { - sleep_in_use_ = configured_sleep_; - SpawnThread(); - } - void Stop() { - sleep_in_use_ = 0ms; - JoinAndDeleteThread(); - } + void Start(); + void Stop(); std::string NodeString() const; private: void PrintNode() const; std::string FormatNode() const; - bool IsRunning() const { return sleep_in_use_ != 0ms; } + void EnableIsRunning(); + void DisableIsRunning(); + bool IsRunning() const; void Run(); + void Step(); void Sleep() { std::this_thread::sleep_for(sleep_in_use_); } void SpawnThread() { thread_ = std::make_unique(&NestPythonVis::Run, this); @@ -71,8 +67,9 @@ class NestPythonVis { conduit::Node* node_{nullptr}; std::unique_ptr thread_{nullptr}; - std::chrono::duration sleep_in_use_{0ms}; + static constexpr std::chrono::duration disabled_sleep_{0ms}; std::chrono::duration configured_sleep_{10ms}; + std::chrono::duration sleep_in_use_{disabled_sleep_}; }; } // namespace npv diff --git a/npv/src/nest_python_vis.cpp b/npv/src/nest_python_vis.cpp index dbf542c..a20f953 100644 --- a/npv/src/nest_python_vis.cpp +++ b/npv/src/nest_python_vis.cpp @@ -27,13 +27,42 @@ namespace npv { +constexpr std::chrono::duration NestPythonVis::disabled_sleep_; + +NestPythonVis::NestPythonVis(std::size_t ptr_to_node) + : NestPythonVis(reinterpret_cast(ptr_to_node)) {} + +NestPythonVis::~NestPythonVis() { JoinAndDeleteThread(); } + +void NestPythonVis::Start() { + EnableIsRunning(); + SpawnThread(); +} + +void NestPythonVis::EnableIsRunning() { sleep_in_use_ = configured_sleep_; } + +void NestPythonVis::DisableIsRunning() { sleep_in_use_ = disabled_sleep_; } + +bool NestPythonVis::IsRunning() const { + return sleep_in_use_ != disabled_sleep_; +} + +void NestPythonVis::Stop() { + DisableIsRunning(); + JoinAndDeleteThread(); +} + void NestPythonVis::Run() { while (IsRunning()) { - PrintNode(); - Sleep(); + Step(); } } +void NestPythonVis::Step() { + PrintNode(); + Sleep(); +} + void NestPythonVis::PrintNode() const { std::cout << NodeString() << std::endl; } diff --git a/pynpv/src/pynpv.hpp b/pynpv/src/pynpv.hpp index f134c71..5604cff 100644 --- a/pynpv/src/pynpv.hpp +++ b/pynpv/src/pynpv.hpp @@ -24,6 +24,7 @@ SUPPRESS_WARNINGS_BEGIN #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#pragma GCC diagnostic ignored "-fpermissive" #include "boost/python.hpp" SUPPRESS_WARNINGS_END From e649846051a9348b0fe6ff1fc69de5c49a8faadb Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 29 Aug 2017 07:13:35 +0200 Subject: [PATCH 29/71] Did not work: Try and add Qt to the mix --- CMakeLists.txt | 4 ++++ npv/CMakeLists.txt | 2 ++ npv/include/npv/nest_python_vis.hpp | 10 +++++++++- npv/src/nest_python_vis.cpp | 19 +++++++++++++++++++ npv/tests/src/test_nest_python_vis.cpp | 14 ++++++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc846df..d4bd44b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,10 @@ find_package(conduit) set_target_properties(conduit PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CONDUIT_INCLUDE_DIRS}/..") +set(CMAKE_AUTOMOC ON) +find_package(Qt5 COMPONENTS Core Widgets REQUIRED) + + add_subdirectory(npv) add_subdirectory(pynpv) add_subdirectory(pytest_utilities) diff --git a/npv/CMakeLists.txt b/npv/CMakeLists.txt index d8fee85..42c79ef 100644 --- a/npv/CMakeLists.txt +++ b/npv/CMakeLists.txt @@ -34,6 +34,8 @@ target_include_directories(npv ) target_link_libraries(npv conduit + Qt5::Core + Qt5::Widgets ) generate_export_header(npv diff --git a/npv/include/npv/nest_python_vis.hpp b/npv/include/npv/nest_python_vis.hpp index f71ac12..038fa8a 100644 --- a/npv/include/npv/nest_python_vis.hpp +++ b/npv/include/npv/nest_python_vis.hpp @@ -29,6 +29,9 @@ #include "conduit/conduit.hpp" +#include "QApplication" +#include "QLabel" + // gcc-5 does not accept using std::chrono_literals::operator""ms; using namespace std::literals::chrono_literals; // NOLINT @@ -36,7 +39,7 @@ namespace npv { class NestPythonVis { public: - explicit NestPythonVis(conduit::Node* node = nullptr) : node_(node) {} + explicit NestPythonVis(conduit::Node* node = nullptr); explicit NestPythonVis(std::size_t ptr_to_node); ~NestPythonVis(); NestPythonVis(const NestPythonVis&) = delete; @@ -70,6 +73,11 @@ class NestPythonVis { static constexpr std::chrono::duration disabled_sleep_{0ms}; std::chrono::duration configured_sleep_{10ms}; std::chrono::duration sleep_in_use_{disabled_sleep_}; + + int argc_{0}; + QApplication qt_app_; + QWidget* qt_window_{nullptr}; + QLabel* qt_label_{nullptr}; }; } // namespace npv diff --git a/npv/src/nest_python_vis.cpp b/npv/src/nest_python_vis.cpp index a20f953..630b5b2 100644 --- a/npv/src/nest_python_vis.cpp +++ b/npv/src/nest_python_vis.cpp @@ -25,10 +25,23 @@ #include #include +#include "QString" +#include "QVBoxLayout" + namespace npv { constexpr std::chrono::duration NestPythonVis::disabled_sleep_; +NestPythonVis::NestPythonVis(conduit::Node* node) + : node_(node), + qt_app_{argc_, nullptr}, + qt_window_{new QWidget}, + qt_label_{new QLabel} { + auto layout = new QVBoxLayout; + layout->addWidget(qt_label_); + qt_window_->setLayout(layout); +} + NestPythonVis::NestPythonVis(std::size_t ptr_to_node) : NestPythonVis(reinterpret_cast(ptr_to_node)) {} @@ -36,6 +49,8 @@ NestPythonVis::~NestPythonVis() { JoinAndDeleteThread(); } void NestPythonVis::Start() { EnableIsRunning(); + qt_window_->show(); + QApplication::processEvents(); SpawnThread(); } @@ -59,8 +74,12 @@ void NestPythonVis::Run() { } void NestPythonVis::Step() { + static int i = 0; PrintNode(); + qt_label_->setText(QString(i)); + QApplication::processEvents(); Sleep(); + ++i; } void NestPythonVis::PrintNode() const { diff --git a/npv/tests/src/test_nest_python_vis.cpp b/npv/tests/src/test_nest_python_vis.cpp index b0e4df6..723b431 100644 --- a/npv/tests/src/test_nest_python_vis.cpp +++ b/npv/tests/src/test_nest_python_vis.cpp @@ -81,3 +81,17 @@ SCENARIO("An npv object shall visualize the double it is bound to", } } } + +SCENARIO("We have a visualization application with a window") { + GIVEN("A VisApplication") { + npv::NestPythonVis app{nullptr}; + app.Start(); + WHEN("we call run") { + THEN("we see one window") { + auto all_windows{QApplication::topLevelWindows()}; + REQUIRE(all_windows.size() == 1); + } + } + app.Stop(); + } +} From 76d2df554826929ba18342d3a0df5dcf8e6c9b43 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 29 Aug 2017 07:13:51 +0200 Subject: [PATCH 30/71] Revert "Did not work: Try and add Qt to the mix" This reverts commit 1ee871488eaafdd3fa73950096548e1456983b89. --- CMakeLists.txt | 4 ---- npv/CMakeLists.txt | 2 -- npv/include/npv/nest_python_vis.hpp | 10 +--------- npv/src/nest_python_vis.cpp | 19 ------------------- npv/tests/src/test_nest_python_vis.cpp | 14 -------------- 5 files changed, 1 insertion(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4bd44b..cc846df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,10 +45,6 @@ find_package(conduit) set_target_properties(conduit PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CONDUIT_INCLUDE_DIRS}/..") -set(CMAKE_AUTOMOC ON) -find_package(Qt5 COMPONENTS Core Widgets REQUIRED) - - add_subdirectory(npv) add_subdirectory(pynpv) add_subdirectory(pytest_utilities) diff --git a/npv/CMakeLists.txt b/npv/CMakeLists.txt index 42c79ef..d8fee85 100644 --- a/npv/CMakeLists.txt +++ b/npv/CMakeLists.txt @@ -34,8 +34,6 @@ target_include_directories(npv ) target_link_libraries(npv conduit - Qt5::Core - Qt5::Widgets ) generate_export_header(npv diff --git a/npv/include/npv/nest_python_vis.hpp b/npv/include/npv/nest_python_vis.hpp index 038fa8a..f71ac12 100644 --- a/npv/include/npv/nest_python_vis.hpp +++ b/npv/include/npv/nest_python_vis.hpp @@ -29,9 +29,6 @@ #include "conduit/conduit.hpp" -#include "QApplication" -#include "QLabel" - // gcc-5 does not accept using std::chrono_literals::operator""ms; using namespace std::literals::chrono_literals; // NOLINT @@ -39,7 +36,7 @@ namespace npv { class NestPythonVis { public: - explicit NestPythonVis(conduit::Node* node = nullptr); + explicit NestPythonVis(conduit::Node* node = nullptr) : node_(node) {} explicit NestPythonVis(std::size_t ptr_to_node); ~NestPythonVis(); NestPythonVis(const NestPythonVis&) = delete; @@ -73,11 +70,6 @@ class NestPythonVis { static constexpr std::chrono::duration disabled_sleep_{0ms}; std::chrono::duration configured_sleep_{10ms}; std::chrono::duration sleep_in_use_{disabled_sleep_}; - - int argc_{0}; - QApplication qt_app_; - QWidget* qt_window_{nullptr}; - QLabel* qt_label_{nullptr}; }; } // namespace npv diff --git a/npv/src/nest_python_vis.cpp b/npv/src/nest_python_vis.cpp index 630b5b2..a20f953 100644 --- a/npv/src/nest_python_vis.cpp +++ b/npv/src/nest_python_vis.cpp @@ -25,23 +25,10 @@ #include #include -#include "QString" -#include "QVBoxLayout" - namespace npv { constexpr std::chrono::duration NestPythonVis::disabled_sleep_; -NestPythonVis::NestPythonVis(conduit::Node* node) - : node_(node), - qt_app_{argc_, nullptr}, - qt_window_{new QWidget}, - qt_label_{new QLabel} { - auto layout = new QVBoxLayout; - layout->addWidget(qt_label_); - qt_window_->setLayout(layout); -} - NestPythonVis::NestPythonVis(std::size_t ptr_to_node) : NestPythonVis(reinterpret_cast(ptr_to_node)) {} @@ -49,8 +36,6 @@ NestPythonVis::~NestPythonVis() { JoinAndDeleteThread(); } void NestPythonVis::Start() { EnableIsRunning(); - qt_window_->show(); - QApplication::processEvents(); SpawnThread(); } @@ -74,12 +59,8 @@ void NestPythonVis::Run() { } void NestPythonVis::Step() { - static int i = 0; PrintNode(); - qt_label_->setText(QString(i)); - QApplication::processEvents(); Sleep(); - ++i; } void NestPythonVis::PrintNode() const { diff --git a/npv/tests/src/test_nest_python_vis.cpp b/npv/tests/src/test_nest_python_vis.cpp index 723b431..b0e4df6 100644 --- a/npv/tests/src/test_nest_python_vis.cpp +++ b/npv/tests/src/test_nest_python_vis.cpp @@ -81,17 +81,3 @@ SCENARIO("An npv object shall visualize the double it is bound to", } } } - -SCENARIO("We have a visualization application with a window") { - GIVEN("A VisApplication") { - npv::NestPythonVis app{nullptr}; - app.Start(); - WHEN("we call run") { - THEN("we see one window") { - auto all_windows{QApplication::topLevelWindows()}; - REQUIRE(all_windows.size() == 1); - } - } - app.Stop(); - } -} From 253e413c772ec21c6b3151f78ac834d42513f0b5 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 29 Aug 2017 07:15:39 +0200 Subject: [PATCH 31/71] Refactor constructor --- npv/include/npv/nest_python_vis.hpp | 2 +- npv/src/nest_python_vis.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/npv/include/npv/nest_python_vis.hpp b/npv/include/npv/nest_python_vis.hpp index f71ac12..01e0a18 100644 --- a/npv/include/npv/nest_python_vis.hpp +++ b/npv/include/npv/nest_python_vis.hpp @@ -36,7 +36,7 @@ namespace npv { class NestPythonVis { public: - explicit NestPythonVis(conduit::Node* node = nullptr) : node_(node) {} + explicit NestPythonVis(conduit::Node* node = nullptr); explicit NestPythonVis(std::size_t ptr_to_node); ~NestPythonVis(); NestPythonVis(const NestPythonVis&) = delete; diff --git a/npv/src/nest_python_vis.cpp b/npv/src/nest_python_vis.cpp index a20f953..8960340 100644 --- a/npv/src/nest_python_vis.cpp +++ b/npv/src/nest_python_vis.cpp @@ -29,6 +29,8 @@ namespace npv { constexpr std::chrono::duration NestPythonVis::disabled_sleep_; +NestPythonVis::NestPythonVis(conduit::Node* node) : node_(node) {} + NestPythonVis::NestPythonVis(std::size_t ptr_to_node) : NestPythonVis(reinterpret_cast(ptr_to_node)) {} From aec38764767df1d09ccfdbf49e9ec6ecbcbf11b2 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 29 Aug 2017 16:22:23 +0200 Subject: [PATCH 32/71] Refactor exposure to python --- pynpv/src/conduit_data.cpp | 34 +++++++++++++++++++ pynpv/src/conduit_data.hpp | 7 ---- ...est_python_vis.hpp => nest_python_vis.cpp} | 5 --- pynpv/src/pynpv.cpp | 11 +----- pynpv/src/pynpv.hpp | 6 ---- pytest_utilities/src/cout_capture.cpp | 9 ----- 6 files changed, 35 insertions(+), 37 deletions(-) create mode 100644 pynpv/src/conduit_data.cpp rename pynpv/src/{nest_python_vis.hpp => nest_python_vis.cpp} (92%) diff --git a/pynpv/src/conduit_data.cpp b/pynpv/src/conduit_data.cpp new file mode 100644 index 0000000..5d05d05 --- /dev/null +++ b/pynpv/src/conduit_data.cpp @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------ +// nest python vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "conduit_data.hpp" +#include "pynpv.hpp" + +namespace pynpv { + +template <> +void expose() { + class_("ConduitData") + .def("Set", &ConduitData::Set) + .def("Pointer", &ConduitData::Pointer); +} + +} // namespace pynpv diff --git a/pynpv/src/conduit_data.hpp b/pynpv/src/conduit_data.hpp index 65876e1..7b692b7 100644 --- a/pynpv/src/conduit_data.hpp +++ b/pynpv/src/conduit_data.hpp @@ -43,13 +43,6 @@ class ConduitData { conduit::Node node_; }; -template <> -void expose() { - class_("ConduitData") - .def("Set", &ConduitData::Set) - .def("Pointer", &ConduitData::Pointer); -} - } // namespace pynpv #endif // PYNPV_SRC_CONDUIT_DATA_HPP_ diff --git a/pynpv/src/nest_python_vis.hpp b/pynpv/src/nest_python_vis.cpp similarity index 92% rename from pynpv/src/nest_python_vis.hpp rename to pynpv/src/nest_python_vis.cpp index f3da947..711ce31 100644 --- a/pynpv/src/nest_python_vis.hpp +++ b/pynpv/src/nest_python_vis.cpp @@ -19,9 +19,6 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef PYNPV_SRC_NEST_PYTHON_VIS_HPP_ -#define PYNPV_SRC_NEST_PYTHON_VIS_HPP_ - #include "npv/nest_python_vis.hpp" #include "pynpv.hpp" @@ -38,5 +35,3 @@ void expose() { } } // namespace pynpv - -#endif // PYNPV_SRC_NEST_PYTHON_VIS_HPP_ diff --git a/pynpv/src/pynpv.cpp b/pynpv/src/pynpv.cpp index 9cf74f5..851a305 100644 --- a/pynpv/src/pynpv.cpp +++ b/pynpv/src/pynpv.cpp @@ -21,22 +21,13 @@ #include "pynpv.hpp" -SUPPRESS_WARNINGS_BEGIN -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#include "boost/python.hpp" -SUPPRESS_WARNINGS_END - +#include "npv/nest_python_vis.hpp" #include "npv/npv.hpp" #include "conduit_data.hpp" -#include "nest_python_vis.hpp" BOOST_PYTHON_MODULE(pynpv) { def("Greet", npv::Greet); pynpv::expose(); pynpv::expose(); } - -#if defined __clang__ -#pragma clang diagnostic pop -#endif diff --git a/pynpv/src/pynpv.hpp b/pynpv/src/pynpv.hpp index 5604cff..a584076 100644 --- a/pynpv/src/pynpv.hpp +++ b/pynpv/src/pynpv.hpp @@ -24,15 +24,9 @@ SUPPRESS_WARNINGS_BEGIN #pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#pragma GCC diagnostic ignored "-fpermissive" #include "boost/python.hpp" SUPPRESS_WARNINGS_END -#if defined __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wmissing-prototypes" -#endif - using boost::python::class_; using boost::python::def; using boost::python::init; diff --git a/pytest_utilities/src/cout_capture.cpp b/pytest_utilities/src/cout_capture.cpp index cdceb05..d661f0b 100644 --- a/pytest_utilities/src/cout_capture.cpp +++ b/pytest_utilities/src/cout_capture.cpp @@ -27,11 +27,6 @@ SUPPRESS_WARNINGS_BEGIN #include "boost/python.hpp" SUPPRESS_WARNINGS_END -#if defined __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wmissing-prototypes" -#endif - namespace test_utilities { class CoutCapture { @@ -60,7 +55,3 @@ BOOST_PYTHON_MODULE(pytest_utilities) { class_("CoutCapture") .def("ToString", &test_utilities::CoutCapture::ToString); } - -#if defined __clang__ -#pragma clang diagnostic pop -#endif From 6907ac6138d459640bb586f016c3a5114a63ff8b Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 29 Aug 2017 17:00:19 +0200 Subject: [PATCH 33/71] Rename to nest in situ vis Second step of renaming --- CMakeLists.txt | 10 ++--- LICENSE | 2 +- README.md | 4 +- cmake/ConfigureFiles.cmake | 9 ++--- cmake/WarningLevels.cmake | 9 ++--- cmake/catch.cmake | 10 ++--- cmake/cpplint.cmake | 2 +- ...pv-config.cmake.in => niv-config.cmake.in} | 22 +++++----- cmake/py.test.cmake | 4 +- cmake/suppress_warnings.hpp.in | 8 ++-- {npv => niv}/CMakeLists.txt | 40 +++++++++---------- .../include/niv/nest_in_situ_vis.hpp | 24 +++++------ .../npv/npv.hpp => niv/include/niv/niv.hpp | 12 +++--- .../src/nest_in_situ_vis.cpp | 38 +++++++++--------- npv/src/npv.cpp => niv/src/niv.cpp | 8 ++-- {npv => niv}/tests/CMakeLists.txt | 30 +++++++------- {npv => niv}/tests/catch/LICENSE.txt | 0 {npv => niv}/tests/catch/catch.hpp | 0 .../tests/src/test_nest_in_situ_vis.cpp | 17 ++++---- {npv => niv}/tests/src/tests.cpp | 2 +- .../tests/test_utilities/cout_capture.hpp | 8 ++-- .../tests/src/test_cout_capture.cpp | 2 +- {pynpv => pyniv}/CMakeLists.txt | 24 ++++++----- {pynpv => pyniv}/src/conduit_data.cpp | 8 ++-- {pynpv => pyniv}/src/conduit_data.hpp | 12 +++--- .../src/nest_in_situ_vis.cpp | 20 +++++----- pynpv/src/pynpv.cpp => pyniv/src/pyniv.cpp | 16 ++++---- pynpv/src/pynpv.hpp => pyniv/src/pyniv.hpp | 12 +++--- {pynpv => pyniv}/tests/CMakeLists.txt | 10 +++-- {pynpv => pyniv}/tests/src/test_pynpv.py | 26 ++++++------ pytest_utilities/CMakeLists.txt | 2 +- pytest_utilities/src/cout_capture.cpp | 2 +- 32 files changed, 195 insertions(+), 198 deletions(-) rename cmake/{npv-config.cmake.in => niv-config.cmake.in} (72%) rename {npv => niv}/CMakeLists.txt (68%) rename npv/include/npv/nest_python_vis.hpp => niv/include/niv/nest_in_situ_vis.hpp (81%) rename npv/include/npv/npv.hpp => niv/include/niv/niv.hpp (86%) rename npv/src/nest_python_vis.cpp => niv/src/nest_in_situ_vis.cpp (64%) rename npv/src/npv.cpp => niv/src/niv.cpp (92%) rename {npv => niv}/tests/CMakeLists.txt (63%) rename {npv => niv}/tests/catch/LICENSE.txt (100%) rename {npv => niv}/tests/catch/catch.hpp (100%) rename npv/tests/src/test_nest_python_vis.cpp => niv/tests/src/test_nest_in_situ_vis.cpp (87%) rename {npv => niv}/tests/src/tests.cpp (98%) rename {npv => niv}/tests/test_utilities/cout_capture.hpp (90%) rename {npv => niv}/tests/test_utilities/tests/src/test_cout_capture.cpp (99%) rename {pynpv => pyniv}/CMakeLists.txt (80%) rename {pynpv => pyniv}/src/conduit_data.cpp (93%) rename {pynpv => pyniv}/src/conduit_data.hpp (89%) rename pynpv/src/nest_python_vis.cpp => pyniv/src/nest_in_situ_vis.cpp (73%) rename pynpv/src/pynpv.cpp => pyniv/src/pyniv.cpp (80%) rename pynpv/src/pynpv.hpp => pyniv/src/pyniv.hpp (88%) rename {pynpv => pyniv}/tests/CMakeLists.txt (86%) rename {pynpv => pyniv}/tests/src/test_pynpv.py (77%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc846df..afc9c9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -19,9 +19,9 @@ # limitations under the License. #------------------------------------------------------------------------------- -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.8.2) -project(nest_python_vis) +project(nest_in_situ_vis) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(CMAKE_CXX_STANDARD 17) @@ -45,6 +45,6 @@ find_package(conduit) set_target_properties(conduit PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CONDUIT_INCLUDE_DIRS}/..") -add_subdirectory(npv) -add_subdirectory(pynpv) +add_subdirectory(niv) +add_subdirectory(pyniv) add_subdirectory(pytest_utilities) diff --git a/LICENSE b/LICENSE index 97c130c..8d73b9f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ -------------------------------------------------------------------------------- - nest python vis + nest in situ vis Copyright (c) 2017 RWTH Aachen University, Germany, Virtual Reality & Immersive Visualisation Group. diff --git a/README.md b/README.md index 0423d5f..1f1406b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# nest python vis +# nest in situ vis -*Project Phoenix* is Copyright (c) 2017 RWTH Aachen University, Germany, +*nest in situ vis* is Copyright (c) 2017 RWTH Aachen University, Germany, Virtual Reality & Immersive Visualization Group. diff --git a/cmake/ConfigureFiles.cmake b/cmake/ConfigureFiles.cmake index 01b3872..a3594b7 100644 --- a/cmake/ConfigureFiles.cmake +++ b/cmake/ConfigureFiles.cmake @@ -1,17 +1,16 @@ #------------------------------------------------------------------------------- -# Project Phoenix +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. #------------------------------------------------------------------------------- -# License -# only for this file +# License # -# Licensed under the 3-Clause BSD License (the "License"); +# Licensed 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 # -# https://opensource.org/licenses/BSD-3-Clause +# 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, diff --git a/cmake/WarningLevels.cmake b/cmake/WarningLevels.cmake index 7261b96..75bad0c 100644 --- a/cmake/WarningLevels.cmake +++ b/cmake/WarningLevels.cmake @@ -1,17 +1,16 @@ #------------------------------------------------------------------------------- -# Project Phoenix +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. #------------------------------------------------------------------------------- -# License -# only for this file +# License # -# Licensed under the 3-Clause BSD License (the "License"); +# Licensed 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 # -# https://opensource.org/licenses/BSD-3-Clause +# 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, diff --git a/cmake/catch.cmake b/cmake/catch.cmake index 95c7343..4e29d15 100644 --- a/cmake/catch.cmake +++ b/cmake/catch.cmake @@ -1,17 +1,16 @@ #------------------------------------------------------------------------------- -# Project Phoenix +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. #------------------------------------------------------------------------------- -# License -# only for this file +# License # -# Licensed under the 3-Clause BSD License (the "License"); +# Licensed 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 # -# https://opensource.org/licenses/BSD-3-Clause +# 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, @@ -22,6 +21,7 @@ include(WarningLevels) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) diff --git a/cmake/cpplint.cmake b/cmake/cpplint.cmake index 87ddd6a..9856c1c 100644 --- a/cmake/cpplint.cmake +++ b/cmake/cpplint.cmake @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. diff --git a/cmake/npv-config.cmake.in b/cmake/niv-config.cmake.in similarity index 72% rename from cmake/npv-config.cmake.in rename to cmake/niv-config.cmake.in index 60012b5..f74c3c7 100644 --- a/cmake/npv-config.cmake.in +++ b/cmake/niv-config.cmake.in @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -19,21 +19,19 @@ # limitations under the License. #------------------------------------------------------------------------------- - - -# - Config file for the npv package +# - Config file for the niv package # It defines the following variables -# NPV_INCLUDE_DIRS - include directories for Project Phoenix -# NPV_LIBRARIES - libraries to link against +# NIV_INCLUDE_DIRS - include directories for nest in situ vis +# NIV_LIBRARIES - libraries to link against # Compute paths -get_filename_component(NPV_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -set(NPV_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") +get_filename_component(NIV_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(NIV_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") # Our library dependencies (contains definitions for IMPORTED targets) -if(NOT TARGET npv) - include("${NPV_CMAKE_DIR}/npv-targets.cmake") +if(NOT TARGET niv) + include("${NIV_CMAKE_DIR}/niv-targets.cmake") endif() -# These are IMPORTED targets created by npv-targets.cmake -set(NPV_LIBRARIES npv) +# These are IMPORTED targets created by niv-targets.cmake +set(NIV_LIBRARIES niv) diff --git a/cmake/py.test.cmake b/cmake/py.test.cmake index e07be20..6246b5a 100644 --- a/cmake/py.test.cmake +++ b/cmake/py.test.cmake @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -19,8 +19,6 @@ # limitations under the License. #------------------------------------------------------------------------------- - - include(FindPythonInterp) if(NOT PYTHON_EXECUTABLE) message(SEND_ERROR diff --git a/cmake/suppress_warnings.hpp.in b/cmake/suppress_warnings.hpp.in index ed997f4..70c97e0 100644 --- a/cmake/suppress_warnings.hpp.in +++ b/cmake/suppress_warnings.hpp.in @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Project Phoenix +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,8 +19,8 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef PROJECT_PHOENIX_SUPPRESS_WARNINGS_ -#define PROJECT_PHOENIX_SUPPRESS_WARNINGS_ +#ifndef NEST_IN_SITU_VIS_SUPPRESS_WARNINGS_ +#define NEST_IN_SITU_VIS_SUPPRESS_WARNINGS_ #if defined __clang__ #define SUPPRESS_WARNINGS_BEGIN \ @@ -43,4 +43,4 @@ #endif -#endif // PROJECT_PHOENIX_SUPPRESS_WARNINGS_ +#endif // NEST_IN_SITU_VIS_SUPPRESS_WARNINGS_ diff --git a/npv/CMakeLists.txt b/niv/CMakeLists.txt similarity index 68% rename from npv/CMakeLists.txt rename to niv/CMakeLists.txt index d8fee85..942338e 100644 --- a/npv/CMakeLists.txt +++ b/niv/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -19,37 +19,37 @@ # limitations under the License. #------------------------------------------------------------------------------- -file(GLOB NPV_SOURCES src/*.cpp) -file(GLOB NPV_HEADERS src/*.hpp) -file(GLOB NPV_API_HEADERS include/npv/*.hpp) +file(GLOB NIV_SOURCES src/*.cpp) +file(GLOB NIV_HEADERS src/*.hpp) +file(GLOB NIV_API_HEADERS include/niv/*.hpp) -add_library(npv - ${NPV_SOURCES} - ${NPV_HEADERS} - ${NPV_API_HEADERS} -) -target_include_directories(npv +add_library(niv + ${NIV_SOURCES} + ${NIV_HEADERS} + ${NIV_API_HEADERS} + ) +target_include_directories(niv PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ) -target_link_libraries(npv +target_link_libraries(niv conduit ) -generate_export_header(npv - EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/include/npv/export.hpp +generate_export_header(niv + EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/include/niv/export.hpp ) -set_warning_levels_RWTH(npv - SUPPRESS_WARNINGS_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/npv/suppress_warnings.hpp +set_warning_levels_RWTH(niv + SUPPRESS_WARNINGS_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/niv/suppress_warnings.hpp ) -add_test_cpplint(NAME "npv--cpplint" - ${NPV_SOURCES} - ${NPV_HEADERS} - ${NPV_API_HEADERS} +add_test_cpplint(NAME "niv--cpplint" + ${NIV_SOURCES} + ${NIV_HEADERS} + ${NIV_API_HEADERS} ) -generate_configure_files(npv) +generate_configure_files(niv) add_subdirectory(tests) diff --git a/npv/include/npv/nest_python_vis.hpp b/niv/include/niv/nest_in_situ_vis.hpp similarity index 81% rename from npv/include/npv/nest_python_vis.hpp rename to niv/include/niv/nest_in_situ_vis.hpp index 01e0a18..3117e5b 100644 --- a/npv/include/npv/nest_python_vis.hpp +++ b/niv/include/niv/nest_in_situ_vis.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,8 +19,8 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef NPV_INCLUDE_NPV_NEST_PYTHON_VIS_HPP_ -#define NPV_INCLUDE_NPV_NEST_PYTHON_VIS_HPP_ +#ifndef NIV_INCLUDE_NIV_NEST_IN_SITU_VIS_HPP_ +#define NIV_INCLUDE_NIV_NEST_IN_SITU_VIS_HPP_ #include #include @@ -32,14 +32,14 @@ // gcc-5 does not accept using std::chrono_literals::operator""ms; using namespace std::literals::chrono_literals; // NOLINT -namespace npv { +namespace niv { -class NestPythonVis { +class NestInSituVis { public: - explicit NestPythonVis(conduit::Node* node = nullptr); - explicit NestPythonVis(std::size_t ptr_to_node); - ~NestPythonVis(); - NestPythonVis(const NestPythonVis&) = delete; + explicit NestInSituVis(conduit::Node* node = nullptr); + explicit NestInSituVis(std::size_t ptr_to_node); + ~NestInSituVis(); + NestInSituVis(const NestInSituVis&) = delete; void Start(); void Stop(); @@ -56,7 +56,7 @@ class NestPythonVis { void Step(); void Sleep() { std::this_thread::sleep_for(sleep_in_use_); } void SpawnThread() { - thread_ = std::make_unique(&NestPythonVis::Run, this); + thread_ = std::make_unique(&NestInSituVis::Run, this); } void JoinAndDeleteThread() { if (thread_ != nullptr) { @@ -72,6 +72,6 @@ class NestPythonVis { std::chrono::duration sleep_in_use_{disabled_sleep_}; }; -} // namespace npv +} // namespace niv -#endif // NPV_INCLUDE_NPV_NEST_PYTHON_VIS_HPP_ +#endif // NIV_INCLUDE_NIV_NEST_IN_SITU_VIS_HPP_ diff --git a/npv/include/npv/npv.hpp b/niv/include/niv/niv.hpp similarity index 86% rename from npv/include/npv/npv.hpp rename to niv/include/niv/niv.hpp index e899831..6cce4f0 100644 --- a/npv/include/npv/npv.hpp +++ b/niv/include/niv/niv.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,13 +19,13 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef NPV_INCLUDE_NPV_NPV_HPP_ -#define NPV_INCLUDE_NPV_NPV_HPP_ +#ifndef NIV_INCLUDE_NIV_NIV_HPP_ +#define NIV_INCLUDE_NIV_NIV_HPP_ -namespace npv { +namespace niv { char const* Greet(); -} // namespace npv +} // namespace niv -#endif // NPV_INCLUDE_NPV_NPV_HPP_ +#endif // NIV_INCLUDE_NIV_NIV_HPP_ diff --git a/npv/src/nest_python_vis.cpp b/niv/src/nest_in_situ_vis.cpp similarity index 64% rename from npv/src/nest_python_vis.cpp rename to niv/src/nest_in_situ_vis.cpp index 8960340..b7e0078 100644 --- a/npv/src/nest_python_vis.cpp +++ b/niv/src/nest_in_situ_vis.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,64 +19,64 @@ // limitations under the License. //------------------------------------------------------------------------------ -#include "npv/nest_python_vis.hpp" +#include "niv/nest_in_situ_vis.hpp" #include #include #include -namespace npv { +namespace niv { -constexpr std::chrono::duration NestPythonVis::disabled_sleep_; +constexpr std::chrono::duration NestInSituVis::disabled_sleep_; -NestPythonVis::NestPythonVis(conduit::Node* node) : node_(node) {} +NestInSituVis::NestInSituVis(conduit::Node* node) : node_(node) {} -NestPythonVis::NestPythonVis(std::size_t ptr_to_node) - : NestPythonVis(reinterpret_cast(ptr_to_node)) {} +NestInSituVis::NestInSituVis(std::size_t ptr_to_node) + : NestInSituVis(reinterpret_cast(ptr_to_node)) {} -NestPythonVis::~NestPythonVis() { JoinAndDeleteThread(); } +NestInSituVis::~NestInSituVis() { JoinAndDeleteThread(); } -void NestPythonVis::Start() { +void NestInSituVis::Start() { EnableIsRunning(); SpawnThread(); } -void NestPythonVis::EnableIsRunning() { sleep_in_use_ = configured_sleep_; } +void NestInSituVis::EnableIsRunning() { sleep_in_use_ = configured_sleep_; } -void NestPythonVis::DisableIsRunning() { sleep_in_use_ = disabled_sleep_; } +void NestInSituVis::DisableIsRunning() { sleep_in_use_ = disabled_sleep_; } -bool NestPythonVis::IsRunning() const { +bool NestInSituVis::IsRunning() const { return sleep_in_use_ != disabled_sleep_; } -void NestPythonVis::Stop() { +void NestInSituVis::Stop() { DisableIsRunning(); JoinAndDeleteThread(); } -void NestPythonVis::Run() { +void NestInSituVis::Run() { while (IsRunning()) { Step(); } } -void NestPythonVis::Step() { +void NestInSituVis::Step() { PrintNode(); Sleep(); } -void NestPythonVis::PrintNode() const { +void NestInSituVis::PrintNode() const { std::cout << NodeString() << std::endl; } -std::string NestPythonVis::NodeString() const { +std::string NestInSituVis::NodeString() const { return node_ == nullptr ? "nullptr" : FormatNode(); } -std::string NestPythonVis::FormatNode() const { +std::string NestInSituVis::FormatNode() const { std::ostringstream sstr; sstr << (*node_)["V_m"].as_double(); return sstr.str(); } -} // namespace npv +} // namespace niv diff --git a/npv/src/npv.cpp b/niv/src/niv.cpp similarity index 92% rename from npv/src/npv.cpp rename to niv/src/niv.cpp index 61e7b6e..5174553 100644 --- a/npv/src/npv.cpp +++ b/niv/src/niv.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,10 +19,10 @@ // limitations under the License. //------------------------------------------------------------------------------ -#include "npv/npv.hpp" +#include "niv/niv.hpp" -namespace npv { +namespace niv { char const* Greet() { return "G'day!"; } -} // namespace npv +} // namespace niv diff --git a/npv/tests/CMakeLists.txt b/niv/tests/CMakeLists.txt similarity index 63% rename from npv/tests/CMakeLists.txt rename to niv/tests/CMakeLists.txt index 6875481..a784e4d 100644 --- a/npv/tests/CMakeLists.txt +++ b/niv/tests/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -19,24 +19,24 @@ # limitations under the License. #------------------------------------------------------------------------------- -file(GLOB NPV_TEST_SOURCES src/*.cpp) -file(GLOB NPV_TEST_HEADERS src/*.hpp) -file(GLOB NPV_TEST_UTILITIES_TEST_SOURCES test_utilities/tests/src/*.cpp) -file(GLOB NPV_TEST_UTILITIES_HEADERS test_utilities/*.hpp) +file(GLOB NIV_TEST_SOURCES src/*.cpp) +file(GLOB NIV_TEST_HEADERS src/*.hpp) +file(GLOB NIV_TEST_UTILITIES_TEST_SOURCES test_utilities/tests/src/*.cpp) +file(GLOB NIV_TEST_UTILITIES_HEADERS test_utilities/*.hpp) -add_test_catch(NAME "NPV-tests" - SOURCES ${NPV_TEST_SOURCES} ${NPV_TEST_UTILITIES_TEST_SOURCES} - HEADERS ${NPV_TEST_HEADERS} ${NPV_TEST_UTILITIES_HEADERS} +add_test_catch(NAME "niv-tests" + SOURCES ${NIV_TEST_SOURCES} ${NIV_TEST_UTILITIES_TEST_SOURCES} + HEADERS ${NIV_TEST_HEADERS} ${NIV_TEST_UTILITIES_HEADERS} CATCH_MAIN src/tests.cpp INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} - LINK_LIBRARIES npv - PATH_TO_ADD ${PROJECT_BINARY_DIR}/npv + LINK_LIBRARIES niv + PATH_TO_ADD ${PROJECT_BINARY_DIR}/niv ) -add_test_cpplint(NAME "npv-tests--cpplint" - ${NPV_TEST_SOURCES} - ${NPV_TEST_HEADERS} - ${NPV_TEST_UTILITIES_TEST_SOURCES} - ${NPV_TEST_UTILITIES_HEADERS} +add_test_cpplint(NAME "niv-tests--cpplint" + ${NIV_TEST_SOURCES} + ${NIV_TEST_HEADERS} + ${NIV_TEST_UTILITIES_TEST_SOURCES} + ${NIV_TEST_UTILITIES_HEADERS} ) diff --git a/npv/tests/catch/LICENSE.txt b/niv/tests/catch/LICENSE.txt similarity index 100% rename from npv/tests/catch/LICENSE.txt rename to niv/tests/catch/LICENSE.txt diff --git a/npv/tests/catch/catch.hpp b/niv/tests/catch/catch.hpp similarity index 100% rename from npv/tests/catch/catch.hpp rename to niv/tests/catch/catch.hpp diff --git a/npv/tests/src/test_nest_python_vis.cpp b/niv/tests/src/test_nest_in_situ_vis.cpp similarity index 87% rename from npv/tests/src/test_nest_python_vis.cpp rename to niv/tests/src/test_nest_in_situ_vis.cpp index b0e4df6..7328522 100644 --- a/npv/tests/src/test_nest_python_vis.cpp +++ b/niv/tests/src/test_nest_in_situ_vis.cpp @@ -1,6 +1,5 @@ - //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -29,21 +28,21 @@ #include "conduit/conduit.hpp" -#include "npv/nest_python_vis.hpp" +#include "niv/nest_in_situ_vis.hpp" #include "test_utilities/cout_capture.hpp" // gcc-5 does not accept using std::chrono_literals::operator""ms; using namespace std::literals::chrono_literals; // NOLINT -SCENARIO("An npv object shall visualize the double it is bound to", - "[npv][npv::NestPythonVis") { +SCENARIO("An niv object shall visualize the double it is bound to", + "[niv][niv::NestInSituVis") { GIVEN( - "A membrane potenial in a conduit node and A NestPythonVis " + "A membrane potenial in a conduit node and A NestInSituVis " "object") { conduit::Node node; node["V_m"] = 0.0; - npv::NestPythonVis vis(&node); + niv::NestInSituVis vis(&node); WHEN("I ask for a string representing the value") { auto ret_node = vis.NodeString(); @@ -73,8 +72,8 @@ SCENARIO("An npv object shall visualize the double it is bound to", } } - GIVEN("A NestPythonVis object bound to nullptr") { - npv::NestPythonVis vis(nullptr); + GIVEN("A NestInSituVis object bound to nullptr") { + niv::NestInSituVis vis(nullptr); WHEN("I ask for a string representing tha value") { auto ret_val = vis.NodeString(); THEN("it shall read 'nullptr'.") { REQUIRE(ret_val == "nullptr"); } diff --git a/npv/tests/src/tests.cpp b/niv/tests/src/tests.cpp similarity index 98% rename from npv/tests/src/tests.cpp rename to niv/tests/src/tests.cpp index 890f1ae..f45a0ae 100644 --- a/npv/tests/src/tests.cpp +++ b/niv/tests/src/tests.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. diff --git a/npv/tests/test_utilities/cout_capture.hpp b/niv/tests/test_utilities/cout_capture.hpp similarity index 90% rename from npv/tests/test_utilities/cout_capture.hpp rename to niv/tests/test_utilities/cout_capture.hpp index a52a9cf..b5fbb7d 100644 --- a/npv/tests/test_utilities/cout_capture.hpp +++ b/niv/tests/test_utilities/cout_capture.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,8 +19,8 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef NPV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ -#define NPV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ +#ifndef NIV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ +#define NIV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ #include #include @@ -59,4 +59,4 @@ struct StringMaker { } // namespace Catch -#endif // NPV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ +#endif // NIV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ diff --git a/npv/tests/test_utilities/tests/src/test_cout_capture.cpp b/niv/tests/test_utilities/tests/src/test_cout_capture.cpp similarity index 99% rename from npv/tests/test_utilities/tests/src/test_cout_capture.cpp rename to niv/tests/test_utilities/tests/src/test_cout_capture.cpp index ae70b70..b306734 100644 --- a/npv/tests/test_utilities/tests/src/test_cout_capture.cpp +++ b/niv/tests/test_utilities/tests/src/test_cout_capture.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. diff --git a/pynpv/CMakeLists.txt b/pyniv/CMakeLists.txt similarity index 80% rename from pynpv/CMakeLists.txt rename to pyniv/CMakeLists.txt index a20be62..6bdce94 100644 --- a/pynpv/CMakeLists.txt +++ b/pyniv/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -19,32 +19,34 @@ # limitations under the License. #------------------------------------------------------------------------------- -file(GLOB PYNPV_SOURCES src/*.cpp) + + +file(GLOB PYNIV_SOURCES src/*.cpp) find_package(Boost REQUIRED COMPONENTS python) find_package(PythonInterp) find_package(PythonLibs) -python_add_module(pynpv - ${PYNPV_SOURCES} +python_add_module(pyniv + ${PYNIV_SOURCES} ) -target_link_libraries(pynpv npv) +target_link_libraries(pyniv niv) -target_include_directories(pynpv +target_include_directories(pyniv PRIVATE ${Boost_INCLUDE_DIRS} PRIVATE ${PYTHON_INCLUDE_DIRS} ) -target_link_libraries(pynpv +target_link_libraries(pyniv ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ) -set_warning_levels_RWTH(pynpv - SUPPRESS_WARNINGS_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/pynpv/suppress_warnings.hpp +set_warning_levels_RWTH(pyniv + SUPPRESS_WARNINGS_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/pyniv/suppress_warnings.hpp ) -add_test_cpplint(NAME "pynpv--cpplint" - ${PYNPV_SOURCES} +add_test_cpplint(NAME "pyniv--cpplint" + ${PYNIV_SOURCES} ) add_subdirectory(tests) diff --git a/pynpv/src/conduit_data.cpp b/pyniv/src/conduit_data.cpp similarity index 93% rename from pynpv/src/conduit_data.cpp rename to pyniv/src/conduit_data.cpp index 5d05d05..ca573a0 100644 --- a/pynpv/src/conduit_data.cpp +++ b/pyniv/src/conduit_data.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -20,9 +20,9 @@ //------------------------------------------------------------------------------ #include "conduit_data.hpp" -#include "pynpv.hpp" +#include "pyniv.hpp" -namespace pynpv { +namespace pyniv { template <> void expose() { @@ -31,4 +31,4 @@ void expose() { .def("Pointer", &ConduitData::Pointer); } -} // namespace pynpv +} // namespace pyniv diff --git a/pynpv/src/conduit_data.hpp b/pyniv/src/conduit_data.hpp similarity index 89% rename from pynpv/src/conduit_data.hpp rename to pyniv/src/conduit_data.hpp index 7b692b7..b1cbc8f 100644 --- a/pynpv/src/conduit_data.hpp +++ b/pyniv/src/conduit_data.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,12 +19,12 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef PYNPV_SRC_CONDUIT_DATA_HPP_ -#define PYNPV_SRC_CONDUIT_DATA_HPP_ +#ifndef PYNIV_SRC_CONDUIT_DATA_HPP_ +#define PYNIV_SRC_CONDUIT_DATA_HPP_ #include "conduit/conduit.hpp" -namespace pynpv { +namespace pyniv { class ConduitData { public: @@ -43,6 +43,6 @@ class ConduitData { conduit::Node node_; }; -} // namespace pynpv +} // namespace pyniv -#endif // PYNPV_SRC_CONDUIT_DATA_HPP_ +#endif // PYNIV_SRC_CONDUIT_DATA_HPP_ diff --git a/pynpv/src/nest_python_vis.cpp b/pyniv/src/nest_in_situ_vis.cpp similarity index 73% rename from pynpv/src/nest_python_vis.cpp rename to pyniv/src/nest_in_situ_vis.cpp index 711ce31..0e76d0a 100644 --- a/pynpv/src/nest_python_vis.cpp +++ b/pyniv/src/nest_in_situ_vis.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,19 +19,19 @@ // limitations under the License. //------------------------------------------------------------------------------ -#include "npv/nest_python_vis.hpp" +#include "niv/nest_in_situ_vis.hpp" -#include "pynpv.hpp" +#include "pyniv.hpp" -namespace pynpv { +namespace pyniv { template <> -void expose() { - class_("NestPythonVis", +void expose() { + class_("NestInSituVis", init()) - .def("NodeString", &npv::NestPythonVis::NodeString) - .def("Start", &npv::NestPythonVis::Start) - .def("Stop", &npv::NestPythonVis::Stop); + .def("NodeString", &niv::NestInSituVis::NodeString) + .def("Start", &niv::NestInSituVis::Start) + .def("Stop", &niv::NestInSituVis::Stop); } -} // namespace pynpv +} // namespace pyniv diff --git a/pynpv/src/pynpv.cpp b/pyniv/src/pyniv.cpp similarity index 80% rename from pynpv/src/pynpv.cpp rename to pyniv/src/pyniv.cpp index 851a305..d1cf0db 100644 --- a/pynpv/src/pynpv.cpp +++ b/pyniv/src/pyniv.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,15 +19,15 @@ // limitations under the License. //------------------------------------------------------------------------------ -#include "pynpv.hpp" +#include "pyniv.hpp" -#include "npv/nest_python_vis.hpp" -#include "npv/npv.hpp" +#include "niv/nest_in_situ_vis.hpp" +#include "niv/niv.hpp" #include "conduit_data.hpp" -BOOST_PYTHON_MODULE(pynpv) { - def("Greet", npv::Greet); - pynpv::expose(); - pynpv::expose(); +BOOST_PYTHON_MODULE(pyniv) { + def("Greet", niv::Greet); + pyniv::expose(); + pyniv::expose(); } diff --git a/pynpv/src/pynpv.hpp b/pyniv/src/pyniv.hpp similarity index 88% rename from pynpv/src/pynpv.hpp rename to pyniv/src/pyniv.hpp index a584076..6defd1e 100644 --- a/pynpv/src/pynpv.hpp +++ b/pyniv/src/pyniv.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,8 +19,8 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef PYNPV_SRC_PYNPV_HPP_ -#define PYNPV_SRC_PYNPV_HPP_ +#ifndef PYNIV_SRC_PYNIV_HPP_ +#define PYNIV_SRC_PYNIV_HPP_ SUPPRESS_WARNINGS_BEGIN #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -31,11 +31,11 @@ using boost::python::class_; using boost::python::def; using boost::python::init; -namespace pynpv { +namespace pyniv { template void expose(); -} // namespace pynpv +} // namespace pyniv -#endif // PYNPV_SRC_PYNPV_HPP_ +#endif // PYNIV_SRC_PYNIV_HPP_ diff --git a/pynpv/tests/CMakeLists.txt b/pyniv/tests/CMakeLists.txt similarity index 86% rename from pynpv/tests/CMakeLists.txt rename to pyniv/tests/CMakeLists.txt index 7b62c46..dcf1703 100644 --- a/pynpv/tests/CMakeLists.txt +++ b/pyniv/tests/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -19,9 +19,11 @@ # limitations under the License. #------------------------------------------------------------------------------- -file(GLOB PYNPV_TEST_SOURCES src/*.py) -add_test_py_test(NAME test_pynpv + +file(GLOB PYNIV_TEST_SOURCES src/*.py) + +add_test_py_test(NAME test_pyniv ${CMAKE_CURRENT_SOURCE_DIR} - PYTHONPATH "$:$" + PYTHONPATH "$:$" ) diff --git a/pynpv/tests/src/test_pynpv.py b/pyniv/tests/src/test_pynpv.py similarity index 77% rename from pynpv/tests/src/test_pynpv.py rename to pyniv/tests/src/test_pynpv.py index e1fbf71..4dfcdfa 100644 --- a/pynpv/tests/src/test_pynpv.py +++ b/pyniv/tests/src/test_pynpv.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -23,7 +23,7 @@ import sys import time -import pynpv +import pyniv import pytest_utilities @@ -40,23 +40,23 @@ def test_cout_capture(capsys): out, err = capsys.readouterr() assert out == "next\n" -def test_pynpv_greet(): - assert pynpv.Greet() == "G'day!" +def test_pyniv_greet(): + assert pyniv.Greet() == "G'day!" -def test_pynpv_npv_NodeString_zero_on_creation(): - d = pynpv.ConduitData(); - v = pynpv.NestPythonVis(d.Pointer()); +def test_pyniv_niv_NodeString_zero_on_creation(): + d = pyniv.ConduitData(); + v = pyniv.NestInSituVis(d.Pointer()); assert v.NodeString() == "0" -def test_pynpv_npv_NodeString_correct_after_set(): - d = pynpv.ConduitData(); - v = pynpv.NestPythonVis(d.Pointer()); +def test_pyniv_niv_NodeString_correct_after_set(): + d = pyniv.ConduitData(); + v = pyniv.NestInSituVis(d.Pointer()); d.Set("V_m", 42.0) assert v.NodeString() == "42" -def test_pynpv_npv_StartStop(): - d = pynpv.ConduitData(); - v = pynpv.NestPythonVis(d.Pointer()); +def test_pyniv_niv_StartStop(): + d = pyniv.ConduitData(); + v = pyniv.NestInSituVis(d.Pointer()); d.Set("V_m", 42.0) c = pytest_utilities.CoutCapture() diff --git a/pytest_utilities/CMakeLists.txt b/pytest_utilities/CMakeLists.txt index 2d65de4..acecd98 100644 --- a/pytest_utilities/CMakeLists.txt +++ b/pytest_utilities/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. diff --git a/pytest_utilities/src/cout_capture.cpp b/pytest_utilities/src/cout_capture.cpp index d661f0b..65fc1b3 100644 --- a/pytest_utilities/src/cout_capture.cpp +++ b/pytest_utilities/src/cout_capture.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. From ffaf3e29cb6d1a13fd90fc3d51c2af2258552545 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 29 Aug 2017 17:16:39 +0200 Subject: [PATCH 34/71] Refactor --- pyniv/src/conduit_data.cpp | 16 ++++++++++++++++ pyniv/src/conduit_data.hpp | 9 +++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pyniv/src/conduit_data.cpp b/pyniv/src/conduit_data.cpp index ca573a0..e9cb6f2 100644 --- a/pyniv/src/conduit_data.cpp +++ b/pyniv/src/conduit_data.cpp @@ -20,10 +20,26 @@ //------------------------------------------------------------------------------ #include "conduit_data.hpp" + +#include + #include "pyniv.hpp" namespace pyniv { +ConduitData::ConduitData() { + node_["V_m"] = 0.0; + std::cout << "Ptr. to conduit node: " << Pointer() << std::endl; +} + +void ConduitData::Set(const char* attribute, double value) { + node_[attribute] = value; +} + +std::size_t ConduitData::Pointer() const { + return reinterpret_cast(&node_); +} + template <> void expose() { class_("ConduitData") diff --git a/pyniv/src/conduit_data.hpp b/pyniv/src/conduit_data.hpp index b1cbc8f..5b0252d 100644 --- a/pyniv/src/conduit_data.hpp +++ b/pyniv/src/conduit_data.hpp @@ -28,16 +28,13 @@ namespace pyniv { class ConduitData { public: - ConduitData() { - node_["V_m"] = 0.0; - std::cout << "Ptr. to conduit node: " << Pointer() << std::endl; - } + ConduitData(); ~ConduitData() = default; ConduitData(const ConduitData&) = default; ConduitData(ConduitData&&) = default; - void Set(const char* attribute, double value) { node_[attribute] = value; } - std::size_t Pointer() const { return reinterpret_cast(&node_); } + void Set(const char* attribute, double value); + std::size_t Pointer() const; private: conduit::Node node_; From 867af0257a83b28856728bcc5e245a8f56dc8906 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 30 Aug 2017 07:47:09 +0200 Subject: [PATCH 35/71] Add function to read data --- niv/include/niv/nest_in_situ_vis.hpp | 2 ++ niv/src/nest_in_situ_vis.cpp | 6 +++++ niv/tests/src/test_nest_in_situ_vis.cpp | 30 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/niv/include/niv/nest_in_situ_vis.hpp b/niv/include/niv/nest_in_situ_vis.hpp index 3117e5b..aca5339 100644 --- a/niv/include/niv/nest_in_situ_vis.hpp +++ b/niv/include/niv/nest_in_situ_vis.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "conduit/conduit.hpp" @@ -45,6 +46,7 @@ class NestInSituVis { void Stop(); std::string NodeString() const; + void Read(const conduit::Schema& schema, std::vector* data); private: void PrintNode() const; diff --git a/niv/src/nest_in_situ_vis.cpp b/niv/src/nest_in_situ_vis.cpp index b7e0078..79aa470 100644 --- a/niv/src/nest_in_situ_vis.cpp +++ b/niv/src/nest_in_situ_vis.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace niv { @@ -79,4 +80,9 @@ std::string NestInSituVis::FormatNode() const { return sstr.str(); } +void NestInSituVis::Read(const conduit::Schema& schema, + std::vector* data) { + node_->set_external(schema, data->data()); +} + } // namespace niv diff --git a/niv/tests/src/test_nest_in_situ_vis.cpp b/niv/tests/src/test_nest_in_situ_vis.cpp index 7328522..72345b4 100644 --- a/niv/tests/src/test_nest_in_situ_vis.cpp +++ b/niv/tests/src/test_nest_in_situ_vis.cpp @@ -19,10 +19,13 @@ // limitations under the License. //------------------------------------------------------------------------------ +#include + #include #include #include #include +#include #include "catch/catch.hpp" @@ -70,6 +73,33 @@ SCENARIO("An niv object shall visualize the double it is bound to", REQUIRE(num_linebreaks > 1); } } + + GIVEN("A vector for buffering data") { + std::vector data; + THEN("the buffer is empty") { REQUIRE(data.size() == 0); } + WHEN("When I ask the node to serialize into the buffer") { + node.serialize(data); + THEN("there is data in it") { REQUIRE(data.size() > 0); } + } + } + + GIVEN("Another node and a buffer") { + conduit::Node another_node; + another_node["V_m"] = 3.1415926; + std::vector data; + WHEN( + "I serialize another node into the buffer and read the buffer into " + "the visualization") { + another_node.serialize(data); + conduit::Schema schema; + another_node.schema().compact_to(schema); + + vis.Read(schema, &data); + THEN("the first node will have acquired the data") { + REQUIRE(node["V_m"].as_double() == Approx(3.1415926)); + } + } + } } GIVEN("A NestInSituVis object bound to nullptr") { From 90025b9a5d1ffdf1a12aaeeab05c6354deb442ae Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 30 Aug 2017 16:41:24 +0200 Subject: [PATCH 36/71] Move dependencies to top-level CMakeLists --- CMakeLists.txt | 5 +++++ pyniv/CMakeLists.txt | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index afc9c9f..b48f641 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,11 @@ project(nest_in_situ_vis) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(CMAKE_CXX_STANDARD 17) +find_package(Boost REQUIRED COMPONENTS python) + +find_package(PythonInterp) +find_package(PythonLibs) + include(catch) include(ConfigureFiles) diff --git a/pyniv/CMakeLists.txt b/pyniv/CMakeLists.txt index 6bdce94..fbce4ef 100644 --- a/pyniv/CMakeLists.txt +++ b/pyniv/CMakeLists.txt @@ -23,10 +23,6 @@ file(GLOB PYNIV_SOURCES src/*.cpp) -find_package(Boost REQUIRED COMPONENTS python) -find_package(PythonInterp) -find_package(PythonLibs) - python_add_module(pyniv ${PYNIV_SOURCES} ) From 9796707c01a5ce60723991286604690226972097 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 30 Aug 2017 16:42:17 +0200 Subject: [PATCH 37/71] Add shared memory class --- niv/include/niv/shared_memory.hpp | 59 ++++++++++++++++++++++++++++ niv/src/shared_memory.cpp | 44 +++++++++++++++++++++ niv/tests/src/test_shared_memory.cpp | 51 ++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 niv/include/niv/shared_memory.hpp create mode 100644 niv/src/shared_memory.cpp create mode 100644 niv/tests/src/test_shared_memory.cpp diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp new file mode 100644 index 0000000..486f00d --- /dev/null +++ b/niv/include/niv/shared_memory.hpp @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 NIV_INCLUDE_NIV_SHARED_MEMORY_HPP_ +#define NIV_INCLUDE_NIV_SHARED_MEMORY_HPP_ + +#include + +#include + +#include "boost/interprocess/allocators/allocator.hpp" +#include "boost/interprocess/managed_shared_memory.hpp" + +#include "conduit/conduit_core.hpp" + +namespace niv { + +class SharedMemory { + public: + using ManagedSharedMemory = boost::interprocess::managed_shared_memory; + using Allocator = + boost::interprocess::allocator; + using DataVector = std::vector; + + static constexpr std::size_t kInitialSize{65536u}; + + SharedMemory(); + ~SharedMemory(); + + std::size_t GetFreeSize() const { return segment_.get_free_memory(); } + DataVector& GetDataVector(); + + private: + ManagedSharedMemory segment_; + const Allocator allocator_; + DataVector* data_vector_; +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_SHARED_MEMORY_HPP_ diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp new file mode 100644 index 0000000..0c410b9 --- /dev/null +++ b/niv/src/shared_memory.cpp @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "niv/shared_memory.hpp" + +#include + +namespace niv { + +constexpr std::size_t SharedMemory::kInitialSize; + +SharedMemory::SharedMemory() + : segment_{boost::interprocess::create_only, "niv-shared-memory", + kInitialSize}, + allocator_{segment_.get_segment_manager()}, + data_vector_(segment_.construct("DataVector")(allocator_)) {} + +SharedMemory::~SharedMemory() { + boost::interprocess::shared_memory_object::remove("niv-shared-memory"); +} + +SharedMemory::DataVector& SharedMemory::GetDataVector() { + return *data_vector_; +} + +} // namespace niv diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory.cpp new file mode 100644 index 0000000..cae0b26 --- /dev/null +++ b/niv/tests/src/test_shared_memory.cpp @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "catch/catch.hpp" + +#include "niv/shared_memory.hpp" + +SCENARIO("Shared memory", "[niv][niv::SharedMemory]") { + GIVEN("A shared memory segment") { + niv::SharedMemory segment; + WHEN("I ask it for its free size") { + auto free_size_after_creation = segment.GetFreeSize(); + THEN("it is > 0") { REQUIRE(free_size_after_creation > 0); } + } + + WHEN("I request a data vector in that shared memory segment") { + auto data_vector = segment.GetDataVector(); + THEN("it is empty") { REQUIRE(data_vector.size() == 0); } + + WHEN("I add one data entry into the vector") { + auto free_size_before_push = segment.GetFreeSize(); + data_vector.push_back(conduit::uint8{9u}); + auto free_size_after_push = segment.GetFreeSize(); + THEN("I can retrieve it") { + REQUIRE(data_vector[0] == conduit::uint8{9u}); + } + THEN("we have less free space in the segment") { + REQUIRE(free_size_after_push < free_size_before_push); + } + } + } + } +} From cbbc531ec918808b503e512bd6a58aeacfabbb10 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Thu, 31 Aug 2017 07:03:30 +0200 Subject: [PATCH 38/71] Destroy DataVector on exit --- niv/src/shared_memory.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index 0c410b9..a664d11 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -34,6 +34,7 @@ SharedMemory::SharedMemory() data_vector_(segment_.construct("DataVector")(allocator_)) {} SharedMemory::~SharedMemory() { + segment_.destroy("DataVector"); boost::interprocess::shared_memory_object::remove("niv-shared-memory"); } From 14c1650528e53366a3e612c026d6c6b0bb1581dd Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Thu, 31 Aug 2017 07:03:45 +0200 Subject: [PATCH 39/71] Simplify creation of DataVector --- niv/include/niv/shared_memory.hpp | 6 +++--- niv/src/shared_memory.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp index 486f00d..e99eb82 100644 --- a/niv/include/niv/shared_memory.hpp +++ b/niv/include/niv/shared_memory.hpp @@ -36,9 +36,10 @@ namespace niv { class SharedMemory { public: using ManagedSharedMemory = boost::interprocess::managed_shared_memory; + template using Allocator = - boost::interprocess::allocator; - using DataVector = std::vector; + boost::interprocess::allocator; + using DataVector = std::vector>; static constexpr std::size_t kInitialSize{65536u}; @@ -50,7 +51,6 @@ class SharedMemory { private: ManagedSharedMemory segment_; - const Allocator allocator_; DataVector* data_vector_; }; diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index a664d11..5b17a4c 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -30,8 +30,8 @@ constexpr std::size_t SharedMemory::kInitialSize; SharedMemory::SharedMemory() : segment_{boost::interprocess::create_only, "niv-shared-memory", kInitialSize}, - allocator_{segment_.get_segment_manager()}, - data_vector_(segment_.construct("DataVector")(allocator_)) {} + data_vector_(segment_.construct("DataVector")( + DataVector::allocator_type(segment_.get_segment_manager()))) {} SharedMemory::~SharedMemory() { segment_.destroy("DataVector"); From 9c6b232289e038ddc70e434764ebe17432578b72 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Thu, 31 Aug 2017 07:31:00 +0200 Subject: [PATCH 40/71] Add schema string to shared memory --- niv/include/niv/shared_memory.hpp | 3 +++ niv/src/shared_memory.cpp | 11 ++++++++-- niv/tests/src/test_shared_memory.cpp | 31 ++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp index e99eb82..564af88 100644 --- a/niv/include/niv/shared_memory.hpp +++ b/niv/include/niv/shared_memory.hpp @@ -40,6 +40,7 @@ class SharedMemory { using Allocator = boost::interprocess::allocator; using DataVector = std::vector>; + using SchemaString = std::vector>; static constexpr std::size_t kInitialSize{65536u}; @@ -48,10 +49,12 @@ class SharedMemory { std::size_t GetFreeSize() const { return segment_.get_free_memory(); } DataVector& GetDataVector(); + SchemaString& GetSchemaString(); private: ManagedSharedMemory segment_; DataVector* data_vector_; + SchemaString* schema_string_; }; } // namespace niv diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index 5b17a4c..f37371e 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -30,11 +30,14 @@ constexpr std::size_t SharedMemory::kInitialSize; SharedMemory::SharedMemory() : segment_{boost::interprocess::create_only, "niv-shared-memory", kInitialSize}, - data_vector_(segment_.construct("DataVector")( - DataVector::allocator_type(segment_.get_segment_manager()))) {} + data_vector_{segment_.construct("DataVector")( + DataVector::allocator_type(segment_.get_segment_manager()))}, + schema_string_{segment_.construct("SchemaString")( + SchemaString::allocator_type(segment_.get_segment_manager()))} {} SharedMemory::~SharedMemory() { segment_.destroy("DataVector"); + segment_.destroy("SchemaString"); boost::interprocess::shared_memory_object::remove("niv-shared-memory"); } @@ -42,4 +45,8 @@ SharedMemory::DataVector& SharedMemory::GetDataVector() { return *data_vector_; } +SharedMemory::SchemaString& SharedMemory::GetSchemaString() { + return *schema_string_; +} + } // namespace niv diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory.cpp index cae0b26..b7460f4 100644 --- a/niv/tests/src/test_shared_memory.cpp +++ b/niv/tests/src/test_shared_memory.cpp @@ -19,6 +19,8 @@ // limitations under the License. //------------------------------------------------------------------------------ +#include + #include "catch/catch.hpp" #include "niv/shared_memory.hpp" @@ -32,20 +34,37 @@ SCENARIO("Shared memory", "[niv][niv::SharedMemory]") { } WHEN("I request a data vector in that shared memory segment") { - auto data_vector = segment.GetDataVector(); - THEN("it is empty") { REQUIRE(data_vector.size() == 0); } + auto data = segment.GetDataVector(); + THEN("it is empty") { REQUIRE(data.size() == 0); } WHEN("I add one data entry into the vector") { auto free_size_before_push = segment.GetFreeSize(); - data_vector.push_back(conduit::uint8{9u}); + data.push_back(conduit::uint8{9u}); auto free_size_after_push = segment.GetFreeSize(); - THEN("I can retrieve it") { - REQUIRE(data_vector[0] == conduit::uint8{9u}); - } + THEN("I can retrieve it") { REQUIRE(data[0] == conduit::uint8{9u}); } THEN("we have less free space in the segment") { REQUIRE(free_size_after_push < free_size_before_push); } } } + + WHEN("I request a schema string in that shared memory segment") { + auto schema = segment.GetSchemaString(); + THEN("it is empty") { REQUIRE(schema.size() == 0); } + + WHEN("I assign a string to the schema") { + const std::string any_string{"foo_bar"}; + auto free_size_before_assign = segment.GetFreeSize(); + schema.assign(any_string.begin(), any_string.end()); + auto free_size_after_assign = segment.GetFreeSize(); + THEN("schema holds the string") { + const std::string schema_as_string{schema.begin(), schema.end()}; + REQUIRE(schema_as_string == any_string); + } + THEN("we have less free space in the segment") { + REQUIRE(free_size_after_assign < free_size_before_assign); + } + } + } } } From af6c104beaa5fa0588b374f177132b41fdb8c865 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Thu, 31 Aug 2017 15:51:34 +0200 Subject: [PATCH 41/71] Start sketching out the shared memory accessor --- niv/include/niv/shared_memory.hpp | 13 +++++++++---- niv/src/shared_memory.cpp | 25 ++++++++++++------------ niv/tests/src/test_shared_memory.cpp | 29 ++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp index 564af88..831c02b 100644 --- a/niv/include/niv/shared_memory.hpp +++ b/niv/include/niv/shared_memory.hpp @@ -33,6 +33,10 @@ namespace niv { +struct SharedMemoryCreate; +struct SharedMemoryAccess; + +template class SharedMemory { public: using ManagedSharedMemory = boost::interprocess::managed_shared_memory; @@ -42,16 +46,17 @@ class SharedMemory { using DataVector = std::vector>; using SchemaString = std::vector>; - static constexpr std::size_t kInitialSize{65536u}; - SharedMemory(); ~SharedMemory(); std::size_t GetFreeSize() const { return segment_.get_free_memory(); } - DataVector& GetDataVector(); - SchemaString& GetSchemaString(); + DataVector& GetDataVector() { return *data_vector_; } + + SchemaString& GetSchemaString() { return *schema_string_; } private: + static constexpr std::size_t InitialSize() { return 65536u; } + ManagedSharedMemory segment_; DataVector* data_vector_; SchemaString* schema_string_; diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index f37371e..a1d9bdf 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -25,28 +25,29 @@ namespace niv { -constexpr std::size_t SharedMemory::kInitialSize; - -SharedMemory::SharedMemory() +template <> +SharedMemory::SharedMemory() : segment_{boost::interprocess::create_only, "niv-shared-memory", - kInitialSize}, + InitialSize()}, data_vector_{segment_.construct("DataVector")( DataVector::allocator_type(segment_.get_segment_manager()))}, schema_string_{segment_.construct("SchemaString")( SchemaString::allocator_type(segment_.get_segment_manager()))} {} -SharedMemory::~SharedMemory() { +template <> +SharedMemory::SharedMemory() + : segment_{boost::interprocess::open_only, "niv-shared-memory"}, + data_vector_{segment_.find("DataVector").first}, + schema_string_{segment_.find("SchemaString").first} {} + +template <> +SharedMemory::~SharedMemory() { segment_.destroy("DataVector"); segment_.destroy("SchemaString"); boost::interprocess::shared_memory_object::remove("niv-shared-memory"); } -SharedMemory::DataVector& SharedMemory::GetDataVector() { - return *data_vector_; -} - -SharedMemory::SchemaString& SharedMemory::GetSchemaString() { - return *schema_string_; -} +template <> +SharedMemory::~SharedMemory() = default; } // namespace niv diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory.cpp index b7460f4..89a6748 100644 --- a/niv/tests/src/test_shared_memory.cpp +++ b/niv/tests/src/test_shared_memory.cpp @@ -25,9 +25,9 @@ #include "niv/shared_memory.hpp" -SCENARIO("Shared memory", "[niv][niv::SharedMemory]") { +SCENARIO("Shared memory creation", "[niv][niv::SharedMemory]") { GIVEN("A shared memory segment") { - niv::SharedMemory segment; + niv::SharedMemory<> segment; WHEN("I ask it for its free size") { auto free_size_after_creation = segment.GetFreeSize(); THEN("it is > 0") { REQUIRE(free_size_after_creation > 0); } @@ -66,5 +66,30 @@ SCENARIO("Shared memory", "[niv][niv::SharedMemory]") { } } } + + WHEN("I request a second shared memory segment") { + THEN("It throws an exception") { + REQUIRE_THROWS_WITH([]() { niv::SharedMemory<> segment2; }(), + "File exists"); + } + } + } +} + +SCENARIO("Shared memory access", "[niv][niv::SharedMemory]") { + GIVEN("A shared memory segment with some data in it") { + niv::SharedMemory<> segment; + auto data = segment.GetDataVector(); + data.push_back(conduit::uint8{9u}); + auto schema = segment.GetSchemaString(); + const std::string any_string{"foo_bar"}; + schema.assign(any_string.begin(), any_string.end()); + + WHEN("I request a second shared memory segment for accessing the first") { + THEN("It does not throw an exception") { + REQUIRE_NOTHROW( + []() { niv::SharedMemory segment2; }()); + } + } } } From 2e3fcc0ef79179bfc73c875d502899193cfc8af1 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Thu, 31 Aug 2017 16:50:14 +0200 Subject: [PATCH 42/71] Move to class hierarchy for shared memory --- niv/include/niv/shared_memory.hpp | 24 ++------- niv/include/niv/shared_memory_access.hpp | 37 +++++++++++++ niv/include/niv/shared_memory_base.hpp | 60 +++++++++++++++++++++ niv/src/shared_memory.cpp | 28 ++++------ niv/src/shared_memory_access.cpp | 32 +++++++++++ niv/src/shared_memory_base.cpp | 26 +++++++++ niv/tests/src/test_shared_memory.cpp | 22 +------- niv/tests/src/test_shared_memory_access.cpp | 44 +++++++++++++++ 8 files changed, 213 insertions(+), 60 deletions(-) create mode 100644 niv/include/niv/shared_memory_access.hpp create mode 100644 niv/include/niv/shared_memory_base.hpp create mode 100644 niv/src/shared_memory_access.cpp create mode 100644 niv/src/shared_memory_base.cpp create mode 100644 niv/tests/src/test_shared_memory_access.cpp diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp index 831c02b..297b912 100644 --- a/niv/include/niv/shared_memory.hpp +++ b/niv/include/niv/shared_memory.hpp @@ -31,35 +31,17 @@ #include "conduit/conduit_core.hpp" -namespace niv { +#include "niv/shared_memory_base.hpp" -struct SharedMemoryCreate; -struct SharedMemoryAccess; +namespace niv { -template -class SharedMemory { +class SharedMemory : public SharedMemoryBase { public: - using ManagedSharedMemory = boost::interprocess::managed_shared_memory; - template - using Allocator = - boost::interprocess::allocator; - using DataVector = std::vector>; - using SchemaString = std::vector>; - SharedMemory(); ~SharedMemory(); - std::size_t GetFreeSize() const { return segment_.get_free_memory(); } - DataVector& GetDataVector() { return *data_vector_; } - - SchemaString& GetSchemaString() { return *schema_string_; } - private: static constexpr std::size_t InitialSize() { return 65536u; } - - ManagedSharedMemory segment_; - DataVector* data_vector_; - SchemaString* schema_string_; }; } // namespace niv diff --git a/niv/include/niv/shared_memory_access.hpp b/niv/include/niv/shared_memory_access.hpp new file mode 100644 index 0000000..8903baf --- /dev/null +++ b/niv/include/niv/shared_memory_access.hpp @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 NIV_INCLUDE_NIV_SHARED_MEMORY_ACCESS_HPP_ +#define NIV_INCLUDE_NIV_SHARED_MEMORY_ACCESS_HPP_ + +#include "niv/shared_memory_base.hpp" + +namespace niv { + +class SharedMemoryAccess : public SharedMemoryBase { + public: + SharedMemoryAccess(); + ~SharedMemoryAccess() = default; +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_SHARED_MEMORY_ACCESS_HPP_ diff --git a/niv/include/niv/shared_memory_base.hpp b/niv/include/niv/shared_memory_base.hpp new file mode 100644 index 0000000..f8bac2c --- /dev/null +++ b/niv/include/niv/shared_memory_base.hpp @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 NIV_INCLUDE_NIV_SHARED_MEMORY_BASE_HPP_ +#define NIV_INCLUDE_NIV_SHARED_MEMORY_BASE_HPP_ + +#include +#include + +#include "boost/interprocess/allocators/allocator.hpp" +#include "boost/interprocess/managed_shared_memory.hpp" + +#include "conduit/conduit_core.hpp" + +namespace niv { + +class SharedMemoryBase { + public: + using ManagedSharedMemory = boost::interprocess::managed_shared_memory; + template + using Allocator = + boost::interprocess::allocator; + using DataVector = std::vector>; + using SchemaString = std::vector>; + + explicit SharedMemoryBase(ManagedSharedMemory&& segment) + : segment_{std::move(segment)} {} + virtual ~SharedMemoryBase() = default; + + std::size_t GetFreeSize() const { return segment_.get_free_memory(); } + DataVector& GetDataVector() { return *data_vector_; } + SchemaString& GetSchemaString() { return *schema_string_; } + + protected: + ManagedSharedMemory segment_; + DataVector* data_vector_{nullptr}; + SchemaString* schema_string_{nullptr}; +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_SHARED_MEMORY_BASE_HPP_ diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index a1d9bdf..a466e4d 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -25,29 +25,19 @@ namespace niv { -template <> -SharedMemory::SharedMemory() - : segment_{boost::interprocess::create_only, "niv-shared-memory", - InitialSize()}, - data_vector_{segment_.construct("DataVector")( - DataVector::allocator_type(segment_.get_segment_manager()))}, - schema_string_{segment_.construct("SchemaString")( - SchemaString::allocator_type(segment_.get_segment_manager()))} {} - -template <> -SharedMemory::SharedMemory() - : segment_{boost::interprocess::open_only, "niv-shared-memory"}, - data_vector_{segment_.find("DataVector").first}, - schema_string_{segment_.find("SchemaString").first} {} +SharedMemory::SharedMemory() + : SharedMemoryBase({boost::interprocess::create_only, "niv-shared-memory", + InitialSize()}) { + data_vector_ = segment_.construct("DataVector")( + DataVector::allocator_type(segment_.get_segment_manager())); + schema_string_ = segment_.construct("SchemaString")( + SchemaString::allocator_type(segment_.get_segment_manager())); +} -template <> -SharedMemory::~SharedMemory() { +SharedMemory::~SharedMemory() { segment_.destroy("DataVector"); segment_.destroy("SchemaString"); boost::interprocess::shared_memory_object::remove("niv-shared-memory"); } -template <> -SharedMemory::~SharedMemory() = default; - } // namespace niv diff --git a/niv/src/shared_memory_access.cpp b/niv/src/shared_memory_access.cpp new file mode 100644 index 0000000..9808386 --- /dev/null +++ b/niv/src/shared_memory_access.cpp @@ -0,0 +1,32 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "niv/shared_memory_access.hpp" + +namespace niv { + +SharedMemoryAccess::SharedMemoryAccess() + : SharedMemoryBase{{boost::interprocess::open_only, "niv-shared-memory"}} { + data_vector_ = segment_.find("DataVector").first; + schema_string_ = segment_.find("SchemaString").first; +} + +} // namespace niv diff --git a/niv/src/shared_memory_base.cpp b/niv/src/shared_memory_base.cpp new file mode 100644 index 0000000..03e9ea5 --- /dev/null +++ b/niv/src/shared_memory_base.cpp @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "niv/shared_memory_base.hpp" + +#include + +namespace niv {} // namespace niv diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory.cpp index 89a6748..d32a7cc 100644 --- a/niv/tests/src/test_shared_memory.cpp +++ b/niv/tests/src/test_shared_memory.cpp @@ -27,7 +27,7 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemory]") { GIVEN("A shared memory segment") { - niv::SharedMemory<> segment; + niv::SharedMemory segment; WHEN("I ask it for its free size") { auto free_size_after_creation = segment.GetFreeSize(); THEN("it is > 0") { REQUIRE(free_size_after_creation > 0); } @@ -69,27 +69,9 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemory]") { WHEN("I request a second shared memory segment") { THEN("It throws an exception") { - REQUIRE_THROWS_WITH([]() { niv::SharedMemory<> segment2; }(), + REQUIRE_THROWS_WITH([]() { niv::SharedMemory segment2; }(), "File exists"); } } } } - -SCENARIO("Shared memory access", "[niv][niv::SharedMemory]") { - GIVEN("A shared memory segment with some data in it") { - niv::SharedMemory<> segment; - auto data = segment.GetDataVector(); - data.push_back(conduit::uint8{9u}); - auto schema = segment.GetSchemaString(); - const std::string any_string{"foo_bar"}; - schema.assign(any_string.begin(), any_string.end()); - - WHEN("I request a second shared memory segment for accessing the first") { - THEN("It does not throw an exception") { - REQUIRE_NOTHROW( - []() { niv::SharedMemory segment2; }()); - } - } - } -} diff --git a/niv/tests/src/test_shared_memory_access.cpp b/niv/tests/src/test_shared_memory_access.cpp new file mode 100644 index 0000000..0d65a02 --- /dev/null +++ b/niv/tests/src/test_shared_memory_access.cpp @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "catch/catch.hpp" + +#include "niv/shared_memory.hpp" +#include "niv/shared_memory_access.hpp" + +SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { + GIVEN("A shared memory segment with some data in it") { + niv::SharedMemory segment; + auto data = segment.GetDataVector(); + data.push_back(conduit::uint8{9u}); + auto schema = segment.GetSchemaString(); + const std::string any_string{"foo_bar"}; + schema.assign(any_string.begin(), any_string.end()); + + WHEN("I request a second shared memory segment for accessing the first") { + THEN("It does not throw an exception") { + REQUIRE_NOTHROW([]() { niv::SharedMemoryAccess segment2; }()); + } + } + } +} From d36b08070fcc1f5fbfe7efb8d40b68e357e99e27 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Thu, 31 Aug 2017 17:02:37 +0200 Subject: [PATCH 43/71] Refactor: replace magic strings, improve code layout --- niv/include/niv/shared_memory_base.hpp | 17 ++++++++++------- niv/src/shared_memory.cpp | 14 +++++++------- niv/src/shared_memory_access.cpp | 6 +++--- niv/src/shared_memory_base.cpp | 17 ++++++++++++++++- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/niv/include/niv/shared_memory_base.hpp b/niv/include/niv/shared_memory_base.hpp index f8bac2c..4bbf268 100644 --- a/niv/include/niv/shared_memory_base.hpp +++ b/niv/include/niv/shared_memory_base.hpp @@ -35,19 +35,22 @@ namespace niv { class SharedMemoryBase { public: using ManagedSharedMemory = boost::interprocess::managed_shared_memory; + using SegmentManager = ManagedSharedMemory::segment_manager; template - using Allocator = - boost::interprocess::allocator; + using Allocator = boost::interprocess::allocator; using DataVector = std::vector>; using SchemaString = std::vector>; - explicit SharedMemoryBase(ManagedSharedMemory&& segment) - : segment_{std::move(segment)} {} + explicit SharedMemoryBase(ManagedSharedMemory&& segment); virtual ~SharedMemoryBase() = default; - std::size_t GetFreeSize() const { return segment_.get_free_memory(); } - DataVector& GetDataVector() { return *data_vector_; } - SchemaString& GetSchemaString() { return *schema_string_; } + std::size_t GetFreeSize() const; + DataVector& GetDataVector(); + SchemaString& GetSchemaString(); + + static constexpr const char* SegmentName() { return "niv-shared-memory"; } + static constexpr const char* DataVectorName() { return "DataVector"; } + static constexpr const char* SchemaStringName() { return "SchemaString"; } protected: ManagedSharedMemory segment_; diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index a466e4d..8538edf 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -26,18 +26,18 @@ namespace niv { SharedMemory::SharedMemory() - : SharedMemoryBase({boost::interprocess::create_only, "niv-shared-memory", - InitialSize()}) { - data_vector_ = segment_.construct("DataVector")( + : SharedMemoryBase( + {boost::interprocess::create_only, SegmentName(), InitialSize()}) { + data_vector_ = segment_.construct(DataVectorName())( DataVector::allocator_type(segment_.get_segment_manager())); - schema_string_ = segment_.construct("SchemaString")( + schema_string_ = segment_.construct(SchemaStringName())( SchemaString::allocator_type(segment_.get_segment_manager())); } SharedMemory::~SharedMemory() { - segment_.destroy("DataVector"); - segment_.destroy("SchemaString"); - boost::interprocess::shared_memory_object::remove("niv-shared-memory"); + segment_.destroy(DataVectorName()); + segment_.destroy(SchemaStringName()); + boost::interprocess::shared_memory_object::remove(SegmentName()); } } // namespace niv diff --git a/niv/src/shared_memory_access.cpp b/niv/src/shared_memory_access.cpp index 9808386..fdd02fe 100644 --- a/niv/src/shared_memory_access.cpp +++ b/niv/src/shared_memory_access.cpp @@ -24,9 +24,9 @@ namespace niv { SharedMemoryAccess::SharedMemoryAccess() - : SharedMemoryBase{{boost::interprocess::open_only, "niv-shared-memory"}} { - data_vector_ = segment_.find("DataVector").first; - schema_string_ = segment_.find("SchemaString").first; + : SharedMemoryBase{{boost::interprocess::open_only, SegmentName()}} { + data_vector_ = segment_.find(DataVectorName()).first; + schema_string_ = segment_.find(SchemaStringName()).first; } } // namespace niv diff --git a/niv/src/shared_memory_base.cpp b/niv/src/shared_memory_base.cpp index 03e9ea5..94572a1 100644 --- a/niv/src/shared_memory_base.cpp +++ b/niv/src/shared_memory_base.cpp @@ -23,4 +23,19 @@ #include -namespace niv {} // namespace niv +namespace niv { + +SharedMemoryBase::SharedMemoryBase(ManagedSharedMemory&& segment) + : segment_{std::move(segment)} {} + +std::size_t SharedMemoryBase::GetFreeSize() const { + return segment_.get_free_memory(); +} +SharedMemoryBase::DataVector& SharedMemoryBase::GetDataVector() { + return *data_vector_; +} +SharedMemoryBase::SchemaString& SharedMemoryBase::GetSchemaString() { + return *schema_string_; +} + +} // namespace niv From 5073b33a96805cca5283fa8782948abc111f3460 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 00:03:01 +0200 Subject: [PATCH 44/71] WIP: Read data, schema from shared memory acces. Tests fail. --- niv/tests/src/test_shared_memory_access.cpp | 38 ++++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/niv/tests/src/test_shared_memory_access.cpp b/niv/tests/src/test_shared_memory_access.cpp index 0d65a02..772e499 100644 --- a/niv/tests/src/test_shared_memory_access.cpp +++ b/niv/tests/src/test_shared_memory_access.cpp @@ -20,6 +20,7 @@ //------------------------------------------------------------------------------ #include +#include #include "catch/catch.hpp" @@ -27,17 +28,44 @@ #include "niv/shared_memory_access.hpp" SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { + GIVEN("No shared memory segment") { + THEN("Creating a shared memory access throws an exception.") { + REQUIRE_THROWS_WITH([]() { niv::SharedMemoryAccess segment_access; }(), + "No such file or directory"); + } + } + GIVEN("A shared memory segment with some data in it") { niv::SharedMemory segment; + auto data = segment.GetDataVector(); - data.push_back(conduit::uint8{9u}); + std::vector any_data{'a', 'b', 'c'}; + data.assign(any_data.begin(), any_data.end()); + auto schema = segment.GetSchemaString(); - const std::string any_string{"foo_bar"}; - schema.assign(any_string.begin(), any_string.end()); + const std::string any_schema{"foo_bar_baz"}; + schema.assign(any_schema.begin(), any_schema.end()); - WHEN("I request a second shared memory segment for accessing the first") { + WHEN("I create shared memory access") { THEN("It does not throw an exception") { - REQUIRE_NOTHROW([]() { niv::SharedMemoryAccess segment2; }()); + REQUIRE_NOTHROW([]() { niv::SharedMemoryAccess segment_access; }()); + } + niv::SharedMemoryAccess segment_access; + + WHEN("I read the data") { + auto data = segment_access.GetDataVector(); + THEN("I get the original data") { + std::vector data_as_vector{data.begin(), data.end()}; + REQUIRE(data_as_vector == any_data); + } + } + + WHEN("I read the schema") { + auto schema = segment_access.GetSchemaString(); + THEN("I get the original schema") { + const std::string schema_as_string{schema.begin(), schema.end()}; + REQUIRE(schema_as_string == any_schema); + } } } } From 91c4ac9bbf09a1d03592453cb774365660654336 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 00:34:21 +0200 Subject: [PATCH 45/71] Remove aggregate test case --- cmake/catch.cmake | 9 --------- 1 file changed, 9 deletions(-) diff --git a/cmake/catch.cmake b/cmake/catch.cmake index 4e29d15..b6e4607 100644 --- a/cmake/catch.cmake +++ b/cmake/catch.cmake @@ -81,15 +81,6 @@ function(ADD_TEST_CATCH) file(GLOB ADD_TEST_CATCH_CATCH_MAIN_ABSOLUTE ${ADD_TEST_CATCH_CATCH_MAIN}) list(REMOVE_ITEM ADD_TEST_CATCH_SOURCES ${ADD_TEST_CATCH_CATCH_MAIN_ABSOLUTE}) - # add aggregate test target - ADD_TEST_CATCH_INTERNAL_("${ADD_TEST_CATCH_NAME}" - "${ADD_TEST_CATCH_SOURCES}" - "${ADD_TEST_CATCH_HEADERS}" - "${ADD_TEST_CATCH_INCLUDE_DIRECTORIES}" - "${ADD_TEST_CATCH_LINK_LIBRARIES};${ADD_TEST_CATCH_NAME}_catch_main" - "${ADD_TEST_CATCH_PATH_TO_ADD}" - ) - # add test for each test source file foreach(TEST_SOURCE_FILE ${ADD_TEST_CATCH_SOURCES}) get_filename_component(TEST_NAME ${TEST_SOURCE_FILE} NAME_WE) From 8136dc88f85c48372395f4334ecc3b3bd7b5c801 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 01:14:03 +0200 Subject: [PATCH 46/71] Rename shared memory classes --- niv/include/niv/shared_memory.hpp | 34 +++++++--- niv/include/niv/shared_memory_access.hpp | 4 +- niv/include/niv/shared_memory_base.hpp | 63 ------------------- .../niv/shared_memory_segment.hpp} | 34 ++++++---- niv/src/shared_memory.cpp | 24 ++++--- niv/src/shared_memory_access.cpp | 2 +- niv/src/shared_memory_segment.cpp | 43 +++++++++++++ niv/tests/src/test_shared_memory.cpp | 8 +-- niv/tests/src/test_shared_memory_access.cpp | 4 +- 9 files changed, 108 insertions(+), 108 deletions(-) delete mode 100644 niv/include/niv/shared_memory_base.hpp rename niv/{src/shared_memory_base.cpp => include/niv/shared_memory_segment.hpp} (64%) create mode 100644 niv/src/shared_memory_segment.cpp diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp index 297b912..4e12821 100644 --- a/niv/include/niv/shared_memory.hpp +++ b/niv/include/niv/shared_memory.hpp @@ -22,8 +22,7 @@ #ifndef NIV_INCLUDE_NIV_SHARED_MEMORY_HPP_ #define NIV_INCLUDE_NIV_SHARED_MEMORY_HPP_ -#include - +#include #include #include "boost/interprocess/allocators/allocator.hpp" @@ -31,17 +30,32 @@ #include "conduit/conduit_core.hpp" -#include "niv/shared_memory_base.hpp" - namespace niv { -class SharedMemory : public SharedMemoryBase { +class SharedMemory { public: - SharedMemory(); - ~SharedMemory(); - - private: - static constexpr std::size_t InitialSize() { return 65536u; } + using ManagedSharedMemory = boost::interprocess::managed_shared_memory; + using SegmentManager = ManagedSharedMemory::segment_manager; + template + using Allocator = boost::interprocess::allocator; + using DataVector = std::vector>; + using SchemaString = std::vector>; + + explicit SharedMemory(ManagedSharedMemory&& segment); + virtual ~SharedMemory() = default; + + std::size_t GetFreeSize() const; + DataVector& GetDataVector(); + SchemaString& GetSchemaString(); + + static constexpr const char* SegmentName() { return "niv-shared-memory"; } + static constexpr const char* DataVectorName() { return "DataVector"; } + static constexpr const char* SchemaStringName() { return "SchemaString"; } + + protected: + ManagedSharedMemory segment_; + DataVector* data_vector_{nullptr}; + SchemaString* schema_string_{nullptr}; }; } // namespace niv diff --git a/niv/include/niv/shared_memory_access.hpp b/niv/include/niv/shared_memory_access.hpp index 8903baf..eaae40d 100644 --- a/niv/include/niv/shared_memory_access.hpp +++ b/niv/include/niv/shared_memory_access.hpp @@ -22,11 +22,11 @@ #ifndef NIV_INCLUDE_NIV_SHARED_MEMORY_ACCESS_HPP_ #define NIV_INCLUDE_NIV_SHARED_MEMORY_ACCESS_HPP_ -#include "niv/shared_memory_base.hpp" +#include "niv/shared_memory.hpp" namespace niv { -class SharedMemoryAccess : public SharedMemoryBase { +class SharedMemoryAccess : public SharedMemory { public: SharedMemoryAccess(); ~SharedMemoryAccess() = default; diff --git a/niv/include/niv/shared_memory_base.hpp b/niv/include/niv/shared_memory_base.hpp deleted file mode 100644 index 4bbf268..0000000 --- a/niv/include/niv/shared_memory_base.hpp +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// nest in situ vis -// -// Copyright (c) 2017 RWTH Aachen University, Germany, -// Virtual Reality & Immersive Visualisation Group. -//------------------------------------------------------------------------------ -// License -// -// Licensed 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 NIV_INCLUDE_NIV_SHARED_MEMORY_BASE_HPP_ -#define NIV_INCLUDE_NIV_SHARED_MEMORY_BASE_HPP_ - -#include -#include - -#include "boost/interprocess/allocators/allocator.hpp" -#include "boost/interprocess/managed_shared_memory.hpp" - -#include "conduit/conduit_core.hpp" - -namespace niv { - -class SharedMemoryBase { - public: - using ManagedSharedMemory = boost::interprocess::managed_shared_memory; - using SegmentManager = ManagedSharedMemory::segment_manager; - template - using Allocator = boost::interprocess::allocator; - using DataVector = std::vector>; - using SchemaString = std::vector>; - - explicit SharedMemoryBase(ManagedSharedMemory&& segment); - virtual ~SharedMemoryBase() = default; - - std::size_t GetFreeSize() const; - DataVector& GetDataVector(); - SchemaString& GetSchemaString(); - - static constexpr const char* SegmentName() { return "niv-shared-memory"; } - static constexpr const char* DataVectorName() { return "DataVector"; } - static constexpr const char* SchemaStringName() { return "SchemaString"; } - - protected: - ManagedSharedMemory segment_; - DataVector* data_vector_{nullptr}; - SchemaString* schema_string_{nullptr}; -}; - -} // namespace niv - -#endif // NIV_INCLUDE_NIV_SHARED_MEMORY_BASE_HPP_ diff --git a/niv/src/shared_memory_base.cpp b/niv/include/niv/shared_memory_segment.hpp similarity index 64% rename from niv/src/shared_memory_base.cpp rename to niv/include/niv/shared_memory_segment.hpp index 94572a1..fe0264a 100644 --- a/niv/src/shared_memory_base.cpp +++ b/niv/include/niv/shared_memory_segment.hpp @@ -19,23 +19,31 @@ // limitations under the License. //------------------------------------------------------------------------------ -#include "niv/shared_memory_base.hpp" +#ifndef NIV_INCLUDE_NIV_SHARED_MEMORY_SEGMENT_HPP_ +#define NIV_INCLUDE_NIV_SHARED_MEMORY_SEGMENT_HPP_ -#include +#include + +#include + +#include "boost/interprocess/allocators/allocator.hpp" +#include "boost/interprocess/managed_shared_memory.hpp" + +#include "conduit/conduit_core.hpp" + +#include "niv/shared_memory.hpp" namespace niv { -SharedMemoryBase::SharedMemoryBase(ManagedSharedMemory&& segment) - : segment_{std::move(segment)} {} +class SharedMemorySegment : public SharedMemory { + public: + SharedMemorySegment(); + ~SharedMemorySegment(); -std::size_t SharedMemoryBase::GetFreeSize() const { - return segment_.get_free_memory(); -} -SharedMemoryBase::DataVector& SharedMemoryBase::GetDataVector() { - return *data_vector_; -} -SharedMemoryBase::SchemaString& SharedMemoryBase::GetSchemaString() { - return *schema_string_; -} + private: + static constexpr std::size_t InitialSize() { return 65536u; } +}; } // namespace niv + +#endif // NIV_INCLUDE_NIV_SHARED_MEMORY_SEGMENT_HPP_ diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index 8538edf..6db5cea 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -21,23 +21,21 @@ #include "niv/shared_memory.hpp" -#include +#include namespace niv { -SharedMemory::SharedMemory() - : SharedMemoryBase( - {boost::interprocess::create_only, SegmentName(), InitialSize()}) { - data_vector_ = segment_.construct(DataVectorName())( - DataVector::allocator_type(segment_.get_segment_manager())); - schema_string_ = segment_.construct(SchemaStringName())( - SchemaString::allocator_type(segment_.get_segment_manager())); -} +SharedMemory::SharedMemory(ManagedSharedMemory&& segment) + : segment_{std::move(segment)} {} -SharedMemory::~SharedMemory() { - segment_.destroy(DataVectorName()); - segment_.destroy(SchemaStringName()); - boost::interprocess::shared_memory_object::remove(SegmentName()); +std::size_t SharedMemory::GetFreeSize() const { + return segment_.get_free_memory(); +} +SharedMemory::DataVector& SharedMemory::GetDataVector() { + return *data_vector_; +} +SharedMemory::SchemaString& SharedMemory::GetSchemaString() { + return *schema_string_; } } // namespace niv diff --git a/niv/src/shared_memory_access.cpp b/niv/src/shared_memory_access.cpp index fdd02fe..431fc5a 100644 --- a/niv/src/shared_memory_access.cpp +++ b/niv/src/shared_memory_access.cpp @@ -24,7 +24,7 @@ namespace niv { SharedMemoryAccess::SharedMemoryAccess() - : SharedMemoryBase{{boost::interprocess::open_only, SegmentName()}} { + : SharedMemory{{boost::interprocess::open_only, SegmentName()}} { data_vector_ = segment_.find(DataVectorName()).first; schema_string_ = segment_.find(SchemaStringName()).first; } diff --git a/niv/src/shared_memory_segment.cpp b/niv/src/shared_memory_segment.cpp new file mode 100644 index 0000000..e7879b3 --- /dev/null +++ b/niv/src/shared_memory_segment.cpp @@ -0,0 +1,43 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "niv/shared_memory_segment.hpp" + +#include + +namespace niv { + +SharedMemorySegment::SharedMemorySegment() + : SharedMemory( + {boost::interprocess::create_only, SegmentName(), InitialSize()}) { + data_vector_ = segment_.construct(DataVectorName())( + DataVector::allocator_type(segment_.get_segment_manager())); + schema_string_ = segment_.construct(SchemaStringName())( + SchemaString::allocator_type(segment_.get_segment_manager())); +} + +SharedMemorySegment::~SharedMemorySegment() { + segment_.destroy(DataVectorName()); + segment_.destroy(SchemaStringName()); + boost::interprocess::shared_memory_object::remove(SegmentName()); +} + +} // namespace niv diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory.cpp index d32a7cc..bd481b2 100644 --- a/niv/tests/src/test_shared_memory.cpp +++ b/niv/tests/src/test_shared_memory.cpp @@ -23,11 +23,11 @@ #include "catch/catch.hpp" -#include "niv/shared_memory.hpp" +#include "niv/shared_memory_segment.hpp" -SCENARIO("Shared memory creation", "[niv][niv::SharedMemory]") { +SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { GIVEN("A shared memory segment") { - niv::SharedMemory segment; + niv::SharedMemorySegment segment; WHEN("I ask it for its free size") { auto free_size_after_creation = segment.GetFreeSize(); THEN("it is > 0") { REQUIRE(free_size_after_creation > 0); } @@ -69,7 +69,7 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemory]") { WHEN("I request a second shared memory segment") { THEN("It throws an exception") { - REQUIRE_THROWS_WITH([]() { niv::SharedMemory segment2; }(), + REQUIRE_THROWS_WITH([]() { niv::SharedMemorySegment segment2; }(), "File exists"); } } diff --git a/niv/tests/src/test_shared_memory_access.cpp b/niv/tests/src/test_shared_memory_access.cpp index 772e499..79d9087 100644 --- a/niv/tests/src/test_shared_memory_access.cpp +++ b/niv/tests/src/test_shared_memory_access.cpp @@ -24,8 +24,8 @@ #include "catch/catch.hpp" -#include "niv/shared_memory.hpp" #include "niv/shared_memory_access.hpp" +#include "niv/shared_memory_segment.hpp" SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { GIVEN("No shared memory segment") { @@ -36,7 +36,7 @@ SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { } GIVEN("A shared memory segment with some data in it") { - niv::SharedMemory segment; + niv::SharedMemorySegment segment; auto data = segment.GetDataVector(); std::vector any_data{'a', 'b', 'c'}; From 3df64da715f684e08c0b3e1865f2d2bf2a69ff56 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 01:27:59 +0200 Subject: [PATCH 47/71] Deactivate shared memory access and read test --- niv/tests/src/test_shared_memory_access.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/niv/tests/src/test_shared_memory_access.cpp b/niv/tests/src/test_shared_memory_access.cpp index 79d9087..d323845 100644 --- a/niv/tests/src/test_shared_memory_access.cpp +++ b/niv/tests/src/test_shared_memory_access.cpp @@ -52,6 +52,8 @@ SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { } niv::SharedMemoryAccess segment_access; + // TODO(@tvierjahn) currently broken, reactivate when fixed + /* WHEN("I read the data") { auto data = segment_access.GetDataVector(); THEN("I get the original data") { @@ -67,6 +69,7 @@ SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { REQUIRE(schema_as_string == any_schema); } } + */ } } } From 94d5b2a24304b43ac29b591f0f55816941e41875 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 01:28:23 +0200 Subject: [PATCH 48/71] Refactor creation and access --- niv/include/niv/shared_memory.hpp | 9 ++++++++- niv/include/niv/shared_memory_segment.hpp | 1 - niv/src/shared_memory.cpp | 18 ++++++++++++++++-- niv/src/shared_memory_access.cpp | 6 +----- niv/src/shared_memory_segment.cpp | 15 ++------------- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp index 4e12821..9135411 100644 --- a/niv/include/niv/shared_memory.hpp +++ b/niv/include/niv/shared_memory.hpp @@ -34,6 +34,9 @@ namespace niv { class SharedMemory { public: + class Create {}; + class Access {}; + using ManagedSharedMemory = boost::interprocess::managed_shared_memory; using SegmentManager = ManagedSharedMemory::segment_manager; template @@ -41,9 +44,12 @@ class SharedMemory { using DataVector = std::vector>; using SchemaString = std::vector>; - explicit SharedMemory(ManagedSharedMemory&& segment); + explicit SharedMemory(const Create&); + explicit SharedMemory(const Access&); virtual ~SharedMemory() = default; + void Destroy(); + std::size_t GetFreeSize() const; DataVector& GetDataVector(); SchemaString& GetSchemaString(); @@ -51,6 +57,7 @@ class SharedMemory { static constexpr const char* SegmentName() { return "niv-shared-memory"; } static constexpr const char* DataVectorName() { return "DataVector"; } static constexpr const char* SchemaStringName() { return "SchemaString"; } + static constexpr std::size_t InitialSize() { return 65536u; } protected: ManagedSharedMemory segment_; diff --git a/niv/include/niv/shared_memory_segment.hpp b/niv/include/niv/shared_memory_segment.hpp index fe0264a..61c9fa0 100644 --- a/niv/include/niv/shared_memory_segment.hpp +++ b/niv/include/niv/shared_memory_segment.hpp @@ -41,7 +41,6 @@ class SharedMemorySegment : public SharedMemory { ~SharedMemorySegment(); private: - static constexpr std::size_t InitialSize() { return 65536u; } }; } // namespace niv diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index 6db5cea..22078b6 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -25,8 +25,22 @@ namespace niv { -SharedMemory::SharedMemory(ManagedSharedMemory&& segment) - : segment_{std::move(segment)} {} +SharedMemory::SharedMemory(const Create&) + : segment_{boost::interprocess::create_only, SegmentName(), InitialSize()}, + data_vector_{segment_.construct(DataVectorName())( + SchemaString::allocator_type(segment_.get_segment_manager()))}, + schema_string_{segment_.construct(SchemaStringName())( + SchemaString::allocator_type(segment_.get_segment_manager()))} {} +SharedMemory::SharedMemory(const Access&) + : segment_{boost::interprocess::open_only, SegmentName()}, + data_vector_{segment_.find(DataVectorName()).first}, + schema_string_{segment_.find(SchemaStringName()).first} {} + +void SharedMemory::Destroy() { + segment_.destroy(DataVectorName()); + segment_.destroy(SchemaStringName()); + boost::interprocess::shared_memory_object::remove(SegmentName()); +} std::size_t SharedMemory::GetFreeSize() const { return segment_.get_free_memory(); diff --git a/niv/src/shared_memory_access.cpp b/niv/src/shared_memory_access.cpp index 431fc5a..edbb51c 100644 --- a/niv/src/shared_memory_access.cpp +++ b/niv/src/shared_memory_access.cpp @@ -23,10 +23,6 @@ namespace niv { -SharedMemoryAccess::SharedMemoryAccess() - : SharedMemory{{boost::interprocess::open_only, SegmentName()}} { - data_vector_ = segment_.find(DataVectorName()).first; - schema_string_ = segment_.find(SchemaStringName()).first; -} +SharedMemoryAccess::SharedMemoryAccess() : SharedMemory{Access()} {} } // namespace niv diff --git a/niv/src/shared_memory_segment.cpp b/niv/src/shared_memory_segment.cpp index e7879b3..c1f8e43 100644 --- a/niv/src/shared_memory_segment.cpp +++ b/niv/src/shared_memory_segment.cpp @@ -25,19 +25,8 @@ namespace niv { -SharedMemorySegment::SharedMemorySegment() - : SharedMemory( - {boost::interprocess::create_only, SegmentName(), InitialSize()}) { - data_vector_ = segment_.construct(DataVectorName())( - DataVector::allocator_type(segment_.get_segment_manager())); - schema_string_ = segment_.construct(SchemaStringName())( - SchemaString::allocator_type(segment_.get_segment_manager())); -} +SharedMemorySegment::SharedMemorySegment() : SharedMemory{Create()} {} -SharedMemorySegment::~SharedMemorySegment() { - segment_.destroy(DataVectorName()); - segment_.destroy(SchemaStringName()); - boost::interprocess::shared_memory_object::remove(SegmentName()); -} +SharedMemorySegment::~SharedMemorySegment() { Destroy(); } } // namespace niv From 76d26480ff1613e2ab5b83c362e8def0a89e1629 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 07:56:52 +0200 Subject: [PATCH 49/71] Fix bug that rendered shared memory empty You have to use `auto&` when getting the shared vectors --- niv/src/shared_memory.cpp | 2 +- niv/tests/CMakeLists.txt | 4 ++-- niv/tests/src/test_shared_memory_access.cpp | 11 ++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index 22078b6..00f2e7b 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -28,7 +28,7 @@ namespace niv { SharedMemory::SharedMemory(const Create&) : segment_{boost::interprocess::create_only, SegmentName(), InitialSize()}, data_vector_{segment_.construct(DataVectorName())( - SchemaString::allocator_type(segment_.get_segment_manager()))}, + DataVector::allocator_type(segment_.get_segment_manager()))}, schema_string_{segment_.construct(SchemaStringName())( SchemaString::allocator_type(segment_.get_segment_manager()))} {} SharedMemory::SharedMemory(const Access&) diff --git a/niv/tests/CMakeLists.txt b/niv/tests/CMakeLists.txt index a784e4d..f1cf95d 100644 --- a/niv/tests/CMakeLists.txt +++ b/niv/tests/CMakeLists.txt @@ -32,11 +32,11 @@ add_test_catch(NAME "niv-tests" INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} LINK_LIBRARIES niv PATH_TO_ADD ${PROJECT_BINARY_DIR}/niv -) + ) add_test_cpplint(NAME "niv-tests--cpplint" ${NIV_TEST_SOURCES} ${NIV_TEST_HEADERS} ${NIV_TEST_UTILITIES_TEST_SOURCES} ${NIV_TEST_UTILITIES_HEADERS} -) + ) diff --git a/niv/tests/src/test_shared_memory_access.cpp b/niv/tests/src/test_shared_memory_access.cpp index d323845..0747110 100644 --- a/niv/tests/src/test_shared_memory_access.cpp +++ b/niv/tests/src/test_shared_memory_access.cpp @@ -38,11 +38,11 @@ SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { GIVEN("A shared memory segment with some data in it") { niv::SharedMemorySegment segment; - auto data = segment.GetDataVector(); + auto& data = segment.GetDataVector(); std::vector any_data{'a', 'b', 'c'}; data.assign(any_data.begin(), any_data.end()); - auto schema = segment.GetSchemaString(); + auto& schema = segment.GetSchemaString(); const std::string any_schema{"foo_bar_baz"}; schema.assign(any_schema.begin(), any_schema.end()); @@ -52,10 +52,8 @@ SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { } niv::SharedMemoryAccess segment_access; - // TODO(@tvierjahn) currently broken, reactivate when fixed - /* WHEN("I read the data") { - auto data = segment_access.GetDataVector(); + auto& data = segment_access.GetDataVector(); THEN("I get the original data") { std::vector data_as_vector{data.begin(), data.end()}; REQUIRE(data_as_vector == any_data); @@ -63,13 +61,12 @@ SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { } WHEN("I read the schema") { - auto schema = segment_access.GetSchemaString(); + auto& schema = segment_access.GetSchemaString(); THEN("I get the original schema") { const std::string schema_as_string{schema.begin(), schema.end()}; REQUIRE(schema_as_string == any_schema); } } - */ } } } From b4dcc30ab80d84becc02bcb43e87506c99775be1 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 07:57:28 +0200 Subject: [PATCH 50/71] Add shared memory helper app. --- niv/CMakeLists.txt | 1 + niv/helper_apps/CMakeLists.txt | 27 +++++++++++++ niv/helper_apps/src/shared_memory.cpp | 57 +++++++++++++++++++++++++++ niv/tests/CMakeLists.txt | 1 + niv/tests/src/test_shared_memory.cpp | 4 +- 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 niv/helper_apps/CMakeLists.txt create mode 100644 niv/helper_apps/src/shared_memory.cpp diff --git a/niv/CMakeLists.txt b/niv/CMakeLists.txt index 942338e..3a0f319 100644 --- a/niv/CMakeLists.txt +++ b/niv/CMakeLists.txt @@ -53,3 +53,4 @@ add_test_cpplint(NAME "niv--cpplint" generate_configure_files(niv) add_subdirectory(tests) +add_subdirectory(helper_apps) diff --git a/niv/helper_apps/CMakeLists.txt b/niv/helper_apps/CMakeLists.txt new file mode 100644 index 0000000..686dde9 --- /dev/null +++ b/niv/helper_apps/CMakeLists.txt @@ -0,0 +1,27 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed 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(nvi-shared-memory + src/shared_memory.cpp + ) +target_link_libraries(nvi-shared-memory + niv + ) diff --git a/niv/helper_apps/src/shared_memory.cpp b/niv/helper_apps/src/shared_memory.cpp new file mode 100644 index 0000000..bcae215 --- /dev/null +++ b/niv/helper_apps/src/shared_memory.cpp @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 +#include + +#include "conduit/conduit_core.hpp" +#include "niv/shared_memory.hpp" + +void create() { + niv::SharedMemory s{niv::SharedMemory::Create()}; + auto& data = s.GetDataVector(); + std::vector any_vector{'a', 'b', 'c'}; + data.assign(any_vector.begin(), any_vector.end()); +} + +void destroy() { + niv::SharedMemory s{niv::SharedMemory::Access()}; + s.Destroy(); +} + +int command(char* command) { + if (std::string(command) == std::string("create")) { + create(); + return EXIT_SUCCESS; + } else if (std::string(command) == std::string("destroy")) { + destroy(); + return EXIT_SUCCESS; + } + return EXIT_FAILURE; +} + +int main(int argc, char** argv) { + if (argc == 2) { + return command(argv[1]); + } + return EXIT_FAILURE; +} diff --git a/niv/tests/CMakeLists.txt b/niv/tests/CMakeLists.txt index f1cf95d..287b50d 100644 --- a/niv/tests/CMakeLists.txt +++ b/niv/tests/CMakeLists.txt @@ -33,6 +33,7 @@ add_test_catch(NAME "niv-tests" LINK_LIBRARIES niv PATH_TO_ADD ${PROJECT_BINARY_DIR}/niv ) +add_dependencies(test_shared_memory_access nvi-shared-memory) add_test_cpplint(NAME "niv-tests--cpplint" ${NIV_TEST_SOURCES} ${NIV_TEST_HEADERS} diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory.cpp index bd481b2..cb623fc 100644 --- a/niv/tests/src/test_shared_memory.cpp +++ b/niv/tests/src/test_shared_memory.cpp @@ -34,7 +34,7 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { } WHEN("I request a data vector in that shared memory segment") { - auto data = segment.GetDataVector(); + auto& data = segment.GetDataVector(); THEN("it is empty") { REQUIRE(data.size() == 0); } WHEN("I add one data entry into the vector") { @@ -49,7 +49,7 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { } WHEN("I request a schema string in that shared memory segment") { - auto schema = segment.GetSchemaString(); + auto& schema = segment.GetSchemaString(); THEN("it is empty") { REQUIRE(schema.size() == 0); } WHEN("I assign a string to the schema") { From 4b1ec0011b2eba28fbaddcc4ff07bf7eb774429b Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 07:57:36 +0200 Subject: [PATCH 51/71] Revert "Add shared memory helper app." This reverts commit b4dcc30ab80d84becc02bcb43e87506c99775be1. --- niv/CMakeLists.txt | 1 - niv/helper_apps/CMakeLists.txt | 27 ------------- niv/helper_apps/src/shared_memory.cpp | 57 --------------------------- niv/tests/CMakeLists.txt | 1 - niv/tests/src/test_shared_memory.cpp | 4 +- 5 files changed, 2 insertions(+), 88 deletions(-) delete mode 100644 niv/helper_apps/CMakeLists.txt delete mode 100644 niv/helper_apps/src/shared_memory.cpp diff --git a/niv/CMakeLists.txt b/niv/CMakeLists.txt index 3a0f319..942338e 100644 --- a/niv/CMakeLists.txt +++ b/niv/CMakeLists.txt @@ -53,4 +53,3 @@ add_test_cpplint(NAME "niv--cpplint" generate_configure_files(niv) add_subdirectory(tests) -add_subdirectory(helper_apps) diff --git a/niv/helper_apps/CMakeLists.txt b/niv/helper_apps/CMakeLists.txt deleted file mode 100644 index 686dde9..0000000 --- a/niv/helper_apps/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -#------------------------------------------------------------------------------- -# nest in situ vis -# -# Copyright (c) 2017 RWTH Aachen University, Germany, -# Virtual Reality & Immersive Visualisation Group. -#------------------------------------------------------------------------------- -# License -# -# Licensed 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(nvi-shared-memory - src/shared_memory.cpp - ) -target_link_libraries(nvi-shared-memory - niv - ) diff --git a/niv/helper_apps/src/shared_memory.cpp b/niv/helper_apps/src/shared_memory.cpp deleted file mode 100644 index bcae215..0000000 --- a/niv/helper_apps/src/shared_memory.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// nest in situ vis -// -// Copyright (c) 2017 RWTH Aachen University, Germany, -// Virtual Reality & Immersive Visualisation Group. -//------------------------------------------------------------------------------ -// License -// -// Licensed 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 -#include - -#include "conduit/conduit_core.hpp" -#include "niv/shared_memory.hpp" - -void create() { - niv::SharedMemory s{niv::SharedMemory::Create()}; - auto& data = s.GetDataVector(); - std::vector any_vector{'a', 'b', 'c'}; - data.assign(any_vector.begin(), any_vector.end()); -} - -void destroy() { - niv::SharedMemory s{niv::SharedMemory::Access()}; - s.Destroy(); -} - -int command(char* command) { - if (std::string(command) == std::string("create")) { - create(); - return EXIT_SUCCESS; - } else if (std::string(command) == std::string("destroy")) { - destroy(); - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} - -int main(int argc, char** argv) { - if (argc == 2) { - return command(argv[1]); - } - return EXIT_FAILURE; -} diff --git a/niv/tests/CMakeLists.txt b/niv/tests/CMakeLists.txt index 287b50d..f1cf95d 100644 --- a/niv/tests/CMakeLists.txt +++ b/niv/tests/CMakeLists.txt @@ -33,7 +33,6 @@ add_test_catch(NAME "niv-tests" LINK_LIBRARIES niv PATH_TO_ADD ${PROJECT_BINARY_DIR}/niv ) -add_dependencies(test_shared_memory_access nvi-shared-memory) add_test_cpplint(NAME "niv-tests--cpplint" ${NIV_TEST_SOURCES} ${NIV_TEST_HEADERS} diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory.cpp index cb623fc..bd481b2 100644 --- a/niv/tests/src/test_shared_memory.cpp +++ b/niv/tests/src/test_shared_memory.cpp @@ -34,7 +34,7 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { } WHEN("I request a data vector in that shared memory segment") { - auto& data = segment.GetDataVector(); + auto data = segment.GetDataVector(); THEN("it is empty") { REQUIRE(data.size() == 0); } WHEN("I add one data entry into the vector") { @@ -49,7 +49,7 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { } WHEN("I request a schema string in that shared memory segment") { - auto& schema = segment.GetSchemaString(); + auto schema = segment.GetSchemaString(); THEN("it is empty") { REQUIRE(schema.size() == 0); } WHEN("I assign a string to the schema") { From f0577d6f5678b8e67fbe77538962cda6b671be28 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 08:02:49 +0200 Subject: [PATCH 52/71] Apply previous bugfix to shared mem creation test for symmetry --- niv/tests/src/test_shared_memory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory.cpp index bd481b2..cb623fc 100644 --- a/niv/tests/src/test_shared_memory.cpp +++ b/niv/tests/src/test_shared_memory.cpp @@ -34,7 +34,7 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { } WHEN("I request a data vector in that shared memory segment") { - auto data = segment.GetDataVector(); + auto& data = segment.GetDataVector(); THEN("it is empty") { REQUIRE(data.size() == 0); } WHEN("I add one data entry into the vector") { @@ -49,7 +49,7 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { } WHEN("I request a schema string in that shared memory segment") { - auto schema = segment.GetSchemaString(); + auto& schema = segment.GetSchemaString(); THEN("it is empty") { REQUIRE(schema.size() == 0); } WHEN("I assign a string to the schema") { From 06f70ac0ca64e5391e5fad47fac8194b0bfb3723 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 08:12:12 +0200 Subject: [PATCH 53/71] Provide SharedData::Store and GetData --- niv/include/niv/shared_memory.hpp | 3 +++ niv/src/shared_memory.cpp | 10 ++++++++++ niv/tests/src/test_shared_memory.cpp | 15 +++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp index 9135411..7382be3 100644 --- a/niv/include/niv/shared_memory.hpp +++ b/niv/include/niv/shared_memory.hpp @@ -54,6 +54,9 @@ class SharedMemory { DataVector& GetDataVector(); SchemaString& GetSchemaString(); + void Store(const std::vector& data); + std::vector GetData() const; + static constexpr const char* SegmentName() { return "niv-shared-memory"; } static constexpr const char* DataVectorName() { return "DataVector"; } static constexpr const char* SchemaStringName() { return "SchemaString"; } diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index 00f2e7b..b87cebe 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -22,6 +22,7 @@ #include "niv/shared_memory.hpp" #include +#include namespace niv { @@ -52,4 +53,13 @@ SharedMemory::SchemaString& SharedMemory::GetSchemaString() { return *schema_string_; } +void SharedMemory::Store(const std::vector& data) { + data_vector_->assign(data.begin(), data.end()); +} + +std::vector SharedMemory::GetData() const { + return std::vector{data_vector_->begin(), + data_vector_->end()}; +} + } // namespace niv diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory.cpp index cb623fc..ffe3b80 100644 --- a/niv/tests/src/test_shared_memory.cpp +++ b/niv/tests/src/test_shared_memory.cpp @@ -20,6 +20,7 @@ //------------------------------------------------------------------------------ #include +#include #include "catch/catch.hpp" @@ -48,6 +49,20 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { } } + WHEN("I store data in the segment") { + std::vector some_data{1u, 2u, 3u}; + auto free_size_before = segment.GetFreeSize(); + segment.Store(some_data); + auto free_size_after = segment.GetFreeSize(); + THEN("I can retrieve it") { + auto retrieved_data = segment.GetData(); + REQUIRE(retrieved_data == some_data); + } + THEN("we have less free space in the segment") { + REQUIRE(free_size_after < free_size_before); + } + } + WHEN("I request a schema string in that shared memory segment") { auto& schema = segment.GetSchemaString(); THEN("it is empty") { REQUIRE(schema.size() == 0); } From 7c63b33fcf9e7a3aad4389fcd953e9033fe3347a Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 15:52:23 +0200 Subject: [PATCH 54/71] Provide SProvide SharedData::Store and GetSchema --- niv/include/niv/shared_memory.hpp | 3 +++ niv/src/shared_memory.cpp | 9 +++++++++ niv/tests/src/test_shared_memory.cpp | 26 +++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp index 7382be3..c2e4983 100644 --- a/niv/include/niv/shared_memory.hpp +++ b/niv/include/niv/shared_memory.hpp @@ -22,6 +22,7 @@ #ifndef NIV_INCLUDE_NIV_SHARED_MEMORY_HPP_ #define NIV_INCLUDE_NIV_SHARED_MEMORY_HPP_ +#include #include #include @@ -55,7 +56,9 @@ class SharedMemory { SchemaString& GetSchemaString(); void Store(const std::vector& data); + void Store(const std::string& schema); std::vector GetData() const; + std::string GetSchema() const; static constexpr const char* SegmentName() { return "niv-shared-memory"; } static constexpr const char* DataVectorName() { return "DataVector"; } diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index b87cebe..ec93221 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -21,6 +21,7 @@ #include "niv/shared_memory.hpp" +#include #include #include @@ -57,9 +58,17 @@ void SharedMemory::Store(const std::vector& data) { data_vector_->assign(data.begin(), data.end()); } +void SharedMemory::Store(const std::string& schema) { + schema_string_->assign(schema.begin(), schema.end()); +} + std::vector SharedMemory::GetData() const { return std::vector{data_vector_->begin(), data_vector_->end()}; } +std::string SharedMemory::GetSchema() const { + return std::string{schema_string_->begin(), schema_string_->end()}; +} + } // namespace niv diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory.cpp index ffe3b80..a92f313 100644 --- a/niv/tests/src/test_shared_memory.cpp +++ b/niv/tests/src/test_shared_memory.cpp @@ -49,18 +49,42 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { } } + WHEN("I retrieve data from the new segment") { + auto retrieved_data = segment.GetData(); + THEN("it is empty") { REQUIRE(retrieved_data.size() == 0); } + } + WHEN("I store data in the segment") { std::vector some_data{1u, 2u, 3u}; auto free_size_before = segment.GetFreeSize(); segment.Store(some_data); auto free_size_after = segment.GetFreeSize(); - THEN("I can retrieve it") { + THEN("we have less free space in the segment") { + REQUIRE(free_size_after < free_size_before); + } + THEN("I can retrieve the data") { auto retrieved_data = segment.GetData(); REQUIRE(retrieved_data == some_data); } + } + + WHEN("I retrieve the schema from the new segment") { + auto retrieved_schema = segment.GetSchema(); + THEN("it is empty") { REQUIRE(retrieved_schema.size() == 0); } + } + + WHEN("I store a scema in the segment") { + std::string some_schema{"foo bar"}; + auto free_size_before = segment.GetFreeSize(); + segment.Store(some_schema); + auto free_size_after = segment.GetFreeSize(); THEN("we have less free space in the segment") { REQUIRE(free_size_after < free_size_before); } + THEN("I can retrieve it") { + auto retrieved_schema = segment.GetSchema(); + REQUIRE(retrieved_schema == some_schema); + } } WHEN("I request a schema string in that shared memory segment") { From 920dcbbe9339efc5c99fee7e5a17158b5e3c0214 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Fri, 1 Sep 2017 15:59:59 +0200 Subject: [PATCH 55/71] Remove SharedData::GetDataVector, GetSchemaString. Adjust tests. --- niv/include/niv/shared_memory.hpp | 2 -- niv/src/shared_memory.cpp | 6 ---- niv/tests/src/test_shared_memory.cpp | 36 +-------------------- niv/tests/src/test_shared_memory_access.cpp | 28 ++++++---------- 4 files changed, 11 insertions(+), 61 deletions(-) diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp index c2e4983..5e2d1d5 100644 --- a/niv/include/niv/shared_memory.hpp +++ b/niv/include/niv/shared_memory.hpp @@ -52,8 +52,6 @@ class SharedMemory { void Destroy(); std::size_t GetFreeSize() const; - DataVector& GetDataVector(); - SchemaString& GetSchemaString(); void Store(const std::vector& data); void Store(const std::string& schema); diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index ec93221..a9e2553 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -47,12 +47,6 @@ void SharedMemory::Destroy() { std::size_t SharedMemory::GetFreeSize() const { return segment_.get_free_memory(); } -SharedMemory::DataVector& SharedMemory::GetDataVector() { - return *data_vector_; -} -SharedMemory::SchemaString& SharedMemory::GetSchemaString() { - return *schema_string_; -} void SharedMemory::Store(const std::vector& data) { data_vector_->assign(data.begin(), data.end()); diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory.cpp index a92f313..fab68b4 100644 --- a/niv/tests/src/test_shared_memory.cpp +++ b/niv/tests/src/test_shared_memory.cpp @@ -34,21 +34,6 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { THEN("it is > 0") { REQUIRE(free_size_after_creation > 0); } } - WHEN("I request a data vector in that shared memory segment") { - auto& data = segment.GetDataVector(); - THEN("it is empty") { REQUIRE(data.size() == 0); } - - WHEN("I add one data entry into the vector") { - auto free_size_before_push = segment.GetFreeSize(); - data.push_back(conduit::uint8{9u}); - auto free_size_after_push = segment.GetFreeSize(); - THEN("I can retrieve it") { REQUIRE(data[0] == conduit::uint8{9u}); } - THEN("we have less free space in the segment") { - REQUIRE(free_size_after_push < free_size_before_push); - } - } - } - WHEN("I retrieve data from the new segment") { auto retrieved_data = segment.GetData(); THEN("it is empty") { REQUIRE(retrieved_data.size() == 0); } @@ -73,7 +58,7 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { THEN("it is empty") { REQUIRE(retrieved_schema.size() == 0); } } - WHEN("I store a scema in the segment") { + WHEN("I store a schema in the segment") { std::string some_schema{"foo bar"}; auto free_size_before = segment.GetFreeSize(); segment.Store(some_schema); @@ -87,25 +72,6 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { } } - WHEN("I request a schema string in that shared memory segment") { - auto& schema = segment.GetSchemaString(); - THEN("it is empty") { REQUIRE(schema.size() == 0); } - - WHEN("I assign a string to the schema") { - const std::string any_string{"foo_bar"}; - auto free_size_before_assign = segment.GetFreeSize(); - schema.assign(any_string.begin(), any_string.end()); - auto free_size_after_assign = segment.GetFreeSize(); - THEN("schema holds the string") { - const std::string schema_as_string{schema.begin(), schema.end()}; - REQUIRE(schema_as_string == any_string); - } - THEN("we have less free space in the segment") { - REQUIRE(free_size_after_assign < free_size_before_assign); - } - } - } - WHEN("I request a second shared memory segment") { THEN("It throws an exception") { REQUIRE_THROWS_WITH([]() { niv::SharedMemorySegment segment2; }(), diff --git a/niv/tests/src/test_shared_memory_access.cpp b/niv/tests/src/test_shared_memory_access.cpp index 0747110..4eb4002 100644 --- a/niv/tests/src/test_shared_memory_access.cpp +++ b/niv/tests/src/test_shared_memory_access.cpp @@ -37,14 +37,10 @@ SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { GIVEN("A shared memory segment with some data in it") { niv::SharedMemorySegment segment; - - auto& data = segment.GetDataVector(); - std::vector any_data{'a', 'b', 'c'}; - data.assign(any_data.begin(), any_data.end()); - - auto& schema = segment.GetSchemaString(); - const std::string any_schema{"foo_bar_baz"}; - schema.assign(any_schema.begin(), any_schema.end()); + std::vector some_data{1u, 2u, 3u}; + segment.Store(some_data); + std::string some_schema{"foo bar"}; + segment.Store(some_schema); WHEN("I create shared memory access") { THEN("It does not throw an exception") { @@ -52,19 +48,15 @@ SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { } niv::SharedMemoryAccess segment_access; - WHEN("I read the data") { - auto& data = segment_access.GetDataVector(); - THEN("I get the original data") { - std::vector data_as_vector{data.begin(), data.end()}; - REQUIRE(data_as_vector == any_data); - } + WHEN("I read the data from shared memory access") { + auto read_data = segment_access.GetData(); + THEN("I get the original data") { REQUIRE(read_data == some_data); } } - WHEN("I read the schema") { - auto& schema = segment_access.GetSchemaString(); + WHEN("I read the schema from shared memory access") { + auto read_schema = segment_access.GetSchema(); THEN("I get the original schema") { - const std::string schema_as_string{schema.begin(), schema.end()}; - REQUIRE(schema_as_string == any_schema); + REQUIRE(read_schema == some_schema); } } } From 71dbac16b57ee7da823c7abfa71c3660386af6c7 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Sat, 2 Sep 2017 00:23:59 +0200 Subject: [PATCH 56/71] Make SharedMemoryAccess destructor virtual --- niv/include/niv/shared_memory_access.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/niv/include/niv/shared_memory_access.hpp b/niv/include/niv/shared_memory_access.hpp index eaae40d..68dc8d6 100644 --- a/niv/include/niv/shared_memory_access.hpp +++ b/niv/include/niv/shared_memory_access.hpp @@ -29,7 +29,7 @@ namespace niv { class SharedMemoryAccess : public SharedMemory { public: SharedMemoryAccess(); - ~SharedMemoryAccess() = default; + virtual ~SharedMemoryAccess() = default; }; } // namespace niv From 12f2b4a92180995830dae9aaa51fde7bcc54896d Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Sat, 2 Sep 2017 00:24:33 +0200 Subject: [PATCH 57/71] Rename one test file --- .../{test_shared_memory.cpp => test_shared_memory_segment.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename niv/tests/src/{test_shared_memory.cpp => test_shared_memory_segment.cpp} (100%) diff --git a/niv/tests/src/test_shared_memory.cpp b/niv/tests/src/test_shared_memory_segment.cpp similarity index 100% rename from niv/tests/src/test_shared_memory.cpp rename to niv/tests/src/test_shared_memory_segment.cpp From d4c22f53eb3ef01f6b42a052e195a5286ee6d3d8 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Sat, 2 Sep 2017 00:25:00 +0200 Subject: [PATCH 58/71] Add Relay classes --- .../niv/receiving_relay_shared_memory.hpp | 45 +++++++++ niv/include/niv/relay_shared_memory.hpp | 42 ++++++++ .../niv/sending_relay_shared_memory.hpp | 49 ++++++++++ niv/src/receiving_relay_shared_memory.cpp | 42 ++++++++ niv/src/relay_shared_memory.cpp | 35 +++++++ niv/src/sending_relay_shared_memory.cpp | 54 +++++++++++ niv/tests/src/test_relay_shared_memory.cpp | 95 +++++++++++++++++++ 7 files changed, 362 insertions(+) create mode 100644 niv/include/niv/receiving_relay_shared_memory.hpp create mode 100644 niv/include/niv/relay_shared_memory.hpp create mode 100644 niv/include/niv/sending_relay_shared_memory.hpp create mode 100644 niv/src/receiving_relay_shared_memory.cpp create mode 100644 niv/src/relay_shared_memory.cpp create mode 100644 niv/src/sending_relay_shared_memory.cpp create mode 100644 niv/tests/src/test_relay_shared_memory.cpp diff --git a/niv/include/niv/receiving_relay_shared_memory.hpp b/niv/include/niv/receiving_relay_shared_memory.hpp new file mode 100644 index 0000000..4e97d4f --- /dev/null +++ b/niv/include/niv/receiving_relay_shared_memory.hpp @@ -0,0 +1,45 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 NIV_INCLUDE_NIV_RECEIVING_RELAY_SHARED_MEMORY_HPP_ +#define NIV_INCLUDE_NIV_RECEIVING_RELAY_SHARED_MEMORY_HPP_ + +#include + +#include "conduit/conduit_node.hpp" + +#include "niv/relay_shared_memory.hpp" +#include "niv/shared_memory.hpp" + +namespace niv { + +class ReceivingRelaySharedMemory : public RelaySharedMemory { + public: + explicit ReceivingRelaySharedMemory( + std::unique_ptr shared_memory); + virtual ~ReceivingRelaySharedMemory() = default; + + void Receive(conduit::Node* node); +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_RECEIVING_RELAY_SHARED_MEMORY_HPP_ diff --git a/niv/include/niv/relay_shared_memory.hpp b/niv/include/niv/relay_shared_memory.hpp new file mode 100644 index 0000000..8144d61 --- /dev/null +++ b/niv/include/niv/relay_shared_memory.hpp @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 NIV_INCLUDE_NIV_RELAY_SHARED_MEMORY_HPP_ +#define NIV_INCLUDE_NIV_RELAY_SHARED_MEMORY_HPP_ + +#include + +#include "niv/shared_memory.hpp" + +namespace niv { + +class RelaySharedMemory { + public: + virtual ~RelaySharedMemory() = default; + + protected: + explicit RelaySharedMemory(std::unique_ptr shared_memory); + std::unique_ptr shared_memory_; +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_RELAY_SHARED_MEMORY_HPP_ diff --git a/niv/include/niv/sending_relay_shared_memory.hpp b/niv/include/niv/sending_relay_shared_memory.hpp new file mode 100644 index 0000000..d168a12 --- /dev/null +++ b/niv/include/niv/sending_relay_shared_memory.hpp @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 NIV_INCLUDE_NIV_SENDING_RELAY_SHARED_MEMORY_HPP_ +#define NIV_INCLUDE_NIV_SENDING_RELAY_SHARED_MEMORY_HPP_ + +#include + +#include "conduit/conduit_node.hpp" + +#include "niv/relay_shared_memory.hpp" +#include "niv/shared_memory.hpp" + +namespace niv { + +class SendingRelaySharedMemory : public RelaySharedMemory { + public: + explicit SendingRelaySharedMemory( + std::unique_ptr shared_memory); + virtual ~SendingRelaySharedMemory() = default; + + void Send(const conduit::Node& node); + + private: + void SendData(const conduit::Node& node); + void SendSchema(const conduit::Node& node); +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_SENDING_RELAY_SHARED_MEMORY_HPP_ diff --git a/niv/src/receiving_relay_shared_memory.cpp b/niv/src/receiving_relay_shared_memory.cpp new file mode 100644 index 0000000..6f71bbd --- /dev/null +++ b/niv/src/receiving_relay_shared_memory.cpp @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "niv/receiving_relay_shared_memory.hpp" + +#include +#include + +#include "conduit/conduit_node.hpp" +#include "conduit/conduit_schema.hpp" + +namespace niv { + +ReceivingRelaySharedMemory::ReceivingRelaySharedMemory( + std::unique_ptr shared_memory) + : RelaySharedMemory{std::move(shared_memory)} {} + +void ReceivingRelaySharedMemory::Receive(conduit::Node* node) { + auto schema = shared_memory_->GetSchema(); + auto data = shared_memory_->GetData(); + node->set_data_using_schema(conduit::Schema(schema), data.data()); +} + +} // namespace niv diff --git a/niv/src/relay_shared_memory.cpp b/niv/src/relay_shared_memory.cpp new file mode 100644 index 0000000..9d3877e --- /dev/null +++ b/niv/src/relay_shared_memory.cpp @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "niv/relay_shared_memory.hpp" + +#include +#include + +#include "niv/shared_memory_segment.hpp" + +namespace niv { + +RelaySharedMemory::RelaySharedMemory( + std::unique_ptr shared_memory) + : shared_memory_{std::move(shared_memory)} {} + +} // namespace niv diff --git a/niv/src/sending_relay_shared_memory.cpp b/niv/src/sending_relay_shared_memory.cpp new file mode 100644 index 0000000..4e681c1 --- /dev/null +++ b/niv/src/sending_relay_shared_memory.cpp @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "niv/sending_relay_shared_memory.hpp" + +#include +#include +#include + +#include "conduit/conduit_node.hpp" +#include "conduit/conduit_schema.hpp" + +namespace niv { + +SendingRelaySharedMemory::SendingRelaySharedMemory( + std::unique_ptr shared_memory) + : RelaySharedMemory{std::move(shared_memory)} {} + +void SendingRelaySharedMemory::Send(const conduit::Node& node) { + SendData(node); + SendSchema(node); +} + +void SendingRelaySharedMemory::SendData(const conduit::Node& node) { + std::vector data; + node.serialize(data); + shared_memory_->Store(data); +} + +void SendingRelaySharedMemory::SendSchema(const conduit::Node& node) { + conduit::Schema schema; + node.schema().compact_to(schema); + shared_memory_->Store(schema.to_json()); +} + +} // namespace niv diff --git a/niv/tests/src/test_relay_shared_memory.cpp b/niv/tests/src/test_relay_shared_memory.cpp new file mode 100644 index 0000000..fc8a5de --- /dev/null +++ b/niv/tests/src/test_relay_shared_memory.cpp @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "catch/catch.hpp" + +#include "conduit/conduit_node.hpp" + +#include "niv/receiving_relay_shared_memory.hpp" +#include "niv/sending_relay_shared_memory.hpp" +#include "niv/shared_memory_access.hpp" +#include "niv/shared_memory_segment.hpp" + +namespace { +conduit::Node AnyNode() { + conduit::Node node; + node["A"]["B"]["E"] = 1.1; + node["A"]["C"]["F"] = 2.1; + node["A"]["C"]["G"] = 2.2; + node["A"]["D"]["H"] = 3.1; + node["A"]["D"]["I"] = 3.2; + node["A"]["D"]["J"] = 3.3; + return node; +} + +void REQUIRE_EQ(const conduit::Node left, const conduit::Node right) { + REQUIRE(left["A"]["B"]["E"].as_double() == right["A"]["B"]["E"].as_double()); + REQUIRE(left["A"]["C"]["F"].as_double() == right["A"]["C"]["F"].as_double()); + REQUIRE(left["A"]["C"]["G"].as_double() == left["A"]["C"]["G"].as_double()); + REQUIRE(left["A"]["D"]["H"].as_double() == right["A"]["D"]["H"].as_double()); + REQUIRE(left["A"]["D"]["I"].as_double() == right["A"]["D"]["I"].as_double()); + REQUIRE(left["A"]["D"]["J"].as_double() == right["A"]["D"]["J"].as_double()); +} + +conduit::Node& AnyLeaf(conduit::Node* node) { return (*node)["A"]["D"]["H"]; } + +constexpr double kAnyOtherValue{42.0f}; + +} // namespace + +SCENARIO("Communicate a conduit node", "[niv][nvi::RelaySharedMemory]") { + GIVEN( + "A conduit node with some data, a sending shared memory relay, and a " + "reveiving node") { + conduit::Node any_node{::AnyNode()}; + + niv::SendingRelaySharedMemory sending_relay{ + std::make_unique()}; + + conduit::Node receiving_node; + + GIVEN("a receiving shared memory relay") { + niv::ReceivingRelaySharedMemory receiving_relay{ + std::make_unique()}; + + WHEN("I send the data via the sending relay") { + sending_relay.Send(any_node); + + THEN("I receive the data on the receiving relay") { + receiving_relay.Receive(&receiving_node); + REQUIRE_EQ(receiving_node, any_node); + } + + WHEN("I change one value and send again") { + ::AnyLeaf(&any_node) = ::kAnyOtherValue; + sending_relay.Send(any_node); + + THEN("I receive the data on the receiving relay") { + receiving_relay.Receive(&receiving_node); + REQUIRE_EQ(receiving_node, any_node); + } + } + } + } + } +} From 9cfc19ead192b47af6ac22958e1e83cecfe52b8e Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Sat, 2 Sep 2017 00:40:47 +0200 Subject: [PATCH 59/71] Provide listening to shared data that may change --- .../niv/receiving_relay_shared_memory.hpp | 1 + niv/include/niv/shared_memory.hpp | 1 + niv/src/receiving_relay_shared_memory.cpp | 6 ++++ niv/src/shared_memory.cpp | 4 +++ niv/tests/src/test_relay_shared_memory.cpp | 33 ++++++++++++------- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/niv/include/niv/receiving_relay_shared_memory.hpp b/niv/include/niv/receiving_relay_shared_memory.hpp index 4e97d4f..0193274 100644 --- a/niv/include/niv/receiving_relay_shared_memory.hpp +++ b/niv/include/niv/receiving_relay_shared_memory.hpp @@ -38,6 +38,7 @@ class ReceivingRelaySharedMemory : public RelaySharedMemory { virtual ~ReceivingRelaySharedMemory() = default; void Receive(conduit::Node* node); + void Listen(conduit::Node* node); }; } // namespace niv diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp index 5e2d1d5..cdcd76e 100644 --- a/niv/include/niv/shared_memory.hpp +++ b/niv/include/niv/shared_memory.hpp @@ -56,6 +56,7 @@ class SharedMemory { void Store(const std::vector& data); void Store(const std::string& schema); std::vector GetData() const; + conduit::uint8* GetRawData() const; std::string GetSchema() const; static constexpr const char* SegmentName() { return "niv-shared-memory"; } diff --git a/niv/src/receiving_relay_shared_memory.cpp b/niv/src/receiving_relay_shared_memory.cpp index 6f71bbd..9830240 100644 --- a/niv/src/receiving_relay_shared_memory.cpp +++ b/niv/src/receiving_relay_shared_memory.cpp @@ -39,4 +39,10 @@ void ReceivingRelaySharedMemory::Receive(conduit::Node* node) { node->set_data_using_schema(conduit::Schema(schema), data.data()); } +void ReceivingRelaySharedMemory::Listen(conduit::Node* node) { + auto schema = shared_memory_->GetSchema(); + auto raw_data = shared_memory_->GetRawData(); + node->set_external_data_using_schema(conduit::Schema(schema), raw_data); +} + } // namespace niv diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp index a9e2553..d3f184a 100644 --- a/niv/src/shared_memory.cpp +++ b/niv/src/shared_memory.cpp @@ -61,6 +61,10 @@ std::vector SharedMemory::GetData() const { data_vector_->end()}; } +conduit::uint8* SharedMemory::GetRawData() const { + return data_vector_->data(); +} + std::string SharedMemory::GetSchema() const { return std::string{schema_string_->begin(), schema_string_->end()}; } diff --git a/niv/tests/src/test_relay_shared_memory.cpp b/niv/tests/src/test_relay_shared_memory.cpp index fc8a5de..d43e50c 100644 --- a/niv/tests/src/test_relay_shared_memory.cpp +++ b/niv/tests/src/test_relay_shared_memory.cpp @@ -42,10 +42,10 @@ conduit::Node AnyNode() { return node; } -void REQUIRE_EQ(const conduit::Node left, const conduit::Node right) { +void REQUIRE_EQ(const conduit::Node& left, const conduit::Node& right) { REQUIRE(left["A"]["B"]["E"].as_double() == right["A"]["B"]["E"].as_double()); REQUIRE(left["A"]["C"]["F"].as_double() == right["A"]["C"]["F"].as_double()); - REQUIRE(left["A"]["C"]["G"].as_double() == left["A"]["C"]["G"].as_double()); + REQUIRE(left["A"]["C"]["G"].as_double() == right["A"]["C"]["G"].as_double()); REQUIRE(left["A"]["D"]["H"].as_double() == right["A"]["D"]["H"].as_double()); REQUIRE(left["A"]["D"]["I"].as_double() == right["A"]["D"]["I"].as_double()); REQUIRE(left["A"]["D"]["J"].as_double() == right["A"]["D"]["J"].as_double()); @@ -59,33 +59,44 @@ constexpr double kAnyOtherValue{42.0f}; SCENARIO("Communicate a conduit node", "[niv][nvi::RelaySharedMemory]") { GIVEN( - "A conduit node with some data, a sending shared memory relay, and a " - "reveiving node") { + "A conduit node with some data, a sending shared memory relay, a " + "receiving shared memory relay, and a receiving node") { conduit::Node any_node{::AnyNode()}; - niv::SendingRelaySharedMemory sending_relay{ std::make_unique()}; - + niv::ReceivingRelaySharedMemory receiving_relay{ + std::make_unique()}; conduit::Node receiving_node; - GIVEN("a receiving shared memory relay") { - niv::ReceivingRelaySharedMemory receiving_relay{ - std::make_unique()}; + WHEN("I send the data via the sending relay") { + sending_relay.Send(any_node); - WHEN("I send the data via the sending relay") { + THEN("I receive the data on the receiving relay") { + receiving_relay.Receive(&receiving_node); + REQUIRE_EQ(receiving_node, any_node); + } + + WHEN("I change one value and send again") { + ::AnyLeaf(&any_node) = ::kAnyOtherValue; sending_relay.Send(any_node); THEN("I receive the data on the receiving relay") { receiving_relay.Receive(&receiving_node); REQUIRE_EQ(receiving_node, any_node); } + } + + WHEN("I listen to the data on the receiving relay") { + receiving_relay.Listen(&receiving_node); + THEN("I receive the data on the receiving relay") { + REQUIRE_EQ(receiving_node, any_node); + } WHEN("I change one value and send again") { ::AnyLeaf(&any_node) = ::kAnyOtherValue; sending_relay.Send(any_node); THEN("I receive the data on the receiving relay") { - receiving_relay.Receive(&receiving_node); REQUIRE_EQ(receiving_node, any_node); } } From 407bbe8a3f5028c3c23f9f8b7965a86efe7a81ad Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Mon, 4 Sep 2017 07:01:44 +0200 Subject: [PATCH 60/71] Add relay test for sending from shared mem access to segment --- niv/tests/src/test_relay_shared_memory.cpp | 56 ++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/niv/tests/src/test_relay_shared_memory.cpp b/niv/tests/src/test_relay_shared_memory.cpp index d43e50c..b07e5aa 100644 --- a/niv/tests/src/test_relay_shared_memory.cpp +++ b/niv/tests/src/test_relay_shared_memory.cpp @@ -57,10 +57,11 @@ constexpr double kAnyOtherValue{42.0f}; } // namespace -SCENARIO("Communicate a conduit node", "[niv][nvi::RelaySharedMemory]") { +SCENARIO("Communicate a conduit node from shared mem segment to access", + "[niv][nvi::RelaySharedMemory]") { GIVEN( - "A conduit node with some data, a sending shared memory relay, a " - "receiving shared memory relay, and a receiving node") { + "A conduit node with some data, a sending shared memory segment relay, a " + "receiving shared memory access relay, and a receiving node") { conduit::Node any_node{::AnyNode()}; niv::SendingRelaySharedMemory sending_relay{ std::make_unique()}; @@ -104,3 +105,52 @@ SCENARIO("Communicate a conduit node", "[niv][nvi::RelaySharedMemory]") { } } } + +SCENARIO("Communicate a conduit node from shared mem access to segment", + "[niv][nvi::RelaySharedMemory]") { + GIVEN( + "A conduit node with some data, a sending shared memory access relay, a " + "receiving shared memory segment relay, and a receiving node") { + niv::ReceivingRelaySharedMemory receiving_relay{ + std::make_unique()}; + conduit::Node receiving_node; + conduit::Node any_node{::AnyNode()}; + niv::SendingRelaySharedMemory sending_relay{ + std::make_unique()}; + + WHEN("I send the data via the sending relay") { + sending_relay.Send(any_node); + + THEN("I receive the data on the receiving relay") { + receiving_relay.Receive(&receiving_node); + REQUIRE_EQ(receiving_node, any_node); + } + + WHEN("I change one value and send again") { + ::AnyLeaf(&any_node) = ::kAnyOtherValue; + sending_relay.Send(any_node); + + THEN("I receive the data on the receiving relay") { + receiving_relay.Receive(&receiving_node); + REQUIRE_EQ(receiving_node, any_node); + } + } + + WHEN("I listen to the data on the receiving relay") { + receiving_relay.Listen(&receiving_node); + THEN("I receive the data on the receiving relay") { + REQUIRE_EQ(receiving_node, any_node); + } + + WHEN("I change one value and send again") { + ::AnyLeaf(&any_node) = ::kAnyOtherValue; + sending_relay.Send(any_node); + + THEN("I receive the data on the receiving relay") { + REQUIRE_EQ(receiving_node, any_node); + } + } + } + } + } +} From a0f99fa4dd31b0878125a1b9cf5800703fd151ff Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Mon, 4 Sep 2017 16:09:47 +0200 Subject: [PATCH 61/71] Add helper apps --- niv/CMakeLists.txt | 1 + niv/helper_apps/CMakeLists.txt | 27 +++++++++ niv/helper_apps/src/shared_memory.cpp | 86 +++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 niv/helper_apps/CMakeLists.txt create mode 100644 niv/helper_apps/src/shared_memory.cpp diff --git a/niv/CMakeLists.txt b/niv/CMakeLists.txt index 942338e..3a0f319 100644 --- a/niv/CMakeLists.txt +++ b/niv/CMakeLists.txt @@ -53,3 +53,4 @@ add_test_cpplint(NAME "niv--cpplint" generate_configure_files(niv) add_subdirectory(tests) +add_subdirectory(helper_apps) diff --git a/niv/helper_apps/CMakeLists.txt b/niv/helper_apps/CMakeLists.txt new file mode 100644 index 0000000..037766a --- /dev/null +++ b/niv/helper_apps/CMakeLists.txt @@ -0,0 +1,27 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed 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(niv-shared-memory + src/shared_memory.cpp + ) +target_link_libraries(niv-shared-memory + niv + ) diff --git a/niv/helper_apps/src/shared_memory.cpp b/niv/helper_apps/src/shared_memory.cpp new file mode 100644 index 0000000..6e59914 --- /dev/null +++ b/niv/helper_apps/src/shared_memory.cpp @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 +#include + +#include "conduit/conduit_node.hpp" +#include "conduit/conduit_schema.hpp" + +#include "niv/shared_memory.hpp" + +conduit::Node AnyNode() { + conduit::Node node; + node["A"]["B"]["E"] = 1.1; + node["A"]["C"]["F"] = 2.1; + node["A"]["C"]["G"] = 2.2; + node["A"]["D"]["H"] = 3.1; + node["A"]["D"]["I"] = 3.2; + node["A"]["D"]["J"] = 3.3; + return node; +} + +void StoreSchema(const conduit::Node& node, niv::SharedMemory* shared_memory) { + conduit::Schema schema; + node.schema().compact_to(schema); + shared_memory->Store(schema.to_json()); +} + +void StoreData(const conduit::Node& node, niv::SharedMemory* shared_memory) { + std::vector data; + node.serialize(data); + shared_memory->Store(data); +} + +void FillWithData(niv::SharedMemory* shared_memory) { + conduit::Node node{AnyNode()}; + StoreSchema(node, shared_memory); + StoreData(node, shared_memory); +} + +void Create() { + niv::SharedMemory shared_memory{niv::SharedMemory::Create()}; + FillWithData(&shared_memory); +} + +void Destroy() { + niv::SharedMemory s{niv::SharedMemory::Access()}; + s.Destroy(); +} + +int Command(char* command) { + if (std::string(command) == std::string("create")) { + Create(); + return EXIT_SUCCESS; + } else if (std::string(command) == std::string("destroy")) { + Destroy(); + return EXIT_SUCCESS; + } + return EXIT_FAILURE; +} + +int main(int argc, char** argv) { + if (argc == 2) { + return Command(argv[1]); + } + return EXIT_FAILURE; +} From fc7ba36867b403bf68c94ca48c25fa3daac1a37e Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Mon, 4 Sep 2017 16:40:57 +0200 Subject: [PATCH 62/71] Add, expose test ConduitReceiver --- niv/include/niv/conduit_receiver.hpp | 48 ++++++++++++++++++++++ niv/src/conduit_receiver.cpp | 34 ++++++++++++++++ niv/tests/src/test_conduit_receiver.cpp | 53 +++++++++++++++++++++++++ pyniv/src/conduit_data.cpp | 2 +- pyniv/src/conduit_data.hpp | 2 + pyniv/src/conduit_data_sender.cpp | 39 ++++++++++++++++++ pyniv/src/conduit_data_sender.hpp | 44 ++++++++++++++++++++ pyniv/src/conduit_receiver.cpp | 35 ++++++++++++++++ pyniv/src/pyniv.cpp | 4 ++ pyniv/src/pyniv.hpp | 1 + pyniv/tests/src/test_pynpv.py | 18 ++++++++- 11 files changed, 278 insertions(+), 2 deletions(-) create mode 100644 niv/include/niv/conduit_receiver.hpp create mode 100644 niv/src/conduit_receiver.cpp create mode 100644 niv/tests/src/test_conduit_receiver.cpp create mode 100644 pyniv/src/conduit_data_sender.cpp create mode 100644 pyniv/src/conduit_data_sender.hpp create mode 100644 pyniv/src/conduit_receiver.cpp diff --git a/niv/include/niv/conduit_receiver.hpp b/niv/include/niv/conduit_receiver.hpp new file mode 100644 index 0000000..3e061e9 --- /dev/null +++ b/niv/include/niv/conduit_receiver.hpp @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 NIV_INCLUDE_NIV_CONDUIT_RECEIVER_HPP_ +#define NIV_INCLUDE_NIV_CONDUIT_RECEIVER_HPP_ + +#include +#include + +#include "conduit/conduit_node.hpp" + +#include "niv/receiving_relay_shared_memory.hpp" +#include "niv/shared_memory_segment.hpp" + +namespace niv { + +class ConduitReceiver { + public: + void Start(); + double Get(const std::string& path) const; + + private: + niv::ReceivingRelaySharedMemory relay_{ + std::make_unique()}; + conduit::Node node_; +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_CONDUIT_RECEIVER_HPP_ diff --git a/niv/src/conduit_receiver.cpp b/niv/src/conduit_receiver.cpp new file mode 100644 index 0000000..4e15be3 --- /dev/null +++ b/niv/src/conduit_receiver.cpp @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "niv/conduit_receiver.hpp" + +#include + +namespace niv { + +void ConduitReceiver::Start() { relay_.Listen(&node_); } + +double ConduitReceiver::Get(const std::string& path) const { + return node_.fetch(path).as_double(); +} + +} // namespace niv diff --git a/niv/tests/src/test_conduit_receiver.cpp b/niv/tests/src/test_conduit_receiver.cpp new file mode 100644 index 0000000..ebf0ff6 --- /dev/null +++ b/niv/tests/src/test_conduit_receiver.cpp @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "catch/catch.hpp" + +#include "conduit/conduit_node.hpp" + +#include "niv/conduit_receiver.hpp" +#include "niv/sending_relay_shared_memory.hpp" +#include "niv/shared_memory_access.hpp" + +SCENARIO("Conduit data is received by a conduit receiver", + "[niv][niv::ConduitReceiver]") { + GIVEN("A ConduitReceiver") { + niv::ConduitReceiver receiver; + + WHEN("I send some data") { + conduit::Node data; + data["A"]["B"] = 17.0; + data["A"]["C"] = 42.0; + + niv::SendingRelaySharedMemory relay( + std::make_unique()); + relay.Send(data); + + THEN("I receive the data") { + receiver.Start(); + REQUIRE(receiver.Get("A/B") == 17.0); + REQUIRE(receiver.Get("A/C") == 42.0); + } + } + } +} diff --git a/pyniv/src/conduit_data.cpp b/pyniv/src/conduit_data.cpp index e9cb6f2..34d84d3 100644 --- a/pyniv/src/conduit_data.cpp +++ b/pyniv/src/conduit_data.cpp @@ -28,7 +28,7 @@ namespace pyniv { ConduitData::ConduitData() { - node_["V_m"] = 0.0; + node_["V_m"] = 1.2; std::cout << "Ptr. to conduit node: " << Pointer() << std::endl; } diff --git a/pyniv/src/conduit_data.hpp b/pyniv/src/conduit_data.hpp index 5b0252d..33f6518 100644 --- a/pyniv/src/conduit_data.hpp +++ b/pyniv/src/conduit_data.hpp @@ -36,6 +36,8 @@ class ConduitData { void Set(const char* attribute, double value); std::size_t Pointer() const; + const conduit::Node& GetNode() const { return node_; } + private: conduit::Node node_; }; diff --git a/pyniv/src/conduit_data_sender.cpp b/pyniv/src/conduit_data_sender.cpp new file mode 100644 index 0000000..ad085c6 --- /dev/null +++ b/pyniv/src/conduit_data_sender.cpp @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "conduit_data_sender.hpp" + +#include "conduit_data.hpp" +#include "pyniv.hpp" + +namespace pyniv { + +void ConduitDataSender::Send(const ConduitData& data) { + relay_.Send(data.GetNode()); +} + +template <> +void expose() { + class_("ConduitDataSender") + .def("Send", &ConduitDataSender::Send, args("data")); +} + +} // namespace pyniv diff --git a/pyniv/src/conduit_data_sender.hpp b/pyniv/src/conduit_data_sender.hpp new file mode 100644 index 0000000..8fa5a83 --- /dev/null +++ b/pyniv/src/conduit_data_sender.hpp @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 PYNIV_SRC_CONDUIT_DATA_SENDER_HPP_ +#define PYNIV_SRC_CONDUIT_DATA_SENDER_HPP_ + +#include "niv/sending_relay_shared_memory.hpp" +#include "niv/shared_memory_access.hpp" + +#include "conduit_data.hpp" + +namespace pyniv { + +class ConduitDataSender { + public: + void Send(const ConduitData& data); + + private: + niv::SendingRelaySharedMemory relay_{ + std::make_unique()}; + conduit::Node node_; +}; + +} // namespace pyniv + +#endif // PYNIV_SRC_CONDUIT_DATA_SENDER_HPP_ diff --git a/pyniv/src/conduit_receiver.cpp b/pyniv/src/conduit_receiver.cpp new file mode 100644 index 0000000..73943e5 --- /dev/null +++ b/pyniv/src/conduit_receiver.cpp @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed 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 "niv/conduit_receiver.hpp" + +#include "pyniv.hpp" + +namespace pyniv { + +template <> +void expose() { + class_("ConduitReceiver") + .def("Start", &niv::ConduitReceiver::Start) + .def("Get", &niv::ConduitReceiver::Get, args("path")); +} + +} // namespace pyniv diff --git a/pyniv/src/pyniv.cpp b/pyniv/src/pyniv.cpp index d1cf0db..bdbadd2 100644 --- a/pyniv/src/pyniv.cpp +++ b/pyniv/src/pyniv.cpp @@ -21,13 +21,17 @@ #include "pyniv.hpp" +#include "niv/conduit_receiver.hpp" #include "niv/nest_in_situ_vis.hpp" #include "niv/niv.hpp" #include "conduit_data.hpp" +#include "conduit_data_sender.hpp" BOOST_PYTHON_MODULE(pyniv) { def("Greet", niv::Greet); pyniv::expose(); + pyniv::expose(); + pyniv::expose(); pyniv::expose(); } diff --git a/pyniv/src/pyniv.hpp b/pyniv/src/pyniv.hpp index 6defd1e..360bb67 100644 --- a/pyniv/src/pyniv.hpp +++ b/pyniv/src/pyniv.hpp @@ -27,6 +27,7 @@ SUPPRESS_WARNINGS_BEGIN #include "boost/python.hpp" SUPPRESS_WARNINGS_END +using boost::python::args; using boost::python::class_; using boost::python::def; using boost::python::init; diff --git a/pyniv/tests/src/test_pynpv.py b/pyniv/tests/src/test_pynpv.py index 4dfcdfa..5030c7c 100644 --- a/pyniv/tests/src/test_pynpv.py +++ b/pyniv/tests/src/test_pynpv.py @@ -46,7 +46,7 @@ def test_pyniv_greet(): def test_pyniv_niv_NodeString_zero_on_creation(): d = pyniv.ConduitData(); v = pyniv.NestInSituVis(d.Pointer()); - assert v.NodeString() == "0" + assert v.NodeString() == "1.2" def test_pyniv_niv_NodeString_correct_after_set(): d = pyniv.ConduitData(); @@ -66,3 +66,19 @@ def test_pyniv_niv_StartStop(): v.Stop() assert len(c.ToString().split('\n')) > 2 + +def test_pyniv_receive_via_shared_mem_segment_relay(): + r = pyniv.ConduitReceiver() + + d = pyniv.ConduitData() + s = pyniv.ConduitDataSender() + s.Send(d) + + r.Start() + + assert r.Get("V_m") == 1.2 + + d.Set("V_m", 42.0) + s.Send(d) + + assert r.Get("V_m") == 42.0 From 5d4fcfd585489a29e86e532392c7275be8f79386 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 5 Sep 2017 16:09:24 +0200 Subject: [PATCH 63/71] Add nest python vis demo --- CMakeLists.txt | 1 + cmake/py.test.cmake | 2 +- demo/CMakeLists.txt | 22 +++++++++++ demo/nest_python_vis/CMakeLists.txt | 27 +++++++++++++ demo/nest_python_vis/nest_python_vis.py | 52 +++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 demo/CMakeLists.txt create mode 100644 demo/nest_python_vis/CMakeLists.txt create mode 100644 demo/nest_python_vis/nest_python_vis.py diff --git a/CMakeLists.txt b/CMakeLists.txt index b48f641..db6da92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,3 +53,4 @@ set_target_properties(conduit add_subdirectory(niv) add_subdirectory(pyniv) add_subdirectory(pytest_utilities) +add_subdirectory(demo) diff --git a/cmake/py.test.cmake b/cmake/py.test.cmake index 6246b5a..0694fe1 100644 --- a/cmake/py.test.cmake +++ b/cmake/py.test.cmake @@ -19,7 +19,7 @@ # limitations under the License. #------------------------------------------------------------------------------- -include(FindPythonInterp) +find_package(PythonInterp) if(NOT PYTHON_EXECUTABLE) message(SEND_ERROR " ERROR: Could not find any python interpreter. diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt new file mode 100644 index 0000000..f7ef20d --- /dev/null +++ b/demo/CMakeLists.txt @@ -0,0 +1,22 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed 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_subdirectory(nest_python_vis) diff --git a/demo/nest_python_vis/CMakeLists.txt b/demo/nest_python_vis/CMakeLists.txt new file mode 100644 index 0000000..24c0509 --- /dev/null +++ b/demo/nest_python_vis/CMakeLists.txt @@ -0,0 +1,27 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------- + +set(NEST_PYTHON_VIS_SOURCE nest_python_vis.py) + +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/run.sh + CONTENT "PYTHONPATH=$:$ ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${NEST_PYTHON_VIS_SOURCE}" + ) + diff --git a/demo/nest_python_vis/nest_python_vis.py b/demo/nest_python_vis/nest_python_vis.py new file mode 100644 index 0000000..9e58f9a --- /dev/null +++ b/demo/nest_python_vis/nest_python_vis.py @@ -0,0 +1,52 @@ +import sys + +import pyniv + +from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QGridLayout, QPushButton + +class MainWindow: + def __init__(self): + self.receiver = pyniv.ConduitReceiver() + self.SetupWindow() + + def SetupWindow(self): + self.label = QLabel("V_m:") + self.value = QLabel("0.0") + + self.start_button = QPushButton("Start") + self.start_button.clicked.connect(self.StartButtonClicked) + + self.layout = QGridLayout() + self.layout.addWidget(self.label, 0, 0) + self.layout.addWidget(self.value, 0, 1) + + self.layout.addWidget(self.start_button, 1, 0, 1, 2) + + self.window = QWidget() + self.window.setLayout(self.layout) + self.window.show() + + def StartButtonClicked(self): + self.start_button.setEnabled(False) + self.receiver.Start() + self.UpdateValue() + + def Show(self): + self.window.show() + + def UpdateValue(self): + print("{}".format(self.receiver.Get("V_m"))) + +def StartButtonClicked(): + print("FOO") + +def main(argv): + app = QApplication(argv) + + w = MainWindow() + w.Show() + + return app.exec_() + +if __name__ == "__main__": + main(sys.argv) From c7aae39d42a2dd63a600dc09992c01bbd53860e2 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 5 Sep 2017 16:09:38 +0200 Subject: [PATCH 64/71] Add fill command to shared memory helper app --- niv/helper_apps/src/shared_memory.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/niv/helper_apps/src/shared_memory.cpp b/niv/helper_apps/src/shared_memory.cpp index 6e59914..aa55b4a 100644 --- a/niv/helper_apps/src/shared_memory.cpp +++ b/niv/helper_apps/src/shared_memory.cpp @@ -62,6 +62,11 @@ void Create() { FillWithData(&shared_memory); } +void Fill() { + niv::SharedMemory shared_memory{niv::SharedMemory::Access()}; + FillWithData(&shared_memory); +} + void Destroy() { niv::SharedMemory s{niv::SharedMemory::Access()}; s.Destroy(); @@ -71,6 +76,8 @@ int Command(char* command) { if (std::string(command) == std::string("create")) { Create(); return EXIT_SUCCESS; + } else if (std::string(command) == "fill") { + Fill(); } else if (std::string(command) == std::string("destroy")) { Destroy(); return EXIT_SUCCESS; From ee1ebed8e58548d8440d25ad7e4960d66a3f5bc0 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 5 Sep 2017 16:49:54 +0200 Subject: [PATCH 65/71] Remove suprefluous output --- demo/nest_python_vis/nest_python_vis.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/demo/nest_python_vis/nest_python_vis.py b/demo/nest_python_vis/nest_python_vis.py index 9e58f9a..1a4cce0 100644 --- a/demo/nest_python_vis/nest_python_vis.py +++ b/demo/nest_python_vis/nest_python_vis.py @@ -35,11 +35,8 @@ def Show(self): self.window.show() def UpdateValue(self): - print("{}".format(self.receiver.Get("V_m"))) + pass -def StartButtonClicked(): - print("FOO") - def main(argv): app = QApplication(argv) From 3f8df7188acd173c2a340f28f3c2aedc9490b1a2 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 5 Sep 2017 17:08:09 +0200 Subject: [PATCH 66/71] Add auto update to vis mockup --- demo/nest_python_vis/nest_python_vis.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/demo/nest_python_vis/nest_python_vis.py b/demo/nest_python_vis/nest_python_vis.py index 1a4cce0..5770170 100644 --- a/demo/nest_python_vis/nest_python_vis.py +++ b/demo/nest_python_vis/nest_python_vis.py @@ -3,15 +3,18 @@ import pyniv from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QGridLayout, QPushButton +from PyQt5.QtCore import QTimer class MainWindow: def __init__(self): self.receiver = pyniv.ConduitReceiver() self.SetupWindow() + self.SetupUpdateTimer() + def SetupWindow(self): self.label = QLabel("V_m:") - self.value = QLabel("0.0") + self.value = QLabel("{:0.3f} mV".format(0.0)) self.start_button = QPushButton("Start") self.start_button.clicked.connect(self.StartButtonClicked) @@ -26,16 +29,24 @@ def SetupWindow(self): self.window.setLayout(self.layout) self.window.show() + def SetupUpdateTimer(self): + self.update_timer = QTimer() + self.update_timer.timeout.connect(self.UpdateValue) + + def StartButtonClicked(self): self.start_button.setEnabled(False) self.receiver.Start() + self.update_timer.start(0.01) self.UpdateValue() def Show(self): self.window.show() def UpdateValue(self): - pass + self.value.setText("{:0.3f} mV".format(self.receiver.Get("V_m"))) + self.value.update() + self.window.update() def main(argv): app = QApplication(argv) From d64bf52f148046d0088aaadbc3f4ae0b8391ae26 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Tue, 5 Sep 2017 17:15:19 +0200 Subject: [PATCH 67/71] Add g_ex g_in --- demo/nest_python_vis/nest_python_vis.py | 27 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/demo/nest_python_vis/nest_python_vis.py b/demo/nest_python_vis/nest_python_vis.py index 5770170..48d2164 100644 --- a/demo/nest_python_vis/nest_python_vis.py +++ b/demo/nest_python_vis/nest_python_vis.py @@ -13,17 +13,27 @@ def __init__(self): def SetupWindow(self): - self.label = QLabel("V_m:") - self.value = QLabel("{:0.3f} mV".format(0.0)) + self.label_V_m = QLabel("V_m:") + self.value_V_m = QLabel("{:0.3f} mV".format(0.0)) + + self.label_g_ex = QLabel("g_ex:") + self.value_g_ex = QLabel("{:0.3f}".format(0.0)) + + self.label_g_in = QLabel("g_ex:") + self.value_g_in = QLabel("{:0.3f}".format(0.0)) self.start_button = QPushButton("Start") self.start_button.clicked.connect(self.StartButtonClicked) self.layout = QGridLayout() - self.layout.addWidget(self.label, 0, 0) - self.layout.addWidget(self.value, 0, 1) + self.layout.addWidget(self.label_V_m, 0, 0) + self.layout.addWidget(self.value_V_m, 0, 1) + self.layout.addWidget(self.label_g_ex, 1, 0) + self.layout.addWidget(self.value_g_ex, 1, 1) + self.layout.addWidget(self.label_g_in, 2, 0) + self.layout.addWidget(self.value_g_in, 2, 1) - self.layout.addWidget(self.start_button, 1, 0, 1, 2) + self.layout.addWidget(self.start_button, 3, 0, 1, 2) self.window = QWidget() self.window.setLayout(self.layout) @@ -44,8 +54,11 @@ def Show(self): self.window.show() def UpdateValue(self): - self.value.setText("{:0.3f} mV".format(self.receiver.Get("V_m"))) - self.value.update() + self.value_V_m.setText("{:0.3f} mV".format(self.receiver.Get("V_m"))) + self.value_g_ex.setText("{:0.3f}".format(self.receiver.Get("g_ex"))) + self.value_g_in.setText("{:0.3f}".format(self.receiver.Get("g_in"))) + + self.value_V_m.update() self.window.update() def main(argv): From 43dbf06d146ae434b26115919b0a1e662c1e5838 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 6 Sep 2017 00:02:06 +0200 Subject: [PATCH 68/71] Add simulation script --- demo/nest_python_vis/CMakeLists.txt | 9 +- demo/nest_python_vis/nest_python_vis.py | 21 ++++ demo/nest_python_vis/nest_sim.py | 123 ++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 demo/nest_python_vis/nest_sim.py diff --git a/demo/nest_python_vis/CMakeLists.txt b/demo/nest_python_vis/CMakeLists.txt index 24c0509..88a19d6 100644 --- a/demo/nest_python_vis/CMakeLists.txt +++ b/demo/nest_python_vis/CMakeLists.txt @@ -20,8 +20,15 @@ #------------------------------------------------------------------------------- set(NEST_PYTHON_VIS_SOURCE nest_python_vis.py) +set(NEST_SIM_SOURCE nest_sim.py) -file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/run.sh +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/run_vis.sh CONTENT "PYTHONPATH=$:$ ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${NEST_PYTHON_VIS_SOURCE}" ) +set(NEST_DIR) +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/run_sim.sh + CONTENT +"source ${NEST_DIR}/bin/nest_vars.sh +PYTHONPATH=$:$PYTHONPATH ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${NEST_SIM_SOURCE}" + ) diff --git a/demo/nest_python_vis/nest_python_vis.py b/demo/nest_python_vis/nest_python_vis.py index 48d2164..5eda3e7 100644 --- a/demo/nest_python_vis/nest_python_vis.py +++ b/demo/nest_python_vis/nest_python_vis.py @@ -1,3 +1,24 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed 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. +#------------------------------------------------------------------------------- + import sys import pyniv diff --git a/demo/nest_python_vis/nest_sim.py b/demo/nest_python_vis/nest_sim.py new file mode 100644 index 0000000..5af7183 --- /dev/null +++ b/demo/nest_python_vis/nest_sim.py @@ -0,0 +1,123 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed 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. +#------------------------------------------------------------------------------- + +import sys +import nest +import numpy + +from PyQt5.QtWidgets import QApplication, QPushButton +from PyQt5.QtCore import QTimer + +class Simulation: + def __init__(self): + self.ConfigureNest() + self.CreateNeuron() + self.CreateAndConnectMultimeters() + self.CreateAndConnectSpikeGenerators() + + def ConfigureNest(self): + nest.ResetKernel() + nest.SetKernelStatus({"overwrite_files": True, + "data_path": "", + "data_prefix": ""}) + nest.SetDefaults('static_synapse', {'delay': 0.1}) + + def CreateNeuron(self): + neuron_params={"tau_syn_ex": 1.0, + "V_reset": -70.0} + self.neuron = nest.Create("iaf_cond_alpha", + params=neuron_params) + + def CreateAndConnectMultimeters(self): + self.CreateAndConnectConduitMultimeter() + self.CreateAndConnectScreenMultimeter() + + def CreateAndConnectConduitMultimeter(self): + multimeter_conduit_params = {"interval": 0.1, + "record_from": ["V_m", "g_ex", "g_in"], + "record_to": ["conduit"], + "label": "multimeter_conduit"} + multimeter_conduit = nest.Create("multimeter", + params=multimeter_conduit_params) + nest.Connect(multimeter_conduit, self.neuron) + + def CreateAndConnectScreenMultimeter(self): + multimeter_screen_params = {"interval": 0.1, + "record_from": ["V_m", "g_ex", "g_in"], + "record_to": ["screen"], + "label": "my_screen_multimeter"} + multimeter_screen = nest.Create("multimeter", + params=multimeter_screen_params) + nest.Connect(multimeter_screen, self.neuron) + + def CreateAndConnectSpikeGenerators(self): + self.CreateAndConnectExitatorySpikeGenerator() + self.CreateAndConnectInhibitorySpikeGenerator() + + def CreateAndConnectExitatorySpikeGenerator(self): + spikes_ex_params = {"spike_times": numpy.array([1.0, 5.0, 10.0, 15.0, 20.0, 50.0])} + spikes_ex = nest.Create("spike_generator", + params=spikes_ex_params) + nest.Connect(spikes_ex, self.neuron, syn_spec={"weight": 40.0}) + + def CreateAndConnectInhibitorySpikeGenerator(self): + spikes_in_params = {"spike_times": numpy.array([4.0, 8.0, 13.0, 18.0, 23.0, 53.0])} + spikes_in = nest.Create("spike_generator", + params=spikes_in_params) + nest.Connect(spikes_in, self.neuron, syn_spec={"weight": -20.0}) + + def Simulate(self, time): + nest.Simulate(time) + + +class MainWindow: + def __init__(self): + self.SetupWindow() + self.simulation = Simulation() + self.simulation.Simulate(0.2) + + def SetupWindow(self): + self.simulate_button = QPushButton("nest.Simulate(20)") + self.simulate_button.clicked.connect(self.SimulateButtonClicked) + + def SimulateButtonClicked(self): + self.simulate_button.setEnabled(False) + QApplication.processEvents() + + self.simulation.Simulate(20) + + QApplication.processEvents() + self.simulate_button.setEnabled(True) + + def Show(self): + self.simulate_button.show() + + +def main(argv): + app = QApplication(argv) + + w = MainWindow() + w.Show() + + return app.exec_() + +if __name__ == "__main__": + main(sys.argv) From 6bc94890bb6ae4be816bb8c74edbc156bbec013c Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 6 Sep 2017 00:15:11 +0200 Subject: [PATCH 69/71] Remove suprefluous files, tests --- niv/include/niv/nest_in_situ_vis.hpp | 79 ----------------- niv/src/nest_in_situ_vis.cpp | 88 ------------------- niv/tests/src/test_nest_in_situ_vis.cpp | 112 ------------------------ pyniv/src/nest_in_situ_vis.cpp | 37 -------- pyniv/src/pyniv.cpp | 2 - pyniv/tests/src/test_pynpv.py | 24 ----- 6 files changed, 342 deletions(-) delete mode 100644 niv/include/niv/nest_in_situ_vis.hpp delete mode 100644 niv/src/nest_in_situ_vis.cpp delete mode 100644 niv/tests/src/test_nest_in_situ_vis.cpp delete mode 100644 pyniv/src/nest_in_situ_vis.cpp diff --git a/niv/include/niv/nest_in_situ_vis.hpp b/niv/include/niv/nest_in_situ_vis.hpp deleted file mode 100644 index aca5339..0000000 --- a/niv/include/niv/nest_in_situ_vis.hpp +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// nest in situ vis -// -// Copyright (c) 2017 RWTH Aachen University, Germany, -// Virtual Reality & Immersive Visualisation Group. -//------------------------------------------------------------------------------ -// License -// -// Licensed 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 NIV_INCLUDE_NIV_NEST_IN_SITU_VIS_HPP_ -#define NIV_INCLUDE_NIV_NEST_IN_SITU_VIS_HPP_ - -#include -#include -#include -#include -#include - -#include "conduit/conduit.hpp" - -// gcc-5 does not accept using std::chrono_literals::operator""ms; -using namespace std::literals::chrono_literals; // NOLINT - -namespace niv { - -class NestInSituVis { - public: - explicit NestInSituVis(conduit::Node* node = nullptr); - explicit NestInSituVis(std::size_t ptr_to_node); - ~NestInSituVis(); - NestInSituVis(const NestInSituVis&) = delete; - - void Start(); - void Stop(); - - std::string NodeString() const; - void Read(const conduit::Schema& schema, std::vector* data); - - private: - void PrintNode() const; - std::string FormatNode() const; - void EnableIsRunning(); - void DisableIsRunning(); - bool IsRunning() const; - void Run(); - void Step(); - void Sleep() { std::this_thread::sleep_for(sleep_in_use_); } - void SpawnThread() { - thread_ = std::make_unique(&NestInSituVis::Run, this); - } - void JoinAndDeleteThread() { - if (thread_ != nullptr) { - thread_->join(); - thread_.reset(); - } - } - - conduit::Node* node_{nullptr}; - std::unique_ptr thread_{nullptr}; - static constexpr std::chrono::duration disabled_sleep_{0ms}; - std::chrono::duration configured_sleep_{10ms}; - std::chrono::duration sleep_in_use_{disabled_sleep_}; -}; - -} // namespace niv - -#endif // NIV_INCLUDE_NIV_NEST_IN_SITU_VIS_HPP_ diff --git a/niv/src/nest_in_situ_vis.cpp b/niv/src/nest_in_situ_vis.cpp deleted file mode 100644 index 79aa470..0000000 --- a/niv/src/nest_in_situ_vis.cpp +++ /dev/null @@ -1,88 +0,0 @@ -//------------------------------------------------------------------------------ -// nest in situ vis -// -// Copyright (c) 2017 RWTH Aachen University, Germany, -// Virtual Reality & Immersive Visualisation Group. -//------------------------------------------------------------------------------ -// License -// -// Licensed 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 "niv/nest_in_situ_vis.hpp" - -#include -#include -#include -#include - -namespace niv { - -constexpr std::chrono::duration NestInSituVis::disabled_sleep_; - -NestInSituVis::NestInSituVis(conduit::Node* node) : node_(node) {} - -NestInSituVis::NestInSituVis(std::size_t ptr_to_node) - : NestInSituVis(reinterpret_cast(ptr_to_node)) {} - -NestInSituVis::~NestInSituVis() { JoinAndDeleteThread(); } - -void NestInSituVis::Start() { - EnableIsRunning(); - SpawnThread(); -} - -void NestInSituVis::EnableIsRunning() { sleep_in_use_ = configured_sleep_; } - -void NestInSituVis::DisableIsRunning() { sleep_in_use_ = disabled_sleep_; } - -bool NestInSituVis::IsRunning() const { - return sleep_in_use_ != disabled_sleep_; -} - -void NestInSituVis::Stop() { - DisableIsRunning(); - JoinAndDeleteThread(); -} - -void NestInSituVis::Run() { - while (IsRunning()) { - Step(); - } -} - -void NestInSituVis::Step() { - PrintNode(); - Sleep(); -} - -void NestInSituVis::PrintNode() const { - std::cout << NodeString() << std::endl; -} - -std::string NestInSituVis::NodeString() const { - return node_ == nullptr ? "nullptr" : FormatNode(); -} - -std::string NestInSituVis::FormatNode() const { - std::ostringstream sstr; - sstr << (*node_)["V_m"].as_double(); - return sstr.str(); -} - -void NestInSituVis::Read(const conduit::Schema& schema, - std::vector* data) { - node_->set_external(schema, data->data()); -} - -} // namespace niv diff --git a/niv/tests/src/test_nest_in_situ_vis.cpp b/niv/tests/src/test_nest_in_situ_vis.cpp deleted file mode 100644 index 72345b4..0000000 --- a/niv/tests/src/test_nest_in_situ_vis.cpp +++ /dev/null @@ -1,112 +0,0 @@ -//------------------------------------------------------------------------------ -// nest in situ vis -// -// Copyright (c) 2017 RWTH Aachen University, Germany, -// Virtual Reality & Immersive Visualisation Group. -//------------------------------------------------------------------------------ -// License -// -// Licensed 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 -#include -#include -#include -#include - -#include "catch/catch.hpp" - -#include "conduit/conduit.hpp" - -#include "niv/nest_in_situ_vis.hpp" - -#include "test_utilities/cout_capture.hpp" - -// gcc-5 does not accept using std::chrono_literals::operator""ms; -using namespace std::literals::chrono_literals; // NOLINT - -SCENARIO("An niv object shall visualize the double it is bound to", - "[niv][niv::NestInSituVis") { - GIVEN( - "A membrane potenial in a conduit node and A NestInSituVis " - "object") { - conduit::Node node; - node["V_m"] = 0.0; - niv::NestInSituVis vis(&node); - - WHEN("I ask for a string representing the value") { - auto ret_node = vis.NodeString(); - THEN("it shall represent the bound value.") { REQUIRE(ret_node == "0"); } - } - - WHEN("the bound value is changed by some external code") { - node["V_m"] = 42.0; - THEN("its string representation shall be updated accordingly.") { - REQUIRE(vis.NodeString() == "42"); - } - } - - WHEN("I run the visualization for 30 ms") { - test_utilities::CoutCapture cout_capture; - vis.Start(); - std::this_thread::sleep_for(30ms); - vis.Stop(); - THEN( - "I will find more than one linebreak in printed the string " - "representation") { - const std::string cout_string = cout_capture.ToString(); - auto num_linebreaks = - std::count(cout_string.begin(), cout_string.end(), '\n'); - REQUIRE(num_linebreaks > 1); - } - } - - GIVEN("A vector for buffering data") { - std::vector data; - THEN("the buffer is empty") { REQUIRE(data.size() == 0); } - WHEN("When I ask the node to serialize into the buffer") { - node.serialize(data); - THEN("there is data in it") { REQUIRE(data.size() > 0); } - } - } - - GIVEN("Another node and a buffer") { - conduit::Node another_node; - another_node["V_m"] = 3.1415926; - std::vector data; - WHEN( - "I serialize another node into the buffer and read the buffer into " - "the visualization") { - another_node.serialize(data); - conduit::Schema schema; - another_node.schema().compact_to(schema); - - vis.Read(schema, &data); - THEN("the first node will have acquired the data") { - REQUIRE(node["V_m"].as_double() == Approx(3.1415926)); - } - } - } - } - - GIVEN("A NestInSituVis object bound to nullptr") { - niv::NestInSituVis vis(nullptr); - WHEN("I ask for a string representing tha value") { - auto ret_val = vis.NodeString(); - THEN("it shall read 'nullptr'.") { REQUIRE(ret_val == "nullptr"); } - } - } -} diff --git a/pyniv/src/nest_in_situ_vis.cpp b/pyniv/src/nest_in_situ_vis.cpp deleted file mode 100644 index 0e76d0a..0000000 --- a/pyniv/src/nest_in_situ_vis.cpp +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// nest in situ vis -// -// Copyright (c) 2017 RWTH Aachen University, Germany, -// Virtual Reality & Immersive Visualisation Group. -//------------------------------------------------------------------------------ -// License -// -// Licensed 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 "niv/nest_in_situ_vis.hpp" - -#include "pyniv.hpp" - -namespace pyniv { - -template <> -void expose() { - class_("NestInSituVis", - init()) - .def("NodeString", &niv::NestInSituVis::NodeString) - .def("Start", &niv::NestInSituVis::Start) - .def("Stop", &niv::NestInSituVis::Stop); -} - -} // namespace pyniv diff --git a/pyniv/src/pyniv.cpp b/pyniv/src/pyniv.cpp index bdbadd2..f0f7a70 100644 --- a/pyniv/src/pyniv.cpp +++ b/pyniv/src/pyniv.cpp @@ -22,7 +22,6 @@ #include "pyniv.hpp" #include "niv/conduit_receiver.hpp" -#include "niv/nest_in_situ_vis.hpp" #include "niv/niv.hpp" #include "conduit_data.hpp" @@ -33,5 +32,4 @@ BOOST_PYTHON_MODULE(pyniv) { pyniv::expose(); pyniv::expose(); pyniv::expose(); - pyniv::expose(); } diff --git a/pyniv/tests/src/test_pynpv.py b/pyniv/tests/src/test_pynpv.py index 5030c7c..3f8fd95 100644 --- a/pyniv/tests/src/test_pynpv.py +++ b/pyniv/tests/src/test_pynpv.py @@ -43,30 +43,6 @@ def test_cout_capture(capsys): def test_pyniv_greet(): assert pyniv.Greet() == "G'day!" -def test_pyniv_niv_NodeString_zero_on_creation(): - d = pyniv.ConduitData(); - v = pyniv.NestInSituVis(d.Pointer()); - assert v.NodeString() == "1.2" - -def test_pyniv_niv_NodeString_correct_after_set(): - d = pyniv.ConduitData(); - v = pyniv.NestInSituVis(d.Pointer()); - d.Set("V_m", 42.0) - assert v.NodeString() == "42" - -def test_pyniv_niv_StartStop(): - d = pyniv.ConduitData(); - v = pyniv.NestInSituVis(d.Pointer()); - d.Set("V_m", 42.0) - - c = pytest_utilities.CoutCapture() - - v.Start() - time.sleep(0.03) - v.Stop() - - assert len(c.ToString().split('\n')) > 2 - def test_pyniv_receive_via_shared_mem_segment_relay(): r = pyniv.ConduitReceiver() From 8ed9623c02ee1c82a225802c675e7361e1cceb77 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 6 Sep 2017 01:05:47 +0200 Subject: [PATCH 70/71] Fix demo's CMakeLinsts --- demo/nest_python_vis/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demo/nest_python_vis/CMakeLists.txt b/demo/nest_python_vis/CMakeLists.txt index 88a19d6..ff3fb9b 100644 --- a/demo/nest_python_vis/CMakeLists.txt +++ b/demo/nest_python_vis/CMakeLists.txt @@ -26,7 +26,8 @@ file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/run_vis.sh CONTENT "PYTHONPATH=$:$ ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${NEST_PYTHON_VIS_SOURCE}" ) -set(NEST_DIR) +set(NEST_DIR + CACHE PATH "Path to installed nest") file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/run_sim.sh CONTENT "source ${NEST_DIR}/bin/nest_vars.sh From 20c4017e2763a7c0eb4a9e0058a5ef1b095778d0 Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Wed, 6 Sep 2017 01:05:57 +0200 Subject: [PATCH 71/71] Update README --- README.md | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f1406b..0e71830 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,107 @@ # nest in situ vis - *nest in situ vis* is Copyright (c) 2017 RWTH Aachen University, Germany, Virtual Reality & Immersive Visualization Group. +## Overview + +*nest in situ vis* (`niv`) is (the yet prototypical implementation of) a library facilitating in situ visualization for the [nest simulator](http://www.nest-simulator.org). + +With `niv` data can be collected in nest's recording backends and transported to a visualization process. Currently, only on-node transport to a separate visualization process is provided using shared memory. + + +## Building + + +### Requirements + +* a customized nest simulator with nestio and a conduit recording backend +* [conduit 0.2.1](https://github.com/LLNL/conduit/tree/v0.2.1) +* Boost python and boost interprocess v1.64.0 +* Python 2.7.13 +* CMake 3.8.2 (or above) +* gcc 5.3 (or above) + + +### Compiling the Library + +* In a teminal, `cd to `niv`'s root directory + +``` +mkdir build +cd build +cmake .. \ + -DCONDUIT_DIR= \ + -DBOOST_ROOT= \ + -DPYTHON_INCLUDE_DIR= \ + -DPYTHON_LIBRARY= +make +``` + +### Compiling the Custom Nest Simulator + +These are hints for compiling nest (not included in this repository). + +* In a terminal, `cd` to nest's root directory + +``` +mkdir build +cd build +cmake ../.. \ + -Dwith-conduit= \ + -Dniv_DIR= \ + -DPYTHON_INCLUDE_DIR= \ + -DPYTHON_LIBRARY= \ + -DCMAKE_INSTALL_PREFIX:PATH= +make +make install +``` + + +### Generating the Demo Runners + +* In a teminal, `cd to `niv`'s root directory + +``` +cd build +cmake . -DNEST_DIR= +chmod +x chmod +x demo/nest_python_vis/*.sh +``` + + +## Running the Demo + +You'll need two terminals. + +* in both, `cd` to `/demo/nest_python_vis` + +* in the first + +``` +./run_vis.sh +``` + +* in the second + +``` +./run_sim.sh +``` + +* in the visualization app press "Start" +* in the simulation app press "nest.Simulate(20)" + + +## Releasing Shared Memory if Something Breaks + +If one of the two apps crashes, shared memory might still exist. Consequently, the visualization will throw an exception. In order to manually release the shared memory: + +* in a terminal `cd` to `niv`s build directory + +``` +niv/helper_apps/niv-shared-memory destroy +``` + ## License Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,3 +115,8 @@ 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. + + +## Acknowledgements + +`niv` is developed in the Human Brain Project. This project has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 720270 (HBP SGA1).