// up :: [String] MTaskShare -> MTaskShare
// up ns s = {MTaskShare | s & withTask=[t\\t<-s.withTask|not (isMember t ns)]}
-getRealShare :: MTaskDevice BCShare -> Shared BCValue
-getRealShare dev {sdsi} = SDSSource {SDSSource
- | name = "mTaskShareMap-" +++ toString sdsi, read=rr, write=ww}
+getRealShare :: MTaskDevice MTaskShare -> Shared BCValue
+getRealShare dev {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 == sdsi) deviceShares of
+ Just {deviceShares} = case find (\s->s.identifier == identifier) deviceShares of
Nothing = (Error $ exception "Share doesn't exist", iworld)
Just share = (Ok share.MTaskShare.value, iworld)
// Also send messages
- ww name value iworld = case modify (\r->((), map (modFun value) r)) deviceStore iworld of
+ ww name value iworld
+ | not (trace_tn ("Update to: " +++ printToString value)) = undef
+ = case modify (\r->((), map (modFun value) r)) deviceStore iworld of
(Error e, iworld) = (Error e, iworld)
- (Ok _, iworld) = case sendMessagesIW [MTUpd sdsi value] dev iworld of
+ (Ok _, iworld) = case sendMessagesIW [MTUpd identifier value] dev iworld of
(Error e, iworld) = (Error e, iworld)
(Ok _, iworld) = (Ok $ const True, iworld)
//Selects the correct share
modFun2 value share
- | sdsi == share.MTaskShare.identifier = {MTaskShare | share & value=value}
+ | identifier == share.MTaskShare.identifier = {MTaskShare | share & value=value}
= share
publish "/" $ const demo
] world
-demo = viewInformation "" [] "Hello world"
+demo = viewSharedInformation "Devices" [] deviceStore
+ >>* [OnValue $ ifValue pred (cont o hd)]
+ where
+ pred [] = False
+ pred [x:_] = not $ isEmpty x.deviceShares
+
+ cont :: MTaskDevice -> Task ()
+ cont dev = updateSharedInformation "Blinkyblink" [] (getRealShare dev (hd dev.deviceShares))
+ >>| cont dev
+
mTaskManager :: Task ()
mTaskManager = startupDevices >>| anyTask