X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=Shares%2FmTaskShare.icl;fp=Shares%2FmTaskShare.icl;h=edd84d06d009c3e44bcc480ba507152ab2a795ca;hb=54c127405f2b7e0085d1c6ff48b6b496f5917dcf;hp=481d3ad9fa6f1a74a049f46793a6c0b8f957bc21;hpb=7d9088b54956fe56c36ca8d01ec386b48f0a1c47;p=mTask.git diff --git a/Shares/mTaskShare.icl b/Shares/mTaskShare.icl index 481d3ad..edd84d0 100644 --- a/Shares/mTaskShare.icl +++ b/Shares/mTaskShare.icl @@ -6,6 +6,7 @@ import Utils.Devices import iTasks import mTask import Data.List +import Data.Tuple from Data.Func import $ from StdFunc import flip @@ -66,6 +67,8 @@ makeShare withTask identifier value = {MTaskShare ,value=value } +if` i t e = if i t e + updateShareFromPublish :: MTaskDevice Int BCValue -> Task [MTaskShare] updateShareFromPublish dev ident val = updateShares dev $ map $ up ident val where @@ -90,33 +93,36 @@ cleanSharesTask taskid d = updateShares d id //TODO // up :: [String] MTaskShare -> MTaskShare // up ns s = {MTaskShare | s & withTask=[t\\t<-s.withTask|not (isMember t ns)]} +instance == MTaskShare where + (==) a b = a.identifier == b.identifier + getRealShare :: MTaskDevice MTaskShare -> Shared BCValue -getRealShare dev {identifier} = SDSSource {SDSSource +getRealShare dev share=:{identifier} = sdsFocus (Just identifier) $ SDSSource {SDSSource | name = "mTaskShareMap-" +++ toString identifier, read=rr, write=ww} where rr name iworld = case read deviceStore iworld of (Error e, iworld) = (Error e, iworld) (Ok devices, iworld) = case find ((==)dev) devices of Nothing = (Error $ exception "Device doesn't exist anymore", iworld) - Just {deviceShares} = case find (\s->s.identifier == identifier) deviceShares of + Just {deviceShares} = case find ((==)share) deviceShares of Nothing = (Error $ exception "Share doesn't exist", iworld) Just share = (Ok share.MTaskShare.value, iworld) // Also send messages ww name value iworld | not (trace_tn ("Update to: " +++ printToString value)) = undef - = case modify (\r->((), map (modFun value) r)) deviceStore iworld of + = case modify (tuple () o modifyValue value) deviceStore iworld of (Error e, iworld) = (Error e, iworld) (Ok _, iworld) = case sendMessagesIW [MTUpd identifier value] dev iworld of (Error e, iworld) = (Error e, iworld) - (Ok _, iworld) = (Ok $ const True, iworld) + (Ok _, iworld) = (Ok $ maybe True ((==) identifier), iworld) - //Selects the correct device - modFun value d - | d == dev = {d & deviceShares=map (modFun2 value) d.deviceShares} - = d + modifyValue :: BCValue [MTaskDevice] -> [MTaskDevice] + modifyValue v ds = filterMap ((==)dev) deviceUpdate ds + where + deviceUpdate d = {MTaskDevice | d + & deviceShares=filterMap ((==)share) shareUpd d.deviceShares} + shareUpd s = {MTaskShare | s & value=v} - //Selects the correct share - modFun2 value share - | identifier == share.MTaskShare.identifier = {MTaskShare | share & value=value} - = share + filterMap :: (a -> Bool) (a -> a) [a] -> [a] + filterMap f t xs = [if (f x) (t x) x\\x<-xs]