4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include "MsgHandle.h"
22 #include "MsgUtilFunction.h"
23 #include "MsgCppTypes.h"
24 #include "MsgException.h"
27 /*==================================================================================================
28 IMPLEMENTATION OF MsgHandle - Filter Member Functions
29 ==================================================================================================*/
30 msg_error_t MsgHandle::addFilter(const MSG_FILTER_S *pFilter)
32 // Allocate Memory to Command Data
33 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FILTER_S);
36 bzero(cmdBuf, cmdSize);
37 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
39 // Set Command Parameters
40 pCmd->cmdType = MSG_CMD_ADD_FILTER;
43 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
46 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFilter, sizeof(MSG_FILTER_S));
48 // Send Command to Messaging FW
49 char* pEventData = NULL;
50 AutoPtr<char> eventBuf(&pEventData);
52 write((char*)pCmd, cmdSize, &pEventData);
55 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
57 if (pEvent->eventType != MSG_EVENT_ADD_FILTER)
59 THROW(MsgException::INVALID_RESULT, "Event Data Error");
62 return pEvent->result;
66 msg_error_t MsgHandle::updateFilter(const MSG_FILTER_S *pFilter)
68 // Allocate Memory to Command Data
69 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FILTER_S);
72 bzero(cmdBuf, cmdSize);
73 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
75 // Set Command Parameters
76 pCmd->cmdType = MSG_CMD_UPDATE_FILTER;
79 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
82 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFilter, sizeof(MSG_FILTER_S));
84 // Send Command to Messaging FW
85 char* pEventData = NULL;
86 AutoPtr<char> eventBuf(&pEventData);
88 write((char*)pCmd, cmdSize, &pEventData);
91 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
93 if (pEvent->eventType != MSG_EVENT_UPDATE_FILTER)
95 THROW(MsgException::INVALID_RESULT, "Event Data Error");
98 return pEvent->result;
102 msg_error_t MsgHandle::deleteFilter(msg_filter_id_t FilterId)
104 // Allocate Memory to Command Data
105 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_filter_id_t);
107 char cmdBuf[cmdSize];
108 bzero(cmdBuf, cmdSize);
109 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
111 // Set Command Parameters
112 pCmd->cmdType = MSG_CMD_DELETE_FILTER;
115 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
118 memcpy(pCmd->cmdData, &FilterId, sizeof(msg_filter_id_t));
120 // Send Command to Messaging FW
121 char* pEventData = NULL;
122 AutoPtr<char> eventBuf(&pEventData);
124 write((char*)pCmd, cmdSize, &pEventData);
127 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
129 if (pEvent->eventType != MSG_EVENT_DELETE_FILTER)
131 THROW(MsgException::INVALID_RESULT, "Event Data Error");
134 return pEvent->result;
138 msg_error_t MsgHandle::getFilterList(msg_struct_list_s *pFilterList)
140 // Allocate Memory to Command Data
141 int cmdSize = sizeof(MSG_CMD_S);
143 char cmdBuf[cmdSize];
144 bzero(cmdBuf, cmdSize);
145 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
147 // Set Command Parameters
148 pCmd->cmdType = MSG_CMD_GET_FILTERLIST;
151 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
153 // Send Command to Messaging FW
154 char* pEventData = NULL;
155 AutoPtr<char> eventBuf(&pEventData);
157 write((char*)pCmd, cmdSize, &pEventData);
160 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
162 if (pEvent->eventType != MSG_EVENT_GET_FILTERLIST)
164 THROW(MsgException::INVALID_RESULT, "Event Data Error");
167 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
169 // Decode Return Data
170 MsgDecodeFilterList(pEvent->data, pFilterList);
176 msg_error_t MsgHandle::setFilterOperation(bool bSetFlag)
178 msg_error_t ret = MSG_SUCCESS;
180 // Allocate Memory to Command Data
181 int cmdSize = sizeof(MSG_CMD_S) + sizeof(bool);
183 char cmdBuf[cmdSize];
184 bzero(cmdBuf, cmdSize);
185 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
187 // Set Command Parameters
188 pCmd->cmdType = MSG_CMD_SET_FILTER_OPERATION;
191 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
194 memcpy(pCmd->cmdData, &bSetFlag, sizeof(bool));
196 // Send Command to Messaging FW
197 char* pEventData = NULL;
198 AutoPtr<char> eventBuf(&pEventData);
200 write((char*)pCmd, cmdSize, &pEventData);
203 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
205 if (pEvent->eventType != MSG_EVENT_SET_FILTER_OPERATION)
207 THROW(MsgException::INVALID_RESULT, "Event Data Error");
210 ret = pEvent->result;
216 msg_error_t MsgHandle::getFilterOperation(bool *pSetFlag)
218 msg_error_t ret = MSG_SUCCESS;
220 // Allocate Memory to Command Data
221 int cmdSize = sizeof(MSG_CMD_S);
223 char cmdBuf[cmdSize];
224 bzero(cmdBuf, cmdSize);
225 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
227 // Set Command Parameters
228 pCmd->cmdType = MSG_CMD_GET_FILTER_OPERATION;
231 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
233 // Send Command to Messaging FW
234 char* pEventData = NULL;
235 AutoPtr<char> eventBuf(&pEventData);
237 write((char*)pCmd, cmdSize, &pEventData);
240 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
242 if (pEvent->eventType != MSG_EVENT_GET_FILTER_OPERATION)
244 THROW(MsgException::INVALID_RESULT, "Event Data Error");
247 ret = pEvent->result;
249 // Decode Return Data
250 if (ret == MSG_SUCCESS)
252 MsgDecodeFilterFlag(pEvent->data, pSetFlag);
253 MSG_DEBUG("Flag : %d", *pSetFlag);
259 msg_error_t MsgHandle::setFilterActivation(msg_filter_id_t filter_id, bool active)
261 // Allocate Memory to Command Data
262 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_filter_id_t) + sizeof(bool);
264 char cmdBuf[cmdSize];
265 bzero(cmdBuf, cmdSize);
266 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
268 // Set Command Parameters
269 pCmd->cmdType = MSG_CMD_SET_FILTER_ACTIVATION;
272 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
275 memcpy(pCmd->cmdData, &filter_id, sizeof(msg_filter_id_t));
276 memcpy(pCmd->cmdData+sizeof(msg_filter_id_t), &active, sizeof(bool));
278 // Send Command to Messaging FW
279 char* pEventData = NULL;
280 AutoPtr<char> eventBuf(&pEventData);
282 write((char*)pCmd, cmdSize, &pEventData);
285 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
287 if (pEvent->eventType != MSG_EVENT_SET_FILTER_ACTIVATION)
289 THROW(MsgException::INVALID_RESULT, "Event Data Error");
292 return pEvent->result;