Exemplo n.º 1
0
	void ManagerImpl::nowIs(Time t) {
		static bool beenHere = false;

		if (!beenHere) {
			beenHere = true;
			//cout <<__FILE__<<":"<< __LINE__<< " doing preprocess" << endl;
			
			//cout << "network=" << network.ptr() << endl;
			//cout << "conn=" << network->connectivity().ptr() << endl;
			Shipping::Connectivity::Ptr c = const_cast<Shipping::Connectivity*>(network_->connectivity().ptr());
			c->simulationStatusIs(Shipping::Connectivity::running());
			//cout <<__FILE__<<":"<< __LINE__<< " end preprocess" << endl;
		}

		if (t < now_) return;
		cout << "Time is " << t.value() << endl;
		
		//find the most recent activites to run and run them in order
		while (!scheduledActivities_.empty()) {
			
			//figure out the next activity to run
			Activity::Ptr nextToRun = scheduledActivities_.top();

			//if the next time is greater than the specified time, break
			//the loop
			if (nextToRun->nextTime() > t) {
				break;
			}
			
			//calculate amount of time to sleep
			Time diff = Time(nextToRun->nextTime().value() - now_.value());
			
			if (managerType() == ManagerImpl::realtime()) {
				//cout << "going to sleep" << endl;
				//sleep 1s (1,000,000 microseconds) for every unit of time
				usleep(( (diff.value()) * 200000 ));
			}
			
			now_ = nextToRun->nextTime();

			//run the minimum time activity and remove it from the queue
			scheduledActivities_.pop();

			nextToRun->statusIs(Activity::executing);
			nextToRun->statusIs(Activity::free);

		}
		
		//syncrhonize the time
		now_ = t;
	}
Exemplo n.º 2
0
    void ManagerImpl::nowIs(Time t) {
	//find the most recent activites to run and run them in order
	while (!scheduledActivities_.empty()) {
	    
	    //figure out the next activity to run
	    Activity::Ptr nextToRun = scheduledActivities_.top();

	    //if the next time is greater than the specified time, break
	    //the loop
	    if (nextToRun->nextTime().value() > t.value()) {
		break;
	    }
	    
	    //calculate amount of time to sleep
	    Time diff = Time(nextToRun->nextTime().value() - now_.value());
	    
	    //sleep 100ms (100,000 microseconds) for every unit of time
	    //Sleep only for the real time activity manager
	    if(realTime_){
	    	usleep(( ((int)diff.value()) * 100000));
	    }
	    
	    now_ = nextToRun->nextTime();

	    //run the minimum time activity and remove it from the queue
	    scheduledActivities_.pop();

	    if(nextToRun->status() != Activity::deleted)
	    	nextToRun->statusIs(Activity::executing);

	    if(nextToRun->status() != Activity::deleted && nextToRun->status() != Activity::waiting){
	    	nextToRun->statusIs(Activity::free);
	    }
	}

	//syncrhonize the time
	now_ = t;
    }