5749ce31ec3bd2d87a6c5cdcbcdb4ed203cd084c
[platform/core/pim/contacts-service.git] / common / ipc / ctsvc_ipc_email.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 #include "ctsvc_internal.h"
20 #include "ctsvc_ipc_marshal.h"
21 #include "contacts_record.h"
22
23
24 static int __ctsvc_ipc_unmarshal_email(pims_ipc_data_h ipc_data,
25                 const char *view_uri, contacts_record_h record)
26 {
27         ctsvc_email_s *email_p = (ctsvc_email_s*)record;
28
29         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_NO_DATA);
30         RETV_IF(NULL == record, CONTACTS_ERROR_NO_DATA);
31
32         do {
33                 if (ctsvc_ipc_unmarshal_bool(ipc_data, &email_p->is_default) != CONTACTS_ERROR_NONE)
34                         break;
35                 if (ctsvc_ipc_unmarshal_int(ipc_data, &email_p->id) != CONTACTS_ERROR_NONE)
36                         break;
37                 if (ctsvc_ipc_unmarshal_int(ipc_data, &email_p->contact_id) != CONTACTS_ERROR_NONE)
38                         break;
39                 if (ctsvc_ipc_unmarshal_int(ipc_data, &email_p->type) != CONTACTS_ERROR_NONE)
40                         break;
41                 if (ctsvc_ipc_unmarshal_string(ipc_data, &email_p->label) != CONTACTS_ERROR_NONE)
42                         break;
43                 if (ctsvc_ipc_unmarshal_string(ipc_data, &email_p->email_addr) != CONTACTS_ERROR_NONE)
44                         break;
45
46                 return CONTACTS_ERROR_NONE;
47
48         } while (0);
49
50         ERR("__ctsvc_ipc_unmarshal_email() Fail");
51         return CONTACTS_ERROR_INVALID_PARAMETER;
52 }
53
54 static int __ctsvc_ipc_marshal_email(const contacts_record_h record,
55                 pims_ipc_data_h ipc_data)
56 {
57         ctsvc_email_s *email_p = (ctsvc_email_s*)record;
58
59         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_NO_DATA);
60         RETV_IF(NULL == email_p, CONTACTS_ERROR_NO_DATA);
61
62         do {
63                 if (ctsvc_ipc_marshal_bool((email_p->is_default), ipc_data) != CONTACTS_ERROR_NONE)
64                         break;
65                 if (ctsvc_ipc_marshal_int((email_p->id), ipc_data) != CONTACTS_ERROR_NONE)
66                         break;
67                 if (ctsvc_ipc_marshal_int((email_p->contact_id), ipc_data) != CONTACTS_ERROR_NONE)
68                         break;
69                 if (ctsvc_ipc_marshal_int((email_p->type), ipc_data) != CONTACTS_ERROR_NONE)
70                         break;
71                 if (ctsvc_ipc_marshal_string((email_p->label), ipc_data) != CONTACTS_ERROR_NONE)
72                         break;
73                 if (ctsvc_ipc_marshal_string((email_p->email_addr), ipc_data) != CONTACTS_ERROR_NONE)
74                         break;
75
76                 return CONTACTS_ERROR_NONE;
77
78         } while (0);
79
80         ERR("_ctsvc_ipc_marshal() Fail");
81         return CONTACTS_ERROR_INVALID_PARAMETER;
82 }
83
84 ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_email_plugin_cb = {
85         .unmarshal_record = __ctsvc_ipc_unmarshal_email,
86         .marshal_record = __ctsvc_ipc_marshal_email
87 };
88