import iTasks
import mTask
import Data.List
+import Data.Tuple
from Data.Func import $
from StdFunc import flip
,value=value
}
+if` i t e = if i t e
+
updateShareFromPublish :: MTaskDevice Int BCValue -> Task [MTaskShare]
updateShareFromPublish dev ident val = updateShares dev $ map $ up ident val
where
// up :: [String] MTaskShare -> MTaskShare
// up ns s = {MTaskShare | s & withTask=[t\\t<-s.withTask|not (isMember t ns)]}
+instance == MTaskShare where
+ (==) a b = a.identifier == b.identifier
+
getRealShare :: MTaskDevice MTaskShare -> Shared BCValue
-getRealShare dev {identifier} = SDSSource {SDSSource
+getRealShare dev share=:{identifier} = sdsFocus (Just identifier) $ SDSSource {SDSSource
| name = "mTaskShareMap-" +++ toString identifier, read=rr, write=ww}
where
rr name iworld = case read deviceStore iworld of
(Error e, iworld) = (Error e, iworld)
(Ok devices, iworld) = case find ((==)dev) devices of
Nothing = (Error $ exception "Device doesn't exist anymore", iworld)
- Just {deviceShares} = case find (\s->s.identifier == identifier) deviceShares of
+ Just {deviceShares} = case find ((==)share) deviceShares of
Nothing = (Error $ exception "Share doesn't exist", iworld)
Just share = (Ok share.MTaskShare.value, iworld)
// Also send messages
ww name value iworld
| not (trace_tn ("Update to: " +++ printToString value)) = undef
- = case modify (\r->((), map (modFun value) r)) deviceStore iworld of
+ = case modify (tuple () o modifyValue value) deviceStore iworld of
(Error e, iworld) = (Error e, iworld)
(Ok _, iworld) = case sendMessagesIW [MTUpd identifier value] dev iworld of
(Error e, iworld) = (Error e, iworld)
- (Ok _, iworld) = (Ok $ const True, iworld)
+ (Ok _, iworld) = (Ok $ maybe True ((==) identifier), iworld)
- //Selects the correct device
- modFun value d
- | d == dev = {d & deviceShares=map (modFun2 value) d.deviceShares}
- = d
+ modifyValue :: BCValue [MTaskDevice] -> [MTaskDevice]
+ modifyValue v ds = filterMap ((==)dev) deviceUpdate ds
+ where
+ deviceUpdate d = {MTaskDevice | d
+ & deviceShares=filterMap ((==)share) shareUpd d.deviceShares}
+ shareUpd s = {MTaskShare | s & value=v}
- //Selects the correct share
- modFun2 value share
- | identifier == share.MTaskShare.identifier = {MTaskShare | share & value=value}
- = share
+ filterMap :: (a -> Bool) (a -> a) [a] -> [a]
+ filterMap f t xs = [if (f x) (t x) x\\x<-xs]
cont :: MTaskDevice -> Task ()
cont dev = updateSharedInformation "Blinkyblink" [] (getRealShare dev (hd dev.deviceShares))
- >>| cont dev
+ >>* [OnAction ActionContinue (const $ Just $ cont dev)]
mTaskManager :: Task ()
-mTaskManager = startupDevices >>| anyTask
- [ viewmTasks @! ()
- , manageShares @! ()
- , whileUnchanged deviceStore $ manageDevices process
- ] <<@ ApplyLayout (foldl1 sequenceLayouts
- [arrangeWithSideBar 0 LeftSide 260 True
- ,arrangeSplit Vertical True])
+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