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.
27 #include "email-ipc.h"
28 #include "email-ipc-build.h"
29 #include "email-proxy-main.h"
30 #include "email-proxy-socket.h"
31 #include "email-proxy-callback-info.h"
33 #include "email-debug-log.h"
36 EXPORT_API int emipc_initialize_proxy_main()
38 EM_DEBUG_FUNC_BEGIN();
41 sock_fd = emipc_get_proxy_socket_id();
44 EM_DEBUG_LOG("Socket already initialized");
45 return EMAIL_ERROR_IPC_ALREADY_INITIALIZED;
48 if (!emipc_start_proxy_socket()) {
49 EM_DEBUG_EXCEPTION("Socket start failed");
50 return EMAIL_ERROR_IPC_CONNECTION_FAILURE;
53 EM_DEBUG_LOG("Socket ID : %d", emipc_get_proxy_socket_id());
55 return EMAIL_ERROR_NONE;
58 EXPORT_API int emipc_finalize_proxy_main()
60 EM_DEBUG_FUNC_BEGIN();
61 if (!emipc_end_proxy_socket()) {
62 EM_DEBUG_EXCEPTION("emipc_finalize_proxy_main failed");
63 return EMAIL_ERROR_IPC_SOCKET_FAILURE;
67 return EMAIL_ERROR_NONE;
70 EXPORT_API bool emipc_execute_api_of_proxy_main(emipc_email_api_info *api_info)
72 EM_DEBUG_FUNC_BEGIN();
75 unsigned char *in_stream = NULL;
81 EM_DEBUG_EXCEPTION("Invalid Parameter");
85 in_stream = emipc_serialize_api_info(api_info, ePARAMETER_IN, &length);
87 EM_DEBUG_EXCEPTION("NULL stream");
91 sending_bytes = emipc_send_proxy_socket(in_stream, length);
93 EM_DEBUG_LOG("Proxy=>stub sending %d byte.", sending_bytes);
95 if (sending_bytes > 0) {
96 #ifdef IPCLIB_STREAM_TRACE_ON
98 for (index=0;index<length;index++)
99 EM_DEBUG_LOG("in_stream[index] : [%x]", in_stream[index]);
101 char *ipc_buf = NULL;
103 ret = emipc_recv_proxy_socket(&ipc_buf);
105 EM_DEBUG_LOG("Recv length : %d", ret);
108 result = emipc_deserialize_api_info(api_info, ePARAMETER_OUT, ipc_buf);
112 EM_SAFE_FREE(ipc_buf);