virtual void ReceivePacket(cDataPacket* packet, cPeer* peer, size_t channel){

		// the compiler will generate a jump table once the switch becomes large enough. This is extremly fast . . .
		switch(packet->GetID()){
			case(0):// login packet
				return ProcessLoginRequest(packet, peer);
			case(1):// chat message. I assume the chat message is formated correctly. In a real application, you should check the data to ensure it is valid and check to make sure the user is actually loged in before assuming to process the message
				return ProcessChatMessage(packet, peer);
			default:
				std::cout<<"packet type was unrecognized... ignoring"<<std::endl;
		};
	}
Exemple #2
0
RsslRet UPAProvider::ProcessRequest(RsslChannel* chnl, RsslBuffer* buffer)
{
    RsslRet ret = 0;
    RsslMsg msg = RSSL_INIT_MSG;
    RsslDecodeIterator dIter;

    // set up an iterator to decode the message
    rsslClearDecodeIterator(&dIter);
    rsslSetDecodeIteratorRWFVersion(&dIter, chnl->majorVersion, chnl->minorVersion);
    // and attach it top the message buffer
    rsslSetDecodeIteratorBuffer(&dIter, buffer);

    ret = rsslDecodeMsg(&dIter, &msg);				
    if (ret != RSSL_RET_SUCCESS)
    {
        t42log_error("UPAProvider::ProcessRequest - rsslDecodeMsg(): Error %d on channel fd=%d  Size %d \n", ret, chnl->socketId, buffer->length);
        RemoveChannelConnection(chnl);
        return RSSL_RET_FAILURE;
    }

    switch ( msg.msgBase.domainType )
    {
    case RSSL_DMT_LOGIN:
        if (ProcessLoginRequest(chnl, &msg, &dIter) != RSSL_RET_SUCCESS)
        {

            RemoveChannelConnection(chnl);
            return RSSL_RET_FAILURE;
        }
        break;
    case RSSL_DMT_SOURCE:

        if (ProcessSourceDirectoryRequest(chnl, &msg, &dIter) != RSSL_RET_SUCCESS)
        {
            RemoveChannelConnection(chnl);
            return RSSL_RET_FAILURE;
        }
        break;
    case RSSL_DMT_DICTIONARY:
        if (ProcessDictionaryRequest(chnl, &msg, &dIter) != RSSL_RET_SUCCESS)
        {
            RemoveChannelConnection(chnl);
            return RSSL_RET_FAILURE;
        }
        break;
    case RSSL_DMT_MARKET_PRICE:
    case RSSL_DMT_MARKET_BY_ORDER:
    case RSSL_DMT_SYMBOL_LIST:
    case RSSL_DMT_MARKET_BY_PRICE:
    case RSSL_DMT_YIELD_CURVE:
        if (ProcessItemRequest(chnl, &msg, &dIter) != RSSL_RET_SUCCESS)
        {
            RemoveChannelConnection(chnl);
            return RSSL_RET_FAILURE;
        }
        break;
    default:
          break;
    }


    return RSSL_RET_SUCCESS;
}