static std::string g_device_name = "Generic device";
static std::string g_device_model = "Model 1";
static std::string g_device_type = "iotdevice";
-static main_thread g_main_thread;
+static MainThread g_main_thread;
bool volatile g_running = true;
#include <string>
#include <memory>
-#include <ctime>
-#include "main_thread.h"
+#include "main_thread.h"
#include "utils.h"
-
#include "hub_resource.h"
#include "easysetup_server.h"
#include "reporthandler.h"
#include "iot_policy_enforce.h"
#include "proxythread.h"
#include "iotivity.h"
-#include "RDClient.h"
#include "control_resource.h"
#include "agentpolicyservice.h"
+#include "report_stub.h" // TODO: Remove after migration on report service
-using namespace NMD;
using namespace NetworkManager;
namespace PH = std::placeholders;
extern bool volatile g_running;
-namespace
-{
-
-const std::string CTRL_RESOURCE_URI = "/sec/control";
-const std::string CTRL_RESOURCE_TYPE = "device.control";
-
-/**
- * @brief The TestReport struct used for mocking DPM reports
- */
-struct TestReport
+namespace NMD
{
- std::string name;
- std::string data;
- int result;
-};
-
-const TestReport test_reports[] = {
- {
- "sim",
- R"({"Content":{"deviceInfo":{"model":"UKS9000","tizenVersion":"2.3","tizenName":"Tizen","platform":"Tizen","manufacturer":"Samsung","cpuArch":"armv7","cpuFreq":"1.5GHz","buildStr":"tztv-2.4-main2016-jazz-m_20160930.1","buildDate":"2016-09-30","buildTime":"04:52:44","duid":"BUYD7RXBSUXKICGD"},"timestamp":"2017-02-22 UTC 11:15:20","appid":"0","nonce":"LocalAttestationNonce","AttReport":{"status":"1","report":{"SIMReport":{"version":"2.0","status":"1","protector":{"EVT":{"symbol":{},"status":"0"},"File":{"symbol":{"/usr/lib/systemd/system":{"attackCount":"1"}},"status":"1"},"PageTable":{"symbol":{},"status":"0"},"StaticMemory":{"symbol":{},"status":"0"},"LSM":{"symbol":{},"status":"0"},"LKM":{"symbol":{},"status":"0"},"VFS":{"symbol":{},"status":"0"},"Netfilter":{"symbol":{},"status":"0"}}}}}},"Integrity":{"Sign":"0"}})",
- 0
- },
- {
- "smart-security",
- "{\"status\":\"secured\",\"health\": 100}",
- 11
- }
-};
-
-}
-main_thread::main_thread(const std::string& _device_name, const std::string& _device_model, const std::string& _device_type) :
- thread_base(), m_device_name(_device_name), m_device_model(_device_model), m_device_type(_device_type)
+MainThread::MainThread(const std::string& device_name, const std::string& device_model, const std::string& device_type) :
+ ThreadBase(), m_device_name(device_name), m_device_model(device_model), m_device_type(device_type)
{
}
-main_thread::~main_thread()
+MainThread::~MainThread()
{
}
-void main_thread::routine()
+void MainThread::routine()
{
write_log("[MAIN_THREADS] started\n");
std::shared_ptr<OC::OCResource> report_res = nullptr;
AgentPolicyService agent_policy_service(std::bind(&PolicyHandler::enforceCallback, policy_handler.get(), PH::_1, PH::_2));
std::thread rmi_thread(&AgentPolicyService::run, &agent_policy_service);
- std::srand(time(NULL));
-
while(m_running)
{
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
hub->findDevices();
}
- int sel = std::rand() % (sizeof(test_reports) / sizeof(TestReport));
OCRepresentation rpr;
- const TestReport& tr = test_reports[sel];
- rpr.setValue("report", makeReport(iotivity->getDeviceID(), tr.name, tr.result, tr.data));
+ rpr.setValue("report", getReport(iotivity->getDeviceID()));
rpr.setValue("duid", iotivity->getDeviceID());
if (g_working_mode == WorkingMode::Hub)
}
}
-// iotivity->unPublishAllResources();
-// hub->unownAll();
-
if (proxy_thread)
{
proxy_thread->stop();
{
write_log("[MAIN_THREADS] error - %s\n", _e.what());
}
+
write_log("[MAIN_THREADS] stopped\n");
- std::cout << "Stop!" << std::endl;
g_running = false;
}
+
+} // namespace NMD
#ifndef __MAIN_THREAD_H__\r
#define __MAIN_THREAD_H__\r
\r
-#include <iostream>\r
#include <string>\r
-#include <vector>\r
-\r
#include "thread_base.h"\r
\r
namespace NMD\r
{\r
\r
-class main_thread : public thread_base\r
+class MainThread : public ThreadBase\r
{\r
public:\r
- main_thread(const std::string& _device_name = "", const std::string& _device_model = "", const std::string& _device_type = "");\r
+ MainThread(const std::string& device_name = "", const std::string& device_model = "", const std::string& device_type = "");\r
\r
- void set_device_name(const std::string& _device_name)\r
+ void set_device_name(const std::string& device_name)\r
{\r
- m_device_name = _device_name;\r
+ m_device_name = device_name;\r
}\r
\r
- void set_device_model(const std::string& _device_model)\r
+ void set_device_model(const std::string& device_model)\r
{\r
- m_device_model = _device_model;\r
+ m_device_model = device_model;\r
}\r
\r
- void set_device_type(const std::string& _device_type)\r
+ void set_device_type(const std::string& device_type)\r
{\r
- m_device_type = "oic.d." + _device_type;\r
+ m_device_type = "oic.d." + device_type;\r
}\r
\r
- virtual ~main_thread();\r
+ virtual ~MainThread();\r
\r
virtual void routine();\r
\r
#include "thread_base.h"
#include <iostream>
-class ProxyThread : public NMD::thread_base
+class ProxyThread : public NMD::ThreadBase
{
public:
ProxyThread()
--- /dev/null
+/**
+ * @brief Report creation stub. Used as temporary solutution for test perposes.
+ * Migrate to normal report service when possible.
+ * @date Created 14.07.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:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
+ */
+
+#include <cstdlib>
+#include <sstream>
+#include <OCApi.h>
+#include <ctime>
+#include "report_stub.h"
+
+namespace
+{
+
+/**
+ * @brief The TestReport struct used for mocking DPM reports
+ */
+struct TestReport
+{
+ std::string name;
+ std::string data;
+ int result;
+};
+
+const TestReport test_reports[] = {
+ {
+ "sim",
+ R"({"Content":{"deviceInfo":{"model":"UKS9000","tizenVersion":"2.3","tizenName":"Tizen","platform":"Tizen","manufacturer":"Samsung","cpuArch":"armv7","cpuFreq":"1.5GHz","buildStr":"tztv-2.4-main2016-jazz-m_20160930.1","buildDate":"2016-09-30","buildTime":"04:52:44","duid":"BUYD7RXBSUXKICGD"},"timestamp":"2017-02-22 UTC 11:15:20","appid":"0","nonce":"LocalAttestationNonce","AttReport":{"status":"1","report":{"SIMReport":{"version":"2.0","status":"1","protector":{"EVT":{"symbol":{},"status":"0"},"File":{"symbol":{"/usr/lib/systemd/system":{"attackCount":"1"}},"status":"1"},"PageTable":{"symbol":{},"status":"0"},"StaticMemory":{"symbol":{},"status":"0"},"LSM":{"symbol":{},"status":"0"},"LKM":{"symbol":{},"status":"0"},"VFS":{"symbol":{},"status":"0"},"Netfilter":{"symbol":{},"status":"0"}}}}}},"Integrity":{"Sign":"0"}})",
+ 0
+ },
+ {
+ "smart-security",
+ "{\"status\":\"secured\",\"health\": 100}",
+ 11
+ }
+};
+
+} // namespace
+
+namespace NMD
+{
+
+static std::string currentDateTime();
+
+std::string getReport(const std::string& id)
+{
+ int sel = std::rand() % (sizeof(test_reports) / sizeof(TestReport));
+ const TestReport& tr = test_reports[sel];
+ return makeReport(id, tr.name, tr.result, tr.data);
+}
+
+std::string makeReport(const std::string& id, const std::string& name, int result, const std::string& data)
+{
+ std::ostringstream oss;
+ std::string current_time = currentDateTime();
+ oss << "{\"did\": \"" << id << "\",";
+ oss << "\"date\": \"" << current_time << "\",";
+ oss << "\"name\": \"" << name << "\",";
+ oss << "\"result\": " << result << ",";
+ oss << "\"data\": " << data << "}";
+ return oss.str();
+}
+
+std::string currentDateTime()
+{
+ time_t rawtime;
+ struct tm* timeinfo;
+ char buffer[128];
+ time(&rawtime);
+ timeinfo = localtime(&rawtime);
+ strftime(buffer, sizeof(buffer), "%d-%m-%Y %I:%M:%S", timeinfo);
+ return std::string(buffer);
+}
+
+} // namespace NMD
--- /dev/null
+#ifndef REPORT_STUB_H
+#define REPORT_STUB_H
+
+#include <string>
+
+namespace NMD
+{
+
+/**
+ * @brief Generate test report
+ * @param id [in] duid value to insert to JSON
+ * @return report JSON
+ */
+std::string getReport(const std::string& id);
+
+/**
+ * @brief Create test report
+ * @param id [in] device identifier
+ * @param name [in] report name
+ * @param result [in] report result
+ * @param data [in] report data
+ * @return report JSON
+ */
+std::string makeReport(const std::string& id, const std::string& name, int result, const std::string& data);
+
+} // namespace NMD
+
+#endif // REPORT_STUB_H
namespace NMD\r
{\r
\r
-thread_base::thread_base() : m_running(false)\r
+ThreadBase::ThreadBase() : m_running(false)\r
{\r
}\r
\r
-thread_base::~thread_base()\r
+ThreadBase::~ThreadBase()\r
{\r
}\r
\r
-void thread_base::start()\r
+void ThreadBase::start()\r
{\r
m_running = true;\r
- m_thread = std::thread(&thread_base::routine, this);\r
+ m_thread = std::thread(&ThreadBase::routine, this);\r
}\r
\r
-void thread_base::stop()\r
+void ThreadBase::stop()\r
{\r
m_running = false;\r
}\r
\r
-void thread_base::routine()\r
+void ThreadBase::routine()\r
{\r
}\r
\r
-void thread_base::join()\r
+void ThreadBase::join()\r
{\r
if (m_thread.joinable())\r
{\r
namespace NMD\r
{\r
\r
-class thread_base\r
+class ThreadBase\r
{\r
public:\r
- thread_base();\r
+ ThreadBase();\r
\r
- thread_base(const thread_base&) = delete;\r
+ ThreadBase(const ThreadBase&) = delete;\r
\r
- virtual ~thread_base();\r
+ virtual ~ThreadBase();\r
\r
- thread_base& operator=(const thread_base&) = delete;\r
+ ThreadBase& operator=(const ThreadBase&) = delete;\r
\r
virtual void start();\r
\r
return res;\r
}\r
\r
-static std::string currentDateTime()\r
-{\r
- time_t rawtime;\r
- struct tm* timeinfo;\r
- char buffer[128];\r
- time(&rawtime);\r
- timeinfo = localtime(&rawtime);\r
- strftime(buffer, sizeof(buffer), "%d-%m-%Y %I:%M:%S", timeinfo);\r
- return std::string(buffer);\r
-}\r
-\r
-std::string makeReport(const std::string& id, const std::string& name, int result, const std::string& data)\r
-{\r
- std::ostringstream oss;\r
- std::string current_time = currentDateTime();\r
- oss << "{\"did\": \"" << id << "\",";\r
- oss << "\"date\": \"" << current_time << "\",";\r
- oss << "\"name\": \"" << name << "\",";\r
- oss << "\"result\": " << result << ",";\r
- oss << "\"data\": " << data << "}";\r
- return oss.str();\r
-}\r
-\r
}\r
*/\r
void clear_hub_cache();\r
\r
-std::string makeReport(const std::string& id, const std::string& name, int result, const std::string& data);\r
-\r
bool write_log(const char* _msg, ...);\r
\r
#if defined(__TIZEN__)\r
../nmdaemon/utils.cpp
../nmdaemon/dpm/dpm_api_mapper.cpp
../nmdaemon/control_resource.cpp
+ ../nmdaemon/report_stub.cpp
)
add_executable (${PROJECT_NAME} ${SRCS})
#include "easysetup_server.h"
#include "iot_resource.h"
#include "utils.h"
+#include "report_stub.h"
using namespace std;
using namespace OC;
#include "nmexceptions.h"
#include "securitycontext.h"
#include "utils.h"
+#include "report_stub.h"
using namespace std;
using namespace NetworkManager;