コード例 #1
0
ファイル: controller.cpp プロジェクト: shoupon/lock-protocol
int Controller::nullInputTrans(vector<MessageTuple*>& outMsgs,
                               bool& high_prob, int startIdx ) 
{ 
    outMsgs.clear();
    high_prob = true ;
    if( startIdx < 0 )
        return -1;
    else if( startIdx >= 0 ) {
        // check for initiation
        size_t i = 0 ;
        int count = startIdx;
        while( i < _busy.size() ) {
            if( _busy[i] == -1 && _actives[i] == true ) {
                if (count)
                    count--;
                else {
                    // merge start event
                    int f = _nbrs[i].front().first ;
                    int b = _nbrs[i].front().second ;
                    // create response
                    int dstId = machineToInt(Lock_Utils::getLockName((int)i));
                    int dstMsgId = messageToInt("init");            
                    ControllerMessage* initMsg
                        = new ControllerMessage(0,dstId, 0,dstMsgId,macId());
                    initMsg->addParams(_time, f, b);
                    outMsgs.push_back(initMsg);                    
                    // Change state
                    _busy[i] = _time ;
                    _time++;
                    return startIdx + 1;
                }               
            }
            ++i ;
        }
        // the startIdx exceeds the number of available vehicles
        return -1;
    }
    return -1;
}
コード例 #2
0
ファイル: cycle.cpp プロジェクト: skiegyt/prob_verify
int Cycle::nullInputTrans(vector<MessageTuple*>& outMsgs, bool& high_prob, int startIdx)
{
    high_prob = true ;
    outMsgs.clear() ;
    
    if( startIdx == 0 ) {
        for( int ii = 0 ; ii < _allMacs.size() ; ++ii ) {
            MessageTuple* fire = new SyncMessage(0, _allMacs[ii]->macId(),
                                                 0, messageToInt("DEADLINE"),
                                                 macId(), false, _nextDl) ;
            outMsgs.push_back(fire);
        }
        
        _nextDl++;
        if( _nextDl == _numDl )
            _nextDl = 0 ;
        
        return 3;
    }
    else
        return -1 ;
}