import Tasks.Examples
import qualified Data.Map as DM
from Data.Func import $
-
-derive class iTask MTaskShare
+import Data.Tuple
memoryShare :: String a -> Shared a | iTask a
-memoryShare s d = sdsFocus s $ memoryStore "" $ Just d
+memoryShare s d = sdsFocus s $ memoryStore s $ Just d
+
+deviceStoreNP :: Shared [MTaskDevice]
+deviceStoreNP = sdsFocus Nothing $ deviceStore
+
+deviceStore :: RWShared (Maybe Int) [MTaskDevice] [MTaskDevice]
+deviceStore = SDSSource {SDSSource
+ | name = "deviceStore"
+ , read = \_->read realDeviceStore
+ , write= \p w->appFst ((<$) (lens p)) o write w realDeviceStore
+ }
-deviceStore :: Shared [MTaskDevice]
-deviceStore = sharedStore "mTaskDevices" []
+lens Nothing _ = True
+lens _ Nothing = True
+lens (Just p) (Just p`) = p` == -1 || p == p`
-sdsStore :: Shared [MTaskShare]
-sdsStore = memoryShare "mTaskShares" []
+realDeviceStore :: Shared [MTaskDevice]
+realDeviceStore = sharedStore "mTaskDevices" []
bcStateStore :: Shared BCState
bcStateStore = memoryShare "mTaskBCState" zero
mTaskTaskStore :: Shared [String]
mTaskTaskStore = memoryShare "mTaskTasks" $ 'DM'.keys allmTasks
-
-getSDSStore :: MTaskShare -> Shared Int
-getSDSStore sh = memoryShare sh.realShare 0
-
-getSDSRecord :: Int -> Task MTaskShare
-getSDSRecord i = get sdsStore @ \l->hd [s\\s<-l | s.identifier == i]