[SECARSP-125] SysInfo class that implements system info used during the device regist...
authorDmytro Lomtiev <d.lomtev@samsung.com>
Tue, 27 Feb 2018 10:17:31 +0000 (12:17 +0200)
committerDmytro Lomtiev <d.lomtev@samsung.com>
Fri, 16 Mar 2018 14:17:19 +0000 (16:17 +0200)
Change-Id: Ia1dcdfaacb238cd15ee6ad080149155a33ddec16

20 files changed:
device-agent/communication/CMakeLists.txt
device-agent/communication/inc/connection.h
device-agent/communication/inc/irestservice.h
device-agent/communication/inc/restservice.h
device-agent/communication/inc/settings.h
device-agent/communication/inc/sysinfo.h [new file with mode: 0644]
device-agent/communication/src/connection.cpp
device-agent/communication/src/restservice.cpp
device-agent/communication/src/settings.cpp
device-agent/communication/src/sysinfo.cpp [new file with mode: 0644]
device-agent/packaging/samonitor.spec
device-agent/samonitor/CMakeLists.txt
device-agent/samonitor/main.cpp
device-agent/samonitor/main_thread.cpp
device-agent/samonitor/main_thread.h
device-agent/scripts/bin_copy.sh
device-agent/utest/CMakeLists.txt
device-agent/utest/mock/restservicemock.h
device-agent/utest/test_connection.cpp
device-agent/utest/test_settings.cpp

index 9c1d0dd..c4ddf51 100644 (file)
@@ -11,7 +11,7 @@ include_directories(
 
 file(GLOB COMM_SRC src/*.cpp)
 
-pkg_check_modules(pkgs REQUIRED curl)
+pkg_check_modules(pkgs REQUIRED curl capi-system-info)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 70f55d4..4dfb30a 100644 (file)
@@ -116,7 +116,7 @@ private:
     std::queue<Event> eventQueue;
     Settings& settings;
     DeviceState state;
-    DeviceInfo dinfo;
+    SessionInfo sinfo;
     IRestService* rest;
     std::mutex locker;
     std::condition_variable notice;
index 3c4739b..048a40a 100644 (file)
 #define IRESTSERVICE_H
 #include <string>
 #include <jsoncpp/json/value.h>
+#include <settings.h>
 
 namespace NetworkManager
 {
 
-struct DeviceInfo {
+struct SessionInfo {
     std::string duid;       /**< Device identifier */
-    std::string model;      /**< Device model */
-    std::string type;       /**< Device type */
-    std::string osVersion;  /**< Operating System version */
-    std::string serial;     /**< Device serial number */
     std::string authToken;  /**< Authentication token */
 };
 
@@ -35,19 +32,59 @@ public:
 
     virtual ~IRestService() {}
 
-    virtual std::string getUpdates(const DeviceInfo& info) = 0;
+    /**
+     * @brief getUpdates request for updates
+     * @param info session information
+     * @return a JSON document that contains information about the resources which an update is
+     *         required or empty string
+     */
+    virtual std::string getUpdates(const SessionInfo& info) = 0;
 
-    virtual std::string registerDevice(const DeviceInfo& info) = 0;
+    /**
+     * @brief registerDevice registers the device
+     * @param info session information
+     * @param settings device settings
+     * @return the device unique identifier on success or throws an exception on failure
+     */
+    virtual std::string registerDevice(const SessionInfo& info, const Settings& settings) = 0;
 
-    virtual std::string auth(const DeviceInfo& info, const std::string& secret) = 0;
+    /**
+     * @brief auth performs the device authentication on the DSM server
+     * @param info session information
+     * @param secret shared secret
+     * @return an authentication token on success or throws an exception on failure
+     */
+    virtual std::string auth(const SessionInfo& info, const std::string& secret) = 0;
 
-    virtual std::string doGet(const DeviceInfo& info, const std::string& uri) = 0;
+    /**
+     * @brief doGet performs a HTTP GET request on the DSM server using specified URI
+     * @param info session information
+     * @param uri relative URI
+     * @return the body of the GET response  or throws an exception on failure
+     */
+    virtual std::string doGet(const SessionInfo& info, const std::string& uri) = 0;
 
-    virtual void doPost(const DeviceInfo& info, const std::string& uri, const std::string& data) = 0;
+    /**
+     * @brief doPost performs a HTTP POST request on the DSM server using specified URI
+     * @param info session information
+     * @param uri relative URI
+     * @param data body of the POST response  or throws an exception on failure
+     */
+    virtual void doPost(const SessionInfo& info, const std::string& uri, const std::string& data) = 0;
 
-    virtual void sendReport(const DeviceInfo& info, const std::string& report) = 0;
+    /**
+     * @brief sendReport sends report to the DSM server
+     * @param info session information
+     * @param report JSON document the contains the reports
+     */
+    virtual void sendReport(const SessionInfo& info, const std::string& report) = 0;
 
-    virtual void sendReport(const DeviceInfo& info, const Json::Value& report) = 0;
+    /**
+     * @brief sendReport sends report to the DSM server
+     * @param info session information
+     * @param report JSON object the contains the reports
+     */
+    virtual void sendReport(const SessionInfo& info, const Json::Value& report) = 0;
 };
 
 }
