use share lenses
[mTask.git] / Utils / SDS.icl
index cd684ae..a7c3763 100644 (file)
@@ -4,27 +4,33 @@ import iTasks
 import iTasks._Framework.Store
 import Devices.mTaskDevice
 import Shares.mTaskShare
+import Tasks.Examples
+import qualified Data.Map as DM
 from Data.Func import $
-
-derive class iTask MTaskShare, BCState
+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" ["count", "ledon", "ledoff"]
-
-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]
+mTaskTaskStore = memoryShare "mTaskTasks" $ 'DM'.keys allmTasks