2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "MsgException.h"
21 #include "MsgHandle.h"
22 #include "msg_private.h"
25 /*==================================================================================================
26 FUNCTION IMPLEMENTATION
27 ==================================================================================================*/
28 EXPORT_API int msg_add_filter(msg_handle_t handle, const msg_struct_t msg_struct_handle)
30 CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
31 msg_error_t err = MSG_SUCCESS;
33 if (handle == NULL || msg_struct_handle == NULL)
34 return MSG_ERR_INVALID_PARAMETER;
36 msg_struct_s *msg_struct = (msg_struct_s *) msg_struct_handle;
37 MSG_TYPE_CHECK(msg_struct->type, MSG_STRUCT_FILTER);
39 MsgHandle* pHandle = (MsgHandle*)handle;
42 err = pHandle->addFilter((const MSG_FILTER_S *)msg_struct->data);
43 } catch (MsgException& e) {
44 MSG_FATAL("%s", e.what());
45 return MSG_ERR_FILTER_ERROR;
52 EXPORT_API int msg_update_filter(msg_handle_t handle, const msg_struct_t msg_struct_handle)
54 CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
55 msg_error_t err = MSG_SUCCESS;
57 if (handle == NULL || msg_struct_handle == NULL)
58 return MSG_ERR_INVALID_PARAMETER;
60 msg_struct_s *msg_struct = (msg_struct_s *) msg_struct_handle;
61 MSG_TYPE_CHECK(msg_struct->type, MSG_STRUCT_FILTER);
63 MsgHandle* pHandle = (MsgHandle*)handle;
66 err = pHandle->updateFilter((const MSG_FILTER_S *)msg_struct->data);
67 } catch (MsgException& e) {
68 MSG_FATAL("%s", e.what());
69 return MSG_ERR_FILTER_ERROR;
76 EXPORT_API int msg_delete_filter(msg_handle_t handle, msg_filter_id_t filter_id)
78 CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
79 msg_error_t err = MSG_SUCCESS;
82 return MSG_ERR_INVALID_PARAMETER;
84 MsgHandle* pHandle = (MsgHandle*)handle;
87 err = pHandle->deleteFilter(filter_id);
88 } catch (MsgException& e) {
89 MSG_FATAL("%s", e.what());
90 return MSG_ERR_FILTER_ERROR;
97 EXPORT_API int msg_get_filter_list(msg_handle_t handle, msg_struct_list_s *filter_list)
99 CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
100 msg_error_t err = MSG_SUCCESS;
102 if (handle == NULL || filter_list == NULL)
103 return MSG_ERR_INVALID_PARAMETER;
105 MsgHandle* pHandle = (MsgHandle*)handle;
108 err = pHandle->getFilterList(filter_list);
109 } catch (MsgException& e) {
110 MSG_FATAL("%s", e.what());
111 return MSG_ERR_FILTER_ERROR;
118 EXPORT_API int msg_set_filter_operation(msg_handle_t handle, bool set_flag)
120 CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
121 msg_error_t err = MSG_SUCCESS;
124 return MSG_ERR_INVALID_PARAMETER;
126 MsgHandle* pHandle = (MsgHandle*)handle;
129 err = pHandle->setFilterOperation(set_flag);
130 } catch (MsgException& e) {
131 MSG_FATAL("%s", e.what());
132 return MSG_ERR_FILTER_ERROR;
139 EXPORT_API int msg_get_filter_operation(msg_handle_t handle, bool *set_flag)
141 CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
142 msg_error_t err = MSG_SUCCESS;
144 if (handle == NULL || set_flag == NULL)
145 return MSG_ERR_INVALID_PARAMETER;
147 MsgHandle* pHandle = (MsgHandle*)handle;
150 err = pHandle->getFilterOperation(set_flag);
151 } catch (MsgException& e) {
152 MSG_FATAL("%s", e.what());
153 return MSG_ERR_FILTER_ERROR;
160 EXPORT_API int msg_set_filter_active(msg_handle_t handle, msg_filter_id_t filter_id, bool active)
162 CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
163 msg_error_t err = MSG_SUCCESS;
166 return MSG_ERR_INVALID_PARAMETER;
168 MsgHandle* pHandle = (MsgHandle*)handle;
171 err = pHandle->setFilterActivation(filter_id, active);
172 } catch (MsgException& e) {
173 MSG_FATAL("%s", e.what());
174 return MSG_ERR_FILTER_ERROR;
181 int msg_get_filter_info_bool(void *filter, int field, bool *value)
184 return MSG_ERR_NULL_POINTER;
186 int ret = MSG_SUCCESS;
188 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
191 case MSG_FILTER_ACTIVE_BOOL:
192 *value = filter_data->bActive;
195 ret = MSG_ERR_INVALID_PARAMETER;
203 int msg_get_filter_info_int(void *filter, int field, int *value)
206 return MSG_ERR_NULL_POINTER;
208 int ret = MSG_SUCCESS;
210 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
213 case MSG_FILTER_ID_INT:
214 *value = filter_data->filterId;
216 case MSG_FILTER_TYPE_INT:
217 *value = filter_data->filterType;
220 ret = MSG_ERR_INVALID_PARAMETER;
228 int msg_get_filter_info_str(void *filter, int field, char *value, int size)
231 return MSG_ERR_NULL_POINTER;
233 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
236 case MSG_FILTER_VALUE_STR:
237 strncpy(value, filter_data->filterValue, size);
240 return MSG_ERR_INVALID_PARAMETER;
246 int msg_set_filter_info_bool(void *filter, int field, bool value)
249 return MSG_ERR_NULL_POINTER;
251 msg_error_t err = MSG_SUCCESS;
252 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
255 case MSG_FILTER_ACTIVE_BOOL:
256 filter_data->bActive = value;
259 return MSG_ERR_INVALID_PARAMETER;
265 int msg_set_filter_info_int(void *filter, int field, int value)
268 return MSG_ERR_NULL_POINTER;
270 msg_error_t err = MSG_SUCCESS;
271 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
274 case MSG_FILTER_ID_INT:
275 filter_data->filterId = value;
277 case MSG_FILTER_TYPE_INT:
278 filter_data->filterType = value;
281 return MSG_ERR_INVALID_PARAMETER;
287 int msg_set_filter_info_str(void *filter, int field, const char *value, int size)
289 if (!filter || !value)
290 return MSG_ERR_NULL_POINTER;
292 msg_error_t err = MSG_SUCCESS;
293 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
296 case MSG_FILTER_VALUE_STR: {
297 int len = (size > MAX_FILTER_VALUE_LEN)?MAX_FILTER_VALUE_LEN:size;
298 strncpy(filter_data->filterValue, value, len);
302 return MSG_ERR_INVALID_PARAMETER;