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.
21 #include "ctsvc_internal.h"
22 #include "ctsvc_record.h"
23 #include "ctsvc_view.h"
25 static int __ctsvc_sdn_create(contacts_record_h *out_record);
26 static int __ctsvc_sdn_destroy(contacts_record_h record, bool delete_child);
27 static int __ctsvc_sdn_clone(contacts_record_h record, contacts_record_h *out_record);
28 static int __ctsvc_sdn_get_int(contacts_record_h record, unsigned int property_id, int *out);
29 static int __ctsvc_sdn_get_str(contacts_record_h record, unsigned int property_id, char **out_str);
30 static int __ctsvc_sdn_get_str_p(contacts_record_h record, unsigned int property_id, char **out_str);
31 static int __ctsvc_sdn_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty);
32 static int __ctsvc_sdn_set_str(contacts_record_h record, unsigned int property_id, const char *str, bool *is_dirty);
34 ctsvc_record_plugin_cb_s sdn_plugin_cbs = {
35 .create = __ctsvc_sdn_create,
36 .destroy = __ctsvc_sdn_destroy,
37 .clone = __ctsvc_sdn_clone,
38 .get_str = __ctsvc_sdn_get_str,
39 .get_str_p = __ctsvc_sdn_get_str_p,
40 .get_int = __ctsvc_sdn_get_int,
44 .set_str = __ctsvc_sdn_set_str,
45 .set_int = __ctsvc_sdn_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_sdn_create(contacts_record_h *out_record)
59 sdn = calloc(1, sizeof(ctsvc_sdn_s));
60 RETVM_IF(NULL == sdn, CONTACTS_ERROR_OUT_OF_MEMORY, "calloc() Fail");
62 *out_record = (contacts_record_h)sdn;
63 return CONTACTS_ERROR_NONE;
66 static int __ctsvc_sdn_destroy(contacts_record_h record, bool delete_child)
68 ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
69 sdn->base.plugin_cbs = NULL; /* help to find double destroy bug (refer to the contacts_record_destroy) */
70 free(sdn->base.properties_flags);
76 return CONTACTS_ERROR_NONE;
79 static int __ctsvc_sdn_clone(contacts_record_h record, contacts_record_h *out_record)
81 ctsvc_sdn_s *out_data = NULL;
82 ctsvc_sdn_s *src_data = NULL;
84 src_data = (ctsvc_sdn_s*)record;
85 out_data = calloc(1, sizeof(ctsvc_sdn_s));
86 RETVM_IF(NULL == out_data, CONTACTS_ERROR_OUT_OF_MEMORY,
87 "Out of memeory : calloc(ctsvc_sdn_s) Fail(%d)", CONTACTS_ERROR_OUT_OF_MEMORY);
89 out_data->id = src_data->id;
90 out_data->name = SAFE_STRDUP(src_data->name);
91 out_data->number = SAFE_STRDUP(src_data->number);
92 out_data->sim_slot_no = src_data->sim_slot_no;
94 int ret = ctsvc_record_copy_base(&(out_data->base), &(src_data->base));
95 if (CONTACTS_ERROR_NONE != ret) {
96 ERR("ctsvc_record_copy_base() Fail");
97 __ctsvc_sdn_destroy((contacts_record_h)out_data, true);
101 *out_record = (contacts_record_h)out_data;
102 return CONTACTS_ERROR_NONE;
105 static int __ctsvc_sdn_get_int(contacts_record_h record, unsigned int property_id, int *out)
107 ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
109 switch (property_id) {
110 case CTSVC_PROPERTY_SDN_ID:
113 case CTSVC_PROPERTY_SDN_SIM_SLOT_NO:
114 *out = sdn->sim_slot_no;
117 ERR("This field(%d) is not supported in value(sdn)", property_id);
118 return CONTACTS_ERROR_INVALID_PARAMETER;
120 return CONTACTS_ERROR_NONE;
123 static int __ctsvc_sdn_get_str_real(contacts_record_h record, unsigned int property_id, char **out_str, bool copy)
125 ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
127 switch (property_id) {
128 case CTSVC_PROPERTY_SDN_NAME:
129 *out_str = GET_STR(copy, sdn->name);
131 case CTSVC_PROPERTY_SDN_NUMBER:
132 *out_str = GET_STR(copy, sdn->number);
135 ERR("This field(%d) is not supported in value(sdn)", property_id);
136 return CONTACTS_ERROR_INVALID_PARAMETER;
138 return CONTACTS_ERROR_NONE;
141 static int __ctsvc_sdn_get_str_p(contacts_record_h record, unsigned int property_id, char **out_str)
143 return __ctsvc_sdn_get_str_real(record, property_id, out_str, false);
146 static int __ctsvc_sdn_get_str(contacts_record_h record, unsigned int property_id, char **out_str)
148 return __ctsvc_sdn_get_str_real(record, property_id, out_str, true);
151 static int __ctsvc_sdn_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty)
153 ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
155 switch (property_id) {
156 case CTSVC_PROPERTY_SDN_ID:
157 CHECK_DIRTY_VAL(sdn->id, value, is_dirty);
160 case CTSVC_PROPERTY_SDN_SIM_SLOT_NO:
161 CHECK_DIRTY_VAL(sdn->sim_slot_no, value, is_dirty);
162 sdn->sim_slot_no = value;
165 ERR("This field(%d) is not supported in value(sdn)", property_id);
166 return CONTACTS_ERROR_INVALID_PARAMETER;
168 return CONTACTS_ERROR_NONE;
171 static int __ctsvc_sdn_set_str(contacts_record_h record, unsigned int property_id, const char *str, bool *is_dirty)
173 ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
175 switch (property_id) {
176 case CTSVC_PROPERTY_SDN_NAME:
177 CHECK_DIRTY_STR(sdn->name, str, is_dirty);
178 FREEandSTRDUP(sdn->name, str);
180 case CTSVC_PROPERTY_SDN_NUMBER:
181 CHECK_DIRTY_STR(sdn->number, str, is_dirty);
182 FREEandSTRDUP(sdn->number, str);
185 ERR("This field(%d) is not supported in value(sdn)", property_id);
186 return CONTACTS_ERROR_INVALID_PARAMETER;
188 return CONTACTS_ERROR_NONE;