Exemplo n.º 1
0
    def Pass(self, sequenceNo):
        """SequenceNo must be a monotonously incrementing integer"""
        if self.closed:
            return
        if self.expected is None:
            self.expected = sequenceNo
        if sequenceNo < self.expected:
            return
        while sequenceNo > self.expected:
            me = (sequenceNo, stackless.getcurrent())
            heapq.heappush(self.queue, me)
            self.OnSleep(sequenceNo)
            stackless.schedule_remove()
            self.OnWakeUp(sequenceNo)
            if self.closed:
                return

        self.Assert(self.expected == sequenceNo)
        self.expected += 1
        expected = self.expected
        while self.queue and self.queue[0][0] == expected:
            self.OnWakingUp(sequenceNo, expected)
            expected += 1
            other = heapq.heappop(self.queue)
            other[1].insert()

        if self.lastThrough is not None:
            self.Assert(self.lastThrough + 1 == sequenceNo)
        self.lastThrough = sequenceNo
Exemplo n.º 2
0
    def Pass(self, sequenceNo):
        if self.closed:
            return
        if self.expected is None:
            self.expected = sequenceNo
        if sequenceNo < self.expected:
            return
        while sequenceNo > self.expected:
            me = (sequenceNo, stackless.getcurrent())
            heapq.heappush(self.queue, me)
            self.OnSleep(sequenceNo)
            stackless.schedule_remove()
            self.OnWakeUp(sequenceNo)
            if self.closed:
                return

        self.Assert(self.expected == sequenceNo)
        self.expected += 1
        expected = self.expected
        while self.queue and self.queue[0][0] == expected:
            self.OnWakingUp(sequenceNo, expected)
            expected += 1
            other = heapq.heappop(self.queue)
            other[1].insert()

        if self.lastThrough is not None:
            self.Assert(self.lastThrough + 1 == sequenceNo)
        self.lastThrough = sequenceNo
Exemplo n.º 3
0
    def AddTrigger(self, trigger):
        for t in self.triggers:
            if trigger.moduleID == t.moduleID:
                sm.services['FxSequencer'].LogWarn(
                    'Activation: Duplicate Activations for a Module')
                return

        heapq.heappush(self.triggers, trigger)
        stampUpdated = self.UpdateRepeatTime()
        if self.effect is None:
            try:
                self.effect = self.GetEffectFromGuid(trigger.guid, trigger)
            except:
                self.effect = CreateInstance('effects.GenericEffect',
                                             (trigger, ))
                log.LogException()
                sys.exc_clear()

            self.balls = set(self.effect.GetBalls())
            self.PrepareAndStart()
            self.isOn = True
        else:
            self.balls.add(trigger.shipID)
            self.balls.add(trigger.targetID)
        return stampUpdated
Exemplo n.º 4
0
 def AddEffect(self, effect, priority = lightfxConstants.LFX_NORMAL_PRIORITY):
     if not isinstance(effect, LedEffect):
         raise TypeError('effect must be a LedEffect or a subclass thereof.')
     if not self.Enabled() or not self.IsLightFxSupported():
         return
     effect.SetManager(self.ledFx)
     heapq.heappush(self.effects, (priority, effect))
     self.LogInfo('Adding effect. Total:', len(self.effects))
Exemplo n.º 5
0
 def AddEffect(self, effect, priority=lightfxConstants.LFX_NORMAL_PRIORITY):
     if not isinstance(effect, LedEffect):
         raise TypeError(
             'effect must be a LedEffect or a subclass thereof.')
     if not self.Enabled() or not self.IsLightFxSupported():
         return
     effect.SetManager(self.ledFx)
     heapq.heappush(self.effects, (priority, effect))
     self.LogInfo('Adding effect. Total:', len(self.effects))
Exemplo n.º 6
0
    def AddActivationToSequencer(self, activation):
        currentStopTime = activation.stamp
        reschedule = True
        if self.stopCandidates:
            if self.stopCandidates[0].stamp <= currentStopTime:
                reschedule = False
        heapq.heappush(self.stopCandidates, activation)
        if reschedule:
            try:
                self.LogInfo('\t\tAddActivationToSequencer: just going for some rescheduling here')
                blue.pyos.synchro.WakeupAtSim(self.sequencerTasklet, currentStopTime)
            except:
                self.LogInfo('\t\tAddActivationToSequencer: Activation rescedule failed, sequencer will wake up by itself')
                sys.exc_clear()

        self.LogInfo('\t\tAddActivationToSequencer: Activation added')
Exemplo n.º 7
0
    def GetSortedRoutesForPin(self, pinID, commodities):
        processorRoutes = []
        storageRoutes = []
        with bluepy.TimerPush('SortingRoutes'):
            for (destID, commodityTypeID), qty in self.megaRoutesBySource.get(pinID, {}).iteritems():
                if not qty:
                    continue
                if commodityTypeID not in commodities:
                    continue
                destPin = self.GetPin(destID)
                if destPin.IsProcessor():
                    heapq.heappush(processorRoutes, (destPin.GetInputBufferState(), (destID, commodityTypeID, qty)))
                else:
                    heapq.heappush(storageRoutes, (destPin.GetFreeSpace(), (destID, commodityTypeID, qty)))

        return (processorRoutes, storageRoutes)
