2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FAppAppRegistry.h
20 * @brief This is the header file for the %AppRegistry class.
22 * This header file contains the declarations of the %AppRegistry class.
25 #ifndef _FAPP_APP_REGISTRY_H_
26 #define _FAPP_APP_REGISTRY_H_
28 #include <FBaseObject.h>
29 #include <FAppTypes.h>
31 namespace Tizen { namespace App
36 * @brief This class manages an application's preferences.
40 * @final This class is not intended for extension.
42 * The %AppRegistry class lets an application to save or restore its preferences.
43 * An instance of this class can be obtained through the Application class.
44 * 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.
46 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/app/app_namespace.htm">App Guide</a>.
48 * The following example demonstrates how to use the %AppRegistry class.
53 * MyAppClass::AppRegistryCallSample(void)
55 * AppRegistry* pAppRegistry = GetAppRegistry();
56 * String countKey("BasicAppRunCount");
57 * String nameKey("BasicAppUserName");
58 * String temperatureKey("BasicAppTemperature");
59 * String name("BasicApp");
60 * double temperature = 32.5;
61 * result r = E_SUCCESS;
64 * r = pAppRegistry->Get(nameKey, name);
65 * if (r == E_KEY_NOT_FOUND)
67 * pAppRegistry->Add(nameKey, name);
70 * r = pAppRegistry->Get(countKey, count);
71 * if (r == E_KEY_NOT_FOUND)
73 * pAppRegistry->Add(countKey, count);
76 * r = pAppRegistry->Get(temperatureKey, temperature);
77 * if (r == E_KEY_NOT_FOUND)
79 * pAppRegistry->Add(temperatureKey, temperature);
82 * r = pAppRegistry->Save();
85 * // Failed to save data to registry
88 * // Displays the retrieved data
89 * AppLog("AppRegistry Name value [%ls]", name.GetPointer());
90 * AppLog("AppRegistry count [%d]", count);
91 * AppLog("AppRegistry temperature value [%f]", temperature);
93 * // Updates the state of the application variables
98 * // Saves the app registry
99 * r = pAppRegistry->Set(nameKey, name);
105 * r = pAppRegistry->Set(countKey, count);
111 * r = pAppRegistry->Set(temperatureKey, temperature);
117 * r = pAppRegistry->Save();
120 * // Failed to save data to registry
123 * // Retrieves the saved content
124 * pAppRegistry->Get(nameKey, name);
125 * pAppRegistry->Get(countKey, count);
126 * pAppRegistry->Get(temperatureKey, temperature);
128 * AppLog("AppRegistry Name value [%ls]", name.GetPointer());
129 * AppLog("AppRegistry count [%d]", count);
130 * AppLog("AppRegistry temperature value [%f]", temperature);
137 class _OSP_EXPORT_ AppRegistry
138 : public Tizen::Base::Object
142 * Adds a string value along with the specified @c key.
146 * @return An error code
147 * @param[in] key A key corresponding to the value
148 * @param[in] value A string value
149 * @exception E_SUCCESS The method is successful.
150 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
151 * @exception E_KEY_ALREADY_EXIST The key has already been used in the application preferences.
152 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
154 result Add(const Tizen::Base::String& key, const Tizen::Base::String& value);
157 * Adds an integer value along with the specified @c key.
161 * @return An error code
162 * @param[in] key A key corresponding to the value
163 * @param[in] value An integer value
164 * @exception E_SUCCESS The method is successful.
165 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
166 * @exception E_KEY_ALREADY_EXIST The key has already been used in the application preferences.
167 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
169 result Add(const Tizen::Base::String& key, int value);
172 * Adds a floating point value along with the specified @c key.
176 * @return An error code
177 * @param[in] key A key corresponding to the value
178 * @param[in] value A floating point value
179 * @exception E_SUCCESS The method is successful.
180 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
181 * @exception E_KEY_ALREADY_EXIST The key has already been used in the application preferences.
182 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
184 result Add(const Tizen::Base::String& key, double value);
187 * Sets a string value associated with the specified @c key.
191 * @return An error code
192 * @param[in] key A key corresponding to the value
193 * @param[in] value A string value
194 * @exception E_SUCCESS The method is successful.
195 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
196 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
197 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
199 result Set(const Tizen::Base::String& key, const Tizen::Base::String& value);
202 * Sets an integer value associated with the specified @c key.
206 * @return An error code
207 * @param[in] key A key corresponding to the value
208 * @param[in] value An integer value
209 * @exception E_SUCCESS The method is successful.
210 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
211 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
212 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
214 result Set(const Tizen::Base::String& key, int value);
217 * Sets a floating point value associated with the specified @c key.
221 * @return An error code
222 * @param[in] key A key corresponding to the value
223 * @param[in] value A floating point value
224 * @exception E_SUCCESS The method is successful.
225 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
226 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
227 * @remarks In order to save the value in the persistent storage, the Save() method must be called.
229 result Set(const Tizen::Base::String& key, double value);
232 * Saves the values temporarily in the persistent storage. @n
233 * The %Save() method is invoked internally when the instance of this class is deleted.
237 * @return An error code
238 * @exception E_SUCCESS The method is successful.
243 * Removes a preference associated with the specified @c key.
247 * @return An error code
248 * @param[in] key The key of the value to remove
249 * @exception E_SUCCESS The method is successful.
250 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
252 result Remove(const Tizen::Base::String& key);
255 * Gets a string value associated with the specified @c key.
259 * @return An error code
260 * @param[in] key The key of the value to retrieve
261 * @param[out] value A string value to retrieve
262 * @exception E_SUCCESS The method is successful.
263 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
264 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
266 result Get(const Tizen::Base::String& key, Tizen::Base::String& value) const;
269 * Gets an integer value associated with the specified @c key.
273 * @return An error code
274 * @param[in] key The key of the value to retrieve
275 * @param[out] value An integer value to retrieve
276 * @exception E_SUCCESS The method is successful.
277 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
278 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
280 result Get(const Tizen::Base::String& key, int& value) const;
283 * Gets a floating point value associated with the specified @c key.
287 * @return An error code
288 * @param[in] key The key of the value to retrieve
289 * @param[out] value A floating point value to retrieve
290 * @exception E_SUCCESS The method is successful.
291 * @exception E_INVALID_ARG The specified @c key is empty or is string with '\0' and @htmlonly '\n' @endhtmlonly.
292 * @exception E_KEY_NOT_FOUND The specified @c key is not used in the application preferences.
294 result Get(const Tizen::Base::String& key, double& value) const;
297 * Gets the %AppRegistry instance pointer.
301 * @return A pointer to the %AppRegistry instance, @n
302 * else @c null if it fails
304 static AppRegistry* GetInstance(void);
308 * This default constructor is intentionally declared as private to implement the %Singleton semantic.
315 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
319 AppRegistry(const AppRegistry& rhs);
322 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
326 AppRegistry& operator =(const AppRegistry& rhs);
329 * This destructor is intentionally declared as private to implement the %Singleton semantic.
333 virtual ~AppRegistry(void);
336 * Initializes this instance.
340 * @return An error code
341 * @exception E_SUCCESS The method is successful.
342 * @exception E_SYSTEM A system error has occurred.
344 result Construct(void);
347 class _AppRegistryImpl* __pAppRegistryImpl;
349 friend class _AppRegistryImpl;
354 #endif // _FAPP_APP_REGISTRY_H_