Rename file extension from .h to .hpp
authorSangwan Kwon <sangwan.kwon@samsung.com>
Thu, 7 Nov 2019 05:16:12 +0000 (14:16 +0900)
committerSangwan Kwon <sangwan.kwon@samsung.com>
Fri, 8 Nov 2019 05:40:50 +0000 (14:40 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
103 files changed:
AUTHORS [new file with mode: 0644]
plugins/bluetooth/bluetooth.cpp
plugins/wifi/wifi.cpp
src/osquery/tables/tizen/policy.cpp
src/osquery/tables/tizen/policy_admin.cpp
src/osquery/tables/tizen/tests/policy.cpp [new file with mode: 0644]
src/osquery/tables/tizen/tests/policy_tests.cpp [deleted file]
src/vist/CMakeLists.txt
src/vist/client/query.cpp
src/vist/client/query.h [deleted file]
src/vist/client/query.hpp [new file with mode: 0644]
src/vist/client/schema/policy.h [deleted file]
src/vist/client/schema/policy.hpp [new file with mode: 0644]
src/vist/client/schema/processes.h [deleted file]
src/vist/client/schema/processes.hpp [new file with mode: 0644]
src/vist/client/schema/time.h [deleted file]
src/vist/client/schema/time.hpp [new file with mode: 0644]
src/vist/client/tests/client-tests.cpp [deleted file]
src/vist/client/tests/client.cpp [new file with mode: 0644]
src/vist/client/tests/virtual-table-tests.cpp [deleted file]
src/vist/client/tests/virtual-table.cpp [new file with mode: 0644]
src/vist/client/virtual-table.cpp
src/vist/client/virtual-table.h [deleted file]
src/vist/client/virtual-table.hpp [new file with mode: 0644]
src/vist/common/CMakeLists.txt [deleted file]
src/vist/common/audit/logger.h [deleted file]
src/vist/common/exception.h [deleted file]
src/vist/common/ipc/client.h [deleted file]
src/vist/common/ipc/server.h [deleted file]
src/vist/common/ipc/tests/ipc_tests.cpp [deleted file]
src/vist/common/tests/exception.cpp [deleted file]
src/vist/exception.hpp [new file with mode: 0644]
src/vist/ipc/client.hpp [new file with mode: 0644]
src/vist/ipc/server.hpp [new file with mode: 0644]
src/vist/ipc/tests/ipc.cpp [new file with mode: 0644]
src/vist/logger.hpp [new file with mode: 0644]
src/vist/main/main.cpp
src/vist/main/tests.cpp
src/vist/notification/notification.cpp
src/vist/notification/notification.h [deleted file]
src/vist/notification/notification.hpp [new file with mode: 0644]
src/vist/notification/tests/notification-tests.cpp [deleted file]
src/vist/notification/tests/notification.cpp [new file with mode: 0644]
src/vist/policy/api.h [deleted file]
src/vist/policy/api.hpp [new file with mode: 0644]
src/vist/policy/core/api.cpp
src/vist/policy/core/db-schema.h [deleted file]
src/vist/policy/core/db-schema.hpp [new file with mode: 0644]
src/vist/policy/core/policy-loader.cpp
src/vist/policy/core/policy-loader.h [deleted file]
src/vist/policy/core/policy-loader.hpp [new file with mode: 0644]
src/vist/policy/core/policy-manager.cpp
src/vist/policy/core/policy-manager.h [deleted file]
src/vist/policy/core/policy-manager.hpp [new file with mode: 0644]
src/vist/policy/core/policy-storage.cpp
src/vist/policy/core/policy-storage.h [deleted file]
src/vist/policy/core/policy-storage.hpp [new file with mode: 0644]
src/vist/policy/core/tests/core-tests.cpp [deleted file]
src/vist/policy/core/tests/core.cpp [new file with mode: 0644]
src/vist/policy/core/tests/storage-tests.cpp [deleted file]
src/vist/policy/core/tests/storage.cpp [new file with mode: 0644]
src/vist/policy/sdk/policy-model.h [deleted file]
src/vist/policy/sdk/policy-model.hpp [new file with mode: 0644]
src/vist/policy/sdk/policy-provider.h [deleted file]
src/vist/policy/sdk/policy-provider.hpp [new file with mode: 0644]
src/vist/policy/sdk/policy-value.h [deleted file]
src/vist/policy/sdk/policy-value.hpp [new file with mode: 0644]
src/vist/policy/sdk/tests/sdk-tests.cpp [deleted file]
src/vist/policy/sdk/tests/sdk.cpp [new file with mode: 0644]
src/vist/query-builder.hpp [new file with mode: 0644]
src/vist/query-builder/CMakeLists.txt [new file with mode: 0644]
src/vist/query-builder/column-pack.hpp [new file with mode: 0644]
src/vist/query-builder/column.hpp [new file with mode: 0644]
src/vist/query-builder/condition.hpp [new file with mode: 0644]
src/vist/query-builder/crud.hpp [new file with mode: 0644]
src/vist/query-builder/database.hpp [new file with mode: 0644]
src/vist/query-builder/expression.hpp [new file with mode: 0644]
src/vist/query-builder/table-pack.hpp [new file with mode: 0644]
src/vist/query-builder/table.hpp [new file with mode: 0644]
src/vist/query-builder/tests/query-builder.cpp [new file with mode: 0644]
src/vist/query-builder/tuple-helper.hpp [new file with mode: 0644]
src/vist/query-builder/type.hpp [new file with mode: 0644]
src/vist/query-builder/util.hpp [new file with mode: 0644]
src/vist/service/tests/core-tests.cpp [deleted file]
src/vist/service/tests/core.cpp [new file with mode: 0644]
src/vist/service/vist.cpp
src/vist/service/vist.h [deleted file]
src/vist/service/vist.hpp [new file with mode: 0644]
src/vist/tests/exception.cpp [new file with mode: 0644]
src/vist/tsqb/CMakeLists.txt [deleted file]
src/vist/tsqb/include/column-pack.hxx [deleted file]
src/vist/tsqb/include/column.hxx [deleted file]
src/vist/tsqb/include/condition.hxx [deleted file]
src/vist/tsqb/include/crud.hxx [deleted file]
src/vist/tsqb/include/database.hxx [deleted file]
src/vist/tsqb/include/expression.hxx [deleted file]
src/vist/tsqb/include/table-pack.hxx [deleted file]
src/vist/tsqb/include/table.hxx [deleted file]
src/vist/tsqb/include/tuple-helper.hxx [deleted file]
src/vist/tsqb/include/type.hxx [deleted file]
src/vist/tsqb/include/util.hxx [deleted file]
src/vist/tsqb/tests/tsqb-tests.cpp [deleted file]
src/vist/tsqb/tsqb.hxx [deleted file]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..166e74e
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,13 @@
+# This is the official list of ViST authors for copyright purposes.
+# This file is distinct from the CONTRIBUTORS files.
+# See the latter for an explanation.
+#
+# Names should be added to this file as:
+#      Name or Organization <email address>
+# The email address is not required for organizations.
+#
+# Please keep the list sorted.
+
+Jaemin Ryu <jm77.ryu@samsung.com>
+Samsung Electronics Co.
+Sangwan Kwon <sangwan.kwon@samsung.com>
index eafbc65e2f0a2359cd31cc43e3a7d0e6229ab7fc..0caa39eb4dd31733d9264e8c795b8769bc156d1c 100644 (file)
@@ -18,8 +18,8 @@
 #include <bluetooth-api.h>
 #include <bluetooth_internal.h>
 
-#include <vist/policy/sdk/policy-model.h>
-#include <vist/policy/sdk/policy-provider.h>
+#include <vist/policy/sdk/policy-model.hpp>
+#include <vist/policy/sdk/policy-provider.hpp>
 
 #include <memory>
 
index b8d8aa53429cdb2b14effa954911e4615d9b0ff6..95ca32e9b61092e4678088301ba9621258481ab3 100644 (file)
@@ -17,8 +17,8 @@
 #include <arpa/inet.h>
 #include <wifi-manager.h>
 
-#include <vist/policy/sdk/policy-model.h>
-#include <vist/policy/sdk/policy-provider.h>
+#include <vist/policy/sdk/policy-model.hpp>
+#include <vist/policy/sdk/policy-provider.hpp>
 
 #include <klay/dbus/connection.h>
 
index 53010712548428ca37a664fdeb662dbdc1d39520..313ac1471e66e3d4b203058c175aa78dead52ed8 100644 (file)
@@ -21,8 +21,8 @@
 #include <osquery/sql.h>
 #include <osquery/tables.h>
 
-#include <vist/policy/api.h>
-#include <vist/common/audit/logger.h>
+#include <vist/policy/api.hpp>
+#include <vist/logger.hpp>
 
 namespace osquery {
 namespace tables {
index a83170189d182b3f4d7e53427c22e724d7851eae..00d7a35a7af8f9e9291c3820d9095888c84dfb2d 100644 (file)
@@ -21,8 +21,8 @@
 #include <osquery/sql.h>
 #include <osquery/tables.h>
 
-#include <vist/policy/api.h>
-#include <vist/common/audit/logger.h>
+#include <vist/policy/api.hpp>
+#include <vist/logger.hpp>
 
 namespace {
 
diff --git a/src/osquery/tables/tizen/tests/policy.cpp b/src/osquery/tables/tizen/tests/policy.cpp
new file mode 100644 (file)
index 0000000..983b693
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ *  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/policy/api.hpp>
+
+using namespace vist;
+
+class PolicyTests : public testing::Test {};
+
+TEST_F(PolicyTests, get_all) {
+       auto policies = policy::API::GetAll();
+
+       EXPECT_TRUE(policies.size() > 0);
+}
+
+TEST_F(PolicyTests, get_admin_all) {
+       auto admins = policy::API::Admin::GetAll();
+       EXPECT_EQ(admins.size(), 0);
+
+       policy::API::Admin::Enroll("testAdmin");
+       admins = policy::API::Admin::GetAll();
+       EXPECT_EQ(admins.size(), 1);
+
+       policy::API::Admin::Enroll("testAdmin1");
+       admins = policy::API::Admin::GetAll();
+       EXPECT_EQ(admins.size(), 2);
+
+       policy::API::Admin::Disenroll("testAdmin");
+       admins = policy::API::Admin::GetAll();
+       EXPECT_EQ(admins.size(), 1);
+
+       policy::API::Admin::Disenroll("testAdmin1");
+       admins = policy::API::Admin::GetAll();
+       EXPECT_EQ(admins.size(), 0);
+}
diff --git a/src/osquery/tables/tizen/tests/policy_tests.cpp b/src/osquery/tables/tizen/tests/policy_tests.cpp
deleted file mode 100644 (file)
index e7cb5b2..0000000
+++ /dev/null
@@ -1,50 +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/policy/api.h>
-
-using namespace vist;
-
-class PolicyTests : public testing::Test {};
-
-TEST_F(PolicyTests, get_all) {
-       auto policies = policy::API::GetAll();
-
-       EXPECT_TRUE(policies.size() > 0);
-}
-
-TEST_F(PolicyTests, get_admin_all) {
-       auto admins = policy::API::Admin::GetAll();
-       EXPECT_EQ(admins.size(), 0);
-
-       policy::API::Admin::Enroll("testAdmin");
-       admins = policy::API::Admin::GetAll();
-       EXPECT_EQ(admins.size(), 1);
-
-       policy::API::Admin::Enroll("testAdmin1");
-       admins = policy::API::Admin::GetAll();
-       EXPECT_EQ(admins.size(), 2);
-
-       policy::API::Admin::Disenroll("testAdmin");
-       admins = policy::API::Admin::GetAll();
-       EXPECT_EQ(admins.size(), 1);
-
-       policy::API::Admin::Disenroll("testAdmin1");
-       admins = policy::API::Admin::GetAll();
-       EXPECT_EQ(admins.size(), 0);
-}
index 73f9be14284fb905e22ad23aa72663e965380580..4d7cf181f5fee9fcdfb1856f632409f974befa0c 100644 (file)
@@ -29,7 +29,6 @@ ADD_DEFINITIONS(-DDB_PATH="${DB_INSTALL_DIR}/.vist.db"
                                -DSCRIPT_INSTALL_DIR="${SCRIPT_INSTALL_DIR}")
 
 ADD_SUBDIRECTORY(client)
-ADD_SUBDIRECTORY(common)
 ADD_SUBDIRECTORY(notification)
 ADD_SUBDIRECTORY(policy)
 ADD_SUBDIRECTORY(service)
@@ -54,6 +53,9 @@ INSTALL(TARGETS ${TARGET_VIST_DAEMON}
                                        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}
index 81124a1fa0ca967ca407de54795772c2fbf5ee65..29fb8fdcb82e0df2c9f55bbed93eea5d9d33bf6d 100644 (file)
  *  limitations under the License
  */
 
-#include "query.h"
+#include "query.hpp"
 
-#include <vist/common/ipc/client.h>
-#include <vist/common/audit/logger.h>
+#include <vist/logger.hpp>
+#include <vist/ipc/client.hpp>
 
 namespace {
        const std::string SOCK_ADDR = "/tmp/.vist";
diff --git a/src/vist/client/query.h b/src/vist/client/query.h
deleted file mode 100644 (file)
index ccce173..0000000
+++ /dev/null
@@ -1,32 +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
- */
-
-#pragma once
-
-#include <map>
-#include <string>
-#include <vector>
-
-namespace vist {
-
-using Row = std::map<std::string, std::string>;
-using Rows = std::vector<Row>;
-
-struct Query final {
-       static Rows Execute(const std::string& statement);
-};
-
-} // namespace vist
diff --git a/src/vist/client/query.hpp b/src/vist/client/query.hpp
new file mode 100644 (file)
index 0000000..ccce173
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <map>
+#include <string>
+#include <vector>
+
+namespace vist {
+
+using Row = std::map<std::string, std::string>;
+using Rows = std::vector<Row>;
+
+struct Query final {
+       static Rows Execute(const std::string& statement);
+};
+
+} // namespace vist
diff --git a/src/vist/client/schema/policy.h b/src/vist/client/schema/policy.h
deleted file mode 100644 (file)
index 17d4a3e..0000000
+++ /dev/null
@@ -1,37 +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
- */
-
-
-/**
- * @file processes.h
- * @brief The scheme of policy
- */
-
-
-#pragma once
-
-#include <string>
-
-namespace vist {
-namespace schema {
-
-struct Policy {
-       std::string     name;
-       std::string value;
-};
-
-} // namesapce schema
-} // namesapce vist
diff --git a/src/vist/client/schema/policy.hpp b/src/vist/client/schema/policy.hpp
new file mode 100644 (file)
index 0000000..2d33fc4
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <string>
+
+namespace vist {
+namespace schema {
+
+struct Policy {
+       std::string     name;
+       std::string value;
+};
+
+} // namesapce schema
+} // namesapce vist
diff --git a/src/vist/client/schema/processes.h b/src/vist/client/schema/processes.h
deleted file mode 100644 (file)
index 9e9325c..0000000
+++ /dev/null
@@ -1,46 +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
- */
-
-
-/**
- * @file processes.h
- * @brief The scheme of processes (sync with osquery/tables/spec/x/processes.table)
- */
-
-
-#pragma once
-
-#include <string>
-
-namespace vist {
-namespace schema {
-
-struct Processes {
-       long long int pid;
-       std::string name;
-       std::string path;
-       std::string cmdline;
-       long long int uid;
-       long long int gid;
-       long long int euid;
-       long long int egid;
-       int on_disk;
-       long long int resident_size;
-       long long int parent;
-};
-
-} // namesapce schema
-} // namesapce vist
diff --git a/src/vist/client/schema/processes.hpp b/src/vist/client/schema/processes.hpp
new file mode 100644 (file)
index 0000000..764cd2d
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <string>
+
+namespace vist {
+namespace schema {
+
+struct Processes {
+       long long int pid;
+       std::string name;
+       std::string path;
+       std::string cmdline;
+       long long int uid;
+       long long int gid;
+       long long int euid;
+       long long int egid;
+       int on_disk;
+       long long int resident_size;
+       long long int parent;
+};
+
+} // namesapce schema
+} // namesapce vist
diff --git a/src/vist/client/schema/time.h b/src/vist/client/schema/time.h
deleted file mode 100644 (file)
index 02258df..0000000
+++ /dev/null
@@ -1,36 +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
- */
-
-
-/**
- * @file time.h
- * @brief The scheme of time (sync with osquery/tables/spec/time.table)
- */
-
-
-#pragma once
-
-namespace vist {
-namespace schema {
-
-struct Time {
-       int hour;
-       int minutes;
-       int seconds;
-};
-
-} // namesapce schema
-} // namesapce vist
diff --git a/src/vist/client/schema/time.hpp b/src/vist/client/schema/time.hpp
new file mode 100644 (file)
index 0000000..18a655d
--- /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
+ */
+
+#pragma once
+
+namespace vist {
+namespace schema {
+
+struct Time {
+       int hour;
+       int minutes;
+       int seconds;
+};
+
+} // namesapce schema
+} // namesapce vist
diff --git a/src/vist/client/tests/client-tests.cpp b/src/vist/client/tests/client-tests.cpp
deleted file mode 100644 (file)
index f7bc148..0000000
+++ /dev/null
@@ -1,54 +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 "../query.h" 
-
-#include <chrono>
-#include <thread>
-
-using namespace vist;
-
-class ClientTests : public testing::Test {};
-
-TEST_F(ClientTests, query) {
-       auto rows = Query::Execute("SELECT * FROM policy");
-
-       EXPECT_TRUE(rows.size() > 0);
-}
-
-TEST_F(ClientTests, admin_enrollment) {
-       auto rows = Query::Execute("INSERT INTO policy_admin (name) VALUES ('testAdmin')");
-       EXPECT_EQ(rows.size(), 0);
-
-       rows = Query::Execute("SELECT * FROM policy_admin");
-       EXPECT_EQ(rows.size(), 1);
-
-       Query::Execute("INSERT INTO policy_admin (name) VALUES ('testAdmin2')");
-       rows = Query::Execute("SELECT * FROM policy_admin");
-       EXPECT_EQ(rows.size(), 2);
-
-       rows = Query::Execute("DELETE FROM policy_admin WHERE name = 'testAdmin'");
-       EXPECT_EQ(rows.size(), 0);
-
-       rows = Query::Execute("SELECT * FROM policy_admin");
-       EXPECT_EQ(rows.size(), 1);
-
-       Query::Execute("DELETE FROM policy_admin WHERE name = 'testAdmin2'");
-       rows = Query::Execute("SELECT * FROM policy_admin");
-       EXPECT_EQ(rows.size(), 0);
-}
diff --git a/src/vist/client/tests/client.cpp b/src/vist/client/tests/client.cpp
new file mode 100644 (file)
index 0000000..e45c60b
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *  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/client/query.hpp>
+
+#include <chrono>
+#include <thread>
+
+using namespace vist;
+
+class ClientTests : public testing::Test {};
+
+TEST(ClientTests, query) {
+       auto rows = Query::Execute("SELECT * FROM policy");
+
+       EXPECT_TRUE(rows.size() > 0);
+}
+
+TEST(ClientTests, admin_enrollment) {
+       auto rows = Query::Execute("INSERT INTO policy_admin (name) VALUES ('testAdmin')");
+       EXPECT_EQ(rows.size(), 0);
+
+       rows = Query::Execute("SELECT * FROM policy_admin");
+       EXPECT_EQ(rows.size(), 1);
+
+       Query::Execute("INSERT INTO policy_admin (name) VALUES ('testAdmin2')");
+       rows = Query::Execute("SELECT * FROM policy_admin");
+       EXPECT_EQ(rows.size(), 2);
+
+       rows = Query::Execute("DELETE FROM policy_admin WHERE name = 'testAdmin'");
+       EXPECT_EQ(rows.size(), 0);
+
+       rows = Query::Execute("SELECT * FROM policy_admin");
+       EXPECT_EQ(rows.size(), 1);
+
+       Query::Execute("DELETE FROM policy_admin WHERE name = 'testAdmin2'");
+       rows = Query::Execute("SELECT * FROM policy_admin");
+       EXPECT_EQ(rows.size(), 0);
+}
diff --git a/src/vist/client/tests/virtual-table-tests.cpp b/src/vist/client/tests/virtual-table-tests.cpp
deleted file mode 100644 (file)
index c3aaaec..0000000
+++ /dev/null
@@ -1,119 +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 "../virtual-table.h"
-
-#include "../schema/time.h"
-#include "../schema/policy.h"
-#include "../schema/processes.h"
-
-#include <vist/common/audit/logger.h>
-
-using namespace vist;
-using namespace vist::schema;
-
-class VirtualTableTests : public testing::Test {};
-
-TEST_F(VirtualTableTests, time_row_at) {
-       Time result = { -1, -1, -1 };
-
-       VirtualRow<Time> time;
-       result.hour = time.at(&Time::hour);
-       result.minutes = time.at(&Time::minutes);
-       result.seconds = time.at(&Time::seconds);
-
-       /// Once query execution
-       INFO(VIST_CLIENT, "[Test] time table:");
-       INFO(VIST_CLIENT, "\t hour: " << result.hour);
-       INFO(VIST_CLIENT, "\t minutes: " << result.minutes);
-       INFO(VIST_CLIENT, "\t seconds: " << result.seconds);
-
-       /// Each query execution
-       INFO(VIST_CLIENT, "[Test] time table:");
-       INFO(VIST_CLIENT, "\t hour: " << VirtualRow<Time>().at(&Time::hour));
-       INFO(VIST_CLIENT, "\t minutes: " << VirtualRow<Time>().at(&Time::minutes));
-       INFO(VIST_CLIENT, "\t seconds: " <<  VirtualRow<Time>().at(&Time::seconds));
-
-       EXPECT_NE(result.hour, -1);
-       EXPECT_NE(result.minutes, -1);
-       EXPECT_NE(result.seconds, -1);
-}
-
-TEST_F(VirtualTableTests, time_row_arry_op) {
-       Time result = { -1, -1, -1 };
-
-       VirtualRow<Time> time;
-       result.hour = time[&Time::hour];
-       result.minutes = time[&Time::minutes];
-       result.seconds = time[&Time::seconds];
-
-       /// Once query execution
-       INFO(VIST_CLIENT, "[Test] time table:");
-       INFO(VIST_CLIENT, "\t hour: " << result.hour);
-       INFO(VIST_CLIENT, "\t minutes: " << result.minutes);
-       INFO(VIST_CLIENT, "\t seconds: " << result.seconds);
-
-       EXPECT_NE(result.hour, -1);
-       EXPECT_NE(result.minutes, -1);
-       EXPECT_NE(result.seconds, -1);
-}
-
-TEST_F(VirtualTableTests, processes_table) {
-       Processes result;
-       VirtualTable<Processes> processes;
-       EXPECT_TRUE(processes.size() > 0);
-
-       for(auto& p : processes) {
-               EXPECT_TRUE(p.size() > 0);
-               result.pid = p.at(&Processes::pid);
-               result.name = p.at(&Processes::name);
-               result.path = p.at(&Processes::path);
-               result.cmdline = p.at(&Processes::cmdline);
-               result.uid = p.at(&Processes::uid);
-               result.gid = p.at(&Processes::gid);
-               result.euid = p.at(&Processes::euid);
-               result.egid = p.at(&Processes::egid);
-               result.on_disk = p.at(&Processes::on_disk);
-               result.parent = p.at(&Processes::parent);
-
-               INFO(VIST_CLIENT, "[Test] Processes table:");
-               INFO(VIST_CLIENT, "\t pid: " << result.pid);
-               INFO(VIST_CLIENT, "\t name: " << result.name);
-               INFO(VIST_CLIENT, "\t path: " << result.path);
-               INFO(VIST_CLIENT, "\t cmdline: " << result.cmdline);
-               INFO(VIST_CLIENT, "\t uid: " << result.uid);
-               INFO(VIST_CLIENT, "\t gid: " << result.gid);
-               INFO(VIST_CLIENT, "\t euid: " << result.euid);
-               INFO(VIST_CLIENT, "\t egid: " << result.egid);
-               INFO(VIST_CLIENT, "\t on_disk: " << result.on_disk);
-               INFO(VIST_CLIENT, "\t parent: " << result.parent);
-       }
-}
-
-TEST_F(VirtualTableTests, policy_table) {
-       VirtualTable<Policy> table;
-       EXPECT_TRUE(table.size() > 0);
-
-       for(const auto& row : table) {
-               Policy policy = { row[&Policy::name], row[&Policy::value] };
-
-               INFO(VIST_CLIENT, "[Test] Policy table:");
-               INFO(VIST_CLIENT, "\t name: " << policy.name);
-               INFO(VIST_CLIENT, "\t value: " << policy.value);
-       }
-}
diff --git a/src/vist/client/tests/virtual-table.cpp b/src/vist/client/tests/virtual-table.cpp
new file mode 100644 (file)
index 0000000..3d3133f
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ *  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/client/virtual-table.hpp>
+
+#include <vist/client/schema/policy.hpp>
+#include <vist/client/schema/processes.hpp>
+#include <vist/client/schema/time.hpp>
+
+#include <vist/logger.hpp>
+
+using namespace vist;
+using namespace vist::schema;
+
+class VirtualTableTests : public testing::Test {};
+
+TEST(VirtualTableTests, time_row_at) {
+       Time result = { -1, -1, -1 };
+
+       VirtualRow<Time> time;
+       result.hour = time.at(&Time::hour);
+       result.minutes = time.at(&Time::minutes);
+       result.seconds = time.at(&Time::seconds);
+
+       /// Once query execution
+       INFO(VIST_CLIENT, "[Test] time table:");
+       INFO(VIST_CLIENT, "\t hour: " << result.hour);
+       INFO(VIST_CLIENT, "\t minutes: " << result.minutes);
+       INFO(VIST_CLIENT, "\t seconds: " << result.seconds);
+
+       /// Each query execution
+       INFO(VIST_CLIENT, "[Test] time table:");
+       INFO(VIST_CLIENT, "\t hour: " << VirtualRow<Time>().at(&Time::hour));
+       INFO(VIST_CLIENT, "\t minutes: " << VirtualRow<Time>().at(&Time::minutes));
+       INFO(VIST_CLIENT, "\t seconds: " <<  VirtualRow<Time>().at(&Time::seconds));
+
+       EXPECT_NE(result.hour, -1);
+       EXPECT_NE(result.minutes, -1);
+       EXPECT_NE(result.seconds, -1);
+}
+
+TEST(VirtualTableTests, time_row_arry_op) {
+       Time result = { -1, -1, -1 };
+
+       VirtualRow<Time> time;
+       result.hour = time[&Time::hour];
+       result.minutes = time[&Time::minutes];
+       result.seconds = time[&Time::seconds];
+
+       /// Once query execution
+       INFO(VIST_CLIENT, "[Test] time table:");
+       INFO(VIST_CLIENT, "\t hour: " << result.hour);
+       INFO(VIST_CLIENT, "\t minutes: " << result.minutes);
+       INFO(VIST_CLIENT, "\t seconds: " << result.seconds);
+
+       EXPECT_NE(result.hour, -1);
+       EXPECT_NE(result.minutes, -1);
+       EXPECT_NE(result.seconds, -1);
+}
+
+TEST(VirtualTableTests, processes_table) {
+       Processes result;
+       VirtualTable<Processes> processes;
+       EXPECT_TRUE(processes.size() > 0);
+
+       for(auto& p : processes) {
+               EXPECT_TRUE(p.size() > 0);
+               result.pid = p.at(&Processes::pid);
+               result.name = p.at(&Processes::name);
+               result.path = p.at(&Processes::path);
+               result.cmdline = p.at(&Processes::cmdline);
+               result.uid = p.at(&Processes::uid);
+               result.gid = p.at(&Processes::gid);
+               result.euid = p.at(&Processes::euid);
+               result.egid = p.at(&Processes::egid);
+               result.on_disk = p.at(&Processes::on_disk);
+               result.parent = p.at(&Processes::parent);
+
+               INFO(VIST_CLIENT, "[Test] Processes table:");
+               INFO(VIST_CLIENT, "\t pid: " << result.pid);
+               INFO(VIST_CLIENT, "\t name: " << result.name);
+               INFO(VIST_CLIENT, "\t path: " << result.path);
+               INFO(VIST_CLIENT, "\t cmdline: " << result.cmdline);
+               INFO(VIST_CLIENT, "\t uid: " << result.uid);
+               INFO(VIST_CLIENT, "\t gid: " << result.gid);
+               INFO(VIST_CLIENT, "\t euid: " << result.euid);
+               INFO(VIST_CLIENT, "\t egid: " << result.egid);
+               INFO(VIST_CLIENT, "\t on_disk: " << result.on_disk);
+               INFO(VIST_CLIENT, "\t parent: " << result.parent);
+       }
+}
+
+TEST(VirtualTableTests, policy_table) {
+       VirtualTable<Policy> table;
+       EXPECT_TRUE(table.size() > 0);
+
+       for(const auto& row : table) {
+               Policy policy = { row[&Policy::name], row[&Policy::value] };
+
+               INFO(VIST_CLIENT, "[Test] Policy table:");
+               INFO(VIST_CLIENT, "\t name: " << policy.name);
+               INFO(VIST_CLIENT, "\t value: " << policy.value);
+       }
+}
index 2e6f372694a55ea3c70d7dfa14a609e16e60a410..2b359e589958d922b695a306db7a3ce3a803a523 100644 (file)
  *  See the License for the specific language governing permissions and
  *  limitations under the License
  */
-/*
- * @file virtual-table.cpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Implementation of virtual object
- */
-
-#include "virtual-table.h"
-#include "query.h" 
 
-#include "schema/time.h"
-#include "schema/policy.h"
-#include "schema/processes.h"
+#include "virtual-table.hpp"
 
-#include <vist/common/audit/logger.h>
+#include <vist/client/query.hpp>
+#include <vist/client/schema/policy.hpp>
+#include <vist/client/schema/processes.hpp>
+#include <vist/client/schema/time.hpp>
 
-#include <tsqb.hxx>
+#include <vist/logger.hpp>
+#include <vist/query-builder.hpp>
 
 #include <boost/lexical_cast.hpp>
 
 namespace {
 
-using namespace tsqb;
+using namespace vist::tsqb;
 using namespace vist::schema;
 
 auto time = make_table("time",
diff --git a/src/vist/client/virtual-table.h b/src/vist/client/virtual-table.h
deleted file mode 100644 (file)
index e6da834..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
- */
-
-#pragma once
-
-#include <map>
-#include <stdexcept>
-#include <string>
-#include <vector>
-
-namespace vist {
-
-template <typename T>
-class VirtualRow final {
-public:
-       using KeyValuePair = std::map<std::string, std::string>;
-
-       explicit VirtualRow();
-       explicit VirtualRow(KeyValuePair&&);
-
-       template<typename Struct, typename Member>
-       Member at(Member Struct::*) const;
-
-       template<typename Struct, typename Member>
-       Member operator[](Member Struct::*) const;
-
-       inline std::size_t size() const { return data.size(); }
-
-private:
-       KeyValuePair data;
-};
-
-
-template <typename T>
-class VirtualTable final {
-public:
-       explicit VirtualTable();
-
-       /// Make iteratable
-       using Iter = typename std::vector<VirtualRow<T>>::iterator;
-       using CIter = typename std::vector<VirtualRow<T>>::const_iterator;
-
-       inline Iter begin() { return dataset.begin(); }
-       inline CIter begin() const { return dataset.cbegin(); }
-       inline Iter end() { return dataset.end(); }
-       inline CIter end() const { return dataset.end(); }
-
-       inline std::size_t size() const { return dataset.size(); }
-
-private:
-       std::vector<VirtualRow<T>> dataset;
-};
-
-} // namespace vist
diff --git a/src/vist/client/virtual-table.hpp b/src/vist/client/virtual-table.hpp
new file mode 100644 (file)
index 0000000..e6da834
--- /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
+ */
+
+#pragma once
+
+#include <map>
+#include <stdexcept>
+#include <string>
+#include <vector>
+
+namespace vist {
+
+template <typename T>
+class VirtualRow final {
+public:
+       using KeyValuePair = std::map<std::string, std::string>;
+
+       explicit VirtualRow();
+       explicit VirtualRow(KeyValuePair&&);
+
+       template<typename Struct, typename Member>
+       Member at(Member Struct::*) const;
+
+       template<typename Struct, typename Member>
+       Member operator[](Member Struct::*) const;
+
+       inline std::size_t size() const { return data.size(); }
+
+private:
+       KeyValuePair data;
+};
+
+
+template <typename T>
+class VirtualTable final {
+public:
+       explicit VirtualTable();
+
+       /// Make iteratable
+       using Iter = typename std::vector<VirtualRow<T>>::iterator;
+       using CIter = typename std::vector<VirtualRow<T>>::const_iterator;
+
+       inline Iter begin() { return dataset.begin(); }
+       inline CIter begin() const { return dataset.cbegin(); }
+       inline Iter end() { return dataset.end(); }
+       inline CIter end() const { return dataset.end(); }
+
+       inline std::size_t size() const { return dataset.size(); }
+
+private:
+       std::vector<VirtualRow<T>> dataset;
+};
+
+} // namespace vist
diff --git a/src/vist/common/CMakeLists.txt b/src/vist/common/CMakeLists.txt
deleted file mode 100644 (file)
index 04eeb46..0000000
+++ /dev/null
@@ -1,16 +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
-
-FILE(GLOB COMMON_TESTS "tests/*.cpp")
-ADD_VIST_TEST(${COMMON_TESTS})
diff --git a/src/vist/common/audit/logger.h b/src/vist/common/audit/logger.h
deleted file mode 100644 (file)
index a4bf3ed..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *  Copyright (c) 2017 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
- */
-
-#pragma once
-
-#include <klay/audit/logger.h>
-#include <klay/audit/dlog-sink.h>
-
-#include <memory>
-
-#define VIST vist::Logger::Instance()
-#define VIST_CLIENT vist::Logger::ClientInstance()
-
-namespace vist {
-
-class Logger final {
-public:
-       Logger(const Logger&) = delete;
-       Logger& operator=(const Logger&) = delete;
-
-       Logger(Logger&&) = default;
-       Logger& operator=(Logger&&) = default;
-
-       static klay::LogSink* Instance()
-       {
-               static Logger instance("VIST");
-               return &instance.logSink;
-       }
-
-       static klay::LogSink* ClientInstance()
-       {
-               static Logger instance("VIST_CLIENT");
-               return &instance.logSink;
-       }
-
-private:
-       explicit Logger(const std::string& tag) : logSink(tag) {}
-       ~Logger() = default;
-
-       klay::DlogLogSink logSink;
-};
-
-} // namespace vist
diff --git a/src/vist/common/exception.h b/src/vist/common/exception.h
deleted file mode 100644 (file)
index 8236026..0000000
+++ /dev/null
@@ -1,94 +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
- */
-/*
- * @file   exception.h
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief  Enum based exception handling
- * @usage
- *  enum class ErrCode {
- *    LogicError = 1,
- *    RuntimeError
- *  };
- *
- *  try {
- *    THROW(ErrCode::LogicError) << "Additional information about exception";
- *  } catch (const vist::Exception<ErrCode>& e) {
- *    ErrCode ec = e.get();
- *    std::string message = e.what();
- *  }
- */
-
-#pragma once
-
-#include <cstring>
-#include <exception>
-#include <sstream>
-#include <string>
-#include <type_traits>
-#include <typeinfo>
-
-#include <boost/core/demangle.hpp>
-
-#ifndef __FILENAME__
-#define __FILENAME__ \
-       ::strrchr(__FILE__, '/') ? ::strrchr(__FILE__, '/') + 1 : __FILE__
-#endif
-
-#define THROW(ec) \
-       throw vist::Exception<decltype(ec)>(ec,__FILENAME__,__FUNCTION__,__LINE__)
-
-namespace vist {
-
-template <typename ErrCode>
-class Exception final : public std::exception {
-public:
-       static_assert(std::is_enum<ErrCode>::value, "Error code must be enum type.");
-
-       using Self = Exception<ErrCode>;
-
-       Exception(ErrCode ec, const char *file,
-                         const char *function, unsigned int line) noexcept : ec(ec)
-       {
-               std::stringstream ss;
-               ss << "[" << file << ":" << line << " " << function << "()]"
-                  << "[" << boost::core::demangle(typeid(ec).name())
-                  << "(" << static_cast<typename std::underlying_type_t<ErrCode>>(ec) << ")]";
-               message = ss.str();
-       }
-
-       virtual const char* what() const noexcept override
-       {
-               return message.c_str();
-       }
-
-       inline ErrCode get() const noexcept
-       {
-               return ec;
-       }
-
-       template<typename T>
-       Self& operator<<(const T& arg) noexcept
-       {
-               message += (static_cast<std::stringstream&>(std::stringstream() << arg)).str();
-               return *this;
-       }
-
-private:
-       ErrCode ec;
-       std::string message;
-};
-
-} // namespace vist
diff --git a/src/vist/common/ipc/client.h b/src/vist/common/ipc/client.h
deleted file mode 100644 (file)
index 5e39a57..0000000
+++ /dev/null
@@ -1,53 +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
- */
-
-#pragma once
-
-#include <string>
-#include <memory>
-
-#include <klay/rmi/client.h>
-
-namespace vist {
-namespace ipc {
-
-class Client final {
-public:
-       Client(const Client&) = delete;
-       Client& operator=(const Client&) = delete;
-
-       Client(Client&&) = delete;
-       Client& operator=(Client&&) = delete;
-
-       static std::unique_ptr<klay::rmi::Client>& Instance(const std::string& sock)
-       {
-               static Client client(sock);
-               return client.instance;
-       }
-
-private:
-       explicit Client(const std::string& sock) :
-               instance(std::make_unique<klay::rmi::Client>(sock))
-       {
-               instance->connect();
-       }
-       ~Client() = default;
-
-       std::unique_ptr<klay::rmi::Client> instance;
-};
-
-} // namespace ipc
-} // namespace vist
diff --git a/src/vist/common/ipc/server.h b/src/vist/common/ipc/server.h
deleted file mode 100644 (file)
index 667d6b1..0000000
+++ /dev/null
@@ -1,50 +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
- */
-
-#pragma once
-
-#include <string>
-#include <memory>
-
-#include <klay/rmi/service.h>
-
-namespace vist {
-namespace ipc {
-
-class Server final {
-public:
-       Server(const Server&) = delete;
-       Server& operator=(const Server&) = delete;
-
-       Server(Server&&) = delete;
-       Server& operator=(Server&&) = delete;
-
-       static std::unique_ptr<klay::rmi::Service>& Instance(const std::string& sock)
-       {
-               static Server server(sock);
-               return server.instance;
-       }
-
-private:
-       explicit Server(const std::string& sock) :
-               instance(std::make_unique<klay::rmi::Service>(sock)) {}
-       ~Server() = default;
-
-       std::unique_ptr<klay::rmi::Service> instance;
-};
-
-} // namespace ipc
-} // namespace vist
diff --git a/src/vist/common/ipc/tests/ipc_tests.cpp b/src/vist/common/ipc/tests/ipc_tests.cpp
deleted file mode 100644 (file)
index 94c082a..0000000
+++ /dev/null
@@ -1,83 +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 "ipc/server.h"
-#include "ipc/client.h"
-
-#include <chrono>
-#include <thread>
-
-#include <sys/types.h>
-#include <unistd.h>
-
-using namespace vist;
-
-namespace {
-       std::string g_socket = "/tmp/vist-test";
-} // anonymous namespace
-
-class TestServer {
-public:
-       void init()
-       {
-               auto& server = ipc::Server::Instance(g_socket);
-               server->expose(this, "", (std::string)(TestServer::testMethod)());
-               server->start();
-       }
-
-       std::string testMethod()
-       {
-               return "test";
-       }
-};
-
-class IpcTests : public testing::Test {
-public:
-       void SetUp() override
-       {
-               ::unlink(g_socket.c_str());
-
-               this->pid = fork();
-               if (pid < 0) {
-                       return;
-               } else if (pid == 0) {
-                       TestServer server;
-                       server.init();
-               }
-
-               std::this_thread::sleep_for(std::chrono::seconds(1));
-       }
-
-       void TearDown() override
-       {
-               if (::kill(pid, SIGTERM) == -1)
-                       return;
-
-               std::this_thread::sleep_for(std::chrono::seconds(1));
-       }
-
-private:
-       pid_t pid = -1;
-};
-
-TEST_F(IpcTests, method_call) {
-       auto& client = ipc::Client::Instance(g_socket);
-
-       std::string ret = client->methodCall<std::string>("TestServer::testMethod");
-       EXPECT_EQ(ret, "test");
-}
diff --git a/src/vist/common/tests/exception.cpp b/src/vist/common/tests/exception.cpp
deleted file mode 100644 (file)
index 9dd4f5e..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 "../exception.h"
-
-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) << msg;
-       EXPECT_EQ(ec, ErrCode::RuntimeError);
-       EXPECT_NE(std::string::npos, msg.find("Additional"));
-}
diff --git a/src/vist/exception.hpp b/src/vist/exception.hpp
new file mode 100644 (file)
index 0000000..ba848fe
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ *  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
+ */
+/*
+ * @usage
+ *  enum class ErrCode {
+ *    LogicError = 1,
+ *    RuntimeError
+ *  };
+ *
+ *  try {
+ *    THROW(ErrCode::LogicError) << "Additional information about exception";
+ *  } catch (const vist::Exception<ErrCode>& e) {
+ *    ErrCode ec = e.get();
+ *    std::string message = e.what();
+ *  }
+ */
+
+#pragma once
+
+#include <cstring>
+#include <exception>
+#include <sstream>
+#include <string>
+#include <type_traits>
+#include <typeinfo>
+
+#include <boost/core/demangle.hpp>
+
+#ifndef __FILENAME__
+#define __FILENAME__ \
+       ::strrchr(__FILE__, '/') ? ::strrchr(__FILE__, '/') + 1 : __FILE__
+#endif
+
+#define THROW(ec) \
+       throw vist::Exception<decltype(ec)>(ec,__FILENAME__,__FUNCTION__,__LINE__)
+
+namespace vist {
+
+template <typename ErrCode>
+class Exception final : public std::exception {
+public:
+       static_assert(std::is_enum<ErrCode>::value, "Error code must be enum type.");
+
+       using Self = Exception<ErrCode>;
+
+       Exception(ErrCode ec, const char *file,
+                         const char *function, unsigned int line) noexcept : ec(ec)
+       {
+               std::stringstream ss;
+               ss << "[" << file << ":" << line << " " << function << "()]"
+                  << "[" << boost::core::demangle(typeid(ec).name())
+                  << "(" << static_cast<typename std::underlying_type_t<ErrCode>>(ec) << ")]";
+               message = ss.str();
+       }
+
+       virtual const char* what() const noexcept override
+       {
+               return message.c_str();
+       }
+
+       inline ErrCode get() const noexcept
+       {
+               return ec;
+       }
+
+       template<typename T>
+       Self& operator<<(const T& arg) noexcept
+       {
+               message += (static_cast<std::stringstream&>(std::stringstream() << arg)).str();
+               return *this;
+       }
+
+private:
+       ErrCode ec;
+       std::string message;
+};
+
+} // namespace vist
diff --git a/src/vist/ipc/client.hpp b/src/vist/ipc/client.hpp
new file mode 100644 (file)
index 0000000..5e39a57
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+
+#include <klay/rmi/client.h>
+
+namespace vist {
+namespace ipc {
+
+class Client final {
+public:
+       Client(const Client&) = delete;
+       Client& operator=(const Client&) = delete;
+
+       Client(Client&&) = delete;
+       Client& operator=(Client&&) = delete;
+
+       static std::unique_ptr<klay::rmi::Client>& Instance(const std::string& sock)
+       {
+               static Client client(sock);
+               return client.instance;
+       }
+
+private:
+       explicit Client(const std::string& sock) :
+               instance(std::make_unique<klay::rmi::Client>(sock))
+       {
+               instance->connect();
+       }
+       ~Client() = default;
+
+       std::unique_ptr<klay::rmi::Client> instance;
+};
+
+} // namespace ipc
+} // namespace vist
diff --git a/src/vist/ipc/server.hpp b/src/vist/ipc/server.hpp
new file mode 100644 (file)
index 0000000..667d6b1
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+
+#include <klay/rmi/service.h>
+
+namespace vist {
+namespace ipc {
+
+class Server final {
+public:
+       Server(const Server&) = delete;
+       Server& operator=(const Server&) = delete;
+
+       Server(Server&&) = delete;
+       Server& operator=(Server&&) = delete;
+
+       static std::unique_ptr<klay::rmi::Service>& Instance(const std::string& sock)
+       {
+               static Server server(sock);
+               return server.instance;
+       }
+
+private:
+       explicit Server(const std::string& sock) :
+               instance(std::make_unique<klay::rmi::Service>(sock)) {}
+       ~Server() = default;
+
+       std::unique_ptr<klay::rmi::Service> instance;
+};
+
+} // namespace ipc
+} // namespace vist
diff --git a/src/vist/ipc/tests/ipc.cpp b/src/vist/ipc/tests/ipc.cpp
new file mode 100644 (file)
index 0000000..1e8c0d2
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ *  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/ipc/client.hpp>
+#include <vist/ipc/server.hpp>
+
+#include <chrono>
+#include <thread>
+
+#include <sys/types.h>
+#include <unistd.h>
+
+using namespace vist;
+
+namespace {
+       std::string g_socket = "/tmp/vist-test";
+} // anonymous namespace
+
+class TestServer {
+public:
+       void init()
+       {
+               auto& server = ipc::Server::Instance(g_socket);
+               server->expose(this, "", (std::string)(TestServer::testMethod)());
+               server->start();
+       }
+
+       std::string testMethod()
+       {
+               return "test";
+       }
+};
+
+class IpcTests : public testing::Test {
+public:
+       void SetUp() override
+       {
+               ::unlink(g_socket.c_str());
+
+               this->pid = fork();
+               if (pid < 0) {
+                       return;
+               } else if (pid == 0) {
+                       TestServer server;
+                       server.init();
+               }
+
+               std::this_thread::sleep_for(std::chrono::seconds(1));
+       }
+
+       void TearDown() override
+       {
+               if (::kill(pid, SIGTERM) == -1)
+                       return;
+
+               std::this_thread::sleep_for(std::chrono::seconds(1));
+       }
+
+private:
+       pid_t pid = -1;
+};
+
+TEST_F(IpcTests, method_call) {
+       auto& client = ipc::Client::Instance(g_socket);
+
+       std::string ret = client->methodCall<std::string>("TestServer::testMethod");
+       EXPECT_EQ(ret, "test");
+}
diff --git a/src/vist/logger.hpp b/src/vist/logger.hpp
new file mode 100644 (file)
index 0000000..592a0ea
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <klay/audit/dlog-sink.h>
+#include <klay/audit/logger.h>
+
+#include <memory>
+
+#define VIST vist::Logger::Instance()
+#define VIST_CLIENT vist::Logger::ClientInstance()
+
+namespace vist {
+
+class Logger final {
+public:
+       Logger(const Logger&) = delete;
+       Logger& operator=(const Logger&) = delete;
+
+       Logger(Logger&&) = default;
+       Logger& operator=(Logger&&) = default;
+
+       static klay::LogSink* Instance()
+       {
+               static Logger instance("VIST");
+               return &instance.logSink;
+       }
+
+       static klay::LogSink* ClientInstance()
+       {
+               static Logger instance("VIST_CLIENT");
+               return &instance.logSink;
+       }
+
+private:
+       explicit Logger(const std::string& tag) : logSink(tag) {}
+       ~Logger() = default;
+
+       klay::DlogLogSink logSink;
+};
+
+} // namespace vist
index 64e1c0eecaad69191526a898565b46e4f823ea29..eec9680f7e8545b2f11f2a22bdef60573faebb72 100644 (file)
  *  limitations under the License
  */
 
-#include "service/vist.h"
+#include <vist/service/vist.hpp>
 
 #include <cstdlib>
 #include <stdexcept>
 
 using namespace vist;
 
-int main() try
-{
+int main() try {
        Vist::Instance().start();
        return EXIT_SUCCESS;
-} catch(const std::exception&)
-{
+} catch(const std::exception&) {
        return EXIT_FAILURE;
 }
index e249cbe39dee2873a47c9053c2c81973b2717194..0fcfc89712d9c77fa53ec4ca8c11cd01b573e51d 100644 (file)
@@ -1,6 +1,22 @@
+/*
+ *  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>
 
 int main(int argc, char* argv[]) {
-  testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
+       testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
 }
index f30285df89b470567e01c11bba76028b64c83bd0..06e945ed7f83ddb3a4969f3160d14d7e80454398 100644 (file)
  *  See the License for the specific language governing permissions and
  *  limitations under the License
  */
-/*
- * @file notification.cpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Implementation of notification
- */
 
-#include "notification.h"
+#include "notification.hpp"
 
 #include <mutex>
 
diff --git a/src/vist/notification/notification.h b/src/vist/notification/notification.h
deleted file mode 100644 (file)
index 56a5962..0000000
+++ /dev/null
@@ -1,57 +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
- */
-
-
-/**
- * @file notification.h
- * @brief Notify to registered stuffs when event-callback called
- */
-
-
-#pragma once
-
-#include <map>
-#include <vector>
-
-#include <osquery/status.h>
-
-namespace vist {
-
-using Row = std::map<std::string, std::string>;
-using Rows = std::vector<Row>;
-
-using Callback = std::function<void(const Row&)>;
-
-using NotifyCallback = Callback;
-
-class Notification final {
-public:
-       static Notification& instance();
-
-       Notification(const Notification&) = delete;
-       Notification& operator=(const Notification&) = delete;
-
-       osquery::Status add(const std::string& table, const NotifyCallback& callback);
-       osquery::Status emit(const std::string& table, const Row& result) const;
-
-private:
-       Notification() = default;
-       ~Notification() = default;
-
-       std::multimap<std::string, NotifyCallback> callbacks;
-};
-
-} // namespace vist
diff --git a/src/vist/notification/notification.hpp b/src/vist/notification/notification.hpp
new file mode 100644 (file)
index 0000000..5d47321
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <map>
+#include <vector>
+
+#include <osquery/status.h>
+
+namespace vist {
+
+using Row = std::map<std::string, std::string>;
+using Rows = std::vector<Row>;
+
+using Callback = std::function<void(const Row&)>;
+
+using NotifyCallback = Callback;
+
+class Notification final {
+public:
+       static Notification& instance();
+
+       Notification(const Notification&) = delete;
+       Notification& operator=(const Notification&) = delete;
+
+       osquery::Status add(const std::string& table, const NotifyCallback& callback);
+       osquery::Status emit(const std::string& table, const Row& result) const;
+
+private:
+       Notification() = default;
+       ~Notification() = default;
+
+       std::multimap<std::string, NotifyCallback> callbacks;
+};
+
+} // namespace vist
diff --git a/src/vist/notification/tests/notification-tests.cpp b/src/vist/notification/tests/notification-tests.cpp
deleted file mode 100644 (file)
index d01af91..0000000
+++ /dev/null
@@ -1,72 +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 "../notification.h"
-#include <osquery/logger.h>
-
-using namespace vist;
-
-class NotificationTests : public testing::Test {};
-
-TEST_F(NotificationTests, test_add_positive) {
-       auto& notifier = Notification::instance();
-
-       auto callback = [](const Row& row) {
-               LOG(INFO) << "NotifyCallback called:";
-               for (const auto& r : row)
-                       LOG(INFO) << "\t" << r.first << " : " << r.second;
-       };
-
-       auto s = notifier.add("test", std::move(callback));
-       EXPECT_TRUE(s.ok());
-}
-
-TEST_F(NotificationTests, test_add_negative) {
-       auto& notifier = Notification::instance();
-
-       auto callback = [](const Row& row) {
-               LOG(INFO) << "NotifyCallback called:";
-               for (const auto& r : row)
-                       LOG(INFO) << "\t" << r.first << " : " << r.second;
-       };
-
-       auto s = notifier.add("", std::move(callback));
-       EXPECT_FALSE(s.ok());
-}
-
-TEST_F(NotificationTests, test_emit_positive) {
-       auto& notifier = Notification::instance();
-
-       int called = 0;
-       auto callback = [&](const Row& row) {
-               LOG(INFO) << "NotifyCallback called:";
-               for (const auto& r : row)
-                       LOG(INFO) << "\t" << r.first << " : " << r.second;
-               called++;
-       };
-
-       auto s = notifier.add("test2", std::move(callback));
-       EXPECT_TRUE(s.ok());
-
-       Row row;
-       row["foo"] = "bar";
-       s = notifier.emit("test2", row);
-
-       EXPECT_TRUE(s.ok());
-       EXPECT_EQ(called, 1);
-}
diff --git a/src/vist/notification/tests/notification.cpp b/src/vist/notification/tests/notification.cpp
new file mode 100644 (file)
index 0000000..e376b74
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ *  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/notification/notification.hpp>
+
+#include <osquery/logger.h>
+
+using namespace vist;
+
+class NotificationTests : public testing::Test {};
+
+TEST_F(NotificationTests, test_add_positive)
+{
+       auto& notifier = Notification::instance();
+
+       auto callback = [](const Row& row) {
+               LOG(INFO) << "NotifyCallback called:";
+               for (const auto& r : row)
+                       LOG(INFO) << "\t" << r.first << " : " << r.second;
+       };
+
+       auto s = notifier.add("test", std::move(callback));
+       EXPECT_TRUE(s.ok());
+}
+
+TEST_F(NotificationTests, test_add_negative)
+{
+       auto& notifier = Notification::instance();
+
+       auto callback = [](const Row& row) {
+               LOG(INFO) << "NotifyCallback called:";
+               for (const auto& r : row)
+                       LOG(INFO) << "\t" << r.first << " : " << r.second;
+       };
+
+       auto s = notifier.add("", std::move(callback));
+       EXPECT_FALSE(s.ok());
+}
+
+TEST_F(NotificationTests, test_emit_positive)
+{
+       auto& notifier = Notification::instance();
+
+       int called = 0;
+       auto callback = [&](const Row& row) {
+               LOG(INFO) << "NotifyCallback called:";
+               for (const auto& r : row)
+                       LOG(INFO) << "\t" << r.first << " : " << r.second;
+               called++;
+       };
+
+       auto s = notifier.add("test2", std::move(callback));
+       EXPECT_TRUE(s.ok());
+
+       Row row;
+       row["foo"] = "bar";
+       s = notifier.emit("test2", row);
+
+       EXPECT_TRUE(s.ok());
+       EXPECT_EQ(called, 1);
+}
diff --git a/src/vist/policy/api.h b/src/vist/policy/api.h
deleted file mode 100644 (file)
index 6fd3d06..0000000
+++ /dev/null
@@ -1,43 +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
- */
-
-#pragma once
-
-#include <vist/policy/sdk/policy-value.h>
-
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-namespace vist {
-namespace policy {
-
-struct API {
-       static PolicyValue Get(const std::string& policy);
-       static std::unordered_map<std::string, PolicyValue> GetAll();
-
-       struct Admin {
-               static void Set(const std::string& policy, const PolicyValue& value);
-
-               static void Enroll(const std::string& admin);
-               static void Disenroll(const std::string& admin);
-
-               static std::vector<std::string> GetAll();
-       };
-};
-
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/policy/api.hpp b/src/vist/policy/api.hpp
new file mode 100644 (file)
index 0000000..bd8aa91
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <vist/policy/sdk/policy-value.hpp>
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+namespace vist {
+namespace policy {
+
+struct API {
+       static PolicyValue Get(const std::string& policy);
+       static std::unordered_map<std::string, PolicyValue> GetAll();
+
+       struct Admin {
+               static void Set(const std::string& policy, const PolicyValue& value);
+
+               static void Enroll(const std::string& admin);
+               static void Disenroll(const std::string& admin);
+
+               static std::vector<std::string> GetAll();
+       };
+};
+
+} // namespace policy
+} // namespace vist
index 2277cb4720057d697f63fa2219df16dca8598620..0a38eb5213eb530d58c172b34d26463ec8bf65e7 100644 (file)
@@ -14,9 +14,9 @@
  *  limitations under the License
  */
 
-#include <vist/policy/api.h>
+#include <vist/policy/api.hpp>
 
-#include "policy-manager.h"
+#include "policy-manager.hpp"
 
 namespace vist {
 namespace policy {
diff --git a/src/vist/policy/core/db-schema.h b/src/vist/policy/core/db-schema.h
deleted file mode 100644 (file)
index 159dc56..0000000
+++ /dev/null
@@ -1,41 +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
- */
-#pragma once
-
-#include <string>
-
-namespace vist {
-namespace policy {
-namespace schema {
-
-struct Admin {
-       std::string name;
-};
-
-struct PolicyActivated {
-       std::string admin;
-       std::string policy;
-       int value = -1;
-};
-
-struct PolicyDefinition {
-       std::string name;
-       int ivalue = -1;
-};
-
-} // namespace schema
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/policy/core/db-schema.hpp b/src/vist/policy/core/db-schema.hpp
new file mode 100644 (file)
index 0000000..2bdf75b
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <string>
+
+namespace vist {
+namespace policy {
+namespace schema {
+
+struct Admin {
+       std::string name;
+};
+
+struct PolicyActivated {
+       std::string admin;
+       std::string policy;
+       int value = -1;
+};
+
+struct PolicyDefinition {
+       std::string name;
+       int ivalue = -1;
+};
+
+} // namespace schema
+} // namespace policy
+} // namespace vist
index b9350fb895f3fd772c00128c19db826435e99a00..28c3b415e48a3bc1f021ea25dd320be3addef937 100644 (file)
@@ -14,7 +14,7 @@
  *  limitations under the License
  */
 
-#include "policy-loader.h"
+#include "policy-loader.hpp"
 
 namespace vist {
 namespace policy {
diff --git a/src/vist/policy/core/policy-loader.h b/src/vist/policy/core/policy-loader.h
deleted file mode 100644 (file)
index 73dab2d..0000000
+++ /dev/null
@@ -1,55 +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
- */
-
-#pragma once
-
-#include <vist/policy/sdk/policy-provider.h>
-
-#include <stdexcept>
-#include <string>
-#include <memory>
-
-#include <dlfcn.h>
-
-namespace vist {
-namespace policy {
-
-struct PolicyLoader final {
-       static PolicyProvider* load(const std::string& path);
-};
-
-class PluginLoader final {
-public:
-       explicit PluginLoader(const std::string& path, int flag = RTLD_LAZY);
-
-       template<typename T>
-       void load(const std::string& name, T& symbol);
-
-private:
-       using Handle = std::unique_ptr<void, int(*)(void*)>;
-       Handle handle;
-};
-
-template<typename T>
-void PluginLoader::load(const std::string& name, T& symbol)
-{
-       symbol = reinterpret_cast<T>(::dlsym(handle.get(), name.c_str()));
-       if (symbol == nullptr)
-               throw std::runtime_error("Failed to load: " + name);
-}
-
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/policy/core/policy-loader.hpp b/src/vist/policy/core/policy-loader.hpp
new file mode 100644 (file)
index 0000000..b463fd6
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <vist/policy/sdk/policy-provider.hpp>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+
+#include <dlfcn.h>
+
+namespace vist {
+namespace policy {
+
+struct PolicyLoader final {
+       static PolicyProvider* load(const std::string& path);
+};
+
+class PluginLoader final {
+public:
+       explicit PluginLoader(const std::string& path, int flag = RTLD_LAZY);
+
+       template<typename T>
+       void load(const std::string& name, T& symbol);
+
+private:
+       using Handle = std::unique_ptr<void, int(*)(void*)>;
+       Handle handle;
+};
+
+template<typename T>
+void PluginLoader::load(const std::string& name, T& symbol)
+{
+       symbol = reinterpret_cast<T>(::dlsym(handle.get(), name.c_str()));
+       if (symbol == nullptr)
+               throw std::runtime_error("Failed to load: " + name);
+}
+
+} // namespace policy
+} // namespace vist
index 2ec9ab609761e8d03ed65e2fa1d19c582e74d754..d335ab025a9cd267792164a0eb1199d37da43bb1 100644 (file)
  *  limitations under the License
  */
 
-#include "policy-manager.h"
-#include "policy-loader.h"
+#include "policy-manager.hpp"
+#include "policy-loader.hpp"
 
-#include <vist/common/audit/logger.h>
+#include <vist/logger.hpp>
 
 #include <klay/filesystem.h>
 
diff --git a/src/vist/policy/core/policy-manager.h b/src/vist/policy/core/policy-manager.h
deleted file mode 100644 (file)
index 7e81c18..0000000
+++ /dev/null
@@ -1,77 +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
- */
-
-#pragma once
-
-#include <vist/policy/sdk/policy-provider.h>
-#include <vist/policy/sdk/policy-value.h>
-
-#include "policy-storage.h"
-
-#include <exception>
-#include <memory>
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-#include <gtest/gtest_prod.h>
-
-namespace vist {
-namespace policy {
-
-class PolicyManager final {
-public:
-       PolicyManager(const PolicyManager&) = delete;
-       PolicyManager& operator=(const PolicyManager&) = delete;
-
-       PolicyManager(PolicyManager&&) = delete;
-       PolicyManager& operator=(PolicyManager&&) = delete;
-
-       static PolicyManager& Instance()
-       {
-               static PolicyManager manager;
-               return manager;
-       }
-
-       void enroll(const std::string& admin);
-       void disenroll(const std::string& admin);
-
-       void set(const std::string& policy,
-                        const PolicyValue& value,
-                        const std::string& admin);
-       PolicyValue get(const std::string& policy);
-       std::unordered_map<std::string, PolicyValue> getAll();
-
-       std::vector<std::string> getAdmins();
-
-private:
-       explicit PolicyManager();
-       ~PolicyManager() = default;
-
-       std::pair<int, int> loadProviders(const std::string& path);
-       int loadPolicies();
-
-       PolicyStorage storage;
-       std::vector<std::unique_ptr<PolicyProvider>> providers;
-
-       /// Policy-Provider
-       std::unordered_map<std::string, std::string> policies;
-
-       FRIEND_TEST(PolicyCoreTests, policy_loader);
-};
-
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/policy/core/policy-manager.hpp b/src/vist/policy/core/policy-manager.hpp
new file mode 100644 (file)
index 0000000..bdc364b
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <vist/policy/sdk/policy-provider.hpp>
+#include <vist/policy/sdk/policy-value.hpp>
+
+#include "policy-storage.hpp"
+
+#include <exception>
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include <gtest/gtest_prod.h>
+
+namespace vist {
+namespace policy {
+
+class PolicyManager final {
+public:
+       PolicyManager(const PolicyManager&) = delete;
+       PolicyManager& operator=(const PolicyManager&) = delete;
+
+       PolicyManager(PolicyManager&&) = delete;
+       PolicyManager& operator=(PolicyManager&&) = delete;
+
+       static PolicyManager& Instance()
+       {
+               static PolicyManager manager;
+               return manager;
+       }
+
+       void enroll(const std::string& admin);
+       void disenroll(const std::string& admin);
+
+       void set(const std::string& policy,
+                        const PolicyValue& value,
+                        const std::string& admin);
+       PolicyValue get(const std::string& policy);
+       std::unordered_map<std::string, PolicyValue> getAll();
+
+       std::vector<std::string> getAdmins();
+
+private:
+       explicit PolicyManager();
+       ~PolicyManager() = default;
+
+       std::pair<int, int> loadProviders(const std::string& path);
+       int loadPolicies();
+
+       PolicyStorage storage;
+       std::vector<std::unique_ptr<PolicyProvider>> providers;
+
+       /// Policy-Provider
+       std::unordered_map<std::string, std::string> policies;
+
+       FRIEND_TEST(PolicyCoreTests, policy_loader);
+};
+
+} // namespace policy
+} // namespace vist
index 4a1e3412833b593d48d45cd31177e47216612798..9ef1f0a6653103ddf085f7102195aea9a089ad35 100644 (file)
  *  limitations under the License
  */
 
-#include "policy-storage.h"
+#include "policy-storage.hpp"
 
-#include <vist/common/audit/logger.h>
+#include <vist/logger.hpp>
+#include <vist/query-builder.hpp>
 
 #include <klay/db/column.h>
-#include <klay/db/query-builder.h>
 #include <klay/db/statement.h>
 #include <klay/exception.h>
 
-#include <fstream>
 #include <algorithm>
+#include <fstream>
 
-using namespace query_builder;
+using namespace vist::tsqb;
 using namespace vist::policy::schema;
 
 namespace {
diff --git a/src/vist/policy/core/policy-storage.h b/src/vist/policy/core/policy-storage.h
deleted file mode 100644 (file)
index b26df61..0000000
+++ /dev/null
@@ -1,82 +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
- *
- *      ttp://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
- */
-
-#pragma once
-
-#include <vist/policy/sdk/policy-value.h>
-
-#include "db-schema.h"
-
-#include <memory>
-#include <unordered_map>
-#include <vector>
-
-#include <klay/db/connection.h>
-
-namespace vist {
-namespace policy {
-
-using namespace schema;
-
-class PolicyStorage final {
-public:
-       explicit PolicyStorage(const std::string& path);
-
-       /// TODO(Sangwan): Consider to support lazy sync
-       void sync();
-
-       void syncAdmin();
-       void syncPolicyActivated();
-       void syncPolicyDefinition();
-
-       inline bool exists(const std::string& policy) const noexcept
-       {
-               return definitions.find(policy) != definitions.end();
-       }
-
-       inline bool isActivated() const noexcept
-       {
-               return admins.size() > 0 && activatedPolicies.size() > 0;
-       }
-
-       void enroll(const std::string& admin);
-       void disenroll(const std::string& admin);
-
-       void define(const std::string& policy, int ivalue);
-       void update(const std::string& admin,
-                               const std::string& policy,
-                               const PolicyValue& value);
-
-       PolicyValue strictest(const std::string& policy);
-       /// Return all strictest policy values
-       std::unordered_map<std::string, PolicyValue> strictest();
-
-       const std::vector<std::string>& getAdmins() const noexcept;
-
-private:
-       std::string getScript(const std::string& name);
-
-       std::shared_ptr<klay::database::Connection> database;
-
-       /// DB Cache objects
-       /// TODO(Sangwan): add locking mechanism
-       std::vector<std::string> admins;
-       std::unordered_map<std::string, PolicyActivated> activatedPolicies;
-       std::unordered_map<std::string, PolicyDefinition> definitions;
-};
-
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/policy/core/policy-storage.hpp b/src/vist/policy/core/policy-storage.hpp
new file mode 100644 (file)
index 0000000..cec538d
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ *  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
+ *
+ *      ttp://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
+ */
+
+#pragma once
+
+#include <vist/policy/sdk/policy-value.hpp>
+
+#include "db-schema.hpp"
+
+#include <memory>
+#include <unordered_map>
+#include <vector>
+
+#include <klay/db/connection.h>
+
+namespace vist {
+namespace policy {
+
+using namespace schema;
+
+class PolicyStorage final {
+public:
+       explicit PolicyStorage(const std::string& path);
+
+       /// TODO(Sangwan): Consider to support lazy sync
+       void sync();
+
+       void syncAdmin();
+       void syncPolicyActivated();
+       void syncPolicyDefinition();
+
+       inline bool exists(const std::string& policy) const noexcept
+       {
+               return definitions.find(policy) != definitions.end();
+       }
+
+       inline bool isActivated() const noexcept
+       {
+               return admins.size() > 0 && activatedPolicies.size() > 0;
+       }
+
+       void enroll(const std::string& admin);
+       void disenroll(const std::string& admin);
+
+       void define(const std::string& policy, int ivalue);
+       void update(const std::string& admin,
+                               const std::string& policy,
+                               const PolicyValue& value);
+
+       PolicyValue strictest(const std::string& policy);
+       /// Return all strictest policy values
+       std::unordered_map<std::string, PolicyValue> strictest();
+
+       const std::vector<std::string>& getAdmins() const noexcept;
+
+private:
+       std::string getScript(const std::string& name);
+
+       std::shared_ptr<klay::database::Connection> database;
+
+       /// DB Cache objects
+       /// TODO(Sangwan): add locking mechanism
+       std::vector<std::string> admins;
+       std::unordered_map<std::string, PolicyActivated> activatedPolicies;
+       std::unordered_map<std::string, PolicyDefinition> definitions;
+};
+
+} // namespace policy
+} // namespace vist
diff --git a/src/vist/policy/core/tests/core-tests.cpp b/src/vist/policy/core/tests/core-tests.cpp
deleted file mode 100644 (file)
index 4a30c19..0000000
+++ /dev/null
@@ -1,53 +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 "../policy-manager.h"
-
-namespace vist {
-namespace policy {
-
-class PolicyCoreTests : public testing::Test {};
-
-TEST_F(PolicyCoreTests, policy_loader) {
-       auto& manager = PolicyManager::Instance();
-
-       EXPECT_TRUE(manager.providers.size() > 0);
-       EXPECT_TRUE(manager.policies.size() > 0);
-}
-
-TEST_F(PolicyCoreTests, policy_set_get) {
-       auto& manager = PolicyManager::Instance();
-       manager.enroll("testAdmin");
-       manager.set("bluetooth", PolicyValue(5), "testAdmin");
-
-       auto policy = manager.get("bluetooth");
-       EXPECT_EQ(policy.value, 5);
-
-       manager.enroll("testAdmin1");
-       manager.set("bluetooth", PolicyValue(10), "testAdmin1");
-
-       /// Manager should return the strongest policy.
-       policy = manager.get("bluetooth");
-       EXPECT_EQ(policy.value, 5);
-
-       manager.disenroll("testAdmin");
-       manager.disenroll("testAdmin1");
-}
-
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/policy/core/tests/core.cpp b/src/vist/policy/core/tests/core.cpp
new file mode 100644 (file)
index 0000000..2cf5bb8
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  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/policy/core/policy-manager.hpp>
+
+namespace vist {
+namespace policy {
+
+class PolicyCoreTests : public testing::Test {};
+
+TEST_F(PolicyCoreTests, policy_loader) {
+       auto& manager = PolicyManager::Instance();
+
+       EXPECT_TRUE(manager.providers.size() > 0);
+       EXPECT_TRUE(manager.policies.size() > 0);
+}
+
+TEST_F(PolicyCoreTests, policy_set_get) {
+       auto& manager = PolicyManager::Instance();
+       manager.enroll("testAdmin");
+       manager.set("bluetooth", PolicyValue(5), "testAdmin");
+
+       auto policy = manager.get("bluetooth");
+       EXPECT_EQ(policy.value, 5);
+
+       manager.enroll("testAdmin1");
+       manager.set("bluetooth", PolicyValue(10), "testAdmin1");
+
+       /// Manager should return the strongest policy.
+       policy = manager.get("bluetooth");
+       EXPECT_EQ(policy.value, 5);
+
+       manager.disenroll("testAdmin");
+       manager.disenroll("testAdmin1");
+}
+
+} // namespace policy
+} // namespace vist
diff --git a/src/vist/policy/core/tests/storage-tests.cpp b/src/vist/policy/core/tests/storage-tests.cpp
deleted file mode 100644 (file)
index 1fd0579..0000000
+++ /dev/null
@@ -1,159 +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 <memory>
-
-#include "../policy-storage.h"
-
-using namespace vist::policy;
-
-class PolicyStorageTests : public testing::Test {
-public:
-       void SetUp() override
-       {
-               this->storage = std::make_shared<PolicyStorage>(DB_PATH);
-       }
-
-       std::shared_ptr<PolicyStorage> getStorage()
-       {
-               return this->storage;
-       }
-
-private:
-       std::shared_ptr<PolicyStorage> storage = nullptr;
-};
-
-TEST_F(PolicyStorageTests, initialize)
-{
-       bool isRaised = false;
-
-       try {
-               // DB is maden at run-time
-               PolicyStorage storage("/tmp/dummy");
-       } catch (const std::exception&) {
-               isRaised = true;
-       }
-
-       EXPECT_FALSE(isRaised);
-}
-
-TEST_F(PolicyStorageTests, enrollment)
-{
-       auto storage = getStorage();
-       EXPECT_FALSE(storage->isActivated());
-
-       storage->enroll("testAdmin0");
-       storage->enroll("testAdmin1");
-       EXPECT_TRUE(storage->isActivated());
-
-       storage->disenroll("testAdmin0");
-       EXPECT_TRUE(storage->isActivated());
-
-       storage->disenroll("testAdmin1");
-       EXPECT_FALSE(storage->isActivated());
-}
-
-TEST_F(PolicyStorageTests, update)
-{
-       auto storage = getStorage();
-       storage->enroll("testAdmin");
-
-       bool isRaised = false;
-       try {
-               storage->update("fakeAdmin", "bluetooth", PolicyValue(0));
-       } catch (const std::exception&) {
-               isRaised = true;
-       }
-
-       isRaised = false;
-       try {
-               storage->update("testAdmin", "bluetooth", PolicyValue(0));
-       } catch (const std::exception&) {
-               isRaised = true;
-       }
-       EXPECT_FALSE(isRaised);
-
-       isRaised = false;
-       try {
-               storage->update("testAdmin", "FakePolicy", PolicyValue(0));
-       } catch (const std::exception&) {
-               isRaised = true;
-       }
-       EXPECT_TRUE(isRaised);
-
-       storage->disenroll("testAdmin");
-}
-
-TEST_F(PolicyStorageTests, strictest)
-{
-       auto storage = getStorage();
-       storage->enroll("testAdmin0");
-       storage->enroll("testAdmin1");
-
-       storage->update("testAdmin0", "bluetooth", PolicyValue(3));
-       storage->update("testAdmin1", "bluetooth", PolicyValue(6));
-
-       bool isRaised = false;
-       try {
-               auto value = storage->strictest("FakePolicy");
-       } catch (const std::exception&) {
-               isRaised = true;
-       }
-       EXPECT_TRUE(isRaised);
-
-       auto policy = storage->strictest("bluetooth");
-       EXPECT_EQ(policy.value, 3);
-
-       storage->disenroll("testAdmin0");
-       storage->disenroll("testAdmin1");
-}
-
-TEST_F(PolicyStorageTests, strictest_all)
-{
-       auto storage = getStorage();
-       storage->enroll("testAdmin");
-
-       auto policies = storage->strictest();
-       EXPECT_TRUE(policies.size() > 0);
-
-       storage->disenroll("testAdmin");
-}
-
-TEST_F(PolicyStorageTests, admin_list)
-{
-       auto storage = getStorage();
-
-       auto admins = storage->getAdmins();
-       EXPECT_EQ(admins.size(), 0);
-
-       storage->enroll("testAdmin1");
-       admins = storage->getAdmins();
-       EXPECT_EQ(admins.size(), 1);
-
-       storage->enroll("testAdmin2");
-       admins = storage->getAdmins();
-       EXPECT_EQ(admins.size(), 2);
-
-       storage->disenroll("testAdmin2");
-       admins = storage->getAdmins();
-       EXPECT_EQ(admins.size(), 1);
-
-       storage->disenroll("testAdmin1");
-       admins = storage->getAdmins();
-       EXPECT_EQ(admins.size(), 0);
-}
diff --git a/src/vist/policy/core/tests/storage.cpp b/src/vist/policy/core/tests/storage.cpp
new file mode 100644 (file)
index 0000000..369fb00
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ *  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 <memory>
+
+#include <vist/policy/core/policy-storage.hpp>
+
+using namespace vist::policy;
+
+class PolicyStorageTests : public testing::Test {
+public:
+       void SetUp() override
+       {
+               this->storage = std::make_shared<PolicyStorage>(DB_PATH);
+       }
+
+       std::shared_ptr<PolicyStorage> getStorage()
+       {
+               return this->storage;
+       }
+
+private:
+       std::shared_ptr<PolicyStorage> storage = nullptr;
+};
+
+TEST_F(PolicyStorageTests, initialize)
+{
+       bool isRaised = false;
+
+       try {
+               // DB is maden at run-time
+               PolicyStorage storage("/tmp/dummy");
+       } catch (const std::exception&) {
+               isRaised = true;
+       }
+
+       EXPECT_FALSE(isRaised);
+}
+
+TEST_F(PolicyStorageTests, enrollment)
+{
+       auto storage = getStorage();
+       EXPECT_FALSE(storage->isActivated());
+
+       storage->enroll("testAdmin0");
+       storage->enroll("testAdmin1");
+       EXPECT_TRUE(storage->isActivated());
+
+       storage->disenroll("testAdmin0");
+       EXPECT_TRUE(storage->isActivated());
+
+       storage->disenroll("testAdmin1");
+       EXPECT_FALSE(storage->isActivated());
+}
+
+TEST_F(PolicyStorageTests, update)
+{
+       auto storage = getStorage();
+       storage->enroll("testAdmin");
+
+       bool isRaised = false;
+       try {
+               storage->update("fakeAdmin", "bluetooth", PolicyValue(0));
+       } catch (const std::exception&) {
+               isRaised = true;
+       }
+
+       isRaised = false;
+       try {
+               storage->update("testAdmin", "bluetooth", PolicyValue(0));
+       } catch (const std::exception&) {
+               isRaised = true;
+       }
+       EXPECT_FALSE(isRaised);
+
+       isRaised = false;
+       try {
+               storage->update("testAdmin", "FakePolicy", PolicyValue(0));
+       } catch (const std::exception&) {
+               isRaised = true;
+       }
+       EXPECT_TRUE(isRaised);
+
+       storage->disenroll("testAdmin");
+}
+
+TEST_F(PolicyStorageTests, strictest)
+{
+       auto storage = getStorage();
+       storage->enroll("testAdmin0");
+       storage->enroll("testAdmin1");
+
+       storage->update("testAdmin0", "bluetooth", PolicyValue(3));
+       storage->update("testAdmin1", "bluetooth", PolicyValue(6));
+
+       bool isRaised = false;
+       try {
+               auto value = storage->strictest("FakePolicy");
+       } catch (const std::exception&) {
+               isRaised = true;
+       }
+       EXPECT_TRUE(isRaised);
+
+       auto policy = storage->strictest("bluetooth");
+       EXPECT_EQ(policy.value, 3);
+
+       storage->disenroll("testAdmin0");
+       storage->disenroll("testAdmin1");
+}
+
+TEST_F(PolicyStorageTests, strictest_all)
+{
+       auto storage = getStorage();
+       storage->enroll("testAdmin");
+
+       auto policies = storage->strictest();
+       EXPECT_TRUE(policies.size() > 0);
+
+       storage->disenroll("testAdmin");
+}
+
+TEST_F(PolicyStorageTests, admin_list)
+{
+       auto storage = getStorage();
+
+       auto admins = storage->getAdmins();
+       EXPECT_EQ(admins.size(), 0);
+
+       storage->enroll("testAdmin1");
+       admins = storage->getAdmins();
+       EXPECT_EQ(admins.size(), 1);
+
+       storage->enroll("testAdmin2");
+       admins = storage->getAdmins();
+       EXPECT_EQ(admins.size(), 2);
+
+       storage->disenroll("testAdmin2");
+       admins = storage->getAdmins();
+       EXPECT_EQ(admins.size(), 1);
+
+       storage->disenroll("testAdmin1");
+       admins = storage->getAdmins();
+       EXPECT_EQ(admins.size(), 0);
+}
diff --git a/src/vist/policy/sdk/policy-model.h b/src/vist/policy/sdk/policy-model.h
deleted file mode 100644 (file)
index 8dd0392..0000000
+++ /dev/null
@@ -1,75 +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
- */
-
-#pragma once
-
-#include <vist/policy/sdk/policy-value.h>
-
-#include <string>
-#include <stdexcept>
-
-namespace vist {
-namespace policy {
-
-class PolicyModel {
-public:
-       explicit PolicyModel(std::string name, PolicyValue initial) noexcept :
-               name(std::move(name)), initial(std::move(initial)) {}
-       virtual ~PolicyModel() = default;
-
-       PolicyModel(const PolicyModel&) = delete;
-       PolicyModel& operator=(const PolicyModel&) = delete;
-
-       PolicyModel(PolicyModel&&) = default;
-       PolicyModel& operator=(PolicyModel&&) = default;
-
-       inline void set(const PolicyValue& value)
-       {
-               auto rollback = current;
-               current = value;
-               ready = true;
-
-               try {
-                       this->onChanged(value);
-               } catch (const std::exception& e) {
-                       current = rollback;
-                       ready = false;
-                       std::rethrow_exception(std::current_exception());
-               }
-       }
-
-       inline const PolicyValue& get() const
-       {
-               if (!ready)
-                       throw std::runtime_error("Policy value should be set once before use.");
-
-               return current;
-       }
-
-       virtual void onChanged(const PolicyValue& value) = 0;
-
-       const std::string& getName() const noexcept { return name; }
-       const PolicyValue& getInitial() const noexcept { return initial; }
-
-protected:
-       std::string name;
-       PolicyValue initial;
-       PolicyValue current;
-       bool ready = false;
-};
-
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/policy/sdk/policy-model.hpp b/src/vist/policy/sdk/policy-model.hpp
new file mode 100644 (file)
index 0000000..64580fc
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <vist/policy/sdk/policy-value.hpp>
+
+#include <string>
+#include <stdexcept>
+
+namespace vist {
+namespace policy {
+
+class PolicyModel {
+public:
+       explicit PolicyModel(std::string name, PolicyValue initial) noexcept :
+               name(std::move(name)), initial(std::move(initial)) {}
+       virtual ~PolicyModel() = default;
+
+       PolicyModel(const PolicyModel&) = delete;
+       PolicyModel& operator=(const PolicyModel&) = delete;
+
+       PolicyModel(PolicyModel&&) = default;
+       PolicyModel& operator=(PolicyModel&&) = default;
+
+       inline void set(const PolicyValue& value)
+       {
+               auto rollback = current;
+               current = value;
+               ready = true;
+
+               try {
+                       this->onChanged(value);
+               } catch (const std::exception& e) {
+                       current = rollback;
+                       ready = false;
+                       std::rethrow_exception(std::current_exception());
+               }
+       }
+
+       inline const PolicyValue& get() const
+       {
+               if (!ready)
+                       throw std::runtime_error("Policy value should be set once before use.");
+
+               return current;
+       }
+
+       virtual void onChanged(const PolicyValue& value) = 0;
+
+       const std::string& getName() const noexcept { return name; }
+       const PolicyValue& getInitial() const noexcept { return initial; }
+
+protected:
+       std::string name;
+       PolicyValue initial;
+       PolicyValue current;
+       bool ready = false;
+};
+
+} // namespace policy
+} // namespace vist
diff --git a/src/vist/policy/sdk/policy-provider.h b/src/vist/policy/sdk/policy-provider.h
deleted file mode 100644 (file)
index ff79099..0000000
+++ /dev/null
@@ -1,57 +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
- */
-
-#pragma once
-
-#include <vist/policy/sdk/policy-model.h>
-
-#include <cstddef>
-#include <memory>
-#include <unordered_map>
-
-namespace vist {
-namespace policy {
-
-class PolicyProvider {
-public:
-       using FactoryType = PolicyProvider* (*)();
-
-       explicit PolicyProvider(std::string name) noexcept : name(std::move(name)) {}
-       virtual ~PolicyProvider() = default;
-
-       inline void add(const std::shared_ptr<PolicyModel>& policy)
-       {
-               policies[policy->getName()] = policy;
-       }
-
-       inline const std::string& getName() const noexcept { return name; }
-       static const std::string& getFactoryName() noexcept
-       {
-               static std::string name = "PolicyFactory";
-               return name;
-       }
-
-       inline std::size_t size() const noexcept { return policies.size(); }
-
-private:
-       std::string name;
-       std::unordered_map<std::string, std::shared_ptr<PolicyModel>> policies;
-
-       friend class PolicyManager;
-};
-
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/policy/sdk/policy-provider.hpp b/src/vist/policy/sdk/policy-provider.hpp
new file mode 100644 (file)
index 0000000..c55ff26
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <vist/policy/sdk/policy-model.hpp>
+
+#include <cstddef>
+#include <memory>
+#include <unordered_map>
+
+namespace vist {
+namespace policy {
+
+class PolicyProvider {
+public:
+       using FactoryType = PolicyProvider* (*)();
+
+       explicit PolicyProvider(std::string name) noexcept : name(std::move(name)) {}
+       virtual ~PolicyProvider() = default;
+
+       inline void add(const std::shared_ptr<PolicyModel>& policy)
+       {
+               policies[policy->getName()] = policy;
+       }
+
+       inline const std::string& getName() const noexcept { return name; }
+       static const std::string& getFactoryName() noexcept
+       {
+               static std::string name = "PolicyFactory";
+               return name;
+       }
+
+       inline std::size_t size() const noexcept { return policies.size(); }
+
+private:
+       std::string name;
+       std::unordered_map<std::string, std::shared_ptr<PolicyModel>> policies;
+
+       friend class PolicyManager;
+};
+
+} // namespace policy
+} // namespace vist
diff --git a/src/vist/policy/sdk/policy-value.h b/src/vist/policy/sdk/policy-value.h
deleted file mode 100644 (file)
index e1b2464..0000000
+++ /dev/null
@@ -1,48 +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
- */
-
-#pragma once
-
-namespace vist {
-namespace policy {
-
-// TODO: Support various value type
-struct PolicyValue final {
-       explicit PolicyValue(int value) noexcept : value(value) {}
-       explicit PolicyValue() noexcept = default;
-       ~PolicyValue() = default;
-
-       PolicyValue(const PolicyValue&) noexcept = default;
-       PolicyValue& operator=(const PolicyValue&) noexcept = default;
-
-       PolicyValue(PolicyValue&&) noexcept = default;
-       PolicyValue& operator=(PolicyValue&&) noexcept = default;
-
-       PolicyValue& operator=(int val) {
-               value = val;
-               return *this;
-       }
-
-       operator int() const { return value; }
-       bool operator==(const PolicyValue& rhs) const { return value == rhs.value; }
-       bool operator!=(const PolicyValue& rhs) const { return value != rhs.value; }
-       bool operator<(const PolicyValue& rhs) const { return value < rhs.value; }
-
-       int value = -1;
-};
-
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/policy/sdk/policy-value.hpp b/src/vist/policy/sdk/policy-value.hpp
new file mode 100644 (file)
index 0000000..e1b2464
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+namespace vist {
+namespace policy {
+
+// TODO: Support various value type
+struct PolicyValue final {
+       explicit PolicyValue(int value) noexcept : value(value) {}
+       explicit PolicyValue() noexcept = default;
+       ~PolicyValue() = default;
+
+       PolicyValue(const PolicyValue&) noexcept = default;
+       PolicyValue& operator=(const PolicyValue&) noexcept = default;
+
+       PolicyValue(PolicyValue&&) noexcept = default;
+       PolicyValue& operator=(PolicyValue&&) noexcept = default;
+
+       PolicyValue& operator=(int val) {
+               value = val;
+               return *this;
+       }
+
+       operator int() const { return value; }
+       bool operator==(const PolicyValue& rhs) const { return value == rhs.value; }
+       bool operator!=(const PolicyValue& rhs) const { return value != rhs.value; }
+       bool operator<(const PolicyValue& rhs) const { return value < rhs.value; }
+
+       int value = -1;
+};
+
+} // namespace policy
+} // namespace vist
diff --git a/src/vist/policy/sdk/tests/sdk-tests.cpp b/src/vist/policy/sdk/tests/sdk-tests.cpp
deleted file mode 100644 (file)
index 656e29d..0000000
+++ /dev/null
@@ -1,98 +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 "../policy-model.h"
-#include "../policy-provider.h"
-
-#include <exception>
-
-namespace {
-       int g_value = -1;
-} // anonymous namespace
-
-using namespace vist::policy;
-
-class PolicySDKTests : public testing::Test {};
-
-class TestPolicyModel : public PolicyModel {
-public:
-       TestPolicyModel() : PolicyModel("test_policy", PolicyValue(1)) {}
-
-       virtual void onChanged(const PolicyValue& value)
-       {
-               g_value = value;
-       }
-};
-
-class TestPolicyModelFailed : public PolicyModel {
-public:
-       TestPolicyModelFailed() : PolicyModel("test_policy_failed", PolicyValue(1)) {}
-
-       virtual void onChanged(const PolicyValue& value)
-       {
-               throw std::runtime_error("Intended exception for test.");
-       }
-};
-
-TEST_F(PolicySDKTests, policy_model)
-{
-       TestPolicyModel policy;
-
-       EXPECT_EQ(policy.getName(), "test_policy");
-       EXPECT_EQ(policy.getInitial(), 1);
-
-       // Policy value should be set once before use
-       bool isRaised = false;
-       try {
-               auto value = policy.get();
-       } catch (const std::exception&) {
-               isRaised = true;
-       }
-
-       EXPECT_TRUE(isRaised);
-
-       policy.set(PolicyValue(3));
-       EXPECT_EQ(3, g_value);
-       EXPECT_EQ(3, policy.get());
-}
-
-TEST_F(PolicySDKTests, policy_model_failed)
-{
-       TestPolicyModelFailed policy;
-
-       EXPECT_EQ(policy.getName(), "test_policy_failed");
-       EXPECT_EQ(policy.getInitial(), 1);
-
-       bool isRaised = true;
-       try {
-               policy.set(PolicyValue(3));
-       } catch (const std::exception&) {
-               isRaised = true;
-       }
-
-       EXPECT_TRUE(isRaised);
-}
-
-TEST_F(PolicySDKTests, policy_provider)
-{
-       PolicyProvider provider("testProvider");
-       provider.add(std::make_shared<TestPolicyModel>());
-       provider.add(std::make_shared<TestPolicyModelFailed>());
-
-       EXPECT_EQ(2, provider.size());
-}
diff --git a/src/vist/policy/sdk/tests/sdk.cpp b/src/vist/policy/sdk/tests/sdk.cpp
new file mode 100644 (file)
index 0000000..4be5d8d
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ *  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/policy/sdk/policy-model.hpp>
+#include <vist/policy/sdk/policy-provider.hpp>
+
+#include <exception>
+
+namespace {
+       int g_value = -1;
+} // anonymous namespace
+
+using namespace vist::policy;
+
+class PolicySDKTests : public testing::Test {};
+
+class TestPolicyModel : public PolicyModel {
+public:
+       TestPolicyModel() : PolicyModel("test_policy", PolicyValue(1)) {}
+
+       virtual void onChanged(const PolicyValue& value)
+       {
+               g_value = value;
+       }
+};
+
+class TestPolicyModelFailed : public PolicyModel {
+public:
+       TestPolicyModelFailed() : PolicyModel("test_policy_failed", PolicyValue(1)) {}
+
+       virtual void onChanged(const PolicyValue& value)
+       {
+               throw std::runtime_error("Intended exception for test.");
+       }
+};
+
+TEST_F(PolicySDKTests, policy_model)
+{
+       TestPolicyModel policy;
+
+       EXPECT_EQ(policy.getName(), "test_policy");
+       EXPECT_EQ(policy.getInitial(), 1);
+
+       // Policy value should be set once before use
+       bool isRaised = false;
+       try {
+               auto value = policy.get();
+       } catch (const std::exception&) {
+               isRaised = true;
+       }
+
+       EXPECT_TRUE(isRaised);
+
+       policy.set(PolicyValue(3));
+       EXPECT_EQ(3, g_value);
+       EXPECT_EQ(3, policy.get());
+}
+
+TEST_F(PolicySDKTests, policy_model_failed)
+{
+       TestPolicyModelFailed policy;
+
+       EXPECT_EQ(policy.getName(), "test_policy_failed");
+       EXPECT_EQ(policy.getInitial(), 1);
+
+       bool isRaised = true;
+       try {
+               policy.set(PolicyValue(3));
+       } catch (const std::exception&) {
+               isRaised = true;
+       }
+
+       EXPECT_TRUE(isRaised);
+}
+
+TEST_F(PolicySDKTests, policy_provider)
+{
+       PolicyProvider provider("testProvider");
+       provider.add(std::make_shared<TestPolicyModel>());
+       provider.add(std::make_shared<TestPolicyModelFailed>());
+
+       EXPECT_EQ(2, provider.size());
+}
diff --git a/src/vist/query-builder.hpp b/src/vist/query-builder.hpp
new file mode 100644 (file)
index 0000000..35a918e
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+/*
+ * @brief namespace TSQB means type-safe query builder
+ */
+
+#pragma once
+
+#include "query-builder/column.hpp"
+#include "query-builder/condition.hpp"
+#include "query-builder/database.hpp"
+#include "query-builder/expression.hpp"
+#include "query-builder/table.hpp"
+#include "query-builder/util.hpp"
diff --git a/src/vist/query-builder/CMakeLists.txt b/src/vist/query-builder/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5f41c24
--- /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
+
+/// TSQB: Type Safe Query Builder
+FILE(GLOB TSQB_TESTS "tests/*.cpp")
+ADD_VIST_TEST(${TSQB_TESTS})
diff --git a/src/vist/query-builder/column-pack.hpp b/src/vist/query-builder/column-pack.hpp
new file mode 100644 (file)
index 0000000..6f4e66f
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+
+#pragma once
+
+#include "type.hpp"
+
+#include <string>
+#include <vector>
+
+namespace vist {
+namespace tsqb {
+namespace internal {
+
+template<typename... Base>
+class ColumnPack {
+public:
+       virtual ~ColumnPack() = default;
+
+       template<typename ColumnType>
+       std::string getName(ColumnType&&) const noexcept { return std::string(); }
+       std::vector<std::string> getNames(void) const noexcept { return {}; }
+
+       int size() const noexcept { return 0; }
+};
+
+template<typename Front, typename... Rest>
+class ColumnPack<Front, Rest...> : public ColumnPack<Rest...> {
+public:
+       using Column = Front;
+       using TableType = typename Column::TableType;
+
+       explicit ColumnPack(Front&& front, Rest&& ...rest);
+       virtual ~ColumnPack() = default;
+
+       ColumnPack(const ColumnPack&) = delete;
+       ColumnPack& operator=(const ColumnPack&) = delete;
+
+       ColumnPack(ColumnPack&&) = default;
+       ColumnPack& operator=(ColumnPack&&) = default;
+
+       template<typename ColumnType>
+       std::string getName(ColumnType&& type) const noexcept;
+       std::vector<std::string> getNames(void) const noexcept;
+
+       int size() const noexcept { return Base::size() + 1; }
+
+private:
+       using Base = ColumnPack<Rest...>;
+
+       Column column;
+};
+
+template<typename Front, typename... Rest>
+ColumnPack<Front, Rest...>::ColumnPack(Front&& front, Rest&& ...rest) :
+       Base(std::forward<Rest>(rest)...), column(front)
+{
+}
+
+template<typename Front, typename... Rest>
+std::vector<std::string> ColumnPack<Front, Rest...>::getNames(void) const noexcept
+{
+       auto names = Base::getNames();
+       names.push_back(this->column.name);
+
+       return std::move(names);
+}
+
+template<typename Front, typename... Rest>
+template<typename ColumnType>
+std::string ColumnPack<Front, Rest...>::getName(ColumnType&& type) const noexcept
+{
+       if (type::cast_compare(column.type, std::forward<ColumnType>(type)))
+               return column.name;
+
+       return Base::template getName<ColumnType>(std::forward<ColumnType>(type));
+}
+
+} // namespace internal
+} // namespace tsqb
+} // namespace vist
diff --git a/src/vist/query-builder/column.hpp b/src/vist/query-builder/column.hpp
new file mode 100644 (file)
index 0000000..5ec7aba
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+
+#pragma once
+
+#include <string>
+#include <tuple>
+
+namespace vist {
+namespace tsqb {
+
+template<typename Object, typename Field>
+struct Column {
+       using Type = Field Object::*;
+       using FieldType = Field;
+       using TableType = Object;
+
+       std::string name;
+       Type type;
+};
+
+template<typename O, typename F>
+Column<O, F> make_column(const std::string& name, F O::*field)
+{
+       return {name, field};
+}
+
+template<typename Type>
+struct Distinct {
+       Type value;
+};
+
+template<typename... Args>
+auto distinct(Args&&... args) -> decltype(Distinct<std::tuple<Args...>>())
+{
+       return {std::make_tuple(std::forward<Args>(args)...)};
+}
+
+} // namespace tsqb
+} // namespace vist
diff --git a/src/vist/query-builder/condition.hpp b/src/vist/query-builder/condition.hpp
new file mode 100644 (file)
index 0000000..54fdcce
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+
+#pragma once
+
+#include "type.hpp"
+
+namespace vist {
+namespace tsqb {
+namespace condition {
+
+struct Base {};
+
+template<typename L, typename R>
+struct And : public Base {
+       L l;
+       R r;
+
+       And(L l, R r) : l(l), r(r) {}
+       operator std::string() const
+       {
+               return "AND";
+       }
+};
+
+template<typename L, typename R>
+struct Or : public Base {
+       L l;
+       R r;
+
+       Or(L l, R r) : l(l), r(r) {}
+       operator std::string() const
+       {
+               return "OR";
+       }
+};
+
+template<typename L, typename R>
+struct Binary : public Base {
+       L l;
+       R r;
+
+       Binary(L l, R r) : l(l), r(r)
+       {
+               using FieldType = typename L::FieldType;
+               type::assert_compare(FieldType(), r);
+       }
+};
+
+template<typename L>
+struct Binary<L, const char*> : public Base {
+       L l;
+       std::string r;
+
+       Binary(L l, const char* r) : l(l), r(r)
+       {
+               using FieldType = typename L::FieldType;
+               type::assert_compare(FieldType(), std::string());
+       }
+};
+
+enum class Join : int {
+       INNER,
+       CROSS,
+       LEFT_OUTER,
+       RIGHT_OUTER,
+       FULL_OUTER
+};
+
+inline std::string to_string(Join type)
+{
+       switch (type) {
+       case Join::CROSS: return "CROSS";
+       case Join::LEFT_OUTER: return "LEFT OUTER";
+       case Join::RIGHT_OUTER: return "RIGHT OUTER";
+       case Join::FULL_OUTER: return "FULL OUTER";
+       case Join::INNER:
+       default:
+               return "INNER";
+       }
+}
+
+} // namespace condition
+} // namespace tsqb
+} // namespace vist
diff --git a/src/vist/query-builder/crud.hpp b/src/vist/query-builder/crud.hpp
new file mode 100644 (file)
index 0000000..2ef2a14
--- /dev/null
@@ -0,0 +1,275 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+
+#pragma once
+
+#include "column.hpp"
+#include "expression.hpp"
+
+#include <string>
+#include <sstream>
+
+namespace vist {
+namespace tsqb {
+
+template<typename T>
+class Crud {
+public:
+       template<typename... ColumnTypes>
+       T& select(ColumnTypes&&... cts);
+
+       template<typename Type>
+       T& select(Distinct<Type> distinct);
+
+       template<typename TableType>
+       T& selectAll(void);
+
+       T& selectAll(void);
+
+       template<typename... ColumnTypes>
+       T& update(ColumnTypes&&... cts);
+
+       template<typename... ColumnTypes>
+       T& insert(ColumnTypes&&... cts);
+
+       template<typename... ColumnTypes>
+       T& remove(ColumnTypes&&... cts);
+
+       template<typename Expr>
+       T& where(Expr expr);
+
+private:
+       template<typename ColumnTuple>
+       T& selectInternal(ColumnTuple&& ct, bool distinct = false);
+
+       template<typename L, typename R>
+       std::string processWhere(condition::And<L,R>& expr);
+
+       template<typename L, typename R>
+       std::string processWhere(condition::Or<L,R>& expr);
+
+       template<typename Expr>
+       std::string processWhere(Expr expr);
+};
+
+template<typename T>
+template<typename... ColumnTypes>
+T& Crud<T>::select(ColumnTypes&&... cts)
+{
+       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
+
+       return this->selectInternal(std::move(columnTuple));
+}
+
+template<typename T>
+template<typename Type>
+T& Crud<T>::select(Distinct<Type> distinct)
+{
+       return this->selectInternal(std::move(distinct.value), true);
+}
+
+template<typename T>
+T& Crud<T>::selectAll(void)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       std::stringstream ss;
+       ss << "SELECT * FROM " << static_cast<T*>(this)->name;
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename TableType>
+T& Crud<T>::selectAll(void)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       std::stringstream ss;
+       auto tableName = static_cast<T*>(this)->getTableName(TableType());
+       ss << "SELECT * FROM " << tableName;
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename ColumnTuple>
+T& Crud<T>::selectInternal(ColumnTuple&& ct, bool distinct)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(ct));
+       auto tableNames = static_cast<T*>(this)->getTableNames(std::move(ct));
+
+       std::stringstream ss;
+       ss << "SELECT ";
+
+       if (distinct)
+               ss << "DISTINCT ";
+
+       int i = 0;
+       for (const auto& c : columnNames) {
+               ss << c;
+
+               if (i++ < columnNames.size() - 1)
+                       ss << ", ";
+       }
+
+       ss << " FROM ";
+
+       i = 0;
+       for (const auto& t : tableNames) {
+               ss << t;
+
+               if (i++ < tableNames.size() - 1)
+                       ss << ", ";
+       }
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename... ColumnTypes>
+T& Crud<T>::update(ColumnTypes&&... cts)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
+       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
+
+       std::stringstream ss;
+       ss << "UPDATE " << static_cast<T*>(this)->name << " ";
+       ss << "SET ";
+
+       int i = 0;
+       for (const auto& c : columnNames) {
+               ss << c << " = ?";
+
+               if (i++ < columnNames.size() - 1)
+                       ss << ", ";
+       }
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename... ColumnTypes>
+T& Crud<T>::insert(ColumnTypes&&... cts)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
+       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
+
+       std::stringstream ss;
+       ss << "INSERT INTO " << static_cast<T*>(this)->name << " (";
+
+       const int columnCount = columnNames.size();
+       for (int i = 0; i < columnCount; i++) {
+               ss << columnNames[i];
+               if (i < columnCount - 1)
+                       ss << ", ";
+       }
+
+       ss << ") VALUES (";
+
+       for (int i = 0; i < columnCount; i++) {
+               ss << "?";
+               if (i < columnCount - 1)
+                       ss << ", ";
+       }
+
+       ss << ")";
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename... ColumnTypes>
+T& Crud<T>::remove(ColumnTypes&&... cts)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
+       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
+
+       std::stringstream ss;
+       ss << "DELETE FROM " << static_cast<T*>(this)->name;
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename Expr>
+T& Crud<T>::where(Expr expr)
+{
+       std::stringstream ss;
+       ss << "WHERE " << this->processWhere(expr);
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename L, typename R>
+std::string Crud<T>::processWhere(condition::And<L,R>& expr)
+{
+       std::stringstream ss;
+       ss << this->processWhere(expr.l) << " ";
+       ss << static_cast<std::string>(expr) << " ";
+       ss << this->processWhere(expr.r);
+
+       return ss.str();
+}
+
+template<typename T>
+template<typename L, typename R>
+std::string Crud<T>::processWhere(condition::Or<L,R>& expr)
+{
+       std::stringstream ss;
+       ss << this->processWhere(expr.l) << " ";
+       ss << static_cast<std::string>(expr) << " ";
+       ss << this->processWhere(expr.r);
+
+       return ss.str();
+}
+
+template<typename T>
+template<typename Expr>
+std::string Crud<T>::processWhere(Expr expr)
+{
+       std::stringstream ss;
+       ss << static_cast<T*>(this)->getColumnName(expr.l.type);
+       ss << " " << std::string(expr) << " ?";
+
+       return ss.str();
+}
+
+} // namespace tsqb
+} // namespace vist
diff --git a/src/vist/query-builder/database.hpp b/src/vist/query-builder/database.hpp
new file mode 100644 (file)
index 0000000..ef6189b
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+
+#pragma once
+
+#include "crud.hpp"
+#include "condition.hpp"
+#include "expression.hpp"
+#include "table-pack.hpp"
+#include "tuple-helper.hpp"
+#include "util.hpp"
+
+#include <vector>
+#include <set>
+#include <string>
+#include <sstream>
+#include <algorithm>
+
+namespace vist {
+namespace tsqb {
+
+template<typename... Tables>
+class Database : public Crud<Database<Tables...>> {
+public:
+       using Self = Database<Tables...>;
+
+       virtual ~Database() = default;
+
+       Database(const Database&) = delete;
+       Database& operator=(const Database&) = delete;
+
+       Database(Database&&) = default;
+       Database& operator=(Database&&) = default;
+
+       // Functions for Crud
+       template<typename Cs>
+       std::set<std::string> getTableNames(Cs&& tuple) const noexcept;
+       template<typename Cs>
+       std::vector<std::string> getColumnNames(Cs&& tuple) const noexcept;
+       template<typename TableType>
+       std::string getTableName(TableType&& type) const noexcept;
+       template<typename ColumnType>
+       std::string getColumnName(ColumnType&& type) const noexcept;
+
+       template<typename Table>
+       Self& join(condition::Join type = condition::Join::INNER);
+
+       template<typename Expr>
+       Self& on(Expr expr);
+
+       operator std::string();
+
+       std::string name;
+       std::vector<std::string> cache;
+
+private:
+       using TablePackType = internal::TablePack<Tables...>;
+       using ColumnNames = std::vector<std::string>;
+       using TableNames = std::set<std::string>;
+
+       explicit Database(const std::string& name, TablePackType&& tablePack);
+
+       template<typename ...Ts>
+       friend Database<Ts...> make_database(const std::string& name, Ts&& ...tables);
+
+       struct GetTableNames {
+               const TablePackType& tablePack;
+               std::set<std::string> names;
+               GetTableNames(const TablePackType& tablePack) : tablePack(tablePack) {}
+
+               template <typename T>
+               void operator()(T&& type)
+               {
+                       auto column = make_column("anonymous", type);
+                       using TableType = typename decltype(column)::TableType;
+                       auto name = this->tablePack.getName(TableType());
+                       if (!name.empty())
+                               names.emplace(name);
+               }
+       };
+
+       struct GetColumnNames {
+               const TablePackType& tablePack;
+               std::vector<std::string> names;
+
+               GetColumnNames(const TablePackType& tablePack) : tablePack(tablePack) {}
+
+               template <typename T>
+               void operator()(T&& type)
+               {
+                       auto column = make_column("anonymous", type);
+                       auto name = this->tablePack.getColumnName(std::move(column));
+                       if (!name.empty())
+                               names.emplace_back(name);
+               }
+       };
+
+       TablePackType tablePack;
+};
+
+template<typename ...Tables>
+Database<Tables...> make_database(const std::string& name, Tables&& ...tables)
+{
+       auto tablePack = internal::TablePack<Tables...>(std::forward<Tables>(tables)...);
+       return Database<Tables...>(name, std::move(tablePack));
+}
+
+template<typename ...Tables>
+Database<Tables...>::Database(const std::string& name, TablePackType&& tablePack)
+       : name(name), tablePack(std::move(tablePack)) {}
+
+template<typename... Tables>
+template<typename Table>
+Database<Tables...>& Database<Tables...>::join(condition::Join type)
+{
+       std::stringstream ss;
+       ss << condition::to_string(type) << " ";
+       ss << "JOIN ";
+       ss << this->tablePack.getName(Table());
+
+       this->cache.emplace_back(ss.str());
+       return *this;
+}
+
+template<typename... Tables>
+template<typename Expr>
+Database<Tables...>& Database<Tables...>::on(Expr expr)
+{
+       std::stringstream ss;
+       ss << "ON ";
+
+       auto lname = this->tablePack.getColumnName(std::move(expr.l));
+       ss << lname << " ";
+
+       ss << std::string(expr) << " ";
+
+       auto rname = this->tablePack.getColumnName(std::move(expr.r));
+       ss << rname;
+
+       this->cache.emplace_back(ss.str());
+       return *this;
+}
+
+template<typename... Tables>
+Database<Tables...>::operator std::string()
+{
+       std::stringstream ss;
+       for (const auto& c : cache)
+               ss << c << " ";
+
+       this->cache.clear();
+       return util::rtrim(ss.str());
+}
+
+template<typename... Tables>
+template<typename Cs>
+std::set<std::string> Database<Tables...>::getTableNames(Cs&& tuple) const noexcept
+{
+       GetTableNames closure(this->tablePack);
+       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
+
+       return closure.names;
+}
+
+template<typename... Tables>
+template<typename Cs>
+std::vector<std::string> Database<Tables...>::getColumnNames(Cs&& tuple) const noexcept
+{
+       GetColumnNames closure(this->tablePack);
+       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
+
+       return closure.names;
+}
+
+template<typename... Tables>
+template<typename TableType>
+std::string Database<Tables...>::getTableName(TableType&& type) const noexcept
+{
+       return this->tablePack.getName(std::forward<TableType>(type));
+}
+
+template<typename... Tables>
+template<typename ColumnType>
+std::string Database<Tables...>::getColumnName(ColumnType&& type) const noexcept
+{
+       auto column = make_column("anonymous", type);
+       return this->tablePack.getColumnName(std::move(column));
+}
+
+} // namespace tsqb
+} // namespace vist
diff --git a/src/vist/query-builder/expression.hpp b/src/vist/query-builder/expression.hpp
new file mode 100644 (file)
index 0000000..a1525f5
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+
+#pragma once
+
+#include "column.hpp"
+#include "type.hpp"
+#include "condition.hpp"
+
+#include <type_traits>
+
+namespace vist {
+namespace tsqb {
+
+template<typename Type>
+struct Expression {
+       Type value;
+};
+
+template<typename O, typename F>
+Expression<Column<O, F>> expr(F O::*field)
+{
+       Column<O, F> anonymous = {"anonymous", field};
+       return {anonymous};
+}
+
+template<typename L, typename R>
+struct Lesser : public condition::Binary<L, R> {
+       using condition::Binary<L, R>::Binary;
+
+       operator std::string() const
+       {
+               return "<";
+       }
+};
+
+template<typename L, typename R>
+Lesser<L, R> operator<(Expression<L> expr, R r)
+{
+       return {expr.value, r};
+}
+
+template<typename L, typename R>
+struct Equal : public condition::Binary<L, R>
+{
+       using condition::Binary<L, R>::Binary;
+
+       operator std::string() const
+       {
+               return "=";
+       }
+};
+
+template<typename L, typename R>
+Equal<L, R> operator==(Expression<L> expr, R r)
+{
+       return {expr.value, r};
+}
+
+namespace join {
+
+template<typename L, typename R>
+struct Equal
+{
+       L l;
+       R r;
+
+       operator std::string() const
+       {
+               return "=";
+       }
+};
+
+} // namespace join
+
+template<typename L, typename R>
+join::Equal<L, R> operator==(Expression<L> l, Expression<R> r)
+{
+       return {l.value, r.value};
+}
+
+template<typename L, typename R>
+struct Greater : public condition::Binary<L, R>
+{
+       using condition::Binary<L, R>::Binary;
+
+       operator std::string() const
+       {
+               return ">";
+       }
+};
+
+template<typename L, typename R>
+Greater<L, R> operator>(Expression<L> expr, R r)
+{
+       return {expr.value, r};
+}
+
+template<bool B, typename T = void>
+using enable_if_t = typename std::enable_if<B, T>::type;
+
+template<typename T>
+using is_condition = typename std::is_base_of<condition::Base, T>;
+
+template<typename L,
+                typename R,
+                typename = typename tsqb::enable_if_t<is_condition<L>::value
+                                                        && tsqb::is_condition<R>::value>>
+condition::And<L, R> operator&&(const L& l, const R& r)
+{
+       return {l, r};
+}
+
+template<typename L,
+                typename R,
+                typename = typename tsqb::enable_if_t<is_condition<L>::value
+                                                        && tsqb::is_condition<R>::value>>
+condition::Or<L, R> operator||(const L& l, const R& r)
+{
+       return {l, r};
+}
+
+} // namespace tsqb
+} // namespace vist
diff --git a/src/vist/query-builder/table-pack.hpp b/src/vist/query-builder/table-pack.hpp
new file mode 100644 (file)
index 0000000..eeda955
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+
+#pragma once
+
+#include <vector>
+#include <set>
+#include <string>
+
+namespace vist {
+namespace tsqb {
+namespace internal {
+
+template<typename... Base>
+class TablePack {
+public:
+       virtual ~TablePack() = default;
+
+       template<typename TableType>
+       std::string getName(TableType&&) const noexcept { return std::string(); }
+
+       template<typename ColumnType>
+       std::string getColumnName(ColumnType&&) const noexcept { return std::string(); }
+};
+
+template<typename Front, typename... Rest>
+class TablePack<Front, Rest...> : public TablePack<Rest...> {
+public:
+       using Table = Front;
+
+       explicit TablePack(Front&& front, Rest&& ...rest);
+       virtual ~TablePack() = default;
+
+       TablePack(const TablePack&) = delete;
+       TablePack& operator=(const TablePack&) = delete;
+
+       TablePack(TablePack&&) = default;
+       TablePack& operator=(TablePack&&) = default;
+
+       template<typename TableType>
+       std::string getName(TableType&& table) const noexcept;
+
+       template<typename ColumnType>
+       std::string getColumnName(ColumnType&& column) const noexcept;
+
+private:
+       using Base = TablePack<Rest...>;
+
+       Table table;
+};
+
+template<typename Front, typename... Rest>
+TablePack<Front, Rest...>::TablePack(Front&& front, Rest&& ...rest) :
+       Base(std::forward<Rest>(rest)...), table(front)
+{
+}
+
+template<typename Front, typename... Rest>
+template<typename TableType>
+std::string TablePack<Front, Rest...>::getName(TableType&& table) const noexcept
+{
+       if (this->table.compare(table))
+               return this->table.name;
+
+       return Base::template getName<TableType>(std::forward<TableType>(table));
+}
+
+template<typename Front, typename... Rest>
+template<typename ColumnType>
+std::string TablePack<Front, Rest...>::getColumnName(ColumnType&& column) const noexcept
+{
+       using DecayColumnType = typename std::decay<ColumnType>::type;
+       using DecayTableType = typename DecayColumnType::TableType;
+       if (this->table.compare(DecayTableType())) {
+               auto cname = this->table.getColumnName(column.type);
+               return this->table.name + "." + cname;
+       }
+
+       return Base::template getColumnName<ColumnType>(std::forward<ColumnType>(column));
+}
+
+} // namespace internal
+} // namespace tsqb
+} // namespace vist
diff --git a/src/vist/query-builder/table.hpp b/src/vist/query-builder/table.hpp
new file mode 100644 (file)
index 0000000..9bdafad
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+
+#pragma once
+
+#include "crud.hpp"
+#include "column.hpp"
+#include "column-pack.hpp"
+#include "tuple-helper.hpp"
+#include "util.hpp"
+
+#include <vector>
+#include <string>
+#include <sstream>
+
+namespace vist {
+namespace tsqb {
+
+template<typename... Columns>
+class Table : public Crud<Table<Columns...>> {
+public:
+       virtual ~Table() = default;
+
+       Table(const Table&) = delete;
+       Table& operator=(const Table&) = delete;
+
+       Table(Table&&) = default;
+       Table& operator=(Table&&) = default;
+
+       // Functions for Crud
+       template<typename Cs>
+       std::set<std::string> getTableNames(Cs&& tuple) const noexcept;
+       template<typename Cs>
+       std::vector<std::string> getColumnNames(Cs&& tuple) const noexcept;
+       template<typename That>
+       std::string getTableName(That&& type) const noexcept;
+       template<typename ColumnType>
+       std::string getColumnName(ColumnType&& type) const noexcept;
+
+       std::vector<std::string> getColumnNames(void) const noexcept;
+
+       template<typename That>
+       bool compare(const That& that) const noexcept;
+
+       int size() const noexcept;
+
+       operator std::string();
+
+       std::string name;
+       std::vector<std::string> cache;
+
+private:
+       using ColumnPackType = internal::ColumnPack<Columns...>;
+       using TableType = typename ColumnPackType::TableType;
+
+       explicit Table(const std::string& name, ColumnPackType&& columnPack);
+
+       template<typename ...Cs>
+       friend Table<Cs...> make_table(const std::string& name, Cs&& ...columns);
+
+       struct GetColumnNames {
+               const ColumnPackType& columnPack;
+               std::vector<std::string> names;
+
+               GetColumnNames(const ColumnPackType& columnPack) : columnPack(columnPack) {}
+
+               template <typename T>
+               void operator()(T&& type)
+               {
+                       auto name = this->columnPack.getName(std::forward<T>(type));
+                       if (!name.empty())
+                               names.emplace_back(name);
+               }
+       };
+
+       ColumnPackType columnPack;
+};
+
+template<typename ...Columns>
+Table<Columns...> make_table(const std::string& name, Columns&& ...cs)
+{
+       auto columnPack = internal::ColumnPack<Columns...>(std::forward<Columns>(cs)...);
+       return Table<Columns...>(name, std::move(columnPack));
+}
+
+template<typename... Columns>
+Table<Columns...>::Table(const std::string& name, ColumnPackType&& columnPack)
+       : name(name), columnPack(std::move(columnPack)) {}
+
+template<typename... Columns>
+template<typename Cs>
+std::set<std::string> Table<Columns...>::getTableNames(Cs&& tuple) const noexcept
+{
+       return {this->name};
+}
+
+template<typename... Columns>
+template<typename Cs>
+std::vector<std::string> Table<Columns...>::getColumnNames(Cs&& tuple) const noexcept
+{
+       GetColumnNames closure(this->columnPack);
+       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
+
+       return closure.names;
+}
+
+template<typename... Columns>
+template<typename That>
+std::string Table<Columns...>::getTableName(That&& type) const noexcept
+{
+       return this->name;
+}
+
+template<typename... Columns>
+template<typename ColumnType>
+std::string Table<Columns...>::getColumnName(ColumnType&& type) const noexcept
+{
+       return this->columnPack.getName(std::forward<ColumnType>(type));
+}
+
+template<typename... Columns>
+std::vector<std::string> Table<Columns...>::getColumnNames(void) const noexcept
+{
+       return this->columnPack.getNames();
+}
+
+template<typename... Columns>
+template<typename That>
+bool Table<Columns...>::compare(const That& that) const noexcept
+{
+       using This = TableType;
+       return type::compare(This(), that);
+}
+
+template<typename... Columns>
+Table<Columns...>::operator std::string()
+{
+       std::stringstream ss;
+       for (const auto& c : cache)
+               ss << c << " ";
+
+       this->cache.clear();
+       return util::rtrim(ss.str());
+}
+
+template<typename... Columns>
+int Table<Columns...>::size() const noexcept
+{
+       return this->columnPack.size();
+}
+
+} // namespace tsqb
+} // namespace vist
diff --git a/src/vist/query-builder/tests/query-builder.cpp b/src/vist/query-builder/tests/query-builder.cpp
new file mode 100644 (file)
index 0000000..ae6f75e
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ *  Copyright (c) 2017-present 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>
+
+#include <gtest/gtest.h>
+
+using namespace vist::tsqb;
+
+struct Admin {
+       int id;
+       std::string pkg;
+       int uid;
+       std::string key;
+       int removable;
+};
+
+struct ManagedPolicy {
+       int id;
+       int aid;
+       int pid;
+       int value;
+};
+
+struct PolicyDefinition {
+       int id;
+       int scope;
+       std::string name;
+       int ivalue;
+};
+
+auto admin = make_table("admin", make_column("id", &Admin::id),
+                                                                make_column("pkg", &Admin::pkg),
+                                                                make_column("uid", &Admin::uid),
+                                                                make_column("key", &Admin::key),
+                                                                make_column("removable", &Admin::removable));
+
+auto managedPolicy = make_table("managed_policy",
+                                                                make_column("id", &ManagedPolicy::id),
+                                                                make_column("aid", &ManagedPolicy::aid),
+                                                                make_column("pid", &ManagedPolicy::pid),
+                                                                make_column("value", &ManagedPolicy::value));
+
+auto policyDefinition = make_table("policy_definition",
+                                                                  make_column("id", &PolicyDefinition::id),
+                                                                  make_column("scope", &PolicyDefinition::scope),
+                                                                  make_column("name", &PolicyDefinition::name),
+                                                                  make_column("ivalue", &PolicyDefinition::ivalue));
+
+auto db = make_database("dpm", admin, managedPolicy, policyDefinition);
+
+class TsqbTests : public testing::Test {};
+
+TEST_F(TsqbTests, SELECT)
+{
+       std::string select1 = admin.select(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
+       std::string select2 = admin.select(&Admin::id, &Admin::uid, &Admin::key);
+
+       EXPECT_EQ(select1, "SELECT id, pkg, uid, key FROM admin");
+       EXPECT_EQ(select2, "SELECT id, uid, key FROM admin");
+}
+
+TEST_F(TsqbTests, SELECT_ALL)
+{
+       std::string select = admin.selectAll();
+
+       EXPECT_EQ(select, "SELECT * FROM admin");
+}
+
+TEST_F(TsqbTests, SELECT_WHERE)
+{
+       std::string select1 = admin.select(&Admin::uid, &Admin::key)
+                                                          .where(expr(&Admin::id) > 3);
+       std::string select2 = admin.selectAll().where(expr(&Admin::uid) > 3);
+       std::string select3 = admin.selectAll().where(expr(&Admin::uid) > 3 &&
+                                                                                                 expr(&Admin::pkg) == "dpm");
+       std::string select4 = admin.selectAll().where(expr(&Admin::uid) > 3 ||
+                                                                                                 expr(&Admin::pkg) == "dpm");
+
+       EXPECT_EQ(select1, "SELECT uid, key FROM admin WHERE id > ?");
+       EXPECT_EQ(select2, "SELECT * FROM admin WHERE uid > ?");
+       EXPECT_EQ(select3, "SELECT * FROM admin WHERE uid > ? AND pkg = ?");
+       EXPECT_EQ(select4, "SELECT * FROM admin WHERE uid > ? OR pkg = ?");
+}
+
+TEST_F(TsqbTests, SELECT_DISTINCT)
+{
+       std::string select = admin.select(distinct(&Admin::uid, &Admin::key))
+                                                          .where(expr(&Admin::id) > 3);
+
+       EXPECT_EQ(select, "SELECT DISTINCT uid, key FROM admin WHERE id > ?");
+}
+
+TEST_F(TsqbTests, UPDATE)
+{
+       int uid = 0, id = 1;
+       std::string update1 = admin.update(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
+       std::string update2 = admin.update(&Admin::key).where(expr(&Admin::uid) == uid &&
+                                                                                                                 expr(&Admin::id) == id);
+       std::string update3 = admin.update(&Admin::key, &Admin::pkg)
+                                                          .where(expr(&Admin::uid) == 0 && expr(&Admin::id) == 1);
+
+       EXPECT_EQ(update1, "UPDATE admin SET id = ?, pkg = ?, uid = ?, key = ?");
+       EXPECT_EQ(update2, "UPDATE admin SET key = ? WHERE uid = ? AND id = ?");
+       EXPECT_EQ(update3, "UPDATE admin SET key = ?, pkg = ? WHERE uid = ? AND id = ?");
+}
+
+TEST_F(TsqbTests, DELETE)
+{
+       std::string delete1 = admin.remove();
+       std::string delete2 = admin.remove().where(expr(&Admin::pkg) == "dpm" &&
+                                                                                          expr(&Admin::uid) == 3);
+
+       EXPECT_EQ(delete1, "DELETE FROM admin");
+       EXPECT_EQ(delete2, "DELETE FROM admin WHERE pkg = ? AND uid = ?");
+}
+
+TEST_F(TsqbTests, INSERT)
+{
+       std::string insert1 = admin.insert(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
+       std::string insert2 = admin.insert(&Admin::id, &Admin::pkg, &Admin::key);
+
+       EXPECT_EQ(insert1, "INSERT INTO admin (id, pkg, uid, key) VALUES (?, ?, ?, ?)");
+       EXPECT_EQ(insert2, "INSERT INTO admin (id, pkg, key) VALUES (?, ?, ?)");
+}
+
+TEST_F(TsqbTests, TYPE_SAFE)
+{
+/*
+ * Below cause complie error since expression types are dismatch.
+
+       std::string type_unsafe1 = admin.selectAll().where(expr(&Admin::uid) > "dpm");
+       std::string type_unsafe2 = admin.selectAll().where(expr(&Admin::uid) == "dpm");
+       std::string type_unsafe3 = admin.selectAll().where(expr(&Admin::pkg) == 3);
+       int pkg = 3;
+       std::string type_unsafe4 = admin.selectAll().where(expr(&Admin::pkg) < pkg);
+       std::string type_unsafe5 = admin.remove().where(expr(&Admin::pkg) == "dpm" &&
+                                                                                                       expr(&Admin::uid) == "dpm");
+*/
+}
+
+TEST_F(TsqbTests, MULTI_SELECT)
+{
+       std::string multiSelect1 = db.select(&Admin::uid, &Admin::key,
+                                                                                &ManagedPolicy::id, &ManagedPolicy::value);
+       std::string multiSelect2 = db.select(&Admin::uid, &Admin::key,
+                                                                                &ManagedPolicy::id, &ManagedPolicy::value)
+                                                                .where(expr(&Admin::uid) > 0 && expr(&ManagedPolicy::id) == 3);
+
+       EXPECT_EQ(multiSelect1, "SELECT admin.uid, admin.key, managed_policy.id, "
+                                                       "managed_policy.value FROM admin, managed_policy");
+       EXPECT_EQ(multiSelect2, "SELECT admin.uid, admin.key, managed_policy.id, "
+                                                       "managed_policy.value FROM admin, managed_policy "
+                                                       "WHERE admin.uid > ? AND managed_policy.id = ?");
+}
+
+TEST_F(TsqbTests, JOIN)
+{
+       std::string join1 = db.select(&Admin::uid, &Admin::key)
+                                                 .join<PolicyDefinition>(condition::Join::LEFT_OUTER);
+       std::string join2 = db.select(&Admin::uid, &Admin::key)
+                                                 .join<ManagedPolicy>(condition::Join::CROSS);
+       std::string join3 = db.select(&ManagedPolicy::value)
+                                                 .join<PolicyDefinition>()
+                                                 .on(expr(&ManagedPolicy::pid) == expr(&PolicyDefinition::id))
+                                                 .join<Admin>()
+                                                 .on(expr(&ManagedPolicy::aid) == expr(&Admin::id))
+                                                 .where(expr(&ManagedPolicy::pid) == 99);
+
+       EXPECT_EQ(join1, "SELECT admin.uid, admin.key FROM admin "
+                                        "LEFT OUTER JOIN policy_definition");
+       EXPECT_EQ(join2, "SELECT admin.uid, admin.key FROM admin "
+                                        "CROSS JOIN managed_policy");
+       EXPECT_EQ(join3, "SELECT managed_policy.value FROM managed_policy "
+                                        "INNER JOIN policy_definition "
+                                        "ON managed_policy.pid = policy_definition.id "
+                                        "INNER JOIN admin ON managed_policy.aid = admin.id "
+                                        "WHERE managed_policy.pid = ?");
+}
diff --git a/src/vist/query-builder/tuple-helper.hpp b/src/vist/query-builder/tuple-helper.hpp
new file mode 100644 (file)
index 0000000..23e2558
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+
+#pragma once
+
+#include <tuple>
+
+namespace vist {
+namespace tsqb {
+namespace tuple_helper {
+namespace internal {
+
+template<int n, typename T, typename C>
+class Iterator {
+public:
+       Iterator(const T& tuple, C&& closure) {
+               Iterator<n - 1, T, C> iter(tuple, std::forward<C>(closure));
+               closure(std::get<n-1>(tuple));
+       }
+};
+
+template<typename T, typename C>
+class Iterator<0, T, C> {
+public:
+       Iterator(const T&, C&&) {}
+};
+
+} // namespace internal
+
+template<typename T, typename C>
+void for_each(const T& tuple, C&& closure)
+{
+       using Iter = internal::Iterator<std::tuple_size<T>::value, T, C>;
+       Iter iter(tuple, std::forward<C>(closure));
+}
+
+} // namspace tuple-hepler
+} // namspace tsqb
+} // namspace vist
diff --git a/src/vist/query-builder/type.hpp b/src/vist/query-builder/type.hpp
new file mode 100644 (file)
index 0000000..17882a5
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+
+#pragma once
+
+#include <type_traits>
+
+namespace vist {
+namespace tsqb {
+namespace type {
+
+template<typename L, typename R>
+bool cast_compare(L l, R r)
+{
+       return l == reinterpret_cast<L>(r);
+}
+
+template<typename L, typename R>
+bool compare(L l, R r)
+{
+       return std::is_same<L, R>::value;
+}
+
+template<typename L, typename R>
+void assert_compare(L l, R r)
+{
+       static_assert(std::is_same<L, R>::value, "Type is unsafe.");
+}
+
+} // namespace type
+} // namespace tsqb
+} // namespace vist
diff --git a/src/vist/query-builder/util.hpp b/src/vist/query-builder/util.hpp
new file mode 100644 (file)
index 0000000..6156a17
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ *  Copyright (c) 2017-present 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
+ */
+
+#pragma once
+
+#include <string>
+#include <algorithm>
+#include <cctype>
+
+namespace vist {
+namespace tsqb {
+namespace util {
+
+inline std::string rtrim(std::string&& s)
+{
+       auto predicate = [](unsigned char c){ return !std::isspace(c); };
+       auto base = std::find_if(s.rbegin(), s.rend(), predicate).base();
+       s.erase(base, s.end());
+       return s;
+}
+
+} // namespace util
+} // namespace tsqb
+} // namespace vist
diff --git a/src/vist/service/tests/core-tests.cpp b/src/vist/service/tests/core-tests.cpp
deleted file mode 100644 (file)
index f60e602..0000000
+++ /dev/null
@@ -1,61 +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.h" 
-
-#include <iostream>
-#include <chrono>
-#include <thread>
-
-#include <vist/policy/core/policy-manager.h>
-
-using namespace vist;
-
-class CoreTests : public testing::Test {};
-
-TEST_F(CoreTests, query_select) {
-       auto rows = Vist::Query("SELECT * FROM policy");
-
-       EXPECT_TRUE(rows.size() > 0);
-
-       std::string statement = "SELECT * FROM policy WHERE name = 'bluetooth'";
-       rows = Vist::Query(statement);
-
-       EXPECT_EQ(rows.size(), 1);
-       EXPECT_EQ(rows[0]["name"], "bluetooth");
-}
-
-TEST_F(CoreTests, query_update) {
-       auto& manager = policy::PolicyManager::Instance();
-       manager.enroll("admin");
-
-       std::string statement = "SELECT * FROM policy WHERE name = 'bluetooth'";
-       auto rows = Vist::Query(statement);
-       /// Initial policy value
-       EXPECT_EQ(rows[0]["value"], std::to_string(1));
-
-       statement = "UPDATE policy SET value = '3' WHERE name = 'bluetooth'";
-       rows = Vist::Query(statement);
-       EXPECT_EQ(rows.size(), 0);
-
-       statement = "SELECT * FROM policy WHERE name = 'bluetooth'";
-       rows = Vist::Query(statement);
-       EXPECT_EQ(rows[0]["value"], std::to_string(3));
-
-       manager.disenroll("admin");
-}
diff --git a/src/vist/service/tests/core.cpp b/src/vist/service/tests/core.cpp
new file mode 100644 (file)
index 0000000..4153827
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ *  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/service/vist.hpp>
+#include <vist/policy/core/policy-manager.hpp>
+
+#include <iostream>
+#include <chrono>
+#include <thread>
+
+using namespace vist;
+
+class CoreTests : public testing::Test {};
+
+TEST_F(CoreTests, query_select)
+{
+       auto rows = Vist::Query("SELECT * FROM policy");
+
+       EXPECT_TRUE(rows.size() > 0);
+
+       std::string statement = "SELECT * FROM policy WHERE name = 'bluetooth'";
+       rows = Vist::Query(statement);
+
+       EXPECT_EQ(rows.size(), 1);
+       EXPECT_EQ(rows[0]["name"], "bluetooth");
+}
+
+TEST_F(CoreTests, query_update)
+{
+       auto& manager = policy::PolicyManager::Instance();
+       manager.enroll("admin");
+
+       std::string statement = "SELECT * FROM policy WHERE name = 'bluetooth'";
+       auto rows = Vist::Query(statement);
+       /// Initial policy value
+       EXPECT_EQ(rows[0]["value"], std::to_string(1));
+
+       statement = "UPDATE policy SET value = '3' WHERE name = 'bluetooth'";
+       rows = Vist::Query(statement);
+       EXPECT_EQ(rows.size(), 0);
+
+       statement = "SELECT * FROM policy WHERE name = 'bluetooth'";
+       rows = Vist::Query(statement);
+       EXPECT_EQ(rows[0]["value"], std::to_string(3));
+
+       manager.disenroll("admin");
+}
index cb0ec41db064e71f588e0195f753fc8e09741465..88bc8ed365ee7909c24578f76376e03b1e9650be 100644 (file)
  *  limitations under the License
  */
 
-#include "vist.h"
+#include "vist.hpp"
 
-#include <vist/common/ipc/server.h>
-#include <vist/common/audit/logger.h>
+#include <vist/ipc/server.hpp>
+#include <vist/logger.hpp>
 
 #include <stdexcept>
 
diff --git a/src/vist/service/vist.h b/src/vist/service/vist.h
deleted file mode 100644 (file)
index 03cf9e9..0000000
+++ /dev/null
@@ -1,57 +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
- */
-
-#pragma once
-
-#include <map>
-#include <string>
-#include <vector>
-
-namespace vist {
-
-using Row = std::map<std::string, std::string>;
-using Rows = std::vector<Row>;
-
-class Vist final {
-public:
-       Vist(const Vist&) = delete;
-       Vist& operator=(const Vist&) = delete;
-
-       Vist(Vist&&) = default;
-       Vist& operator=(Vist&&) = default;
-
-       /// Exposed method (API)
-       Rows query(const std::string& statement);
-
-       static Vist& Instance()
-       {
-               static Vist instance;
-               return instance;
-       }
-
-       static Rows Query(const std::string& statement)
-       {
-               return Vist::Instance().query(statement);
-       }
-
-       void start();
-
-private:
-       explicit Vist();
-       ~Vist() = default;
-};
-
-} // namespace vist
diff --git a/src/vist/service/vist.hpp b/src/vist/service/vist.hpp
new file mode 100644 (file)
index 0000000..03cf9e9
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <map>
+#include <string>
+#include <vector>
+
+namespace vist {
+
+using Row = std::map<std::string, std::string>;
+using Rows = std::vector<Row>;
+
+class Vist final {
+public:
+       Vist(const Vist&) = delete;
+       Vist& operator=(const Vist&) = delete;
+
+       Vist(Vist&&) = default;
+       Vist& operator=(Vist&&) = default;
+
+       /// Exposed method (API)
+       Rows query(const std::string& statement);
+
+       static Vist& Instance()
+       {
+               static Vist instance;
+               return instance;
+       }
+
+       static Rows Query(const std::string& statement)
+       {
+               return Vist::Instance().query(statement);
+       }
+
+       void start();
+
+private:
+       explicit Vist();
+       ~Vist() = default;
+};
+
+} // namespace vist
diff --git a/src/vist/tests/exception.cpp b/src/vist/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/tsqb/CMakeLists.txt b/src/vist/tsqb/CMakeLists.txt
deleted file mode 100644 (file)
index d6bf3fe..0000000
+++ /dev/null
@@ -1,16 +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
-
-FILE(GLOB TSQB_TESTS "tests/*.cpp")
-ADD_VIST_TEST(${TSQB_TESTS})
diff --git a/src/vist/tsqb/include/column-pack.hxx b/src/vist/tsqb/include/column-pack.hxx
deleted file mode 100644 (file)
index 9688e8e..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file column-pack.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Tie different types of columns
- */
-
-#pragma once
-
-#include "type.hxx"
-
-#include <string>
-#include <vector>
-
-namespace tsqb {
-namespace internal {
-
-template<typename... Base>
-class ColumnPack {
-public:
-       virtual ~ColumnPack() = default;
-
-       template<typename ColumnType>
-       std::string getName(ColumnType&&) const noexcept { return std::string(); }
-       std::vector<std::string> getNames(void) const noexcept { return {}; }
-
-       int size() const noexcept { return 0; }
-};
-
-template<typename Front, typename... Rest>
-class ColumnPack<Front, Rest...> : public ColumnPack<Rest...> {
-public:
-       using Column = Front;
-       using TableType = typename Column::TableType;
-
-       explicit ColumnPack(Front&& front, Rest&& ...rest);
-       virtual ~ColumnPack() = default;
-
-       ColumnPack(const ColumnPack&) = delete;
-       ColumnPack& operator=(const ColumnPack&) = delete;
-
-       ColumnPack(ColumnPack&&) = default;
-       ColumnPack& operator=(ColumnPack&&) = default;
-
-       template<typename ColumnType>
-       std::string getName(ColumnType&& type) const noexcept;
-       std::vector<std::string> getNames(void) const noexcept;
-
-       int size() const noexcept { return Base::size() + 1; }
-
-private:
-       using Base = ColumnPack<Rest...>;
-
-       Column column;
-};
-
-template<typename Front, typename... Rest>
-ColumnPack<Front, Rest...>::ColumnPack(Front&& front, Rest&& ...rest) :
-       Base(std::forward<Rest>(rest)...), column(front)
-{
-}
-
-template<typename Front, typename... Rest>
-std::vector<std::string> ColumnPack<Front, Rest...>::getNames(void) const noexcept
-{
-       auto names = Base::getNames();
-       names.push_back(this->column.name);
-
-       return std::move(names);
-}
-
-template<typename Front, typename... Rest>
-template<typename ColumnType>
-std::string ColumnPack<Front, Rest...>::getName(ColumnType&& type) const noexcept
-{
-       if (type::cast_compare(column.type, std::forward<ColumnType>(type)))
-               return column.name;
-
-       return Base::template getName<ColumnType>(std::forward<ColumnType>(type));
-}
-
-} // namespace internal
-} // namespace tsqb
diff --git a/src/vist/tsqb/include/column.hxx b/src/vist/tsqb/include/column.hxx
deleted file mode 100644 (file)
index ca17415..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file culumn.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Capture member pointer of struct and use it for matching with column
- */
-
-#pragma once
-
-#include <string>
-#include <tuple>
-
-namespace tsqb {
-
-template<typename Object, typename Field>
-struct Column {
-       using Type = Field Object::*;
-       using FieldType = Field;
-       using TableType = Object;
-
-       std::string name;
-       Type type;
-};
-
-template<typename O, typename F>
-Column<O, F> make_column(const std::string& name, F O::*field)
-{
-       return {name, field};
-}
-
-template<typename Type>
-struct Distinct {
-       Type value;
-};
-
-template<typename... Args>
-auto distinct(Args&&... args) -> decltype(Distinct<std::tuple<Args...>>())
-{
-       return {std::make_tuple(std::forward<Args>(args)...)};
-}
-
-} // namespace tsqb
diff --git a/src/vist/tsqb/include/condition.hxx b/src/vist/tsqb/include/condition.hxx
deleted file mode 100644 (file)
index 7ec13da..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file condition.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Represent the condition statement of SQL
- */
-
-#pragma once
-
-#include "type.hxx"
-
-namespace tsqb {
-namespace condition {
-
-struct Base {};
-
-template<typename L, typename R>
-struct And : public Base {
-       L l;
-       R r;
-
-       And(L l, R r) : l(l), r(r) {}
-       operator std::string() const
-       {
-               return "AND";
-       }
-};
-
-template<typename L, typename R>
-struct Or : public Base {
-       L l;
-       R r;
-
-       Or(L l, R r) : l(l), r(r) {}
-       operator std::string() const
-       {
-               return "OR";
-       }
-};
-
-template<typename L, typename R>
-struct Binary : public Base {
-       L l;
-       R r;
-
-       Binary(L l, R r) : l(l), r(r)
-       {
-               using FieldType = typename L::FieldType;
-               type::assert_compare(FieldType(), r);
-       }
-};
-
-template<typename L>
-struct Binary<L, const char*> : public Base {
-       L l;
-       std::string r;
-
-       Binary(L l, const char* r) : l(l), r(r)
-       {
-               using FieldType = typename L::FieldType;
-               type::assert_compare(FieldType(), std::string());
-       }
-};
-
-enum class Join : int {
-       INNER,
-       CROSS,
-       LEFT_OUTER,
-       RIGHT_OUTER,
-       FULL_OUTER
-};
-
-inline std::string to_string(Join type)
-{
-       switch (type) {
-       case Join::CROSS: return "CROSS";
-       case Join::LEFT_OUTER: return "LEFT OUTER";
-       case Join::RIGHT_OUTER: return "RIGHT OUTER";
-       case Join::FULL_OUTER: return "FULL OUTER";
-       case Join::INNER:
-       default:
-               return "INNER";
-       }
-}
-
-} // namespace condition
-} // namespace tsqb
diff --git a/src/vist/tsqb/include/crud.hxx b/src/vist/tsqb/include/crud.hxx
deleted file mode 100644 (file)
index be48c86..0000000
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file crud.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Represent four basic functions of CRUD
- */
-
-#pragma once
-
-#include "column.hxx"
-#include "expression.hxx"
-
-#include <string>
-#include <sstream>
-
-namespace tsqb {
-
-template<typename T>
-class Crud {
-public:
-       template<typename... ColumnTypes>
-       T& select(ColumnTypes&&... cts);
-
-       template<typename Type>
-       T& select(Distinct<Type> distinct);
-
-       template<typename TableType>
-       T& selectAll(void);
-
-       T& selectAll(void);
-
-       template<typename... ColumnTypes>
-       T& update(ColumnTypes&&... cts);
-
-       template<typename... ColumnTypes>
-       T& insert(ColumnTypes&&... cts);
-
-       template<typename... ColumnTypes>
-       T& remove(ColumnTypes&&... cts);
-
-       template<typename Expr>
-       T& where(Expr expr);
-
-private:
-       template<typename ColumnTuple>
-       T& selectInternal(ColumnTuple&& ct, bool distinct = false);
-
-       template<typename L, typename R>
-       std::string processWhere(condition::And<L,R>& expr);
-
-       template<typename L, typename R>
-       std::string processWhere(condition::Or<L,R>& expr);
-
-       template<typename Expr>
-       std::string processWhere(Expr expr);
-};
-
-template<typename T>
-template<typename... ColumnTypes>
-T& Crud<T>::select(ColumnTypes&&... cts)
-{
-       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
-
-       return this->selectInternal(std::move(columnTuple));
-}
-
-template<typename T>
-template<typename Type>
-T& Crud<T>::select(Distinct<Type> distinct)
-{
-       return this->selectInternal(std::move(distinct.value), true);
-}
-
-template<typename T>
-T& Crud<T>::selectAll(void)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       std::stringstream ss;
-       ss << "SELECT * FROM " << static_cast<T*>(this)->name;
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename TableType>
-T& Crud<T>::selectAll(void)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       std::stringstream ss;
-       auto tableName = static_cast<T*>(this)->getTableName(TableType());
-       ss << "SELECT * FROM " << tableName;
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename ColumnTuple>
-T& Crud<T>::selectInternal(ColumnTuple&& ct, bool distinct)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(ct));
-       auto tableNames = static_cast<T*>(this)->getTableNames(std::move(ct));
-
-       std::stringstream ss;
-       ss << "SELECT ";
-
-       if (distinct)
-               ss << "DISTINCT ";
-
-       int i = 0;
-       for (const auto& c : columnNames) {
-               ss << c;
-
-               if (i++ < columnNames.size() - 1)
-                       ss << ", ";
-       }
-
-       ss << " FROM ";
-
-       i = 0;
-       for (const auto& t : tableNames) {
-               ss << t;
-
-               if (i++ < tableNames.size() - 1)
-                       ss << ", ";
-       }
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename... ColumnTypes>
-T& Crud<T>::update(ColumnTypes&&... cts)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
-       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
-
-       std::stringstream ss;
-       ss << "UPDATE " << static_cast<T*>(this)->name << " ";
-       ss << "SET ";
-
-       int i = 0;
-       for (const auto& c : columnNames) {
-               ss << c << " = ?";
-
-               if (i++ < columnNames.size() - 1)
-                       ss << ", ";
-       }
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename... ColumnTypes>
-T& Crud<T>::insert(ColumnTypes&&... cts)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
-       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
-
-       std::stringstream ss;
-       ss << "INSERT INTO " << static_cast<T*>(this)->name << " (";
-
-       const int columnCount = columnNames.size();
-       for (int i = 0; i < columnCount; i++) {
-               ss << columnNames[i];
-               if (i < columnCount - 1)
-                       ss << ", ";
-       }
-
-       ss << ") VALUES (";
-
-       for (int i = 0; i < columnCount; i++) {
-               ss << "?";
-               if (i < columnCount - 1)
-                       ss << ", ";
-       }
-
-       ss << ")";
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename... ColumnTypes>
-T& Crud<T>::remove(ColumnTypes&&... cts)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
-       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
-
-       std::stringstream ss;
-       ss << "DELETE FROM " << static_cast<T*>(this)->name;
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename Expr>
-T& Crud<T>::where(Expr expr)
-{
-       std::stringstream ss;
-       ss << "WHERE " << this->processWhere(expr);
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename L, typename R>
-std::string Crud<T>::processWhere(condition::And<L,R>& expr)
-{
-       std::stringstream ss;
-       ss << this->processWhere(expr.l) << " ";
-       ss << static_cast<std::string>(expr) << " ";
-       ss << this->processWhere(expr.r);
-
-       return ss.str();
-}
-
-template<typename T>
-template<typename L, typename R>
-std::string Crud<T>::processWhere(condition::Or<L,R>& expr)
-{
-       std::stringstream ss;
-       ss << this->processWhere(expr.l) << " ";
-       ss << static_cast<std::string>(expr) << " ";
-       ss << this->processWhere(expr.r);
-
-       return ss.str();
-}
-
-template<typename T>
-template<typename Expr>
-std::string Crud<T>::processWhere(Expr expr)
-{
-       std::stringstream ss;
-       ss << static_cast<T*>(this)->getColumnName(expr.l.type);
-       ss << " " << std::string(expr) << " ?";
-
-       return ss.str();
-}
-
-} // namespace tsqb
diff --git a/src/vist/tsqb/include/database.hxx b/src/vist/tsqb/include/database.hxx
deleted file mode 100644 (file)
index 0c8bf54..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file database.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Represent the database scheme of SQL
- */
-
-#pragma once
-
-#include "crud.hxx"
-#include "condition.hxx"
-#include "expression.hxx"
-#include "table-pack.hxx"
-#include "tuple-helper.hxx"
-#include "util.hxx"
-
-#include <vector>
-#include <set>
-#include <string>
-#include <sstream>
-#include <algorithm>
-
-namespace tsqb {
-
-template<typename... Tables>
-class Database : public Crud<Database<Tables...>> {
-public:
-       using Self = Database<Tables...>;
-
-       virtual ~Database() = default;
-
-       Database(const Database&) = delete;
-       Database& operator=(const Database&) = delete;
-
-       Database(Database&&) = default;
-       Database& operator=(Database&&) = default;
-
-       // Functions for Crud
-       template<typename Cs>
-       std::set<std::string> getTableNames(Cs&& tuple) const noexcept;
-       template<typename Cs>
-       std::vector<std::string> getColumnNames(Cs&& tuple) const noexcept;
-       template<typename TableType>
-       std::string getTableName(TableType&& type) const noexcept;
-       template<typename ColumnType>
-       std::string getColumnName(ColumnType&& type) const noexcept;
-
-       template<typename Table>
-       Self& join(condition::Join type = condition::Join::INNER);
-
-       template<typename Expr>
-       Self& on(Expr expr);
-
-       operator std::string();
-
-       std::string name;
-       std::vector<std::string> cache;
-
-private:
-       using TablePackType = internal::TablePack<Tables...>;
-       using ColumnNames = std::vector<std::string>;
-       using TableNames = std::set<std::string>;
-
-       explicit Database(const std::string& name, TablePackType&& tablePack);
-
-       template<typename ...Ts>
-       friend Database<Ts...> make_database(const std::string& name, Ts&& ...tables);
-
-       struct GetTableNames {
-               const TablePackType& tablePack;
-               std::set<std::string> names;
-               GetTableNames(const TablePackType& tablePack) : tablePack(tablePack) {}
-
-               template <typename T>
-               void operator()(T&& type)
-               {
-                       auto column = make_column("anonymous", type);
-                       using TableType = typename decltype(column)::TableType;
-                       auto name = this->tablePack.getName(TableType());
-                       if (!name.empty())
-                               names.emplace(name);
-               }
-       };
-
-       struct GetColumnNames {
-               const TablePackType& tablePack;
-               std::vector<std::string> names;
-
-               GetColumnNames(const TablePackType& tablePack) : tablePack(tablePack) {}
-
-               template <typename T>
-               void operator()(T&& type)
-               {
-                       auto column = make_column("anonymous", type);
-                       auto name = this->tablePack.getColumnName(std::move(column));
-                       if (!name.empty())
-                               names.emplace_back(name);
-               }
-       };
-
-       TablePackType tablePack;
-};
-
-template<typename ...Tables>
-Database<Tables...> make_database(const std::string& name, Tables&& ...tables)
-{
-       auto tablePack = internal::TablePack<Tables...>(std::forward<Tables>(tables)...);
-       return Database<Tables...>(name, std::move(tablePack));
-}
-
-template<typename ...Tables>
-Database<Tables...>::Database(const std::string& name, TablePackType&& tablePack)
-       : name(name), tablePack(std::move(tablePack)) {}
-
-template<typename... Tables>
-template<typename Table>
-Database<Tables...>& Database<Tables...>::join(condition::Join type)
-{
-       std::stringstream ss;
-       ss << condition::to_string(type) << " ";
-       ss << "JOIN ";
-       ss << this->tablePack.getName(Table());
-
-       this->cache.emplace_back(ss.str());
-       return *this;
-}
-
-template<typename... Tables>
-template<typename Expr>
-Database<Tables...>& Database<Tables...>::on(Expr expr)
-{
-       std::stringstream ss;
-       ss << "ON ";
-
-       auto lname = this->tablePack.getColumnName(std::move(expr.l));
-       ss << lname << " ";
-
-       ss << std::string(expr) << " ";
-
-       auto rname = this->tablePack.getColumnName(std::move(expr.r));
-       ss << rname;
-
-       this->cache.emplace_back(ss.str());
-       return *this;
-}
-
-template<typename... Tables>
-Database<Tables...>::operator std::string()
-{
-       std::stringstream ss;
-       for (const auto& c : cache)
-               ss << c << " ";
-
-       this->cache.clear();
-       return util::rtrim(ss.str());
-}
-
-template<typename... Tables>
-template<typename Cs>
-std::set<std::string> Database<Tables...>::getTableNames(Cs&& tuple) const noexcept
-{
-       GetTableNames closure(this->tablePack);
-       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
-
-       return closure.names;
-}
-
-template<typename... Tables>
-template<typename Cs>
-std::vector<std::string> Database<Tables...>::getColumnNames(Cs&& tuple) const noexcept
-{
-       GetColumnNames closure(this->tablePack);
-       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
-
-       return closure.names;
-}
-
-template<typename... Tables>
-template<typename TableType>
-std::string Database<Tables...>::getTableName(TableType&& type) const noexcept
-{
-       return this->tablePack.getName(std::forward<TableType>(type));
-}
-
-template<typename... Tables>
-template<typename ColumnType>
-std::string Database<Tables...>::getColumnName(ColumnType&& type) const noexcept
-{
-       auto column = make_column("anonymous", type);
-       return this->tablePack.getColumnName(std::move(column));
-}
-
-} // namespace tsqb
diff --git a/src/vist/tsqb/include/expression.hxx b/src/vist/tsqb/include/expression.hxx
deleted file mode 100644 (file)
index c901ab0..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file expression.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Represent the expression of SQL
- */
-
-#pragma once
-
-#include "column.hxx"
-#include "type.hxx"
-#include "condition.hxx"
-
-#include <type_traits>
-
-namespace tsqb {
-
-template<typename Type>
-struct Expression {
-       Type value;
-};
-
-template<typename O, typename F>
-Expression<Column<O, F>> expr(F O::*field)
-{
-       Column<O, F> anonymous = {"anonymous", field};
-       return {anonymous};
-}
-
-template<typename L, typename R>
-struct Lesser : public condition::Binary<L, R> {
-       using condition::Binary<L, R>::Binary;
-
-       operator std::string() const
-       {
-               return "<";
-       }
-};
-
-template<typename L, typename R>
-Lesser<L, R> operator<(Expression<L> expr, R r)
-{
-       return {expr.value, r};
-}
-
-template<typename L, typename R>
-struct Equal : public condition::Binary<L, R>
-{
-       using condition::Binary<L, R>::Binary;
-
-       operator std::string() const
-       {
-               return "=";
-       }
-};
-
-template<typename L, typename R>
-Equal<L, R> operator==(Expression<L> expr, R r)
-{
-       return {expr.value, r};
-}
-
-namespace join {
-
-template<typename L, typename R>
-struct Equal
-{
-       L l;
-       R r;
-
-       operator std::string() const
-       {
-               return "=";
-       }
-};
-
-} // namespace join
-
-template<typename L, typename R>
-join::Equal<L, R> operator==(Expression<L> l, Expression<R> r)
-{
-       return {l.value, r.value};
-}
-
-template<typename L, typename R>
-struct Greater : public condition::Binary<L, R>
-{
-       using condition::Binary<L, R>::Binary;
-
-       operator std::string() const
-       {
-               return ">";
-       }
-};
-
-template<typename L, typename R>
-Greater<L, R> operator>(Expression<L> expr, R r)
-{
-       return {expr.value, r};
-}
-
-template<bool B, typename T = void>
-using enable_if_t = typename std::enable_if<B, T>::type;
-
-template<typename T>
-using is_condition = typename std::is_base_of<condition::Base, T>;
-
-template<typename L,
-                typename R,
-                typename = typename tsqb::enable_if_t<is_condition<L>::value
-                                                        && tsqb::is_condition<R>::value>>
-condition::And<L, R> operator&&(const L& l, const R& r)
-{
-       return {l, r};
-}
-
-template<typename L,
-                typename R,
-                typename = typename tsqb::enable_if_t<is_condition<L>::value
-                                                        && tsqb::is_condition<R>::value>>
-condition::Or<L, R> operator||(const L& l, const R& r)
-{
-       return {l, r};
-}
-
-} // namespace tsqb
diff --git a/src/vist/tsqb/include/table-pack.hxx b/src/vist/tsqb/include/table-pack.hxx
deleted file mode 100644 (file)
index d192886..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file table-pack.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Tie diffirent types of tables
- */
-
-#pragma once
-
-#include <vector>
-#include <set>
-#include <string>
-
-namespace tsqb {
-namespace internal {
-
-template<typename... Base>
-class TablePack {
-public:
-       virtual ~TablePack() = default;
-
-       template<typename TableType>
-       std::string getName(TableType&&) const noexcept { return std::string(); }
-
-       template<typename ColumnType>
-       std::string getColumnName(ColumnType&&) const noexcept { return std::string(); }
-};
-
-template<typename Front, typename... Rest>
-class TablePack<Front, Rest...> : public TablePack<Rest...> {
-public:
-       using Table = Front;
-
-       explicit TablePack(Front&& front, Rest&& ...rest);
-       virtual ~TablePack() = default;
-
-       TablePack(const TablePack&) = delete;
-       TablePack& operator=(const TablePack&) = delete;
-
-       TablePack(TablePack&&) = default;
-       TablePack& operator=(TablePack&&) = default;
-
-       template<typename TableType>
-       std::string getName(TableType&& table) const noexcept;
-
-       template<typename ColumnType>
-       std::string getColumnName(ColumnType&& column) const noexcept;
-
-private:
-       using Base = TablePack<Rest...>;
-
-       Table table;
-};
-
-template<typename Front, typename... Rest>
-TablePack<Front, Rest...>::TablePack(Front&& front, Rest&& ...rest) :
-       Base(std::forward<Rest>(rest)...), table(front)
-{
-}
-
-template<typename Front, typename... Rest>
-template<typename TableType>
-std::string TablePack<Front, Rest...>::getName(TableType&& table) const noexcept
-{
-       if (this->table.compare(table))
-               return this->table.name;
-
-       return Base::template getName<TableType>(std::forward<TableType>(table));
-}
-
-template<typename Front, typename... Rest>
-template<typename ColumnType>
-std::string TablePack<Front, Rest...>::getColumnName(ColumnType&& column) const noexcept
-{
-       using DecayColumnType = typename std::decay<ColumnType>::type;
-       using DecayTableType = typename DecayColumnType::TableType;
-       if (this->table.compare(DecayTableType())) {
-               auto cname = this->table.getColumnName(column.type);
-               return this->table.name + "." + cname;
-       }
-
-       return Base::template getColumnName<ColumnType>(std::forward<ColumnType>(column));
-}
-
-} // namespace internal
-} // namespace tsqb
diff --git a/src/vist/tsqb/include/table.hxx b/src/vist/tsqb/include/table.hxx
deleted file mode 100644 (file)
index e1ac527..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file table.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Represent the table of SQL
- */
-
-#pragma once
-
-#include "crud.hxx"
-#include "column.hxx"
-#include "column-pack.hxx"
-#include "tuple-helper.hxx"
-#include "util.hxx"
-
-#include <vector>
-#include <string>
-#include <sstream>
-
-namespace tsqb {
-
-template<typename... Columns>
-class Table : public Crud<Table<Columns...>> {
-public:
-       virtual ~Table() = default;
-
-       Table(const Table&) = delete;
-       Table& operator=(const Table&) = delete;
-
-       Table(Table&&) = default;
-       Table& operator=(Table&&) = default;
-
-       // Functions for Crud
-       template<typename Cs>
-       std::set<std::string> getTableNames(Cs&& tuple) const noexcept;
-       template<typename Cs>
-       std::vector<std::string> getColumnNames(Cs&& tuple) const noexcept;
-       template<typename That>
-       std::string getTableName(That&& type) const noexcept;
-       template<typename ColumnType>
-       std::string getColumnName(ColumnType&& type) const noexcept;
-
-       std::vector<std::string> getColumnNames(void) const noexcept;
-
-       template<typename That>
-       bool compare(const That& that) const noexcept;
-
-       int size() const noexcept;
-
-       operator std::string();
-
-       std::string name;
-       std::vector<std::string> cache;
-
-private:
-       using ColumnPackType = internal::ColumnPack<Columns...>;
-       using TableType = typename ColumnPackType::TableType;
-
-       explicit Table(const std::string& name, ColumnPackType&& columnPack);
-
-       template<typename ...Cs>
-       friend Table<Cs...> make_table(const std::string& name, Cs&& ...columns);
-
-       struct GetColumnNames {
-               const ColumnPackType& columnPack;
-               std::vector<std::string> names;
-
-               GetColumnNames(const ColumnPackType& columnPack) : columnPack(columnPack) {}
-
-               template <typename T>
-               void operator()(T&& type)
-               {
-                       auto name = this->columnPack.getName(std::forward<T>(type));
-                       if (!name.empty())
-                               names.emplace_back(name);
-               }
-       };
-
-       ColumnPackType columnPack;
-};
-
-template<typename ...Columns>
-Table<Columns...> make_table(const std::string& name, Columns&& ...cs)
-{
-       auto columnPack = internal::ColumnPack<Columns...>(std::forward<Columns>(cs)...);
-       return Table<Columns...>(name, std::move(columnPack));
-}
-
-template<typename... Columns>
-Table<Columns...>::Table(const std::string& name, ColumnPackType&& columnPack)
-       : name(name), columnPack(std::move(columnPack)) {}
-
-template<typename... Columns>
-template<typename Cs>
-std::set<std::string> Table<Columns...>::getTableNames(Cs&& tuple) const noexcept
-{
-       return {this->name};
-}
-
-template<typename... Columns>
-template<typename Cs>
-std::vector<std::string> Table<Columns...>::getColumnNames(Cs&& tuple) const noexcept
-{
-       GetColumnNames closure(this->columnPack);
-       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
-
-       return closure.names;
-}
-
-template<typename... Columns>
-template<typename That>
-std::string Table<Columns...>::getTableName(That&& type) const noexcept
-{
-       return this->name;
-}
-
-template<typename... Columns>
-template<typename ColumnType>
-std::string Table<Columns...>::getColumnName(ColumnType&& type) const noexcept
-{
-       return this->columnPack.getName(std::forward<ColumnType>(type));
-}
-
-template<typename... Columns>
-std::vector<std::string> Table<Columns...>::getColumnNames(void) const noexcept
-{
-       return this->columnPack.getNames();
-}
-
-template<typename... Columns>
-template<typename That>
-bool Table<Columns...>::compare(const That& that) const noexcept
-{
-       using This = TableType;
-       return type::compare(This(), that);
-}
-
-template<typename... Columns>
-Table<Columns...>::operator std::string()
-{
-       std::stringstream ss;
-       for (const auto& c : cache)
-               ss << c << " ";
-
-       this->cache.clear();
-       return util::rtrim(ss.str());
-}
-
-template<typename... Columns>
-int Table<Columns...>::size() const noexcept
-{
-       return this->columnPack.size();
-}
-
-} // namespace tsqb
diff --git a/src/vist/tsqb/include/tuple-helper.hxx b/src/vist/tsqb/include/tuple-helper.hxx
deleted file mode 100644 (file)
index 495946e..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file tuple-helper.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Iterator method for tuple
- */
-
-#pragma once
-
-#include <tuple>
-
-namespace tsqb {
-namespace tuple_helper {
-namespace internal {
-
-template<int n, typename T, typename C>
-class Iterator {
-public:
-       Iterator(const T& tuple, C&& closure) {
-               Iterator<n - 1, T, C> iter(tuple, std::forward<C>(closure));
-               closure(std::get<n-1>(tuple));
-       }
-};
-
-template<typename T, typename C>
-class Iterator<0, T, C> {
-public:
-       Iterator(const T&, C&&) {}
-};
-
-} // namespace internal
-
-template<typename T, typename C>
-void for_each(const T& tuple, C&& closure)
-{
-       using Iter = internal::Iterator<std::tuple_size<T>::value, T, C>;
-       Iter iter(tuple, std::forward<C>(closure));
-}
-
-} // namspace tuple-hepler
-} // namspace tsqb
diff --git a/src/vist/tsqb/include/type.hxx b/src/vist/tsqb/include/type.hxx
deleted file mode 100644 (file)
index 939b3da..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file type.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Make type safety with compile time checking
- */
-
-#pragma once
-
-#include <type_traits>
-
-namespace tsqb {
-namespace type {
-
-template<typename L, typename R>
-bool cast_compare(L l, R r)
-{
-       return l == reinterpret_cast<L>(r);
-}
-
-template<typename L, typename R>
-bool compare(L l, R r)
-{
-       return std::is_same<L, R>::value;
-}
-
-template<typename L, typename R>
-void assert_compare(L l, R r)
-{
-       static_assert(std::is_same<L, R>::value, "Type is unsafe.");
-}
-
-} // namespace type
-} // namespace tsqb
diff --git a/src/vist/tsqb/include/util.hxx b/src/vist/tsqb/include/util.hxx
deleted file mode 100644 (file)
index e65583d..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file util.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- */
-
-#pragma once
-
-#include <string>
-#include <algorithm>
-#include <cctype>
-
-namespace tsqb {
-namespace util {
-
-inline std::string rtrim(std::string&& s)
-{
-       auto predicate = [](unsigned char c){ return !std::isspace(c); };
-       auto base = std::find_if(s.rbegin(), s.rend(), predicate).base();
-       s.erase(base, s.end());
-       return s;
-}
-
-} // namespace util
-} // namespace tsqb
diff --git a/src/vist/tsqb/tests/tsqb-tests.cpp b/src/vist/tsqb/tests/tsqb-tests.cpp
deleted file mode 100644 (file)
index 7770140..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file tsqb-tests.cpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Testcases of tsqb
- */
-
-#include "tsqb.hxx"
-
-#include <gtest/gtest.h>
-
-using namespace tsqb;
-
-struct Admin {
-       int id;
-       std::string pkg;
-       int uid;
-       std::string key;
-       int removable;
-};
-
-struct ManagedPolicy {
-       int id;
-       int aid;
-       int pid;
-       int value;
-};
-
-struct PolicyDefinition {
-       int id;
-       int scope;
-       std::string name;
-       int ivalue;
-};
-
-auto admin = make_table("admin", make_column("id", &Admin::id),
-                                                                make_column("pkg", &Admin::pkg),
-                                                                make_column("uid", &Admin::uid),
-                                                                make_column("key", &Admin::key),
-                                                                make_column("removable", &Admin::removable));
-
-auto managedPolicy = make_table("managed_policy",
-                                                                make_column("id", &ManagedPolicy::id),
-                                                                make_column("aid", &ManagedPolicy::aid),
-                                                                make_column("pid", &ManagedPolicy::pid),
-                                                                make_column("value", &ManagedPolicy::value));
-
-auto policyDefinition = make_table("policy_definition",
-                                                                  make_column("id", &PolicyDefinition::id),
-                                                                  make_column("scope", &PolicyDefinition::scope),
-                                                                  make_column("name", &PolicyDefinition::name),
-                                                                  make_column("ivalue", &PolicyDefinition::ivalue));
-
-auto db = make_database("dpm", admin, managedPolicy, policyDefinition);
-
-class TsqbTests : public testing::Test {};
-
-TEST_F(TsqbTests, SELECT)
-{
-       std::string select1 = admin.select(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
-       std::string select2 = admin.select(&Admin::id, &Admin::uid, &Admin::key);
-
-       EXPECT_EQ(select1, "SELECT id, pkg, uid, key FROM admin");
-       EXPECT_EQ(select2, "SELECT id, uid, key FROM admin");
-}
-
-TEST_F(TsqbTests, SELECT_ALL)
-{
-       std::string select = admin.selectAll();
-
-       EXPECT_EQ(select, "SELECT * FROM admin");
-}
-
-TEST_F(TsqbTests, SELECT_WHERE)
-{
-       std::string select1 = admin.select(&Admin::uid, &Admin::key)
-                                                          .where(expr(&Admin::id) > 3);
-       std::string select2 = admin.selectAll().where(expr(&Admin::uid) > 3);
-       std::string select3 = admin.selectAll().where(expr(&Admin::uid) > 3 &&
-                                                                                                 expr(&Admin::pkg) == "dpm");
-       std::string select4 = admin.selectAll().where(expr(&Admin::uid) > 3 ||
-                                                                                                 expr(&Admin::pkg) == "dpm");
-
-       EXPECT_EQ(select1, "SELECT uid, key FROM admin WHERE id > ?");
-       EXPECT_EQ(select2, "SELECT * FROM admin WHERE uid > ?");
-       EXPECT_EQ(select3, "SELECT * FROM admin WHERE uid > ? AND pkg = ?");
-       EXPECT_EQ(select4, "SELECT * FROM admin WHERE uid > ? OR pkg = ?");
-}
-
-TEST_F(TsqbTests, SELECT_DISTINCT)
-{
-       std::string select = admin.select(distinct(&Admin::uid, &Admin::key))
-                                                          .where(expr(&Admin::id) > 3);
-
-       EXPECT_EQ(select, "SELECT DISTINCT uid, key FROM admin WHERE id > ?");
-}
-
-TEST_F(TsqbTests, UPDATE)
-{
-       int uid = 0, id = 1;
-       std::string update1 = admin.update(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
-       std::string update2 = admin.update(&Admin::key).where(expr(&Admin::uid) == uid &&
-                                                                                                                 expr(&Admin::id) == id);
-       std::string update3 = admin.update(&Admin::key, &Admin::pkg)
-                                                          .where(expr(&Admin::uid) == 0 && expr(&Admin::id) == 1);
-
-       EXPECT_EQ(update1, "UPDATE admin SET id = ?, pkg = ?, uid = ?, key = ?");
-       EXPECT_EQ(update2, "UPDATE admin SET key = ? WHERE uid = ? AND id = ?");
-       EXPECT_EQ(update3, "UPDATE admin SET key = ?, pkg = ? WHERE uid = ? AND id = ?");
-}
-
-TEST_F(TsqbTests, DELETE)
-{
-       std::string delete1 = admin.remove();
-       std::string delete2 = admin.remove().where(expr(&Admin::pkg) == "dpm" &&
-                                                                                          expr(&Admin::uid) == 3);
-
-       EXPECT_EQ(delete1, "DELETE FROM admin");
-       EXPECT_EQ(delete2, "DELETE FROM admin WHERE pkg = ? AND uid = ?");
-}
-
-TEST_F(TsqbTests, INSERT)
-{
-       std::string insert1 = admin.insert(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
-       std::string insert2 = admin.insert(&Admin::id, &Admin::pkg, &Admin::key);
-
-       EXPECT_EQ(insert1, "INSERT INTO admin (id, pkg, uid, key) VALUES (?, ?, ?, ?)");
-       EXPECT_EQ(insert2, "INSERT INTO admin (id, pkg, key) VALUES (?, ?, ?)");
-}
-
-TEST_F(TsqbTests, TYPE_SAFE)
-{
-/*
- * Below cause complie error since expression types are dismatch.
-
-       std::string type_unsafe1 = admin.selectAll().where(expr(&Admin::uid) > "dpm");
-       std::string type_unsafe2 = admin.selectAll().where(expr(&Admin::uid) == "dpm");
-       std::string type_unsafe3 = admin.selectAll().where(expr(&Admin::pkg) == 3);
-       int pkg = 3;
-       std::string type_unsafe4 = admin.selectAll().where(expr(&Admin::pkg) < pkg);
-       std::string type_unsafe5 = admin.remove().where(expr(&Admin::pkg) == "dpm" &&
-                                                                                                       expr(&Admin::uid) == "dpm");
-*/
-}
-
-TEST_F(TsqbTests, MULTI_SELECT)
-{
-       std::string multiSelect1 = db.select(&Admin::uid, &Admin::key,
-                                                                                &ManagedPolicy::id, &ManagedPolicy::value);
-       std::string multiSelect2 = db.select(&Admin::uid, &Admin::key,
-                                                                                &ManagedPolicy::id, &ManagedPolicy::value)
-                                                                .where(expr(&Admin::uid) > 0 && expr(&ManagedPolicy::id) == 3);
-
-       EXPECT_EQ(multiSelect1, "SELECT admin.uid, admin.key, managed_policy.id, "
-                                                       "managed_policy.value FROM admin, managed_policy");
-       EXPECT_EQ(multiSelect2, "SELECT admin.uid, admin.key, managed_policy.id, "
-                                                       "managed_policy.value FROM admin, managed_policy "
-                                                       "WHERE admin.uid > ? AND managed_policy.id = ?");
-}
-
-TEST_F(TsqbTests, JOIN)
-{
-       std::string join1 = db.select(&Admin::uid, &Admin::key)
-                                                 .join<PolicyDefinition>(condition::Join::LEFT_OUTER);
-       std::string join2 = db.select(&Admin::uid, &Admin::key)
-                                                 .join<ManagedPolicy>(condition::Join::CROSS);
-       std::string join3 = db.select(&ManagedPolicy::value)
-                                                 .join<PolicyDefinition>()
-                                                 .on(expr(&ManagedPolicy::pid) == expr(&PolicyDefinition::id))
-                                                 .join<Admin>()
-                                                 .on(expr(&ManagedPolicy::aid) == expr(&Admin::id))
-                                                 .where(expr(&ManagedPolicy::pid) == 99);
-
-       EXPECT_EQ(join1, "SELECT admin.uid, admin.key FROM admin "
-                                        "LEFT OUTER JOIN policy_definition");
-       EXPECT_EQ(join2, "SELECT admin.uid, admin.key FROM admin "
-                                        "CROSS JOIN managed_policy");
-       EXPECT_EQ(join3, "SELECT managed_policy.value FROM managed_policy "
-                                        "INNER JOIN policy_definition "
-                                        "ON managed_policy.pid = policy_definition.id "
-                                        "INNER JOIN admin ON managed_policy.aid = admin.id "
-                                        "WHERE managed_policy.pid = ?");
-}
diff --git a/src/vist/tsqb/tsqb.hxx b/src/vist/tsqb/tsqb.hxx
deleted file mode 100644 (file)
index c3791f0..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- *  Copyright (c) 2017-present 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
- */
-/*
- * @file tsqb.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief TSQB is type-safe query builder
- */
-
-#pragma once
-
-#include "include/database.hxx"
-#include "include/table.hxx"
-#include "include/column.hxx"
-#include "include/expression.hxx"
-#include "include/condition.hxx"
-#include "include/util.hxx"