summaryrefslogtreecommitdiff
path: root/Announcer.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-05-24 19:35:52 -0400
committerjoe <joe@jerkface.net>2018-05-24 19:35:52 -0400
commit3de9992f3e30a911617737827bce3242db0cc978 (patch)
tree9f2cd558ef943876875e99a14f76a49511f51427 /Announcer.hs
parent07584194c4c7fa270b78095970cf0d4101005b12 (diff)
Dropped dependency on generic-data for now.
Diffstat (limited to 'Announcer.hs')
-rw-r--r--Announcer.hs16
1 files changed, 12 insertions, 4 deletions
diff --git a/Announcer.hs b/Announcer.hs
index 2b96c421..72d70a1e 100644
--- a/Announcer.hs
+++ b/Announcer.hs
@@ -35,7 +35,7 @@ import Data.Maybe
35import Data.Ord 35import Data.Ord
36import Data.Time.Clock.POSIX 36import Data.Time.Clock.POSIX
37import qualified GHC.Generics as Generics 37import qualified GHC.Generics as Generics
38import Generic.Data.Internal.Meta as Lyxia 38-- import Generic.Data.Internal.Meta as Lyxia
39 39
40newtype AnnounceKey = AnnounceKey ByteString 40newtype AnnounceKey = AnnounceKey ByteString
41 deriving (Hashable,Ord,Eq) 41 deriving (Hashable,Ord,Eq)
@@ -54,13 +54,21 @@ data ScheduledItem
54 | SearchResult (STM (IO ())) 54 | SearchResult (STM (IO ()))
55 | StopAnnouncer 55 | StopAnnouncer
56 -- Can't use Data because STM and IO. :( 56 -- Can't use Data because STM and IO. :(
57 -- deriving Data {- itemStatusNum sch = constrIndex $ toConstr sch -} 57 -- deriving Data {- itemStatusNum sch = constrIndex $ toConstr sch -}
58 -- Using Generic to accomplish the job. 58 -- Using Generic works with Lyxia's generic-data package...
59 -- {- itemStatusNum sch = Lyxia.conIdToInt $ Lyxia.conId sch -}
60 -- For now, make sure to keep 'itemStatusNum' up to date with 'ScheduledItem'.
59 deriving Generics.Generic 61 deriving Generics.Generic
60 62
61 63
62itemStatusNum :: ScheduledItem -> Int 64itemStatusNum :: ScheduledItem -> Int
63itemStatusNum sch = Lyxia.conIdToInt $ Lyxia.conId sch 65itemStatusNum (DeleteAnnouncement ) = 0
66itemStatusNum (NewAnnouncement {}) = 1
67itemStatusNum (SearchFinished {}) = 2
68itemStatusNum (Announce {}) = 3
69itemStatusNum (SearchResult {}) = 4
70itemStatusNum (StopAnnouncer ) = 5
71itemStatusNum _ = error "itemStatusNum not in sync with ScheduledItem declaration."
64 72
65data Announcer = Announcer 73data Announcer = Announcer
66 { scheduled :: TVar (PSQ' AnnounceKey POSIXTime ScheduledItem) 74 { scheduled :: TVar (PSQ' AnnounceKey POSIXTime ScheduledItem)