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.
23 #include "ctsvc_internal.h"
24 #include "ctsvc_record.h"
25 #include "ctsvc_view.h"
27 static int __ctsvc_person_create(contacts_record_h* out_record);
28 static int __ctsvc_person_destroy(contacts_record_h record, bool delete_child);
29 static int __ctsvc_person_clone(contacts_record_h record, contacts_record_h *out_record);
30 static int __ctsvc_person_get_int(contacts_record_h record, unsigned int property_id, int *out);
31 static int __ctsvc_person_get_str_p(contacts_record_h record, unsigned int property_id, char** out_str);
32 static int __ctsvc_person_get_str(contacts_record_h record, unsigned int property_id, char** out_str);
33 static int __ctsvc_person_get_bool( contacts_record_h record, unsigned int property_id, bool *value );
34 static int __ctsvc_person_set_int(contacts_record_h record, unsigned int property_id, int value);
35 static int __ctsvc_person_set_str(contacts_record_h record, unsigned int property_id, const char* str );
36 static int __ctsvc_person_set_bool(contacts_record_h record, unsigned int property_id, bool value);
39 ctsvc_record_plugin_cb_s person_plugin_cbs = {
40 .create = __ctsvc_person_create,
41 .destroy = __ctsvc_person_destroy,
42 .clone = __ctsvc_person_clone,
43 .get_str = __ctsvc_person_get_str,
44 .get_str_p = __ctsvc_person_get_str_p,
45 .get_int = __ctsvc_person_get_int,
46 .get_bool = __ctsvc_person_get_bool,
49 .set_str = __ctsvc_person_set_str,
50 .set_int = __ctsvc_person_set_int,
51 .set_bool = __ctsvc_person_set_bool,
54 .add_child_record = NULL,
55 .remove_child_record = NULL,
56 .get_child_record_count = NULL,
57 .get_child_record_at_p = NULL,
58 .clone_child_record_list = NULL,
61 static int __ctsvc_person_create(contacts_record_h* out_record)
63 ctsvc_person_s *person;
64 person = (ctsvc_person_s*)calloc(1, sizeof(ctsvc_person_s));
65 RETVM_IF(NULL == person, CONTACTS_ERROR_OUT_OF_MEMORY,
66 "Out of memory : calloc is failed");
68 *out_record = (contacts_record_h)person;
69 return CONTACTS_ERROR_NONE;
72 static int __ctsvc_person_destroy(contacts_record_h record, bool delete_child)
74 ctsvc_person_s *person = (ctsvc_person_s*)record;
75 person->base.plugin_cbs = NULL; // help to find double-destroy bug (refer to the contacts_record_destroy)
76 free(person->base.properties_flags);
78 free(person->display_name);
79 free(person->display_name_index);
80 free(person->ringtone_path);
81 free(person->vibration);
82 free(person->message_alert);
83 free(person->image_thumbnail_path);
85 free(person->addressbook_ids);
88 return CONTACTS_ERROR_NONE;
91 static int __ctsvc_person_clone(contacts_record_h record, contacts_record_h *out_record)
93 ctsvc_person_s *out_data = NULL;
94 ctsvc_person_s *src_data = NULL;
96 src_data = (ctsvc_person_s*)record;
97 out_data = calloc(1, sizeof(ctsvc_person_s));
98 RETVM_IF(NULL == out_data, CONTACTS_ERROR_OUT_OF_MEMORY,
99 "Out of memeory : calloc(ctsvc_person_s) Failed(%d)", CONTACTS_ERROR_OUT_OF_MEMORY);
101 out_data->is_favorite = src_data->is_favorite;
102 out_data->has_phonenumber = src_data->has_phonenumber;
103 out_data->has_email = src_data->has_email;
104 out_data->person_id = src_data->person_id;
105 out_data->name_contact_id = src_data->name_contact_id;
106 out_data->link_count = src_data->link_count;
107 out_data->addressbook_ids = SAFE_STRDUP(src_data->addressbook_ids);
108 out_data->display_name = SAFE_STRDUP(src_data->display_name);
109 out_data->display_name_index = SAFE_STRDUP(src_data->display_name_index);
110 out_data->image_thumbnail_path = SAFE_STRDUP(src_data->image_thumbnail_path);
111 out_data->ringtone_path = SAFE_STRDUP(src_data->ringtone_path);
112 out_data->vibration = SAFE_STRDUP(src_data->vibration);
113 out_data->message_alert = SAFE_STRDUP(src_data->message_alert);
114 out_data->status = SAFE_STRDUP(src_data->status);
116 CTSVC_RECORD_COPY_BASE(&(out_data->base), &(src_data->base));
118 *out_record = (contacts_record_h)out_data;
119 return CONTACTS_ERROR_NONE;
122 static int __ctsvc_person_get_int(contacts_record_h record, unsigned int property_id, int *out)
124 ctsvc_person_s *person = (ctsvc_person_s *)record;
125 switch(property_id) {
126 case CTSVC_PROPERTY_PERSON_ID:
127 *out = person->person_id;
129 case CTSVC_PROPERTY_PERSON_DISPLAY_CONTACT_ID:
130 *out = person->name_contact_id;
132 case CTSVC_PROPERTY_PERSON_LINK_COUNT:
133 *out = person->link_count;
136 CTS_ERR("This field(%d) is not supported in value(person)", property_id);
137 return CONTACTS_ERROR_INVALID_PARAMETER;
139 return CONTACTS_ERROR_NONE;
142 static int __ctsvc_person_get_str_real(contacts_record_h record, unsigned int property_id, char** out_str, bool copy )
144 ctsvc_person_s *person = (ctsvc_person_s *)record;
145 switch(property_id) {
146 case CTSVC_PROPERTY_PERSON_DISPLAY_NAME:
147 *out_str = GET_STR(copy, person->display_name);
149 case CTSVC_PROPERTY_PERSON_RINGTONE:
150 *out_str = GET_STR(copy, person->ringtone_path);
152 case CTSVC_PROPERTY_PERSON_IMAGE_THUMBNAIL:
153 *out_str = GET_STR(copy, person->image_thumbnail_path);
155 case CTSVC_PROPERTY_PERSON_VIBRATION:
156 *out_str = GET_STR(copy, person->vibration);
158 case CTSVC_PROPERTY_PERSON_MESSAGE_ALERT:
159 *out_str = GET_STR(copy, person->message_alert);
161 case CTSVC_PROPERTY_PERSON_STATUS:
162 *out_str = GET_STR(copy, person->status);
164 case CTSVC_PROPERTY_PERSON_DISPLAY_NAME_INDEX:
165 *out_str = GET_STR(copy, person->display_name_index);
167 case CTSVC_PROPERTY_PERSON_ADDRESSBOOK_IDS:
168 *out_str = GET_STR(copy, person->addressbook_ids);
171 CTS_ERR("This field(%d) is not supported in value(person)", property_id);
172 return CONTACTS_ERROR_INVALID_PARAMETER;
174 return CONTACTS_ERROR_NONE;
177 static int __ctsvc_person_get_str_p(contacts_record_h record, unsigned int property_id, char** out_str)
179 return __ctsvc_person_get_str_real(record, property_id, out_str, false);
182 static int __ctsvc_person_get_str(contacts_record_h record, unsigned int property_id, char** out_str)
184 return __ctsvc_person_get_str_real(record, property_id, out_str, true);
187 static int __ctsvc_person_get_bool(contacts_record_h record, unsigned int property_id, bool *value )
189 ctsvc_person_s *person = (ctsvc_person_s *)record;
190 switch (property_id) {
191 case CTSVC_PROPERTY_PERSON_IS_FAVORITE:
192 *value = person->is_favorite;
194 case CTSVC_PROPERTY_PERSON_HAS_PHONENUMBER:
195 *value = person->has_phonenumber;
197 case CTSVC_PROPERTY_PERSON_HAS_EMAIL:
198 *value = person->has_email;
201 CTS_ERR("This field(%d) is not supported in value(company)", property_id);
202 return CONTACTS_ERROR_INVALID_PARAMETER;
204 return CONTACTS_ERROR_NONE;
207 static int __ctsvc_person_set_int(contacts_record_h record, unsigned int property_id, int value)
209 ctsvc_person_s *person = (ctsvc_person_s *)record;
211 switch(property_id) {
212 case CTSVC_PROPERTY_PERSON_DISPLAY_CONTACT_ID:
213 person->name_contact_id = value;
215 case CTSVC_PROPERTY_PERSON_ID:
216 person->person_id = value;
218 case CTSVC_PROPERTY_PERSON_LINK_COUNT:
219 person->link_count = value;
222 CTS_ERR("This field(0x%0x) is not supported in value(person)", property_id);
223 return CONTACTS_ERROR_INVALID_PARAMETER;
225 return CONTACTS_ERROR_NONE;
228 static int __ctsvc_person_set_str(contacts_record_h record, unsigned int property_id, const char* str )
230 ctsvc_person_s *person = (ctsvc_person_s *)record;
232 switch(property_id) {
233 case CTSVC_PROPERTY_PERSON_DISPLAY_NAME:
234 FREEandSTRDUP( person->display_name, str);
236 case CTSVC_PROPERTY_PERSON_DISPLAY_NAME_INDEX:
237 FREEandSTRDUP( person->display_name_index, str);
239 case CTSVC_PROPERTY_PERSON_IMAGE_THUMBNAIL:
240 FREEandSTRDUP(person->image_thumbnail_path, str);
242 case CTSVC_PROPERTY_PERSON_RINGTONE:
243 FREEandSTRDUP(person->ringtone_path, str);
245 case CTSVC_PROPERTY_PERSON_VIBRATION:
246 FREEandSTRDUP(person->vibration, str);
248 case CTSVC_PROPERTY_PERSON_MESSAGE_ALERT:
249 FREEandSTRDUP(person->message_alert, str);
252 CTS_ERR("This field(%d) is not supported in value(person)", property_id);
253 return CONTACTS_ERROR_INVALID_PARAMETER;
255 return CONTACTS_ERROR_NONE;
258 static int __ctsvc_person_set_bool(contacts_record_h record, unsigned int property_id, bool value)
260 ctsvc_person_s *person = (ctsvc_person_s *)record;
262 switch(property_id) {
263 case CTSVC_PROPERTY_PERSON_IS_FAVORITE:
264 if (person->is_favorite != value) {
265 person->is_favorite = value;
269 CTS_ERR("This field(%d) is not supported in value(person)", property_id);
270 return CONTACTS_ERROR_INVALID_PARAMETER;
272 return CONTACTS_ERROR_NONE;