9ee03696e2b8244a5e2a220e35a2510393ec5889
[platform/core/security/suspicious-activity-monitor.git] / device-agent / communication / src / sysinfo.cpp
1 /**
2  * Samsung Ukraine R&D Center (SRK under a contract between)
3  * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
5  */
6 /**
7  * @file   sysinfo.h
8  * @brief  System information collector
9  * @date   Created Feb 26, 2018
10  * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
11  */
12
13 #include "sysinfo.h"
14 #include <system/system_info.h>
15
16 namespace
17 {
18
19 /**
20  * @brief getStringSystemProperty returns system property as std::string
21  * @param prop the requested system property key
22  * @return requested system property on success and "undefined" otherwise
23  */
24 std::string getStringSystemProperty(system_info_key_e prop)
25 {
26     std::string property{"undefined"};
27     char* val;
28
29     if (0 == system_info_get_value_string(prop, &val)) {
30         property.assign(val);
31         free(val);
32     }
33
34     return property;
35 }
36
37 /**
38  * @brief getStringPlatformProperty returns platform property as std::string
39  * @param prop the requested platform property key
40  * @return requested platform property on success and "undefined" otherwise
41  */
42 std::string getStringPlatformProperty(const char* prop)
43 {
44     std::string property{"undefined"};
45     char* val;
46
47     if (0 == system_info_get_platform_string(prop, &val)) {
48         property.assign(val);
49         free(val);
50     }
51
52     return property;
53 }
54
55 }
56
57 namespace NetworkManager
58 {
59
60 std::string SysInfo::model()
61 {
62     return getStringSystemProperty(SYSTEM_INFO_KEY_MODEL);
63 }
64
65 std::string SysInfo::type()
66 {
67     return getStringPlatformProperty("com.samsung/build_config/product_type");
68 }
69
70 std::string SysInfo::osVersion()
71 {
72     return getStringPlatformProperty("tizen.org/feature/platform.version");
73 }
74
75 std::string SysInfo::osName()
76 {
77     return getStringSystemProperty(SYSTEM_INFO_KEY_PLATFORM_NAME);
78 }
79
80 std::string SysInfo::swVersion()
81 {
82     return getStringSystemProperty(SYSTEM_INFO_KEY_TIZEN_VERSION);
83 }
84
85 }