Tizen 2.0 Release
[platform/core/messaging/email-service.git] / email-ipc / email-ipc-api / email-ipc-param.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 <stdlib.h>
25
26 #include "email-ipc-param.h"
27 #include "email-debug-log.h"
28
29 EXPORT_API bool emipc_set_param(emipc_param *param, void *data, int len)
30 {
31         EM_DEBUG_FUNC_BEGIN();
32
33         if (!param) {
34                 EM_DEBUG_EXCEPTION("Invalid paramter");
35                 return false;
36         }
37
38         if (len == 0)
39                 return true;
40         
41         param->data = (void *)malloc(len);
42         if (param->data == NULL) {
43                 return false;
44         }
45         memset(param->data, 0x00, len);
46         memcpy(param->data, data, len);
47         param->length = len;
48         return true;
49 }
50
51 EXPORT_API void emipc_set_dynamic_param(emipc_param *param, void *data, int len)
52 {
53         EM_DEBUG_FUNC_BEGIN();
54
55         if (!param) {
56                 EM_DEBUG_EXCEPTION("Invalid paramter");
57                 return;
58         }
59
60         /* even take care of null data */
61         param->data = data;
62         param->length = len;
63 }
64
65 EXPORT_API void emipc_free_param(emipc_param param)
66 {
67         EM_SAFE_FREE(param.data);
68 }
69
70 EXPORT_API int emipc_get_length(emipc_param param)
71 {
72         return param.length;
73 }
74
75 EXPORT_API void *emipc_get_data(emipc_param param)
76 {
77         return param.data;
78 }