Tizen 2.0 Release
[platform/core/messaging/email-service.git] / email-api / email-api-init.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2012 - 2013 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
23
24 /**
25  *
26  * This file contains the data structures and interfaces needed for application,
27  * to interact with email-service.
28  * @file                email-api-init.c
29  * @brief               This file contains the data structures and interfaces of Email FW intialization related Functionality provided by 
30  *                      email-service . 
31  */
32  
33 #include "email-api.h"
34 #include "string.h"
35 #include "email-convert.h"
36 #include "email-storage.h"
37 #include "email-ipc.h"
38 #include "email-core-task-manager.h"
39 #include <sqlite3.h>
40
41
42 EXPORT_API int email_open_db(void)
43 {
44         EM_DEBUG_FUNC_BEGIN();
45         int error  = EMAIL_ERROR_NONE;
46         
47         if (emstorage_db_open(&error) == NULL)
48                 EM_DEBUG_EXCEPTION("emstorage_db_open failed [%d]", error);
49
50         
51         EM_DEBUG_FUNC_END("error [%d]", error);
52
53         return error;   
54 }
55
56 EXPORT_API int email_close_db(void)
57 {
58         EM_DEBUG_FUNC_BEGIN();
59         int error  = EMAIL_ERROR_NONE;
60
61         if ( !emstorage_db_close(&error)) 
62                 EM_DEBUG_EXCEPTION("emstorage_db_close failed [%d]", error);
63
64         EM_DEBUG_FUNC_END("error [%d]", error);
65         return error;   
66 }
67
68
69 EXPORT_API int email_service_begin(void)
70 {
71         EM_DEBUG_FUNC_BEGIN();
72         int ret = -1;
73
74         signal(SIGPIPE, SIG_IGN); /* to ignore signal 13(SIGPIPE) */
75         
76         ret = emipc_initialize_proxy();
77
78         emcore_init_task_handler_array();
79
80         EM_DEBUG_FUNC_END("err[%d]", ret);
81         return ret;
82 }
83
84
85 EXPORT_API int email_service_end(void)
86 {
87         EM_DEBUG_FUNC_BEGIN();
88         int ret = -1;
89         
90         ret = emipc_finalize_proxy();
91         if (ret != EMAIL_ERROR_NONE)
92                 EM_DEBUG_FUNC_END("err[%d]", ret);
93         
94         return ret;
95 }
96
97 /* API - Exposed to External Application- core team.Creates all Email DB tables [ EXTERNAL] */
98
99
100 EXPORT_API int email_init_storage(void)
101 {
102         EM_DEBUG_FUNC_BEGIN();
103         int error  = EMAIL_ERROR_NONE;
104         
105         if (!emstorage_create_table(EMAIL_CREATE_DB_CHECK, &error))  {
106                 EM_DEBUG_EXCEPTION("emstorage_create_table failed [%d]", error);
107         }
108
109         EM_DEBUG_FUNC_END("error[%d]", error);
110         return error;
111 }
112
113 EXPORT_API int email_ping_service(void)
114 {
115         EM_DEBUG_FUNC_BEGIN();
116         int error  = EMAIL_ERROR_NONE;
117         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_PING_SERVICE);
118
119         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
120                 
121         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
122                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
123                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
124         }
125
126         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &error);
127         
128         emipc_destroy_email_api(hAPI);
129
130         hAPI = NULL;
131
132         EM_DEBUG_FUNC_END("err[%d]", error);
133         return error;
134 }