3 import StdDebug, StdMisc
4 from StdFunc import flip
8 import Devices.mTaskDevice
9 import Shares.mTaskShare
13 from Text import class Text(startsWith,concat,split,join), instance Text String
15 import qualified Data.Map as DM
17 from Data.Func import $
20 import System.Directory
22 import iTasks._Framework.Store
23 import iTasks._Framework.Serialization
27 Start world = startEngine [
28 publish "/manage" $ const $ mTaskManager
29 >>* [OnAction (Action "Shutdown") (always $ shutDown)],
30 publish "/" $ const demo
33 demo = viewSharedInformation "Devices" [] deviceStore
34 >>* [OnValue $ ifValue pred (cont o hd)]
37 pred [x:_] = not $ isEmpty x.deviceShares
39 cont :: MTaskDevice -> Task ()
40 cont dev = updateSharedInformation "Blinkyblink" [] (getRealShare dev (hd dev.deviceShares))
41 >>* [OnAction ActionContinue (const $ Just $ cont dev)]
44 mTaskManager :: Task ()
45 mTaskManager = (>>|) startupDevices $
47 ((manageShares ||- whileUnchanged deviceStore (manageDevices process))
48 <<@ ArrangeSplit Vertical True)
49 <<@ ArrangeWithSideBar 0 LeftSide 260 True
51 viewmTasks :: Task String
52 viewmTasks = enterChoiceWithShared "Available mTasks" [ChooseFromList id] mTaskTaskStore
53 >&^ \sh->whileUnchanged sh $ \mi->forever (case mi of
54 Nothing = viewInformation "No task selected" [] ()
55 Just mTaskTask = get deviceStore
56 >>= \devices->case devices of
57 [] = viewInformation "No devices yet" [] ()
58 ds = fromJust ('DM'.get mTaskTask allmTasks)
59 >>= \bc->(enterChoice "Choose Device" [ChooseFromDropdown \t->t.deviceName] ds
60 -&&- enterInformation "Timeout" []
61 ) >>* [OnAction (Action "Send") (withValue $ Just o sendTaskToDevice mTaskTask bc)]
65 process :: MTaskDevice (Shared Channels) -> Task ()
66 process device ch = forever (watch ch >>* [OnValue (
67 ifValue (not o isEmpty o fst3)
68 (\t->upd (appFst3 (const [])) ch >>| proc (fst3 t)))])
70 proc :: [MTaskMSGRecv] -> Task ()
72 proc [MTEmpty:ms] = proc ms
73 proc [m:ms] = traceValue (toString m) >>| (case m of
74 // MTSDSAck i = traceValue (toString m) @! ()
75 // MTSDSDelAck i = traceValue (toString m) @! ()
76 MTPub i val = updateShareFromPublish device i val @! ()
77 MTTaskAck i mem = deviceTaskAcked device i mem
78 MTTaskDelAck i = deviceTaskDeleteAcked device i @! ()
79 MTDevSpec s = deviceAddSpec device s @! ()