index 6a36b4c..c64eadf 100644 (file)
@@ -32,19 +32,19 @@ public:
 
     ~RestService();
 
-    std::string getUpdates(const DeviceInfo& info) override;
+    std::string getUpdates(const SessionInfo& info) override;
 
-    std::string registerDevice(const DeviceInfo& info) override;
+    std::string registerDevice(const SessionInfo& info, const Settings& settings) override;
 
-    std::string auth(const DeviceInfo& info, const std::string& secret) override;
+    std::string auth(const SessionInfo& info, const std::string& secret) override;
 
-    std::string doGet(const DeviceInfo& info, const std::string& uri) override;
+    std::string doGet(const SessionInfo& info, const std::string& uri) override;
 
-    void doPost(const DeviceInfo& info, const std::string& uri, const std::string& data) override;
+    void doPost(const SessionInfo& info, const std::string& uri, const std::string& data) override;
 
-    void sendReport(const DeviceInfo& info, const std::string& report) override;
+    void sendReport(const SessionInfo& info, const std::string& report) override;
 
-    void sendReport(const DeviceInfo& info, const Json::Value& report) override;
+    void sendReport(const SessionInfo& info, const Json::Value& report) override;
 private:
     std::string host;
 };
index 370a9f7..2b57dd1 100644 (file)
@@ -62,24 +62,6 @@ public:
     }
 
     /**
-     * @brief getDeviceType returns the device type
-     * @return the device type as string
-     */
-    const std::string& getDeviceType() const
-    {
-        return deviceType;
-    }
-
-    /**
-     * @brief getDeviceModel returns the device model
-     * @return the device model as string
-     */
-    const std::string& getDeviceModel() const
-    {
-        return deviceModel;
-    }
-
-    /**
      * @brief getKeepAliveTimeout returns KeepAlive timeout period
      * @return KeepAlive timeout period
      */
@@ -89,15 +71,6 @@ public:
     }
 
     /**
-     * @brief getOsVersion returns the version of the Operating System running on the device
-     * @return OS version as string
-     */
-    const std::string& getOsVersion() const
-    {
-        return osVersion;
-    }
-
-    /**
      * @brief getSerial returns the device serial number
      * @return serial number as string
      */
@@ -125,24 +98,6 @@ public:
     }
 
     /**
-     * @brief setDeviceType sets the device type
-     * @param type type of the device
-     */
-    void setDeviceType(const std::string& type)
-    {
-        deviceType = type;
-    }
-
-    /**
-     * @brief setDeviceModel sets the device model
-     * @param model the device model
-     */
-    void setDeviceModel(const std::string& model)
-    {
-        deviceModel = model;
-    }
-
-    /**
      * @brief setKeepAliveTimeout sets KeepAlive timeout period
      * @param keepalive KeepAlive timeout period
      */
@@ -200,9 +155,6 @@ private:
 
     std::string serverAddress;
     std::string deviceId;
-    std::string deviceType;
-    std::string deviceModel;
-    std::string osVersion;
     std::string serial;
     std::chrono::seconds keepAliveTimeout;
     std::string saveFileName;
diff --git a/device-agent/communication/inc/sysinfo.h b/device-agent/communication/inc/sysinfo.h
new file mode 100644 (file)
index 0000000..8f2a963
--- /dev/null
@@ -0,0 +1,59 @@
+/**
+ * Samsung Ukraine R&D Center (SRK under a contract between)
+ * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ */
+/**
+ * @file   sysinfo.h
+ * @brief  System information collector
+ * @date   Created Feb 26, 2018
+ * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
+ */
+#ifndef SYSINFO_H
+#define SYSINFO_H
+
+#include <string>
+
+namespace NetworkManager
+{
+
+/**
+ * @brief System information collector
+ */
+class SysInfo
+{
+public:
+    /**
+     * @brief model returns the name of the device model
+     * @return model name as string on success and "undefined" otherwise
+     */
+    static std::string model();
+
+    /**
+     * @brief type returns the type of the device
+     * @return device type on success and "undefined" otherwise
+     */
+    static std::string type();
+
+    /**
+     * @brief osVersion returns the version number of the Operating System
+     * @return OS version number as string on success and "undefined" otherwise
+     */
+    static std::string osVersion();
+
+    /**
+     * @brief osName returns the name of the Operating System version
+     * @return OS version name as string on success and "undefined" otherwise
+     */
+    static std::string osName();
+
+    /**
+     * @brief swVersion returns revision of the device software
+     * @return software version as string on success and "undefined" otherwise
+     */
+    static std::string swVersion();
+};
+
+} // namespace NetworkManager
+
+#endif // SYSINFO_H
index 6ad3b6e..a5aac9e 100644 (file)
@@ -17,6 +17,7 @@
 #include "samonitor_tag.h"
 #include "reportcomposer.h"
 #include "resource.h"
