From: Mart Lubbers Date: Mon, 27 Feb 2017 08:18:34 +0000 (+0100) Subject: split out again for tasks X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=526e9fec79086ef2a701420736cf89a6191cc13c;p=mTask.git split out again for tasks --- diff --git a/Devices/mTaskDevice.dcl b/Devices/mTaskDevice.dcl index f21e654..6a09c55 100644 --- a/Devices/mTaskDevice.dcl +++ b/Devices/mTaskDevice.dcl @@ -4,6 +4,7 @@ from Data.Maybe import :: Maybe import iTasks import Devices.mTaskSerial import Devices.mTaskTCP +import Tasks.mTaskTask import mTaskInterpret import Generics.gCons import iTasksTTY @@ -24,7 +25,7 @@ channels :: MTaskDevice -> Shared Channels deviceTask :: Maybe TaskId ,deviceChannels :: String ,deviceName :: String - ,deviceTasks :: [(String, Int)] + ,deviceTasks :: [MTaskTask] ,deviceData :: MTaskResource } @@ -34,6 +35,6 @@ class MTaskDuplex a where manageDevices :: (MTaskDevice (Shared Channels) -> Task ()) [MTaskDevice] -> Task () sendToDevice :: (Map String (Main (ByteCode () Stmt))) String (MTaskDevice, Int) -> Task () -deviceTaskDelete :: MTaskDevice Int -> Task () +deviceTaskDelete :: MTaskDevice MTaskTask -> Task () deviceTaskAcked :: MTaskDevice Int -> Task () deviceTaskDeleteAcked :: MTaskDevice Int -> Task () diff --git a/Devices/mTaskDevice.icl b/Devices/mTaskDevice.icl index 53b3944..972aa7b 100644 --- a/Devices/mTaskDevice.icl +++ b/Devices/mTaskDevice.icl @@ -64,8 +64,8 @@ viewDevice d = anyTask [viewInformation "Device settings" [] d @! () ,viewSharedInformation "Channels" [ViewAs dropEmpty] (channels d) @! () ,forever $ - enterChoice "Delete task on device" [ChooseFromList fst] d.deviceTasks - >>* [OnAction (Action "Delete") $ ifValue (\(_,i)->i <> -1) (deviceTaskDelete d o snd)] + enterChoice "Delete task on device" [ChooseFromGrid id] d.deviceTasks + >>* [OnAction (Action "Delete") $ ifValue (\t->t.ident <> -1) (deviceTaskDelete d)] @! () ] <<@ ArrangeHorizontal where @@ -78,7 +78,8 @@ sendToDevice tmap mTask (device, timeout) = >>= \sdss->upd ((++)sdss) sdsStore//MTaskShareaddToSDSShare >>| makeShares sdss >>| sendMessage device msgs - >>| withDevices device (addTask timeout) + >>| makeTask mTask -1 + >>= \task->withDevices device (addTask timeout task) @! () where createBytecode st = toMessages timeout $ toRealByteCode (unMain $ fromJust ('DM'.get mTask tmap)) st @@ -91,8 +92,8 @@ sendToDevice tmap mTask (device, timeout) = \\(i,[d1,d2])<-st.sdss] makeShares = foldr (\sh t->set sh.initValue (getSDSStore sh) >>| t) (treturn ()) - addTask :: Int MTaskDevice -> MTaskDevice - addTask timeout device = {device & deviceTasks=[(mTask, -1):device.deviceTasks]} + addTask :: Int MTaskTask MTaskDevice -> MTaskDevice + addTask timeout task device = {device & deviceTasks=[task:device.deviceTasks]} sendMessage :: MTaskDevice [MTaskMSGSend] -> Task () sendMessage dev msgs = upd (\(r,s,ss)->(r,msgs++s,ss)) (channels dev) @! () @@ -103,15 +104,16 @@ withDevices a trans = upd (map withDevice) deviceStore @! () deviceTaskAcked :: MTaskDevice Int -> Task () deviceTaskAcked dev i - = withDevices dev (\d->{d&deviceTasks=ackFirst i d.deviceTasks}) + = withDevices dev (\d->{d&deviceTasks=ackFirst d.deviceTasks}) where - ackFirst :: Int [(String, Int)] -> [(String, Int)] - ackFirst _ [] = [] - ackFirst a [(s,i):ts] = if (i == -1) [(s,a):ts] [(s,i):ackFirst a ts] + ackFirst :: [MTaskTask] -> [MTaskTask] + ackFirst [] = [] + ackFirst [t:ts] = if (t.ident == -1) + [{t & ident=i}:ts] [t:ackFirst ts] -deviceTaskDelete :: MTaskDevice Int -> Task () -deviceTaskDelete dev tid = sendMessage dev [MTTaskDel tid] +deviceTaskDelete :: MTaskDevice MTaskTask -> Task () +deviceTaskDelete dev task = sendMessage dev [MTTaskDel task.ident] deviceTaskDeleteAcked :: MTaskDevice Int -> Task () deviceTaskDeleteAcked d i = withDevices d $ deleteTask - where deleteTask d = {d & deviceTasks=[s\\s<-d.deviceTasks | i <> snd s]} + where deleteTask d = {d & deviceTasks=[s\\s<-d.deviceTasks | i <> s.ident]} diff --git a/Tasks/mTaskTask.dcl b/Tasks/mTaskTask.dcl new file mode 100644 index 0000000..0a89129 --- /dev/null +++ b/Tasks/mTaskTask.dcl @@ -0,0 +1,13 @@ +definition module Tasks.mTaskTask + +import iTasks + +derive class iTask MTaskTask + +:: MTaskTask = { + name :: String, + ident :: Int, + dateAdded :: DateTime + } + +makeTask :: String Int -> Task MTaskTask diff --git a/Tasks/mTaskTask.icl b/Tasks/mTaskTask.icl new file mode 100644 index 0000000..1af27ba --- /dev/null +++ b/Tasks/mTaskTask.icl @@ -0,0 +1,9 @@ +implementation module Tasks.mTaskTask + +import iTasks + +derive class iTask MTaskTask + +makeTask :: String Int -> Task MTaskTask +makeTask name ident = get currentDateTime + @ \dt->{MTaskTask | name=name,ident=ident,dateAdded=dt}