Detach common library
authorSangwan Kwon <sangwan.kwon@samsung.com>
Mon, 18 Nov 2019 03:26:42 +0000 (12:26 +0900)
committer권상완/Security 2Lab(SR)/Engineer/삼성전자 <sangwan.kwon@samsung.com>
Fri, 22 Nov 2019 01:52:17 +0000 (10:52 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
17 files changed:
CMake/Macro.cmake
src/CMakeLists.txt
src/vist/CMakeLists.txt
src/vist/common/CMakeLists.txt [new file with mode: 0644]
src/vist/common/common.cpp [new file with mode: 0644]
src/vist/common/tests/exception.cpp [new file with mode: 0644]
src/vist/common/tests/logger.cpp [new file with mode: 0644]
src/vist/common/tests/result.cpp [new file with mode: 0644]
src/vist/ipc/CMakeLists.txt [new file with mode: 0644]
src/vist/ipc/ipc.cpp [new file with mode: 0644]
src/vist/query-builder/CMakeLists.txt
src/vist/query-builder/query-builder.cpp [new file with mode: 0644]
src/vist/sdk/CMakeLists.txt
src/vist/sdk/sdk.cpp [new file with mode: 0644]
src/vist/tests/exception.cpp [deleted file]
src/vist/tests/logger.cpp [deleted file]
src/vist/tests/result.cpp [deleted file]

index d7e804dd7ef42c9f2ed12bee0e5d4372e1f9eb01..326fd61e17ee8e26ef91bad36756525087c7f7dc 100644 (file)
@@ -39,9 +39,15 @@ ENDMACRO(ADD_VIST_LIBRARY)
 MACRO(ADD_VIST_CLIENT_LIBRARY TARGET)
        ADD_LIBRARY(${TARGET} OBJECT ${ARGN})
        LIST(APPEND ${TARGET_VIST_CLIENT_LIB}_SRCS $<TARGET_OBJECTS:${TARGET}>)
-       SET(${TARGET_VIST_LIB}_SRCS ${${TARGET_VIST_CLIENT_LIB}_SRCS} PARENT_SCOPE)
+       SET(${TARGET_VIST_CLIENT_LIB}_SRCS ${${TARGET_VIST_CLIENT_LIB}_SRCS} PARENT_SCOPE)
 ENDMACRO(ADD_VIST_CLIENT_LIBRARY)
 
+MACRO(ADD_VIST_COMMON_LIBRARY TARGET)
+       ADD_LIBRARY(${TARGET} OBJECT ${ARGN})
+       LIST(APPEND ${TARGET_VIST_COMMON_LIB}_SRCS $<TARGET_OBJECTS:${TARGET}>)
+       SET(${TARGET_VIST_COMMON_LIB}_SRCS ${${TARGET_VIST_COMMON_LIB}_SRCS} PARENT_SCOPE)
+ENDMACRO(ADD_VIST_COMMON_LIBRARY)
+
 MACRO(ADD_VIST_POLICY_LIBRARY TARGET)
        ADD_LIBRARY(${TARGET} OBJECT ${ARGN})
        LIST(APPEND ${TARGET_VIST_POLICY_LIB}_SRCS $<TARGET_OBJECTS:${TARGET}>)
index 52f231eb3a976950fa5edc15cfc48d5412c18977..16480432bf8d7ecf1235cf7dd3b0106c73cee307 100644 (file)
@@ -14,6 +14,7 @@
 
 SET(TARGET_OSQUERY_LIB osquery)
 SET(TARGET_VIST_CLIENT_LIB vist-client)
+SET(TARGET_VIST_COMMON_LIB vist-common)
 SET(TARGET_VIST_LIB vist)
 SET(TARGET_VIST_POLICY_LIB vist-policy)
 
index 66bfde5df65217935d3adedb2034586f753c392d..e4c7c9c45e0df1220d2325189b6c1a55ba85f346 100644 (file)
@@ -18,6 +18,7 @@ SET(TARGET_VIST_TEST vist-test)
 
 SET(${TARGET_VIST_LIB}_SRCS "")
 SET(${TARGET_VIST_LIB}_TESTS "")
+SET(${TARGET_VIST_COMMON_LIB}_SRCS "")
 
 SET(DEPENDENCY klay dlog gflags)
 
@@ -31,6 +32,8 @@ ADD_DEFINITIONS(-DDB_PATH="${DB_INSTALL_DIR}/.vist.db"
                                -DSCRIPT_INSTALL_DIR="${SCRIPT_INSTALL_DIR}")
 
 ADD_SUBDIRECTORY(client)
+ADD_SUBDIRECTORY(common)
+ADD_SUBDIRECTORY(ipc)
 ADD_SUBDIRECTORY(notification)
 ADD_SUBDIRECTORY(policy)
 ADD_SUBDIRECTORY(sdk)
@@ -70,12 +73,11 @@ INSTALL(TARGETS ${TARGET_VIST_CLI}
                                        WORLD_READ
                                        WORLD_EXECUTE)
 
-FILE(GLOB COMMON_TESTS "tests/*.cpp")
-ADD_VIST_TEST(${COMMON_TESTS})
-
 ADD_EXECUTABLE(${TARGET_VIST_TEST} main/tests.cpp
                                                                   ${${TARGET_VIST_LIB}_TESTS})
 TARGET_LINK_LIBRARIES(${TARGET_VIST_TEST} ${TARGET_VIST_LIB}
+                                                                                 ${TARGET_VIST_CLIENT_LIB}
+                                                                                 ${TARGET_VIST_COMMON_LIB}
                                                                                  gtest)
 TARGET_LINK_WHOLE(${TARGET_VIST_TEST} ${TARGET_OSQUERY_LIB})
 ADD_TEST(${TARGET_VIST_TEST} ${TARGET_VIST_TEST})
diff --git a/src/vist/common/CMakeLists.txt b/src/vist/common/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c76ae24
--- /dev/null
@@ -0,0 +1,26 @@
+#  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#  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
+
+PKG_CHECK_MODULES(VIST_COMMON_DEPS REQUIRED gflags klay dlog)
+
+INCLUDE_DIRECTORIES(SYSTEM . ${VIST_COMMON_DEPS_INCLUDE_DIRS})
+
+ADD_VIST_COMMON_LIBRARY(vist_common common.cpp)
+
+FILE(GLOB COMMON_TESTS "tests/*.cpp")
+ADD_VIST_TEST(${COMMON_TESTS})
+
+ADD_LIBRARY(${TARGET_VIST_COMMON_LIB} STATIC ${${TARGET_VIST_COMMON_LIB}_SRCS})
+TARGET_LINK_LIBRARIES(${TARGET_VIST_COMMON_LIB} ${VIST_COMMON_DEPS_LIBRARIES}
+                                                                                               pthread)
diff --git a/src/vist/common/common.cpp b/src/vist/common/common.cpp
new file mode 100644 (file)
index 0000000..14ffe17
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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 <vist/exception.hpp>
+#include <vist/logger.hpp>
+#include <vist/result.hpp>
diff --git a/src/vist/common/tests/exception.cpp b/src/vist/common/tests/exception.cpp
new file mode 100644 (file)
index 0000000..16bd539
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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 <gtest/gtest.h>
+
+#include <vist/exception.hpp>
+
+enum class ErrCode {
+       InvalidArgument = 1,
+       DominError,
+       LogicError,
+       RuntimeError,
+       None
+};
+
+class ExceptionTests : public testing::Test {};
+
+TEST_F(ExceptionTests, exception)
+{
+       bool raised = false;
+       ErrCode ec = ErrCode::None;
+       std::string msg;
+
+       try {
+               THROW(ErrCode::InvalidArgument);
+       } catch (const vist::Exception<ErrCode>& e) {
+               raised = true;
+               ec = e.get();
+               msg = e.what();
+       }
+
+       EXPECT_TRUE(raised);
+       EXPECT_EQ(ec, ErrCode::InvalidArgument);
+       EXPECT_NE(std::string::npos, msg.find("ErrCode"));
+}
+
+TEST_F(ExceptionTests, exception_msg)
+{
+       bool raised = false;
+       ErrCode ec = ErrCode::None;
+       std::string msg;
+
+       try {
+               THROW(ErrCode::RuntimeError) << "Additional error message";
+       } catch (const vist::Exception<ErrCode>& e) {
+               raised = true;
+               ec = e.get();
+               msg = e.what();
+       }
+
+       EXPECT_TRUE(raised);
+       EXPECT_EQ(ec, ErrCode::RuntimeError);
+       EXPECT_NE(std::string::npos, msg.find("Additional"));
+}
diff --git a/src/vist/common/tests/logger.cpp b/src/vist/common/tests/logger.cpp
new file mode 100644 (file)
index 0000000..78336ec
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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 <gtest/gtest.h>
+
+#include <vist/logger.hpp>
+
+class LoggerTests : public testing::Test {};
+
+TEST_F(LoggerTests, logging)
+{
+       INFO(VIST) << "Info message" << 1;
+       DEBUG(VIST) << "Debug message" << 2 << 'a';
+       WARN(VIST) << "Warn message" << 3 << 'b' << true;
+       ERROR(VIST) << "Error message" << 4 << 'c' << false << 0.0f;
+}
diff --git a/src/vist/common/tests/result.cpp b/src/vist/common/tests/result.cpp
new file mode 100644 (file)
index 0000000..c1a6a33
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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 <gtest/gtest.h>
+
+#include <vist/result.hpp>
+
+#include <string>
+#include <vector>
+
+class ResultTests : public testing::Test {};
+
+using namespace vist;
+
+enum class FileErr {
+       InvalidArgument,
+       NotFound
+};
+
+Result<std::string, FileErr> readSuccess()
+{
+       return std::string("File contents");
+}
+
+Result<std::string, FileErr> readFail()
+{
+       return FileErr::NotFound;
+}
+
+Result<std::vector<int>, FileErr> readVector()
+{
+       std::vector<int> v{1, 2, 3};
+       return v;
+}
+
+TEST_F(ResultTests, success)
+{
+       EXPECT_TRUE(readSuccess().ok());
+       EXPECT_TRUE(!readSuccess().err());
+       EXPECT_NE(std::string::npos, readSuccess().get().find("File"));
+}
+
+TEST_F(ResultTests, fail)
+{
+       EXPECT_TRUE(readFail().err());
+       EXPECT_TRUE(!readFail().ok());
+       EXPECT_EQ(FileErr::NotFound, readFail().getErrCode());
+}
+
+TEST_F(ResultTests, vector)
+{
+       EXPECT_TRUE(readVector().ok());
+       EXPECT_TRUE(!readVector().err());
+       EXPECT_EQ(3, readVector().get().size());
+}
diff --git a/src/vist/ipc/CMakeLists.txt b/src/vist/ipc/CMakeLists.txt
new file mode 100644 (file)
index 0000000..616a117
--- /dev/null
@@ -0,0 +1,16 @@
+# Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# 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_VIST_COMMON_LIBRARY(vist_ipc ipc.cpp)
diff --git a/src/vist/ipc/ipc.cpp b/src/vist/ipc/ipc.cpp
new file mode 100644 (file)
index 0000000..2a92627
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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 <vist/ipc/client.hpp>
+#include <vist/ipc/server.hpp>
index 5f41c24b9ce44eb0467faf5302da17f6bb683f95..3965ab000dee2a262df744ce19e112b7769d79d3 100644 (file)
@@ -12,6 +12,8 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License
 
+ADD_VIST_COMMON_LIBRARY(vist_query_builder query-builder.cpp)
+
 /// TSQB: Type Safe Query Builder
 FILE(GLOB TSQB_TESTS "tests/*.cpp")
 ADD_VIST_TEST(${TSQB_TESTS})
diff --git a/src/vist/query-builder/query-builder.cpp b/src/vist/query-builder/query-builder.cpp
new file mode 100644 (file)
index 0000000..21f34b0
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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 <vist/query-builder.hpp>
index 5e233cf79ffbdff760be30ae24e68cc013271de7..a370c59fdbcef8b0fe863fde4d8be0084c76fde8 100644 (file)
@@ -13,5 +13,7 @@
 # limitations under the License.
 #
 
+ADD_VIST_COMMON_LIBRARY(vist_sdk sdk.cpp)
+
 FILE(GLOB POLICY_SDK_TESTS "tests/*.cpp")
 ADD_VIST_TEST(${POLICY_SDK_TESTS})
diff --git a/src/vist/sdk/sdk.cpp b/src/vist/sdk/sdk.cpp
new file mode 100644 (file)
index 0000000..ab97ed9
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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 <vist/sdk/policy-model.hpp>
+#include <vist/sdk/policy-provider.hpp>
+#include <vist/sdk/policy-value.hpp>
diff --git a/src/vist/tests/exception.cpp b/src/vist/tests/exception.cpp
deleted file mode 100644 (file)
index 16bd539..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  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 <gtest/gtest.h>
-
-#include <vist/exception.hpp>
-
-enum class ErrCode {
-       InvalidArgument = 1,
-       DominError,
-       LogicError,
-       RuntimeError,
-       None
-};
-
-class ExceptionTests : public testing::Test {};
-
-TEST_F(ExceptionTests, exception)
-{
-       bool raised = false;
-       ErrCode ec = ErrCode::None;
-       std::string msg;
-
-       try {
-               THROW(ErrCode::InvalidArgument);
-       } catch (const vist::Exception<ErrCode>& e) {
-               raised = true;
-               ec = e.get();
-               msg = e.what();
-       }
-
-       EXPECT_TRUE(raised);
-       EXPECT_EQ(ec, ErrCode::InvalidArgument);
-       EXPECT_NE(std::string::npos, msg.find("ErrCode"));
-}
-
-TEST_F(ExceptionTests, exception_msg)
-{
-       bool raised = false;
-       ErrCode ec = ErrCode::None;
-       std::string msg;
-
-       try {
-               THROW(ErrCode::RuntimeError) << "Additional error message";
-       } catch (const vist::Exception<ErrCode>& e) {
-               raised = true;
-               ec = e.get();
-               msg = e.what();
-       }
-
-       EXPECT_TRUE(raised);
-       EXPECT_EQ(ec, ErrCode::RuntimeError);
-       EXPECT_NE(std::string::npos, msg.find("Additional"));
-}
diff --git a/src/vist/tests/logger.cpp b/src/vist/tests/logger.cpp
deleted file mode 100644 (file)
index 78336ec..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  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 <gtest/gtest.h>
-
-#include <vist/logger.hpp>
-
-class LoggerTests : public testing::Test {};
-
-TEST_F(LoggerTests, logging)
-{
-       INFO(VIST) << "Info message" << 1;
-       DEBUG(VIST) << "Debug message" << 2 << 'a';
-       WARN(VIST) << "Warn message" << 3 << 'b' << true;
-       ERROR(VIST) << "Error message" << 4 << 'c' << false << 0.0f;
-}
diff --git a/src/vist/tests/result.cpp b/src/vist/tests/result.cpp
deleted file mode 100644 (file)
index c1a6a33..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  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 <gtest/gtest.h>
-
-#include <vist/result.hpp>
-
-#include <string>
-#include <vector>
-
-class ResultTests : public testing::Test {};
-
-using namespace vist;
-
-enum class FileErr {
-       InvalidArgument,
-       NotFound
-};
-
-Result<std::string, FileErr> readSuccess()
-{
-       return std::string("File contents");
-}
-
-Result<std::string, FileErr> readFail()
-{
-       return FileErr::NotFound;
-}
-
-Result<std::vector<int>, FileErr> readVector()
-{
-       std::vector<int> v{1, 2, 3};
-       return v;
-}
-
-TEST_F(ResultTests, success)
-{
-       EXPECT_TRUE(readSuccess().ok());
-       EXPECT_TRUE(!readSuccess().err());
-       EXPECT_NE(std::string::npos, readSuccess().get().find("File"));
-}
-
-TEST_F(ResultTests, fail)
-{
-       EXPECT_TRUE(readFail().err());
-       EXPECT_TRUE(!readFail().ok());
-       EXPECT_EQ(FileErr::NotFound, readFail().getErrCode());
-}
-
-TEST_F(ResultTests, vector)
-{
-       EXPECT_TRUE(readVector().ok());
-       EXPECT_TRUE(!readVector().err());
-       EXPECT_EQ(3, readVector().get().size());
-}