+#include <iostream>
 
 namespace NetworkManager
 {
@@ -28,19 +29,15 @@ Connection::Connection(Settings& deviceSettings, IRestService* restService)
     , listeners()
     , settings(deviceSettings)
     , state(DeviceState::REGISTER)
-    , dinfo()
+    , sinfo()
     , rest(restService)
     , locker()
     , lastId(0)
     , work(true)
 {
-    dinfo.duid = settings.getDeviceId();
-    dinfo.type = settings.getDeviceType();
-    dinfo.model = settings.getDeviceModel();
-    dinfo.osVersion = settings.getOsVersion();
-    dinfo.serial = settings.getSerial();
+    sinfo.duid = settings.getDeviceId();
 
-    if (!dinfo.duid.empty())
+    if (!sinfo.duid.empty())
     {
         state = DeviceState::AUTHORIZE;
     }
@@ -88,7 +85,6 @@ void Connection::loop()
     std::chrono::steady_clock clock;
     std::chrono::steady_clock::time_point next = clock.now();
     auto period = settings.getKeepAliveTimeout();
-    next += period;
 
     while(work)
     {
@@ -96,7 +92,7 @@ void Connection::loop()
         {
         case DeviceState::REGISTER:
             if (reg()) {
-                settings.setDeviceId(dinfo.duid);
+                settings.setDeviceId(sinfo.duid);
                 settings.save();
                 state = DeviceState::AUTHORIZE;
             }
@@ -120,16 +116,12 @@ void Connection::loop()
                     }
 
                     lock.unlock();
-                    rest->sendReport(dinfo, composer.get());
+                    rest->sendReport(sinfo, composer.get());
                 }
             } while(0);
 
-            if (next > clock.now()) {
-                std::unique_lock<std::mutex> lock(locker);
-                notice.wait_until(lock, next);
-            } else {
-                next += period;
-                std::string updates = rest->getUpdates(dinfo);
+            if (next <= clock.now()) {
+                std::string updates = rest->getUpdates(sinfo);
 
                 if (updates.empty()) {
                     break;
@@ -175,13 +167,20 @@ void Connection::loop()
             break;
         }
         }
+
+        if (next <= clock.now()) {
+            next += period;
+        }
+
+        std::unique_lock<std::mutex> lock(locker);
+        notice.wait_until(lock, next);
     }
 }
 
 void Connection::confirm(const std::string& uri, const std::string& response)
 {
     try {
-        rest->doPost(dinfo, uri, response);
+        rest->doPost(sinfo, uri, response);
     } catch (std::exception& e) {
         LOG_E(TAG, "Fail to confirm update uri: [%s], error: [%s]", uri.c_str(), e.what());
     }
@@ -189,18 +188,19 @@ void Connection::confirm(const std::string& uri, const std::string& response)
 
 std::string Connection::getContent(const std::string& uri)
 {
-    return rest->doGet(dinfo, uri);
+    return rest->doGet(sinfo, uri);
 }
 
 bool Connection::reg()
 {
     try {
-        dinfo.duid = rest->registerDevice(dinfo);
+        sinfo.duid = rest->registerDevice(sinfo, settings);
     } catch (std::exception& e){
+        LOG_E(TAG, "Register failed: %s", e.what());
         return false;
     }
 
-    return !dinfo.duid.empty();
+    return !sinfo.duid.empty();
 }
 
 bool Connection::authorize()
index 9a53c62..e27a4c0 100644 (file)
@@ -15,6 +15,7 @@
 #include "rest_request.h"
 #include "logging.h"
 #include "samonitor_tag.h"
+#include "sysinfo.h"
 
 namespace
 {
@@ -47,7 +48,7 @@ RestService::~RestService()
 
 }
 
-std::string RestService::getUpdates(const DeviceInfo& info)
+std::string RestService::getUpdates(const SessionInfo& info)
 {
     RestRequest request(host);
     RestRequest::QueryParameters params{{"duid", info.duid}};
@@ -66,14 +67,16 @@ std::string RestService::getUpdates(const DeviceInfo& info)
     return response_body;
 }
 
-std::string RestService::registerDevice(const DeviceInfo& info)
+std::string RestService::registerDevice(const SessionInfo& info, const Settings& settings)
 {
     RestRequest request(host);
     Json::Value root;
-    root["sn"] = info.serial;
-    root["model"] = info.model;
-    root["type"] = info.type;
-    root["dos"] = info.osVersion;
+    root["sn"] = settings.getSerial();
+    root["model"] = SysInfo::model();
+    root["type"] = SysInfo::type();
+    root["sw"] = SysInfo::swVersion();
+    root["osname"] = SysInfo::osName();
+    root["osver"] = SysInfo::osVersion();
 
     Json::FastWriter writer;
     std::string payload = writer.write(root);
@@ -84,12 +87,13 @@ std::string RestService::registerDevice(const DeviceInfo& info)
     return request.body();
 }
 
-std::string RestService::auth(const DeviceInfo& info, const std::string& secret)
-{    
+std::string RestService::auth(const SessionInfo& info, const std::string& secret)
+{
+    //TODO: implement in the future
     return "";
 }
 
-std::string RestService::doGet(const DeviceInfo& info, const std::string& uri)
+std::string RestService::doGet(const SessionInfo& info, const std::string& uri)
 {
     RestRequest request(host);
     request.addHeader("Content-Type", "application/json");
@@ -99,19 +103,18 @@ std::string RestService::doGet(const DeviceInfo& info, const std::string& uri)
     return response;
 }
 
-void RestService::doPost(const DeviceInfo& info, const std::string& uri, const std::string& data)
+void RestService::doPost(const SessionInfo& info, const std::string& uri, const std::string& data)
 {
     RestRequest request(host);
-//    request.addHeader("Content-Type", "application/json");
     restResultGuard(request.post(RestRequest::QueryParameters{}, uri, data));
 }
 
-void RestService::sendReport(const DeviceInfo& info, const std::string& report)
+void RestService::sendReport(const SessionInfo& info, const std::string& report)
 {
     sendReport(info, Json::Value(report));
 }
 
-void RestService::sendReport(const DeviceInfo& info, const Json::Value& report)
+void RestService::sendReport(const SessionInfo& info, const Json::Value& report)
 {
     RestRequest request(host);
     Json::Value root;
index db9a839..d40e571 100644 (file)
@@ -32,8 +32,11 @@ namespace
 const std::string defaultConfig{CONFIG_FILE};
 const int DEFAULT_KEEPALIVE_SECONDS = 10;
 const std::string DEFAULT_STRING_PROPERTY{"unknown"};
-const std::string OS_INFO_PATH{"/etc/os-release"};
-const std::string OS_VERSION_KEY{"VERSION"};
+
+const std::string PROPKEY_SERVER_ADDR{"Server.URL"};
+const std::string PROPKEY_KEEPALIVE{"Server.keepalive"};
+const std::string PROPKEY_DUID{"Device.id"};
+const std::string PROPKEY_SERIAL{"Device.serial"};
 
 std::string randomString(char minc, char maxc, int len)
 {
@@ -51,30 +54,6 @@ std::string randomString(char minc, char maxc, int len)
     return str;
 }
 
-std::pair<std::string, std::string> keyValue(const std::string& s)
-{
-    size_t pos = s.find_first_of('=');
-
-    if (pos != std::string::npos) {
-        size_t val_pos = pos;
-
-        if (++val_pos == s.size()) {
-            return std::make_pair(s.substr(0, pos), std::string{});
-        }
-
-        size_t val_end = std::string::npos;
-
-        if (s.at(val_pos) == '\"' && (val_end = s.find_first_of('"', val_pos + 1)) != std::string::npos) {
-            val_pos++;
-            val_end -= val_pos;
-        }
-
-        return std::make_pair(s.substr(0, pos), s.substr(val_pos, val_end));
-    }
-
-    return std::make_pair(std::string{}, std::string{});
-}
-
 }
 
 namespace NetworkManager
@@ -83,33 +62,11 @@ namespace NetworkManager
 Settings::Settings()
     : serverAddress()
     , deviceId()
-    , deviceType(DEFAULT_STRING_PROPERTY)
-    , deviceModel(DEFAULT_STRING_PROPERTY)
-    , osVersion()
     , serial()
     , keepAliveTimeout(DEFAULT_KEEPALIVE_SECONDS)
     , saveFileName()
     , loaded(false)
 {
-    std::ifstream os_release(OS_INFO_PATH);
-
-    if (os_release.good()) {
-        std::string line;
-        do {
-            std::getline(os_release, line);
-            auto keyVal = keyValue(line);
-
-            LOG_D(TAG, "For line '%s' -> <%s, %s>", line.c_str(), keyVal.first.c_str(), keyVal.second.c_str());
-
-            if (keyVal.first == OS_VERSION_KEY) {
-                LOG_D(TAG, "Set OS version to: %s", keyVal.second.c_str());
-                osVersion = keyVal.second;
-                break;
-            }
-        } while (!os_release.eof());
-    } else {
-        LOG_D(TAG, "Fail to open %s", OS_INFO_PATH.c_str());
-    }
 }
 
 Settings::Settings(const std::string& fileName): Settings()
@@ -131,13 +88,10 @@ bool Settings::_load(const std::string& fileName)
         boost::property_tree::ptree properties;
         boost::property_tree::read_ini(fileName, properties);
 
-        serverAddress = properties.get<std::string>("Server.URL", std::string{});
-        deviceId = properties.get<std::string>("Device.id", std::string{});
-        deviceType = properties.get<std::string>("Device.type", DEFAULT_STRING_PROPERTY);
-        deviceModel = properties.get<std::string>("Device.model", DEFAULT_STRING_PROPERTY);
-        serial = properties.get<std::string>("Device.serial", std::string{});
-        keepAliveTimeout = std::chrono::seconds(properties.get<int>("Server.keepalive", DEFAULT_KEEPALIVE_SECONDS));
-        serial =
+        serverAddress = properties.get<std::string>(PROPKEY_SERVER_ADDR, std::string{});
+        deviceId = properties.get<std::string>(PROPKEY_DUID, std::string{});
+        serial = properties.get<std::string>(PROPKEY_SERIAL, std::string{});
+        keepAliveTimeout = std::chrono::seconds(properties.get<int>(PROPKEY_KEEPALIVE, DEFAULT_KEEPALIVE_SECONDS));
         loaded = true;
     } catch (std::exception& e) {
         LOG_E(TAG, "Fail to load configuration from \"%s\". Error: %s", fileName.c_str(), e.what());
@@ -173,12 +127,10 @@ bool Settings::save() const
     try
     {
         boost::property_tree::ptree properties;
-        properties.put("Server.URL", serverAddress);
-        properties.put("Server.keepalive", keepAliveTimeout.count());
-        properties.put("Device.id", deviceId);
-        properties.put("Device.type", deviceType);
-        properties.put("Device.model", deviceModel);
-        properties.put("Device.serial", serial);
+        properties.put(PROPKEY_SERVER_ADDR, serverAddress);
+        properties.put(PROPKEY_KEEPALIVE, keepAliveTimeout.count());
+        properties.put(PROPKEY_DUID, deviceId);
+        properties.put(PROPKEY_SERIAL, serial);
 
         boost::property_tree::write_ini(saveFileName, properties);
         return true;
diff --git a/device-agent/communication/src/sysinfo.cpp b/device-agent/communication/src/sysinfo.cpp
new file mode 100644 (file)
index 0000000..152eb70
--- /dev/null
@@ -0,0 +1,85 @@
+/**
+ * Samsung Ukraine R&D Center (SRK under a contract between)
+ * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ */
+/**
+ * @file   sysinfo.h
+ * @brief  System information collector
+ * @date   Created Feb 26, 2018
+ * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
+ */
+
+#include "sysinfo.h"
+#include <capi-system-info/system_info.h>
+
+namespace
+{
+
+/**
+ * @brief getStringSystemProperty returns system property as std::string
+ * @param prop the requested system property key
+ * @return requested system property on success and "undefined" otherwise
+ */
+std::string getStringSystemProperty(system_info_key_e prop)
+{
+    std::string property{"undefined"};
+    char* val;
+
+    if (0 == system_info_get_value_string(prop, &val)) {
+        property.assign(val);
+        free(val);
+    }
+
+    return property;
+}
+
+/**
+ * @brief getStringPlatformProperty returns platform property as std::string
+ * @param prop the requested platform property key
+ * @return requested platform property on success and "undefined" otherwise
+ */
+std::string getStringPlatformProperty(const char* prop)
+{
+    std::string property{"undefined"};
+    char* val;
+
+    if (0 == system_info_get_platform_string(prop, &val)) {
+        property.assign(val);
+        free(val);
+    }
+
+    return property;
+}
+
+}
+
+namespace NetworkManager
+{
+
+std::string SysInfo::model()
+{
+    return getStringSystemProperty(SYSTEM_INFO_KEY_MODEL);
+}
+
+std::string SysInfo::type()
+{
+    return getStringPlatformProperty("com.samsung/build_config/product_type");
+}
+
+std::string SysInfo::osVersion()
+{
+    return getStringPlatformProperty("tizen.org/feature/platform.version");
+}
+
+std::string SysInfo::osName()
+{
+    return getStringSystemProperty(SYSTEM_INFO_KEY_PLATFORM_NAME);
+}
+
+std::string SysInfo::swVersion()
+{
+    return getStringSystemProperty(SYSTEM_INFO_KEY_SW_VERSION);
+}
+
+}
index 5a91fc4..6cda450 100644 (file)
@@ -7,6 +7,7 @@ License:    Apache
 Source0:    %{name}-%{version}.tar.gz
 
 BuildRequires: cmake
+BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(libcurl)
 BuildRequires: pkgconfig(dpm)
index c18ad93..9c36b8d 100644 (file)
@@ -32,6 +32,7 @@ target_link_libraries (${PROJECT_NAME}
        boost_thread
        boost_serialization
        curl
+       capi-system-info
 )
 
 # systemd dependency handling
index e6e4d81..de4ddcb 100644 (file)
@@ -36,9 +36,6 @@
 
 using namespace NMD;
 
-static std::string g_device_name = "Generic device";
-static std::string g_device_model = "Model 1";
-static std::string g_device_type = "iotdevice";
 static MainThread g_main_thread;
 
 bool volatile g_running = true;
@@ -56,33 +53,6 @@ int main(int argc, char** argv)
     struct sigaction act;
     int ret;
 
-    if (argc < 4) {
-        std::cout << TAG "please specify device name, model and type [optional path]" << std::endl;
-        std::cout << TAG "stopped" << std::endl;
-        return 1;
-    }
-
-    g_device_name = std::string({argv[1]});
-    g_device_model = std::string({argv[2]});
-    g_device_type = std::string({argv[3]});
-
-    if (argc < 5) {
-        std::string curr_path = current_path();
-
-        std::cout << TAG "storage path not specified. default path is used - " << curr_path.c_str() << std::endl;
-
-        dat_file_path_name = curr_path + "/nmdaemon.dat";
-        cfg_file_path_name = curr_path + "/nmdaemon.cfg";
-        log_file_path_name = curr_path + "/nmdaemon.log";
-        hub_file_path_name = curr_path + "/nmdaemon.hub";
-    } else {
-        std::string path{argv[4]};
-        dat_file_path_name = path + "/nmdaemon.dat";
-        cfg_file_path_name = path + "/nmdaemon.cfg";
-        log_file_path_name = path + "/nmdaemon.log";
-        hub_file_path_name = path + "/nmdaemon.hub";
-    }
-
     auto res = signal(SIGSEGV, sig_handler);
 
     if (res == SIG_ERR) {
@@ -153,9 +123,6 @@ void kill_handler(int _sig)
 
 bool threads_init(void)
 {
-    g_main_thread.set_device_name(g_device_name);
-    g_main_thread.set_device_model(g_device_model);
-    g_main_thread.set_device_type(g_device_type);
     g_main_thread.start();
     return true;
 }
index 85c4628..92a050b 100644 (file)
@@ -38,9 +38,7 @@ const std::string savedConfig{"sam.conf"};
 namespace NMD
 {
 
-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)
+MainThread::MainThread() : ThreadBase()
 {
 }
 
index 717e6be..6820370 100644 (file)
@@ -1,81 +1,47 @@
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file   main_thread.h
- * @brief  Main thread
- * @date   Created Apr 18, 2017
- * @author Mail to: <A HREF="mailto:i.metelytsia@samsung.com">Iurii Metelytsia, i.metelytsia@samsung.com</A>
- */
-
-#ifndef __MAIN_THREAD_H__
-#define __MAIN_THREAD_H__
-
-#include <string>
-#include "proxythread.h"
-#include "thread_base.h"
-
-namespace NMD
-{
-
-/**
- * @brief The Main Thread class
- */
-class MainThread : public ThreadBase
-{
-public:
-    /**
-     * @brief Constructor
-     * @param device_name  [in] the name of the device
-     * @param device_model [in] the model of the device
-     * @param device_type  [in] the type of the device
-     */
-    MainThread(const std::string& device_name = "",
-               const std::string& device_model = "",
-               const std::string& device_type = "");
-
-    /**
-     * @brief Sets the device name
-     * @param device_name  [in] the name of the device
-     */
-    void set_device_name(const std::string& device_name) {
-        m_device_name = device_name;
-    }
-
-    /**
-     * @brief Sets the device model
-     * @param device_model [in] the model of the device
-     */
-    void set_device_model(const std::string& device_model) {
-        m_device_model = device_model;
-    }
-
-    /**
-     * @brief Sets the device type
-     * @param device_type  [in] the type of the device
-     */
-    void set_device_type(const std::string& device_type) {
-        m_device_type = device_type;
-    }
-
-    /**
-     * @brief Destructor
-     */
-    virtual ~MainThread();
-
-    /**
-     * @brief Main routine
-     */
-    virtual void routine();
-
-private:
-    std::string m_device_name;
-    std::string m_device_model;
-    std::string m_device_type;
-};
-
-}
-
-#endif /* __MAIN_THREAD_H__ */
+/**\r
+ * Samsung Ukraine R&D Center (SRK under a contract between)\r
+ * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)\r
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.\r
+ */\r
+/**\r
+ * @file   main_thread.h\r
+ * @brief  Main thread\r
+ * @date   Created Apr 18, 2017\r
+ * @author Mail to: <A HREF="mailto:i.metelytsia@samsung.com">Iurii Metelytsia, i.metelytsia@samsung.com</A>\r
+ */\r
+\r
+#ifndef __MAIN_THREAD_H__\r
+#define __MAIN_THREAD_H__\r
+\r
+#include <string>\r
+#include "proxythread.h"\r
+#include "thread_base.h"\r
+\r
+namespace NMD\r
+{\r
+\r
+/**\r
+ * @brief The Main Thread class\r
+ */\r
+class MainThread : public ThreadBase\r
+{\r
+public:\r
+    /**\r
+     * @brief Constructor\r
+     */\r
+    MainThread();\r
+\r
+    /**\r
+     * @brief Destructor\r
+     */\r
+    virtual ~MainThread();\r
+\r
+    /**\r
+     * @brief Main routine\r
+     */\r
+    virtual void routine();\r
+};\r
+\r
+}\r
+\r
+#endif /* __MAIN_THREAD_H__ */\r
index 405576d..7c48152 100755 (executable)
@@ -119,7 +119,8 @@ GBS_RPMS_DIR=~/gbs_root_${PROFILE_NAME}/local/repos/${PROFILE_NAME}/${TARGET_ARC
 
 mkdir /tmp/bins
 cp ${GBS_RPMS_DIR}/samonitor-* /tmp/bins/
-bash -c "cd /tmp/bins && rpm2cpio samonitor-* | cpio -dium"
+bash -c "cd /tmp/bins && rpm2cpio samonitor-samonitor* | cpio -dium"
+bash -c "cd /tmp/bins && rpm2cpio samonitor-test* | cpio -dium"
 
 TARGET_HOST="root@${TARGET_IP}"
 
index 8396405..6a1347f 100644 (file)
@@ -41,6 +41,7 @@ set (TEST_LINK_LIBRARIES ${GTEST_LIB}
        boost_system boost_thread boost_serialization
        dlog
        curl
+       capi-system-info
 )
 
 target_link_libraries(${PROJECT_NAME} ${TEST_LINK_LIBRARIES})
index 8c22c89..006a644 100644 (file)
@@ -22,13 +22,13 @@ class RestServiceMock: public IRestService
 {
 public:
     ~RestServiceMock(){}
-    MOCK_METHOD1(getUpdates, std::string(const DeviceInfo& info));
-    MOCK_METHOD1(registerDevice, std::string(const DeviceInfo& info));
-    MOCK_METHOD2(auth, std::string(const DeviceInfo& info, const std::string& secret));
-    MOCK_METHOD2(doGet, std::string(const DeviceInfo& info, const std::string& uri));
-    MOCK_METHOD3(doPost, void(const DeviceInfo& info, const std::string& uri, const std::string& data));
-    MOCK_METHOD2(sendReport, void(const DeviceInfo& info, const std::string& report));
-    MOCK_METHOD2(sendReport, void(const DeviceInfo& info, const Json::Value& report));
+    MOCK_METHOD1(getUpdates, std::string(const SessionInfo& info));
+    MOCK_METHOD2(registerDevice, std::string(const SessionInfo& info, const Settings& settings));
+    MOCK_METHOD2(auth, std::string(const SessionInfo& info, const std::string& secret));
+    MOCK_METHOD2(doGet, std::string(const SessionInfo& info, const std::string& uri));
+    MOCK_METHOD3(doPost, void(const SessionInfo& info, const std::string& uri, const std::string& data));
+    MOCK_METHOD2(sendReport, void(const SessionInfo& info, const std::string& report));
+    MOCK_METHOD2(sendReport, void(const SessionInfo& info, const Json::Value& report));
 };
 
 }
index eb59a28..19b7d27 100644 (file)
@@ -19,8 +19,6 @@ namespace
 const std::chrono::seconds TEST_KEEP_ALIVE(1);
 const std::string TEST_SERVER_ADDRESS{"test-server"};
 const std::string TEST_DEVICE_ID{"device-id"};
-const std::string TEST_DEVICE_TYPE{"device-type"};
-const std::string TEST_DEVICE_MODEL{"device-model"};
 
 const std::string TEST_EVENT_TYPE{"report"};
 const std::string TEST_EVENT_DATA1{"{sdfssdfsdfffsdfsdfsd}"};
@@ -53,8 +51,6 @@ public:
         settings.setKeepAliveTimeout(TEST_KEEP_ALIVE);
         settings.setServerAddress(TEST_SERVER_ADDRESS);
         settings.setDeviceId(TEST_DEVICE_ID);
-        settings.setDeviceModel(TEST_DEVICE_MODEL);
-        settings.setDeviceType(TEST_DEVICE_TYPE);
     }
 
     void TearDown() override
@@ -80,6 +76,8 @@ TEST_F(TestConnection, test_signal)
     rc.addEvent(Event(TEST_EVENT_TYPE, TEST_EVENT_DATA1));
     rc.addEvent(Event(TEST_EVENT_TYPE, TEST_EVENT_DATA2));
 
+    EXPECT_CALL(rest, getUpdates(_))
+            .WillRepeatedly(Return(""));
     EXPECT_CALL(rest, sendReport(_, ::testing::Matcher<const Json::Value&>(rc.get())))
             .Times(1);
 
@@ -89,7 +87,7 @@ TEST_F(TestConnection, test_signal)
     conn.signal(ev);
     conn.signal(Event(TEST_EVENT_TYPE, TEST_EVENT_DATA2));
 
-    std::this_thread::sleep_for(std::chrono::milliseconds(100));
+    std::this_thread::sleep_for(std::chrono::milliseconds(1100));
 
     conn.stop();
 
index bb894fc..12faccc 100644 (file)
@@ -5,6 +5,7 @@
 #include <random>
 #include <fstream>
 #include <cerrno>
+#include <capi-system-info/system_info.h>
 #include "settings.h"
 
 using namespace NetworkManager;
@@ -18,19 +19,10 @@ const char OS_RELEASE_PATH[] = "/etc/os-release";
 const std::string DEFAULT_UNKNOWN{"unknown"};
 const std::chrono::seconds DEFAULT_KEEPALIVE(10);
 
-const std::string DEVICE_TYPE{"device-type"};
-const std::string DEVICE_MODEL{"device-model"};
 const std::string DEVICE_ID{"device-id"};
+const std::string DEVICE_SERIAL{"device-serial"};
 const std::string SERVER_ADDRESS{"device-id"};
 const std::chrono::seconds KEEPALIVE_TIME(123);
-const std::string DUMMY_OS_RELEASE{ R"-=(NAME=Tizen
-VERSION="4.0.0 (Tizen4/TV)"
-ID=tizen
-VERSION_ID=4.0.0
-PRETTY_NAME="Tizen 4.0.0 (Tizen4/TV)"
-ANSI_COLOR="0;36"
-CPE_NAME="cpe:/o:tizen:tizen:4.0.0"
-BUILD_ID=T-KTMAKUC-201709262043)-=" };
 
 std::string randomString(char minc, char maxc, int len)
 {
@@ -61,9 +53,8 @@ std::string createSettingsFile()
        << "URL=" << SERVER_ADDRESS << std::endl
        << "keepalive=" << KEEPALIVE_TIME.count() << std::endl
        << "[Device]" << std::endl
-       << "type=" << DEVICE_TYPE << std::endl
-       << "model=" << DEVICE_MODEL << std::endl
-       << "id=" << DEVICE_ID << std::endl;
+       << "id=" << DEVICE_ID << std::endl
+       << "serial=" << DEVICE_SERIAL << std::endl;
     return filename;
 }
 
@@ -93,9 +84,8 @@ TEST_F(TestSettings, test_Constructors)
 
     ASSERT_TRUE(settings.getServerAddress().empty());
     ASSERT_TRUE(settings.getDeviceId().empty());
+    ASSERT_TRUE(settings.getSerial().empty());
     ASSERT_FALSE(settings.isLoaded());
-    ASSERT_EQ(DEFAULT_UNKNOWN, settings.getDeviceType());
-    ASSERT_EQ(DEFAULT_UNKNOWN, settings.getDeviceModel());
     ASSERT_EQ(DEFAULT_KEEPALIVE, settings.getKeepAliveTimeout());
 
     std::string filename = createSettingsFile();
@@ -104,8 +94,7 @@ TEST_F(TestSettings, test_Constructors)
     ASSERT_TRUE(from_ini.isLoaded());
     ASSERT_EQ(SERVER_ADDRESS, from_ini.getServerAddress());
     ASSERT_EQ(DEVICE_ID, from_ini.getDeviceId());
-    ASSERT_EQ(DEVICE_TYPE, from_ini.getDeviceType());
-    ASSERT_EQ(DEVICE_MODEL, from_ini.getDeviceModel());
+    ASSERT_EQ(DEVICE_SERIAL, from_ini.getSerial());
     ASSERT_EQ(KEEPALIVE_TIME, from_ini.getKeepAliveTimeout());
 
     ASSERT_EQ(0, remove(filename.c_str()));
@@ -124,14 +113,6 @@ TEST_F(TestSettings, test_getters_setters)
     ASSERT_EQ(rstring, settings.getDeviceId());
 
     rstring = randomString('a', 'z', 10);
-    settings.setDeviceType(rstring);
-    ASSERT_EQ(rstring, settings.getDeviceType());
-
-    rstring = randomString('a', 'z', 10);
-    settings.setDeviceModel(rstring);
-    ASSERT_EQ(rstring, settings.getDeviceModel());
-
-    rstring = randomString('a', 'z', 10);
     settings.setServerAddress(rstring);
     ASSERT_EQ(rstring, settings.getServerAddress());