コード例 #1
0
ファイル: L1InterfaceStub.cpp プロジェクト: Luxoft/iviLink
ConnectivityAgentError L1InterfaceStub::sendData(CDataAccessor & accessor)
{
    LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__);
    ConnectivityAgentError result(ConnectivityAgentError::ERROR_NOT_FOUND);
    mRegistryMutex.lock();
    tChannelsRegistryMap::iterator iter = mL1ChannelRegistry.find(accessor.getChannelID());

    if (iter != mL1ChannelRegistry.end())
    {
        Buffer buf;
        UInt32 size = accessor.getDataSize();
        assert (size <= MAX_SIZE);

        LOG4CPLUS_INFO(logger, "L1InterfaceStub::sendData() => Overall data bytes " +
                convertIntegerToString(size));
        buf.reserveSize(size);
        buf.setFilledSize(size);
        memcpy(buf.getData(), accessor.getData(), accessor.getDataSize());
        result = (iter->second.mpSourceAgent->fillBuffer(buf));
    }
    else
    {
        LOG4CPLUS_ERROR(logger, "L1InterfaceStub::sendData() => channel not found!");
        result.setErrorCode(ConnectivityAgentError::ERROR_NOT_FOUND);
    }
    mRegistryMutex.unlock();
    return result;
}
コード例 #2
0
ファイル: L1InterfaceStub.cpp プロジェクト: Luxoft/iviLink
ConnectivityAgentError L1InterfaceStub::sendRequest( CDataAccessor & accessor)
{
    LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__);
    Buffer buf;
    UInt32 offset = 0;

    accessor.printContent();

    buf.getFilledSize() = accessor.getObjectSize() + sizeof(UInt16);
    buf.reserveSize(buf.getFilledSize());

    *reinterpret_cast<UInt16*> (buf.getData() + offset) =
            ByteOrder::hton16((UInt16)buf.getFilledSize());
    offset += 2;

    *reinterpret_cast<UInt32*> (buf.getData() + offset) =
            ByteOrder::hton32(accessor.getOpCode());
    offset += 4;

    *reinterpret_cast<UInt32*> (buf.getData() + offset) =
            ByteOrder::hton32(accessor.getChannelID());
    offset += 4;

    *reinterpret_cast<UInt32*> (buf.getData() + offset) =
            ByteOrder::hton32(accessor.getDataSize());
    offset += 4;

    *reinterpret_cast<UInt32*> (buf.getData() + offset) =
            ByteOrder::hton32(accessor.getErrorCode());
    offset += 4;

    if (accessor.getDataSize())
    {
        memcpy(buf.getData() + offset,accessor.getData(), accessor.getDataSize() );
    }

    ConnectivityAgentError ret = mL1ChannelRegistry[CA_SERVICE_CHANNEL].
            mpSourceAgent->fillBuffer(buf);

    buf.forgetData();

    return ret;
}
コード例 #3
0
ファイル: L1InterfaceStub.cpp プロジェクト: Luxoft/iviLink
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;
    }
}
コード例 #4
0
void CConnectivityAgentProxy::receiveDataNotification(CDataAccessor & accessor)
{
	LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__);
	UInt32 channel_id = accessor.getChannelID();

	UInt32 data_size = accessor.getDataSize();

	LOG4CPLUS_INFO(logger,
			"CConnectivityAgentProxy::receiveDataNotification() => channel "
					+ convertIntegerToString(channel_id) + ", data_size "
					+ convertIntegerToString(data_size));

	mRegistryMutex.lockRead();
	tChannelsRegistryMap::iterator iter = mChannelRegistry.find(channel_id);
	if (iter != mChannelRegistry.end())
	{
		Buffer *buf = &(iter->second.mChannelBuffer);
		UInt32 free_size = buf->getAllocatedSize() - buf->getFilledSize();

		if (free_size < data_size)
		{

			mCallbackListMutex.lock();
			CCallbackWrapper* pCallback = new CBufferOverflowCallback(iter->second.mpClient,
					channel_id);
			mCallbackList.push_back(pCallback);
			mCallbackListMutex.unlock();
			mCallbackSema.signal();
			LOG4CPLUS_ERROR(logger,
					"CConnectivityAgentProxy::receiveDataNotification() => overflow!");
			//copy or not?
		} else
		{
			buf->appendData(accessor.getData(), data_size);
			free_size -= data_size;
			mCallbackListMutex.lock();
			CCallbackWrapper* pCallback = new CDataReceivedCallback(iter->second.mpClient,
					channel_id, data_size);
			mCallbackList.push_back(pCallback);
			mCallbackListMutex.unlock();
			mCallbackSema.signal();
		}
	} else
	{
		LOG4CPLUS_ERROR(logger,
				"CConnectivityAgentProxy::receiveDataNotification() => unknown channel!");
	}
	mRegistryMutex.unlockRead();
}
コード例 #5
0
ファイル: L1InterfaceStub.cpp プロジェクト: Luxoft/iviLink
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;
    }
}