summaryrefslogtreecommitdiff
path: root/src/Storage/WatchList.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Storage/WatchList.hs')
-rw-r--r--src/Storage/WatchList.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/Storage/WatchList.hs b/src/Storage/WatchList.hs
new file mode 100644
index 0000000..11ca3e1
--- /dev/null
+++ b/src/Storage/WatchList.hs
@@ -0,0 +1,37 @@
+module Storage.WatchList (
+ WatchList(..),
+ WatchListItem(..),
+ watchListAdd,
+ watchListDel,
+) where
+
+import Erebos.Object
+import Erebos.Storage.Backend
+import Erebos.Storage.Head
+
+
+data WatchList = WatchList
+ { wlNext :: WatchID
+ , wlList :: [ WatchListItem ]
+ }
+
+data WatchListItem = WatchListItem
+ { wlID :: WatchID
+ , wlHead :: ( HeadTypeID, HeadID )
+ , wlFun :: RefDigest -> IO ()
+ }
+
+watchListAdd :: HeadTypeID -> HeadID -> (RefDigest -> IO ()) -> WatchList -> ( WatchList, WatchID )
+watchListAdd tid hid cb wl = ( wl', wlNext wl )
+ where
+ wl' = wl
+ { wlNext = nextWatchID (wlNext wl)
+ , wlList = WatchListItem
+ { wlID = wlNext wl
+ , wlHead = (tid, hid)
+ , wlFun = cb
+ } : wlList wl
+ }
+
+watchListDel :: WatchID -> WatchList -> WatchList
+watchListDel wid wl = wl { wlList = filter ((/= wid) . wlID) $ wlList wl }