示例#1
0
void CMultiXProcess::CancelMsg(CMultiXAppMsgID &ID,bool	bTimedout)
{
    CMultiXAppMsg	*Msg	=	ID.GetObject();
    if(Msg)
    {
        if(Msg->MultiXMsg()->m_SendSem.Initialized())
            Msg->MultiXMsg()->m_SendSem.Lock();
        ID.RemoveObject();
        Msg->m_bKeep	=	false;

        CMultiXSession	*Session	=	Owner()->FindSession(Msg->SessionID());
        if(bTimedout)
        {
            if(Session)
            {
                if(Msg->IsCtrlMsgToTpm())
                    OnSendMsgToTpmTimedout(*Msg);
                else
                    Session->OnSendMsgTimedoutNV(*Msg);
            }	else
            {
                if(Msg->IsCtrlMsgToTpm())
                    OnSendMsgToTpmTimedout(*Msg);
                else
                    OnSendMsgTimedout(*Msg);
            }
        }	else
        {
            if(Session)
            {
                if(Msg->IsCtrlMsgToTpm())
                    OnSendMsgToTpmFailed(*Msg);
                else
                    Session->OnSendMsgFailedNV(*Msg);
            }	else
            {
                if(Msg->IsCtrlMsgToTpm())
                    OnSendMsgToTpmFailed(*Msg);
                else
                    OnSendMsgFailed(*Msg);
            }
        }
        if(!Msg->m_bKeep)
            delete	Msg;
    }

}
示例#2
0
bool CMultiXProcess::OnAppMsg(CMultiXMsg &Msg)
{
    if(!ReceiverEnabled()	||	!SenderEnabled())
        return	false;
    CMultiXAppMsg	*OrgMsg	=	NULL;
    CMultiXSession	*Session	=	NULL;
    CMultiXAppMsg	*AppMsg	=	CreateNewAppMsg(&Msg);
    //if(m_MsgCount++	==	1)
//		m_LastPrintTime	=	Owner()->GetMilliClock();
    m_LastMsgRecvMilliClock	=	Owner()->GetMilliClock();

    AddToMsgQueue(m_pInQueue,AppMsg);

    if(!AppMsg->ResponseRequired())
    {
        if(AppMsg->NotifyAny())
            AppMsg->Reply(MultiXNoError);
    }

    if(AppMsg->IsResponse())
    {
        OrgMsg	=	AppMsg->ReceiverMsgID().GetObject();
        if(OrgMsg	!=	NULL)
        {
            Session	=	Owner()->FindSession(OrgMsg->SessionID());
            OrgMsg->m_bKeep	=	false;
            OrgMsg->ID().RemoveObject();

            if(AppMsg->AppDataSize()	||	OrgMsg->ResponseRequired())
            {
                if(Session)
                {
                    if(AppMsg->IsCtrlMsgFromTpm())
                        Session->OnDataReplyFromTpmReceived(*AppMsg,*OrgMsg);
                    else
                        Session->OnDataReplyReceivedNV(*AppMsg,*OrgMsg);
                }	else
                {
                    if(AppMsg->IsCtrlMsgFromTpm())
                        OnDataReplyFromTpmReceived(*AppMsg,*OrgMsg);
                    else
                        OnDataReplyReceived(*AppMsg,*OrgMsg);
                }
            }	else if(AppMsg->Error())
            {
                if(OrgMsg->NotifyError())
                {
                    if(Session)
                    {
                        if(AppMsg->IsCtrlMsgFromTpm())
                            Session->OnSendMsgToTpmFailed(*OrgMsg);
                        else
                            Session->OnSendMsgFailedNV(*OrgMsg);
                    }	else
                    {
                        if(AppMsg->IsCtrlMsgFromTpm())
                            OnSendMsgToTpmFailed(*OrgMsg);
                        else
                            OnSendMsgFailed(*OrgMsg);
                    }
                }
            }	else
            {
                if(OrgMsg->NotifySuccess())
                {
                    if(Session)
                    {
                        if(AppMsg->IsCtrlMsgFromTpm())
                            Session->OnSendMsgToTpmCompleted(*OrgMsg);
                        else
                            Session->OnSendMsgCompletedNV(*OrgMsg);
                    }	else
                    {
                        if(AppMsg->IsCtrlMsgFromTpm())
                            OnSendMsgToTpmCompleted(*OrgMsg);
                        else
                            OnSendMsgCompleted(*OrgMsg);
                    }
                }
            }
        }	else	//	it is a response but the original does not exist
        {
            AppMsg->Reply(TpmErrUnableToForwardMsg);
        }
    }	else
    {
        Session	=	Owner()->FindSession(AppMsg->SessionID(),true);
        if(Session)
        {
            if(AppMsg->IsCtrlMsgFromTpm())
                Session->OnNewMsgFromTpm(*AppMsg);
            else
                Session->OnNewMsgNV(*AppMsg);
        }	else
        {
            if(AppMsg->IsCtrlMsgFromTpm())
                OnNewMsgFromTpm(*AppMsg);
            else
                OnNewMsg(*AppMsg);
        }
        if(AppMsg->ResponseRequired()	&&	!(AppMsg->ReplySent()	||	AppMsg->m_bKeep))
            Throw();
    }

    if(!(AppMsg->ReplySent()	||	AppMsg->m_bKeep))
    {
        if(AppMsg->ResponseRequired())
            Throw();
        else if(AppMsg->NotifyAny())
            AppMsg->Reply(MultiXNoError);
    }

    if(OrgMsg	&&	!OrgMsg->m_bKeep)
        delete	OrgMsg;
    if(!AppMsg->m_bKeep)
        delete	AppMsg;
    return	true;
}