Apply coding idiom guide
[platform/core/pim/contacts-service.git] / common / ipc / ctsvc_ipc_contact.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2012 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
20 #include "ctsvc_internal.h"
21 #include "ctsvc_ipc_marshal.h"
22
23 static int __ctsvc_ipc_unmarshal_contact(pims_ipc_data_h ipc_data, const char* view_uri, contacts_record_h record);
24 static int __ctsvc_ipc_marshal_contact(const contacts_record_h record, pims_ipc_data_h ipc_data);
25 static int __ctsvc_ipc_marshal_contact_get_primary_id(const contacts_record_h record, unsigned int *property_id, int *id);
26
27 ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_contact_plugin_cb = {
28         .unmarshal_record = __ctsvc_ipc_unmarshal_contact,
29         .marshal_record = __ctsvc_ipc_marshal_contact,
30         .get_primary_id = __ctsvc_ipc_marshal_contact_get_primary_id
31 };
32
33 static int __ctsvc_ipc_unmarshal_contact(pims_ipc_data_h ipc_data, const char* view_uri, contacts_record_h record)
34 {
35         RETV_IF(ipc_data==NULL,CONTACTS_ERROR_NO_DATA);
36         RETV_IF(record==NULL,CONTACTS_ERROR_NO_DATA);
37
38         ctsvc_contact_s* pcontact = (ctsvc_contact_s*) record;
39
40         do {
41                 if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->is_favorite) != CONTACTS_ERROR_NONE) break;
42                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->id) != CONTACTS_ERROR_NONE) break;
43                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->person_id) != CONTACTS_ERROR_NONE) break;
44                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->changed_time) != CONTACTS_ERROR_NONE) break;
45                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->link_mode) != CONTACTS_ERROR_NONE) break;
46                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->addressbook_id) != CONTACTS_ERROR_NONE) break;
47                 if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->has_phonenumber) != CONTACTS_ERROR_NONE) break;
48                 if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->has_email) != CONTACTS_ERROR_NONE) break;
49                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->display_name) != CONTACTS_ERROR_NONE) break;
50                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->reverse_display_name) != CONTACTS_ERROR_NONE) break;
51                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->display_source_type) != CONTACTS_ERROR_NONE) break;
52                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->display_name_language) != CONTACTS_ERROR_NONE) break;
53                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->reverse_display_name_language) != CONTACTS_ERROR_NONE) break;
54                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->sort_name) != CONTACTS_ERROR_NONE) break;
55                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->reverse_sort_name) != CONTACTS_ERROR_NONE) break;
56                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->sortkey) != CONTACTS_ERROR_NONE) break;
57                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->reverse_sortkey) != CONTACTS_ERROR_NONE) break;
58                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->uid) != CONTACTS_ERROR_NONE) break;
59                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->image_thumbnail_path) != CONTACTS_ERROR_NONE) break;
60                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->ringtone_path) != CONTACTS_ERROR_NONE) break;
61                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->vibration) != CONTACTS_ERROR_NONE) break;
62                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->message_alert) != CONTACTS_ERROR_NONE) break;
63                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->changed_ver) != CONTACTS_ERROR_NONE) break;
64
65                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->name) != CONTACTS_ERROR_NONE) break;
66                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->note) != CONTACTS_ERROR_NONE) break;
67                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->company) != CONTACTS_ERROR_NONE) break;
68                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->numbers) != CONTACTS_ERROR_NONE) break;
69                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->emails) != CONTACTS_ERROR_NONE) break;
70                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->grouprelations) != CONTACTS_ERROR_NONE) break;
71                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->events) != CONTACTS_ERROR_NONE) break;
72                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->messengers) != CONTACTS_ERROR_NONE) break;
73                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->postal_addrs) != CONTACTS_ERROR_NONE) break;
74                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->urls) != CONTACTS_ERROR_NONE) break;
75                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->nicknames) != CONTACTS_ERROR_NONE) break;
76                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->profiles) != CONTACTS_ERROR_NONE) break;
77                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->relationships) != CONTACTS_ERROR_NONE) break;
78                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->images) != CONTACTS_ERROR_NONE) break;
79                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->extensions) != CONTACTS_ERROR_NONE) break;
80
81                 return CONTACTS_ERROR_NONE;
82         } while (0);
83
84         CTS_ERR("_ctsvc_ipc_unmarshal fail");
85         return CONTACTS_ERROR_INVALID_PARAMETER;
86 }
87
88 static int __ctsvc_ipc_marshal_contact(const contacts_record_h record, pims_ipc_data_h ipc_data)
89 {
90         ctsvc_contact_s* pcontact = (ctsvc_contact_s*)record;
91         RETV_IF(ipc_data==NULL,CONTACTS_ERROR_NO_DATA);
92         RETV_IF(pcontact==NULL,CONTACTS_ERROR_NO_DATA);
93
94         do {
95                 if (ctsvc_ipc_marshal_bool((pcontact->is_favorite),ipc_data) != CONTACTS_ERROR_NONE) break;
96                 if (ctsvc_ipc_marshal_int((pcontact->id),ipc_data) != CONTACTS_ERROR_NONE) break;
97                 if (ctsvc_ipc_marshal_int((pcontact->person_id),ipc_data) != CONTACTS_ERROR_NONE) break;
98                 if (ctsvc_ipc_marshal_int((pcontact->changed_time),ipc_data) != CONTACTS_ERROR_NONE) break;
99                 if (ctsvc_ipc_marshal_int((pcontact->link_mode),ipc_data) != CONTACTS_ERROR_NONE) break;
100                 if (ctsvc_ipc_marshal_int((pcontact->addressbook_id),ipc_data) != CONTACTS_ERROR_NONE) break;
101                 if (ctsvc_ipc_marshal_bool((pcontact->has_phonenumber),ipc_data) != CONTACTS_ERROR_NONE) break;
102                 if (ctsvc_ipc_marshal_bool((pcontact->has_email),ipc_data) != CONTACTS_ERROR_NONE) break;
103                 if (ctsvc_ipc_marshal_string((pcontact->display_name),ipc_data) != CONTACTS_ERROR_NONE) break;
104                 if (ctsvc_ipc_marshal_string((pcontact->reverse_display_name),ipc_data) != CONTACTS_ERROR_NONE) break;
105                 if (ctsvc_ipc_marshal_int((pcontact->display_source_type),ipc_data) != CONTACTS_ERROR_NONE) break;
106                 if (ctsvc_ipc_marshal_int((pcontact->display_name_language),ipc_data) != CONTACTS_ERROR_NONE) break;
107                 if (ctsvc_ipc_marshal_int((pcontact->reverse_display_name_language),ipc_data) != CONTACTS_ERROR_NONE) break;
108                 if (ctsvc_ipc_marshal_string((pcontact->sort_name),ipc_data) != CONTACTS_ERROR_NONE) break;
109                 if (ctsvc_ipc_marshal_string((pcontact->reverse_sort_name),ipc_data) != CONTACTS_ERROR_NONE) break;
110                 if (ctsvc_ipc_marshal_string((pcontact->sortkey),ipc_data) != CONTACTS_ERROR_NONE) break;
111                 if (ctsvc_ipc_marshal_string((pcontact->reverse_sortkey),ipc_data) != CONTACTS_ERROR_NONE) break;
112                 if (ctsvc_ipc_marshal_string((pcontact->uid),ipc_data) != CONTACTS_ERROR_NONE) break;
113                 if (ctsvc_ipc_marshal_string((pcontact->image_thumbnail_path),ipc_data) != CONTACTS_ERROR_NONE) break;
114                 if (ctsvc_ipc_marshal_string((pcontact->ringtone_path),ipc_data) != CONTACTS_ERROR_NONE) break;
115                 if (ctsvc_ipc_marshal_string((pcontact->vibration),ipc_data) != CONTACTS_ERROR_NONE) break;
116                 if (ctsvc_ipc_marshal_string((pcontact->message_alert),ipc_data) != CONTACTS_ERROR_NONE) break;
117                 if (ctsvc_ipc_marshal_int((pcontact->changed_ver),ipc_data) != CONTACTS_ERROR_NONE) break;
118
119                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->name, ipc_data) != CONTACTS_ERROR_NONE) break;
120                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->note, ipc_data) != CONTACTS_ERROR_NONE) break;
121                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->company, ipc_data) != CONTACTS_ERROR_NONE) break;
122                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->numbers, ipc_data) != CONTACTS_ERROR_NONE) break;
123                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->emails, ipc_data) != CONTACTS_ERROR_NONE) break;
124                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->grouprelations, ipc_data) != CONTACTS_ERROR_NONE) break;
125                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->events, ipc_data) != CONTACTS_ERROR_NONE) break;
126                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->messengers, ipc_data) != CONTACTS_ERROR_NONE) break;
127                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->postal_addrs, ipc_data) != CONTACTS_ERROR_NONE) break;
128                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->urls, ipc_data) != CONTACTS_ERROR_NONE) break;
129                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->nicknames, ipc_data) != CONTACTS_ERROR_NONE) break;
130                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->profiles, ipc_data) != CONTACTS_ERROR_NONE) break;
131                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->relationships, ipc_data) != CONTACTS_ERROR_NONE) break;
132                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->images, ipc_data) != CONTACTS_ERROR_NONE) break;
133                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->extensions, ipc_data) != CONTACTS_ERROR_NONE) break;
134
135                 return CONTACTS_ERROR_NONE;
136         } while (0);
137
138         CTS_ERR("_ctsvc_ipc_marshal fail");
139         return CONTACTS_ERROR_INVALID_PARAMETER;
140 }
141
142 static int __ctsvc_ipc_marshal_contact_get_primary_id(const contacts_record_h record, unsigned int *property_id, int *id)
143 {
144         *property_id = CTSVC_PROPERTY_CONTACT_ID;
145         return contacts_record_get_int(record, *property_id, id);
146 }