Tizen 2.0 Release
[platform/core/messaging/email-service.git] / email-ipc / email-ipc-api / email-ipc-api-info.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 #include <string.h>
24 #include <unistd.h>
25 #include <malloc.h>
26
27 #include "email-ipc-api-info.h"
28 #include "email-ipc-param-list.h"
29 #include "email-ipc-build.h"
30
31 #include "email-debug-log.h"
32
33
34 /* deserializing data from stream */
35 EXPORT_API bool emipc_deserialize_api_info(emipc_email_api_info *api_info, EPARAMETER_DIRECTION direction, void *stream)
36 {
37         EM_DEBUG_FUNC_BEGIN("emipc_email_api_info : [%p], direction : [%d]", api_info, direction);
38         
39         if (!api_info || !stream) {
40                 EM_DEBUG_EXCEPTION("Invalid parameter.");
41                 return false;
42         }
43
44         if (api_info->params[direction] == NULL) {
45                 api_info->params[direction] = emipc_create_param_list();
46                 if (api_info->params[direction] == NULL) {
47                         EM_DEBUG_EXCEPTION("Malloc failed");
48                         return false;
49                 }
50         }
51
52         api_info->api_id = *((long *)stream + eSTREAM_APIID);
53         api_info->app_id = *((long*)stream + eSTREAM_APPID);
54         api_info->response_id = *((long*)stream + eSTREAM_RESID);
55
56         return emipc_parse_stream_of_param_list(api_info->params[direction], stream);
57 }
58
59 EXPORT_API unsigned char *emipc_serialize_api_info(emipc_email_api_info *api_info, EPARAMETER_DIRECTION direction, int *stream_len)
60 {
61         EM_DEBUG_FUNC_BEGIN();
62         unsigned char *stream = NULL;
63         
64         if (!api_info) {
65                 EM_DEBUG_EXCEPTION("Invalid parameter.");
66                 return stream;
67         }
68
69         if (api_info->params[direction] == NULL) {
70                 api_info->params[direction] = emipc_create_param_list();
71                 if (api_info->params[direction] == NULL) {
72                         EM_DEBUG_EXCEPTION("Malloc failed");
73                         return NULL;
74                 }
75         }
76
77         stream = emipc_serialize_param_list(api_info->params[direction], stream_len);
78         if (stream != NULL) {
79                 memcpy(stream, &(api_info->api_id), sizeof(api_info->api_id));
80                 memcpy(stream+(sizeof(long)*eSTREAM_RESID), &(api_info->response_id), sizeof(api_info->response_id));
81                 memcpy(stream+(sizeof(long)*eSTREAM_APPID), &(api_info->app_id), sizeof(api_info->app_id));
82         }
83         EM_DEBUG_FUNC_END();
84         return stream;
85 }
86
87 EXPORT_API void *emipc_get_parameters_of_api_info(emipc_email_api_info *api_info, EPARAMETER_DIRECTION direction)
88 {
89         EM_DEBUG_FUNC_BEGIN("emipc_email_api_info : [%p], direction : [%d]", api_info, direction);
90         
91         if (!api_info) {
92                 EM_DEBUG_EXCEPTION("INVALID_PARAM");
93                 return NULL;
94         }
95         
96         if (api_info->params[direction] == NULL) {
97                 api_info->params[direction] = emipc_create_param_list();
98                 if (api_info->params[direction] == NULL) {
99                         EM_DEBUG_EXCEPTION("emipc_create_param_list failed");
100                         return NULL;
101                 }
102         }
103
104         return api_info->params[direction];
105 }
106
107 EXPORT_API bool emipc_free_api_info(emipc_email_api_info *api_info)
108 {
109         if (!api_info) {
110                 EM_DEBUG_EXCEPTION("Invalid parameter");
111                 return false;
112         }
113
114         if (!emipc_destroy_param_list(api_info->params[ePARAMETER_IN])) {
115                 EM_DEBUG_EXCEPTION("emipc_destroy_param_list failed : ePARAMETER[%d]", ePARAMETER_IN);
116                 return false;
117         }
118
119         if (!emipc_destroy_param_list(api_info->params[ePARAMETER_OUT])) {
120                 EM_DEBUG_EXCEPTION("emipc_destroy_param_list failed : ePARAMETER[%d]", ePARAMETER_OUT);
121                 return false;
122         }
123
124         return true;
125 }
126
127