Ejemplo n.º 1
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;
}