/* * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "MsgDebug.h" #include "MsgHandle.h" #include "MsgUtilFunction.h" #include "MsgCppTypes.h" #include "MsgException.h" /*================================================================================================== IMPLEMENTATION OF MsgHandle - Filter Member Functions ==================================================================================================*/ msg_error_t MsgHandle::addFilter(const MSG_FILTER_S *pFilter) { /* Allocate Memory to Command Data */ int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FILTER_S); char cmdBuf[cmdSize]; bzero(cmdBuf, cmdSize); MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf; /* Set Command Parameters */ pCmd->cmdType = MSG_CMD_ADD_FILTER; /* Copy Cookie */ memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN); /* Copy Command Data*/ memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFilter, sizeof(MSG_FILTER_S)); /* Send Command to Messaging FW */ char* pEventData = NULL; unique_ptr eventBuf(&pEventData, unique_ptr_deleter); write((char*)pCmd, cmdSize, &pEventData); /* Get Return Data */ MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData; if (pEvent->eventType != MSG_EVENT_ADD_FILTER) { THROW(MsgException::INVALID_RESULT, "Event Data Error"); } return pEvent->result; } msg_error_t MsgHandle::updateFilter(const MSG_FILTER_S *pFilter) { /* Allocate Memory to Command Data */ int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FILTER_S); char cmdBuf[cmdSize]; bzero(cmdBuf, cmdSize); MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf; /* Set Command Parameters */ pCmd->cmdType = MSG_CMD_UPDATE_FILTER; /* Copy Cookie */ memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN); /* Copy Command Data */ memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFilter, sizeof(MSG_FILTER_S)); /* Send Command to Messaging FW */ char* pEventData = NULL; unique_ptr eventBuf(&pEventData, unique_ptr_deleter); write((char*)pCmd, cmdSize, &pEventData); /* Get Return Data */ MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData; if (pEvent->eventType != MSG_EVENT_UPDATE_FILTER) { THROW(MsgException::INVALID_RESULT, "Event Data Error"); } return pEvent->result; } msg_error_t MsgHandle::deleteFilter(msg_filter_id_t FilterId) { /* Allocate Memory to Command Data */ int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_filter_id_t); char cmdBuf[cmdSize]; bzero(cmdBuf, cmdSize); MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf; /* Set Command Parameters */ pCmd->cmdType = MSG_CMD_DELETE_FILTER; /* Copy Cookie */ memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN); /* Copy Command Data */ memcpy(pCmd->cmdData, &FilterId, sizeof(msg_filter_id_t)); /* Send Command to Messaging FW */ char* pEventData = NULL; unique_ptr eventBuf(&pEventData, unique_ptr_deleter); write((char*)pCmd, cmdSize, &pEventData); /* Get Return Data */ MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData; if (pEvent->eventType != MSG_EVENT_DELETE_FILTER) { THROW(MsgException::INVALID_RESULT, "Event Data Error"); } return pEvent->result; } msg_error_t MsgHandle::getFilterList(msg_struct_list_s *pFilterList) { /* Allocate Memory to Command Data */ int cmdSize = sizeof(MSG_CMD_S); char cmdBuf[cmdSize]; bzero(cmdBuf, cmdSize); MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf; /* Set Command Parameters */ pCmd->cmdType = MSG_CMD_GET_FILTERLIST; /* Copy Cookie */ memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN); /* Send Command to Messaging FW */ char* pEventData = NULL; unique_ptr eventBuf(&pEventData, unique_ptr_deleter); write((char*)pCmd, cmdSize, &pEventData); /* Get Return Data */ MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData; if (pEvent->eventType != MSG_EVENT_GET_FILTERLIST) { THROW(MsgException::INVALID_RESULT, "Event Data Error"); } if (pEvent->result != MSG_SUCCESS) return pEvent->result; /* Decode Return Data */ MsgDecodeFilterList(pEvent->data, pFilterList); return MSG_SUCCESS; } msg_error_t MsgHandle::setFilterOperation(bool bSetFlag) { msg_error_t ret = MSG_SUCCESS; /* Allocate Memory to Command Data */ int cmdSize = sizeof(MSG_CMD_S) + sizeof(bool); char cmdBuf[cmdSize]; bzero(cmdBuf, cmdSize); MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf; /* Set Command Parameters */ pCmd->cmdType = MSG_CMD_SET_FILTER_OPERATION; /* Copy Cookie */ memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN); /* Copy Command Data */ memcpy(pCmd->cmdData, &bSetFlag, sizeof(bool)); /* Send Command to Messaging FW */ char* pEventData = NULL; unique_ptr eventBuf(&pEventData, unique_ptr_deleter); write((char*)pCmd, cmdSize, &pEventData); /* Get Return Data */ MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData; if (pEvent->eventType != MSG_EVENT_SET_FILTER_OPERATION) { THROW(MsgException::INVALID_RESULT, "Event Data Error"); } ret = pEvent->result; return ret; } msg_error_t MsgHandle::getFilterOperation(bool *pSetFlag) { msg_error_t ret = MSG_SUCCESS; /* Allocate Memory to Command Data */ int cmdSize = sizeof(MSG_CMD_S); char cmdBuf[cmdSize]; bzero(cmdBuf, cmdSize); MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf; /* Set Command Parameters */ pCmd->cmdType = MSG_CMD_GET_FILTER_OPERATION; /* Copy Cookie */ memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN); /* Send Command to Messaging FW */ char* pEventData = NULL; unique_ptr eventBuf(&pEventData, unique_ptr_deleter); write((char*)pCmd, cmdSize, &pEventData); /* Get Return Data */ MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData; if (pEvent->eventType != MSG_EVENT_GET_FILTER_OPERATION) { THROW(MsgException::INVALID_RESULT, "Event Data Error"); } ret = pEvent->result; /* Decode Return Data */ if (ret == MSG_SUCCESS) { MsgDecodeFilterFlag(pEvent->data, pSetFlag); MSG_DEBUG("Flag : %d", *pSetFlag); } return ret; } msg_error_t MsgHandle::setFilterActivation(msg_filter_id_t filter_id, bool active) { /* Allocate Memory to Command Data */ int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_filter_id_t) + sizeof(bool); char cmdBuf[cmdSize]; bzero(cmdBuf, cmdSize); MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf; /* Set Command Parameters */ pCmd->cmdType = MSG_CMD_SET_FILTER_ACTIVATION; /* Copy Cookie */ memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN); /* Copy Command Data */ memcpy(pCmd->cmdData, &filter_id, sizeof(msg_filter_id_t)); memcpy(pCmd->cmdData+sizeof(msg_filter_id_t), &active, sizeof(bool)); /* Send Command to Messaging FW */ char* pEventData = NULL; unique_ptr eventBuf(&pEventData, unique_ptr_deleter); write((char*)pCmd, cmdSize, &pEventData); /* Get Return Data */ MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData; if (pEvent->eventType != MSG_EVENT_SET_FILTER_ACTIVATION) { THROW(MsgException::INVALID_RESULT, "Event Data Error"); } return pEvent->result; }