2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FAppAppRegistry.h
19 * @brief This is the header file for the %AppRegistry class.
21 * This header file contains the declarations of the %AppRegistry class.
24 #ifndef _FAPP_APP_REGISTRY_H_
25 #define _FAPP_APP_REGISTRY_H_
27 #include <FBaseObject.h>
28 #include <FAppTypes.h>
30 namespace Tizen { namespace App
35 * @brief This class manages an application's preferences.
39 * @final This class is not intended for extension.
41 * The %AppRegistry class lets an application to save or restore its preferences.
42 * An instance of this class can be obtained through the Application class.
43 * Also, since an application's state is generally restored in the App::OnAppInitializing() method and saved in the App::OnAppTerminating() method, an instance of this class is passed as an argument when these methods are invoked.
45 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/app/app_namespace.htm">App Guide</a>.
47 * The following example demonstrates how to use the %AppRegistry class.
52 * MyAppClass::AppRegistryCallSample(void)
54 * AppRegistry* pAppRegistry = GetAppRegistry();
55 * String countKey("BasicAppRunCount");
56 * String nameKey("BasicAppUserName");
57 * String temperatureKey("BasicAppTemperature");
58 * String name("BasicApp");
59 * double temperature = 32.5;
60 * result r = E_SUCCESS;
63 * r = pAppRegistry->Get(nameKey, name);
64 * if (r == E_KEY_NOT_FOUND)
66 * pAppRegistry->Add(nameKey, name);
69 * r = pAppRegistry->Get(countKey, count);
70 * if (r == E_KEY_NOT_FOUND)
72 * pAppRegistry->Add(countKey, count);
75 * r = pAppRegistry->Get(temperatureKey, temperature);
76 * if (r == E_KEY_NOT_FOUND)
78 * pAppRegistry->Add(temperatureKey, temperature);
81 * r = pAppRegistry->Save();
84 * // Failed to save data to registry
87 * // Displays the retrieved data
88 * AppLog("AppRegistry Name value [%ls]", name.GetPointer());
89 * AppLog("AppRegistry count [%d]", count);
90 * AppLog("AppRegistry temperature value [%f]", temperature);
92 * // Updates the state of the application variables
97 * // Saves the app registry
98 * r = pAppRegistry->Set(nameKey, name);
104 * r = pAppRegistry->Set(countKey, count);
110 * r = pAppRegistry->Set(temperatureKey, temperature);
116 * r = pAppRegistry->Save();
119 * // Failed to save data to registry
122 * // Retrieves the saved content
123 * pAppRegistry->Get(nameKey, name);
124 * pAppRegistry->Get(countKey, count);
125 * pAppRegistry->Get(temperatureKey, temperature);
127 * AppLog("AppRegistry Name value [%ls]", name.GetPointer());
128 * AppLog("AppRegistry count [%d]", count);
129 * AppLog("AppRegistry temperature value [%f]", temperature);
136 class _OSP_EXPORT_ AppRegistry
137 : public Tizen::Base::Object
141 * Adds a string value along with the specified @c key.
145 * @return An error code
146 * @param[in] key A key corresponding to the value
147 * @param[in] value A string value
148 * @exception E_SUCCESS The method is successful.
149 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
150 * @exception E_KEY_ALREADY_EXIST The key has already been used in the application preferences.
151 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
153 result Add(const Tizen::Base::String& key, const Tizen::Base::String& value);
156 * Adds an integer value along with the specified @c key.
160 * @return An error code
161 * @param[in] key A key corresponding to the value
162 * @param[in] value An integer value
163 * @exception E_SUCCESS The method is successful.
164 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
165 * @exception E_KEY_ALREADY_EXIST The key has already been used in the application preferences.
166 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
168 result Add(const Tizen::Base::String& key, int value);
171 * Adds a floating point value along with the specified @c key.
175 * @return An error code
176 * @param[in] key A key corresponding to the value
177 * @param[in] value A floating point value
178 * @exception E_SUCCESS The method is successful.
179 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
180 * @exception E_KEY_ALREADY_EXIST The key has already been used in the application preferences.
181 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
183 result Add(const Tizen::Base::String& key, double value);
186 * Sets a string value associated with the specified @c key.
190 * @return An error code
191 * @param[in] key A key corresponding to the value
192 * @param[in] value A string value
193 * @exception E_SUCCESS The method is successful.
194 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
195 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
196 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
198 result Set(const Tizen::Base::String& key, const Tizen::Base::String& value);
201 * Sets an integer value associated with the specified @c key.
205 * @return An error code
206 * @param[in] key A key corresponding to the value
207 * @param[in] value An integer value
208 * @exception E_SUCCESS The method is successful.
209 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
210 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
211 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
213 result Set(const Tizen::Base::String& key, int value);
216 * Sets a floating point value associated with the specified @c key.
220 * @return An error code
221 * @param[in] key A key corresponding to the value
222 * @param[in] value A floating point value
223 * @exception E_SUCCESS The method is successful.
224 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
225 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
226 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
228 result Set(const Tizen::Base::String& key, double value);
231 * Saves the values temporarily in the persistent storage. @n
232 * The %Save() method is invoked internally when the instance of this class is deleted.
236 * @return An error code
237 * @exception E_SUCCESS The method is successful.
242 * Removes a preference associated with the specified @c key.
246 * @return An error code
247 * @param[in] key The key of the value to remove
248 * @exception E_SUCCESS The method is successful.
249 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
251 result Remove(const Tizen::Base::String& key);
254 * Gets a string value associated with the specified @c key.
258 * @return An error code
259 * @param[in] key The key of the value to retrieve
260 * @param[out] value A string value to retrieve
261 * @exception E_SUCCESS The method is successful.
262 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
263 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
265 result Get(const Tizen::Base::String& key, Tizen::Base::String& value) const;
268 * Gets an integer value associated with the specified @c key.
272 * @return An error code
273 * @param[in] key The key of the value to retrieve
274 * @param[out] value An integer value to retrieve
275 * @exception E_SUCCESS The method is successful.
276 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
277 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
279 result Get(const Tizen::Base::String& key, int& value) const;
282 * Gets a floating point value associated with the specified @c key.
286 * @return An error code
287 * @param[in] key The key of the value to retrieve
288 * @param[out] value A floating point value to retrieve
289 * @exception E_SUCCESS The method is successful.
290 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
291 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
293 result Get(const Tizen::Base::String& key, double& value) const;
296 * Gets the %AppRegistry instance pointer.
300 * @return A pointer to the %AppRegistry instance, @n
301 * else @c null if it fails
303 static AppRegistry* GetInstance(void);
307 * This default constructor is intentionally declared as private to implement the %Singleton semantic.
314 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
318 AppRegistry(const AppRegistry& rhs);
321 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
325 AppRegistry& operator =(const AppRegistry& rhs);
328 * This destructor is intentionally declared as private to implement the %Singleton semantic.
332 virtual ~AppRegistry(void);
335 * Initializes this instance.
339 * @return An error code
340 * @exception E_SUCCESS The method is successful.
341 * @exception E_SYSTEM A system error has occurred.
343 result Construct(void);
346 class _AppRegistryImpl* __pAppRegistryImpl;
348 friend class _AppRegistryImpl;
353 #endif // _FAPP_APP_REGISTRY_H_