2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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.
17 ////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_HMI_CWORD77_Controller
21 ////////////////////////////////////////////////////////////////////////////////
23 #include <native_service/frameworkunified__CWORD77__session_if.h>
24 #include <native_service/ns__CWORD77__data_pool_if.h>
25 #include <boost/bind.hpp>
28 #include "ns__CWORD77__data_pool_internal.h"
29 #include "ns__CWORD77__common_internal.h"
31 //////////////////////////////////////////
32 /// Function : CFrameworkunified_CWORD77_Session
33 //////////////////////////////////////////
34 CFrameworkunified_CWORD77_Session::CFrameworkunified_CWORD77_Session() {
40 //////////////////////////////////////////
41 /// Function : ~CFrameworkunified_CWORD77_Session
42 //////////////////////////////////////////
43 CFrameworkunified_CWORD77_Session::~CFrameworkunified_CWORD77_Session() { // LCOV_EXCL_BR_LINE 11:except branch
46 void CFrameworkunified_CWORD77_Session::SetSessionType(const UI_32 &sessioType) {
47 m_uiSessionType = sessioType;
50 //////////////////////////////////////////
51 /// Function : GetSessionType
52 //////////////////////////////////////////
53 UI_32 CFrameworkunified_CWORD77_Session::GetSessionType() {
54 return m_uiSessionType;
56 //////////////////////////////////////////
57 /// Function : SetResponseCallback
58 //////////////////////////////////////////
59 void CFrameworkunified_CWORD77_Session::SetResponseCallback(ResponseServiceTo_CWORD77_ f_cbResponse) {
60 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "+"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
61 m_ResponseTo_CWORD77_ = f_cbResponse;
62 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "-"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
64 //////////////////////////////////////////
65 /// Function : AddProtocolHandler
66 //////////////////////////////////////////
67 void CFrameworkunified_CWORD77_Session::AddProtocolHandler(UI_32 f_uiCmdId, CbFuncPtr f_cbFuncPtr) {
68 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "+");
69 FrameworkunifiedProtocolCallbackHandler l_tProtocolCallback;
70 l_tProtocolCallback.iCmd = f_uiCmdId;
71 l_tProtocolCallback.callBack = f_cbFuncPtr;
72 m_vSessionProtocolHanlder.push_back(l_tProtocolCallback);
73 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "-");
75 //////////////////////////////////////////
76 /// Function : AddEventHandler
77 //////////////////////////////////////////
78 void CFrameworkunified_CWORD77_Session::AddEventHandler(UI_32 f_uiCmdId, CbFuncPtr f_cbFuncPtr) {
79 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "+");
80 FrameworkunifiedProtocolCallbackHandler l_tProtocolCallback;
81 l_tProtocolCallback.iCmd = f_uiCmdId;
82 l_tProtocolCallback.callBack = f_cbFuncPtr;
83 m_vSessionEventHandler.push_back(l_tProtocolCallback);
84 m_vEventVector.push_back(f_uiCmdId); // Code added by Shyam
85 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "-");
87 //////////////////////////////////////////
88 /// Function : AttachProtocolwithDispatcher
89 //////////////////////////////////////////
90 EFrameworkunifiedStatus CFrameworkunified_CWORD77_Session::AttachProtocolwithDispatcher(HANDLE f_hApp) {
91 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "+");
92 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
93 size_t l_uiSize = m_vSessionProtocolHanlder.size();
94 PCSTR l_pRequester = FrameworkunifiedGetMsgSrc(f_hApp);
95 for (size_t i = 0; i < l_uiSize; i++) {
96 FrameworkunifiedAttachCallbackToDispatcher(f_hApp, l_pRequester, m_vSessionProtocolHanlder[i].iCmd,
97 m_vSessionProtocolHanlder[i].callBack, m_hSession);
99 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "-");
102 //////////////////////////////////////////
103 /// Function : DetachProtocolwithDispatcher
104 //////////////////////////////////////////
105 EFrameworkunifiedStatus CFrameworkunified_CWORD77_Session::DetachProtocolwithDispatcher(HANDLE f_hApp) {
106 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "+");
107 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
108 size_t l_uiSize = m_vSessionProtocolHanlder.size();
109 PCSTR l_pRequester = FrameworkunifiedGetMsgSrc(f_hApp);
110 for (size_t i = 0; i < l_uiSize; i++) {
111 FrameworkunifiedDetachCallbackFromDispatcher(f_hApp, l_pRequester, m_vSessionProtocolHanlder[i].iCmd,
114 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "-");
117 //////////////////////////////////////////
118 /// Function : AttachEventswithDispatcher
119 //////////////////////////////////////////
120 EFrameworkunifiedStatus CFrameworkunified_CWORD77_Session::AttachEventswithDispatcher(HANDLE f_hApp) {
121 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "+");
122 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
123 size_t l_uiSize = m_vEventVector.size();
125 for (size_t i = 0; i < l_uiSize; i++) {
126 l_eStatus = FrameworkunifiedRegisterEvent(m_hSession, m_vEventVector[i]);
128 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "-");
131 //////////////////////////////////////////
132 /// Function : AttachEventswithDispatcher
133 //////////////////////////////////////////
134 EFrameworkunifiedStatus CFrameworkunified_CWORD77_Session::RegisterEvents(HANDLE f_hApp) {
135 // Function: added by Shyam to overcome the naming conflict in registering the event
136 return AttachEventswithDispatcher(f_hApp);
139 //////////////////////////////////////////
140 /// Function : AttachEventHandlerswithDispatcher
141 //////////////////////////////////////////
142 EFrameworkunifiedStatus CFrameworkunified_CWORD77_Session::AttachEventHandlerswithDispatcher(HANDLE f_hApp) {
143 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "+");
144 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
145 size_t l_uiSize = m_vSessionEventHandler.size();
146 PCSTR l_pRequester = FrameworkunifiedGetMsgSrc(f_hApp);
147 for (size_t i = 0; i < l_uiSize; i++) {
148 FrameworkunifiedAttachCallbackToDispatcher(f_hApp, l_pRequester, m_vSessionEventHandler[i].iCmd,
149 m_vSessionEventHandler[i].callBack, m_hSession);
151 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "-");
154 //////////////////////////////////////////
155 /// Function : DetachEventHandlerswithDispatcher
156 //////////////////////////////////////////
157 EFrameworkunifiedStatus CFrameworkunified_CWORD77_Session::DetachEventHandlerswithDispatcher(HANDLE f_hApp) {
158 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "+");
159 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
160 size_t l_uiSize = m_vSessionEventHandler.size();
161 PCSTR l_pRequester = FrameworkunifiedGetMsgSrc(f_hApp);
162 for (size_t i = 0; i < l_uiSize; i++) {
163 FrameworkunifiedDetachCallbackFromDispatcher(f_hApp, l_pRequester, m_vSessionEventHandler[i].iCmd,
166 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "-");
170 //////////////////////////////////////////
171 /// Function : HandleSessionMessage
172 //////////////////////////////////////////
173 EFrameworkunifiedStatus CFrameworkunified_CWORD77_Session::HandleSessionMessage(UI_32 cmdID) {
174 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "+");
175 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
180 if (NULL != m_hSession && NULL != m_hService) {
181 eStatus = GetReqDataFrom_CWORD77_DataPool(std::make_pair(cmdID, FrameworkunifiedGetSessionName(m_hService)), size, data);
183 if (eFrameworkunifiedStatusOK == eStatus) {
184 eStatus = FrameworkunifiedSendMsg(m_hSession, cmdID, size, data);
185 if (eFrameworkunifiedStatusOK != eStatus) {
186 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: FrameworkunifiedSendMsg() returned %d", eStatus);
188 } else if (eFrameworkunifiedStatusDbRecNotFound == eStatus) {
189 // FIXME: This is added to help, if there is any command with no data. So, that services
190 // don't need to provide _CWORD77_ interfaces for such command.
191 // Correct way to solve the problem is, let services provide one _CWORD77_ interface
192 // which will write 0 length in data pool.
193 // Impact: This may have one impact that, service is expecting some data, but
194 // _CWORD77_ sends data with 0 length because it didn't find anything in the data pool.
195 FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__,
196 "GetReqDataFrom_CWORD77_DataPool() returned %d. But, still sending cmd 0x%X to service %s with length 0.",
197 eStatus, cmdID, FrameworkunifiedGetSessionName(m_hService));
198 eStatus = FrameworkunifiedSendMsg(m_hSession, cmdID, 0, NULL);
199 if (eFrameworkunifiedStatusOK != eStatus) {
200 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: FrameworkunifiedSendMsg() returned %d", eStatus);
204 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__,
205 "GetReqDataFrom_CWORD77_DataPool() returned %d. Can't send cmd 0x%X to service %s.",
206 eStatus, cmdID, FrameworkunifiedGetSessionName(m_hService));
209 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__,
210 "Error: HandleSessionMessage: Error sending cmd 0x%X request to service."
211 " Session handle %p Service Handle %p", cmdID, m_hSession, m_hService);
212 if (NULL == m_hSession) {
213 eStatus = eFrameworkunifiedStatusSessionErr;
217 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "- %d", eStatus);
221 //////////////////////////////////////////
222 /// Function : AttachResponseCallbacks
223 //////////////////////////////////////////
224 void CFrameworkunified_CWORD77_Session::AttachResponseCallbacks(HANDLE f_hApp) {
225 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "+"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
227 PCSTR l_pRequester = FrameworkunifiedGetMsgSrc(f_hApp);
229 // attach response protocols
230 UI_32 const *l_uiResponseProtocol = GetResponseProtocolArray();
231 if (NULL != l_uiResponseProtocol) {
232 for (; l_uiCount < GetResponseProtocolArrayLength(); l_uiResponseProtocol++, l_uiCount++) {
233 FrameworkunifiedAttachCallbackToDispatcher(f_hApp, l_pRequester, *l_uiResponseProtocol,
234 boost::bind(&CFrameworkunified_CWORD77_Session::OnResponse, this, f_hApp), m_hSession);
237 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "No Response protocols available for session with %s",
238 FrameworkunifiedGetSessionName(m_hService));
243 UI_32 const *l_uiEvents = GetEventArray();
244 if (NULL != l_uiEvents) {
245 for (; l_uiCount < GetEventArrayLength(); l_uiEvents++, l_uiCount++) {
247 FrameworkunifiedAttachCallbackToDispatcher(f_hApp, l_pRequester, *l_uiEvents,
248 boost::bind(&CFrameworkunified_CWORD77_Session::OnResponse, this, f_hApp), m_hSession); // LCOV_EXCL_BR_LINE 11:except branch
250 FrameworkunifiedRegisterEvent(m_hSession, *l_uiEvents);
253 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "No event protocols available for session with %s",
254 FrameworkunifiedGetSessionName(m_hService));
257 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "-"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
260 //////////////////////////////////////////
261 /// Function : DetachResponseCallbacks
262 //////////////////////////////////////////
263 void CFrameworkunified_CWORD77_Session::DetachResponseCallbacks(HANDLE f_hApp) {
264 if (NULL != m_hSession) {
266 PCSTR l_cSessionName = FrameworkunifiedGetSessionName(m_hSession);
267 // detach response protocols
268 UI_32 const *l_uiResponseProtocol = GetResponseProtocolArray();
269 if (NULL != l_uiResponseProtocol) {
270 for (; l_uiCount < GetResponseProtocolArrayLength(); l_uiResponseProtocol++, l_uiCount++) {
271 FrameworkunifiedDetachCallbackFromDispatcher(f_hApp, l_cSessionName, *l_uiResponseProtocol, m_hSession);
274 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "No Response protocols available for session with %s",
275 FrameworkunifiedGetSessionName(m_hService));
278 // detach and unregister events
280 UI_32 const *l_uiEvents = GetEventArray();
281 if (NULL != l_uiEvents) {
282 for (; l_uiCount < GetEventArrayLength(); l_uiEvents++, l_uiCount++) {
283 FrameworkunifiedDetachCallbackFromDispatcher(f_hApp, l_cSessionName, *l_uiEvents, m_hSession);
284 FrameworkunifiedUnRegisterEvent(m_hSession, *l_uiEvents);
287 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "No event protocols available for session with %s",
288 FrameworkunifiedGetSessionName(m_hService));
291 FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Detach not required. Session not yet available");
295 //////////////////////////////////////////
296 /// Function : OnResponse
297 //////////////////////////////////////////
298 EFrameworkunifiedStatus CFrameworkunified_CWORD77_Session::OnResponse(HANDLE f_hApp) {
299 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "+");
300 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
302 UI_32 length = FrameworkunifiedGetMsgLength(f_hApp);
303 UI_32 cmdId = FrameworkunifiedGetMsgProtocol(f_hApp);
304 PCSTR l_cMsgSourceName = FrameworkunifiedGetMsgSrc(f_hApp);
305 if (NULL != l_cMsgSourceName) {
307 std::vector<char> data;
309 eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, &data[0], length);
310 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "OnResponse from %s cmdId:%d", l_cMsgSourceName, cmdId);
311 SetRespDataIn_CWORD77_DataPool(std::make_pair(cmdId, l_cMsgSourceName), static_cast<UI_32>(data.size()), &data[0]);
313 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "OnResponse from %s cmdId:[%d], Value: [NULL]", l_cMsgSourceName, cmdId);
314 SetRespDataIn_CWORD77_DataPool(std::make_pair(cmdId, l_cMsgSourceName), 0, NULL);
317 m_ResponseTo_CWORD77_(f_hApp, RESPONSE, l_cMsgSourceName);
319 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: Setting response value of cmd 0x%X in data pool.", cmdId);
322 FRAMEWORKUNIFIEDLOG(ZONE_NS__CWORD77_, __FUNCTION__, "- %d", eStatus);