2.0_alpha release commit
[framework/messaging/email-service.git] / email-ipc / email-ipc-proxy.c
index 2aa6833..2d61de1 100755 (executable)
@@ -1,81 +1,96 @@
-/* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved \r
- *\r
- * PROPRIETARY/CONFIDENTIAL\r
- *\r
- * This software is the confidential and proprietary information of SAMSUNG \r
- * ELECTRONICS ("Confidential Information"). You agree and acknowledge that \r
- * this software is owned by Samsung and you shall not disclose such \r
- * Confidential Information and shall use it only in accordance with the terms\r
- * of the license agreement you entered into with SAMSUNG ELECTRONICS. \r
- * SAMSUNG make no representations or warranties about the suitability of the \r
- * software, either express or implied, including but not limited to the \r
- * implied warranties of merchantability, fitness for a particular purpose, \r
- * or non-infringement. SAMSUNG shall not be liable for any damages suffered \r
- * by licensee arising out of or releated to this software.\r
- * \r
- */\r
-\r
-#include "email-ipc-build.h"\r
-#include "email-ipc.h"\r
-#include "email-ipc-api-info.h"\r
-#include "email-ipc-param-list.h"\r
-#include "email-ipc-socket.h"\r
-#include "email-proxy-main.h"\r
-\r
-#include "email-debug-log.h"\r
-#include "email-api.h"\r
-#include "email-types.h"\r
-\r
-EXPORT_API int emipc_initialize_proxy()\r
-{\r
-       EM_DEBUG_FUNC_BEGIN();\r
-\r
-       int err = emipc_initialize_proxy_main();\r
-\r
-       EM_DEBUG_FUNC_END();\r
-       return err;\r
-}\r
-\r
-EXPORT_API int emipc_finalize_proxy()\r
-{\r
-       EM_DEBUG_FUNC_BEGIN();\r
-       return emipc_finalize_proxy_main();\r
-}\r
-\r
-EXPORT_API bool emipc_execute_proxy_api(HIPC_API api)\r
-{\r
-       EM_DEBUG_FUNC_BEGIN();\r
-       int ret;\r
-       int err = EMF_ERROR_NONE;\r
-       emipc_email_api_info *api_info = (emipc_email_api_info *)api;\r
-\r
-       EM_DEBUG_LOG("API [%p]", api_info);\r
-               \r
-       if(api_info == NULL) {\r
-               EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");\r
-               return EMF_ERROR_INVALID_PARAM;\r
-       }\r
-               \r
-       EM_DEBUG_LOG("APIID [%s], ResponseID [%d], APPID[%d]", EM_APIID_TO_STR(emipc_get_api_id_of_api_info(api_info)), emipc_get_response_id_of_api_info(api_info), emipc_get_app_id_of_api_info(api_info));\r
-\r
-       ret = emipc_execute_api_of_proxy_main(api_info);\r
-\r
-       /* connection retry */\r
-       if (!ret) {\r
-               emipc_finalize_proxy();\r
-\r
-               err = emipc_initialize_proxy();\r
-               if (err != EMF_ERROR_NONE) {\r
-                       EM_DEBUG_EXCEPTION("Failed to open the socket : [%d]", err);\r
-                       return EMF_ERROR_CONNECTION_FAILURE;\r
-               }\r
-\r
-               ret = emipc_execute_api_of_proxy_main(api_info);\r
-               if (!ret) {\r
-                       EM_DEBUG_EXCEPTION("emipc_proxy_main : emipc_execute_api failed [%d]", err);\r
-                       return EMF_ERROR_CONNECTION_FAILURE;\r
-               }\r
-       }\r
-       EM_DEBUG_FUNC_END("err [%d]", err);\r
-       return err;     \r
-}\r
+/*
+*  email-service
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+#include "email-ipc-build.h"
+#include "email-ipc.h"
+#include "email-ipc-api-info.h"
+#include "email-ipc-param-list.h"
+#include "email-ipc-socket.h"
+#include "email-proxy-main.h"
+
+#include "email-debug-log.h"
+#include "email-api.h"
+#include "email-types.h"
+#include "email-internal-types.h"
+
+pthread_mutex_t proxy_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+EXPORT_API int emipc_initialize_proxy()
+{
+       EM_DEBUG_FUNC_BEGIN();
+
+       int err = emipc_initialize_proxy_main();
+
+       EM_DEBUG_FUNC_END();
+       return err;
+}
+
+EXPORT_API int emipc_finalize_proxy()
+{
+       EM_DEBUG_FUNC_BEGIN();
+       return emipc_finalize_proxy_main();
+}
+
+EXPORT_API int emipc_execute_proxy_api(HIPC_API api)
+{
+       EM_DEBUG_FUNC_BEGIN();
+       int ret;
+       int err = EMAIL_ERROR_NONE;
+       emipc_email_api_info *api_info = (emipc_email_api_info *)api;
+
+       EM_DEBUG_LOG("API [%p]", api_info);
+               
+       if(api_info == NULL) {
+               EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+               return EMAIL_ERROR_INVALID_PARAM;
+       }
+               
+       EM_DEBUG_LOG("APIID [%s], ResponseID [%d], APPID[%d]",
+                               EM_APIID_TO_STR(api_info->api_id), api_info->response_id, api_info->app_id);
+
+       ENTER_CRITICAL_SECTION(proxy_mutex);
+       ret = emipc_execute_api_of_proxy_main(api_info);
+
+       /* connection retry */
+       if (!ret) {
+               EM_DEBUG_LOG("Connection retry");
+               emipc_finalize_proxy();
+
+               err = emipc_initialize_proxy();
+               if (err != EMAIL_ERROR_NONE) {
+                       EM_DEBUG_EXCEPTION("Failed to open the socket : [%d]", err);
+                       err = EMAIL_ERROR_CONNECTION_FAILURE;
+                       goto FINISH_OFF;
+               }
+
+               ret = emipc_execute_api_of_proxy_main(api_info);
+               if (!ret) {
+                       EM_DEBUG_EXCEPTION("emipc_proxy_main : emipc_execute_api failed [%d]", err);
+                       err = EMAIL_ERROR_CONNECTION_FAILURE;
+                       goto FINISH_OFF;
+               }
+       }
+       
+FINISH_OFF:
+       LEAVE_CRITICAL_SECTION(proxy_mutex);
+       EM_DEBUG_FUNC_END("err [%d]", err);
+       return err;     
+}