예제 #1
0
Channel::Channel(int from, int to)
    : origin_(from), destination_(to) {
   stringstream ss_channel_name;
   ss_channel_name << CHANNEL_NAME << "(" << from << "," << to << ")";
   channel_name_ = ss_channel_name.str();
   setId(machineToInt(channel_name_));
   stringstream ss_destination_name;
   ss_destination_name << LOCK_NAME << "(" << to << ")";
   destination_id_ = machineToInt(ss_destination_name.str());
}
예제 #2
0
Controller::Controller( Lookup* msg, Lookup* mac, int num )
: StateMachine(msg, mac), _numVehs(num), _time(0)
{ 
    _name = "controller" ;
    setId(machineToInt(_name));
    _actives.resize(num,false);
    reset();
}
예제 #3
0
Cycle::Cycle( int numDeadline, Lookup* msg, Lookup* mac)
: Sync(numDeadline, msg, mac)
{
    setId(machineToInt("sync"));
    reset() ;
    _actives.resize(numDeadline, true);
    _nextDl = 0 ;
}
예제 #4
0
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;
}