2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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"
24 /*==================================================================================================
25 FUNCTION IMPLEMENTATION
26 ==================================================================================================*/
27 EXPORT_API int msg_add_filter(msg_handle_t handle, const msg_struct_t msg_struct_handle)
29 msg_error_t err = MSG_SUCCESS;
31 // TODO : check NULL in msg_struct_handle
32 msg_struct_s *msg_struct = (msg_struct_s *) msg_struct_handle;
34 if (handle == NULL || msg_struct == NULL)
39 if(msg_struct->type != MSG_STRUCT_FILTER)
44 MsgHandle* pHandle = (MsgHandle*)handle;
48 err = pHandle->addFilter((const MSG_FILTER_S *)msg_struct->data);
50 catch (MsgException& e)
52 MSG_FATAL("%s", e.what());
53 return MSG_ERR_FILTER_ERROR;
60 EXPORT_API int msg_update_filter(msg_handle_t handle, const msg_struct_t msg_struct_handle)
62 msg_error_t err = MSG_SUCCESS;
64 // TODO : check NULL in msg_struct_handle
65 msg_struct_s *msg_struct = (msg_struct_s *) msg_struct_handle;
67 if (handle == NULL || msg_struct == NULL)
73 if(msg_struct->type != MSG_STRUCT_FILTER)
78 MsgHandle* pHandle = (MsgHandle*)handle;
82 err = pHandle->updateFilter((const MSG_FILTER_S *)msg_struct->data);
84 catch (MsgException& e)
86 MSG_FATAL("%s", e.what());
87 return MSG_ERR_FILTER_ERROR;
94 EXPORT_API int msg_delete_filter(msg_handle_t handle, msg_filter_id_t filter_id)
96 msg_error_t err = MSG_SUCCESS;
103 MsgHandle* pHandle = (MsgHandle*)handle;
107 err = pHandle->deleteFilter(filter_id);
109 catch (MsgException& e)
111 MSG_FATAL("%s", e.what());
112 return MSG_ERR_FILTER_ERROR;
119 EXPORT_API int msg_get_filter_list(msg_handle_t handle, msg_struct_list_s *filter_list)
121 msg_error_t err = MSG_SUCCESS;
123 if (handle == NULL || filter_list == NULL)
128 MsgHandle* pHandle = (MsgHandle*)handle;
132 err = pHandle->getFilterList(filter_list);
134 catch (MsgException& e)
136 MSG_FATAL("%s", e.what());
137 return MSG_ERR_FILTER_ERROR;
144 EXPORT_API int msg_set_filter_operation(msg_handle_t handle, bool set_flag)
146 msg_error_t err = MSG_SUCCESS;
153 MsgHandle* pHandle = (MsgHandle*)handle;
157 err = pHandle->setFilterOperation(set_flag);
159 catch (MsgException& e)
161 MSG_FATAL("%s", e.what());
162 return MSG_ERR_FILTER_ERROR;
169 EXPORT_API int msg_get_filter_operation(msg_handle_t handle, bool *set_flag)
171 msg_error_t err = MSG_SUCCESS;
178 MsgHandle* pHandle = (MsgHandle*)handle;
182 err = pHandle->getFilterOperation(set_flag);
184 catch (MsgException& e)
186 MSG_FATAL("%s", e.what());
187 return MSG_ERR_FILTER_ERROR;
194 EXPORT_API int msg_set_filter_active(msg_handle_t handle, msg_filter_id_t filter_id, bool active)
196 msg_error_t err = MSG_SUCCESS;
203 MsgHandle* pHandle = (MsgHandle*)handle;
207 err = pHandle->setFilterActivation(filter_id, active);
209 catch (MsgException& e)
211 MSG_FATAL("%s", e.what());
212 return MSG_ERR_FILTER_ERROR;
219 bool msg_get_filter_info_bool(void *filter, int field)
222 return MSG_ERR_NULL_POINTER;
226 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
230 case MSG_FILTER_ACTIVE_BOOL :
231 ret = filter_data->bActive;
234 return MSG_ERR_INVALID_PARAMETER;
241 int msg_get_filter_info_int(void *filter, int field)
244 return MSG_ERR_NULL_POINTER;
248 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
252 case MSG_FILTER_ID_INT :
253 ret = filter_data->filterId;
255 case MSG_FILTER_TYPE_INT :
256 ret = filter_data->filterType;
259 return MSG_ERR_INVALID_PARAMETER;
266 char *msg_get_filter_info_str(void *filter, int field)
271 char *ret_str = NULL;
273 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
277 case MSG_FILTER_VALUE_STR :
278 ret_str = filter_data->filterValue;
287 int msg_set_filter_info_bool(void *filter, int field, bool value)
290 return MSG_ERR_NULL_POINTER;
292 msg_error_t err = MSG_SUCCESS;
293 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
297 case MSG_FILTER_ACTIVE_BOOL :
298 filter_data->bActive = value;
301 return MSG_ERR_INVALID_PARAMETER;
307 int msg_set_filter_info_int(void *filter, int field, int value)
310 return MSG_ERR_NULL_POINTER;
312 msg_error_t err = MSG_SUCCESS;
313 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
317 case MSG_FILTER_ID_INT :
318 filter_data->filterId = value;
320 case MSG_FILTER_TYPE_INT :
321 filter_data->filterType = value;
324 return MSG_ERR_INVALID_PARAMETER;
330 int msg_set_filter_info_str(void *filter, int field, char *value, int size)
332 if (!filter || !value)
333 return MSG_ERR_NULL_POINTER;
335 msg_error_t err = MSG_SUCCESS;
336 MSG_FILTER_S *filter_data = (MSG_FILTER_S *)filter;
340 case MSG_FILTER_VALUE_STR :
342 int len = (size > MAX_FILTER_VALUE_LEN)?MAX_FILTER_VALUE_LEN:size;
343 strncpy(filter_data->filterValue, value, len);
347 return MSG_ERR_INVALID_PARAMETER;