trying to get the sds lenses to work
[mTask.git] / miTask.icl
1 module miTask
2
3 import StdDebug, StdMisc
4 from StdFunc import flip
5
6 import iTasks
7 import mTask
8 import Devices.mTaskDevice
9 import Shares.mTaskShare
10 import Tasks.Examples
11 import Utils.SDS
12
13 from Text import class Text(startsWith,concat,split,join), instance Text String
14
15 import qualified Data.Map as DM
16
17 from Data.Func import $
18 import Data.Tuple
19 import Data.List
20 import System.Directory
21
22 import iTasks._Framework.Store
23 import iTasks._Framework.Serialization
24
25 import TTY, iTasksTTY
26
27 Start world = startEngine [
28 publish "/manage" $ const $ mTaskManager
29 >>* [OnAction (Action "Shutdown") (always $ shutDown)],
30 publish "/" $ const demo
31 ] world
32
33 demo = viewSharedInformation "Devices" [] deviceStore
34 >>* [OnValue $ ifValue pred (cont o hd)]
35 where
36 pred [] = False
37 pred [x:_] = not $ isEmpty x.deviceShares
38
39 cont :: MTaskDevice -> Task ()
40 cont dev = updateSharedInformation "Blinkyblink" [] (getRealShare dev (hd dev.deviceShares))
41 >>* [OnAction ActionContinue (const $ Just $ cont dev)]
42
43
44 mTaskManager :: Task ()
45 mTaskManager = (>>|) startupDevices $
46 viewmTasks ||-
47 ((manageShares ||- whileUnchanged deviceStore (manageDevices process))
48 <<@ ArrangeSplit Vertical True)
49 <<@ ArrangeWithSideBar 0 LeftSide 260 True
50 where
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)]
62 @! ()
63 )
64
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)))])
69 where
70 proc :: [MTaskMSGRecv] -> Task ()
71 proc [] = treturn ()
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 @! ()
80 _ = treturn ()
81 ) >>| proc ms