:: MTaskShare =
{withTask :: [String]
- ,withDevice :: [String]
,identifier :: Int
,value :: BCValue
}
+
//Constructor
-makeShare :: String String Int BCValue -> MTaskShare
+makeShare :: String Int BCValue -> MTaskShare
//General viewing task
-manageShares :: [MTaskShare] -> Task MTaskShare
+manageShares :: Task [MTaskDevice]
+//manageShares :: [MTaskShare] -> Task MTaskShare
+
+updateShares :: MTaskDevice ([MTaskShare] -> [MTaskShare]) -> Task [MTaskShare]
//Clean out shares when a task has been removed
cleanSharesTask :: Int MTaskDevice -> Task [MTaskShare]
+//cleanSharesTask :: Int MTaskDevice -> Task [MTaskShare]
//Clean out shares when a device has been removed
-cleanSharesDevice :: String -> Task [MTaskShare]
-updateShare :: Int BCValue -> Task [MTaskShare]
+updateShare :: MTaskDevice Int BCValue -> Task [MTaskShare]
+//updateShare :: Int BCValue -> Task [MTaskShare]
+
+getRealShare :: MTaskDevice BCShare -> Shared BCValue
//updateShare :: Int BCValue -> Task ()
derive class iTask MTaskShare
-manageShares :: [MTaskShare] -> Task MTaskShare
-manageShares x = enterChoice "" [ChooseFromGrid id] x
- >>| manageShares x
+manageShares :: Task [MTaskDevice]
+manageShares = whileUnchanged deviceStore
+ $ \devs->case devs of
+ [] = viewInformation "No devices yet" [] []
+ _ = allTasks (map manageSharesOnDevice devs)
+
+manageSharesOnDevice :: MTaskDevice -> Task MTaskDevice
+manageSharesOnDevice dev = (case dev.deviceShares of
+ [] = viewInformation dev.deviceName [] "No shares yet"
+ shs = enterChoice dev.deviceName [ChooseFromGrid id] shs @ const ""
+ ) >>| treturn dev
+
+updateShares :: MTaskDevice ([MTaskShare] -> [MTaskShare]) -> Task [MTaskShare]
+updateShares dev tfun = upd (map upFun) deviceStore
+ @ (\d->d.deviceShares) o fromJust o find ((==)dev)
+ where
+ upFun d = if (dev == d) ({d&deviceShares=tfun d.deviceShares}) d
+
//manageShares shares = withShared Nothing $ \cs->forever $
// (viewSharesGrid cs shares -|| updateShares shares <<@ ArrangeVertical)
// @! ()
//viewShare m = viewSharedInformation "" [] (getSDSShare m)
// <<@ Title ("SDS: " +++ toString m.identifier)
-makeShare :: String String Int BCValue -> MTaskShare
-makeShare withTask withDevice identifier value = {MTaskShare
+makeShare :: String Int BCValue -> MTaskShare
+makeShare withTask 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
+updateShare :: MTaskDevice Int BCValue -> Task [MTaskShare]
+updateShare dev ident val = updateShares dev $ map $ up ident val
where
up :: Int BCValue MTaskShare -> MTaskShare
up i v s = if (s.identifier == i) {MTaskShare | s & value=val} s
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)]}
+cleanSharesTask taskid d = updateShares d id //TODO
+//# shares = d.deviceShares
+//| 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
+getRealShare :: MTaskDevice BCShare -> Shared BCValue
+getRealShare dev {sdsi} = SDSSource {SDSSource
+ | name = "mTaskShareMap-" +++ toString sdsi, read=rr, write=ww}
where
- up :: String MTaskShare -> MTaskShare
- up i s = {MTaskShare | s & withDevice = [wt\\wt<-s.withDevice|wt <> i]}
+ 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 == sdsi) deviceShares of
+ Nothing = (Error $ exception "Share doesn't exist", iworld)
+ Just share = (Ok share.MTaskShare.value, iworld)
+
+ // Also send messages
+ ww name value iworld = undef//case modify (modFun name value) sdsStore of
+// (Error e, iworld) = (Error e, iworld)
+// (Ok shares, iworld) = (Ok $ const True, iworld)