Ejemplo n.º 1
0
	int64 CLinkerPipe::PushMsgToSend(CMsg& Msg,bool bUrgence){
		
		assert(Msg.IsValid());
		
		CLock lk(m_Mutex,this);
		
		ePipeline& Sender = Msg.GetSender();
		ePipeline& Receiver = Msg.GetReceiver();
        ePipeline& Letter   = Msg.GetLetter();
		
		int64 MsgID = Letter.GetID();
        assert(MsgID != 0);
        if (MsgID==0)
        {
			return 0;
        }

		int64 EventID = Msg.GetEventID();

		//把本地发送者地址用一个INT64代替
		int64 SenderID = LocalAddress2SenderID(Sender);	
		Sender.Clear();
		Sender.PushInt(SenderID);
		
		//用时间戳代替源ID,对方返回此时间戳表示正常接受
		int64 TimeStamp = CreateTimeStamp();
        Msg.SetSourceID(TimeStamp);

		ePipeline* MsgPtr = (ePipeline*)Msg.Release();
		Encrypt(MsgPtr);

		ePipeline Info;
		Info.PushInt(MsgID);
		Info.PushInt(EventID);
		Info.PushInt(TimeStamp);
		Info.PushInt(m_PendingMsgID);
		Info.PushInt(Size());
		Info.PushInt(m_UrgenceMsg.Size());
		m_Parent->NotifyLinkerState(this,LINKER_PUSH_MSG,Info);

		if (bUrgence)
		{
			m_UrgenceMsg.Push_Directly(MsgPtr);
		}else{
			Push_Directly(MsgPtr);
		}
		return MsgID;
	}; 
Ejemplo n.º 2
0
/// Routes the message to a remote or local destination
CMsg CMsgObjectInfo::Send( CMsg &x_rMsg )
{
    // Sanity check
    if ( !x_rMsg.IsValid() )
        return CMsg();

    // Can't be routed without an id
    if ( guid::CmpGuid( &IID_ZEROS, &x_rMsg.Mi().Dst()->GetId() ) )
        return CMsg();

    // Set our id in the return address
    x_rMsg.Mi().Src()->SetInstance( &m_guidId );

    // Is it for us?
    if ( guid::CmpGuid( &IID_ZEROS, &x_rMsg.Mi().Dst()->GetInstance() )
         || guid::CmpGuid( &m_guidId, &x_rMsg.Mi().Dst()->GetInstance() ) )
    {   
        // Short circuit the reply queue if needed
        if ( x_rMsg.Mi().WantReply() )
        {
            // Create reply signal
            x_rMsg.EnableReplyEvent( oexTRUE );

            // Set direct reply flag
            x_rMsg.SetDirectReply( oexTRUE );

        } // end if

        // Receive the message
        Recv( x_rMsg );
        
        return x_rMsg;

    } // end if

    // Send through the network
    return oexNet.Send( x_rMsg );
}
Ejemplo n.º 3
0
oexBOOL CMsgObjectInfo::Recv( CMsg &x_rMsg )
{
    // Sanity check
    if ( !x_rMsg.IsValid() )
        return oexFALSE;

    // Can't route without an id
    if ( guid::CmpGuid( &IID_ZEROS, &x_rMsg.Mi().Dst()->GetId() ) )
        return oexFALSE;

    // Lock the handler list
    CTlLocalLock ll( m_lockMsgQueue );
    if ( !ll.IsLocked() )
        return oexFALSE;

    // Grab the priority
    oexUINT uPriority = x_rMsg.GetPriority();

    // Lowest priority?
    if ( !uPriority )
        m_lstMsgQueue.Append( x_rMsg );

    else
    {
        // Priority based insert
        oexBOOL bInserted = oexFALSE;
        for ( t_MsgQueue::iterator itInsert; 
              !bInserted && m_lstMsgQueue.Next( itInsert ); )
        {
            // Look for a lower priority object
            if ( itInsert.Obj().GetPriority() < uPriority )
            {
                // Put the command ahead of this item
                t_MsgQueue::iterator it = m_lstMsgQueue.Append( x_rMsg );
                
                // Did we get a valid object?
                if ( it.IsValid() )
                {
                    // Move to correct location
                    m_lstMsgQueue.MoveBefore( it, itInsert );

                    // Check the result
                    bInserted = oexTRUE;

                } // end if

            } // end if

        } // end for

        // Just stick it on the end if we couldn't find a spot
        if ( !bInserted )
            m_lstMsgQueue.Append( x_rMsg );

    } // end else

    // Set event if message is in the queue
    if ( m_lstMsgQueue.Size() )
        m_evMsgWaiting.Set();

    // Hand down
    return oexTRUE;
}