2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 "MsgHandle.h"
19 #include "MsgUtilFunction.h"
20 #include "MsgCppTypes.h"
21 #include "MsgException.h"
24 /*==================================================================================================
25 IMPLEMENTATION OF MsgHandle - Filter Member Functions
26 ==================================================================================================*/
27 msg_error_t MsgHandle::addFilter(const MSG_FILTER_S *pFilter)
29 // Allocate Memory to Command Data
30 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FILTER_S);
33 bzero(cmdBuf, cmdSize);
34 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
36 // Set Command Parameters
37 pCmd->cmdType = MSG_CMD_ADD_FILTER;
40 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
43 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFilter, sizeof(MSG_FILTER_S));
45 // Send Command to Messaging FW
46 char* pEventData = NULL;
47 AutoPtr<char> eventBuf(&pEventData);
49 write((char*)pCmd, cmdSize, &pEventData);
52 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
54 if (pEvent->eventType != MSG_EVENT_ADD_FILTER)
56 THROW(MsgException::INVALID_RESULT, "Event Data Error");
59 return pEvent->result;
63 msg_error_t MsgHandle::updateFilter(const MSG_FILTER_S *pFilter)
65 // Allocate Memory to Command Data
66 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FILTER_S);
69 bzero(cmdBuf, cmdSize);
70 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
72 // Set Command Parameters
73 pCmd->cmdType = MSG_CMD_UPDATE_FILTER;
76 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
79 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFilter, sizeof(MSG_FILTER_S));
81 // Send Command to Messaging FW
82 char* pEventData = NULL;
83 AutoPtr<char> eventBuf(&pEventData);
85 write((char*)pCmd, cmdSize, &pEventData);
88 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
90 if (pEvent->eventType != MSG_EVENT_UPDATE_FILTER)
92 THROW(MsgException::INVALID_RESULT, "Event Data Error");
95 return pEvent->result;
99 msg_error_t MsgHandle::deleteFilter(msg_filter_id_t FilterId)
101 // Allocate Memory to Command Data
102 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_filter_id_t);
104 char cmdBuf[cmdSize];
105 bzero(cmdBuf, cmdSize);
106 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
108 // Set Command Parameters
109 pCmd->cmdType = MSG_CMD_DELETE_FILTER;
112 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
115 memcpy(pCmd->cmdData, &FilterId, sizeof(msg_filter_id_t));
117 // Send Command to Messaging FW
118 char* pEventData = NULL;
119 AutoPtr<char> eventBuf(&pEventData);
121 write((char*)pCmd, cmdSize, &pEventData);
124 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
126 if (pEvent->eventType != MSG_EVENT_DELETE_FILTER)
128 THROW(MsgException::INVALID_RESULT, "Event Data Error");
131 return pEvent->result;
135 msg_error_t MsgHandle::getFilterList(msg_struct_list_s *pFilterList)
137 // Allocate Memory to Command Data
138 int cmdSize = sizeof(MSG_CMD_S);
140 char cmdBuf[cmdSize];
141 bzero(cmdBuf, cmdSize);
142 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
144 // Set Command Parameters
145 pCmd->cmdType = MSG_CMD_GET_FILTERLIST;
148 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
150 // Send Command to Messaging FW
151 char* pEventData = NULL;
152 AutoPtr<char> eventBuf(&pEventData);
154 write((char*)pCmd, cmdSize, &pEventData);
157 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
159 if (pEvent->eventType != MSG_EVENT_GET_FILTERLIST)
161 THROW(MsgException::INVALID_RESULT, "Event Data Error");
164 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
166 // Decode Return Data
167 MsgDecodeFilterList(pEvent->data, pFilterList);
173 msg_error_t MsgHandle::setFilterOperation(bool bSetFlag)
175 msg_error_t ret = MSG_SUCCESS;
177 // Allocate Memory to Command Data
178 int cmdSize = sizeof(MSG_CMD_S) + sizeof(bool);
180 char cmdBuf[cmdSize];
181 bzero(cmdBuf, cmdSize);
182 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
184 // Set Command Parameters
185 pCmd->cmdType = MSG_CMD_SET_FILTER_OPERATION;
188 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
191 memcpy(pCmd->cmdData, &bSetFlag, sizeof(bool));
193 // Send Command to Messaging FW
194 char* pEventData = NULL;
195 AutoPtr<char> eventBuf(&pEventData);
197 write((char*)pCmd, cmdSize, &pEventData);
200 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
202 if (pEvent->eventType != MSG_EVENT_SET_FILTER_OPERATION)
204 THROW(MsgException::INVALID_RESULT, "Event Data Error");
207 ret = pEvent->result;
213 msg_error_t MsgHandle::getFilterOperation(bool *pSetFlag)
215 msg_error_t ret = MSG_SUCCESS;
217 // Allocate Memory to Command Data
218 int cmdSize = sizeof(MSG_CMD_S);
220 char cmdBuf[cmdSize];
221 bzero(cmdBuf, cmdSize);
222 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
224 // Set Command Parameters
225 pCmd->cmdType = MSG_CMD_GET_FILTER_OPERATION;
228 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
230 // Send Command to Messaging FW
231 char* pEventData = NULL;
232 AutoPtr<char> eventBuf(&pEventData);
234 write((char*)pCmd, cmdSize, &pEventData);
237 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
239 if (pEvent->eventType != MSG_EVENT_GET_FILTER_OPERATION)
241 THROW(MsgException::INVALID_RESULT, "Event Data Error");
244 ret = pEvent->result;
246 // Decode Return Data
247 if (ret == MSG_SUCCESS)
249 MsgDecodeFilterFlag(pEvent->data, pSetFlag);
250 MSG_DEBUG("Flag : %d", *pSetFlag);
256 msg_error_t MsgHandle::setFilterActivation(msg_filter_id_t filter_id, bool active)
258 // Allocate Memory to Command Data
259 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_filter_id_t) + sizeof(bool);
261 char cmdBuf[cmdSize];
262 bzero(cmdBuf, cmdSize);
263 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
265 // Set Command Parameters
266 pCmd->cmdType = MSG_CMD_SET_FILTER_ACTIVATION;
269 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
272 memcpy(pCmd->cmdData, &filter_id, sizeof(msg_filter_id_t));
273 memcpy(pCmd->cmdData+sizeof(msg_filter_id_t), &active, sizeof(bool));
275 // Send Command to Messaging FW
276 char* pEventData = NULL;
277 AutoPtr<char> eventBuf(&pEventData);
279 write((char*)pCmd, cmdSize, &pEventData);
282 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
284 if (pEvent->eventType != MSG_EVENT_SET_FILTER_ACTIVATION)
286 THROW(MsgException::INVALID_RESULT, "Event Data Error");
289 return pEvent->result;