bool L1InterfaceStub::processClientAllocateRequest(CDataAccessor & accessor, const iviLink::Ipc::DirectionID dirId) { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); const UInt32 channel_id = accessor.getChannelID(); if(CA_SERVICE_CHANNEL == channel_id) { // SEQ_E_5 LOG4CPLUS_WARN(logger, "Channel CA_SERVICE_CHANNEL is not allowed to be open"); accessor.resetData(); accessor.setErrorCode(ConnectivityAgentError::ERROR_CHANNEL_BUSY); return true; } UInt32 prio = 0; memcpy(&prio, accessor.getData(), accessor.getDataSize()); LOG4CPLUS_INFO(logger, "L1InterfaceStub::processClientAllocateRequest() => " "Allocate Channel Request: ChID = " + convertIntegerToString(channel_id) + ", prio = " + convertIntegerToString(prio)); iviLink::Ipc::DirectionID tmpDirId = dirId; ConnectivityAgentError err = ConnectivityAgentError(ConnectivityAgentError::ERROR_OTHER); mRequestedMapMutex.lock(); mRegistryMutex.lock(); { err = beginAllocateChannel(static_cast<TChannelPriority>(prio), channel_id, true, tmpDirId); accessor.setErrorCode(err.getCode()); if (err.isNoError()) { LOG4CPLUS_INFO(logger, "L1InterfaceStub::processClientAllocateRequest() => " "all ok, sending request to other side" ); err = sendRequest(accessor); } } mRegistryMutex.unlock(); mRequestedMapMutex.unlock(); if (err.isNoError()) //> all ok { return false; } else { // something wrong, need message about error // SEQ_E_5 assert(err.getCode() != ConnectivityAgentError::ERROR_DEFERRED); accessor.resetData(); accessor.setErrorCode(err.getCode()); return true; } }
ConnectivityAgentError L1InterfaceStub::allocateChannelLocally(const UInt32 channel_id, tRequestedChannelInfo const& req_info) { LOG4CPLUS_TRACE_METHOD(logger, "L1InterfaceStub::allocateChannelLocally" " channel_id" + convertIntegerToString(channel_id)); ConnectivityAgentError result; assert(mL1ChannelRegistry.find(channel_id) == mL1ChannelRegistry.end()); assert(req_info.mState == E_TRANSITION_AGENT || req_info.mState == E_TRANSITION_CLIENT); ///>FIXME Set up correct thresholds tL1ChannelInfo info; info.mType = req_info.mType; info.mClientDir = req_info.mClientDir; info.mState = req_info.mState; info.mLowerThresholdTime = 0; info.mUpperThresholdTime = 0xFFFFFFFF; result = CChannelAllocator::getInstance()->allocateChannel(info.mType, channel_id, info); LOG4CPLUS_INFO(logger, "L1InterfaceStub::allocateChannelLocally(): CChannelAllocator ret = " + convertIntegerToString((int)result.getCode())); /// @todo correct processing of error code and return values. PIlin, 31.08.12 //ret = ERR_OK; if (result.isNoError()) { mL1ChannelRegistry.insert(std::pair<UInt32,tL1ChannelInfo >(channel_id, info)); } return result; }
ConnectivityAgentError CCarrierAdapter::processFrame(iviLink::ConnectivityAgent::HAL::Frame & frame) { ConnectivityAgentError processResult = ConnectivityAgentError::NoError(); mFrameProcessingCondVar.lock(); while (!mIsFrameProcessingAllowed) { mFrameProcessingCondVar.wait(); } mFrameProcessingCondVar.unlock(); mFrameReceiverLock.lock(); if (mpFrameReceiver) { processResult = mpFrameReceiver->receiveFrame(frame); if(processResult.isNoError() || processResult.getCode() == ConnectivityAgentError::ERROR_RESEND_ACK) { if (!frame.isACK()) { sendACK(frame); } } else { LOG4CPLUS_INFO(logger, "CCarrierAdapter::receiveFrame ERROR mpFrameReceiver->receiveFrame returned " + convertIntegerToString((int)processResult.getCode()) + ". ACK is not send"); } } mFrameReceiverLock.unlock(); return processResult; }
ConnectivityAgentError CTarget::receiveFrame(const iviLink::ConnectivityAgent::HAL::Frame& frame) { LOG4CPLUS_TRACE(logger, " CTarget::receiveFrame(): channel " + convertIntegerToString(mChannelID)); static bool firstFlag = true; ConnectivityAgentError result; assert(mChannelID == frame.mFrameHeader.channel_id); if((!firstFlag)&&(!mCarrierReplaced)&&(frame.mFrameHeader.number != mLastFrameNr + 1)) { LOG4CPLUS_ERROR(logger, "CTarget::receiveFrame error - ERR_WRONG_FRAME_SEQUENCE: frame.mFrameHeader.number = " + convertIntegerToString(frame.mFrameHeader.number) + ", mLastFrameNr + 1 = " + convertIntegerToString(mLastFrameNr + 1)); if(frame.mFrameHeader.number<=mLastFrameNr) { result.setErrorCode(ConnectivityAgentError::ERROR_RESEND_ACK); } else { result.setErrorCode(ConnectivityAgentError::ERROR_WRONG_FRAME_SEQUENCE); } } else if (mBufferQueue.empty()) { LOG4CPLUS_ERROR(logger, "CTarget::receiveFrame error - mBufferQueue.empty()"); result.setErrorCode(ConnectivityAgentError::ERROR_NO_FREE_BUFFERS_LEFT); } else { mBufferQueueMutex.lock(); Buffer* buf = mBufferQueue.front(); mBufferQueue.pop_front(); mBufferQueueMutex.unlock(); assert(buf); copyFromFrame(frame, *buf); assert(mpBufferConsumer); result = mpBufferConsumer->consumeBuffer(buf); if (result.isNoError()) { if(firstFlag) { firstFlag =false; } if(mCarrierReplaced) { mCarrierReplaced = false; } mLastFrameNr = frame.mFrameHeader.number; } } return result; }
void L1InterfaceStub::processServiceDeallocateRequest(CDataAccessor & accessor) { UInt32 channel_id = accessor.getChannelID(); LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceDeallocateRequest() => " "Channel deallocate request id = " + convertIntegerToString(channel_id)); ConnectivityAgentError ret = deallocateChannel(channel_id ); accessor.setOpCode(E_DEALLOCATE_CHANNEL_RESP); UInt32 data = ret.getCode(); accessor.setData(reinterpret_cast<UInt8 *>(&data), sizeof(UInt32)); sendRequest(accessor); if (ret.isNoError()) { LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceDeallocateRequest() => " "channel successfully deallocated. " "Notifying client"); iviLink::Ipc::DirectionID dirId; bool found = false; mRegistryMutex.lock(); tChannelsRegistryMap::iterator iter = mL1ChannelRegistry.find(accessor.getChannelID()); if (mL1ChannelRegistry.end() != iter) { dirId = iter->second.mClientDir; found = true; LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceDeallocateRequest() => " "channel found in registry - removing"); mL1ChannelRegistry.erase(accessor.getChannelID()); } mRegistryMutex.unlock(); if (found) { accessor.setOpCode(E_DEALLOCATE_CHANNEL_NTF); UInt8* buf = new UInt8[accessor.getObjectSize()]; accessor.copyToRawArray(buf); BaseError err = mpIpc->asyncRequest(mMsgIdGen.next(), buf, accessor.getObjectSize(), &dirId); if (!err.isNoError()) { LOG4CPLUS_WARN(logger, static_cast<std::string>(err)); } delete[] buf; } } // ret == OK }
void CCarrierAdapter::haveData() { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); UInt8* pArray = reinterpret_cast<UInt8*>(&mFrame); // Reading as many as possible UInt32 size = sizeof(mFrame) - mFilledSize; ConnectivityAgentError receiveResult = receiveRawArray(pArray + mFilledSize, size); if (!receiveResult.isNoError()) { return; } UInt32 saved_size = mFilledSize; mFilledSize += size; while (mFilledSize >= sizeof(mFrame.mFrameHeader)) { // header done if (saved_size < sizeof(mFrame.mFrameHeader)) { // header become ready right now CFrameConverter::arrayToFrame(pArray, &mFrame); } const UInt32 full_size = mFrame.getSize() + sizeof(iviLink::ConnectivityAgent::HAL::Frame::FrameHeader); if (full_size <= mFilledSize) { // frame done // ! The error returned is not processed processFrame(mFrame); memmove(pArray, pArray + full_size, mFilledSize - full_size); mFilledSize -= full_size; saved_size = 0; } else { break; } } // while }
ConnectivityAgentError CTcpCarrierAdapter::makeHandshake() { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); ConnectivityAgentError handshakeResult = ConnectivityAgentError::NoError(); mHandshakeStateCondVar.lock(); if (mHandshakeState != eHandshakeBefore) { LOG4CPLUS_ERROR(logger,"wrong handshake state" ); handshakeResult.setErrorCode(ConnectivityAgentError::ERROR_HANDSHAKE_FAILED); } mHandshakeStateCondVar.unlock(); if (!handshakeResult.isNoError()) return handshakeResult; // will return this in case of any handshake fail ConnectivityAgentError failedResult(ConnectivityAgentError::ERROR_HANDSHAKE_FAILED); const UInt32 size = 50; UInt8 pAddr[size]; memset(pAddr, 0, size); strncpy(reinterpret_cast<char*>(pAddr), this->getRemoteAddress(), size); if (mConnectionInfo.serverSocket) { LOG4CPLUS_INFO(logger, "CTcpCarrierAdapter::makeHandshake(): send AXIS ..."); handshakeAndVerStrAxis[4] = IVILINK_VERSION_MAJOR; handshakeAndVerStrAxis[5] = IVILINK_VERSION_MINOR; if (!sendPreparedArray(handshakeAndVerStrAxis, sizeof(handshakeAndVerStrAxis)).isNoError()) { LOG4CPLUS_ERROR(logger,"handshake AXIS send failed" ); return failedResult; } if (!waitHandshakeState(eHandshakeA).isNoError()) { LOG4CPLUS_ERROR(logger,"handshake not state A"); return failedResult; } if (!sendPreparedArray(pAddr, sizeof(pAddr)).isNoError()) { LOG4CPLUS_ERROR(logger,"handshake send addr failed"); return failedResult; } if (!waitHandshakeState(eHandshakeDone).isNoError()) { LOG4CPLUS_ERROR(logger,"handshake not state done"); return failedResult; } mGenderType = eServerGender; } else { if (!waitHandshakeState(eHandshakeA).isNoError()) { LOG4CPLUS_ERROR(logger,"handshake not state A"); return failedResult; } handshakeAndVerStrSixa[4] = IVILINK_VERSION_MAJOR; handshakeAndVerStrSixa[5] = IVILINK_VERSION_MINOR; if (!sendPreparedArray(handshakeAndVerStrSixa, sizeof(handshakeAndVerStrSixa)).isNoError()) { LOG4CPLUS_ERROR(logger,"handshake SIXA send failed" ); return failedResult; } if (!waitHandshakeState(eHandshakeDone).isNoError()) { LOG4CPLUS_ERROR(logger,"handshake not state done"); return failedResult; } if (!sendPreparedArray(pAddr, sizeof(pAddr)).isNoError()) { LOG4CPLUS_ERROR(logger,"handshake send addr failed"); return failedResult; } mGenderType = eClientGender; } return ConnectivityAgentError::NoError(); }