Rule management added.
[platform/core/security/suspicious-activity-monitor.git] / daemon / 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  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 /**
19  * @file   settings.h
20  * @brief  Application settings
21  * @date   Created Feb 14, 2018
22  * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
23  */
24 #ifndef SETTINGS_H
25 #define SETTINGS_H
26
27 #include <string>
28 #include <chrono>
29
30 namespace agent
31 {
32
33 /**
34  * @brief The Settings class reprensents application settings
35  */
36 class Settings
37 {
38 public:
39
40     static Settings& instance()
41     {
42         return _instance;
43     }
44
45     /**
46      * @brief getServerAddress returns the address of the DSM server
47      * @return URL as string
48      */
49     const std::string& getServerAddress() const
50     {
51         return serverAddress;
52     }
53
54     /**
55      * @brief getDeviceId returns the device identifier
56      * @return the device indentifier as string
57      */
58     const std::string& getDeviceId() const
59     {
60         return deviceId;
61     }
62
63     /**
64      * @brief getKeepAliveTimeout returns KeepAlive timeout period
65      * @return KeepAlive timeout period
66      */
67     const std::chrono::milliseconds& getKeepAliveTimeout() const
68     {
69         return keepAliveTimeout;
70     }
71
72     /**
73      * @brief setServerAddress sets the address of the DSM server
74      * @param address DSM server URL
75      */
76     void setServerAddress(const std::string& address)
77     {
78         serverAddress = address;
79     }
80
81     /**
82      * @brief setDeviceId sets the device identifier
83      * @param id the device identifier
84      */
85     void setDeviceId(const std::string& id)
86     {
87         deviceId = id;
88     }
89
90     /**
91      * @brief setKeepAliveTimeout sets KeepAlive timeout period
92      * @param keepalive KeepAlive timeout period
93      */
94     void setKeepAliveTimeout(const std::chrono::milliseconds& keepalive)
95     {
96         keepAliveTimeout = keepalive;
97     }
98
99     /**
100      * @brief setLock sets lock state
101      * @param locked lock state to set
102      */
103     void setLock(bool locked)
104     {
105         lock = locked;
106     }
107
108     /**
109      * @brief loadDefaults loads default settings from the default configuration file
110      * @return true if successfully loaded and false otherwise
111      */
112     bool loadDefaults();
113
114     /**
115      * @brief load loads settings from the configuration file
116      * @return true if successfully loaded and false otherwise
117      */
118     bool load();
119
120     /**
121      * @brief save saves settings to the file
122      * @return true if successfully saved and false otherwise
123      */
124     bool save() const;
125
126     /**
127      * @brief setSaveFileName sets the file path used to store settings
128      * @param fileName path to the file
129      */
130     void setSaveFileName(const std::string& fileName)
131     {
132         saveFileName = fileName;
133     }
134
135     /**
136      * @brief getSaveFileName return the path of the file used to store settings
137      * @return file path
138      */
139     const std::string& getSaveFileName() const
140     {
141         return saveFileName;
142     }
143
144     /**
145      * @brief isLoaded returns settings load state
146      * @return true if settings are loaded and false otherwise
147      */
148     bool isLoaded() const
149     {
150         return loaded;
151     }
152
153     /**
154      * @brief isLocked return lock state
155      * @return lock state
156      */
157     bool isLocked() const
158     {
159         return lock;
160     }
161
162 private:
163
164     /**
165      * @brief Settings default constructor
166      */
167     Settings();
168
169     bool _load(const std::string& fileName);
170
171     std::string serverAddress;
172     std::string deviceId;
173     std::chrono::milliseconds keepAliveTimeout;
174     std::string saveFileName;
175     bool loaded;
176     bool lock;
177     static Settings _instance;
178 };
179
180 } // namespace communication
181
182 #endif // SETTINGS_H