Beispiel #1
0
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;
}
Beispiel #2
0
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;
    }
}
Beispiel #3
0
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;
}
Beispiel #4
0
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
}
Beispiel #5
0
ConnectivityAgentError L1InterfaceStub::beginAllocateChannel(const TChannelPriority prio,
        const UInt32 channel_id, const bool client_side, DirectionID& dirId)
{
    LOG4CPLUS_TRACE_METHOD(logger, "L1InterfaceStub::beginAllocateChannel(" +
            convertIntegerToString(channel_id) + ", "
            "client_side" + std::string(client_side ? "true" : "false") +")");
    ConnectivityAgentError result;

    //if channel wasn't opened yet
    if (mL1ChannelRegistry.find(channel_id) == mL1ChannelRegistry.end())
    {
        tRequestedChannelsMap::iterator iter = mRequestedMap.find(channel_id);
        if (iter == mRequestedMap.end()) // if channel wasn't requested yet ->request channel
        {
            // First call on SEQ_A and SEQ_B or SEQ_A DEFERRED

            tRequestedChannelInfo info;
            info.mType =  prio;
            info.mState = (client_side ? E_TRANSITION_CLIENT : E_TRANSITION_AGENT);
            info.mClientDir = dirId;

            assert((client_side && dirId != -1) || (!client_side && dirId == -1));

            LOG4CPLUS_INFO(logger, "L1InterfaceStub::beginAllocateChannel() =>insert request"
                    " channel_id " + convertIntegerToString(channel_id) +
                    " mState " + std::string(info.mState == E_TRANSITION_CLIENT ?
                            "E_TRANSITION_CLIENT" : "E_TRANSITION_AGENT"));

            mRequestedMap.insert(std::pair<UInt32, tRequestedChannelInfo>(channel_id, info));
            
            result = (client_side ? ConnectivityAgentError::NoError() :
                    ConnectivityAgentError(ConnectivityAgentError::ERROR_DEFERRED));
        }
        else
        {
            tRequestedChannelInfo & info = iter->second;

            //if channel was requested by other side
            if (!client_side || (client_side && info.mState == E_TRANSITION_AGENT))
            {
                // SEQ_A DEFERRED or call from other side

                LOG4CPLUS_INFO(logger, "L1InterfaceStub::beginAllocateChannel() =>"
                        "Opening channel locally");

                if (client_side)
                {
                    info.mClientDir = dirId;
                }
                else
                {
                    dirId = info.mClientDir;
                }

                result = allocateChannelLocally(channel_id, info);

                assert(result.getCode() != ConnectivityAgentError::ERROR_DEFERRED);

                mRequestedMap.erase(channel_id);
            }
            else  //channel was requested by Client Application not the first time
            {
                // SEQ_E_1
                LOG4CPLUS_ERROR(logger, "L1InterfaceStub::beginAllocateChannel() => ERROR: "
                        "allocation is in progress! ");
                result.setErrorCode(ConnectivityAgentError::ERROR_ALLOCATION_IN_PROGRESS);
            }
        }
    }
    else //channel already opened
    {
        // SEQ_E_2

        LOG4CPLUS_ERROR(logger, "L1InterfaceStub::beginAllocateChannel() => ERROR: channel "
                "already exists! ");
        result.setErrorCode(ConnectivityAgentError::ERROR_CHANNEL_BUSY);
    }

    return result;
}