2.0_alpha release commit
[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  = EMAIL_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  = EMAIL_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
77         EM_DEBUG_FUNC_END("err[%d]", ret);
78         return ret;
79 }
80
81
82 EXPORT_API int email_service_end(void)
83 {
84         EM_DEBUG_FUNC_BEGIN();
85         int ret = -1;
86         
87         ret = emipc_finalize_proxy();
88         if (ret != EMAIL_ERROR_NONE)
89                 EM_DEBUG_FUNC_END("err[%d]", ret);
90         
91         return ret;
92 }
93
94 /* API - Exposed to External Application- core team.Creates all Email DB tables [ EXTERNAL] */
95
96
97 EXPORT_API int email_init_storage(void)
98 {
99         EM_DEBUG_FUNC_BEGIN();
100         int error  = EMAIL_ERROR_NONE;
101         
102         if (!emstorage_create_table(EMAIL_CREATE_DB_CHECK, &error))  {
103                 EM_DEBUG_EXCEPTION("emstorage_create_table failed [%d]", error);
104         }
105
106         EM_DEBUG_FUNC_END("error[%d]", error);
107         return error;
108 }
109
110 EXPORT_API int email_ping_service(void)
111 {
112         EM_DEBUG_FUNC_BEGIN();
113         int error  = EMAIL_ERROR_NONE;
114         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_PING_SERVICE);
115
116         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
117                 
118         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
119                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
120                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
121         }
122
123         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &error);
124         
125         emipc_destroy_email_api(hAPI);
126
127         hAPI = NULL;
128
129         EM_DEBUG_FUNC_END("err[%d]", error);
130         return error;
131 }