module miTask import StdDebug, StdMisc from StdFunc import flip import iTasks import mTask import Devices.mTaskDevice import Shares.mTaskShare import Tasks.Examples import Utils.SDS from Text import class Text(startsWith,concat,split,join), instance Text String import qualified Data.Map as DM from Data.Func import $ import Data.Tuple import Data.List import System.Directory import iTasks._Framework.Store import iTasks._Framework.Serialization import TTY, iTasksTTY Start world = startEngine [ publish "/manage" $ const $ mTaskManager >>* [OnAction (Action "Shutdown") (always $ shutDown)], publish "/" $ const demo ] 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 # rs = getRealShare dev (hd dev.deviceShares) = get rs >>= \oldvalue-> forever (updateSharedInformation "Blinkyblink" [] (getRealShare dev (hd dev.deviceShares)) >>* [OnAction ActionContinue (const $ Just $ treturn ())]) -|| (wait "bigger than 10" (\x->x == oldvalue) rs >>= viewInformation "Bigger:)" []) toInt :: BCValue -> Int toInt (BCValue e) = dynToInt (dynamic e) dynToInt :: Dynamic -> Int dynToInt (a :: Int) = a dynToInt x = abort "Not an int" mTaskManager :: Task () mTaskManager = (>>|) startupDevices $ viewmTasks ||- ((manageShares ||- whileUnchanged deviceStore (manageDevices process)) <<@ ArrangeSplit Vertical True) <<@ ArrangeWithSideBar 0 LeftSide 260 True where viewmTasks :: Task String viewmTasks = enterChoiceWithShared "Available mTasks" [ChooseFromList id] mTaskTaskStore >&^ \sh->whileUnchanged sh $ \mi->forever (case mi of Nothing = viewInformation "No task selected" [] () Just mTaskTask = get deviceStore >>= \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)] @! () ) 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)))]) where proc :: [MTaskMSGRecv] -> Task () proc [] = treturn () proc [MTEmpty:ms] = proc ms proc [m:ms] = traceValue (toString m) >>| (case m of // MTSDSAck i = traceValue (toString m) @! () // MTSDSDelAck i = traceValue (toString m) @! () MTPub i val = updateShareFromPublish device i val @! () MTTaskAck i mem = deviceTaskAcked device i mem @! () MTTaskDelAck i = deviceTaskDeleteAcked device i @! () MTDevSpec s = deviceAddSpec device s @! () _ = treturn () ) >>| proc ms