4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include "email-ipc.h"
25 #include "email-ipc-build.h"
26 #include "email-ipc-api-info.h"
27 #include "email-ipc-param-list.h"
28 #include "email-ipc-socket.h"
29 #include "email-proxy-main.h"
30 #include "email-core-task-manager.h"
32 #include "email-debug-log.h"
33 #include "email-errors.h"
35 EXPORT_API emipc_param_list *emipc_get_api_parameters(HIPC_API api, EPARAMETER_DIRECTION direction)
37 EM_DEBUG_FUNC_BEGIN();
38 emipc_email_api_info *api_info = (emipc_email_api_info *)api;
40 return (emipc_param_list *)emipc_get_parameters_of_api_info(api_info, direction);
43 EXPORT_API HIPC_API emipc_create_email_api(long api_id)
45 EM_DEBUG_FUNC_BEGIN();
47 emipc_email_api_info *api_info = (emipc_email_api_info *)calloc(1, sizeof(emipc_email_api_info));
48 if(api_info == NULL) {
49 EM_DEBUG_EXCEPTION("Malloc failed");
53 api_info->api_id = api_id;
55 return (HIPC_API)api_info;
58 EXPORT_API void emipc_destroy_email_api(HIPC_API api)
60 EM_DEBUG_FUNC_BEGIN("API = %p", api);
61 emipc_email_api_info *api_info = (emipc_email_api_info *)api;
62 emipc_free_api_info(api_info);
63 EM_SAFE_FREE(api_info);
66 EXPORT_API long emipc_get_api_id(HIPC_API api)
68 EM_DEBUG_FUNC_BEGIN();
69 emipc_email_api_info *api_info = (emipc_email_api_info*)api;
70 return api_info->api_id;
73 EXPORT_API long emipc_get_app_id(HIPC_API api)
75 EM_DEBUG_FUNC_BEGIN();
76 emipc_email_api_info *api_info = (emipc_email_api_info *)api;
77 return api_info->app_id;
80 /* note: there incurs additional cost (malloc & memcpy). */
81 /* if data is a dynamic variable, please use emipc_dynamic_parameter instead */
82 EXPORT_API bool emipc_add_parameter(HIPC_API api, EPARAMETER_DIRECTION direction, void *data, int data_length)
84 EM_DEBUG_FUNC_BEGIN("data_length[%d]", data_length);
86 emipc_param_list *parameters = emipc_get_api_parameters(api, direction);
88 EM_DEBUG_EXCEPTION("emipc_get_api_parameters failed");
92 return emipc_add_param_to_param_list(parameters, data, data_length);
95 /* caution : data should be a dynamic variable */
96 /* please, do not use a static variable */
97 EXPORT_API bool emipc_add_dynamic_parameter(HIPC_API api, EPARAMETER_DIRECTION direction, void *data, int data_length)
99 EM_DEBUG_FUNC_BEGIN("data_length[%d]", data_length);
101 emipc_param_list *parameters = emipc_get_api_parameters(api, direction);
103 EM_DEBUG_EXCEPTION("emipc_get_api_parameters failed");
107 emipc_add_dynamic_param_to_param_list(parameters, data, data_length);
113 EXPORT_API int emipc_get_parameter(HIPC_API input_api_handle, EPARAMETER_DIRECTION input_parameter_direction,
114 int input_parameter_index, int input_parameter_buffer_size, void *output_parameter_buffer)
116 EM_DEBUG_FUNC_BEGIN("parameter_index [%d], parameter_buffer_size [%d]", input_parameter_index, input_parameter_buffer_size);
117 emipc_param_list *parameters = NULL;
118 void *local_buffer = NULL;
120 if (input_parameter_buffer_size == 0 || output_parameter_buffer == NULL) {
121 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
122 return EMAIL_ERROR_INVALID_PARAM;
125 parameters = emipc_get_api_parameters(input_api_handle, input_parameter_direction);
127 if (parameters == NULL) {
128 EM_DEBUG_EXCEPTION("EMAIL_ERROR_IPC_PROTOCOL_FAILURE");
129 return EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
132 local_buffer = emipc_get_param_of_param_list(parameters, input_parameter_index);
134 if (local_buffer == NULL) {
135 EM_DEBUG_EXCEPTION("EMAIL_ERROR_IPC_PROTOCOL_FAILURE");
136 return EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
139 if (emipc_get_param_len_of_param_list(parameters, input_parameter_index) != input_parameter_buffer_size) {
140 EM_DEBUG_EXCEPTION("EMAIL_ERROR_IPC_PROTOCOL_FAILURE");
141 return EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
144 memcpy(output_parameter_buffer, local_buffer, input_parameter_buffer_size);
147 return EMAIL_ERROR_NONE;
151 EXPORT_API void* emipc_get_nth_parameter_data(HIPC_API api_handle, EPARAMETER_DIRECTION direction, int param_index)
153 EM_DEBUG_FUNC_BEGIN("nth_parameter_index [%d]", param_index);
154 emipc_param_list *parameters = NULL;
157 parameters = emipc_get_api_parameters(api_handle, direction);
159 if (parameters == NULL) {
160 EM_DEBUG_EXCEPTION("EMAIL_ERROR_IPC_PROTOCOL_FAILURE");
164 buf = emipc_get_param_of_param_list(parameters, param_index);
167 EM_DEBUG_EXCEPTION("EMAIL_ERROR_IPC_PROTOCOL_FAILURE");
176 EXPORT_API int emipc_get_parameter_length(HIPC_API api, EPARAMETER_DIRECTION direction, int parameter_index)
178 EM_DEBUG_FUNC_BEGIN();
179 emipc_param_list *parameters = emipc_get_api_parameters(api, direction);
181 EM_DEBUG_FUNC_END("Suceeded");
182 return emipc_get_param_len_of_param_list(parameters, parameter_index);
184 EM_DEBUG_FUNC_END("Failed");
188 EXPORT_API int emipc_get_nth_parameter_length(HIPC_API api, EPARAMETER_DIRECTION direction, int parameter_index)
190 EM_DEBUG_FUNC_BEGIN();
191 emipc_param_list *parameters = emipc_get_api_parameters(api, direction);
193 EM_DEBUG_FUNC_END("Suceeded");
194 return emipc_get_param_len_of_param_list(parameters, parameter_index);
196 EM_DEBUG_FUNC_END("Failed");
200 EXPORT_API int emipc_execute_proxy_task(email_task_type_t input_task_type, void *input_task_parameter)
202 EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_parameter [%p]", input_task_type, input_task_parameter);
204 int err = EMAIL_ERROR_NONE;
205 int task_parameter_length = 0;
206 char *task_parameter_stream = NULL;
207 HIPC_API hAPI = NULL;
209 if(input_task_parameter == NULL) {
210 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
211 err = EMAIL_ERROR_INVALID_PARAM;
215 if((err = emcore_encode_task_parameter(input_task_type, input_task_parameter, &task_parameter_stream, &task_parameter_length)) != EMAIL_ERROR_NONE) {
216 EM_DEBUG_EXCEPTION("emcore_encode_task_parameter failed [%d]", err);
220 hAPI = emipc_create_email_api(input_task_type);
223 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
224 err = EMAIL_ERROR_NULL_VALUE;
228 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)task_parameter_stream, task_parameter_length)) {
229 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
230 err = EMAIL_ERROR_OUT_OF_MEMORY;
234 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
235 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
236 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
240 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
244 emipc_destroy_email_api(hAPI);
246 EM_DEBUG_FUNC_END("err [%d]", err);