Beispiel #1
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 #2
0
void L1InterfaceStub::processServiceAllocateRequest(CDataAccessor & accessor)
{
    const UInt32 channel_id = accessor.getChannelID();
    const UInt32 prio = *reinterpret_cast<UInt32*>(accessor.getData());
    ConnectivityAgentError err(static_cast<ConnectivityAgentError::AgentErrorCodes>
            (accessor.getErrorCode()));
    LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceAllocateRequest()=>"
            "Allocate channel prio = " + convertIntegerToString(prio) +
            " id =" + convertIntegerToString(accessor.getChannelID()));

    iviLink::Ipc::DirectionID dirId = -1;

    accessor.setOpCode(E_ALLOCATE_CHANNEL_RESP);
    accessor.resetData();

    if (!err.isNoError())
    {
        // SEQ_E_3
        failAllocateChannel(channel_id, dirId);

        accessor.setErrorCode(err.getCode());
    }
    else
    {
        mRequestedMapMutex.lock();
        mRegistryMutex.lock();
        {
            err = beginAllocateChannel(static_cast<TChannelPriority>(prio), channel_id,
                    false, dirId);

            if (err.getCode() != ConnectivityAgentError::ERROR_DEFERRED)
            {
                // sending the result to other side
                // SEQ_E_4 or ok
                accessor.setErrorCode(err.getCode());
                sendRequest(accessor);
            }
        }
        mRegistryMutex.unlock();
        mRequestedMapMutex.unlock();

        if (err.getCode() == ConnectivityAgentError::ERROR_DEFERRED)
        {
            // all ok, we will wait for the client requesting this channel
            // setting timeout

            LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceAllocateRequest() => "
                    "channel wasn't requested yet ->set channel to wait and trigger timeout");

            assert(mTimeoutManager);
            mTimeoutManager->addSubscriber(
                    new RequestTimeout(E_ALLOCATE_CHANNEL,channel_id, this), 250000);
            return;
        }
    }

    if (!err.isNoError())
    {
        // messagign about failed channel allocation
        // SEQ_E_4

        if (dirId != -1)
        {
            sendIpcNotification(accessor, dirId);
        }
    }
}
Beispiel #3
0
bool L1InterfaceStub::processClientGetDeviceList(CDataAccessor & accessor, const iviLink::Ipc::DirectionID dirId)
{
    LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__);

    UInt32 number = 0;
    if(accessor.getDataSize()<sizeof(UInt32))
    {
        accessor.resetData();
        accessor.setErrorCode(ConnectivityAgentError::ERROR_REQUEST_FAILED);
        return true;
    }
    number=*(reinterpret_cast<UInt32*>(accessor.getData()));
    if(number!=0)
    {
        accessor.resetData();
        accessor.setErrorCode(ConnectivityAgentError::ERROR_NOT_FOUND);
        return true;
    }
    else
    {
        LOG4CPLUS_INFO(logger, "Device Number know, transmitting");
        FoundDevice device;
        UInt8* serializedData = NULL;
        device.mName="N/a";
        device.mAddress="";
        device.mConnection=CON_UNKNOWN;
        if (mpAgent)
        {
            iviLink::ConnectivityAgent::HAL::CCarrierAdapter* pca = mpAgent->getCurrentCarrierAdapter();
            if (pca)
            {
                const char *remoteAddress = pca->getRemoteAddress();
                const char *connTypeName = pca->getTypeName();
                if(connTypeName == NULL)
                {
                    connTypeName = "";
                }
                if(remoteAddress == NULL)
                {
                    remoteAddress = "N/a";
                }
                std::string typeName = connTypeName;
                device.mName = remoteAddress;
                device.mAddress = remoteAddress;
                if (typeName == "Bluetooth")
                {
                    device.mConnection = CON_BLUETOOTH;
                }
                else if (typeName == "TCP/IP")
                {
                    device.mConnection = CON_IP;
                }
            }
        }
        serializedData = device.serialize();
        accessor.resetData();
        accessor.setData(serializedData,device.getSerializedSize());
        delete[] serializedData;
        accessor.setErrorCode(BaseError::IVILINK_NO_ERROR);
        return true;
    }
}