Add 3.0 APIs and sync APIs same as 2.4
[platform/core/convergence/service-adaptor.git] / client / sal_storage_provider.c
1 /*
2  * Storage Plugin Client
3  *
4  * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <glib.h>
23
24 #include <app.h>
25
26 #include "service_adaptor_errors.h"
27 #include "service_adaptor_internal.h"
28 #include "cloud_service.h"
29 #include "sal_service_provider.h"
30 #include "sal_storage_provider.h"
31
32 API int storage_provider_create(storage_provider_h *provider)
33 {
34         SAL_FN_CALL;
35
36         storage_provider_h storage_provider = (storage_provider_h) g_malloc0(sizeof(storage_provider_s));
37
38         storage_provider->cloud_remove_file = NULL;
39
40         *provider = storage_provider;
41
42         return SERVICE_ADAPTOR_ERROR_NONE;
43 }
44
45 API app_control_h storage_provider_message(storage_provider_h provider, const char *operation, void *user_data)
46 {
47         SAL_FN_CALL;
48
49         app_control_h reply = NULL;
50
51         RETV_IF(NULL == provider, reply);
52
53         int ret = SERVICE_ADAPTOR_ERROR_NONE;
54
55         if (0 == strcmp(operation, CLOUD_REMOVE_FILE_URI))
56         {
57                 app_control_create(&reply);
58
59                 char *cloud_path = NULL;
60                 app_control_get_extra_data((app_control_h) user_data, CLOUD_CLOUD_PATH_KEY, &cloud_path);
61
62                 ret = provider->cloud_remove_file(cloud_path);
63
64                 if (SERVICE_ADAPTOR_ERROR_NONE != ret)
65                 {
66                         SAL_ERR("cloud_remove_file() Fail (%d)", ret);
67                         app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_FAILURE);
68                         return reply;
69                 }
70
71                 app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_SUCCESS);
72         }
73
74         return reply;
75 }
76
77 API int storage_provider_add_extra_data(storage_provider_h provider, app_control_h reply)
78 {
79         SAL_FN_CALL;
80
81         RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
82         RETV_IF(NULL == reply, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
83
84         app_control_add_extra_data(reply, PLUGIN_KEY_STORAGE, PLUGIN_VALUE_TRUE);
85
86         if (NULL != provider->cloud_remove_file)
87         {
88                 app_control_add_extra_data(reply, CLOUD_REMOVE_FILE_URI, PLUGIN_VALUE_TRUE);
89         }
90
91         return SERVICE_ADAPTOR_ERROR_NONE;
92 }