X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=miTask.icl;h=2a80f5cc8492b51a36f716add3ab037b69f4bf7f;hb=71726cdfddd9dfa11395f10ef3b5af28613fd5a0;hp=62b6ce1738c7e51720e05c0b9fed6c0de29d605f;hpb=955c4eb992b45e48a1a3dad6418236431ddcd095;p=mTask.git diff --git a/miTask.icl b/miTask.icl index 62b6ce1..2a80f5c 100644 --- a/miTask.icl +++ b/miTask.icl @@ -1,80 +1,92 @@ module miTask import StdDebug, StdMisc - -from Text import class Text(concat,join,split), instance Text String +from StdFunc import flip import iTasks import mTask +import Devices.mTaskDevice +import Shares.mTaskShare +import Tasks.Examples +import Utils.SDS -derive class iTask MTaskMessage +from Text import class Text(startsWith,concat,split,join), instance Text String -Start :: *World -> *World -Start world = startEngine ( - enterInformation "Port Number?" [] - >>= \port->withShared ([], False, [], False) (mTaskTask port) - ) world -Start world = startEngine mTaskTask world +import qualified Data.Map as DM -mTaskTask :: Int (Shared ([MTaskMessage],Bool,[MTaskMessage],Bool)) -> Task () -mTaskTask port ch = - syncNetworkChannel "localhost" port "\n" decode encode ch ||- - ( - sendMsg msgs ch >>= \_-> - viewSharedInformation "channels" [ViewWith lens] ch @! () - ) >>* [OnAction ActionFinish (always shutDown)] - where - lens :: ([MTaskMessage],Bool,[MTaskMessage],Bool) -> ([String], [String]) - lens (r,_,s,_) = (f r, f s) - where - f [] = [] - f [MTEmpty:xs] = f xs - f [x:xs] = [toString x:f xs] +from Data.Func import $ +import Data.Tuple +import Data.List +import System.Directory + +import iTasks._Framework.Store +import iTasks._Framework.Serialization - msgs - | not (trace_tn (fst (toReadableByteCode (unMain bc)))) = undef - = toMessages 500 (toRealByteCode (unMain bc)) +import TTY, iTasksTTY - bc :: Main (ByteCode Int Stmt) - bc = sds \x=1 In {main = - If (x ==. lit 3) - (x =. lit 1) - (x =. x +. lit 1) :. pub x} +Start world = startEngine [ + publish "/manage" $ const $ mTaskManager + >>* [OnAction (Action "Shutdown") (always $ shutDown)], + publish "/" $ const demo + ] world -sendMsg :: [MTaskMessage] (Shared ([MTaskMessage],Bool,[MTaskMessage],Bool)) -> Task () -sendMsg m ch -| not (trace_tn (join "\n" (map (toString o toJSON) m))) = undef -= upd (\(r,rs,s,ss)->(r,rs,s ++ m,ss)) ch @! () +demo = viewSharedInformation "Devices" [] deviceStoreNP + >>* [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:)" []) -syncNetworkChannel :: String Int String (String -> m) (n -> String) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n -syncNetworkChannel server port msgSeparator decodeFun encodeFun channel - = tcpconnect server port channel {ConnectionHandlers|onConnect=onConnect,whileConnected=whileConnected,onDisconnect=onDisconnect} @! () + 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 deviceStoreNP (manageDevices process)) + <<@ ArrangeSplit Vertical True) + <<@ ArrangeWithSideBar 0 LeftSide 260 True where - onConnect _ (received,receiveStopped,send,sendStopped) - = (Ok "",if (not (isEmpty send)) (Just (received,False,[],sendStopped)) Nothing, map encodeFun send,False) - whileConnected Nothing acc (received,receiveStopped,send,sendStopped) - = (Ok acc, Nothing, [], False) - whileConnected (Just newData) acc (received,receiveStopped,send,sendStopped) - # [acc:msgs] = reverse (split msgSeparator (concat [acc,newData])) - # write = if (not (isEmpty msgs && isEmpty send)) - (Just (received ++ map decodeFun (reverse msgs),receiveStopped,[],sendStopped)) - Nothing - = (Ok acc,write,map encodeFun send,False) - - onDisconnect l (received,receiveStopped,send,sendStopped) - = (Ok l,Just (received,True,send,sendStopped)) + 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 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)] + @! () + ) -//consumeNetworkStream :: ([m] -> Task ()) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n -//consumeNetworkStream processTask channel -// = ((watch channel >>* [OnValue (ifValue ifProcess process)]) >| if (isEmpty received) (return ()) (processTask received) -// @! receiveStopped -// -// empty :: ([m],Bool,[m],Bool) -> ([m],Bool,[m],Bool) -// empty (_,rs,s,ss) = ([],rs,s,ss) + 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