refactoors
[mTask.git] / miTask.icl
index 2a80f5c..c47f525 100644 (file)
@@ -26,11 +26,13 @@ import TTY, iTasksTTY
 
 Start world = startEngine [
                publish "/manage" $ const $ mTaskManager
-                       >>* [OnAction (Action "Shutdown") (always $ shutDown)],
+                       >>* [OnAction (Action "Shutdown") (always $ shutDown 0)],
                publish "/" $ const demo
        ] world
 
-demo = viewSharedInformation "Devices" [] deviceStoreNP
+demo :: Task ()
+demo = set 5 (sharedDynamicStore "Hoi" 5)
+       >>| viewSharedInformation "Devices" [] deviceStoreNP
        >>* [OnValue $ ifValue pred (cont o hd)]
        where
                pred [] = False
@@ -38,9 +40,9 @@ demo = viewSharedInformation "Devices" [] deviceStoreNP
 
                cont :: MTaskDevice -> Task ()
                cont dev
-               # rs = getRealShare dev (hd dev.deviceShares)
+               # rs = shareShare dev (hd dev.deviceShares)
                = get rs >>= \oldvalue->
-                       forever (updateSharedInformation "Blinkyblink" [] (getRealShare dev (hd dev.deviceShares))
+                       forever (updateSharedInformation "Blinkyblink" [] (shareShare dev (hd dev.deviceShares))
                        >>* [OnAction ActionContinue (const $ Just $ treturn ())])
                 -|| (wait "bigger than 10" (\x->x == oldvalue) rs
                        >>= viewInformation "Bigger:)" [])
@@ -54,29 +56,29 @@ demo = viewSharedInformation "Devices" [] deviceStoreNP
 
 mTaskManager :: Task ()
 mTaskManager = (>>|) startupDevices $ 
-               viewmTasks ||-
-               ((manageShares ||- whileUnchanged deviceStoreNP (manageDevices process))
-                       <<@ ArrangeSplit Vertical True)
+               forever viewmTasks ||-
+               ((manageShares ||- forever (manageDevices process)) <<@ ArrangeSplit Vertical True)
                <<@ ArrangeWithSideBar 0 LeftSide 260 True
        where
-               viewmTasks :: Task String
+               viewmTasks :: Task [MTaskDevice]
                viewmTasks = enterChoiceWithShared "Available mTasks" [ChooseFromList id] mTaskTaskStore
-                       >&^ \sh->whileUnchanged sh $ \mi->forever (case mi of
-                               Nothing = viewInformation "No task selected" [] ()
-                               Just mTaskTask = get deviceStoreNP
-                                       >>= \devices->case devices of
-                                               [] = viewInformation "No devices yet" [] ()
-                                               ds = fromJust ('DM'.get mTaskTask allmTasks)
-                                                       >>= \bc->(enterChoice "Choose Device" [ChooseFromDropdown \t->t.deviceName] ds
-                                                               -&&- enterInformation "Timeout" []
-                                                       ) >>* [OnAction (Action "Send") (withValue $ Just o sendTaskToDevice mTaskTask bc)]
-                                                       @! ()
-                               )
+                       >>= \task->get deviceStoreNP
+                       >>* [OnValue $ (ifValue isEmpty)         $ \_->
+                                       viewInformation "No devices yet" [] [] >>= treturn
+                               ,OnValue $ (ifValue $ not o isEmpty) $ \d->
+                                       fromJust ('DM'.get task allmTasks)
+                                       >>= \bc->(enterChoice "Choose Device" [ChooseFromDropdown \t->t.deviceName] d
+                                               -&&- enterInformation "Timeout" []
+                                       ) >>* [OnAction (Action "Send") (withValue $ Just o sendTaskToDevice task bc)]
+                                       >>| treturn []
+                               ]
 
                process :: MTaskDevice (Shared Channels) -> Task ()
-               process device ch = forever (watch ch >>* [OnValue (
-                               ifValue (not o isEmpty o fst3)
-                               (\t->upd (appFst3 (const [])) ch >>| proc (fst3 t)))])
+               process device ch = forever
+                         $ traceValue "Waiting for channel change"
+                       >>| wait "process" (not o isEmpty o fst3) ch
+                       >>= \(r,s,ss)->upd (appFst3 (const [])) ch
+                       >>| proc r
                        where
                                proc :: [MTaskMSGRecv] -> Task ()
                                proc [] = treturn ()