module Simulation.Aivika.GPSS.Block.Preempt
(preemptBlock,
PreemptBlockMode(..),
defaultPreemptBlockMode,
toFacilityPreemptMode,
fromFacilityPreemptMode) where
import Simulation.Aivika
import Simulation.Aivika.GPSS.Transact
import Simulation.Aivika.GPSS.Block
import Simulation.Aivika.GPSS.Facility
data PreemptBlockMode a =
PreemptBlockMode { preemptBlockPriorityMode :: Bool,
preemptBlockTransfer :: Maybe (Maybe Double -> Block (Transact a) ()),
preemptBlockRemoveMode :: Bool
}
toFacilityPreemptMode :: PreemptBlockMode a -> FacilityPreemptMode a
toFacilityPreemptMode m =
FacilityPreemptMode { facilityPriorityMode = preemptBlockPriorityMode m,
facilityTransfer = transfer,
facilityRemoveMode = preemptBlockRemoveMode m
}
where
transfer =
case preemptBlockTransfer m of
Nothing -> Nothing
Just f -> Just (\a dt -> blockProcess (f dt) a)
fromFacilityPreemptMode :: FacilityPreemptMode a -> PreemptBlockMode a
fromFacilityPreemptMode m =
PreemptBlockMode { preemptBlockPriorityMode = facilityPriorityMode m,
preemptBlockTransfer = transfer,
preemptBlockRemoveMode = facilityRemoveMode m
}
where
transfer =
case facilityTransfer m of
Nothing -> Nothing
Just f -> Just (\dt -> Block $ \a -> f a dt)
defaultPreemptBlockMode :: PreemptBlockMode a
defaultPreemptBlockMode =
PreemptBlockMode { preemptBlockPriorityMode = False,
preemptBlockTransfer = Nothing,
preemptBlockRemoveMode = False
}
preemptBlock :: Facility a
-> PreemptBlockMode a
-> Block (Transact a) (Transact a)
preemptBlock r m =
Block { blockProcess = \a -> preemptFacility r a (toFacilityPreemptMode m) >> return a }