Enable dlog only when the vist is running on Tizen
authorSangwan Kwon <sangwan.kwon@samsung.com>
Mon, 23 Dec 2019 05:13:00 +0000 (14:13 +0900)
committer권상완/Security 2Lab(SR)/Engineer/삼성전자 <sangwan.kwon@samsung.com>
Fri, 27 Dec 2019 04:25:30 +0000 (13:25 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
src/vist/CMakeLists.txt
src/vist/client/CMakeLists.txt
src/vist/client/query.cpp
src/vist/main/main.cpp
src/vist/service/CMakeLists.txt
src/vist/service/tests/core.cpp
src/vist/service/vist.cpp [deleted file]
src/vist/service/vist.hpp [deleted file]
src/vist/service/vistd.cpp [new file with mode: 0644]
src/vist/service/vistd.hpp [new file with mode: 0644]

index 30d802656c882ada76ae12d727ef3390eaeb5dc2..65b8c3c699ca978e397fc80143b03680b875ae94 100644 (file)
@@ -24,6 +24,7 @@ IF(DEFINED GBS_BUILD)
        SET(DEPENDENCY sqlite3 dlog gflags)
        PKG_CHECK_MODULES(VIST_COMMON_DEPS REQUIRED ${DEPENDENCY})
        INCLUDE_DIRECTORIES(${VIST_COMMON_DEPS_INCLUDE_DIRS})
+       ADD_DEFINITIONS(-DTIZEN="TIZEN")
 ENDIF(DEFINED GBS_BUILD)
 
 INCLUDE_DIRECTORIES(SYSTEM . common ${VIST_COMMON_DEPS_INCLUDE_DIRS})
index 0cf045cc324b373f640822165fb9001616ad50d3..0655f15284aab1bb863192015e9779b1f8cf856b 100644 (file)
@@ -18,9 +18,7 @@ ADD_VIST_CLIENT_LIBRARY(vist_client query.cpp
                                                                        virtual-table.cpp)
 
 FILE(GLOB CLIENT_TESTS "tests/*.cpp")
-#IF(DEFINED GBS_BUILD)
-       ADD_VIST_TEST(${CLIENT_TESTS})
-       #ENDIF(DEFINED GBS_BUILD)
+ADD_VIST_TEST(${CLIENT_TESTS})
 
 ADD_LIBRARY(${TARGET_VIST_CLIENT_LIB} STATIC ${${TARGET_VIST_CLIENT_LIB}_SRCS})
 TARGET_LINK_LIBRARIES(${TARGET_VIST_CLIENT_LIB} ${VIST_CLIENT_DEPS_LIBRARIES}
index 5b1cbed63bb78bb63a120f423b230257f85ff552..dcb84bdf40527742fd2169d662f52cd55c21f500 100644 (file)
@@ -30,7 +30,7 @@ Rows Query::Execute(const std::string& statement)
        INFO(VIST_CLIENT) << "Query execution: " << statement;
        rmi::Remote remote(SOCK_ADDR);
 
-       auto query = REMOTE_METHOD(remote, &Vist::query);
+       auto query = REMOTE_METHOD(remote, &Vistd::query);
        return query.invoke<Rows>(statement);
 }
 
index 8e64bbcc50a7c44af6e1682149a2daf141e0f8c0..3288accdcf181950d138b8ea421d34c3571d58b3 100644 (file)
  *  limitations under the License
  */
 
-#include <vist/service/vist.hpp>
+#include <vist/service/vistd.hpp>
 
 #include <vist/exception.hpp>
 #include <vist/logger.hpp>
 
 #include <cstdlib>
 
+#ifdef TIZEN
+#include <vist/logger/dlog.hpp>
+#endif
+
 using namespace vist;
 
 int main() try {
-       Vist::Instance().start();
+#ifdef TIZEN
+       LogStream::Init(std::make_shared<Dlog>());
+#endif
+
+       Vistd::Instance().start();
+
        return EXIT_SUCCESS;
 } catch(const Exception<ErrCode>& e) {
        ERROR(VIST) << "Failed while daemon is running." << e.what();
index ee1c427b7971516e7aad5259177df8b7a0b5b524..983e1d2e4c0e5f6e46b218cdf5238b5a6bdce2c2 100644 (file)
@@ -12,7 +12,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License
 
-ADD_VIST_LIBRARY(vist_core vist.cpp)
+ADD_VIST_LIBRARY(vist_core vistd.cpp)
 
 FILE(GLOB CORE_TESTS "tests/*.cpp")
 ADD_VIST_TEST(${CORE_TESTS})
index 35a518de96802aefe123280e1bca9e4f84ae9394..8b329454e67fa4986554cfcb60f4add0558b5bdf 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <gtest/gtest.h>
 
-#include <vist/service/vist.hpp>
+#include <vist/service/vistd.hpp>
 #include <vist/policy/api.hpp>
 
 #include <iostream>
@@ -29,12 +29,12 @@ class CoreTests : public testing::Test {};
 
 TEST_F(CoreTests, query_select)
 {
-       auto rows = Vist::Query("SELECT * FROM policy");
+       auto rows = Vistd::Query("SELECT * FROM policy");
 
        EXPECT_TRUE(rows.size() > 0);
 
        std::string statement = "SELECT * FROM policy WHERE name = 'sample-int-policy'";
-       rows = Vist::Query(statement);
+       rows = Vistd::Query(statement);
 
        EXPECT_EQ(rows.size(), 1);
        EXPECT_EQ(rows[0]["name"], "sample-int-policy");
@@ -45,16 +45,16 @@ TEST_F(CoreTests, query_update)
        policy::API::Admin::Enroll("admin");
 
        std::string statement = "SELECT * FROM policy WHERE name = 'sample-int-policy'";
-       auto rows = Vist::Query(statement);
+       auto rows = Vistd::Query(statement);
        /// Initial policy value
        EXPECT_EQ(rows[0]["value"], "I/7");
 
        statement = "UPDATE policy SET value = 'I/10' WHERE name = 'sample-int-policy'";
-       rows = Vist::Query(statement);
+       rows = Vistd::Query(statement);
        EXPECT_EQ(rows.size(), 0);
 
        statement = "SELECT * FROM policy WHERE name = 'sample-int-policy'";
-       rows = Vist::Query(statement);
+       rows = Vistd::Query(statement);
        EXPECT_EQ(rows[0]["value"], "I/10");
 
        policy::API::Admin::Disenroll("admin");
diff --git a/src/vist/service/vist.cpp b/src/vist/service/vist.cpp
deleted file mode 100644 (file)
index be4b68c..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
- */
-
-#include "vist.hpp"
-
-#include <vist/rmi/gateway.hpp>
-#include <vist/logger.hpp>
-#include <vist/exception.hpp>
-
-#include <osquery/registry_interface.h>
-#include <osquery/sql.h>
-
-namespace {
-       const std::string SOCK_ADDR = "/tmp/.vist";
-} // anonymous namespace
-
-namespace vist {
-
-Vist::Vist()
-{
-       osquery::registryAndPluginInit();
-}
-
-void Vist::start()
-{
-       INFO(VIST) << "Vist daemon starts.";
-       rmi::Gateway gateway(SOCK_ADDR);
-
-       EXPOSE(gateway, this, &Vist::query);
-       gateway.start();
-}
-
-Rows Vist::query(const std::string& statement)
-{
-       osquery::SQL sql(statement, true);
-       if (!sql.ok())
-               THROW(ErrCode::RuntimeError) << "Faild to execute query: " << sql.getMessageString();
-
-       return std::move(sql.rows());
-}
-
-} // namespace vist
diff --git a/src/vist/service/vist.hpp b/src/vist/service/vist.hpp
deleted file mode 100644 (file)
index ab8b8df..0000000
+++ /dev/null
@@ -1,58 +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() = default;
-
-       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();
-};
-
-} // namespace vist
diff --git a/src/vist/service/vistd.cpp b/src/vist/service/vistd.cpp
new file mode 100644 (file)
index 0000000..0c16cff
--- /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
+ */
+
+#include "vistd.hpp"
+
+#include <vist/rmi/gateway.hpp>
+#include <vist/logger.hpp>
+#include <vist/exception.hpp>
+
+#include <osquery/registry_interface.h>
+#include <osquery/sql.h>
+
+namespace {
+       const std::string SOCK_ADDR = "/tmp/.vist";
+} // anonymous namespace
+
+namespace vist {
+
+Vistd::Vistd()
+{
+       osquery::registryAndPluginInit();
+}
+
+void Vistd::start()
+{
+       INFO(VIST) << "Vistd daemon starts.";
+       rmi::Gateway gateway(SOCK_ADDR);
+
+       EXPOSE(gateway, this, &Vistd::query);
+       gateway.start();
+}
+
+Rows Vistd::query(const std::string& statement)
+{
+       osquery::SQL sql(statement, true);
+       if (!sql.ok())
+               THROW(ErrCode::RuntimeError) << "Faild to execute query: " << sql.getMessageString();
+
+       return std::move(sql.rows());
+}
+
+} // namespace vist
diff --git a/src/vist/service/vistd.hpp b/src/vist/service/vistd.hpp
new file mode 100644 (file)
index 0000000..e5f4bb3
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ *  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 Vistd final {
+public:
+       ~Vistd() = default;
+
+       Vistd(const Vistd&) = delete;
+       Vistd& operator=(const Vistd&) = delete;
+
+       Vistd(Vistd&&) = default;
+       Vistd& operator=(Vistd&&) = default;
+
+       /// Exposed method (API)
+       Rows query(const std::string& statement);
+
+       static Vistd& Instance()
+       {
+               static Vistd instance;
+               return instance;
+       }
+
+       static Rows Query(const std::string& statement)
+       {
+               return Vistd::Instance().query(statement);
+       }
+
+       void start();
+
+private:
+       explicit Vistd();
+};
+
+} // namespace vist