Update 0.9.59
[platform/core/pim/contacts-service.git] / common / ipc / ctsvc_ipc_image.c
1 #include "ctsvc_ipc_macros.h"
2
3
4 #include "ctsvc_internal.h"
5 #include "ctsvc_ipc_marshal.h"
6 #include "contacts_record.h"
7
8 static int __ctsvc_ipc_unmarshal_image(pims_ipc_data_h ipc_data, const char* view_uri, contacts_record_h record);
9 static int __ctsvc_ipc_marshal_image(const contacts_record_h record, pims_ipc_data_h ipc_data);
10 static int __ctsvc_ipc_marshal_image_get_primary_id(const contacts_record_h record, unsigned int *property_id, int *id);
11
12 ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_image_plugin_cb = {
13         .unmarshal_record = __ctsvc_ipc_unmarshal_image,
14         .marshal_record = __ctsvc_ipc_marshal_image,
15         .get_primary_id = __ctsvc_ipc_marshal_image_get_primary_id
16 };
17
18
19 static int __ctsvc_ipc_unmarshal_image(pims_ipc_data_h ipc_data, const char* view_uri, contacts_record_h record)
20 {
21         RETV_IF(ipc_data==NULL,CONTACTS_ERROR_NO_DATA);
22         RETV_IF(record==NULL,CONTACTS_ERROR_NO_DATA);
23
24         ctsvc_image_s* image_p = (ctsvc_image_s*) record;
25
26         do {
27                 if (ctsvc_ipc_unmarshal_int(ipc_data, &image_p->id) != CONTACTS_ERROR_NONE) break;
28                 if (ctsvc_ipc_unmarshal_int(ipc_data, &image_p->contact_id) != CONTACTS_ERROR_NONE) break;
29                 if (ctsvc_ipc_unmarshal_int(ipc_data, &image_p->type) != CONTACTS_ERROR_NONE) break;
30                 if (ctsvc_ipc_unmarshal_string(ipc_data, &image_p->label) != CONTACTS_ERROR_NONE) break;
31                 if (ctsvc_ipc_unmarshal_string(ipc_data, &image_p->path) != CONTACTS_ERROR_NONE) break;
32                 if (ctsvc_ipc_unmarshal_bool(ipc_data, &image_p->is_default) != CONTACTS_ERROR_NONE) break;
33
34                 return CONTACTS_ERROR_NONE;
35         } while(0);
36
37         CTS_ERR("_ctsvc_ipc_unmarshal fail");
38         return CONTACTS_ERROR_INVALID_PARAMETER;
39 }
40
41 static int __ctsvc_ipc_marshal_image(const contacts_record_h record, pims_ipc_data_h ipc_data)
42 {
43         ctsvc_image_s* image_p = (ctsvc_image_s*)record;
44         RETV_IF(ipc_data==NULL,CONTACTS_ERROR_NO_DATA);
45         RETV_IF(image_p==NULL,CONTACTS_ERROR_NO_DATA);
46
47         do {
48                 if (ctsvc_ipc_marshal_int((image_p->id),ipc_data) != CONTACTS_ERROR_NONE) break;
49                 if (ctsvc_ipc_marshal_int((image_p->contact_id),ipc_data) != CONTACTS_ERROR_NONE) break;
50                 if (ctsvc_ipc_marshal_int((image_p->type),ipc_data) != CONTACTS_ERROR_NONE) break;
51                 if (ctsvc_ipc_marshal_string((image_p->label),ipc_data) != CONTACTS_ERROR_NONE) break;
52                 if (ctsvc_ipc_marshal_string((image_p->path),ipc_data) != CONTACTS_ERROR_NONE) break;
53                 if (ctsvc_ipc_marshal_bool((image_p->is_default),ipc_data) != CONTACTS_ERROR_NONE) break;
54
55                 return CONTACTS_ERROR_NONE;
56         } while(0);
57
58         CTS_ERR("_ctsvc_ipc_marshal fail");
59         return CONTACTS_ERROR_INVALID_PARAMETER;
60 }
61
62 static int __ctsvc_ipc_marshal_image_get_primary_id(const contacts_record_h record, unsigned int *property_id, int *id)
63 {
64         *property_id = CTSVC_PROPERTY_IMAGE_ID;
65         return contacts_record_get_int(record, *property_id, id );
66 }