Removing gesture API
[platform/core/messaging/msg-service.git] / framework / transaction-manager / MsgCmdHandlerFilter.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15 */
16
17 #include "MsgDebug.h"
18 #include "MsgUtilFunction.h"
19 #include "MsgCppTypes.h"
20 #include "MsgSpamFilter.h"
21 #include "MsgStorageHandler.h"
22 #include "MsgCmdHandler.h"
23
24
25 /*==================================================================================================
26                                      FUNCTION IMPLEMENTATION
27 ==================================================================================================*/
28 int MsgAddFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
29 {
30         msg_error_t err = MSG_SUCCESS;
31
32         if (!pCmd || !ppEvent) {
33                 MSG_DEBUG("pCmd or ppEvent is null");
34                 return 0;
35         }
36
37         int eventSize = 0;
38
39         /* Get Filter Structure */
40         MSG_FILTER_S* pFilter = (MSG_FILTER_S*)pCmd->cmdData;
41
42         /* Add Filter */
43         err = MsgStoAddFilter(pFilter);
44
45         if (err == MSG_SUCCESS) {
46                 MSG_DEBUG("Command Handle Success : MsgStoAddFilter()");
47         } else {
48                 MSG_DEBUG("Command Handle Fail : MsgStoAddFilter()");
49         }
50
51         /* Make Event Data */
52         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_FILTER, err, (void**)ppEvent);
53
54         return eventSize;
55 }
56
57
58 int MsgUpdateFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
59 {
60         msg_error_t err = MSG_SUCCESS;
61
62         if (!pCmd || !ppEvent) {
63                 MSG_DEBUG("pCmd or ppEvent is null");
64                 return 0;
65         }
66
67         int eventSize = 0;
68
69         /* Get Filter Structure */
70         MSG_FILTER_S* pFilter = (MSG_FILTER_S*)pCmd->cmdData;
71
72         /* Update Filter */
73         err = MsgStoUpdateFilter(pFilter);
74
75         if (err == MSG_SUCCESS) {
76                 MSG_DEBUG("Command Handle Success : MsgStoUpdateFilter()");
77         } else {
78                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateFilter()");
79         }
80
81         /* Make Event Data */
82         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_FILTER, err, (void**)ppEvent);
83
84         return eventSize;
85 }
86
87
88 int MsgDeleteFilterHandler(const MSG_CMD_S *pCmd, char **ppEvent)
89 {
90         msg_error_t err = MSG_SUCCESS;
91
92         if (!pCmd || !ppEvent) {
93                 MSG_DEBUG("pCmd or ppEvent is null");
94                 return 0;
95         }
96
97         int eventSize = 0;
98
99         /* Get Filter Structure */
100         msg_filter_id_t  *pFilterId = (msg_filter_id_t *)pCmd->cmdData;
101
102         MSG_DEBUG("Delete Filter id : %d", *pFilterId);
103
104         /* Delete Filter */
105         err = MsgStoDeleteFilter(*pFilterId);
106
107         if (err == MSG_SUCCESS) {
108                 MSG_DEBUG("Command Handle Success : MsgStoDeleteFilter()");
109         } else {
110                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteFilter()");
111         }
112
113         /* Make Event Data */
114         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_FILTER, err, (void**)ppEvent);
115
116         return eventSize;
117 }
118
119
120 int MsgSetFilterActivationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
121 {
122         msg_error_t err = MSG_SUCCESS;
123
124         if (!pCmd || !ppEvent) {
125                 MSG_DEBUG("pCmd or ppEvent is null");
126                 return 0;
127         }
128
129         int eventSize = 0;
130
131         /* Get Filter Structure */
132         msg_filter_id_t  *pFilterId = (msg_filter_id_t *)pCmd->cmdData;
133
134         bool setFlag = false;
135
136         memcpy(&setFlag, pCmd->cmdData+sizeof(msg_filter_id_t), sizeof(bool));
137
138         MSG_DEBUG("Filter id : %d", *pFilterId);
139
140         /* Delete Filter */
141         err = MsgStoSetFilterActivation(*pFilterId, setFlag);
142
143         if (err == MSG_SUCCESS) {
144                 MSG_DEBUG("Command Handle Success : MsgStoSetFilterActivation()");
145         } else {
146                 MSG_DEBUG("Command Handle Fail : MsgStoSetFilterActivation()");
147         }
148
149         /* Make Event Data */
150         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SET_FILTER_ACTIVATION, err, (void**)ppEvent);
151
152         return eventSize;
153 }
154
155
156 int MsgGetFilterListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
157 {
158         msg_error_t err = MSG_SUCCESS;
159
160         if (!pCmd || !ppEvent) {
161                 MSG_DEBUG("pCmd or ppEvent is null");
162                 return 0;
163         }
164
165         char* encodedData = NULL;
166         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
167
168         int dataSize = 0, eventSize = 0;
169
170         /* Get Filter List */
171         msg_struct_list_s filterList;
172
173         err = MsgStoGetFilterList(&filterList);
174
175         if (err == MSG_SUCCESS) {
176                 MSG_DEBUG("Command Handle Success : MsgStoGetFilterList()");
177
178                 /* Encoding Filter List Data */
179                 dataSize = MsgEncodeFilterList(&filterList, &encodedData);
180
181                 if (filterList.msg_struct_info) {
182                         msg_struct_s *msg_struct;
183                         for (int i = 0; i < filterList.nCount; i++) {
184                                 msg_struct = (msg_struct_s *)filterList.msg_struct_info[i];
185                                 if (msg_struct) {
186                                         delete (MSG_FILTER_S *)msg_struct->data;
187                                         delete msg_struct;
188                                 }
189                         }
190                         g_free(filterList.msg_struct_info);
191                 }
192         } else {
193                 MSG_DEBUG("Command Handle Fail : MsgStoGetFilterList()");
194         }
195
196         /* Make Event Data */
197         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FILTERLIST, err, (void**)ppEvent);
198
199         return eventSize;
200 }
201
202
203 int MsgSetFilterOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
204 {
205         msg_error_t err = MSG_SUCCESS;
206
207         if (!pCmd || !ppEvent) {
208                 MSG_DEBUG("pCmd or ppEvent is null");
209                 return 0;
210         }
211
212         int eventSize = 0;
213
214         /* Get Filter Flag */
215         bool setFlag = false;
216
217         memcpy(&setFlag, pCmd->cmdData, sizeof(bool));
218
219         /* Add Filter */
220         err = MsgSetFilterOperation(setFlag);
221
222         if (err == MSG_SUCCESS) {
223                 MSG_DEBUG("Command Handle Success : MsgSetFilterOperation()");
224         } else {
225                 MSG_DEBUG("Command Handle Fail : MsgSetFilterOperation()");
226         }
227
228         /* Make Event Data */
229         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SET_FILTER_OPERATION, err, (void**)ppEvent);
230
231         return eventSize;
232 }
233
234
235 int MsgGetFilterOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
236 {
237         msg_error_t err = MSG_SUCCESS;
238
239         if (!pCmd || !ppEvent) {
240                 MSG_DEBUG("pCmd or ppEvent is null");
241                 return 0;
242         }
243
244         char* encodedData = NULL;
245         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
246
247         int dataSize = 0, eventSize = 0;
248
249         /* Get Filter List */
250         bool setFlag = false;
251
252         err = MsgGetFilterOperation(&setFlag);
253
254         if (err == MSG_SUCCESS) {
255                 MSG_DEBUG("Command Handle Success : MsgGetFilterOperation()");
256
257                 /* Encoding Filter List Data */
258                 dataSize = MsgEncodeFilterFlag(&setFlag, &encodedData);
259         } else {
260                 MSG_DEBUG("Command Handle Fail : MsgFilterGetFilterList()");
261         }
262
263         /* Make Event Data */
264         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FILTER_OPERATION, err, (void**)ppEvent);
265
266         return eventSize;
267 }