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.
19 #include "ctsvc_internal.h"
20 #include "ctsvc_ipc_marshal.h"
21 #include "contacts_record.h"
24 static int __ctsvc_ipc_unmarshal_search_value(pims_ipc_data_h ipc_data,
25 ctsvc_result_value_s *pvalue)
29 ret = ctsvc_ipc_unmarshal_int(ipc_data, &pvalue->property_id);
30 if (ret != CONTACTS_ERROR_NONE) {
31 ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
32 return CONTACTS_ERROR_INVALID_PARAMETER;
34 ret = ctsvc_ipc_unmarshal_int(ipc_data, &pvalue->type);
35 if (ret != CONTACTS_ERROR_NONE) {
36 ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
37 return CONTACTS_ERROR_INVALID_PARAMETER;
41 if (CTSVC_VIEW_CHECK_DATA_TYPE(pvalue->property_id, CTSVC_VIEW_DATA_TYPE_STR) == true) {
42 if (ctsvc_ipc_unmarshal_string(ipc_data, &pvalue->value.s) != CONTACTS_ERROR_NONE) {
43 ERR("ctsvc_ipc_unmarshal_string() Fail");
44 return CONTACTS_ERROR_INVALID_PARAMETER;
46 } else if (CTSVC_VIEW_CHECK_DATA_TYPE(pvalue->property_id, CTSVC_VIEW_DATA_TYPE_BOOL) == true) {
47 if (ctsvc_ipc_unmarshal_bool(ipc_data, &pvalue->value.b) != CONTACTS_ERROR_NONE) {
48 ERR("ctsvc_ipc_unmarshal_bool() Fail");
49 return CONTACTS_ERROR_INVALID_PARAMETER;
51 } else if (CTSVC_VIEW_CHECK_DATA_TYPE(pvalue->property_id, CTSVC_VIEW_DATA_TYPE_INT) == true) {
52 if (ctsvc_ipc_unmarshal_int(ipc_data, &pvalue->value.i) != CONTACTS_ERROR_NONE) {
53 ERR("ctsvc_ipc_unmarshal_int() Fail");
54 return CONTACTS_ERROR_INVALID_PARAMETER;
56 } else if (CTSVC_VIEW_CHECK_DATA_TYPE(pvalue->property_id, CTSVC_VIEW_DATA_TYPE_DOUBLE) == true) {
57 return CONTACTS_ERROR_NONE;
58 } else if (CTSVC_VIEW_CHECK_DATA_TYPE(pvalue->property_id, CTSVC_VIEW_DATA_TYPE_LLI) == true) {
59 return CONTACTS_ERROR_NONE;
61 ASSERT_NOT_REACHED("invalid parameter (property:%d)", pvalue->property_id);
62 return CONTACTS_ERROR_INVALID_PARAMETER;
64 return CONTACTS_ERROR_NONE;
67 static int __ctsvc_ipc_marshal_search_value(const ctsvc_result_value_s *pvalue,
68 pims_ipc_data_h ipc_data)
70 if (ctsvc_ipc_marshal_int(pvalue->property_id, ipc_data) != CONTACTS_ERROR_NONE) {
71 ERR("ctsvc_ipc_marshal() Fail");
72 return CONTACTS_ERROR_INVALID_PARAMETER;
74 if (ctsvc_ipc_marshal_int(pvalue->type, ipc_data) != CONTACTS_ERROR_NONE) {
75 ERR("ctsvc_ipc_marshal() Fail");
76 return CONTACTS_ERROR_INVALID_PARAMETER;
81 if (CTSVC_VIEW_CHECK_DATA_TYPE(pvalue->property_id, CTSVC_VIEW_DATA_TYPE_STR) == true) {
82 if (ctsvc_ipc_marshal_string(pvalue->value.s, ipc_data) != CONTACTS_ERROR_NONE) {
83 ERR("ctsvc_ipc_marshal() Fail");
84 return CONTACTS_ERROR_INVALID_PARAMETER;
86 } else if (CTSVC_VIEW_CHECK_DATA_TYPE(pvalue->property_id, CTSVC_VIEW_DATA_TYPE_BOOL) == true) {
87 if (ctsvc_ipc_marshal_bool(pvalue->value.b, ipc_data) != CONTACTS_ERROR_NONE) {
88 ERR("ctsvc_ipc_marshal() Fail");
89 return CONTACTS_ERROR_INVALID_PARAMETER;
91 } else if (CTSVC_VIEW_CHECK_DATA_TYPE(pvalue->property_id, CTSVC_VIEW_DATA_TYPE_INT) == true) {
92 if (ctsvc_ipc_marshal_int(pvalue->value.i, ipc_data) != CONTACTS_ERROR_NONE) {
93 ERR("ctsvc_ipc_marshal() Fail");
94 return CONTACTS_ERROR_INVALID_PARAMETER;
96 } else if (CTSVC_VIEW_CHECK_DATA_TYPE(pvalue->property_id, CTSVC_VIEW_DATA_TYPE_DOUBLE) == true) {
97 return CONTACTS_ERROR_NONE;
98 } else if (CTSVC_VIEW_CHECK_DATA_TYPE(pvalue->property_id, CTSVC_VIEW_DATA_TYPE_LLI) == true) {
99 return CONTACTS_ERROR_NONE;
101 ASSERT_NOT_REACHED("invalid parameter (property:%d)", pvalue->property_id);
102 return CONTACTS_ERROR_INVALID_PARAMETER;
104 return CONTACTS_ERROR_NONE;
108 static int __ctsvc_ipc_unmarshal_result(pims_ipc_data_h ipc_data, const char *view_uri,
109 contacts_record_h record)
111 ctsvc_result_s *result_p = (ctsvc_result_s*)record;
113 RETV_IF(NULL == ipc_data, CONTACTS_ERROR_NO_DATA);
114 RETV_IF(NULL == record, CONTACTS_ERROR_NO_DATA);
116 unsigned int count = 0;
117 if (ctsvc_ipc_unmarshal_unsigned_int(ipc_data, &count) != CONTACTS_ERROR_NONE) {
118 ERR("ctsvc_ipc_unmarshal_unsigned_int() fail");
119 return CONTACTS_ERROR_INVALID_PARAMETER;
123 for (i = 0; i < count; i++) {
124 ctsvc_result_value_s *value_data = NULL;
125 value_data = calloc(1, sizeof(ctsvc_result_value_s));
126 if (value_data == NULL)
127 return CONTACTS_ERROR_OUT_OF_MEMORY;
129 if (__ctsvc_ipc_unmarshal_search_value(ipc_data, value_data) != CONTACTS_ERROR_NONE) {
130 ERR("__ctsvc_ipc_unmarshal_search_value() Fail");
132 return CONTACTS_ERROR_INVALID_PARAMETER;
134 result_p->values = g_slist_append(result_p->values, value_data);
137 return CONTACTS_ERROR_NONE;
140 static int __ctsvc_ipc_marshal_result(const contacts_record_h record,
141 pims_ipc_data_h ipc_data)
143 ctsvc_result_s *result_p = (ctsvc_result_s*)record;
145 RETV_IF(NULL == ipc_data, CONTACTS_ERROR_NO_DATA);
146 RETV_IF(result_p == NULL, CONTACTS_ERROR_NO_DATA);
148 if (result_p->values) {
149 unsigned int count = g_slist_length(result_p->values);
150 if (ctsvc_ipc_marshal_unsigned_int(count, ipc_data) != CONTACTS_ERROR_NONE) {
151 ERR("ctsvc_ipc_marshal() Fail");
152 return CONTACTS_ERROR_INVALID_PARAMETER;
155 GSList *cursor = result_p->values;
157 ctsvc_result_value_s *value_data = cursor->data;
158 if (value_data == NULL) {
159 cursor = g_slist_next(cursor);
162 if (__ctsvc_ipc_marshal_search_value(value_data, ipc_data) != CONTACTS_ERROR_NONE) {
163 ERR("ctsvc_ipc_marshal() Fail");
164 return CONTACTS_ERROR_INVALID_PARAMETER;
166 cursor = g_slist_next(cursor);
169 if (ctsvc_ipc_marshal_int(0, ipc_data) != CONTACTS_ERROR_NONE) {
170 ERR("ctsvc_ipc_marshal() Fail");
171 return CONTACTS_ERROR_INVALID_PARAMETER;
175 return CONTACTS_ERROR_NONE;
178 ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_result_plugin_cb = {
179 .unmarshal_record = __ctsvc_ipc_unmarshal_result,
180 .marshal_record = __ctsvc_ipc_marshal_result