[SECARSP-269] Policies state handler for device agent implemented. Tizen ID used...
[platform/core/security/suspicious-activity-monitor.git] / device-agent / communication / inc / settings.h
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   settings.h
8  * @brief  Application settings
9  * @date   Created Feb 14, 2018
10  * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
11  */
12 #ifndef SETTINGS_H
13 #define SETTINGS_H
14
15 #include <string>
16 #include <chrono>
17
18 namespace NetworkManager
19 {
20
21 /**
22  * @brief The Settings class reprensents application settings
23  */
24 class Settings
25 {
26 public:
27
28     static Settings& instance()
29     {
30         return _instance;
31     }
32
33     /**
34      * @brief getServerAddress returns the address of the DSM server
35      * @return URL as string
36      */
37     const std::string& getServerAddress() const
38     {
39         return serverAddress;
40     }
41
42     /**
43      * @brief getDeviceId returns the device identifier
44      * @return the device indentifier as string
45      */
46     const std::string& getDeviceId() const
47     {
48         return deviceId;
49     }
50
51     /**
52      * @brief getKeepAliveTimeout returns KeepAlive timeout period
53      * @return KeepAlive timeout period
54      */
55     const std::chrono::milliseconds& getKeepAliveTimeout() const
56     {
57         return keepAliveTimeout;
58     }
59
60     /**
61      * @brief setServerAddress sets the address of the DSM server
62      * @param address DSM server URL
63      */
64     void setServerAddress(const std::string& address)
65     {
66         serverAddress = address;
67     }
68
69     /**
70      * @brief setDeviceId sets the device identifier
71      * @param id the device identifier
72      */
73     void setDeviceId(const std::string& id)
74     {
75         deviceId = id;
76     }
77
78     /**
79      * @brief setKeepAliveTimeout sets KeepAlive timeout period
80      * @param keepalive KeepAlive timeout period
81      */
82     void setKeepAliveTimeout(const std::chrono::milliseconds& keepalive)
83     {
84         keepAliveTimeout = keepalive;
85     }
86
87     /**
88      * @brief setLock sets lock state
89      * @param locked lock state to set
90      */
91     void setLock(bool locked)
92     {
93         lock = locked;
94     }
95
96     /**
97      * @brief loadDefaults loads default settings from the default configuration file
98      * @return true if successfully loaded and false otherwise
99      */
100     bool loadDefaults();
101
102     /**
103      * @brief load loads settings from the configuration file
104      * @return true if successfully loaded and false otherwise
105      */
106     bool load();
107
108     /**
109      * @brief save saves settings to the file
110      * @return true if successfully saved and false otherwise
111      */
112     bool save() const;
113
114     /**
115      * @brief setSaveFileName sets the file path used to store settings
116      * @param fileName path to the file
117      */
118     void setSaveFileName(const std::string& fileName)
119     {
120         saveFileName = fileName;
121     }
122
123     /**
124      * @brief getSaveFileName return the path of the file used to store settings
125      * @return file path
126      */
127     const std::string& getSaveFileName() const
128     {
129         return saveFileName;
130     }
131
132     /**
133      * @brief isLoaded returns settings load state
134      * @return true if settings are loaded and false otherwise
135      */
136     bool isLoaded() const
137     {
138         return loaded;
139     }
140
141     /**
142      * @brief isLocked return lock state
143      * @return lock state
144      */
145     bool isLocked() const
146     {
147         return lock;
148     }
149
150 private:
151
152     /**
153      * @brief Settings default constructor
154      */
155     Settings();
156
157     bool _load(const std::string& fileName);
158
159     std::string serverAddress;
160     std::string deviceId;
161     std::chrono::milliseconds keepAliveTimeout;
162     std::string saveFileName;
163     bool loaded;
164     bool lock;
165     static Settings _instance;
166 };
167
168 } // namespace NetworkManager
169
170 #endif // SETTINGS_H