From a95ec01a69326af3960396b4bf56168a3f2e50a2 Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Thu, 20 Feb 2020 17:35:58 +0900 Subject: [PATCH 01/16] announce required c++ standard version(c++17) Change-Id: I47040b8b02530bfda5006dfd64b7106005efaf68 Signed-off-by: MinJeong Kim --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index fb0b1cb..919546d 100644 --- a/README +++ b/README @@ -1 +1,4 @@ # test-server +Requires: + c++17 standard feature support + - std::variant(>=gcc-7, >=clang4, >=MSVC19.10x) -- 2.7.4 From d95a65753d62fbdbadcb2844a686bc72c29664f8 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 21 Feb 2020 12:47:57 +0900 Subject: [PATCH 02/16] make the libds-unittests package This package contains the unittests of libds using gmock(gtest). Change-Id: I17afe9fb5cf5eb8d8acb74345854dddd07664031 --- meson.build | 4 ++-- packaging/test-server.spec | 12 +++++++++++ tests/libds-tests.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++ tests/libds-tests.h | 40 +++++++++++++++++++++++++++++++++++ tests/meson.build | 11 ++++++++++ 5 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 tests/libds-tests.cpp create mode 100644 tests/libds-tests.h create mode 100644 tests/meson.build diff --git a/meson.build b/meson.build index 4eddada..925619d 100644 --- a/meson.build +++ b/meson.build @@ -10,8 +10,6 @@ dir_prefix = get_option('prefix') dir_lib = join_paths(dir_prefix, get_option('libdir')) dir_bin = join_paths(dir_prefix, get_option('bindir')) -#subdir('src') - ## libds install_headers('src/lib/DSObject.h', @@ -59,6 +57,8 @@ pkgconfig.generate( libraries : lib_libds ) +subdir('tests') + ## For test-server path_test_server = dir_bin diff --git a/packaging/test-server.spec b/packaging/test-server.spec index 0138e57..7b8da09 100644 --- a/packaging/test-server.spec +++ b/packaging/test-server.spec @@ -9,6 +9,7 @@ Source1001: %name.manifest BuildRequires: meson BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gmock) %description @@ -24,6 +25,13 @@ Requires: %{name} = %{version}-%{release} Test DS c++ server and lib +%package libds-unittests +Summary: libds unit tests +Group: System/Libraries + +%description libds-unittests +Test module for testing libtbm APIs + %prep %setup -q cp %{SOURCE1001} . @@ -56,3 +64,7 @@ ninja -C builddir install %{_includedir}/* %{_libdir}/*.so %{_libdir}/pkgconfig/* + +%files libds-unittests +%defattr(-,root,root,-) +%{_bindir}/libds-unittests diff --git a/tests/libds-tests.cpp b/tests/libds-tests.cpp new file mode 100644 index 0000000..6d9761e --- /dev/null +++ b/tests/libds-tests.cpp @@ -0,0 +1,52 @@ +/************************************************************************** + * + * Copyright 2020 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: SooChan Lim + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * +**************************************************************************/ + +#include "libds-tests.h" + +int main(int argc, char **argv) +{ + auto AllTestSuccess = false; + + try { + ::testing::InitGoogleMock(&argc, argv); + ::testing::FLAGS_gtest_death_test_style = "fast"; + } catch ( ... ) { + std::cout << "error while trying to init google tests.\n"; + exit(EXIT_FAILURE); + } + + try { + AllTestSuccess = RUN_ALL_TESTS() == 0 ? true : false; + } catch (const ::testing::internal::GoogleTestFailureException & e) { + AllTestSuccess = false; + std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl; + std::cout << "\n"; + } + + return AllTestSuccess; +} diff --git a/tests/libds-tests.h b/tests/libds-tests.h new file mode 100644 index 0000000..3c8ff11 --- /dev/null +++ b/tests/libds-tests.h @@ -0,0 +1,40 @@ +/************************************************************************** + * + * Copyright 2020 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: SooChan Lim + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * +**************************************************************************/ + +#ifndef _LIBDS_TESTS_H_ +#define _LIBDS_TESTS_H_ + +#include +#include + +using ::testing::TestWithParam; +using ::testing::Bool; +using ::testing::Values; +using ::testing::Combine; + +#endif // UT_H diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..a52e78a --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,11 @@ +incdir = include_directories('../src/lib') +libds_unittests_src = ['libds-tests.cpp'] + +gmock_dep = dependency('gmock', method : 'pkg-config') + +executable('libds-unittests', libds_unittests_src, + include_directories : incdir, + dependencies : gmock_dep, + install_dir : dir_bin, + install : true + ) -- 2.7.4 From 706df76c50ef40f53b257c53b754bf5ad1a49332 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 21 Feb 2020 12:49:41 +0900 Subject: [PATCH 03/16] add the basic test for DSRefBase Change-Id: I7f8c2c17255041afb0e585c96974979839901438 --- tests/DSRefBase-test.cpp | 21 +++++++++++++++++++++ tests/meson.build | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/DSRefBase-test.cpp diff --git a/tests/DSRefBase-test.cpp b/tests/DSRefBase-test.cpp new file mode 100644 index 0000000..57ab821 --- /dev/null +++ b/tests/DSRefBase-test.cpp @@ -0,0 +1,21 @@ +#include "libds-tests.h" +#include "DSRefBase.h" + +class DSRefBaseTest : public ::testing::Test +{ +public: + void SetUp(void) override { + std::cout << "setup\n"; + } + void TearDown(void) override { + std::cout << "teardown\n"; + } +}; + +TEST_F(DSRefBaseTest, CreateRefBase) +{ + display_server::DSRefBase* refBase = new display_server::DSRefBase(); + + int count = refBase->getref(); + ASSERT_TRUE(count == 1); +} \ No newline at end of file diff --git a/tests/meson.build b/tests/meson.build index a52e78a..663d13e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,5 +1,6 @@ incdir = include_directories('../src/lib') -libds_unittests_src = ['libds-tests.cpp'] +libds_unittests_src = ['libds-tests.cpp', + 'DSRefBase-test.cpp'] gmock_dep = dependency('gmock', method : 'pkg-config') -- 2.7.4 From 63bd2b654f8d55eaa51701da9babf3a6646fdd98 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 21 Feb 2020 13:15:23 +0900 Subject: [PATCH 04/16] add directories for initial development. Change-Id: Ic70ee670ee77c04841a295919c644989705048b3 --- src/lib/DSBuffer/README.md | 0 src/lib/DSHWC/README.md | 0 src/lib/DSOutput/README.md | 0 src/lib/DSRender/README.md | 0 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/lib/DSBuffer/README.md create mode 100644 src/lib/DSHWC/README.md create mode 100644 src/lib/DSOutput/README.md create mode 100644 src/lib/DSRender/README.md diff --git a/src/lib/DSBuffer/README.md b/src/lib/DSBuffer/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/DSHWC/README.md b/src/lib/DSHWC/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/DSOutput/README.md b/src/lib/DSOutput/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/DSRender/README.md b/src/lib/DSRender/README.md new file mode 100644 index 0000000..e69de29 -- 2.7.4 From 361e5f45db5c035edd258fed077fd1e373a0efea Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9E=84=EC=88=98=EC=B0=AC/Tizen=20Platform=20Lab=28SR=29/?= =?utf8?q?Staff=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 21 Feb 2020 13:18:53 +0900 Subject: [PATCH 05/16] Update README.md Change-Id: I01bb95691730ed3a19b7d399524ff1c9bf1c143d --- src/lib/DSBuffer/README.md | 14 ++++++++++++++ src/lib/DSHWC/README.md | 14 ++++++++++++++ src/lib/DSOutput/README.md | 11 +++++++++++ src/lib/DSRender/README.md | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/src/lib/DSBuffer/README.md b/src/lib/DSBuffer/README.md index e69de29..2f2bf49 100644 --- a/src/lib/DSBuffer/README.md +++ b/src/lib/DSBuffer/README.md @@ -0,0 +1,14 @@ +# DSBuffer +Buffer + +## Requirements + +* Buffer를 생성해야 한다. with w, h, format +* drmbuf fd(TBM)를 받아서 Buffer를 생성할 수 있어야 한다. +* drmbuf fd(TBM)을 Buffer로 부터 얻을 수 있어야 한다. +* shm_id를 받아서 Buffer를 생성할 수 있어야 한다. +* Buffer를 Reference 관리할 수 있어야 한다.(ref/unref) +* NativeBuffer가 있어야 한다. NativeBuffer라 함은, tbmBuffer, shmBuffer and others +* Buffer에서 virtual address(memory 시작 pointer)를 얻을 수 있어야 한다. + + diff --git a/src/lib/DSHWC/README.md b/src/lib/DSHWC/README.md index e69de29..1009648 100644 --- a/src/lib/DSHWC/README.md +++ b/src/lib/DSHWC/README.md @@ -0,0 +1,14 @@ +# DSHWC +HWCompositing. +HWC and HWCWindow + +## Requirements +### HWC + * Dislay하도록 요청한다. + * Force Full Compositing on/off. + * State pattern 사용해야하지 않을까? (의견) + * <<향후 추가 요망>> +### HWCWindow + * HWCWindow를 생성해야 한다. + * HWCWindow를 ref/unref + * <<향후 추가 요망>> diff --git a/src/lib/DSOutput/README.md b/src/lib/DSOutput/README.md index e69de29..5ef12ba 100644 --- a/src/lib/DSOutput/README.md +++ b/src/lib/DSOutput/README.md @@ -0,0 +1,11 @@ +# DSOutput +Output + +## Requirements +* Output의 정보를 받을 수 있어야 한다. (정보를 구체적으로 나열하여 기입필요.) +* Output 정보를 Noti를 보낼 수 있어야 한다. +* Output mode setting을 할 수 있어야 한다.(virtual mode도 setting가능해야 한다.DSOutput에서 관리해서 transform하여 display할 수 있는) +* Output dpms를 set/get 할 수 있어야 한다. +* Output commit을 할 수 있어야 한다. +* Output transform을 setting할 수 있어야 한다. +* <<향후 추가>> diff --git a/src/lib/DSRender/README.md b/src/lib/DSRender/README.md index e69de29..5dfc6d8 100644 --- a/src/lib/DSRender/README.md +++ b/src/lib/DSRender/README.md @@ -0,0 +1,18 @@ +# DSRender +Render and View. + +## Requirements +### Render + * Renderer를 Trigger할 수 있어야 한다. (feat. ecore_evas_manual_render()) + ** View들의 상하관계에 따라서 Rendering을 DSTBUFFER(????????)에 할 수 있어야 한다. + * View들을 Renderer에 add할 수 있어야 한다. + * tbm_surface_queue를 Renderer에 setting할 수 있어야 한다. + * Renderer는 size가 있어야 한다.(feat. canvas) + * <<향후 추가>> +### View + * View는 Renderer의 Src이다. + * buffer를 View에 넣어 View 내부적으로 texture mapping할 수 있어야 한다. + * View는 Render좌표계에서 상대좌표를 가진다.(x,y) + * View는 size를 가진다. + * View의 position은 Renderer size를 벗어날 수 있다.(?) + * <<향후 추가>> -- 2.7.4 From 3fc7740aef3109cba0f81e31b2e65ef35217702f Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 21 Feb 2020 13:04:51 +0900 Subject: [PATCH 06/16] add .gitignore Change-Id: Icb5f6a95d3219d516a11be0f6de7ae294d88026a --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..51ef652 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode +.TizenBuild + -- 2.7.4 From 8f40f84d52512e272f4e1eb5f1cac8e43d64bba5 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 21 Feb 2020 16:32:04 +0900 Subject: [PATCH 07/16] add Ground rule for development. - change README into REAME.md - add ground rule Change-Id: I6d2cb2450098f608b70c3f207899c5ab2063ae6a --- README | 4 ---- README.md | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index 919546d..0000000 --- a/README +++ /dev/null @@ -1,4 +0,0 @@ -# test-server -Requires: - c++17 standard feature support - - std::variant(>=gcc-7, >=clang4, >=MSVC19.10x) diff --git a/README.md b/README.md new file mode 100644 index 0000000..9e088b6 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# test-server +Requires: + c++17 standard feature support + - std::variant(>=gcc-7, >=clang4, >=MSVC19.10x) + +# Ground Rule + - Reviewer는 Review 시에는 반드시 Comment를 남긴다. + - Reviewer는 코드를 대상으로 의견을 남기고, 절대로 사람(Committer)를 대상으로 의견을 남기지 않는다. + - Committer는 Review Comment에 절대로 상처받지 않는다. + - Committer는 하나의 Commit만 포함하는 PR을 요청한다. + - Committer는 master branch에 merge하려면 두 명이상의 Approve를 받아야 한다. + - PR이 master branch에 merge가 되는 방식은 "Rebase and Merge"를 적용한다. + - Code는 SR SE의 C++ coding rule을 따른다. + - <<향후 추가>> + -- 2.7.4 From 41b22096ad5c0f3c1f34073c3b6d9de9e56aa27f Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 24 Feb 2020 16:21:19 +0900 Subject: [PATCH 08/16] update the Ground Rule Change-Id: I726291b58791edf9771878737ac03ce13d4d617e --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e088b6..fec217d 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Requires: - Committer는 하나의 Commit만 포함하는 PR을 요청한다. - Committer는 master branch에 merge하려면 두 명이상의 Approve를 받아야 한다. - PR이 master branch에 merge가 되는 방식은 "Rebase and Merge"를 적용한다. - - Code는 SR SE의 C++ coding rule을 따른다. + - Code는 SR SE의 C++ coding rule을 따른다. (https://code.sec.samsung.net/confluence/pages/viewpage.action?pageId=45973755) + - Review Comment는 영어/한글 모두 사용 가능하다. - <<향후 추가>> -- 2.7.4 From 539133529de22c0034728508dcce25be074292df Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Tue, 25 Feb 2020 15:50:09 +0900 Subject: [PATCH 09/16] DSProperty: property system prototype added with testcase Change-Id: I8d74c9bd93644f4529ae5a0fb4215eb0e6c67b59 Signed-off-by: MinJeong Kim --- src/lib/DSObject.cpp | 24 +++++-- src/lib/DSObject.h | 4 +- src/lib/DSObjectPrivate.h | 4 +- src/lib/DSProperty.cpp | 156 ++++++++++++++++++++++++++++++++++++++++++++-- src/lib/DSProperty.h | 45 ++++++++++--- tests/DSProperty-test.cpp | 50 +++++++++++++++ tests/DSRefBase-test.cpp | 2 +- tests/meson.build | 14 +++-- 8 files changed, 269 insertions(+), 30 deletions(-) create mode 100644 tests/DSProperty-test.cpp diff --git a/src/lib/DSObject.cpp b/src/lib/DSObject.cpp index 2d13870..f0ee030 100644 --- a/src/lib/DSObject.cpp +++ b/src/lib/DSObject.cpp @@ -23,12 +23,24 @@ void DSObjectPrivate::detachDestroyObserver(DSObjectObserverIface *ob) observers.remove(ob); } -bool DSObjectPrivate::setProperty(std::string key, DSProperty &&property) -{ +void DSObjectPrivate::setProperty(std::string key, const DSPropertyVariant& data, DSPropertyType type) +{ + std::unordered_map::const_iterator ci = properties.find(key); + if (ci == properties.end()){ + properties.emplace(key, DSProperty(key, data, type)); + } + else { + properties[key] = DSProperty(key, data, type); + } } -DSProperty &DSObjectPrivate::getProperty(std::string key) +const DSPropertyVariant& DSObjectPrivate::getProperty(std::string key) { + std::unordered_map::const_iterator ci = properties.find(key); + if (ci == properties.end()){ + throw DSPropertyException("NOT_EXIST"); + } + return properties[key].getData(); } void DSObjectPrivate::notifyDestroy(void) @@ -64,12 +76,14 @@ void DSObject::detachDestroyObserver(DSObjectObserverIface *ob) d_func()->detachDestroyObserver(ob); } -bool DSObject::setProperty(std::string key, const DSPropertyVariant& data, DSPropertyType type) +void DSObject::setProperty(std::string key, const DSPropertyVariant& data, DSPropertyType type) { + d_func()->setProperty(key, data, type); } -DSPropertyVariant &DSObject::getProperty(std::string key) +const DSPropertyVariant& DSObject::getProperty(std::string key) { + return d_func()->getProperty(key); } std::string DSObject::getName(void) diff --git a/src/lib/DSObject.h b/src/lib/DSObject.h index 48b2696..1dce237 100644 --- a/src/lib/DSObject.h +++ b/src/lib/DSObject.h @@ -21,8 +21,8 @@ class DSObject { void attachDestroyObserver(DSObjectObserverIface *ob); void detachDestroyObserver(DSObjectObserverIface *ob); - bool setProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type); - DSPropertyVariant &getProperty(std::string key); + void setProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type); + const DSPropertyVariant& getProperty(std::string key); std::string getName(void); diff --git a/src/lib/DSObjectPrivate.h b/src/lib/DSObjectPrivate.h index 6af36df..94c5f6c 100644 --- a/src/lib/DSObjectPrivate.h +++ b/src/lib/DSObjectPrivate.h @@ -24,8 +24,8 @@ public: void detachDestroyObserver(DSObjectObserverIface *ob); void notifyDestroy(); - bool setProperty(std::string key, DSProperty &&property); - DSProperty &getProperty(std::string key); + void setProperty(std::string key, const DSPropertyVariant& data, DSPropertyType type); + const DSPropertyVariant& getProperty(std::string key); std::string getName(void); diff --git a/src/lib/DSProperty.cpp b/src/lib/DSProperty.cpp index 5510add..c3869bc 100644 --- a/src/lib/DSProperty.cpp +++ b/src/lib/DSProperty.cpp @@ -1,26 +1,172 @@ #include "DSProperty.h" namespace display_server { -DSProperty::DSProperty(std::string _key, DSPropertyVariant &_data, DSPropertyType _type) : key(_key), type(_type) +DSProperty::DSProperty() { - switch (_type) +} + +DSProperty::DSProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type) : __key(key), __type(type) +{ + switch (__type) + { + //copy case + case DSPropertyType::INTEGER: + case DSPropertyType::DOUBLE: + case DSPropertyType::FLOAT: + case DSPropertyType::STRING: + __data = data; //value copy + break; + case DSPropertyType::POINTER: + __data = data; //address copy + break; + default: + break; + } +} + +DSProperty::DSProperty(const DSProperty& property) //Copy Constructor +{ + __type = property.__type; + __key = property.__key; + + switch (__type) + { + //copy case + case DSPropertyType::INTEGER: + case DSPropertyType::DOUBLE: + case DSPropertyType::FLOAT: + case DSPropertyType::STRING: + __data = property.__data; //value copy + break; + case DSPropertyType::POINTER: + __data = property.__data; //address copy + break; + default: + break; + } +} + +DSProperty::DSProperty(DSProperty&& property) //Move Constructor +{ + __type = property.__type; + __key = property.__key; + + switch (__type) { //copy case case DSPropertyType::INTEGER: case DSPropertyType::DOUBLE: case DSPropertyType::FLOAT: case DSPropertyType::STRING: - data = _data; //copy + __data = property.__data; //value copy + property.__data = 0; break; - case DSPropertyType::OBJECT: - data = (&_data); //address + case DSPropertyType::POINTER: + __data = property.__data; //address copy + property.__data = nullptr; break; default: break; } + + property.__type = DSPropertyType::NONE; + property.__key.clear(); } DSProperty::~DSProperty() { + __key.clear(); +} + +DSProperty& DSProperty::operator=(DSProperty& property) //Copy Assign +{ + __type = property.__type; + __key = property.__key; + + switch (__type) + { + //copy case + case DSPropertyType::INTEGER: + case DSPropertyType::DOUBLE: + case DSPropertyType::FLOAT: + case DSPropertyType::STRING: + __data = property.__data; //value copy + break; + case DSPropertyType::POINTER: + __data = property.__data; //address copy + break; + default: + break; + } + + return *this; +} + +DSProperty& DSProperty::operator=(const DSProperty& property) //Copy Assign +{ + __type = property.__type; + __key = property.__key; + + switch (__type) + { + //copy case + case DSPropertyType::INTEGER: + case DSPropertyType::DOUBLE: + case DSPropertyType::FLOAT: + case DSPropertyType::STRING: + __data = property.__data; //value copy + break; + case DSPropertyType::POINTER: + __data = property.__data; //address copy + break; + default: + break; + } + + return *this; +} + +DSProperty& DSProperty::operator=(DSProperty&& property) //Move Assign +{ + __type = property.__type; + __key = property.__key; + + switch (__type) + { + //copy case + case DSPropertyType::INTEGER: + case DSPropertyType::DOUBLE: + case DSPropertyType::FLOAT: + case DSPropertyType::STRING: + __data = property.__data; //value copy + property.__data = 0; + break; + case DSPropertyType::POINTER: + __data = property.__data; //address copy + property.__data = nullptr; + break; + default: + break; + } + + property.__type = DSPropertyType::NONE; + property.__key.clear(); + + return *this; +} + +const DSPropertyVariant& DSProperty::getData(void) const +{ + return __data; +} + +const std::string DSProperty::getKey(void) const +{ + return __key; +} + +const DSPropertyType DSProperty::getType(void) const +{ + return __type; } } // namespace display_server diff --git a/src/lib/DSProperty.h b/src/lib/DSProperty.h index 2270c70..96768bd 100644 --- a/src/lib/DSProperty.h +++ b/src/lib/DSProperty.h @@ -2,15 +2,18 @@ #define __DSPROPERTY_H #include #include +#include +#include +#include "DSPropertyPrivate.h" namespace display_server { using DSPropertyType = enum type { NONE, - INTEGER, - FLOAT, - DOUBLE, - STRING, - OBJECT, + INTEGER, //int + FLOAT, //float + DOUBLE, //double + STRING, //std::string + POINTER, //void* }; using DSPropertyVariant = std::variant; +struct DSPropertyException : public std::exception{ + std::string msg; + public: + DSPropertyException(std::string str) : msg(str) {} + virtual const char* what() const noexcept override + { + return msg.c_str(); + } +}; + class DSProperty { public: - DSProperty(std::string key, DSPropertyVariant& data, DSPropertyType type); + DSProperty(); + DSProperty(std::string key, const DSPropertyVariant& data, DSPropertyType type); + DSProperty(const DSProperty& property); + DSProperty(DSProperty&& property); virtual ~DSProperty(); + + const DSPropertyVariant& getData(void) const; + const std::string getKey(void) const; + const DSPropertyType getType(void) const; + + DSProperty& operator=(DSProperty& property); + DSProperty& operator=(const DSProperty& property); + DSProperty& operator=(DSProperty&& property); + private: - std::string key; - DSPropertyVariant data; - DSPropertyType type; + DSPropertyVariant __data; + std::string __key; + DSPropertyType __type; + + friend class DSObject; }; } // namespace display_server #else diff --git a/tests/DSProperty-test.cpp b/tests/DSProperty-test.cpp new file mode 100644 index 0000000..9c27f31 --- /dev/null +++ b/tests/DSProperty-test.cpp @@ -0,0 +1,50 @@ +#include "libds-tests.h" +#include "DSProperty.h" + +class DSPropertyTest : public ::testing::Test +{ +public: + void SetUp(void) override + { + std::cout << "setup DSPropertyTest\n"; + } + void TearDown(void) override + { + std::cout << "teardown DSPropertyTest\n"; + } +}; + +TEST_F(DSPropertyTest, CreateProperty) +{ + /* display_server::DSProperty::DSProperty()*/ + display_server::DSProperty* pro = new display_server::DSProperty(); + ASSERT_NE(pro, nullptr) << "Failed to DSProperty()"; + delete pro; + + /* display_server::DSProperty::DSProperty(std::__cxx11::string, const DSPropertyVariant&, display_server::DSPropertyType) */ + pro = new display_server::DSProperty("testProperty", 2020, display_server::DSPropertyType::INTEGER); + ASSERT_NE(pro, nullptr) << "Failed to DSProperty(key, data, type)"; + ASSERT_EQ(pro->getKey(), "testProperty") << "Key value mismatch!"; + ASSERT_EQ(pro->getType(), display_server::DSPropertyType::INTEGER) << "Type mistmatch!!"; + try { + int data = std::get(pro->getData()); + ASSERT_TRUE(data == 2020) << "data value mismatch!!"; + } catch (std::bad_variant_access& e) { + ASSERT_TRUE(false) << e.what(); + } + delete pro; + + /* display_server::DSProperty::DSProperty(display_server::DSProperty&) */ + display_server::DSProperty pro_s("testProperty2", 20.20, display_server::DSPropertyType::DOUBLE); + pro = new display_server::DSProperty(pro_s); + ASSERT_NE(pro, nullptr) << "Failed to DSProperty(const DSProperty&)"; + ASSERT_EQ(pro->getKey(), "testProperty2") << "Key value mismatch!"; + ASSERT_EQ(pro->getType(), display_server::DSPropertyType::DOUBLE) << "Type mistmatch!!"; + try { + double data = std::get(pro->getData()); + ASSERT_TRUE(data == 20.20) << "data value mismatch!!"; + } catch (std::bad_variant_access& e) { + ASSERT_TRUE(false) << e.what(); + } + delete pro; +} diff --git a/tests/DSRefBase-test.cpp b/tests/DSRefBase-test.cpp index 57ab821..9fa6a68 100644 --- a/tests/DSRefBase-test.cpp +++ b/tests/DSRefBase-test.cpp @@ -18,4 +18,4 @@ TEST_F(DSRefBaseTest, CreateRefBase) int count = refBase->getref(); ASSERT_TRUE(count == 1); -} \ No newline at end of file +} diff --git a/tests/meson.build b/tests/meson.build index 663d13e..03ef65f 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,12 +1,14 @@ incdir = include_directories('../src/lib') libds_unittests_src = ['libds-tests.cpp', - 'DSRefBase-test.cpp'] + 'DSRefBase-test.cpp', + 'DSProperty-test.cpp'] gmock_dep = dependency('gmock', method : 'pkg-config') executable('libds-unittests', libds_unittests_src, - include_directories : incdir, - dependencies : gmock_dep, - install_dir : dir_bin, - install : true - ) + include_directories : incdir, + link_with : lib_libds, + dependencies : gmock_dep, + install_dir : dir_bin, + install : true + ) -- 2.7.4 From 3963bc734860d263d39b9da6fb4c3bbcb76adf46 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Tue, 25 Feb 2020 18:36:06 +0900 Subject: [PATCH 10/16] change the ground rule for code review. Change-Id: If512271c38f9262c610b1fe6d98421e7cd15d6b5 --- README.md | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fec217d..7f2d808 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,22 @@ Requires: - std::variant(>=gcc-7, >=clang4, >=MSVC19.10x) # Ground Rule - - Reviewer는 Review 시에는 반드시 Comment를 남긴다. - - Reviewer는 코드를 대상으로 의견을 남기고, 절대로 사람(Committer)를 대상으로 의견을 남기지 않는다. - - Committer는 Review Comment에 절대로 상처받지 않는다. - - Committer는 하나의 Commit만 포함하는 PR을 요청한다. - - Committer는 master branch에 merge하려면 두 명이상의 Approve를 받아야 한다. - - PR이 master branch에 merge가 되는 방식은 "Rebase and Merge"를 적용한다. - - Code는 SR SE의 C++ coding rule을 따른다. (https://code.sec.samsung.net/confluence/pages/viewpage.action?pageId=45973755) - - Review Comment는 영어/한글 모두 사용 가능하다. - - <<향후 추가>> + ## Committer rule + - Committer는 Commit message와 Description을 영어로 작성한다. + - Committer는 Reviewer가 patch의 목적을 이해할 수 있도록 Commit message와 Description을 충실히 작성한다. + - Committer는 patch를 간단한 단일기능 혹은 단일 주제를 가지도록 만든다. 단일 주제를 가지는 Commit message를 작성할 수 있도록 한다. + - Committer는 코드 수정들을 가장 작은 단위의 patch들도 나누어 Commit한다. + - Committer는 2명 이상의 Reviewer들에게 리뷰 요청을 한다. + - Committer는 빌드 및 동작검증을 한 후에 PR을 요청한다. + - Committer는 PR에 하나 혹은 그 이상의 patch들을 포함할 수 있다. + - Committer는 patch를 SE의 C++ coding rule을 준수하여 작성한다. (C++ Coding Rule) + ## Reviewer rule + - Reviewer는 한글/영어로 review comment를 작성한다. + - Reviewer는 Merge가 될 수 있는 PR이면 Approve를 체크한다. + - Reviewer는 reviewer로 등록되면 working day 1일 이내에 리뷰하도록 노력한다. + - Reviewer는 Code에 대한 의견만 제시한다. + - Reviewer는 리뷰 시에는 반드시 Comment를 기록한다. + ## Merge rule + - Rebase and Submit를 원칙으로 한다. + - Approve가 두 개 이상일 경우에만 merge가 가능하다. -- 2.7.4 From cdfa2912990b671d2aa8f7a0bb1946ceff921283 Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Thu, 27 Feb 2020 17:31:56 +0900 Subject: [PATCH 11/16] DSProperty/DSProperty: use pimpl idiom Connect DSProperty and DSPropertyPrivate using std::unique_ptr Change-Id: Id0b317af9cb71dd89557e2c10ac67cec575231bc Signed-off-by: MinJeong Kim --- src/lib/DSProperty.cpp | 288 ++++++++++++++++++-------------------------- src/lib/DSProperty.h | 82 +++++-------- src/lib/DSPropertyPrivate.h | 58 ++++++++- 3 files changed, 210 insertions(+), 218 deletions(-) diff --git a/src/lib/DSProperty.cpp b/src/lib/DSProperty.cpp index c3869bc..a4cdc10 100644 --- a/src/lib/DSProperty.cpp +++ b/src/lib/DSProperty.cpp @@ -1,172 +1,124 @@ #include "DSProperty.h" namespace display_server { -DSProperty::DSProperty() -{ -} - -DSProperty::DSProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type) : __key(key), __type(type) -{ - switch (__type) - { - //copy case - case DSPropertyType::INTEGER: - case DSPropertyType::DOUBLE: - case DSPropertyType::FLOAT: - case DSPropertyType::STRING: - __data = data; //value copy - break; - case DSPropertyType::POINTER: - __data = data; //address copy - break; - default: - break; - } -} - -DSProperty::DSProperty(const DSProperty& property) //Copy Constructor -{ - __type = property.__type; - __key = property.__key; - - switch (__type) - { - //copy case - case DSPropertyType::INTEGER: - case DSPropertyType::DOUBLE: - case DSPropertyType::FLOAT: - case DSPropertyType::STRING: - __data = property.__data; //value copy - break; - case DSPropertyType::POINTER: - __data = property.__data; //address copy - break; - default: - break; - } -} - -DSProperty::DSProperty(DSProperty&& property) //Move Constructor -{ - __type = property.__type; - __key = property.__key; - - switch (__type) - { - //copy case - case DSPropertyType::INTEGER: - case DSPropertyType::DOUBLE: - case DSPropertyType::FLOAT: - case DSPropertyType::STRING: - __data = property.__data; //value copy - property.__data = 0; - break; - case DSPropertyType::POINTER: - __data = property.__data; //address copy - property.__data = nullptr; - break; - default: - break; - } - - property.__type = DSPropertyType::NONE; - property.__key.clear(); -} - -DSProperty::~DSProperty() -{ - __key.clear(); -} - -DSProperty& DSProperty::operator=(DSProperty& property) //Copy Assign -{ - __type = property.__type; - __key = property.__key; - - switch (__type) - { - //copy case - case DSPropertyType::INTEGER: - case DSPropertyType::DOUBLE: - case DSPropertyType::FLOAT: - case DSPropertyType::STRING: - __data = property.__data; //value copy - break; - case DSPropertyType::POINTER: - __data = property.__data; //address copy - break; - default: - break; - } - - return *this; -} - -DSProperty& DSProperty::operator=(const DSProperty& property) //Copy Assign -{ - __type = property.__type; - __key = property.__key; - - switch (__type) - { - //copy case - case DSPropertyType::INTEGER: - case DSPropertyType::DOUBLE: - case DSPropertyType::FLOAT: - case DSPropertyType::STRING: - __data = property.__data; //value copy - break; - case DSPropertyType::POINTER: - __data = property.__data; //address copy - break; - default: - break; - } - - return *this; -} - -DSProperty& DSProperty::operator=(DSProperty&& property) //Move Assign -{ - __type = property.__type; - __key = property.__key; - - switch (__type) - { - //copy case - case DSPropertyType::INTEGER: - case DSPropertyType::DOUBLE: - case DSPropertyType::FLOAT: - case DSPropertyType::STRING: - __data = property.__data; //value copy - property.__data = 0; - break; - case DSPropertyType::POINTER: - __data = property.__data; //address copy - property.__data = nullptr; - break; - default: - break; - } - - property.__type = DSPropertyType::NONE; - property.__key.clear(); - - return *this; -} - -const DSPropertyVariant& DSProperty::getData(void) const -{ - return __data; -} - -const std::string DSProperty::getKey(void) const -{ - return __key; -} - -const DSPropertyType DSProperty::getType(void) const -{ - return __type; -} + DSPropertyPrivate::DSPropertyPrivate(DSProperty *p_ptr) : + __p_ptr(p_ptr) + { + __type = DSPropertyType::NONE; + } + DSPropertyPrivate::DSPropertyPrivate(DSProperty *p_ptr, std::string key, const DSPropertyVariant &data, DSPropertyType type) : + __p_ptr(p_ptr), __key(key), __type(type) + { + switch (__type) { // copy case + case DSPropertyType::INTEGER: + case DSPropertyType::DOUBLE: + case DSPropertyType::FLOAT: + case DSPropertyType::STRING: + __data = data; // value copy + break; + case DSPropertyType::POINTER: + __data = data; // address copy + break; + default: + break; + } + } + + DSPropertyPrivate::~DSPropertyPrivate() + { + __key.clear(); + } + + const std::string DSPropertyPrivate::getKey() const + { + return __key; + } + + const DSPropertyVariant &DSPropertyPrivate::getData() const + { + return __data; + } + + const DSPropertyType DSPropertyPrivate::getType() const + { + return __type; + } + + void DSPropertyPrivate::setKey(std::string key) + { + __key = key; + } + + void DSPropertyPrivate::setData(DSPropertyVariant data, DSPropertyType type) + { + __type = type; + + switch (__type) { // copy case + case DSPropertyType::INTEGER: + case DSPropertyType::DOUBLE: + case DSPropertyType::FLOAT: + case DSPropertyType::STRING: + __data = data; // value copy + break; + case DSPropertyType::POINTER: + __data = data; // address copy + break; + default: + break; + } + } + + DSProperty::DSProperty() : + __d_ptr(new DSPropertyPrivate(this)) + { + } + + DSProperty::DSProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type) : + __d_ptr(new DSPropertyPrivate(this)) + { + d_func()->setKey(key); + d_func()->setData(data, type); + } + + DSProperty::DSProperty(const DSProperty &property) : + __d_ptr(new DSPropertyPrivate(this)) + { + d_func()->setKey(property.getKey()); + d_func()->setData(property.getData(), property.getType()); + } + + DSProperty::~DSProperty() + { + } + + DSProperty &DSProperty::operator=(DSProperty &property) // Copy Assign + { + d_func()->setKey(property.getKey()); + d_func()->setData(property.getData(), property.getType()); + + return *this; + } + + DSProperty &DSProperty::operator=(const DSProperty &property) // Copy Assign + { + d_func()->setKey(property.getKey()); + d_func()->setData(property.getData(), property.getType()); + + return *this; + } + + const DSPropertyVariant &DSProperty::getData(void) const + { + return d_func()->getData(); + } + + const std::string DSProperty::getKey(void) const + { + return d_func()->getKey(); + } + + const DSPropertyType DSProperty::getType(void) const + { + return d_func()->getType(); + } } // namespace display_server diff --git a/src/lib/DSProperty.h b/src/lib/DSProperty.h index 96768bd..4d1662c 100644 --- a/src/lib/DSProperty.h +++ b/src/lib/DSProperty.h @@ -1,60 +1,44 @@ #ifndef __DSPROPERTY_H #define __DSPROPERTY_H + +#include +#include #include #include -#include -#include #include "DSPropertyPrivate.h" namespace display_server { -using DSPropertyType = enum type { - NONE, - INTEGER, //int - FLOAT, //float - DOUBLE, //double - STRING, //std::string - POINTER, //void* -}; - -using DSPropertyVariant = std::variant; - -struct DSPropertyException : public std::exception{ - std::string msg; + class DSPropertyPrivate; + + class DSProperty { public: - DSPropertyException(std::string str) : msg(str) {} - virtual const char* what() const noexcept override - { - return msg.c_str(); - } -}; - -class DSProperty { -public: - DSProperty(); - DSProperty(std::string key, const DSPropertyVariant& data, DSPropertyType type); - DSProperty(const DSProperty& property); - DSProperty(DSProperty&& property); - virtual ~DSProperty(); - - const DSPropertyVariant& getData(void) const; - const std::string getKey(void) const; - const DSPropertyType getType(void) const; - - DSProperty& operator=(DSProperty& property); - DSProperty& operator=(const DSProperty& property); - DSProperty& operator=(DSProperty&& property); - -private: - DSPropertyVariant __data; - std::string __key; - DSPropertyType __type; - - friend class DSObject; -}; + DSProperty(); + DSProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type); + DSProperty(const DSProperty &property); + virtual ~DSProperty(); + + const DSPropertyVariant &getData(void) const; + const std::string getKey(void) const; + const DSPropertyType getType(void) const; + + DSProperty &operator=(DSProperty &property); + DSProperty &operator=(const DSProperty &property); + + private: + inline DSPropertyPrivate *d_func() + { + return __d_ptr.get(); + } + inline const DSPropertyPrivate *d_func() const + { + return __d_ptr.get(); + } + + std::unique_ptr __d_ptr; + + friend class DSPropertyPrivate; + friend class DSObject; + }; } // namespace display_server #else #endif /* __DSPROPERTY_H */ diff --git a/src/lib/DSPropertyPrivate.h b/src/lib/DSPropertyPrivate.h index 236482d..2cdd937 100644 --- a/src/lib/DSPropertyPrivate.h +++ b/src/lib/DSPropertyPrivate.h @@ -1,4 +1,60 @@ #ifndef __DSPROPERTYPRIVATE_H -# define __DSPROPERTYPRIVATE_H +# define __DSPROPERTYPRIVATE_H +# include "DSProperty.h" + +namespace display_server { + class DSProperty; + using DSPropertyType = enum type { + NONE, + INTEGER, //int + FLOAT, //float + DOUBLE, //double + STRING, //std::string + POINTER, //void* + }; + + using DSPropertyVariant = std::variant; + + struct DSPropertyException : public std::exception { + public: + DSPropertyException(std::string str) : msg(str) {} + virtual const char *what() const noexcept override + { + return msg.c_str(); + } + + private: + std::string msg; + }; + + class DSPropertyPrivate { + public: + DSPropertyPrivate() = delete; + DSPropertyPrivate(DSProperty *p_ptr); + DSPropertyPrivate(DSProperty *p_ptr, std::string key, const DSPropertyVariant &data, DSPropertyType type); + virtual ~DSPropertyPrivate(); + + inline const DSProperty *p_func() const + { + return __p_ptr; + } + + private: + DSProperty *__p_ptr; + + std::string __key; + DSPropertyVariant __data; + DSPropertyType __type; + + const std::string getKey(void) const; + const DSPropertyVariant &getData(void) const; + const DSPropertyType getType(void) const; + + void setKey(std::string key); + void setData(DSPropertyVariant data, DSPropertyType type); + + friend class DSProperty; + }; +} // namespace display_server #else #endif /* __DSPROPERTYPRIVATE_H */ -- 2.7.4 From 7c62984c5ba6bb663a12390970c8c11affa93b58 Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Fri, 28 Feb 2020 09:15:07 +0900 Subject: [PATCH 12/16] DSObject: formatting and changing variable name with coding rule Change-Id: I9e3c521e57c66506dfbef3fed8a0fec1fac71a42 Signed-off-by: MinJeong Kim --- src/lib/DSObject.cpp | 144 +++++++++++++++++++++++----------------------- src/lib/DSObject.h | 69 +++++++++++----------- src/lib/DSObjectPrivate.h | 63 ++++++++++---------- 3 files changed, 141 insertions(+), 135 deletions(-) diff --git a/src/lib/DSObject.cpp b/src/lib/DSObject.cpp index f0ee030..f26ec7f 100644 --- a/src/lib/DSObject.cpp +++ b/src/lib/DSObject.cpp @@ -1,93 +1,91 @@ -#include "DSObjectPrivate.h" #include "DSObject.h" +#include "DSObjectPrivate.h" #include "DSProperty.h" -namespace display_server -{ -DSObjectPrivate::DSObjectPrivate(DSObject *p_ptr, std::string name) : p_ptr(p_ptr) -{ - type_info.name = name; -} - -DSObjectPrivate::~DSObjectPrivate() -{ -} +namespace display_server { + DSObjectPrivate::DSObjectPrivate(DSObject *p_ptr, std::string name) : + __p_ptr(p_ptr) + { + __type_info.name = name; + } -void DSObjectPrivate::attachDestroyObserver(DSObjectObserverIface *ob) -{ - observers.push_back(ob); -} + DSObjectPrivate::~DSObjectPrivate() + { + } -void DSObjectPrivate::detachDestroyObserver(DSObjectObserverIface *ob) -{ - observers.remove(ob); -} + void DSObjectPrivate::attachDestroyObserver(DSObjectObserverIface *ob) + { + __observers.push_back(ob); + } -void DSObjectPrivate::setProperty(std::string key, const DSPropertyVariant& data, DSPropertyType type) -{ - std::unordered_map::const_iterator ci = properties.find(key); - if (ci == properties.end()){ - properties.emplace(key, DSProperty(key, data, type)); + void DSObjectPrivate::detachDestroyObserver(DSObjectObserverIface *ob) + { + __observers.remove(ob); } - else { - properties[key] = DSProperty(key, data, type); + + void DSObjectPrivate::setProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type) + { + std::unordered_map::const_iterator ci = __properties.find(key); + if (ci == __properties.end()) { + __properties.emplace(key, DSProperty(key, data, type)); + } else { + __properties[key] = DSProperty(key, data, type); + } } -} -const DSPropertyVariant& DSObjectPrivate::getProperty(std::string key) -{ - std::unordered_map::const_iterator ci = properties.find(key); - if (ci == properties.end()){ - throw DSPropertyException("NOT_EXIST"); + const DSPropertyVariant &DSObjectPrivate::getProperty(std::string key) + { + std::unordered_map::const_iterator ci = __properties.find(key); + if (ci == __properties.end()) { + throw DSPropertyException("NOT_EXIST"); + } + return __properties[key].getData(); } - return properties[key].getData(); -} -void DSObjectPrivate::notifyDestroy(void) -{ - for (DSObjectObserverIface *ob : observers) - ob->destroyed(p_ptr); - observers.clear(); -} + void DSObjectPrivate::notifyDestroy(void) + { + for (DSObjectObserverIface *ob : __observers) + ob->destroyed(__p_ptr); + __observers.clear(); + } -std::string DSObjectPrivate::getName(void) -{ - return type_info.name; -} + std::string DSObjectPrivate::getName(void) + { + return __type_info.name; + } -DSObject::DSObject(std::string name) -{ - std::unique_ptr ptr(new DSObjectPrivate(this, name)); - __d_ptr = std::move(ptr); -} + DSObject::DSObject(std::string name) : + __d_ptr(new DSObjectPrivate(this, name)) + { + } -DSObject::~DSObject() -{ - d_func()->notifyDestroy(); -} + DSObject::~DSObject() + { + d_func()->notifyDestroy(); + } -void DSObject::attachDestroyObserver(DSObjectObserverIface *ob) -{ - d_func()->attachDestroyObserver(ob); -} + void DSObject::attachDestroyObserver(DSObjectObserverIface *ob) + { + d_func()->attachDestroyObserver(ob); + } -void DSObject::detachDestroyObserver(DSObjectObserverIface *ob) -{ - d_func()->detachDestroyObserver(ob); -} + void DSObject::detachDestroyObserver(DSObjectObserverIface *ob) + { + d_func()->detachDestroyObserver(ob); + } -void DSObject::setProperty(std::string key, const DSPropertyVariant& data, DSPropertyType type) -{ - d_func()->setProperty(key, data, type); -} + void DSObject::setProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type) + { + d_func()->setProperty(key, data, type); + } -const DSPropertyVariant& DSObject::getProperty(std::string key) -{ - return d_func()->getProperty(key); -} + const DSPropertyVariant &DSObject::getProperty(std::string key) + { + return d_func()->getProperty(key); + } -std::string DSObject::getName(void) -{ - return d_func()->getName(); -} + std::string DSObject::getName(void) + { + return d_func()->getName(); + } } // namespace display_server diff --git a/src/lib/DSObject.h b/src/lib/DSObject.h index 1dce237..6fb8fb1 100644 --- a/src/lib/DSObject.h +++ b/src/lib/DSObject.h @@ -1,46 +1,51 @@ #ifndef __DSOBJECT_H -#define __DSOBJECT_H +# define __DSOBJECT_H -#include -#include -#include -#include "DSObjectPrivate.h" -#include "DSProperty.h" +# include "DSObjectPrivate.h" +# include "DSProperty.h" +# include +# include +# include -namespace display_server -{ -class DSObjectPrivate; -class DSObjectObserverIface; -class DSProperty; +namespace display_server { + class DSObjectPrivate; + class DSObjectObserverIface; + class DSProperty; -class DSObject { + class DSObject { public: - explicit DSObject(std::string name = "WObject"); - virtual ~DSObject(); + explicit DSObject(std::string name = "WObject"); + virtual ~DSObject(); - void attachDestroyObserver(DSObjectObserverIface *ob); - void detachDestroyObserver(DSObjectObserverIface *ob); + void attachDestroyObserver(DSObjectObserverIface *ob); + void detachDestroyObserver(DSObjectObserverIface *ob); - void setProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type); - const DSPropertyVariant& getProperty(std::string key); + void setProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type); + const DSPropertyVariant &getProperty(std::string key); - std::string getName(void); + std::string getName(void); private: - inline DSObjectPrivate* d_func() { return __d_ptr.get(); } - inline const DSObjectPrivate* d_func() const { return __d_ptr.get(); } + inline DSObjectPrivate *d_func() + { + return __d_ptr.get(); + } + inline const DSObjectPrivate *d_func() const + { + return __d_ptr.get(); + } + + std::unique_ptr __d_ptr; + }; + + class DSObjectObserverIface { + protected: + DSObjectObserverIface() {} + virtual ~DSObjectObserverIface() {} - std::unique_ptr __d_ptr; -}; - -class DSObjectObserverIface { -protected: - DSObjectObserverIface() {} - virtual ~DSObjectObserverIface() {} - -public: - virtual void destroyed(DSObject *obj) = 0; -}; + public: + virtual void destroyed(DSObject *obj) = 0; + }; } // namespace display_server #else diff --git a/src/lib/DSObjectPrivate.h b/src/lib/DSObjectPrivate.h index 94c5f6c..b44024c 100644 --- a/src/lib/DSObjectPrivate.h +++ b/src/lib/DSObjectPrivate.h @@ -1,45 +1,48 @@ #ifndef __DSOBJECTPRIVATE_H -#define __DSOBJECTPRIVATE_H +# define __DSOBJECTPRIVATE_H -#include "DSObject.h" -#include -#include -#include -#include -#include "DSProperty.h" +# include "DSObject.h" +# include "DSProperty.h" +# include +# include +# include +# include namespace display_server { -class DSObject; -class DSObjectObserverIface; + class DSObject; + class DSObjectObserverIface; -class DSObjectPrivate { -public: - DSObjectPrivate() = delete; - DSObjectPrivate(DSObject *p_ptr, std::string name = "default"); - virtual ~DSObjectPrivate(); + class DSObjectPrivate { + public: + DSObjectPrivate() = delete; + DSObjectPrivate(DSObject *p_ptr, std::string name = "default"); + virtual ~DSObjectPrivate(); - inline const DSObject *p_func() const { return p_ptr; } + inline const DSObject *p_func() const + { + return __p_ptr; + } - void attachDestroyObserver(DSObjectObserverIface *ob); - void detachDestroyObserver(DSObjectObserverIface *ob); - void notifyDestroy(); + void attachDestroyObserver(DSObjectObserverIface *ob); + void detachDestroyObserver(DSObjectObserverIface *ob); + void notifyDestroy(); - void setProperty(std::string key, const DSPropertyVariant& data, DSPropertyType type); - const DSPropertyVariant& getProperty(std::string key); + void setProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type); + const DSPropertyVariant &getProperty(std::string key); - std::string getName(void); + std::string getName(void); -private: - struct - { - std::string name; - } type_info; + private: + struct + { + std::string name; + } __type_info; - DSObject *p_ptr; + DSObject *__p_ptr; - std::list observers; - std::unordered_map properties; -}; + std::list __observers; + std::unordered_map __properties; + }; } // namespace display_server #else #endif /* __DSOBJECTPRIVATE_H */ -- 2.7.4 From 7ae31c80fdfd17cb3e7cb1a0f04a5728aadbbdf0 Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Thu, 5 Mar 2020 14:14:11 +0900 Subject: [PATCH 13/16] DSObject: update pimpl - removed constructor with name(string) - clean data at destructor - added operator= for move assignment - create __d_ptr for DSObjectPrivate using std::make_unique Change-Id: I006eeb34ce03fee97ea8e804654f6a355120d780 Signed-off-by: MinJeong Kim --- src/lib/DSObject.cpp | 33 +++++++++++++++++++++++++++++---- src/lib/DSObject.h | 8 ++++---- src/lib/DSObjectPrivate.h | 4 +++- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/lib/DSObject.cpp b/src/lib/DSObject.cpp index f26ec7f..7052226 100644 --- a/src/lib/DSObject.cpp +++ b/src/lib/DSObject.cpp @@ -3,14 +3,16 @@ #include "DSProperty.h" namespace display_server { - DSObjectPrivate::DSObjectPrivate(DSObject *p_ptr, std::string name) : + DSObjectPrivate::DSObjectPrivate(DSObject *p_ptr) : __p_ptr(p_ptr) { - __type_info.name = name; } DSObjectPrivate::~DSObjectPrivate() { + __type_info.name.clear(); + __observers.clear(); + __properties.clear(); } void DSObjectPrivate::attachDestroyObserver(DSObjectObserverIface *ob) @@ -54,9 +56,27 @@ namespace display_server { return __type_info.name; } - DSObject::DSObject(std::string name) : - __d_ptr(new DSObjectPrivate(this, name)) + DSObjectPrivate& DSObjectPrivate::operator=(DSObjectPrivate &&p) + { + if (__p_ptr) + return *this; + + __type_info.name = p.__type_info.name; + __p_ptr = p.__p_ptr; + __observers = std::move(p.__observers); + __properties = std::move(p.__properties); + + p.__type_info.name.clear(); + p.__p_ptr = nullptr; + p.__observers.clear(); + p.__properties.clear(); + + return *this; + } + + DSObject::DSObject() { + __d_ptr = std::make_unique(this); } DSObject::~DSObject() @@ -88,4 +108,9 @@ namespace display_server { { return d_func()->getName(); } + + DSObject::DSObject(std::unique_ptr ptr) + { + __d_ptr = std::move(ptr); + } } // namespace display_server diff --git a/src/lib/DSObject.h b/src/lib/DSObject.h index 6fb8fb1..ba84625 100644 --- a/src/lib/DSObject.h +++ b/src/lib/DSObject.h @@ -14,7 +14,7 @@ namespace display_server { class DSObject { public: - explicit DSObject(std::string name = "WObject"); + explicit DSObject(); virtual ~DSObject(); void attachDestroyObserver(DSObjectObserverIface *ob); @@ -24,7 +24,9 @@ namespace display_server { const DSPropertyVariant &getProperty(std::string key); std::string getName(void); - + protected: + DSObject(std::unique_ptr ptr); + std::unique_ptr __d_ptr; private: inline DSObjectPrivate *d_func() { @@ -34,8 +36,6 @@ namespace display_server { { return __d_ptr.get(); } - - std::unique_ptr __d_ptr; }; class DSObjectObserverIface { diff --git a/src/lib/DSObjectPrivate.h b/src/lib/DSObjectPrivate.h index b44024c..4fdf068 100644 --- a/src/lib/DSObjectPrivate.h +++ b/src/lib/DSObjectPrivate.h @@ -15,7 +15,7 @@ namespace display_server { class DSObjectPrivate { public: DSObjectPrivate() = delete; - DSObjectPrivate(DSObject *p_ptr, std::string name = "default"); + DSObjectPrivate(DSObject *p_ptr); virtual ~DSObjectPrivate(); inline const DSObject *p_func() const @@ -32,6 +32,8 @@ namespace display_server { std::string getName(void); + DSObjectPrivate &operator=(DSObjectPrivate &&p); //move assignment + private: struct { -- 2.7.4 From e27e43387be6fbb73f81e4c3a20bd9c66280a475 Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Thu, 5 Mar 2020 14:15:39 +0900 Subject: [PATCH 14/16] example: add new example for DSObject pimpl and property Change-Id: I68d3ae9869ac6df51b70f5a735d3fec5a8ca4454 Signed-off-by: MinJeong Kim --- meson.build | 22 +++++-- src/bin/example/exampleObjectPimpl.cpp | 95 +++++++++++++++++++++++++++ src/bin/example/exampleProperty.cpp | 115 ++++++++++++++++++++++++++++++++ src/bin/example/exampleSignalSlot.cpp | 116 +++++++++++++++++++++++++++++++++ src/bin/sample1.cpp | 86 ------------------------ 5 files changed, 343 insertions(+), 91 deletions(-) create mode 100644 src/bin/example/exampleObjectPimpl.cpp create mode 100644 src/bin/example/exampleProperty.cpp create mode 100644 src/bin/example/exampleSignalSlot.cpp delete mode 100644 src/bin/sample1.cpp diff --git a/meson.build b/meson.build index 925619d..84d3d18 100644 --- a/meson.build +++ b/meson.build @@ -63,15 +63,27 @@ subdir('tests') path_test_server = dir_bin #deps_test_server = [ dep_libds, dependency('libds') ] -src_test_server = [ - 'src/bin/sample1.cpp' -] -executable('test-server', - src_test_server, +executable('exampleSignalSlot', + 'src/bin/example/exampleSignalSlot.cpp', + dependencies : dep_libds, + link_args : link_args, + install_dir : path_test_server, + install : true + ) + +executable('exampleObjectPimpl', + 'src/bin/example/exampleObjectPimpl.cpp', dependencies : dep_libds, link_args : link_args, install_dir : path_test_server, install : true ) +executable('exampleProperty', + 'src/bin/example/exampleProperty.cpp', + dependencies : dep_libds, + link_args : link_args, + install_dir : path_test_server, + install : true + ) diff --git a/src/bin/example/exampleObjectPimpl.cpp b/src/bin/example/exampleObjectPimpl.cpp new file mode 100644 index 0000000..d098b6b --- /dev/null +++ b/src/bin/example/exampleObjectPimpl.cpp @@ -0,0 +1,95 @@ +#include +#include +#include + +/* RESULT + +=== ObjectPimpl *myobj = new ObjectPimpl() === +Constructor 'ObjectPimplPrivate' : example::ObjectPimplPrivate::ObjectPimplPrivate(example::ObjectPimpl*) +Constructor 'ObjectPimpl' : example::ObjectPimpl::ObjectPimpl() + +=== ObjectPimpl *myobj2 = new ObjectPimpl() === +Constructor 'ObjectPimplPrivate' : example::ObjectPimplPrivate::ObjectPimplPrivate(example::ObjectPimpl*) +Constructor 'ObjectPimpl' : example::ObjectPimpl::ObjectPimpl() + +=== delete myobj === +Destructor 'ObjectPimpl' : virtual example::ObjectPimpl::~ObjectPimpl() +Destructor 'ObjectPimplPrivate' : virtual example::ObjectPimplPrivate::~ObjectPimplPrivate() + +=== delete myobj2 === +Destructor 'ObjectPimpl' : virtual example::ObjectPimpl::~ObjectPimpl() +Destructor 'ObjectPimplPrivate' : virtual example::ObjectPimplPrivate::~ObjectPimplPrivate() + +*/ + +namespace example { + class ObjectPimpl; + + class ObjectPimplPrivate : public display_server::DSObjectPrivate { + public: + ObjectPimplPrivate() = delete; + ObjectPimplPrivate(ObjectPimpl *p_ptr); + ~ObjectPimplPrivate(); + }; + + class ObjectPimpl : public display_server::DSObject { + public: + explicit ObjectPimpl(); + virtual ~ObjectPimpl(); + + private: + inline ObjectPimplPrivate *d_func() + { + return reinterpret_cast(__d_ptr.get()); + } + inline const ObjectPimplPrivate *d_func() const + { + return reinterpret_cast(__d_ptr.get()); + } + friend class ObjectPimplPrivate; + }; + + ObjectPimplPrivate::ObjectPimplPrivate(ObjectPimpl *p_ptr) : + display_server::DSObjectPrivate(p_ptr) + { + std::cout << "Constructor 'ObjectPimplPrivate' : " << __PRETTY_FUNCTION__ << std::endl; + } + + ObjectPimplPrivate::~ObjectPimplPrivate() + { + std::cout << "Destructor 'ObjectPimplPrivate' : " << __PRETTY_FUNCTION__ << std::endl; + } + + ObjectPimpl::ObjectPimpl() : + display_server::DSObject(std::make_unique(this)) + { + std::cout << "Constructor 'ObjectPimpl' : " << __PRETTY_FUNCTION__ << std::endl; + } + + ObjectPimpl::~ObjectPimpl() + { + std::cout << "Destructor 'ObjectPimpl' : " << __PRETTY_FUNCTION__ << std::endl; + } + + int exampleObjectPimpl(void) + { + std::cout << "\n=== ObjectPimpl *myobj = new ObjectPimpl() ===" << std::endl; + ObjectPimpl *myobj = new ObjectPimpl(); + + std::cout << "\n=== ObjectPimpl *myobj2 = new ObjectPimpl() ===" << std::endl; + ObjectPimpl *myobj2 = new ObjectPimpl(); + + std::cout << "\n=== delete myobj ===" << std::endl; + delete myobj; + + std::cout << "\n=== delete myobj2 ===" << std::endl; + delete myobj2; + + return 0; + } +} // namespace example + +int main() +{ + return example::exampleObjectPimpl(); +} diff --git a/src/bin/example/exampleProperty.cpp b/src/bin/example/exampleProperty.cpp new file mode 100644 index 0000000..e3520d0 --- /dev/null +++ b/src/bin/example/exampleProperty.cpp @@ -0,0 +1,115 @@ +#include +#include +#include + +/* RESULT +=== Property *myproperty = new Property() === +Constructor 'Property' : example::Property::Property() + +=== Property *myproperty2 = new Property() === +Constructor 'Property' : example::Property::Property() + +=== Add Property [myProperty:1234(int)] to myproperty +Try get Property (key:"myProperty", type:int) of myproperty +myProperty: 1234 +Try get Property (key:"myProperty", type:float) of myproperty +ERR: Unexpected index + +=== Add Property [myProperty:0x11fd378(ptr)] to myproperty === +Try get Property (key:"myProperty", type:int) of myproperty +ERR: Unexpected index +Try get Property (key:"myProperty", type:void *) of myproperty +myProperty: 0x####### +Try get Property (key:"yourProperty", type:DSPropertyVariant&) of myproperty +SUCCESS: NOT_EXIST + +=== delete myproperty === +Destructor 'Property' : virtual example::Property::~Property() + +=== delete myproperty2 === +Destructor 'Property' : virtual example::Property::~Property() +*/ + +namespace example { + class Property : public display_server::DSObject { + public: + explicit Property(); + virtual ~Property(); + }; + + Property::Property() + { + std::cout << "Constructor 'Property' : " << __PRETTY_FUNCTION__ << std::endl; + } + + Property::~Property() + { + std::cout << "Destructor 'Property' : " << __PRETTY_FUNCTION__ << std::endl; + } + + int exampleProperty(void) + { + std::cout << "\n=== Property *myproperty = new Property() ===" << std::endl; + Property *myproperty = new Property(); + + std::cout << "\n=== Property *myproperty2 = new Property() ===" << std::endl; + Property *myproperty2 = new Property(); + + std::cout << "\n=== Add Property [myProperty:1234(int)] to myproperty ===" << std::endl; + myproperty->setProperty("myProperty", 1234, display_server::DSPropertyType::INTEGER); + try { + std::cout << "Try get Property (key:\"myProperty\", type:int) of myproperty" << std::endl; + std::cout << "myProperty: " << std::get(myproperty->getProperty("myProperty")) << std::endl; + } + catch (std::exception &e) { + std::cout << "ERR: " << e.what() << std::endl; + } + try { + std::cout << "Try get Property (key:\"myProperty\", type:float) of myproperty" << std::endl; + std::cout << std::get(myproperty->getProperty("myProperty")) << std::endl; + } + catch (std::exception &e) { + std::cout << "ERR: " << e.what() << std::endl; + } + + std::cout << "\n=== Add Property [myProperty:" << myproperty2 << "(ptr)] to myproperty ===" << std::endl; + myproperty->setProperty("myProperty", static_cast(myproperty2), display_server::DSPropertyType::POINTER); + try { + std::cout << "Try get Property (key:\"myProperty\", type:int) of myproperty" << std::endl; + std::cout << std::get(myproperty->getProperty("myProperty")) << std::endl; + } + catch (std::exception &e) { + std::cout << "ERR: " << e.what() << std::endl; + } + try { + std::cout << "Try get Property (key:\"myProperty\", type:void *) of myproperty" << std::endl; + Property *mypropertyptr = static_cast(std::get(myproperty->getProperty("myProperty"))); + std::cout << "myProperty: " << mypropertyptr << std::endl; + } + catch (std::exception &e) { + std::cout << "ERR: " << e.what() << std::endl; + } + + try { + std::cout << "Try get Property (key:\"yourProperty\", type:DSPropertyVariant&) of myproperty" << std::endl; + const display_server::DSPropertyVariant &ptr = myproperty->getProperty("yourProperty"); + std::cout << " THIS LINE SHOULD BE NOT PRINTED! yourProperty: " << &ptr << std::endl; + } + catch (std::exception &e) { + std::cout << "SUCCESS: " << e.what() << std::endl; + } + + std::cout << "\n=== delete myproperty ===" << std::endl; + delete myproperty; + + std::cout << "\n=== delete myproperty2 ===" << std::endl; + delete myproperty2; + + return 0; + } +} // namespace example + +int main() +{ + return example::exampleProperty(); +} diff --git a/src/bin/example/exampleSignalSlot.cpp b/src/bin/example/exampleSignalSlot.cpp new file mode 100644 index 0000000..42e35f3 --- /dev/null +++ b/src/bin/example/exampleSignalSlot.cpp @@ -0,0 +1,116 @@ +#include +#include +#include +#include + +/* RESULT +construct Sender +construct Sender +construct Receiver +construct Receiver +slotA invoked! a:1234 +slotA2 invoked! a:1234 +slotB invoked! a:45.67 +Lambda slot invoked! val: 45.67 +destruct Receiver(ref: 0) +slotB invoked! a:5678 +slotA invoked! a:90 +destruct Sender +destruct Sender +destruct Receiver(ref: 1) + */ +namespace example { + + using SignalAType = display_server::DSSignal; + using SignalBType = display_server::DSSignal; + + class Sender : public display_server::DSObject { + public: + Sender() : + display_server::DSObject() + { + std::cout << "construct Sender" << std::endl; + } + ~Sender() + { + std::cout << "destruct Sender " << getName() << std::endl; + } + + struct SignalA : public SignalAType { + void emit(int val) + { + SignalAType::emit(val); + } + } signalA; + + struct SignalB : public SignalBType { + void emit(double val) + { + SignalBType::emit(val); + } + } signalB; + }; + + class Receiver : public display_server::DSObject, public display_server::DSRefBase { + public: + Receiver() : + display_server::DSObject(), display_server::DSRefBase() + { + std::cout << "construct Receiver" << std::endl; + } + ~Receiver() + { + std::cout << "destruct Receiver(ref: " << getref() << ") " << getName() << std::endl; + } + + static void slotA(int a) + { + std::cout << "slotA invoked! a:" << a << std::endl; + }; + static void slotA2(int a) + { + std::cout << "slotA2 invoked! a:" << a << std::endl; + } + static void slotB(double a) + { + std::cout << "slotB invoked! a:" << a << std::endl; + }; + }; + + int main(void) + { + Sender *sender = new Sender(); + Sender *sender2 = new Sender(); + Receiver *receiver = new Receiver(); + Receiver *receiver2 = new Receiver(); + + sender->signalA.connect(receiver, Receiver::slotA); + sender->signalA.connect(receiver2, Receiver::slotA2); + sender->signalB.connect(receiver, Receiver::slotB); + sender->signalB.connect(receiver2, [](double val) { + std::cout << "Lambda slot invoked! val: " << val << std::endl; + }); + + sender->signalA.emit(1234); + sender->signalB.emit(45.67); + + if (receiver2->getref() == 1) { + receiver2->unref(); + receiver2 = nullptr; + } + + sender->signalB.emit(5678); + sender->signalA.emit(90.1); + + delete sender; + delete sender2; + delete receiver; + + return 0; + } +} // namespace example + +int main() +{ + return example::main(); +} diff --git a/src/bin/sample1.cpp b/src/bin/sample1.cpp deleted file mode 100644 index 546dbd8..0000000 --- a/src/bin/sample1.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include -#include -#include - -/* SAMPLE RESULT -construct Sender sender -construct Sender sender2 -construct Receiver receiver1 -construct Receiver receiver2 -slotA invoked! a:1234 -slotA2 invoked! a:1234 -slotB invoked! a:45.67 -Lambda slot invoked! val: 45.67 -destruct Receiver(ref: 0) receiver2 -slotB invoked! a:5678 -slotA invoked! a:90 -destruct Sender sender -destruct Sender sender2 -destruct Receiver(ref: 1) receiver1 - */ - -using namespace display_server; - -using SignalAType = DSSignal; -using SignalBType = DSSignal; - -class Sender : public DSObject -{ - public: - Sender() : DSObject("Sender"){ std::cout << "construct Sender" << std::endl;} - Sender(std::string name) : DSObject(name) {std::cout << "construct Sender " << name << std::endl;} - ~Sender(){ std::cout << "destruct Sender " << getName() << std::endl;} - - struct SignalA : public SignalAType { - void emit(int val) { SignalAType::emit(val); } - } signalA; - - struct SignalB : public SignalBType { - void emit(double val) { SignalBType::emit(val); } - } signalB; -}; - -class Receiver : public DSObject, public DSRefBase { - public: - Receiver() : DSObject("Receiver"), DSRefBase() { std::cout << "construct Receiver" << std::endl;} - Receiver(std::string name) : DSObject(name), DSRefBase() { std::cout << "construct Receiver " << name << std::endl;} - ~Receiver() { std::cout << "destruct Receiver(ref: " << getref() << ") " << getName() << std::endl; } - - static void slotA(int a) { std::cout << "slotA invoked! a:" << a << std::endl; }; - static void slotA2(int a) {std::cout << "slotA2 invoked! a:" << a << std::endl; } - static void slotB(double a) { std::cout << "slotB invoked! a:" << a << std::endl; }; -}; - -int main (void) -{ - Sender *sender = new Sender("sender"); - Sender *sender2 = new Sender("sender2"); - Receiver *receiver = new Receiver("receiver1"); - Receiver *receiver2 = new Receiver("receiver2"); - - sender->signalA.connect(receiver, Receiver::slotA); - sender->signalA.connect(receiver2, Receiver::slotA2); - sender->signalB.connect(receiver, Receiver::slotB); - sender->signalB.connect(receiver2, [](double val) { - std::cout << "Lambda slot invoked! val: " << val << std::endl; - }); - - sender->signalA.emit(1234); - sender->signalB.emit(45.67); - - if (receiver2->getref() == 1) - { - receiver2->unref(); - receiver2 = nullptr; - } - - sender->signalB.emit(5678); - sender->signalA.emit(90.1); - - delete sender; - delete sender2; - delete receiver; - - return 0; -} -- 2.7.4 From 7065b291dd39a5166a9836828b7f8f1deb431284 Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Thu, 5 Mar 2020 15:45:19 +0900 Subject: [PATCH 15/16] Separate private cpp Change-Id: I4497e1d1ad52637605a8bfbc5c1dd454fa112218 Signed-off-by: MinJeong Kim --- meson.build | 2 ++ src/lib/DSObject.cpp | 73 ------------------------------------------ src/lib/DSObjectPrivate.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++ src/lib/DSProperty.cpp | 67 --------------------------------------- src/lib/DSPropertyPrivate.cpp | 70 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 146 insertions(+), 140 deletions(-) create mode 100644 src/lib/DSObjectPrivate.cpp create mode 100644 src/lib/DSPropertyPrivate.cpp diff --git a/meson.build b/meson.build index 84d3d18..482c06b 100644 --- a/meson.build +++ b/meson.build @@ -21,12 +21,14 @@ src_libds = [ 'src/lib/DSRefBase.h', 'src/lib/DSObject.cpp', 'src/lib/DSObject.h', + 'src/lib/DSObjectPrivate.cpp', 'src/lib/DSObjectPrivate.h', 'src/lib/DSSignal.cpp', 'src/lib/DSSignal.h', 'src/lib/DSCallback.h', 'src/lib/DSProperty.cpp', 'src/lib/DSProperty.h', + 'src/lib/DSPropertyPrivate.cpp', 'src/lib/DSPropertyPrivate.h' ] diff --git a/src/lib/DSObject.cpp b/src/lib/DSObject.cpp index 7052226..666ef6f 100644 --- a/src/lib/DSObject.cpp +++ b/src/lib/DSObject.cpp @@ -1,79 +1,6 @@ #include "DSObject.h" -#include "DSObjectPrivate.h" -#include "DSProperty.h" namespace display_server { - DSObjectPrivate::DSObjectPrivate(DSObject *p_ptr) : - __p_ptr(p_ptr) - { - } - - DSObjectPrivate::~DSObjectPrivate() - { - __type_info.name.clear(); - __observers.clear(); - __properties.clear(); - } - - void DSObjectPrivate::attachDestroyObserver(DSObjectObserverIface *ob) - { - __observers.push_back(ob); - } - - void DSObjectPrivate::detachDestroyObserver(DSObjectObserverIface *ob) - { - __observers.remove(ob); - } - - void DSObjectPrivate::setProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type) - { - std::unordered_map::const_iterator ci = __properties.find(key); - if (ci == __properties.end()) { - __properties.emplace(key, DSProperty(key, data, type)); - } else { - __properties[key] = DSProperty(key, data, type); - } - } - - const DSPropertyVariant &DSObjectPrivate::getProperty(std::string key) - { - std::unordered_map::const_iterator ci = __properties.find(key); - if (ci == __properties.end()) { - throw DSPropertyException("NOT_EXIST"); - } - return __properties[key].getData(); - } - - void DSObjectPrivate::notifyDestroy(void) - { - for (DSObjectObserverIface *ob : __observers) - ob->destroyed(__p_ptr); - __observers.clear(); - } - - std::string DSObjectPrivate::getName(void) - { - return __type_info.name; - } - - DSObjectPrivate& DSObjectPrivate::operator=(DSObjectPrivate &&p) - { - if (__p_ptr) - return *this; - - __type_info.name = p.__type_info.name; - __p_ptr = p.__p_ptr; - __observers = std::move(p.__observers); - __properties = std::move(p.__properties); - - p.__type_info.name.clear(); - p.__p_ptr = nullptr; - p.__observers.clear(); - p.__properties.clear(); - - return *this; - } - DSObject::DSObject() { __d_ptr = std::make_unique(this); diff --git a/src/lib/DSObjectPrivate.cpp b/src/lib/DSObjectPrivate.cpp new file mode 100644 index 0000000..589c12e --- /dev/null +++ b/src/lib/DSObjectPrivate.cpp @@ -0,0 +1,74 @@ +#include "DSObject.h" + +namespace display_server { + DSObjectPrivate::DSObjectPrivate(DSObject *p_ptr) : + __p_ptr(p_ptr) + { + } + + DSObjectPrivate::~DSObjectPrivate() + { + __type_info.name.clear(); + __observers.clear(); + __properties.clear(); + } + + void DSObjectPrivate::attachDestroyObserver(DSObjectObserverIface *ob) + { + __observers.push_back(ob); + } + + void DSObjectPrivate::detachDestroyObserver(DSObjectObserverIface *ob) + { + __observers.remove(ob); + } + + void DSObjectPrivate::setProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type) + { + std::unordered_map::const_iterator ci = __properties.find(key); + if (ci == __properties.end()) { + __properties.emplace(key, DSProperty(key, data, type)); + } else { + __properties[key] = DSProperty(key, data, type); + } + } + + const DSPropertyVariant &DSObjectPrivate::getProperty(std::string key) + { + std::unordered_map::const_iterator ci = __properties.find(key); + if (ci == __properties.end()) { + throw DSPropertyException("NOT_EXIST"); + } + return __properties[key].getData(); + } + + void DSObjectPrivate::notifyDestroy(void) + { + for (DSObjectObserverIface *ob : __observers) + ob->destroyed(__p_ptr); + __observers.clear(); + } + + std::string DSObjectPrivate::getName(void) + { + return __type_info.name; + } + + DSObjectPrivate& DSObjectPrivate::operator=(DSObjectPrivate &&p) + { + if (__p_ptr) + return *this; + + __type_info.name = p.__type_info.name; + __p_ptr = p.__p_ptr; + __observers = std::move(p.__observers); + __properties = std::move(p.__properties); + + p.__type_info.name.clear(); + p.__p_ptr = nullptr; + p.__observers.clear(); + p.__properties.clear(); + + return *this; + } +} // namespace display_server diff --git a/src/lib/DSProperty.cpp b/src/lib/DSProperty.cpp index a4cdc10..30309da 100644 --- a/src/lib/DSProperty.cpp +++ b/src/lib/DSProperty.cpp @@ -1,73 +1,6 @@ #include "DSProperty.h" namespace display_server { - DSPropertyPrivate::DSPropertyPrivate(DSProperty *p_ptr) : - __p_ptr(p_ptr) - { - __type = DSPropertyType::NONE; - } - DSPropertyPrivate::DSPropertyPrivate(DSProperty *p_ptr, std::string key, const DSPropertyVariant &data, DSPropertyType type) : - __p_ptr(p_ptr), __key(key), __type(type) - { - switch (__type) { // copy case - case DSPropertyType::INTEGER: - case DSPropertyType::DOUBLE: - case DSPropertyType::FLOAT: - case DSPropertyType::STRING: - __data = data; // value copy - break; - case DSPropertyType::POINTER: - __data = data; // address copy - break; - default: - break; - } - } - - DSPropertyPrivate::~DSPropertyPrivate() - { - __key.clear(); - } - - const std::string DSPropertyPrivate::getKey() const - { - return __key; - } - - const DSPropertyVariant &DSPropertyPrivate::getData() const - { - return __data; - } - - const DSPropertyType DSPropertyPrivate::getType() const - { - return __type; - } - - void DSPropertyPrivate::setKey(std::string key) - { - __key = key; - } - - void DSPropertyPrivate::setData(DSPropertyVariant data, DSPropertyType type) - { - __type = type; - - switch (__type) { // copy case - case DSPropertyType::INTEGER: - case DSPropertyType::DOUBLE: - case DSPropertyType::FLOAT: - case DSPropertyType::STRING: - __data = data; // value copy - break; - case DSPropertyType::POINTER: - __data = data; // address copy - break; - default: - break; - } - } - DSProperty::DSProperty() : __d_ptr(new DSPropertyPrivate(this)) { diff --git a/src/lib/DSPropertyPrivate.cpp b/src/lib/DSPropertyPrivate.cpp new file mode 100644 index 0000000..1c0ada3 --- /dev/null +++ b/src/lib/DSPropertyPrivate.cpp @@ -0,0 +1,70 @@ +#include "DSProperty.h" + +namespace display_server { + DSPropertyPrivate::DSPropertyPrivate(DSProperty *p_ptr) : + __p_ptr(p_ptr) + { + __type = DSPropertyType::NONE; + } + DSPropertyPrivate::DSPropertyPrivate(DSProperty *p_ptr, std::string key, const DSPropertyVariant &data, DSPropertyType type) : + __p_ptr(p_ptr), __key(key), __type(type) + { + switch (__type) { // copy case + case DSPropertyType::INTEGER: + case DSPropertyType::DOUBLE: + case DSPropertyType::FLOAT: + case DSPropertyType::STRING: + __data = data; // value copy + break; + case DSPropertyType::POINTER: + __data = data; // address copy + break; + default: + break; + } + } + + DSPropertyPrivate::~DSPropertyPrivate() + { + __key.clear(); + } + + const std::string DSPropertyPrivate::getKey() const + { + return __key; + } + + const DSPropertyVariant &DSPropertyPrivate::getData() const + { + return __data; + } + + const DSPropertyType DSPropertyPrivate::getType() const + { + return __type; + } + + void DSPropertyPrivate::setKey(std::string key) + { + __key = key; + } + + void DSPropertyPrivate::setData(DSPropertyVariant data, DSPropertyType type) + { + __type = type; + + switch (__type) { // copy case + case DSPropertyType::INTEGER: + case DSPropertyType::DOUBLE: + case DSPropertyType::FLOAT: + case DSPropertyType::STRING: + __data = data; // value copy + break; + case DSPropertyType::POINTER: + __data = data; // address copy + break; + default: + break; + } + } +} // namespace display_server -- 2.7.4 From b662198436ce259ec5627a5cd4723bbc7268ee20 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 5 Mar 2020 10:56:38 +0900 Subject: [PATCH 16/16] add initial code for DSBufferQueue Change-Id: I088b0523fae5c28ebb8e9398f63820bbb986f9d6 --- meson.build | 21 ++++++++++++++++----- src/lib/DSBuffer/DSBufferQueue.cpp | 10 ++++++++++ src/lib/DSBuffer/DSBufferQueue.h | 15 +++++++++++++++ src/lib/DSRender/DSDaliRenderer.h | 35 +++++++++++++++++++++++++++++++++++ tests/DSBufferQueue-test.cpp | 17 +++++++++++++++++ tests/meson.build | 27 +++++++++++++++++---------- 6 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 src/lib/DSBuffer/DSBufferQueue.cpp create mode 100644 src/lib/DSBuffer/DSBufferQueue.h create mode 100644 src/lib/DSRender/DSDaliRenderer.h create mode 100644 tests/DSBufferQueue-test.cpp diff --git a/meson.build b/meson.build index 482c06b..952c16d 100644 --- a/meson.build +++ b/meson.build @@ -12,9 +12,12 @@ dir_bin = join_paths(dir_prefix, get_option('bindir')) ## libds -install_headers('src/lib/DSObject.h', +install_headers( + 'src/lib/DSObject.h', 'src/lib/DSSignal.h', - 'src/lib/DSRefBase.h') + 'src/lib/DSRefBase.h', + 'src/lib/DSBuffer/DSBufferQueue.h', + ) src_libds = [ 'src/lib/DSRefBase.cpp', @@ -29,18 +32,26 @@ src_libds = [ 'src/lib/DSProperty.cpp', 'src/lib/DSProperty.h', 'src/lib/DSPropertyPrivate.cpp', - 'src/lib/DSPropertyPrivate.h' -] + 'src/lib/DSPropertyPrivate.h', + 'src/lib/DSBuffer/DSBufferQueue.cpp', + 'src/lib/DSBuffer/DSBufferQueue.h', + ] pkgconfig = import('pkgconfig') deps_libds = [] link_args = '-W' +ds_inc = include_directories( + 'src/lib', + 'src/lib/DSBuffer', + ) + lib_libds = shared_library( 'libds', src_libds, dependencies : deps_libds, + include_directories : [ds_inc], version : meson.project_version(), link_args : link_args, install : true @@ -49,7 +60,7 @@ lib_libds = shared_library( dep_libds = declare_dependency( link_with : lib_libds, dependencies : deps_libds, - include_directories : 'src/lib') + include_directories : [ds_inc]) pkgconfig.generate( filebase : 'libds', diff --git a/src/lib/DSBuffer/DSBufferQueue.cpp b/src/lib/DSBuffer/DSBufferQueue.cpp new file mode 100644 index 0000000..afc4948 --- /dev/null +++ b/src/lib/DSBuffer/DSBufferQueue.cpp @@ -0,0 +1,10 @@ +#include "DSBufferQueue.h" + +namespace display_server +{ + +DSBufferQueue::DSBufferQueue() {} + +DSBufferQueue::~DSBufferQueue() {} + +} // display_server diff --git a/src/lib/DSBuffer/DSBufferQueue.h b/src/lib/DSBuffer/DSBufferQueue.h new file mode 100644 index 0000000..248bd84 --- /dev/null +++ b/src/lib/DSBuffer/DSBufferQueue.h @@ -0,0 +1,15 @@ +#ifndef __DSBUFFERQUEUE_H +#define __DSBUFFERQUEUE_H + +namespace display_server { + +class DSBufferQueue { +private: + +public: + DSBufferQueue(); + virtual ~DSBufferQueue(); +}; + +} +#endif /* __DSBUFFERQUEUE_H */ diff --git a/src/lib/DSRender/DSDaliRenderer.h b/src/lib/DSRender/DSDaliRenderer.h new file mode 100644 index 0000000..313806b --- /dev/null +++ b/src/lib/DSRender/DSDaliRenderer.h @@ -0,0 +1,35 @@ +#ifndef __DSDALIRENDERER_H +#define __DSDALIRENDERER_H + +#include + +namespace display_server { + +class DSDaliRenderView : public DSRenderView +{ +private: +public: + DSDaliRenderView() {} + virtual ~DSDaliRenderView() {} +}; + +class DSDaliRenderer : public DSRenderer +{ +private: +public: + DSDaliRenderer() {}; + virtual ~DSDaliRenderer() {}; + + DSRenderView* NewRenderView() { + DSRenderView* renderView = new DSDaliRenderView(); + + return renderView; + } + + bool RenderFrame () { + std::cout << "[DALi] RenderFrame\n"; + }; +}; + +} +#endif \ No newline at end of file diff --git a/tests/DSBufferQueue-test.cpp b/tests/DSBufferQueue-test.cpp new file mode 100644 index 0000000..8f4a8d9 --- /dev/null +++ b/tests/DSBufferQueue-test.cpp @@ -0,0 +1,17 @@ +#include "libds-tests.h" +#include "DSBufferQueue.h" + +using namespace display_server; + +class DSBufferQueueTest : public ::testing::Test +{ +public: + void SetUp(void) override {} + void TearDown(void) override {} +}; + +TEST_F(DSBufferQueueTest, CreateBufferQueue) +{ + // TODO: + ASSERT_TRUE(true); +} diff --git a/tests/meson.build b/tests/meson.build index 03ef65f..07f58e1 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,14 +1,21 @@ -incdir = include_directories('../src/lib') -libds_unittests_src = ['libds-tests.cpp', - 'DSRefBase-test.cpp', - 'DSProperty-test.cpp'] +incdir = include_directories( + '../src/lib', + '../src/lib/DSBuffer', + ) + +libds_unittests_src = [ + 'libds-tests.cpp', + 'DSRefBase-test.cpp', + 'DSProperty-test.cpp', + 'DSBufferQueue-test.cpp', + ] gmock_dep = dependency('gmock', method : 'pkg-config') executable('libds-unittests', libds_unittests_src, - include_directories : incdir, - link_with : lib_libds, - dependencies : gmock_dep, - install_dir : dir_bin, - install : true - ) + include_directories : incdir, + link_with : lib_libds, + dependencies : gmock_dep, + install_dir : dir_bin, + install : true) + -- 2.7.4