Rearrange contacts-service.service from default.target to delayed.target
[platform/core/pim/contacts-service.git] / common / ctsvc_record_updated_info.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 "contacts.h"
20 #include "ctsvc_internal.h"
21 #include "ctsvc_record.h"
22 #include "ctsvc_view.h"
23
24 static int __ctsvc_updated_info_create(contacts_record_h *out_record);
25 static int __ctsvc_updated_info_destroy(contacts_record_h record, bool delete_child);
26 static int __ctsvc_updated_info_clone(contacts_record_h record, contacts_record_h *out_record);
27 static int __ctsvc_updated_info_get_int(contacts_record_h record, unsigned int property_id, int *out);
28 static int __ctsvc_updated_info_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty);
29 static int __ctsvc_updated_info_get_bool(contacts_record_h record, unsigned int property_id, bool *out);
30 static int __ctsvc_updated_info_set_bool(contacts_record_h record, unsigned int property_id, bool value, bool *is_dirty);
31
32 ctsvc_record_plugin_cb_s updated_info_plugin_cbs = {
33         .create = __ctsvc_updated_info_create,
34         .destroy = __ctsvc_updated_info_destroy,
35         .clone = __ctsvc_updated_info_clone,
36         .get_str = NULL,
37         .get_str_p = NULL,
38         .get_int = __ctsvc_updated_info_get_int,
39         .get_bool = __ctsvc_updated_info_get_bool,
40         .get_lli = NULL,
41         .get_double = NULL,
42         .set_str = NULL,
43         .set_int = __ctsvc_updated_info_set_int,
44         .set_bool = __ctsvc_updated_info_set_bool,
45         .set_lli = NULL,
46         .set_double = NULL,
47         .add_child_record = NULL,
48         .remove_child_record = NULL,
49         .get_child_record_count = NULL,
50         .get_child_record_at_p = NULL,
51         .clone_child_record_list = NULL,
52 };
53
54 static int __ctsvc_updated_info_create(contacts_record_h *out_record)
55 {
56         ctsvc_updated_info_s *updated_info;
57         updated_info = calloc(1, sizeof(ctsvc_updated_info_s));
58         RETVM_IF(NULL == updated_info, CONTACTS_ERROR_OUT_OF_MEMORY, "calloc() is Fail");
59
60         *out_record = (contacts_record_h)updated_info;
61         return CONTACTS_ERROR_NONE;
62 }
63
64 static int __ctsvc_updated_info_destroy(contacts_record_h record, bool delete_child)
65 {
66         ctsvc_updated_info_s *updated_info = (ctsvc_updated_info_s*)record;
67         updated_info->base.plugin_cbs = NULL; /* help to find double destroy bug (refer to the contacts_record_destroy) */
68         free(updated_info->base.properties_flags);
69         free(updated_info);
70
71         return CONTACTS_ERROR_NONE;
72 }
73
74 static int __ctsvc_updated_info_clone(contacts_record_h record, contacts_record_h *out_record)
75 {
76         ctsvc_updated_info_s *out_data = NULL;
77         ctsvc_updated_info_s *src_data = NULL;
78
79         src_data = (ctsvc_updated_info_s*)record;
80         out_data = calloc(1, sizeof(ctsvc_updated_info_s));
81         RETVM_IF(NULL == out_data, CONTACTS_ERROR_OUT_OF_MEMORY,
82                         "Out of memeory : calloc(ctsvc_updated_info_s) Fail(%d)", CONTACTS_ERROR_OUT_OF_MEMORY);
83
84         out_data->id = src_data->id;
85         out_data->changed_type = src_data->changed_type;
86         out_data->changed_ver = src_data->changed_ver;
87         out_data->addressbook_id = src_data->addressbook_id;
88         out_data->image_changed = src_data->image_changed;
89         out_data->last_changed_type = src_data->last_changed_type;
90
91         int ret = ctsvc_record_copy_base(&(out_data->base), &(src_data->base));
92         if (CONTACTS_ERROR_NONE != ret) {
93                 /* LCOV_EXCL_START */
94                 ERR("ctsvc_record_copy_base() Fail");
95                 __ctsvc_updated_info_destroy((contacts_record_h)out_data, true);
96                 return ret;
97                 /* LCOV_EXCL_STOP */
98         }
99
100         *out_record = (contacts_record_h)out_data;
101         return CONTACTS_ERROR_NONE;
102 }
103
104 static int __ctsvc_updated_info_get_int(contacts_record_h record, unsigned int property_id, int *out)
105 {
106         ctsvc_updated_info_s *updated_info = (ctsvc_updated_info_s*)record;
107
108         switch (property_id) {
109         case CTSVC_PROPERTY_UPDATE_INFO_ID:
110                 *out = updated_info->id;
111                 break;
112         case CTSVC_PROPERTY_UPDATE_INFO_ADDRESSBOOK_ID:
113                 *out = updated_info->addressbook_id;
114                 break;
115         case CTSVC_PROPERTY_UPDATE_INFO_TYPE:
116                 *out = updated_info->changed_type;
117                 break;
118         case CTSVC_PROPERTY_UPDATE_INFO_VERSION:
119                 *out = updated_info->changed_ver;
120                 break;
121         case CTSVC_PROPERTY_UPDATE_INFO_LAST_CHANGED_TYPE:
122                 *out = updated_info->last_changed_type;
123                 break;
124         default:
125                 /* LCOV_EXCL_START */
126                 ERR("This field(%d) is not supported in value(updated_info)", property_id);
127                 return CONTACTS_ERROR_INVALID_PARAMETER;
128                 /* LCOV_EXCL_STOP */
129         }
130         return CONTACTS_ERROR_NONE;
131 }
132
133 static int __ctsvc_updated_info_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty)
134 {
135         ctsvc_updated_info_s *updated_info = (ctsvc_updated_info_s*)record;
136
137         switch (property_id) {
138         case CTSVC_PROPERTY_UPDATE_INFO_ID:
139                 CHECK_DIRTY_VAL(updated_info->id, value, is_dirty);
140                 updated_info->id = value;
141                 break;
142         case CTSVC_PROPERTY_UPDATE_INFO_ADDRESSBOOK_ID:
143                 CHECK_DIRTY_VAL(updated_info->addressbook_id, value, is_dirty);
144                 updated_info->addressbook_id = value;
145                 break;
146         case CTSVC_PROPERTY_UPDATE_INFO_TYPE:
147                 RETVM_IF(value < CONTACTS_CHANGE_INSERTED
148                                 || CONTACTS_CHANGE_DELETED < value,
149                                 CONTACTS_ERROR_INVALID_PARAMETER, "update info type is in invalid range (%d)", value);
150                 CHECK_DIRTY_VAL(updated_info->changed_type, value, is_dirty);
151                 updated_info->changed_type = value;
152                 break;
153         case CTSVC_PROPERTY_UPDATE_INFO_VERSION:
154                 CHECK_DIRTY_VAL(updated_info->changed_ver, value, is_dirty);
155                 updated_info->changed_ver = value;
156                 break;
157         case CTSVC_PROPERTY_UPDATE_INFO_LAST_CHANGED_TYPE:
158                 CHECK_DIRTY_VAL(updated_info->last_changed_type, value, is_dirty);
159                 updated_info->last_changed_type = value;
160                 break;
161         default:
162                 /* LCOV_EXCL_START */
163                 ERR("This field(%d) is not supported in value(updated_info)", property_id);
164                 return CONTACTS_ERROR_INVALID_PARAMETER;
165                 /* LCOV_EXCL_STOP */
166         }
167         return CONTACTS_ERROR_NONE;
168 }
169
170 static int __ctsvc_updated_info_get_bool(contacts_record_h record, unsigned int property_id, bool *out)
171 {
172         ctsvc_updated_info_s *updated_info = (ctsvc_updated_info_s*)record;
173
174         switch (property_id) {
175         case CTSVC_PROPERTY_UPDATE_INFO_IMAGE_CHANGED:
176                 *out = updated_info->image_changed;
177                 break;
178         default:
179                 /* LCOV_EXCL_START */
180                 ERR("This field(%d) is not supported in value(updated_info)", property_id);
181                 return CONTACTS_ERROR_INVALID_PARAMETER;
182                 /* LCOV_EXCL_STOP */
183         }
184         return CONTACTS_ERROR_NONE;
185 }
186
187 static int __ctsvc_updated_info_set_bool(contacts_record_h record, unsigned int property_id, bool value, bool *is_dirty)
188 {
189         ctsvc_updated_info_s *updated_info = (ctsvc_updated_info_s*)record;
190
191         switch (property_id) {
192         case CTSVC_PROPERTY_UPDATE_INFO_IMAGE_CHANGED:
193                 CHECK_DIRTY_VAL(updated_info->image_changed, value, is_dirty);
194                 updated_info->image_changed = value;
195                 break;
196         default:
197                 /* LCOV_EXCL_START */
198                 ERR("This field(%d) is not supported in value(updated_info)", property_id);
199                 return CONTACTS_ERROR_INVALID_PARAMETER;
200                 /* LCOV_EXCL_STOP */
201         }
202         return CONTACTS_ERROR_NONE;
203 }
204