2 * Service Adaptor IPC Server
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.
24 #include "service_adaptor_errors.h"
25 #include "service_adaptor_internal.h"
27 #include "sal_ipc_server.h"
28 #include "sal_ipc_server_storage.h"
29 #include "storage_adaptor.h"
30 #include "sal_service_storage.h"
31 #include "sal_service_storage_internal.h"
33 //******************************************************************************
34 //* Global variables and defines
35 //******************************************************************************
37 //******************************************************************************
39 //******************************************************************************
41 //******************************************************************************
42 //* Private interface definition
43 //******************************************************************************
45 void _cloud_remove_file_cb(int result, cloud_file_h file, void *user_data)
49 ipc_reply_data_h reply = (ipc_reply_data_h) user_data;
51 int ipc_ret = SERVICE_ADAPTOR_ERROR_NONE;
53 GVariant *ipc_data = NULL;
55 GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE(file_list_type));
57 ipc_create_error_msg(ipc_ret, &ipc_msg);
58 ipc_data = g_variant_new(ipc_make_return_type(reply->type), file->is_dir, SAL_IPC_STR(file->dir_path), SAL_IPC_STR(file->local_path), SAL_IPC_STR(file->cloud_path), file->size, SAL_IPC_STR(file->operation), builder, ipc_ret, SAL_IPC_STR(ipc_msg));
59 g_dbus_method_invocation_return_value(reply->invocation, ipc_data);
62 ipc_free_reply_data(reply);
63 g_variant_builder_unref(builder);
68 int _get_cloud_file(GVariant *reply_info, service_storage_cloud_file_h *file)
72 service_storage_cloud_file_h cloud_file = (service_storage_cloud_file_h) g_malloc0(sizeof(service_storage_cloud_file_s));
74 int info_size = service_storage_cloud_file_s_type_length;
75 GVariant *info[info_size];
76 ipc_create_variant_info(reply_info, info_size, (GVariant ***) &info);
79 cloud_file->is_dir = g_variant_get_boolean(info[idx++]);
80 cloud_file->dir_path = ipc_insure_g_variant_dup_string(info[idx++]);
81 cloud_file->local_path = ipc_insure_g_variant_dup_string(info[idx++]);
82 cloud_file->cloud_path = ipc_insure_g_variant_dup_string(info[idx++]);
83 cloud_file->size = g_variant_get_uint64(info[idx++]);
84 cloud_file->operation = ipc_insure_g_variant_dup_string(info[idx++]);
86 ipc_destroy_variant_info(info, info_size);
90 return SERVICE_ADAPTOR_ERROR_NONE;
93 int _cloud_execute_operation(storage_plugin_h plugin, service_storage_cloud_file_h file, ipc_reply_data_h reply)
97 RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
98 RETV_IF(NULL == plugin->cloud, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
99 RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
101 int ret = SERVICE_ADAPTOR_ERROR_NONE;
103 if (0 == strcmp(file->operation, SERVICE_STORAGE_CLOUD_REMOVE_FILE_URI))
105 ret = plugin->cloud->cloud_remove_file(plugin, file->cloud_path, _cloud_remove_file_cb, reply);
109 else if (0 == strcmp(file->operation, SERVICE_STORAGE_CLOUD_DOWNLOAD_FILE_URI))
113 else if (0 == strcmp(file->operation, SERVICE_STORAGE_CLOUD_UPLOAD_FILE_URI))
117 else if (0 == strcmp(file->operation, SERVICE_STORAGE_CLOUD_DOWNLOAD_FILE_THUMBNAIL_URI))
121 else if (0 == strcmp(file->operation, SERVICE_STORAGE_CLOUD_GET_FILE_LIST_URI))
126 return SERVICE_ADAPTOR_ERROR_INTERNAL;
129 //******************************************************************************
130 //* Public interface definition
131 //******************************************************************************
133 API void service_storage_method_call(GDBusConnection *connection,
135 const gchar *object_path,
136 const gchar *interface_name,
137 const gchar *method_name,
138 GVariant *parameters,
139 GDBusMethodInvocation *invocation,
144 int ipc_ret = SERVICE_ADAPTOR_ERROR_NONE;
145 char *ipc_msg = NULL;
146 char *ipc_type = NULL;
147 GVariant *ipc_data = NULL;
151 GVariant *in_parameters = g_variant_get_child_value(parameters, 0);
153 if (0 == g_strcmp0(method_name, DBUS_SERVICE_STORAGE_CLOUD_FILE_METHOD))
156 int size = service_storage_cloud_file_req_s_type_length;
157 GVariant *req_info[size];
159 ipc_create_variant_info(in_parameters, size, (GVariant ***) &req_info);
161 char *uri = ipc_insure_g_variant_dup_string(req_info[idx++]);
162 service_storage_cloud_file_h file = NULL;
163 _get_cloud_file(req_info[idx++], &file);
165 SAL_INFO("uri: %s", uri);
167 ipc_ret = SERVICE_ADAPTOR_ERROR_INTERNAL;
168 ipc_type = strdup(service_storage_cloud_file_res_s_type);
170 sal_h sal = sal_get_handle();
171 TRYVM_IF(NULL == sal, ipc_ret = SERVICE_ADAPTOR_ERROR_INTERNAL, "sal_get_handle() Failed");
173 storage_plugin_h plugin = storage_adaptor_get_plugin(sal->storage, uri);
175 ipc_reply_data_h reply = (ipc_reply_data_h) g_malloc0(sizeof(ipc_reply_data_s));
176 reply->invocation = invocation;
177 reply->type = strdup(ipc_type);
179 ipc_ret = _cloud_execute_operation(plugin, file, reply);
180 TRY_IF(SERVICE_ADAPTOR_ERROR_NONE == ipc_ret, "cloud_execute_operation() Request Successed");
182 GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE(file_list_type));
183 ipc_create_error_msg(ipc_ret, &ipc_msg);
184 ipc_data = g_variant_new(ipc_make_return_type(ipc_type), false, "", "", 0, 0, builder, ipc_ret, SAL_IPC_STR(ipc_msg));
186 g_variant_builder_unref(builder);
187 ipc_destroy_variant_info(req_info, size);
190 g_dbus_method_invocation_return_value(invocation, ipc_data);