4 * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "ctsvc_internal.h"
22 #include "ctsvc_record.h"
23 #include "ctsvc_view.h"
25 static int __ctsvc_updated_info_create(contacts_record_h* out_record);
26 static int __ctsvc_updated_info_destroy(contacts_record_h record, bool delete_child);
27 static int __ctsvc_updated_info_clone(contacts_record_h record, contacts_record_h *out_record);
28 static int __ctsvc_updated_info_get_int(contacts_record_h record, unsigned int property_id, int *out);
29 static int __ctsvc_updated_info_set_int(contacts_record_h record, unsigned int property_id, int value);
30 static int __ctsvc_updated_info_get_bool(contacts_record_h record, unsigned int property_id, bool *out);
31 static int __ctsvc_updated_info_set_bool(contacts_record_h record, unsigned int property_id, bool value);
33 ctsvc_record_plugin_cb_s updated_info_plugin_cbs = {
34 .create = __ctsvc_updated_info_create,
35 .destroy = __ctsvc_updated_info_destroy,
36 .clone = __ctsvc_updated_info_clone,
39 .get_int = __ctsvc_updated_info_get_int,
40 .get_bool = __ctsvc_updated_info_get_bool,
44 .set_int = __ctsvc_updated_info_set_int,
45 .set_bool = __ctsvc_updated_info_set_bool,
48 .add_child_record = NULL,
49 .remove_child_record = NULL,
50 .get_child_record_count = NULL,
51 .get_child_record_at_p = NULL,
52 .clone_child_record_list = NULL,
55 static int __ctsvc_updated_info_create(contacts_record_h* out_record)
57 ctsvc_updated_info_s *updated_info;
58 updated_info = (ctsvc_updated_info_s*)calloc(1, sizeof(ctsvc_updated_info_s));
59 RETVM_IF(NULL == updated_info, CONTACTS_ERROR_OUT_OF_MEMORY,
60 "Out of memory calloc is Fail");
62 *out_record = (contacts_record_h)updated_info;
63 return CONTACTS_ERROR_NONE;
66 static int __ctsvc_updated_info_destroy(contacts_record_h record, bool delete_child)
68 ctsvc_updated_info_s* updated_info = (ctsvc_updated_info_s*)record;
69 updated_info->base.plugin_cbs = NULL; // help to find double destroy bug (refer to the contacts_record_destroy)
70 free(updated_info->base.properties_flags);
73 return CONTACTS_ERROR_NONE;
76 static int __ctsvc_updated_info_clone(contacts_record_h record, contacts_record_h *out_record)
78 ctsvc_updated_info_s *out_data = NULL;
79 ctsvc_updated_info_s *src_data = NULL;
81 src_data = (ctsvc_updated_info_s*)record;
82 out_data = calloc(1, sizeof(ctsvc_updated_info_s));
83 RETVM_IF(NULL == out_data, CONTACTS_ERROR_OUT_OF_MEMORY,
84 "Out of memeory : calloc(ctsvc_updated_info_s) Fail(%d)", CONTACTS_ERROR_OUT_OF_MEMORY);
86 out_data->id = src_data->id;
87 out_data->changed_type = src_data->changed_type;
88 out_data->changed_ver = src_data->changed_ver;
89 out_data->addressbook_id = src_data->addressbook_id;
91 CTSVC_RECORD_COPY_BASE(&(out_data->base), &(src_data->base));
93 *out_record = (contacts_record_h)out_data;
94 return CONTACTS_ERROR_NONE;
97 static int __ctsvc_updated_info_get_int(contacts_record_h record, unsigned int property_id, int *out)
99 ctsvc_updated_info_s* updated_info = (ctsvc_updated_info_s*)record;
101 switch(property_id) {
102 case CTSVC_PROPERTY_UPDATE_INFO_ID :
103 *out = updated_info->id;
105 case CTSVC_PROPERTY_UPDATE_INFO_ADDRESSBOOK_ID:
106 *out = updated_info->addressbook_id;
108 case CTSVC_PROPERTY_UPDATE_INFO_TYPE:
109 *out = updated_info->changed_type;
111 case CTSVC_PROPERTY_UPDATE_INFO_VERSION:
112 *out = updated_info->changed_ver;
114 case CTSVC_PROPERTY_UPDATE_INFO_LAST_CHANGED_TYPE:
115 *out = updated_info->last_changed_type;
118 CTS_ERR("This field(%d) is not supported in value(updated_info)", property_id);
119 return CONTACTS_ERROR_INVALID_PARAMETER;
121 return CONTACTS_ERROR_NONE;
124 static int __ctsvc_updated_info_set_int(contacts_record_h record, unsigned int property_id, int value)
126 ctsvc_updated_info_s* updated_info = (ctsvc_updated_info_s*)record;
128 switch(property_id) {
129 case CTSVC_PROPERTY_UPDATE_INFO_ID :
130 updated_info->id = value;
132 case CTSVC_PROPERTY_UPDATE_INFO_ADDRESSBOOK_ID:
133 updated_info->addressbook_id = value;
135 case CTSVC_PROPERTY_UPDATE_INFO_TYPE:
136 RETVM_IF(value < CONTACTS_CHANGE_INSERTED
137 || CONTACTS_CHANGE_DELETED < value,
138 CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : update info type is in invalid range (%d)", value);
139 updated_info->changed_type = value;
141 case CTSVC_PROPERTY_UPDATE_INFO_VERSION:
142 updated_info->changed_ver = value;
144 case CTSVC_PROPERTY_UPDATE_INFO_LAST_CHANGED_TYPE:
145 updated_info->last_changed_type = value;
148 CTS_ERR("This field(%d) is not supported in value(updated_info)", property_id);
149 return CONTACTS_ERROR_INVALID_PARAMETER;
151 return CONTACTS_ERROR_NONE;
154 static int __ctsvc_updated_info_get_bool(contacts_record_h record, unsigned int property_id, bool *out)
156 ctsvc_updated_info_s* updated_info = (ctsvc_updated_info_s*)record;
158 switch(property_id) {
159 case CTSVC_PROPERTY_UPDATE_INFO_IMAGE_CHANGED :
160 *out = updated_info->image_changed;
163 CTS_ERR("This field(%d) is not supported in value(updated_info)", property_id);
164 return CONTACTS_ERROR_INVALID_PARAMETER;
166 return CONTACTS_ERROR_NONE;
169 static int __ctsvc_updated_info_set_bool(contacts_record_h record, unsigned int property_id, bool value)
171 ctsvc_updated_info_s* updated_info = (ctsvc_updated_info_s*)record;
173 switch(property_id) {
174 case CTSVC_PROPERTY_UPDATE_INFO_IMAGE_CHANGED :
175 updated_info->image_changed = value;
178 CTS_ERR("This field(%d) is not supported in value(updated_info)", property_id);
179 return CONTACTS_ERROR_INVALID_PARAMETER;
181 return CONTACTS_ERROR_NONE;