Modify flora license version.
[platform/core/messaging/msg-service.git] / proxy / MsgHandleFilter.cpp
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
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
7 *
8 *    http://floralicense.org/license/
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 "MsgHandle.h"
19 #include "MsgUtilFunction.h"
20 #include "MsgCppTypes.h"
21 #include "MsgException.h"
22
23
24 /*==================================================================================================
25                                      IMPLEMENTATION OF MsgHandle - Filter Member Functions
26 ==================================================================================================*/
27 msg_error_t MsgHandle::addFilter(const MSG_FILTER_S *pFilter)
28 {
29         // Allocate Memory to Command Data
30         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FILTER_S);
31
32         char cmdBuf[cmdSize];
33         bzero(cmdBuf, cmdSize);
34         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
35
36         // Set Command Parameters
37         pCmd->cmdType = MSG_CMD_ADD_FILTER;
38
39         // Copy Cookie
40         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
41
42         // Copy Command Data
43         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFilter, sizeof(MSG_FILTER_S));
44
45         // Send Command to Messaging FW
46         char* pEventData = NULL;
47         AutoPtr<char> eventBuf(&pEventData);
48
49         write((char*)pCmd, cmdSize, &pEventData);
50
51         // Get Return Data
52         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
53
54         if (pEvent->eventType != MSG_EVENT_ADD_FILTER)
55         {
56                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
57         }
58
59         return pEvent->result;
60 }
61
62
63 msg_error_t MsgHandle::updateFilter(const MSG_FILTER_S *pFilter)
64 {
65         // Allocate Memory to Command Data
66         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FILTER_S);
67
68         char cmdBuf[cmdSize];
69         bzero(cmdBuf, cmdSize);
70         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
71
72         // Set Command Parameters
73         pCmd->cmdType = MSG_CMD_UPDATE_FILTER;
74
75         // Copy Cookie
76         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
77
78         // Copy Command Data
79         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFilter, sizeof(MSG_FILTER_S));
80
81         // Send Command to Messaging FW
82         char* pEventData = NULL;
83         AutoPtr<char> eventBuf(&pEventData);
84
85         write((char*)pCmd, cmdSize, &pEventData);
86
87         // Get Return Data
88         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
89
90         if (pEvent->eventType != MSG_EVENT_UPDATE_FILTER)
91         {
92                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
93         }
94
95         return pEvent->result;
96 }
97
98
99 msg_error_t MsgHandle::deleteFilter(msg_filter_id_t FilterId)
100 {
101         // Allocate Memory to Command Data
102         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_filter_id_t);
103
104         char cmdBuf[cmdSize];
105         bzero(cmdBuf, cmdSize);
106         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
107
108         // Set Command Parameters
109         pCmd->cmdType = MSG_CMD_DELETE_FILTER;
110
111         // Copy Cookie
112         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
113
114         // Copy Command Data
115         memcpy(pCmd->cmdData, &FilterId, sizeof(msg_filter_id_t));
116
117         // Send Command to Messaging FW
118         char* pEventData = NULL;
119         AutoPtr<char> eventBuf(&pEventData);
120
121         write((char*)pCmd, cmdSize, &pEventData);
122
123         // Get Return Data
124         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
125
126         if (pEvent->eventType != MSG_EVENT_DELETE_FILTER)
127         {
128                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
129         }
130
131         return pEvent->result;
132 }
133
134
135 msg_error_t MsgHandle::getFilterList(msg_struct_list_s *pFilterList)
136 {
137         // Allocate Memory to Command Data
138         int cmdSize = sizeof(MSG_CMD_S);
139
140         char cmdBuf[cmdSize];
141         bzero(cmdBuf, cmdSize);
142         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
143
144         // Set Command Parameters
145         pCmd->cmdType = MSG_CMD_GET_FILTERLIST;
146
147         // Copy Cookie
148         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
149
150         // Send Command to Messaging FW
151         char* pEventData = NULL;
152         AutoPtr<char> eventBuf(&pEventData);
153
154         write((char*)pCmd, cmdSize, &pEventData);
155
156         // Get Return Data
157         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
158
159         if (pEvent->eventType != MSG_EVENT_GET_FILTERLIST)
160         {
161                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
162         }
163
164         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
165
166         // Decode Return Data
167         MsgDecodeFilterList(pEvent->data, pFilterList);
168
169         return MSG_SUCCESS;
170 }
171
172
173 msg_error_t MsgHandle::setFilterOperation(bool bSetFlag)
174 {
175         msg_error_t ret = MSG_SUCCESS;
176
177         // Allocate Memory to Command Data
178         int cmdSize = sizeof(MSG_CMD_S) + sizeof(bool);
179
180         char cmdBuf[cmdSize];
181         bzero(cmdBuf, cmdSize);
182         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
183
184         // Set Command Parameters
185         pCmd->cmdType = MSG_CMD_SET_FILTER_OPERATION;
186
187         // Copy Cookie
188         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
189
190         // Copy Command Data
191         memcpy(pCmd->cmdData, &bSetFlag, sizeof(bool));
192
193         // Send Command to Messaging FW
194         char* pEventData = NULL;
195         AutoPtr<char> eventBuf(&pEventData);
196
197         write((char*)pCmd, cmdSize, &pEventData);
198
199         // Get Return Data
200         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
201
202         if (pEvent->eventType != MSG_EVENT_SET_FILTER_OPERATION)
203         {
204                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
205         }
206
207         ret = pEvent->result;
208
209         return ret;
210 }
211
212
213 msg_error_t MsgHandle::getFilterOperation(bool *pSetFlag)
214 {
215         msg_error_t ret = MSG_SUCCESS;
216
217         // Allocate Memory to Command Data
218         int cmdSize = sizeof(MSG_CMD_S);
219
220         char cmdBuf[cmdSize];
221         bzero(cmdBuf, cmdSize);
222         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
223
224         // Set Command Parameters
225         pCmd->cmdType = MSG_CMD_GET_FILTER_OPERATION;
226
227         // Copy Cookie
228         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
229
230         // Send Command to Messaging FW
231         char* pEventData = NULL;
232         AutoPtr<char> eventBuf(&pEventData);
233
234         write((char*)pCmd, cmdSize, &pEventData);
235
236         // Get Return Data
237         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
238
239         if (pEvent->eventType != MSG_EVENT_GET_FILTER_OPERATION)
240         {
241                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
242         }
243
244         ret = pEvent->result;
245
246         // Decode Return Data
247         if (ret == MSG_SUCCESS)
248         {
249                 MsgDecodeFilterFlag(pEvent->data, pSetFlag);
250                 MSG_DEBUG("Flag : %d", *pSetFlag);
251         }
252
253         return ret;
254 }
255
256 msg_error_t MsgHandle::setFilterActivation(msg_filter_id_t filter_id, bool active)
257 {
258         // Allocate Memory to Command Data
259         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_filter_id_t) + sizeof(bool);
260
261         char cmdBuf[cmdSize];
262         bzero(cmdBuf, cmdSize);
263         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
264
265         // Set Command Parameters
266         pCmd->cmdType = MSG_CMD_SET_FILTER_ACTIVATION;
267
268         // Copy Cookie
269         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
270
271         // Copy Command Data
272         memcpy(pCmd->cmdData, &filter_id, sizeof(msg_filter_id_t));
273         memcpy(pCmd->cmdData+sizeof(msg_filter_id_t), &active, sizeof(bool));
274
275         // Send Command to Messaging FW
276         char* pEventData = NULL;
277         AutoPtr<char> eventBuf(&pEventData);
278
279         write((char*)pCmd, cmdSize, &pEventData);
280
281         // Get Return Data
282         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
283
284         if (pEvent->eventType != MSG_EVENT_SET_FILTER_ACTIVATION)
285         {
286                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
287         }
288
289         return pEvent->result;
290 }