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);
42 /* Copy Command Data*/
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
49 write((char*)pCmd, cmdSize, &pEventData);
52 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
54 if (pEvent->eventType != MSG_EVENT_ADD_FILTER) {
55 THROW(MsgException::INVALID_RESULT, "Event Data Error");
58 return pEvent->result;
62 msg_error_t MsgHandle::updateFilter(const MSG_FILTER_S *pFilter)
64 /* Allocate Memory to Command Data */
65 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FILTER_S);
68 bzero(cmdBuf, cmdSize);
69 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
71 /* Set Command Parameters */
72 pCmd->cmdType = MSG_CMD_UPDATE_FILTER;
75 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
77 /* Copy Command Data */
78 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFilter, sizeof(MSG_FILTER_S));
80 /* Send Command to Messaging FW */
81 char* pEventData = NULL;
82 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
84 write((char*)pCmd, cmdSize, &pEventData);
87 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
89 if (pEvent->eventType != MSG_EVENT_UPDATE_FILTER) {
90 THROW(MsgException::INVALID_RESULT, "Event Data Error");
93 return pEvent->result;
97 msg_error_t MsgHandle::deleteFilter(msg_filter_id_t FilterId)
99 /* Allocate Memory to Command Data */
100 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_filter_id_t);
102 char cmdBuf[cmdSize];
103 bzero(cmdBuf, cmdSize);
104 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
106 /* Set Command Parameters */
107 pCmd->cmdType = MSG_CMD_DELETE_FILTER;
110 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
112 /* Copy Command Data */
113 memcpy(pCmd->cmdData, &FilterId, sizeof(msg_filter_id_t));
115 /* Send Command to Messaging FW */
116 char* pEventData = NULL;
117 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
119 write((char*)pCmd, cmdSize, &pEventData);
121 /* Get Return Data */
122 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
124 if (pEvent->eventType != MSG_EVENT_DELETE_FILTER) {
125 THROW(MsgException::INVALID_RESULT, "Event Data Error");
128 return pEvent->result;
132 msg_error_t MsgHandle::getFilterList(msg_struct_list_s *pFilterList)
134 /* Allocate Memory to Command Data */
135 int cmdSize = sizeof(MSG_CMD_S);
137 char cmdBuf[cmdSize];
138 bzero(cmdBuf, cmdSize);
139 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
141 /* Set Command Parameters */
142 pCmd->cmdType = MSG_CMD_GET_FILTERLIST;
145 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
147 /* Send Command to Messaging FW */
148 char* pEventData = NULL;
149 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
151 write((char*)pCmd, cmdSize, &pEventData);
153 /* Get Return Data */
154 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
156 if (pEvent->eventType != MSG_EVENT_GET_FILTERLIST) {
157 THROW(MsgException::INVALID_RESULT, "Event Data Error");
160 if (pEvent->result != MSG_SUCCESS) return pEvent->result;
162 /* Decode Return Data */
163 MsgDecodeFilterList(pEvent->data, pFilterList);
169 msg_error_t MsgHandle::setFilterOperation(bool bSetFlag)
171 msg_error_t ret = MSG_SUCCESS;
173 /* Allocate Memory to Command Data */
174 int cmdSize = sizeof(MSG_CMD_S) + sizeof(bool);
176 char cmdBuf[cmdSize];
177 bzero(cmdBuf, cmdSize);
178 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
180 /* Set Command Parameters */
181 pCmd->cmdType = MSG_CMD_SET_FILTER_OPERATION;
184 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
186 /* Copy Command Data */
187 memcpy(pCmd->cmdData, &bSetFlag, sizeof(bool));
189 /* Send Command to Messaging FW */
190 char* pEventData = NULL;
191 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
193 write((char*)pCmd, cmdSize, &pEventData);
195 /* Get Return Data */
196 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
198 if (pEvent->eventType != MSG_EVENT_SET_FILTER_OPERATION) {
199 THROW(MsgException::INVALID_RESULT, "Event Data Error");
202 ret = pEvent->result;
208 msg_error_t MsgHandle::getFilterOperation(bool *pSetFlag)
210 msg_error_t ret = MSG_SUCCESS;
212 /* Allocate Memory to Command Data */
213 int cmdSize = sizeof(MSG_CMD_S);
215 char cmdBuf[cmdSize];
216 bzero(cmdBuf, cmdSize);
217 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
219 /* Set Command Parameters */
220 pCmd->cmdType = MSG_CMD_GET_FILTER_OPERATION;
223 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
225 /* Send Command to Messaging FW */
226 char* pEventData = NULL;
227 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
229 write((char*)pCmd, cmdSize, &pEventData);
231 /* Get Return Data */
232 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
234 if (pEvent->eventType != MSG_EVENT_GET_FILTER_OPERATION) {
235 THROW(MsgException::INVALID_RESULT, "Event Data Error");
238 ret = pEvent->result;
240 /* Decode Return Data */
241 if (ret == MSG_SUCCESS) {
242 MsgDecodeFilterFlag(pEvent->data, pSetFlag);
243 MSG_DEBUG("Flag : %d", *pSetFlag);
250 msg_error_t MsgHandle::setFilterActivation(msg_filter_id_t filter_id, bool active)
252 /* Allocate Memory to Command Data */
253 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_filter_id_t) + sizeof(bool);
255 char cmdBuf[cmdSize];
256 bzero(cmdBuf, cmdSize);
257 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
259 /* Set Command Parameters */
260 pCmd->cmdType = MSG_CMD_SET_FILTER_ACTIVATION;
263 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
265 /* Copy Command Data */
266 memcpy(pCmd->cmdData, &filter_id, sizeof(msg_filter_id_t));
267 memcpy(pCmd->cmdData+sizeof(msg_filter_id_t), &active, sizeof(bool));
269 /* Send Command to Messaging FW */
270 char* pEventData = NULL;
271 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
273 write((char*)pCmd, cmdSize, &pEventData);
275 /* Get Return Data */
276 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
278 if (pEvent->eventType != MSG_EVENT_SET_FILTER_ACTIVATION) {
279 THROW(MsgException::INVALID_RESULT, "Event Data Error");
282 return pEvent->result;