4a1e35e01c85f581f4aa4589e6c321fa0fa6d61a
[platform/framework/native/appfw.git] / src / app / FApp_AppRegistryImpl.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        FApp_AppRegistryImpl.h
19  * @brief       This is the header file of the _AppRegistryImpl class.
20  */
21
22 #ifndef _FAPP_INTERNAL_APP_REGISTRY_IMPL_H_
23 #define _FAPP_INTERNAL_APP_REGISTRY_IMPL_H_
24
25 #include <FBaseObject.h>
26 #include <FAppTypes.h>
27
28 namespace Tizen { namespace Base { namespace Runtime { class Mutex; } } }
29 namespace Tizen { namespace Io { class Registry; } }
30
31 namespace Tizen { namespace App
32 {
33
34 /**
35  * @class               _AppRegistryImpl
36  * @brief               This class manages an application's preferences.
37  * @since               1.0
38  */
39 class _AppRegistryImpl
40         : public Tizen::Base::Object
41 {
42 public:
43         /**
44          * This is the destructor for this class.
45          *
46          * @since               1.0
47          */
48         virtual ~_AppRegistryImpl(void);
49
50         /**
51          * Adds a string value along with the specified key.
52          *
53          * @since               1.0
54          * @return      An error code
55          * @param[in]   key             A key corresponding to the value
56          * @param[in]   value   A string value
57          * @exception   E_SUCCESS                               The method is successful.
58          * @exception   E_INVALID_ARG                   The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
59          * @exception   E_KEY_ALREADY_EXIST             The key has already been used in the application preferences.
60          * @exception   E_OUT_OF_MEMORY                 Insufficient memory.
61          * @remark      In order to save the value in the persistent storage, the _AppRegistryImpl::Save() method must be called.
62          */
63         result Add(const Tizen::Base::String& key, const Tizen::Base::String& value);
64
65         /**
66          * Adds an integer value along with the specified key.
67          *
68          * @since               1.0
69          * @return      An error code
70          * @param[in]   key             A key corresponding to the value
71          * @param[in]   value   An integer value
72          * @exception   E_SUCCESS                               The method is successful.
73          * @exception   E_INVALID_ARG                   The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
74          * @exception   E_KEY_ALREADY_EXIST             The key has already been used in the application preferences.
75          * @exception   E_OUT_OF_MEMORY                 Insufficient memory.
76          * @remark      Call the _AppRegistryImpl::Save() method to save the value in the persistent storage.
77          */
78         result Add(const Tizen::Base::String& key, int value);
79
80         /**
81          * Adds a floating point value along with the specified key.
82          *
83          * @since               1.0
84          * @return      An error code
85          * @param[in]   key             A key corresponding to the value
86          * @param[in]   value   A floating point value
87          * @exception   E_SUCCESS                               The method is successful.
88          * @exception   E_INVALID_ARG                   The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
89          * @exception   E_KEY_ALREADY_EXIST             The key has already been used in the application preferences.
90          * @exception   E_OUT_OF_MEMORY                 Insufficient memory.
91          * @remark      Call the _AppRegistryImpl::Save() method to save the value in the persistent storage.
92          */
93         result Add(const Tizen::Base::String& key, double value);
94
95         /**
96          * Updates a string value associated with the specified key.
97          *
98          * @since               1.0
99          * @return      An error code
100          * @param[in]   key             A key corresponding to the value
101          * @param[in]   value   A string value
102          * @exception   E_SUCCESS                       The method is successful.
103          * @exception   E_INVALID_ARG           The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
104          * @exception   E_KEY_NOT_FOUND         The specified key was not used in the application preferences.
105          * @exception   E_OUT_OF_MEMORY         Insufficient memory.
106          * @remark      Call the _AppRegistryImpl::Save() method to save the value in the persistent storage.
107          */
108         result Set(const Tizen::Base::String& key, const Tizen::Base::String& value);
109
110         /**
111          * Updates an integer value associated with the specified key.
112          *
113          * @since               1.0
114          * @return      An error code
115          * @param[in]   key     A key corresponding to the value
116          * @param[in]   value   An integer value
117          * @exception   E_SUCCESS                       The method is successful.
118          * @exception   E_INVALID_ARG           The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
119          * @exception   E_KEY_NOT_FOUND         The specified key was not used in the application preferences.
120          * @exception   E_OUT_OF_MEMORY         Insufficient memory.
121          * @remark      Call the _AppRegistryImpl::Save() method to save the value in the persistent storage.
122          */
123         result Set(const Tizen::Base::String& key, int value);
124
125         /**
126          * Updates a floating point value associated with the specified key.
127          *
128          * @since               1.0
129          * @return      An error code
130          * @param[in]   key     A key corresponding to the value
131          * @param[in]   value   A floating point value
132          * @exception   E_SUCCESS                       The method is successful.
133          * @exception   E_INVALID_ARG           The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
134          * @exception   E_KEY_NOT_FOUND         The specified key was not used in the application preferences.
135          * @exception   E_OUT_OF_MEMORY         Insufficient memory.
136          * @remark      Call the _AppRegistryImpl::Save() method to save the value in the persistent storage.
137          */
138         result Set(const Tizen::Base::String& key, double value);
139
140         /**
141          * Saves the values temporarily in the persistent storage. @n
142          * This method is invoked internally when the instance of this class is deleted.
143          *
144          * @since               1.0
145          * @return      An error code
146          * @exception   E_SUCCESS                       The method is successful.
147          */
148         result Save(void);
149
150         /**
151          * Removes a preference associated with the specified key.
152          *
153          * @since               1.0
154          * @return      An error code
155          * @param[in]   key             The key of the value to be removed
156          * @exception   E_SUCCESS                               The method is successful.
157          * @exception   E_KEY_NOT_FOUND         The specified key was not used in the application preferences.
158          */
159         result Remove(const Tizen::Base::String& key);
160
161         /**
162          * Retrieves a string value associated with the specified key.
163          *
164          * @since               1.0
165          * @return      An error code
166          * @param[in]   key             The key of the value to retrieve
167          * @param[out]  value   A string value to be retrieved
168          * @exception   E_SUCCESS                       The method is successful.
169          * @exception   E_INVALID_ARG           The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
170          * @exception   E_KEY_NOT_FOUND         The specified key was not used in the application preferences.
171          */
172         result Get(const Tizen::Base::String& key, Tizen::Base::String& value) const;
173
174         /**
175          * Retrieves an integer value associated with the specified key.
176          *
177          * @since               1.0
178          * @return      An error code
179          * @param[in]   key             The key of the value to retrieve
180          * @param[out]  value   An integer value to be retrieved
181          * @exception   E_SUCCESS                       The method is successful.
182          * @exception   E_INVALID_ARG           The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
183          * @exception   E_KEY_NOT_FOUND         The specified key was not used in the application preferences.
184          */
185         result Get(const Tizen::Base::String& key, int& value) const;
186
187         /**
188          * Retrieves a floating point value associated with the specified key.
189          *
190          * @since               1.0
191          * @return      An error code
192          * @param[in]   key             The key of the value to retrieve
193          * @param[out]  value   A floating point value to be retrieved
194          * @exception   E_SUCCESS                       The method is successful.
195          * @exception   E_INVALID_ARG           The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
196          * @exception   E_KEY_NOT_FOUND         The specified key was not used in the application preferences.
197          */
198         result Get(const Tizen::Base::String& key, double& value) const;
199
200 private:
201         /**
202          * This is the default constructor for this class.
203          *
204          * @since 1.0
205          */
206         _AppRegistryImpl(void);
207
208         /**
209          * This is the copy constructor for this class.
210          *
211          * @since       1.0
212          */
213         _AppRegistryImpl(const _AppRegistryImpl& source);
214
215         /**
216          * Allocates memory for an _AppRegistryImpl object.
217          *
218          * @since       1.0
219          * @return      An error code
220          * @exception   E_SUCCESS       The method is successful.
221          */
222         result Construct(void);
223
224         /**
225          * This is the assignment operator for this class.
226          */
227         _AppRegistryImpl& operator =(const _AppRegistryImpl& source);
228
229 private:
230         enum LoadType {
231                 READ_ONLY,
232                 READ_WRITE
233         };
234
235         /**
236          * Loads the registry file.
237          *
238          * @since               2.2
239          * @return              The registry instance
240          * @exception   E_SUCCESS       The method is successful.
241          */
242         Tizen::Io::Registry* LoadN(LoadType type) const;
243
244 private:
245         const Tizen::Base::String __sectionName;
246         Tizen::Base::String __regPath;
247         mutable Tizen::Base::Runtime::Mutex __mutex;
248
249         friend class AppRegistry;
250 }; // _AppRegistryImpl
251
252 } } // Tizen::App
253
254 #endif // _FAPP_INTERNAL_APP_REGISTRY_IMPL_H_