2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.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.
18 #include "MsgUtilFunction.h"
19 #include "MsgCppTypes.h"
20 #include "MsgSpamFilter.h"
21 #include "MsgStorageHandler.h"
22 #include "MsgCmdHandler.h"
25 /*==================================================================================================
26 FUNCTION IMPLEMENTATION
27 ==================================================================================================*/
28 int MsgAddFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
30 msg_error_t err = MSG_SUCCESS;
34 // Get Filter Structure
35 MSG_FILTER_S* pFilter = (MSG_FILTER_S*)pCmd->cmdData;
38 err = MsgStoAddFilter(pFilter);
40 if (err == MSG_SUCCESS)
42 MSG_DEBUG("Command Handle Success : MsgStoAddFilter()");
46 MSG_DEBUG("Command Handle Fail : MsgStoAddFilter()");
50 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_FILTER, err, (void**)ppEvent);
56 int MsgUpdateFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
58 msg_error_t err = MSG_SUCCESS;
62 // Get Filter Structure
63 MSG_FILTER_S* pFilter = (MSG_FILTER_S*)pCmd->cmdData;
66 err = MsgStoUpdateFilter(pFilter);
68 if (err == MSG_SUCCESS)
70 MSG_DEBUG("Command Handle Success : MsgStoUpdateFilter()");
74 MSG_DEBUG("Command Handle Fail : MsgStoUpdateFilter()");
78 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_FILTER, err, (void**)ppEvent);
84 int MsgDeleteFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
86 msg_error_t err = MSG_SUCCESS;
90 // Get Filter Structure
91 msg_filter_id_t *pFilterId = (msg_filter_id_t *)pCmd->cmdData;
93 MSG_DEBUG("Delete Filter id : %d", *pFilterId);
96 err = MsgStoDeleteFilter(*pFilterId);
98 if (err == MSG_SUCCESS)
100 MSG_DEBUG("Command Handle Success : MsgStoDeleteFilter()");
104 MSG_DEBUG("Command Handle Fail : MsgStoDeleteFilter()");
108 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_FILTER, err, (void**)ppEvent);
114 int MsgSetFilterActivationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
116 msg_error_t err = MSG_SUCCESS;
120 // Get Filter Structure
121 msg_filter_id_t *pFilterId = (msg_filter_id_t *)pCmd->cmdData;
123 bool setFlag = false;
125 memcpy(&setFlag, pCmd->cmdData+sizeof(msg_filter_id_t), sizeof(bool));
127 MSG_DEBUG("Filter id : %d", *pFilterId);
130 err = MsgStoSetFilterActivation(*pFilterId, setFlag);
132 if (err == MSG_SUCCESS)
134 MSG_DEBUG("Command Handle Success : MsgStoSetFilterActivation()");
138 MSG_DEBUG("Command Handle Fail : MsgStoSetFilterActivation()");
142 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SET_FILTER_ACTIVATION, err, (void**)ppEvent);
148 int MsgGetFilterListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
150 msg_error_t err = MSG_SUCCESS;
152 char* encodedData = NULL;
153 AutoPtr<char> buf(&encodedData);
155 int dataSize = 0, eventSize = 0;
158 msg_struct_list_s filterList;
160 err = MsgStoGetFilterList(&filterList);
162 if (err == MSG_SUCCESS)
164 MSG_DEBUG("Command Handle Success : MsgStoGetFilterList()");
166 // Encoding Filter List Data
167 dataSize = MsgEncodeFilterList(&filterList, &encodedData);
169 delete [] filterList.msg_struct_info;
173 MSG_DEBUG("Command Handle Fail : MsgStoGetFilterList()");
177 eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FILTERLIST, err, (void**)ppEvent);
183 int MsgSetFilterOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
185 msg_error_t err = MSG_SUCCESS;
190 bool setFlag = false;
192 memcpy(&setFlag, pCmd->cmdData, sizeof(bool));
195 err = MsgSetFilterOperation(setFlag);
197 if (err == MSG_SUCCESS)
199 MSG_DEBUG("Command Handle Success : MsgSetFilterOperation()");
203 MSG_DEBUG("Command Handle Fail : MsgSetFilterOperation()");
207 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SET_FILTER_OPERATION, err, (void**)ppEvent);
213 int MsgGetFilterOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
215 msg_error_t err = MSG_SUCCESS;
217 char* encodedData = NULL;
218 AutoPtr<char> buf(&encodedData);
220 int dataSize = 0, eventSize = 0;
223 bool setFlag = false;
225 err = MsgGetFilterOperation(&setFlag);
227 if (err == MSG_SUCCESS)
229 MSG_DEBUG("Command Handle Success : MsgGetFilterOperation()");
231 // Encoding Filter List Data
232 dataSize = MsgEncodeFilterFlag(&setFlag, &encodedData);
236 MSG_DEBUG("Command Handle Fail : MsgFilterGetFilterList()");
240 eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FILTER_OPERATION, err, (void**)ppEvent);