+//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 Int BCValue -> MTaskShare
+makeShare withTask identifier value = {MTaskShare
+ |withTask=[withTask]
+ ,identifier=identifier
+ ,value=value
+ }
+
+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 = 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)]}
+
+instance == MTaskShare where
+ (==) a b = a.identifier == b.identifier
+
+getRealShare :: MTaskDevice MTaskShare -> Shared BCValue
+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 ((==)share) deviceShares of
+ Nothing = (Error $ exception "Share doesn't exist", iworld)
+ Just s = (Ok s.MTaskShare.value, iworld)
+
+ // Also send messages
+ ww name value iworld
+ | not (trace_tn ("Update to: " +++ printToString value)) = undef
+ = 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 $ maybe True ((==) identifier), iworld)