Ejemplo n.º 1
0
// Consider merging this funciton with nullInputTransit()
int Fsm::transit(MessageTuple* inMsg, vector<MessageTuple*>& outMsgs, bool& high_prob, int startIdx )
{
    State* cs = _states[_current];
    outMsgs.clear();

    // Go through the possible transitions, find that matches the message
    for( int tid = startIdx ; tid < cs->getNumTrans(); ++tid ) {
        Transition tr = cs->getTrans((int)tid);

        if( tr.getFromMachineId() == inMsg->subjectId() && tr.getInputMessageId() == inMsg->destMsgId() ) {
            // Matching found. Get all the outLabels
            for( size_t oid = 0 ; oid < tr.getNumOutLabels() ; ++oid ) {
                OutLabel lbl = tr.getOutLabel(oid);
                MessageTuple* out = new FsmMessage(tr.getFromMachineId(), lbl.first,
                                tr.getInputMessageId(), lbl.second, _macLookup->toInt(this->_name)) ;
                outMsgs.push_back(out);
            }

            // Change state
            State* next = cs->getNextState((int)tid);
            _current = next->getID();
            
            if( tr.isHigh() )
                high_prob = true;
            else
                high_prob = false;
            
            return tid+1;
        }
    }

    // The function will get to this line when no more matching transition is found
    return -1;
}