2.0_alpha release commit
[framework/messaging/email-service.git] / email-ipc / email-ipc-api.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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.
19 *
20 */
21
22 #include <malloc.h>
23
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
31 #include "email-debug-log.h"
32 #include "email-errors.h"
33
34 EXPORT_API emipc_param_list *emipc_get_api_parameters(HIPC_API api, EPARAMETER_DIRECTION direction)
35 {
36         EM_DEBUG_FUNC_BEGIN();
37         emipc_email_api_info *api_info = (emipc_email_api_info *)api;
38
39         return (emipc_param_list *)emipc_get_parameters_of_api_info(api_info, direction);
40 }
41
42 EXPORT_API HIPC_API emipc_create_email_api(long api_id)
43 {
44         EM_DEBUG_FUNC_BEGIN();
45
46         emipc_email_api_info *api_info = (emipc_email_api_info *)calloc(1, sizeof(emipc_email_api_info));
47         if(api_info == NULL) {
48                 EM_DEBUG_EXCEPTION("Malloc failed");
49                 return NULL;
50         }
51
52         api_info->api_id = api_id;
53
54         return (HIPC_API)api_info;
55 }
56
57 EXPORT_API void emipc_destroy_email_api(HIPC_API api)
58 {
59         EM_DEBUG_FUNC_BEGIN("API = %p", api);
60         emipc_email_api_info *api_info = (emipc_email_api_info *)api;
61         emipc_free_api_info(api_info);
62         EM_SAFE_FREE(api_info);
63 }
64
65 EXPORT_API long emipc_get_api_id(HIPC_API api)
66 {
67         EM_DEBUG_FUNC_BEGIN();
68         emipc_email_api_info *api_info = (emipc_email_api_info*)api;
69         return api_info->api_id;
70 }
71
72 EXPORT_API long emipc_get_app_id(HIPC_API api)
73 {
74         EM_DEBUG_FUNC_BEGIN();
75         emipc_email_api_info *api_info = (emipc_email_api_info *)api;
76         return api_info->app_id;
77 }
78
79 /* note: there incurs additional cost (malloc & memcpy). */
80 /* if data is a dynamic variable, please use emipc_dynamic_parameter instead */
81 EXPORT_API bool emipc_add_parameter(HIPC_API api, EPARAMETER_DIRECTION direction, void *data, int data_length)
82 {
83         EM_DEBUG_FUNC_BEGIN("data_length[%d]", data_length);
84
85         emipc_param_list *parameters = emipc_get_api_parameters(api, direction);
86         if (!parameters) {
87                 EM_DEBUG_EXCEPTION("emipc_get_api_parameters failed");
88                 return false;
89 }
90
91         return emipc_add_param_to_param_list(parameters, data, data_length);
92 }
93
94 /* caution : data should be a dynamic variable */
95 /*           please, do not use a static variable */
96 EXPORT_API bool emipc_add_dynamic_parameter(HIPC_API api, EPARAMETER_DIRECTION direction, void *data, int data_length)
97 {
98         EM_DEBUG_FUNC_BEGIN("data_length[%d]", data_length);
99         
100         emipc_param_list *parameters = emipc_get_api_parameters(api, direction);
101         if (!parameters) {
102                 EM_DEBUG_EXCEPTION("emipc_get_api_parameters failed");
103                 return false;
104         }
105
106         emipc_add_dynamic_param_to_param_list(parameters, data, data_length);
107         return true;
108 }
109
110
111
112 EXPORT_API int emipc_get_parameter(HIPC_API input_api_handle, EPARAMETER_DIRECTION input_parameter_direction,
113                         int input_parameter_index, int input_parameter_buffer_size, void *output_parameter_buffer)
114 {
115         EM_DEBUG_FUNC_BEGIN("parameter_index [%d], parameter_buffer_size [%d]", input_parameter_index, input_parameter_buffer_size);
116         emipc_param_list *parameters = NULL;
117         void *local_buffer = NULL;
118
119         if (input_parameter_buffer_size == 0 || output_parameter_buffer == NULL) {
120                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
121                 return EMAIL_ERROR_INVALID_PARAM;
122         }
123
124         parameters = emipc_get_api_parameters(input_api_handle, input_parameter_direction);
125
126         if (parameters == NULL) {
127                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_IPC_PROTOCOL_FAILURE");
128                 return EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
129         }
130
131         local_buffer = emipc_get_param_of_param_list(parameters, input_parameter_index);
132
133         if (local_buffer == NULL) {
134                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_IPC_PROTOCOL_FAILURE");
135                 return EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
136         }
137
138         if (emipc_get_param_len_of_param_list(parameters, input_parameter_index) != input_parameter_buffer_size) {
139                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_IPC_PROTOCOL_FAILURE");
140                 return EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
141         }
142
143         memcpy(output_parameter_buffer, local_buffer, input_parameter_buffer_size);
144
145         EM_DEBUG_FUNC_END();
146         return EMAIL_ERROR_NONE;
147 }
148
149
150 EXPORT_API void* emipc_get_nth_parameter_data(HIPC_API api_handle, EPARAMETER_DIRECTION direction, int param_index)
151 {
152         EM_DEBUG_FUNC_BEGIN("nth_parameter_index [%d]", param_index);
153         emipc_param_list *parameters = NULL;
154         void *buf = NULL;
155
156         parameters = emipc_get_api_parameters(api_handle, direction);
157
158         if (parameters == NULL) {
159                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_IPC_PROTOCOL_FAILURE");
160                 return NULL;
161         }
162
163         buf = emipc_get_param_of_param_list(parameters, param_index);
164
165         if (!buf) {
166                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_IPC_PROTOCOL_FAILURE");
167                 return NULL;
168         }
169
170         EM_DEBUG_FUNC_END();
171         return buf;
172 }
173
174
175 EXPORT_API int emipc_get_parameter_length(HIPC_API api, EPARAMETER_DIRECTION direction, int parameter_index)
176 {
177         EM_DEBUG_FUNC_BEGIN();
178         emipc_param_list *parameters = emipc_get_api_parameters(api, direction);
179         if (parameters) {
180                 EM_DEBUG_FUNC_END("Suceeded");
181                 return emipc_get_param_len_of_param_list(parameters, parameter_index);
182         }
183         EM_DEBUG_FUNC_END("Failed");
184         return -1;
185 }
186
187 EXPORT_API int emipc_get_nth_parameter_length(HIPC_API api, EPARAMETER_DIRECTION direction, int parameter_index)
188 {
189         EM_DEBUG_FUNC_BEGIN();
190         emipc_param_list *parameters = emipc_get_api_parameters(api, direction);
191         if (parameters) {
192                 EM_DEBUG_FUNC_END("Suceeded");
193                 return emipc_get_param_len_of_param_list(parameters, parameter_index);
194         }
195         EM_DEBUG_FUNC_END("Failed");
196         return -1;
197 }
198
199
200