upload tizen1.0 source
[framework/messaging/email-service.git] / email-api / email-api-init.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
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 <sqlite3.h>
39
40
41 EXPORT_API int email_open_db(void)
42 {
43         EM_DEBUG_FUNC_BEGIN();
44         int error  = EMF_ERROR_NONE;
45         
46         if (emstorage_db_open(&error) == NULL)
47                 EM_DEBUG_EXCEPTION("emstorage_db_open failed [%d]", error);
48
49         
50         EM_DEBUG_FUNC_END("error [%d]", error);
51
52         return error;   
53 }
54
55 EXPORT_API int email_close_db(void)
56 {
57         EM_DEBUG_FUNC_BEGIN();
58         int error  = EMF_ERROR_NONE;
59
60         if ( !emstorage_db_close(&error)) 
61                 EM_DEBUG_EXCEPTION("emstorage_db_close failed [%d]", error);
62
63         EM_DEBUG_FUNC_END("error [%d]", error);
64         return error;   
65 }
66
67
68 EXPORT_API int email_service_begin(void)
69 {
70         EM_DEBUG_FUNC_BEGIN();
71         int ret = -1;
72
73         signal(SIGPIPE, SIG_IGN); /*  to ignore signal 13(SIGPIPE) */
74         
75         ret = emipc_initialize_proxy();
76         if (ret != EMF_ERROR_NONE)
77                 EM_DEBUG_FUNC_END("err[%d]", ret);
78         
79         return ret;
80 }
81
82
83 EXPORT_API int email_service_end(void)
84 {
85         EM_DEBUG_FUNC_BEGIN();
86         int ret = -1;
87         
88         ret = emipc_finalize_proxy();
89         if (ret != EMF_ERROR_NONE)
90                 EM_DEBUG_FUNC_END("err[%d]", ret);
91         
92         return ret;
93 }
94
95 /* API - Exposed to External Application- core team.Creates all Email DB tables [ EXTERNAL] */
96
97
98 EXPORT_API int email_init_storage(void)
99 {
100         EM_DEBUG_FUNC_BEGIN();
101         int error  = EMF_ERROR_NONE;
102         
103         if (!emstorage_create_table(EMF_CREATE_DB_CHECK, &error))  {
104                 EM_DEBUG_EXCEPTION("emstorage_create_table failed [%d]", error);
105         }
106
107         EM_DEBUG_FUNC_END("error[%d]", error);
108         return error;
109 }
110
111 EXPORT_API int email_ping_service(void)
112 {
113         EM_DEBUG_FUNC_BEGIN();
114         int error  = EMF_ERROR_NONE;
115         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_PING_SERVICE);
116
117         EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
118                 
119         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
120                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
121                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
122         }
123
124         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &error);
125         
126         emipc_destroy_email_api(hAPI);
127
128         hAPI = NULL;
129
130         EM_DEBUG_FUNC_END("err[%d]", error);
131         return error;
132 }