X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=Utils%2FSDS.icl;h=afd1c6c4f0e41fc25c928c81d1a81d90b2cf4b3a;hb=17aaf6797b3dd4e820b186a55335a36a89ea92cb;hp=9975d275feda16cb072aadcd1e0ef13e16a1ead0;hpb=5eea2c72f8347401784746b5ca3aee99799e49fb;p=mTask.git diff --git a/Utils/SDS.icl b/Utils/SDS.icl index 9975d27..afd1c6c 100644 --- a/Utils/SDS.icl +++ b/Utils/SDS.icl @@ -18,6 +18,10 @@ memoryShare s d = sdsFocus s $ memoryStore s $ Just d deviceStoreNP :: Shared [MTaskDevice] deviceStoreNP = sdsFocus Nothing $ deviceStore +import GenPrint, TTY +derive gPrint MTaskDevice, Maybe, MTaskShare, MTaskResource, TaskId, MTaskTask, (,), TTYSettings, TCPSettings, DateTime, Parity, BaudRate, ByteSize, MaybeError, () +gPrint{|Dynamic|} _ st = gPrint{|*|} "**Dynamic**" st + deviceStore :: RWShared (Maybe (MTaskDevice, Int)) [MTaskDevice] [MTaskDevice] deviceStore = SDSSource {SDSSource | name = "deviceStore" @@ -25,11 +29,17 @@ deviceStore = SDSSource {SDSSource , write= realWrite } where + realRead p iw + | not (trace_tn $ "read called with: " +++ printToString p) = undef + = read realDeviceStore iw + realWrite mi w iw + | not (trace_tn $ "write called with: " +++ printToString mi +++ " w " +++ printToString w) = undef # (merr, iw) = write w realDeviceStore iw - | isError merr || isNothing mi = (merr $> const True, iw) + | not (trace_tn $ "written to real store: " +++ printToString merr) = undef + | isError merr || isNothing mi = (merr $> notifyPred mi, iw) # (Just (dev, ident)) = mi - | ident == -1 = (merr $> const True, iw) + | ident == -1 = (merr $> notifyPred mi, iw) = case find ((==)dev) w of Nothing = (Error $ exception "Device doesn't exist anymore", iw) Just {deviceShares} = case find (\d->d.identifier == ident) deviceShares of @@ -38,14 +48,22 @@ where | not $ trace_tn "Really sending a message from a share update" = undef = case sendMessagesIW [MTUpd ident s.MTaskShare.value] dev iw of (Error e, iw) = (Error e, iw) - (Ok _, iw) = (Ok $ lens mi, iw) + (Ok _, iw) = (Ok $ notifyPred mi, iw) - lens Nothing (Just p) = False - lens Nothing Nothing = True - lens (Just (d1, i1)) (Just (d2, i2)) = d1 == d2 && (i2 == -1 || i1 == i2) + notifyPred :: (Maybe (MTaskDevice, Int)) (Maybe (MTaskDevice, Int)) -> Bool + // Global watcher looking at a global event + notifyPred Nothing Nothing = True + // Global watcher looking at a local event + notifyPred Nothing (Just _) = False + // Local watcher looking at a global event + notifyPred (Just _) Nothing = False + // Local device watcher looking at a local event + notifyPred (Just (d1, -1)) (Just (d2, _)) = d1 == d2 + // Local share watcher looking at a local share event + notifyPred (Just (d1, i1)) (Just (d2, i2)) = d1 == d2 && i1 == i2 realDeviceStore :: Shared [MTaskDevice] -realDeviceStore = sharedStore "mTaskDevices" [] +realDeviceStore = memoryShare "mTaskDevices" [] bcStateStore :: Shared BCState bcStateStore = memoryShare "mTaskBCState" zero