ReportService for test PAD and DLP reports added
authori.metelytsia <i.metelytsia@samsung.com>
Thu, 28 Sep 2017 15:13:58 +0000 (18:13 +0300)
committeri.metelytsia <i.metelytsia@samsung.com>
Thu, 28 Sep 2017 15:13:58 +0000 (18:13 +0300)
device_core/nmdaemon/CMakeLists.txt
device_core/nmdaemon/main_thread.cpp
device_core/nmdaemon/report_service.cpp [new file with mode: 0644]
device_core/nmdaemon/report_service.h [new file with mode: 0644]
device_core/utest/CMakeLists.txt
device_core/utest/test_report_service.cpp [new file with mode: 0644]

index e60c1cb..278d52f 100644 (file)
@@ -16,6 +16,7 @@ file(GLOB DPM_SOURCES dpm/*.cpp)
 file(GLOB NMDAEMON_SOURCES *.cpp)
 if("${FLAVOR}" STREQUAL "UBUNTU")
         list(REMOVE_ITEM NMDAEMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/audit_trail_client.cpp)
+        list(REMOVE_ITEM NMDAEMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/pad_client_stub.cpp)
 endif()
 
 SET (SOURCES
index 5413678..e94e0b6 100644 (file)
@@ -17,6 +17,7 @@
 #include "report_stub.h"  // TODO: Remove after migration on report service
 #ifndef __BUILD_UBUNTU__
 #include "audit_trail_client.h"
+#include "report_service.h"
 #endif
 #include "registration_mq.h"
 #include "application_service.h"
@@ -169,6 +170,11 @@ void MainThread::routine()
             LOG_D(TAG, "audit_trail start_auditing");
             audit_trail_client->start_auditing();
         }
+
+        std::shared_ptr<ReportService> report_service = std::make_shared<ReportService>(iotivity->getDeviceID(), proxy_thread,
+                                                                                    report_handler, g_working_mode);
+        LOG_D(TAG, "ReportService start");
+        report_service->start();
 #endif
 
         while (m_running) {
diff --git a/device_core/nmdaemon/report_service.cpp b/device_core/nmdaemon/report_service.cpp
new file mode 100644 (file)
index 0000000..80744c0
--- /dev/null
@@ -0,0 +1,71 @@
+/**
+ * @brief  Report service. Used as temporary solutution for test PAD and DLP reports.
+ * @date   Created 28.09.2017
+ * @author Created 2017 in Samsung Ukraine R&D Center (SURC) under a contract
+ *         between LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine)
+ *         and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea).
+ *         Copyright: (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
+ * @author Mail to: <A HREF="mailto:i.metelytsia@samsung.com">Iurii Metelytsia, i.metelytsia@samsung.com</A>
+ */
+
+#include <iostream>
+
+#include "iotivity.h"
+
+#include "report_stub.h"
+
+#include "report_service.h"
+#include "logging.h"
+
+#define TAG "nmdaemon"
+
+namespace NMD
+{
+
+const std::string ReportService::RMI_ADDRESS = "/tmp/.rmi_report_service";
+const std::string ReportService::RMI_SERVICE_NAME = "ReportService";
+
+ReportService::ReportService(const std::string& device_id, std::shared_ptr<ProxyThread> proxy_thread,
+                             std::shared_ptr<ReportHandler> report_handler, WorkingMode mode)
+    : m_device_id(device_id), m_proxy_thread(proxy_thread), m_report_handler(report_handler), m_mode(mode),
+      m_service(nullptr)
+{
+    assert(m_device_id != "");
+    assert(m_proxy_thread);
+    assert(m_report_handler);
+
+    m_service.reset(new rmi::Service(RMI_ADDRESS));
+    m_service->registerParametricMethod(this, (int)(ReportService::sendReport)(std::string, std::string));
+}
+
+ReportService::~ReportService()
+{
+    stop();
+}
+
+void ReportService::start()
+{
+    m_service->start();
+}
+
+void ReportService::stop()
+{
+    m_service->stop();
+}
+
+int ReportService::sendReport(std::string report_name, std::string report)
+{
+    LOG_D(TAG, "ReportService : %s - %s", report_name.c_str(), report.c_str());
+
+    report.erase(std::remove(report.begin(), report.end(), '"'), report.end());
+
+    OC::OCRepresentation rpr;
+    rpr.setValue("report", makeReport(m_device_id, report_name, 0, report));
+    rpr.setValue("duid", m_device_id);
+
+    m_report_handler->pass(rpr, OC::QueryParamsMap{});
+
+    return 0;
+}
+
+} // namespace NMD
diff --git a/device_core/nmdaemon/report_service.h b/device_core/nmdaemon/report_service.h
new file mode 100644 (file)
index 0000000..d70a4d7
--- /dev/null
@@ -0,0 +1,83 @@
+/**
+ * @brief  Report service. Used as temporary solutution for test PAD and DLP reports.
+ * @date   Created 28.09.2017
+ * @author Created 2017 in Samsung Ukraine R&D Center (SURC) under a contract
+ *         between LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine)
+ *         and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea).
+ *         Copyright: (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
+ * @author Mail to: <A HREF="mailto:i.metelytsia@samsung.com">Iurii Metelytsia, i.metelytsia@samsung.com</A>
+ */
+
+#ifndef __REPORT_SERVICE_H__
+#define __REPORT_SERVICE_H__
+
+#include <string>
+#include <memory>
+
+#include "proxythread.h"
+#include "reporthandler.h"
+#include "utils.h"
+
+#include "rmi/service.h"
+
+namespace NMD
+{
+
+/**
+ * @brief The PadClientStub class collect logs from PAD
+ */
+class ReportService
+{
+public:
+
+    /**
+     * @brief RMI_ADDRESS is path to file. Contact point of adapter and service on a filesystem.
+     */
+    static const std::string RMI_ADDRESS;
+
+    /**
+     * @brief RMI_SERVICE_NAME is default name of service class. Adapter implementation use it call service
+     */
+    static const std::string RMI_SERVICE_NAME;
+
+
+    /**
+     * @brief CTOR
+     */
+    ReportService(const std::string& device_id, std::shared_ptr<ProxyThread> proxy_thread,
+                  std::shared_ptr<ReportHandler> report_handler, WorkingMode mode);
+
+    /**
+     * @brief DTOR
+     */
+    virtual ~ReportService();
+
+    /**
+     * @brief Start service
+     * @details This API can be used to start service
+     */
+    void start();
+
+    /**
+     * @brief Stop service
+     * @details This API can be used to stop service
+     */
+    void stop();
+
+    /**
+     * @brief Send report to server
+     * @param report
+     */
+    int sendReport(std::string report_name, std::string report);
+
+private:
+    std::string m_device_id;
+    std::shared_ptr<ProxyThread> m_proxy_thread;
+    std::shared_ptr<ReportHandler> m_report_handler;
+    WorkingMode m_mode;
+    std::unique_ptr<rmi::Service> m_service;
+};
+
+} // namespace NMD
+
+#endif /* __REPORT_SERVICE_H__ */
index 9f1dc65..d33109e 100644 (file)
@@ -24,6 +24,7 @@ FILE(GLOB SRCS *.cpp
        ../nmdaemon/thread_base.cpp
        ../nmdaemon/commandhandler.cpp
        ../nmdaemon/application_service.cpp
+        ../nmdaemon/report_service.cpp
        )
 
 add_executable (${PROJECT_NAME} ${SRCS})
diff --git a/device_core/utest/test_report_service.cpp b/device_core/utest/test_report_service.cpp
new file mode 100644 (file)
index 0000000..21e38fd
--- /dev/null
@@ -0,0 +1,64 @@
+/**
+ * @brief  Tests for report service
+ * @date   Created 28.09.2017
+ * @author Created 2017 in Samsung Ukraine R&D Center (SURC) under a contract
+ *                between LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine)
+ *                and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea).
+ *         Copyright: (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
+ * @author Mail to: <A HREF="mailto:i.metelytsia@samsung.com">Iurii Metelytsia, i.metelytsia@samsung.com</A>
+ */
+#include <iostream>
+#include <string>
+
+#include <gtest/gtest.h>
+
+#include "report_service.h"
+
+#include "rmi/service.h"
+#include "rmi/client.h"
+
+using namespace NMD;
+
+/**
+ * Test for check PAD reports
+ * 1. Create RMI client and connect to report service
+ * 2. Call sendReport() method
+ * 3. Check result
+ * 4. Disconnect client
+ */
+TEST(DISABLED_test_report_service, padReport)
+{
+    int result = -1;
+
+    ASSERT_NO_THROW({
+        rmi::Client client(ReportService::RMI_ADDRESS);
+        client.connect();
+        result = client.methodCall<int>("ReportService::sendReport",
+                        std::string{"pad"},
+                        std::string{"[PAD] operation=write gpa=7fffd19c5592 start_symbol=_text end_symbol=__start_rodata mode=debug"});
+        client.disconnect();
+    });
+    ASSERT_EQ(0, result) << "sendReport() error\n";
+}
+
+/**
+ * Test for check DLP reports
+ * 1. Create RMI client and connect to report service
+ * 2. Call sendReport() method
+ * 3. Check result
+ * 4. Disconnect client
+ */
+TEST(DISABLED_test_report_service, dlpReport)
+{
+    int result = -1;
+
+    ASSERT_NO_THROW({
+        rmi::Client client(ReportService::RMI_ADDRESS);
+        client.connect();
+        result = client.methodCall<int>("ReportService::sendReport",
+                        std::string{"dlp"},
+                        std::string{"[DLP] time=1469476424.501:359 appid=org.tizen.gloftasp6 category=IMEI destination=www.google.com"});
+        client.disconnect();
+    });
+    ASSERT_EQ(0, result) << "sendReport() error\n";
+}