implementation module Shares.mTaskShare import dynamic_string import Utils.SDS import Utils.Devices import iTasks import mTask import Data.List from Data.Func import $ from StdFunc import flip derive class iTask MTaskShare manageShares :: [MTaskShare] -> Task MTaskShare manageShares x = enterChoice "" [ChooseFromGrid id] x >>| manageShares x //manageShares shares = withShared Nothing $ \cs->forever $ // (viewSharesGrid cs shares -|| updateShares shares <<@ ArrangeVertical) // @! () //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 //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 //viewShare :: MTaskShare -> Task BCValue //viewShare m = viewSharedInformation "" [] (getSDSShare m) // <<@ Title ("SDS: " +++ toString m.identifier) 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 } 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 import GenPrint, StdMisc, StdDebug, TTY derive gPrint MTaskDevice, MTaskShare, Maybe, MTaskResource, MTaskTask, TaskId, TTYSettings, TCPSettings, DateTime derive gPrint Parity, BaudRate, ByteSize 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)]} 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]}