common: apply Tizen Coding Rule
[platform/core/system/libstorage.git] / include / storage-expand.h
1 /*
2  * storage
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18
19 #ifndef __STORAGE_EXPAND_H__
20 #define __STORAGE_EXPAND_H__
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26
27  /**
28  * @addtogroup CAPI_SYSTEM_STORAGE_MODULE
29  * @{
30  */
31
32 #include <tizen.h>
33
34 /**
35  * @brief Enumeration of error codes for Storage.
36  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
37  */
38 typedef enum {
39     STORAGE_ERROR_NONE              = TIZEN_ERROR_NONE,                /**< Successful */
40     STORAGE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,   /**< Invalid parameter */
41     STORAGE_ERROR_OUT_OF_MEMORY     = TIZEN_ERROR_OUT_OF_MEMORY,       /**< Out of memory */
42     STORAGE_ERROR_NOT_SUPPORTED     = TIZEN_ERROR_NO_SUCH_DEVICE,      /**< Storage not supported */
43     STORAGE_ERROR_OPERATION_FAILED  = TIZEN_ERROR_SYSTEM_CLASS | 0x12, /**< Operation failed */
44 } storage_error_e;
45
46
47 /**
48  * @brief Enumeration of the storage types.
49  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
50  */
51 typedef enum {
52     STORAGE_TYPE_INTERNAL, /**< Internal device storage (built-in storage in a device, non-removable) */
53     STORAGE_TYPE_EXTERNAL, /**< External storage */
54 } storage_type_e;
55
56
57 /**
58  * @brief Enumeration of the state of storage devices.
59  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
60  */
61 typedef enum {
62     STORAGE_STATE_UNMOUNTABLE = -2, /**< Storage is present but cannot be mounted. Typically it happens if the file system of the storage is corrupted */
63     STORAGE_STATE_REMOVED = -1, /**< Storage is not present */
64     STORAGE_STATE_MOUNTED = 0, /**< Storage is present and mounted with read/write access */
65     STORAGE_STATE_MOUNTED_READ_ONLY = 1, /**< Storage is present and mounted with read only access */
66 } storage_state_e;
67
68 /**
69  * @brief Called to get information once for each supported storage.
70  *
71  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
72  *
73  * @param[in] storage_id The unique storage ID
74  * @param[in] type The type of the storage
75  * @param[in] state The current state of the storage
76  * @param[in] path The absolute path to the root directory of the storage
77  * @param[in] user_data The user data passed from the foreach function
78  *
79  * @return @c true to continue with the next iteration of the loop, \n
80  *         otherwise @c false to break out of the loop
81  *
82  * @pre storage_foreach_device_supported() will invoke this callback function.
83  * @see storage_foreach_device_supported()
84  */
85 typedef bool (*storage_device_supported_cb)(int storage_id, storage_type_e type,
86                 storage_state_e state, const char *path, void *user_data);
87
88 /**
89  * @brief Retrieves all storage in a device.
90  * @details This function invokes the callback function once for each storage in a device. \n
91  *          If storage_device_supported_cb() returns @c false, then the iteration will be finished.
92  *
93  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
94  *
95  * @param[in] callback The iteration callback function
96  * @param[in] user_data The user data to be passed to the callback function
97  *
98  * @return @c 0 on success,
99  *         otherwise a negative error value
100  *
101  * @retval #STORAGE_ERROR_NONE               Successful
102  * @retval #STORAGE_ERROR_INVALID_PARAMETER  Invalid parameter
103  *
104  * @post This function invokes storage_device_supported_cb() repeatedly for each supported device.
105  * @see storage_device_supported_cb()
106  */
107 int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data);
108
109 /**
110  * @brief Gets the absolute path to the root directory of the given storage.
111  * @details Files saved on the internal/external storage are readable or writeable by all applications.
112  *          When an application is uninstalled, the files written by that application are not removed from the internal/external storage.
113  *
114  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
115  *
116  * @remarks If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n
117  * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n
118  * You must release @a path using free().
119  *
120  * @param[in] storage_id The storage device
121  * @param[out] path The absolute path to the storage directory
122  *
123  * @return @c 0 on success,
124  *         otherwise a negative error value
125  *
126  * @retval #STORAGE_ERROR_NONE               Successful
127  * @retval #STORAGE_ERROR_INVALID_PARAMETER  Invalid parameter
128  * @retval #STORAGE_ERROR_OUT_OF_MEMORY      Out of memory
129  * @retval #STORAGE_ERROR_NOT_SUPPORTED      Storage not supported
130  *
131  * @see storage_get_state()
132  */
133 int storage_get_root_directory(int storage_id, char **path);
134
135 /**
136  * @brief Enumeration of the storage directory types
137  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
138  */
139 typedef enum {
140         STORAGE_DIRECTORY_IMAGES,           /**< Image directory */
141         STORAGE_DIRECTORY_SOUNDS,           /**< Sounds directory */
142         STORAGE_DIRECTORY_VIDEOS,           /**< Videos directory */
143         STORAGE_DIRECTORY_CAMERA,           /**< Camera directory */
144         STORAGE_DIRECTORY_DOWNLOADS,        /**< Downloads directory */
145         STORAGE_DIRECTORY_MUSIC,            /**< Music directory */
146         STORAGE_DIRECTORY_DOCUMENTS,        /**< Documents directory */
147         STORAGE_DIRECTORY_OTHERS,           /**< Others directory */
148         STORAGE_DIRECTORY_SYSTEM_RINGTONES, /**< System ringtones directory. Only available for internal storage. */
149         STORAGE_DIRECTORY_MAX
150 } storage_directory_e;
151
152 /**
153  * @brief Gets the absolute path to the each directory of the given storage.
154  * @details Files saved on the internal/external storage are readable or writeable by all applications.
155  *          When an application is uninstalled, the files written by that application are not removed from the internal/external storage.
156  *
157  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
158  *
159  * @remarks The directory path may not exist, so you must make sure that it exists before using it.\n
160  * If you want to access files or directories in internal storage except #STORAGE_DIRECTORY_SYSTEM_RINGTONES, you must declare http://tizen.org/privilege/mediastorage.\n
161  * If you want to access files or directories in #STORAGE_DIRECTORY_SYSTEM_RINGTONES, you must declare %http://tizen.org/privilege/systemsettings.\n
162  * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n
163  * You must release @a path using free().
164  *
165  * @param[in] storage_id The storage device
166  * @param[in] type The directory type
167  * @param[out] path The absolute path to the directory type
168  *
169  * @return @c 0 on success,
170  *         otherwise a negative error value
171  *
172  * @retval #STORAGE_ERROR_NONE               Successful
173  * @retval #STORAGE_ERROR_INVALID_PARAMETER  Invalid parameter
174  * @retval #STORAGE_ERROR_OUT_OF_MEMORY      Out of memory
175  * @retval #STORAGE_ERROR_NOT_SUPPORTED      Storage not supported
176  *
177  * @see storage_get_state()
178  */
179 int storage_get_directory(int storage_id, storage_directory_e type, char **path);
180
181 /**
182  * @brief Gets the type of the given storage.
183  *
184  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
185  *
186  * @param[in] storage_id The storage device
187  * @param[out] type The type of the storage
188  *
189  * @return @c 0 on success,
190  *         otherwise a negative error value
191  *
192  * @retval #STORAGE_ERROR_NONE               Successful
193  * @retval #STORAGE_ERROR_INVALID_PARAMETER  Invalid parameter
194  * @retval #STORAGE_ERROR_NOT_SUPPORTED      Storage not supported
195  */
196 int storage_get_type(int storage_id, storage_type_e *type);
197
198 /**
199  * @brief Gets the current state of the given storage.
200  *
201  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
202  *
203  * @param[in] storage_id The storage device
204  * @param[out] state The current state of the storage
205  *
206  * @return @c 0 on success,
207  *         otherwise a negative error value
208  *
209  * @retval #STORAGE_ERROR_NONE               Successful
210  * @retval #STORAGE_ERROR_INVALID_PARAMETER  Invalid parameter
211  * @retval #STORAGE_ERROR_NOT_SUPPORTED      Storage not supported
212  *
213  * @see storage_get_root_directory()
214  * @see storage_get_total_space()
215  * @see storage_get_available_space()
216  */
217 int storage_get_state(int storage_id, storage_state_e *state);
218
219 /**
220  * @brief Called when the state of storage changes
221  *
222  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
223  *
224  * @param[in] storage_id The unique storage ID
225  * @param[in] state The current state of the storage
226  * @param[in] user_data The user data passed from the foreach function
227  *
228  * @pre storage_set_state_changed_cb() will invoke this callback function.
229  * @see storage_set_state_changed_cb()
230  * @see storage_unset_state_changed_cb()
231  */
232 typedef void (*storage_state_changed_cb)(int storage_id, storage_state_e state, void *user_data);
233
234 /**
235  * @brief Registers a callback function to be invoked when the state of the storage changes.
236  *
237  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
238  *
239  * @param[in] storage_id The storage device
240  * @param[in] callback The callback function to register
241  * @param[in] user_data The user data to be passed to the callback function
242  *
243  * @return @c 0 on success,
244  *         otherwise a negative error value
245  *
246  * @retval #STORAGE_ERROR_NONE               Successful
247  * @retval #STORAGE_ERROR_INVALID_PARAMETER  Invalid parameter
248  * @retval #STORAGE_ERROR_NOT_SUPPORTED      Storage not supported
249  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
250  *
251  * @post storage_state_changed_cb() will be invoked if the state of the registered storage changes.
252  * @see storage_state_changed_cb()
253  * @see storage_unset_state_changed_cb()
254  */
255 int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb callback, void *user_data);
256
257 /**
258  * @brief Unregisters the callback function.
259  *
260  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
261  *
262  * @param[in] storage_id The storage device to monitor
263  * @param[in] callback The callback function to register
264  *
265  * @return @c 0 on success,
266  *         otherwise a negative error value
267  *
268  * @retval #STORAGE_ERROR_NONE               Successful
269  * @retval #STORAGE_ERROR_INVALID_PARAMETER  Invalid parameter
270  * @retval #STORAGE_ERROR_NOT_SUPPORTED      Storage not supported
271  * @retval #STORAGE_ERROR_OPERATION_FAILED   Operation failed
272  *
273  * @see storage_state_changed_cb()
274  * @see storage_set_state_changed_cb()
275  */
276 int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb callback);
277
278 /**
279  * @brief Gets the total space of the given storage in bytes.
280  *
281  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
282  *
283  * @param[in] storage_id The storage device
284  * @param[out] bytes The total space size of the storage (bytes)
285  *
286  * @return @c 0 on success,
287  *         otherwise a negative error value
288  *
289  * @retval #STORAGE_ERROR_NONE               Successful
290  * @retval #STORAGE_ERROR_INVALID_PARAMETER  Invalid parameter
291  * @retval #STORAGE_ERROR_NOT_SUPPORTED      Storage not supported
292  * @retval #STORAGE_ERROR_OPERATION_FAILED   Operation failed
293  *
294  * @see storage_get_state()
295  * @see storage_get_available_space()
296  */
297 int storage_get_total_space(int storage_id, unsigned long long *bytes);
298
299 /**
300  * @brief Gets the available space size of the given storage in bytes.
301  *
302  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
303  *
304  * @param[in] storage_id The storage device
305  * @param[out] bytes The available space size of the storage (bytes)
306  *
307  * @return @c 0 on success,
308  *         otherwise a negative error value
309  *
310  * @retval #STORAGE_ERROR_NONE               Successful
311  * @retval #STORAGE_ERROR_INVALID_PARAMETER  Invalid parameter
312  * @retval #STORAGE_ERROR_NOT_SUPPORTED      Storage not supported
313  * @retval #STORAGE_ERROR_OPERATION_FAILED   Operation failed
314  *
315  * @see storage_get_state()
316  * @see storage_get_total_space()
317  */
318 int storage_get_available_space(int storage_id, unsigned long long *bytes);
319
320 /**
321  * @}
322  */
323
324 #ifdef __cplusplus
325 }
326 #endif
327 #endif