Beispiel #1
0
bool L1InterfaceStub::processClientDeallocateRequest(CDataAccessor & accessor,
        const iviLink::Ipc::DirectionID dirId)
{
    UInt32 channel_id = accessor.getChannelID();
    if(CA_SERVICE_CHANNEL !=channel_id)
    {
        LOG4CPLUS_INFO(logger, "L1InterfaceStub::processClientDeallocateRequest() => "
                "Deallocate Channel Request: ChID = " + convertIntegerToString(channel_id));
        mRegistryMutex.lock();
        tChannelsRegistryMap::iterator iter =  mL1ChannelRegistry.find(channel_id);
        if (iter != mL1ChannelRegistry.end())
        {
            iter->second.mState = E_TRANSITION_CLIENT;
            sendRequest(accessor);
            assert(mTimeoutManager);
            mTimeoutManager->addSubscriber(new RequestTimeout(static_cast<tOpCode>
            (accessor.getOpCode()),channel_id,this ), 250000);
            // ret = ERR_OK;
        }
        else
        {
            LOG4CPLUS_INFO(logger, "L1InterfaceStub::processClientDeallocateRequest() "
                    "=> Deallocate Channel Request: ChID = " +
                    convertIntegerToString(channel_id) + " NOT FOUND!");
            // ret = ERR_NOTFOUND;
        }
        mRegistryMutex.unlock();
    }

    return false;
}
Beispiel #2
0
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;
}
Beispiel #3
0
bool L1InterfaceStub::processClientDeallocateByWD(CDataAccessor & accessor,
        const iviLink::Ipc::DirectionID dirId)
{
    LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__);
    UInt32 channel_id = accessor.getChannelID();
    if(CA_SERVICE_CHANNEL !=channel_id)
    {
        LOG4CPLUS_INFO(logger, "L1InterfaceStub::processClientDeallocateByWD() => "
                "Deallocate Channel Request: ChID = " + convertIntegerToString(channel_id));
        mRegistryMutex.lock();
        tChannelsRegistryMap::iterator iter =  mL1ChannelRegistry.find(channel_id);
        if (iter != mL1ChannelRegistry.end())
        {
            iter->second.mClientDir = dirId; // so that Negotiator receives the response
            iter->second.mState = E_TRANSITION_CLIENT;
            accessor.setOpCode(E_DEALLOCATE_CHANNEL);
            sendRequest(accessor);
            assert(mTimeoutManager);
            mTimeoutManager->addSubscriber(new RequestTimeout(static_cast<tOpCode>
            (accessor.getOpCode()),channel_id,this ), 250000);
            accessor.setErrorCode(0);
        }
        else
        {
            LOG4CPLUS_INFO(logger, "L1InterfaceStub::processClientDeallocateByWD() "
                    "=> Deallocate Channel Request: ChID = " +
                    convertIntegerToString(channel_id) + " NOT FOUND!");
            accessor.setErrorCode(ConnectivityAgentError::ERROR_NOT_FOUND);
        }
        mRegistryMutex.unlock();
    }
    else
    {
        accessor.setErrorCode(ConnectivityAgentError::ERROR_OTHER);
    }

    return true;
}
ERROR_CODE CConnectivityAgentProxy::deallocateChannel(UInt32 channel_id)
{
	LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__);
	LOG4CPLUS_INFO(logger,
			"CConnectivityAgentProxy::deallocateChannel(chID = "
					+ convertIntegerToString(channel_id) + ")");
	ERROR_CODE ret = ERR_NOTFOUND;

	mRegistryMutex.lockWrite();
	// Channel info will be saved in info and removed from registry here.
	// In case of some errors, it will be restored in registry.
	tChannelInfo info;
	tChannelsRegistryMap::iterator iter = mChannelRegistry.find(channel_id);
	if (iter == mChannelRegistry.end())
	{
		LOG4CPLUS_ERROR(logger,
				"CConnectivityAgentProxy::deallocateChannel(chID = "
						+ convertIntegerToString(channel_id) + ") => ERROR: Channel not found! ");
	} else
	{
		ret = ERR_OK;
		info = iter->second;
		iter->second.mChannelBuffer.forgetData();
		mChannelRegistry.erase(iter);
		mChannelOnDeallocSet.insert(channel_id);
	}
	mRegistryMutex.unlockWrite();

	if (ret != ERR_OK)
		return ret;

	CDataAccessor requestDA;
	requestDA.setChannelID(channel_id);
	requestDA.setOpCode(E_DEALLOCATE_CHANNEL);
	UInt8* buf = new UInt8[requestDA.getObjectSize()];
	requestDA.copyToRawArray(buf);

	// response will be sent later as a separate request
	UInt32 respSize = 0;
	CError err = mpIpc->request(mMsgIdGen.next(), buf, requestDA.getObjectSize(), NULL, respSize);
	delete[] buf;

	if (!err.isNoError())
	{
		LOG4CPLUS_WARN(logger, static_cast<std::string>(err));
		ret = ERR_FAIL;
	} else
	{
		CDataAccessor responseDA;

		mDeallocateRequestResultCond.lock();
		{
			LOG4CPLUS_INFO(logger,
					"CConnectivityAgentProxy::deallocateChannel waiting for mLastRequestResultDA");
			while (mDeallocateRequestResultMap.find(channel_id) == mDeallocateRequestResultMap.end())
			{
				LOG4CPLUS_INFO(logger, "before wait");
				mDeallocateRequestResultCond.wait();
				LOG4CPLUS_INFO(logger, "after wait");
			}

			responseDA = mDeallocateRequestResultMap[channel_id];
			mDeallocateRequestResultMap.erase(channel_id);
		}
		mDeallocateRequestResultCond.unlock();

		if (responseDA.getData())
		{
			if ((E_DEALLOCATE_CHANNEL_RESP == responseDA.getOpCode())
					&& (channel_id == responseDA.getChannelID()))
			{
				UInt32 data = 0;
				memcpy(&data, responseDA.getData(), sizeof(UInt32));
				responseDA.resetAll();
				ret = static_cast<ERROR_CODE>(data);
			} else
			{
				LOG4CPLUS_ERROR(logger,
						"CConnectivityAgentProxy::deallocateChannel() => ERROR: wrong response type("
								+ convertIntegerToString(responseDA.getOpCode())
								+ ") from Agent  !!! ");
				ret = ERR_WRONG_SEQUENCE;
			}
		} else
		{
			LOG4CPLUS_INFO(logger, "CConnectivityAgentProxy::deallocateChannel() => "
					"channel already deleted form other side");
			ret = ERR_OK;
		}

	}

	if (ret != ERR_OK)
	{
		// something gone wrong, we need to restore information in registry
		mRegistryMutex.lockWrite();

		if (mChannelRegistry.find(channel_id) != mChannelRegistry.end())
		{
			LOG4CPLUS_WARN(logger, "CConnectivityAgentProxy::deallocateChannel: "
					"something gone wrong and I'm unable to restore channel info - "
					"there is a channel in registry with such id");
		} else
		{
			mChannelRegistry[channel_id] = info;
			info.mChannelBuffer.forgetData();
			LOG4CPLUS_INFO(logger,
					"CConnectivityAgentProxy::deallocateChannel:"
							"unable to delete channel " + convertIntegerToString(channel_id)
							+ ", so channel info is restored");
		}

		mRegistryMutex.unlockWrite();
	}

	mRegistryMutex.lockWrite();
	mChannelOnDeallocSet.erase(channel_id);
	mRegistryMutex.unlockWrite();

	return ret;
}