Exemplo n.º 8
0
    def AddActivationToSequencer(self, activation):
        currentStopTime = activation.stamp
        reschedule = True
        if self.stopCandidates:
            if self.stopCandidates[0].stamp <= currentStopTime:
                reschedule = False
        heapq.heappush(self.stopCandidates, activation)
        if reschedule:
            try:
                self.LogInfo('\t\tAddActivationToSequencer: just going for some rescheduling here')
                blue.pyos.synchro.WakeupAtSim(self.sequencerTasklet, currentStopTime)
            except:
                self.LogInfo('\t\tAddActivationToSequencer: Activation rescedule failed, sequencer will wake up by itself')
                sys.exc_clear()

        self.LogInfo('\t\tAddActivationToSequencer: Activation added')
Exemplo n.º 9
0
    def CheckForStopCandidates(self):
        now = blue.os.GetSimTime()
        while self.stopCandidates and self.stopCandidates[0].isZombie:
            heapq.heappop(self.stopCandidates)

        while self.stopCandidates and self.stopCandidates[0].stamp < now:
            activation = heapq.heappop(self.stopCandidates)
            state = activation.Repeat()
            if state == -1:
                self.LogInfo('FxSequencer::CheckForStopCandidates: activation expired')
                self.RemoveActivation(activation)
            else:
                heapq.heappush(self.stopCandidates, activation)
            while self.stopCandidates and self.stopCandidates[0].isZombie:
                heapq.heappop(self.stopCandidates)

            now = blue.os.GetSimTime()
Exemplo n.º 10
0
    def CheckForStopCandidates(self):
        now = blue.os.GetSimTime()
        while self.stopCandidates and self.stopCandidates[0].isZombie:
            heapq.heappop(self.stopCandidates)

        while self.stopCandidates and self.stopCandidates[0].stamp < now:
            activation = heapq.heappop(self.stopCandidates)
            state = activation.Repeat()
            if state == -1:
                self.LogInfo('FxSequencer::CheckForStopCandidates: activation expired')
                self.RemoveActivation(activation)
            else:
                heapq.heappush(self.stopCandidates, activation)
            while self.stopCandidates and self.stopCandidates[0].isZombie:
                heapq.heappop(self.stopCandidates)

            now = blue.os.GetSimTime()
Exemplo n.º 11
0
    def AddTrigger(self, trigger):
        if self.TriggerAlreadyExists(trigger):
            return
        heapq.heappush(self.triggers, trigger)
        stampUpdated = self.UpdateRepeatTime()
        if self.effect is None:
            try:
                self.effect = self.GetEffectFromGuid(trigger.guid, trigger)
            except:
                self.effect = effects.GenericEffect(trigger)
                log.LogException()
                sys.exc_clear()

            self.balls = set(self.effect.GetBalls())
            self.PrepareAndStart()
            self.isOn = True
        else:
            self.balls.add(trigger.shipID)
            self.balls.add(trigger.targetID)
        return stampUpdated
Exemplo n.º 12
0
    def AddTrigger(self, trigger):
        if self.TriggerAlreadyExists(trigger):
            return
        heapq.heappush(self.triggers, trigger)
        stampUpdated = self.UpdateRepeatTime()
        if self.effect is None:
            try:
                self.effect = self.GetEffectFromGuid(trigger)
            except:
                self.effect = GenericEffect(trigger)
                log.LogException()
                sys.exc_clear()

            self.balls = set(self.effect.GetBalls())
            self.PrepareAndStart()
            self.isOn = True
        else:
            self.balls.add(trigger.shipID)
            self.balls.add(trigger.targetID)
        return stampUpdated
Exemplo n.º 13
0
    def AddTrigger(self, trigger):
        for t in self.triggers:
            if trigger.moduleID == t.moduleID:
                sm.services['FxSequencer'].LogWarn('Activation: Duplicate Activations for a Module')
                return

        heapq.heappush(self.triggers, trigger)
        stampUpdated = self.UpdateRepeatTime()
        if self.effect is None:
            try:
                self.effect = self.GetEffectFromGuid(trigger.guid, trigger)
            except:
                self.effect = CreateInstance('effects.GenericEffect', (trigger,))
                log.LogException()
                sys.exc_clear()

            self.balls = set(self.effect.GetBalls())
            self.PrepareAndStart()
            self.isOn = True
        else:
            self.balls.add(trigger.shipID)
            self.balls.add(trigger.targetID)
        return stampUpdated
Exemplo n.º 14
0
 def AddTimer(self, pinID, runTime):
     self.LogInfo('AddTimer :: pinID', pinID, 'at', runTime)
     heapq.heappush(self.simQueue, (runTime, pinID))
Exemplo n.º 15
0
 def __setitem__(self, key, val):
     super(priority_dict, self).__setitem__(key, val)
     if len(self._heap) < 2 * len(self):
         heapq.heappush(self._heap, (val, key))
     else:
         self._rebuild_heap()
Exemplo n.º 16
0
 def AddTimer(self, pinID, runTime):
     self.LogInfo('AddTimer :: pinID', pinID, 'at', runTime)
     heapq.heappush(self.simQueue, (runTime, pinID))
Exemplo n.º 17
0
 def __setitem__(self, key, val):
     super(priority_dict, self).__setitem__(key, val)
     if len(self._heap) < 2 * len(self):
         heapq.heappush(self._heap, (val, key))
     else:
         self._rebuild_heap()