1 implementation module Shares.mTaskShare
9 from Data.Func import $
10 from StdFunc import flip
12 derive class iTask MTaskShareType, MTaskShare
14 manageShares :: [MTaskShare] -> Task ()
15 manageShares shares = withShared Nothing $ \cs->forever $
16 (viewSharesGrid cs shares -|| updateShares shares <<@ ArrangeVertical)
18 updateShares :: [MTaskShare] -> Task BCValue
19 updateShares shares = anyTask (map updateS shares) <<@ ArrangeWithTabs
21 updateS :: MTaskShare -> Task BCValue
22 updateS sh = flip (<<@) (Title $ toString sh.identifier) $ forever $
23 viewSharedInformation "Current value" [] (getSDSShare sh)
25 updateSharedInformation "New value" [] (getSDSShare sh)
26 >>= \nv->allTasks (map getDevice sh.withDevice)
27 >>= \devs->allTasks (map (sendMessages [MTUpd sh.identifier nv]) devs)
32 viewSharesGrid :: (Shared (Maybe MTaskShare)) [MTaskShare] -> Task [BCValue]
33 viewSharesGrid _ [] = viewInformation "No shares yet" [] []
34 viewSharesGrid cs sh = (allTasks [watch (getSDSShare m)\\m<-sh] <<@ NoUserInterface)
35 >&^ \st->flip (<<@) NoUserInterface $ whileUnchanged st $ \mshs->enterChoice "" [ChooseFromGrid id]
36 [{MTaskShare|ss&value=s}\\s<-fromJust mshs & ss<-sh]
37 >>* [OnValue (withValue $ \s->Just (set (Just s) cs))]
40 viewShare :: MTaskShare -> Task BCValue
41 viewShare m = viewSharedInformation "" [] (getSDSShare m)
42 <<@ Title ("SDS: " +++ toString m.identifier)
44 getSDSShare :: MTaskShare -> Shared BCValue
45 getSDSShare s=:{realShare=(MTaskWithShare id),value} = memoryShare id value
47 makeShare :: String String Int BCValue -> Task MTaskShare
48 makeShare withTask withDevice identifier value = treturn
51 ,withDevice=[withDevice]
52 ,identifier=identifier
54 ,realShare=MTaskWithShare $ "mTaskSDS-" +++ toString identifier
55 } >>= \sh->set value (getSDSShare sh) >>| treturn sh
57 updateShare :: Int BCValue -> Task ()
58 updateShare ident val = get sdsStore
59 >>= \sh->(case find (\s->s.identifier==ident) sh of
60 Nothing = abort "Help, no share found with this ident"
61 Just mts = set val (getSDSShare mts))
62 >>| traceValue "Updated" @! ()