X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=Shares%2FmTaskShare.icl;h=4cca1340f9b6ce97a7b33774122ec9e9eca38832;hb=a81623aa9629a3c5c8f8bf920e494a596b30c4b7;hp=fe65501421229f62b4b527f4e6da5a5eda7f68e4;hpb=ae91e169d499a11f5ed3873472aff8e0a06711db;p=mTask.git diff --git a/Shares/mTaskShare.icl b/Shares/mTaskShare.icl index fe65501..4cca134 100644 --- a/Shares/mTaskShare.icl +++ b/Shares/mTaskShare.icl @@ -7,62 +7,77 @@ import iTasks import mTask import Data.List from Data.Func import $ +from StdFunc import flip -derive class iTask MTaskShareType, MTaskShare +derive class iTask MTaskShare -manageShares :: [MTaskShare] -> Task () -manageShares shares = forever $ viewInformation "" [] "" @! () -// viewSharesGrid shares @! () +manageShares :: [MTaskShare] -> Task MTaskShare +manageShares x = enterChoice "" [ChooseFromGrid id] x + >>| manageShares x +//manageShares shares = withShared Nothing $ \cs->forever $ +// (viewSharesGrid cs shares -|| updateShares shares <<@ ArrangeVertical) +// @! () -// >&^ \st->whileUnchanged st $ \msh->case msh of -// Nothing = viewShares shares -// Just sh = forever ( -// viewSharedInformation "View value" [] (getSDSShare sh) >>| treturn sh -// >>* [OnAction (Action "Update") (withValue (Just o updateInformation "New value" []))] -// >>= updateShare sh -// ) -// -// ) @! () +//updateShares :: [MTaskShare] -> Task BCValue +//updateShares shares = anyTask (map updateS shares) <<@ ArrangeWithTabs +//updateS :: MTaskShare -> Task BCValue +//updateS sh = flip (<<@) (Title $ toString sh.identifier) $ forever $ +// viewSharedInformation "Current value" [] (getSDSShare sh) +// ||- ( +// updateSharedInformation "New value" [] (getSDSShare sh) +// >>= \nv->allTasks (map (withDevice treturn) sh.withDevice) +// >>= \devs->allTasks (map (sendMessages [MTUpd sh.identifier nv]) devs) +// >>| treturn nv +// ) +// <<@ ArrangeHorizontal -//viewShares :: [MTaskShare] -> Task BCValue -//viewShares shares = anyTask (map viewShare shares) -// -//viewAndDelete :: [MTaskShare] -> Task () -//viewAndDelete shares -// = enterChoice "Choose share to update" [ChooseFromGrid id] shares @! () +//viewSharesGrid :: (Shared (Maybe MTaskShare)) [MTaskShare] -> Task [BCValue] +//viewSharesGrid _ [] = viewInformation "No shares yet" [] [] +//viewSharesGrid cs sh = (allTasks [watch (getSDSShare m)\\m<-sh] <<@ NoUserInterface) +// >&^ \st->flip (<<@) NoUserInterface $ whileUnchanged st $ \mshs->enterChoice "" [ChooseFromGrid id] +// [{MTaskShare|ss&value=s}\\s<-fromJust mshs & ss<-sh] +// >>* [OnValue (withValue $ \s->Just (set (Just s) cs))] +// @! fromJust mshs -//updateShare :: MTaskShare a -> Task MTaskShare | toByteCode, iTask a -//updateShare sh=:{withTask,identifier} a = getDeviceByName withTask -// >>= sendMessages [MTUpd identifier $ toString $ toByteCode a] -// >>| treturn sh +//viewShare :: MTaskShare -> Task BCValue +//viewShare m = viewSharedInformation "" [] (getSDSShare m) +// <<@ Title ("SDS: " +++ toString m.identifier) -viewSharesGrid :: [MTaskShare] -> Task [BCValue] -viewSharesGrid sh = allTasks [watch (getSDSShare m)\\m<-sh] - >&^ \st->whileUnchanged st $ \mshs->enterChoice "" [ChooseFromGrid id] - [{MTaskShare|ss&value=s}\\s<-fromJust mshs & ss<-sh] - @! fromJust mshs -// /*enterChoice "" [ChooseFromGrid id]*/viewInformation "" [] o fromJust +makeShare :: String String Int BCValue -> MTaskShare +makeShare withTask withDevice identifier value = {MTaskShare + |withTask=[withTask] + ,withDevice=[withDevice] + ,identifier=identifier + ,value=value +// ,realShare=MTaskWithShare $ "mTaskSDS-" +++ toString identifier + } -viewShare :: MTaskShare -> Task BCValue -viewShare m = viewSharedInformation "" [] (getSDSShare m) - <<@ Title ("SDS: " +++ toString m.identifier) +updateShare :: Int BCValue -> Task [MTaskShare] +updateShare ident val = upd (map $ up ident val) sdsStore + where + up :: Int BCValue MTaskShare -> MTaskShare + up i v s = if (s.identifier == i) {MTaskShare | s & value=val} s -getSDSShare :: MTaskShare -> Shared BCValue -getSDSShare s=:{realShare=(MTaskWithShare id),value} = memoryShare id value +import GenPrint, StdMisc, StdDebug, TTY +derive gPrint MTaskDevice, MTaskShare, Maybe, MTaskResource, MTaskTask, TaskId, TTYSettings, TCPSettings, DateTime +derive gPrint Parity, BaudRate, ByteSize -makeShare :: String Int BCValue -> Task MTaskShare -makeShare withTask identifier value = treturn - {MTaskShare - |withTask=withTask - ,identifier=identifier - ,value=value - ,realShare=MTaskWithShare $ "mTaskSDS-" +++ toString identifier - } >>= \sh->set value (getSDSShare sh) >>| treturn sh +cleanSharesTask :: Int MTaskDevice -> Task [MTaskShare] +cleanSharesTask taskid d +| not (trace_tn $ printToString taskid) = undef +| not (trace_tn $ printToString d.deviceTasks) = undef +| not (trace_tn $ printToString $ getNames taskid d) = undef += upd (map $ up $ getNames taskid d) sdsStore + where + getNames :: Int MTaskDevice -> [String] + getNames i d = [t.MTaskTask.name\\t<-d.deviceTasks|t.ident==i] + + up :: [String] MTaskShare -> MTaskShare + up ns s = {MTaskShare | s & withTask=[t\\t<-s.withTask|not (isMember t ns)]} -updateShare :: Int String -> Task () -updateShare ident val = get sdsStore - >>= \sh->(case find (\s->s.identifier==ident) sh of - Nothing = abort "Help, no share found with this ident" - Just mts = set (fromByteCode val) (getSDSShare mts)) - >>| traceValue "Updated" @! () +cleanSharesDevice :: String -> Task [MTaskShare] +cleanSharesDevice did = upd (map (up did)) sdsStore + where + up :: String MTaskShare -> MTaskShare + up i s = {MTaskShare | s & withDevice = [wt\\wt<-s.withDevice|wt <> i]}