4 * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 #include "service_adaptor_errors.h"
27 #include "service_adaptor_internal.h"
28 #include "sal_service_adaptor.h"
29 #include "sal_service_adaptor_internal.h"
30 #include "sal_service_task.h"
31 #include "sal_service_task_internal.h"
32 #include "sal_service_storage.h"
33 #include "sal_service_storage_internal.h"
34 #include "sal_ipc_client_storage.h"
36 //******************************************************************************
37 //* Global variables and defines
38 //******************************************************************************
40 //******************************************************************************
42 //******************************************************************************
44 //******************************************************************************
45 //* Private interface definition
46 //******************************************************************************
48 int service_storage_cloud_start(service_storage_cloud_file_h file)
52 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
53 RETV_IF(NULL == file->plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
55 int ret = SERVICE_ADAPTOR_ERROR_NONE;
58 ret = service_plugin_get_uri(file->plugin, &uri);
59 RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "service_plugin_get_uri() Failed(%d)", ret);
61 service_storage_cloud_file_h cloud_file = NULL;
62 ret = ipc_service_storage_cloud_file(uri, file, &cloud_file);
63 RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "ipc_service_storage_cloud_file() Failed(%d)", ret);
65 RETV_IF(NULL == file->callback, SERVICE_ADAPTOR_ERROR_NONE);
67 file->callback(SERVICE_ADAPTOR_ERROR_NONE, cloud_file, file->user_data);
69 return SERVICE_ADAPTOR_ERROR_NONE;
72 int service_storage_cloud_stop(service_storage_cloud_file_h file)
76 return SERVICE_ADAPTOR_ERROR_NONE;
79 //******************************************************************************
80 //* Public interface definition
81 //******************************************************************************
83 API int service_storage_cloud_file_create(service_plugin_h plugin, service_storage_cloud_file_h *file)
87 RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
88 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
90 service_storage_cloud_file_h cloud_file = (service_storage_cloud_file_h) g_malloc0(sizeof(service_storage_cloud_file_s));
91 cloud_file->plugin = plugin;
92 cloud_file->callback = NULL;
93 cloud_file->is_dir = false;
95 cloud_file->dir_path = NULL;
96 cloud_file->local_path = NULL;
97 cloud_file->cloud_path = NULL;
98 cloud_file->operation = NULL;
99 cloud_file->files = NULL;
103 return SERVICE_ADAPTOR_ERROR_NONE;
106 API int service_storage_cloud_file_clone(service_storage_cloud_file_h src_file, service_storage_cloud_file_h *dst_file)
110 RETV_IF(NULL == src_file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
111 RETV_IF(NULL == dst_file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
113 service_storage_cloud_file_h cloud_file = (service_storage_cloud_file_h) g_malloc0(sizeof(service_storage_cloud_file_s));
114 cloud_file->plugin = src_file->plugin;
115 cloud_file->callback = src_file->callback;
116 cloud_file->is_dir = src_file->is_dir;
117 cloud_file->size = src_file->size;
118 cloud_file->dir_path = g_strdup(src_file->dir_path);
119 cloud_file->local_path = g_strdup(src_file->local_path);
120 cloud_file->cloud_path = g_strdup(src_file->cloud_path);
121 cloud_file->operation = g_strdup(src_file->operation);
122 // TODO: g_list_copy_deep()
123 if (NULL != src_file->files)
125 cloud_file->files = g_list_copy(src_file->files);
129 cloud_file->files = NULL;
132 *dst_file = cloud_file;
134 return SERVICE_ADAPTOR_ERROR_NONE;
137 API int service_storage_cloud_file_destroy(service_storage_cloud_file_h file)
141 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
143 SAL_FREE(file->dir_path);
144 SAL_FREE(file->local_path);
145 SAL_FREE(file->cloud_path);
146 SAL_FREE(file->operation);
149 return SERVICE_ADAPTOR_ERROR_NONE;
152 API int service_storage_cloud_file_set_callback(service_storage_cloud_file_h file, service_storage_cloud_file_cb callback, void *user_data)
156 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
157 RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
159 file->callback = callback;
160 file->user_data = user_data;
162 return SERVICE_ADAPTOR_ERROR_NONE;
165 API int service_storage_cloud_file_unset_callback(service_storage_cloud_file_h file)
169 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
171 file->callback = NULL;
172 file->user_data = NULL;
174 return SERVICE_ADAPTOR_ERROR_NONE;
177 API int service_storage_cloud_file_set_cloud_path(service_storage_cloud_file_h file, const char *cloud_path)
181 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
182 RETV_IF(NULL == cloud_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
184 file->cloud_path = strdup(cloud_path);
186 return SERVICE_ADAPTOR_ERROR_NONE;
189 API int service_storage_cloud_file_get_cloud_path(service_storage_cloud_file_h file, char **cloud_path)
193 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
194 RETV_IF(NULL == cloud_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
196 *cloud_path = g_strdup(file->cloud_path);
198 return SERVICE_ADAPTOR_ERROR_NONE;
201 API int service_storage_cloud_file_set_local_path(service_storage_cloud_file_h file, const char *local_path)
205 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
206 RETV_IF(NULL == local_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
208 file->local_path = strdup(local_path);
210 return SERVICE_ADAPTOR_ERROR_NONE;
213 API int service_storage_cloud_file_get_local_path(service_storage_cloud_file_h file, char **local_path)
217 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
218 RETV_IF(NULL == local_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
220 *local_path = g_strdup(file->local_path);
222 return SERVICE_ADAPTOR_ERROR_NONE;
225 API int service_storage_cloud_file_set_size(service_storage_cloud_file_h file, unsigned long long size)
229 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
233 return SERVICE_ADAPTOR_ERROR_NONE;
236 API int service_storage_cloud_file_get_size(service_storage_cloud_file_h file, unsigned long long *size)
240 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
241 RETV_IF(NULL == size, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
245 return SERVICE_ADAPTOR_ERROR_NONE;
248 API int service_storage_cloud_file_set_operation(service_storage_cloud_file_h file, const char *operation)
252 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
253 RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
255 file->operation = strdup(operation);
257 return SERVICE_ADAPTOR_ERROR_NONE;
260 API int service_storage_cloud_file_get_operation(service_storage_cloud_file_h file, char **operation)
264 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
265 RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
267 *operation = g_strdup(file->operation);
269 return SERVICE_ADAPTOR_ERROR_NONE;
272 API int service_storage_cloud_file_is_directory(service_storage_cloud_file_h file, bool *is_dir)
276 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
277 RETV_IF(NULL == is_dir, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
279 *is_dir = file->is_dir;
281 return SERVICE_ADAPTOR_ERROR_NONE;
284 API int service_storage_cloud_file_foreach_file(service_storage_cloud_file_h file, service_storage_cloud_file_cb callback, void *user_data)
288 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
289 RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
291 RETV_IF(false == file->is_dir, SERVICE_ADAPTOR_ERROR_NO_DATA);
293 RETV_IF(0 == g_list_length(file->files), SERVICE_ADAPTOR_ERROR_NO_DATA);
295 for (GList *list = g_list_first(file->files); list != NULL; list = list->next)
297 service_storage_cloud_file_h file_data = (service_storage_cloud_file_h) list->data;
299 bool ret = callback(SERVICE_ADAPTOR_ERROR_NONE, file_data, user_data);
300 RETV_IF(false == ret, SERVICE_ADAPTOR_ERROR_NONE);
303 return SERVICE_ADAPTOR_ERROR_NONE;
306 API int service_storage_cloud_file_create_task(service_storage_cloud_file_h file, service_task_h *task)
310 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
311 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
313 service_task_h service_task = (service_task_h) g_malloc0(sizeof(service_task_s));
314 service_task->cloud_file = file;
316 *task = service_task;
318 return SERVICE_ADAPTOR_ERROR_NONE;
321 API int service_storage_cloud_file_destroy_task(service_task_h task)
325 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
329 return SERVICE_ADAPTOR_ERROR_NONE;
332 //******************************************************************************
333 //* 2.4 Public interface definition
334 //******************************************************************************
336 API int service_storage_get_file_list(service_plugin_h plugin,
337 const char *dir_path,
338 service_storage_file_list_cb callback,
341 RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
342 RETV_IF(NULL == dir_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
343 RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
345 return SERVICE_ADAPTOR_ERROR_NONE;
348 API int service_storage_remove(service_plugin_h plugin,
349 const char *remove_path,
350 service_storage_result_cb callback,
353 RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
354 RETV_IF(NULL == remove_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
355 RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
357 return SERVICE_ADAPTOR_ERROR_NONE;
360 API int service_storage_create_upload_task(service_plugin_h plugin,
361 const char *file_path,
362 const char *upload_path,
363 service_storage_task_h *task)
365 RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
366 RETV_IF(NULL == file_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
367 RETV_IF(NULL == upload_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
368 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
370 return SERVICE_ADAPTOR_ERROR_NONE;
373 API int service_storage_create_download_task(service_plugin_h plugin,
374 const char *storage_path,
375 const char *download_path,
376 service_storage_task_h *task)
378 RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
379 RETV_IF(NULL == storage_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
380 RETV_IF(NULL == download_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
381 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
383 return SERVICE_ADAPTOR_ERROR_NONE;
386 API int service_storage_create_download_thumbnail_task (service_plugin_h plugin,
387 const char *storage_path,
388 const char *download_path,
390 service_storage_task_h *task)
392 RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
393 RETV_IF(NULL == storage_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
394 RETV_IF(NULL == download_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
395 RETV_IF(0 < thumbnail_size, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
396 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
398 return SERVICE_ADAPTOR_ERROR_NONE;
401 API int service_storage_destroy_task(service_storage_task_h task)
403 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
405 return SERVICE_ADAPTOR_ERROR_NONE;
408 API int service_storage_start_task(service_storage_task_h task)
410 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
412 return SERVICE_ADAPTOR_ERROR_NONE;
415 API int service_storage_cancel_task(service_storage_task_h task)
417 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
419 return SERVICE_ADAPTOR_ERROR_NONE;
422 API int service_storage_set_task_progress_cb(service_storage_task_h task,
423 service_storage_task_progress_cb callback,
426 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
427 RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
429 return SERVICE_ADAPTOR_ERROR_NONE;
432 API int service_storage_unset_task_progress_cb(service_storage_task_h task)
434 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
436 return SERVICE_ADAPTOR_ERROR_NONE;
439 API int service_storage_set_task_state_changed_cb(service_storage_task_h task,
440 service_storage_task_state_cb callback,
443 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
444 RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
446 return SERVICE_ADAPTOR_ERROR_NONE;
449 API int service_storage_unset_task_state_changed_cb(service_storage_task_h task)
451 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
453 return SERVICE_ADAPTOR_ERROR_NONE;
456 API int service_storage_file_list_clone(service_storage_file_list_h src_list,
457 service_storage_file_list_h *dst_list)
459 RETV_IF(NULL == src_list, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
460 RETV_IF(NULL == dst_list, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
462 return SERVICE_ADAPTOR_ERROR_NONE;
465 API int service_storage_file_list_destroy(service_storage_file_list_h list)
467 RETV_IF(NULL == list, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
469 return SERVICE_ADAPTOR_ERROR_NONE;
472 API int service_storage_file_list_get_length(service_storage_file_list_h list,
475 RETV_IF(NULL == list, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
476 RETV_IF(NULL == length, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
478 return SERVICE_ADAPTOR_ERROR_NONE;
481 API int service_storage_file_list_foreach_file(service_storage_file_list_h list,
482 service_storage_file_cb callback,
485 RETV_IF(NULL == list, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
486 RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
488 return SERVICE_ADAPTOR_ERROR_NONE;
491 API int service_storage_file_clone(service_storage_file_h src_file,
492 service_storage_file_h *dst_file)
494 RETV_IF(NULL == src_file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
495 RETV_IF(NULL == dst_file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
497 return SERVICE_ADAPTOR_ERROR_NONE;
500 API int service_storage_file_destroy(service_storage_file_h file)
502 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
504 return SERVICE_ADAPTOR_ERROR_NONE;
507 API int service_storage_file_is_dir(service_storage_file_h file,
510 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
511 RETV_IF(NULL == is_dir, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
513 return SERVICE_ADAPTOR_ERROR_NONE;
516 API int service_storage_file_get_size(service_storage_file_h file,
517 unsigned long long *size)
519 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
520 RETV_IF(NULL == size, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
522 return SERVICE_ADAPTOR_ERROR_NONE;
525 API int service_storage_file_get_logical_path(service_storage_file_h file,
528 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
529 RETV_IF(NULL == path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
531 return SERVICE_ADAPTOR_ERROR_NONE;
534 API int service_storage_file_get_physical_path(service_storage_file_h file,
537 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
538 RETV_IF(NULL == path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
540 return SERVICE_ADAPTOR_ERROR_NONE;