4 * Copyright (c) 2010 - 2015 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.
20 #include "ctsvc_internal.h"
21 #include "ctsvc_record.h"
22 #include "ctsvc_view.h"
24 static int __ctsvc_speeddial_create(contacts_record_h *out_record);
25 static int __ctsvc_speeddial_destroy(contacts_record_h record, bool delete_child);
26 static int __ctsvc_speeddial_clone(contacts_record_h record, contacts_record_h *out_record);
27 static int __ctsvc_speeddial_get_int(contacts_record_h record, unsigned int property_id, int *out);
28 static int __ctsvc_speeddial_get_str(contacts_record_h record, unsigned int property_id, char **out_str);
29 static int __ctsvc_speeddial_get_str_p(contacts_record_h record, unsigned int property_id, char **out_str);
30 static int __ctsvc_speeddial_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty);
31 static int __ctsvc_speeddial_set_str(contacts_record_h record, unsigned int property_id, const char *str, bool *is_dirty);
34 ctsvc_record_plugin_cb_s speeddial_plugin_cbs = {
35 .create = __ctsvc_speeddial_create,
36 .destroy = __ctsvc_speeddial_destroy,
37 .clone = __ctsvc_speeddial_clone,
38 .get_str = __ctsvc_speeddial_get_str,
39 .get_str_p = __ctsvc_speeddial_get_str_p,
40 .get_int = __ctsvc_speeddial_get_int,
44 .set_str = __ctsvc_speeddial_set_str,
45 .set_int = __ctsvc_speeddial_set_int,
49 .add_child_record = NULL,
50 .remove_child_record = NULL,
51 .get_child_record_count = NULL,
52 .get_child_record_at_p = NULL,
53 .clone_child_record_list = NULL,
56 static int __ctsvc_speeddial_create(contacts_record_h *out_record)
58 ctsvc_speeddial_s *speeddial;
59 speeddial = calloc(1, sizeof(ctsvc_speeddial_s));
60 RETVM_IF(NULL == speeddial, CONTACTS_ERROR_OUT_OF_MEMORY, "calloc() Fail");
62 *out_record = (contacts_record_h)speeddial;
63 return CONTACTS_ERROR_NONE;
66 static int __ctsvc_speeddial_destroy(contacts_record_h record, bool delete_child)
68 ctsvc_speeddial_s *speeddial = (ctsvc_speeddial_s*)record;
69 speeddial->base.plugin_cbs = NULL; /* help to find double destroy bug (refer to the contacts_record_destroy) */
70 free(speeddial->base.properties_flags);
72 free(speeddial->display_name);
73 free(speeddial->image_thumbnail_path);
74 free(speeddial->label);
75 free(speeddial->number);
78 return CONTACTS_ERROR_NONE;
81 static int __ctsvc_speeddial_clone(contacts_record_h record, contacts_record_h *out_record)
83 ctsvc_speeddial_s *out_data = NULL;
84 ctsvc_speeddial_s *src_data = NULL;
86 src_data = (ctsvc_speeddial_s*)record;
87 out_data = calloc(1, sizeof(ctsvc_speeddial_s));
88 RETVM_IF(NULL == out_data, CONTACTS_ERROR_OUT_OF_MEMORY,
89 "Out of memeory : calloc(ctsvc_speeddial_s) Fail(%d)", CONTACTS_ERROR_OUT_OF_MEMORY);
91 out_data->id = src_data->id;
92 out_data->dial_number = src_data->dial_number;
93 out_data->number_id = src_data->number_id;
94 out_data->person_id = src_data->person_id;
95 out_data->number_type = src_data->number_type;
96 out_data->display_name = SAFE_STRDUP(src_data->display_name);
97 out_data->image_thumbnail_path = SAFE_STRDUP(src_data->image_thumbnail_path);
98 out_data->label = SAFE_STRDUP(src_data->label);
99 out_data->number = SAFE_STRDUP(src_data->number);
101 int ret = ctsvc_record_copy_base(&(out_data->base), &(src_data->base));
102 if (CONTACTS_ERROR_NONE != ret) {
103 ERR("ctsvc_record_copy_base() Fail");
104 __ctsvc_speeddial_destroy((contacts_record_h)out_data, true);
108 *out_record = (contacts_record_h)out_data;
109 return CONTACTS_ERROR_NONE;
112 static int __ctsvc_speeddial_get_int(contacts_record_h record, unsigned int property_id, int *out)
114 ctsvc_speeddial_s *speeddial = (ctsvc_speeddial_s*)record;
116 switch (property_id) {
117 case CTSVC_PROPERTY_SPEEDDIAL_DIAL_NUMBER:
118 *out = speeddial->dial_number;
120 case CTSVC_PROPERTY_SPEEDDIAL_NUMBER_ID:
121 *out = speeddial->number_id;
123 case CTSVC_PROPERTY_SPEEDDIAL_NUMBER_TYPE:
124 *out = speeddial->number_type;
126 case CTSVC_PROPERTY_SPEEDDIAL_PERSON_ID:
127 *out = speeddial->person_id;
130 ERR("This field(%d) is not supported in value(speeddial)", property_id);
131 return CONTACTS_ERROR_INVALID_PARAMETER;
133 return CONTACTS_ERROR_NONE;
136 static int __ctsvc_speeddial_get_str_real(contacts_record_h record, unsigned int property_id, char **out_str, bool copy)
138 ctsvc_speeddial_s *speeddial = (ctsvc_speeddial_s*)record;
140 switch (property_id) {
141 case CTSVC_PROPERTY_SPEEDDIAL_DISPLAY_NAME:
142 *out_str = GET_STR(copy, speeddial->display_name);
144 case CTSVC_PROPERTY_SPEEDDIAL_NUMBER:
145 *out_str = GET_STR(copy, speeddial->number);
147 case CTSVC_PROPERTY_SPEEDDIAL_IMAGE_THUMBNAIL:
148 *out_str = GET_STR(copy, speeddial->image_thumbnail_path);
150 case CTSVC_PROPERTY_SPEEDDIAL_NUMBER_LABEL:
151 *out_str = GET_STR(copy, speeddial->label);
154 ERR("This field(%d) is not supported in value(speeddial)", property_id);
155 return CONTACTS_ERROR_INVALID_PARAMETER;
157 return CONTACTS_ERROR_NONE;
160 static int __ctsvc_speeddial_get_str_p(contacts_record_h record, unsigned int property_id, char **out_str)
162 return __ctsvc_speeddial_get_str_real(record, property_id, out_str, false);
165 static int __ctsvc_speeddial_get_str(contacts_record_h record, unsigned int property_id, char **out_str)
167 return __ctsvc_speeddial_get_str_real(record, property_id, out_str, true);
170 static int __ctsvc_speeddial_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty)
172 ctsvc_speeddial_s *speeddial = (ctsvc_speeddial_s*)record;
174 switch (property_id) {
175 case CTSVC_PROPERTY_SPEEDDIAL_NUMBER_TYPE:
176 CHECK_DIRTY_VAL(speeddial->number_type, value, is_dirty);
177 speeddial->number_type = value;
179 case CTSVC_PROPERTY_SPEEDDIAL_PERSON_ID:
180 CHECK_DIRTY_VAL(speeddial->person_id, value, is_dirty);
181 speeddial->person_id = value;
183 case CTSVC_PROPERTY_SPEEDDIAL_DIAL_NUMBER:
184 RETVM_IF(0 < speeddial->id, CONTACTS_ERROR_INVALID_PARAMETER,
185 "property_id(%d) is a read-only value (speeddial)", property_id);
186 CHECK_DIRTY_VAL(speeddial->dial_number, value, is_dirty);
187 speeddial->dial_number = value;
189 case CTSVC_PROPERTY_SPEEDDIAL_NUMBER_ID:
190 CHECK_DIRTY_VAL(speeddial->number_id, value, is_dirty);
191 speeddial->number_id = value;
194 ERR("This field(%d) is not supported in value(speeddial)", property_id);
195 return CONTACTS_ERROR_INVALID_PARAMETER;
197 return CONTACTS_ERROR_NONE;
200 static int __ctsvc_speeddial_set_str(contacts_record_h record, unsigned int property_id, const char *str, bool *is_dirty)
202 ctsvc_speeddial_s *speeddial = (ctsvc_speeddial_s*)record;
204 switch (property_id) {
205 case CTSVC_PROPERTY_SPEEDDIAL_DISPLAY_NAME:
206 CHECK_DIRTY_STR(speeddial->display_name, str, is_dirty);
207 FREEandSTRDUP(speeddial->display_name, str);
209 case CTSVC_PROPERTY_SPEEDDIAL_NUMBER:
210 CHECK_DIRTY_STR(speeddial->number, str, is_dirty);
211 FREEandSTRDUP(speeddial->number, str);
213 case CTSVC_PROPERTY_SPEEDDIAL_IMAGE_THUMBNAIL:
214 CHECK_DIRTY_STR(speeddial->image_thumbnail_path, str, is_dirty);
215 FREEandSTRDUP(speeddial->image_thumbnail_path, str);
217 case CTSVC_PROPERTY_SPEEDDIAL_NUMBER_LABEL:
218 CHECK_DIRTY_STR(speeddial->label, str, is_dirty);
219 FREEandSTRDUP(speeddial->label, str);
222 ERR("This field(%d) is not supported in value(speeddial)", property_id);
223 return CONTACTS_ERROR_INVALID_PARAMETER;
225 return CONTACTS_ERROR_NONE;