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}")
std::queue<Event> eventQueue;
Settings& settings;
DeviceState state;
- DeviceInfo dinfo;
+ SessionInfo sinfo;
IRestService* rest;
std::mutex locker;
std::condition_variable notice;
#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 */
};
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;
};
}
~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;
};
}
/**
- * @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
*/
}
/**
- * @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
*/
}
/**
- * @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
*/
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;
--- /dev/null
+/**
+ * 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
#include "samonitor_tag.h"
#include "reportcomposer.h"
#include "resource.h"
+#include <iostream>
namespace NetworkManager
{
, 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;
}
std::chrono::steady_clock clock;
std::chrono::steady_clock::time_point next = clock.now();
auto period = settings.getKeepAliveTimeout();
- next += period;
while(work)
{
{
case DeviceState::REGISTER:
if (reg()) {
- settings.setDeviceId(dinfo.duid);
+ settings.setDeviceId(sinfo.duid);
settings.save();
state = DeviceState::AUTHORIZE;
}
}
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;
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());
}
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()
#include "rest_request.h"
#include "logging.h"
#include "samonitor_tag.h"
+#include "sysinfo.h"
namespace
{
}
-std::string RestService::getUpdates(const DeviceInfo& info)
+std::string RestService::getUpdates(const SessionInfo& info)
{
RestRequest request(host);
RestRequest::QueryParameters params{{"duid", info.duid}};
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);
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");
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;
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)
{
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
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()
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());
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;
--- /dev/null
+/**
+ * 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);
+}
+
+}
Source0: %{name}-%{version}.tar.gz
BuildRequires: cmake
+BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(libcurl)
BuildRequires: pkgconfig(dpm)
boost_thread
boost_serialization
curl
+ capi-system-info
)
# systemd dependency handling
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;
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) {
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;
}
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()
{
}
-/**
- * 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
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}"
boost_system boost_thread boost_serialization
dlog
curl
+ capi-system-info
)
target_link_libraries(${PROJECT_NAME} ${TEST_LINK_LIBRARIES})
{
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));
};
}
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}"};
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
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);
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();
#include <random>
#include <fstream>
#include <cerrno>
+#include <capi-system-info/system_info.h>
#include "settings.h"
using namespace NetworkManager;
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)
{
<< "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;
}
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();
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()));
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());