module Network.Greskell.WebSocket.Connection.Type
( RawReq,
RawRes,
ReqID,
ResPack,
ReqPack(..),
ConnectionState(..),
Connection(..),
GeneralException(..)
) where
import Control.Concurrent.Async (Async)
import Control.Exception.Safe (SomeException, Typeable, Exception)
import Control.Concurrent.STM (TQueue, TBQueue, TVar)
import qualified Data.ByteString.Lazy as BSL
import Data.UUID (UUID)
import Network.Greskell.WebSocket.Response (ResponseMessage)
import Network.Greskell.WebSocket.Codec (Codec)
type RawReq = BSL.ByteString
type RawRes = BSL.ByteString
type ReqID = UUID
type ResPack s = Either SomeException (ResponseMessage s)
data ReqPack s =
ReqPack
{ ReqPack s -> RawReq
reqData :: !RawReq,
ReqPack s -> ReqID
reqId :: !ReqID,
ReqPack s -> TQueue (ResPack s)
reqOutput :: !(TQueue (ResPack s))
}
data ConnectionState =
ConnOpen
| ConnClosing
| ConnClosed
deriving (Int -> ConnectionState -> ShowS
[ConnectionState] -> ShowS
ConnectionState -> String
(Int -> ConnectionState -> ShowS)
-> (ConnectionState -> String)
-> ([ConnectionState] -> ShowS)
-> Show ConnectionState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConnectionState] -> ShowS
$cshowList :: [ConnectionState] -> ShowS
show :: ConnectionState -> String
$cshow :: ConnectionState -> String
showsPrec :: Int -> ConnectionState -> ShowS
$cshowsPrec :: Int -> ConnectionState -> ShowS
Show,ConnectionState -> ConnectionState -> Bool
(ConnectionState -> ConnectionState -> Bool)
-> (ConnectionState -> ConnectionState -> Bool)
-> Eq ConnectionState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConnectionState -> ConnectionState -> Bool
$c/= :: ConnectionState -> ConnectionState -> Bool
== :: ConnectionState -> ConnectionState -> Bool
$c== :: ConnectionState -> ConnectionState -> Bool
Eq,Eq ConnectionState
Eq ConnectionState
-> (ConnectionState -> ConnectionState -> Ordering)
-> (ConnectionState -> ConnectionState -> Bool)
-> (ConnectionState -> ConnectionState -> Bool)
-> (ConnectionState -> ConnectionState -> Bool)
-> (ConnectionState -> ConnectionState -> Bool)
-> (ConnectionState -> ConnectionState -> ConnectionState)
-> (ConnectionState -> ConnectionState -> ConnectionState)
-> Ord ConnectionState
ConnectionState -> ConnectionState -> Bool
ConnectionState -> ConnectionState -> Ordering
ConnectionState -> ConnectionState -> ConnectionState
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ConnectionState -> ConnectionState -> ConnectionState
$cmin :: ConnectionState -> ConnectionState -> ConnectionState
max :: ConnectionState -> ConnectionState -> ConnectionState
$cmax :: ConnectionState -> ConnectionState -> ConnectionState
>= :: ConnectionState -> ConnectionState -> Bool
$c>= :: ConnectionState -> ConnectionState -> Bool
> :: ConnectionState -> ConnectionState -> Bool
$c> :: ConnectionState -> ConnectionState -> Bool
<= :: ConnectionState -> ConnectionState -> Bool
$c<= :: ConnectionState -> ConnectionState -> Bool
< :: ConnectionState -> ConnectionState -> Bool
$c< :: ConnectionState -> ConnectionState -> Bool
compare :: ConnectionState -> ConnectionState -> Ordering
$ccompare :: ConnectionState -> ConnectionState -> Ordering
$cp1Ord :: Eq ConnectionState
Ord,Int -> ConnectionState
ConnectionState -> Int
ConnectionState -> [ConnectionState]
ConnectionState -> ConnectionState
ConnectionState -> ConnectionState -> [ConnectionState]
ConnectionState
-> ConnectionState -> ConnectionState -> [ConnectionState]
(ConnectionState -> ConnectionState)
-> (ConnectionState -> ConnectionState)
-> (Int -> ConnectionState)
-> (ConnectionState -> Int)
-> (ConnectionState -> [ConnectionState])
-> (ConnectionState -> ConnectionState -> [ConnectionState])
-> (ConnectionState -> ConnectionState -> [ConnectionState])
-> (ConnectionState
-> ConnectionState -> ConnectionState -> [ConnectionState])
-> Enum ConnectionState
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: ConnectionState
-> ConnectionState -> ConnectionState -> [ConnectionState]
$cenumFromThenTo :: ConnectionState
-> ConnectionState -> ConnectionState -> [ConnectionState]
enumFromTo :: ConnectionState -> ConnectionState -> [ConnectionState]
$cenumFromTo :: ConnectionState -> ConnectionState -> [ConnectionState]
enumFromThen :: ConnectionState -> ConnectionState -> [ConnectionState]
$cenumFromThen :: ConnectionState -> ConnectionState -> [ConnectionState]
enumFrom :: ConnectionState -> [ConnectionState]
$cenumFrom :: ConnectionState -> [ConnectionState]
fromEnum :: ConnectionState -> Int
$cfromEnum :: ConnectionState -> Int
toEnum :: Int -> ConnectionState
$ctoEnum :: Int -> ConnectionState
pred :: ConnectionState -> ConnectionState
$cpred :: ConnectionState -> ConnectionState
succ :: ConnectionState -> ConnectionState
$csucc :: ConnectionState -> ConnectionState
Enum,ConnectionState
ConnectionState -> ConnectionState -> Bounded ConnectionState
forall a. a -> a -> Bounded a
maxBound :: ConnectionState
$cmaxBound :: ConnectionState
minBound :: ConnectionState
$cminBound :: ConnectionState
Bounded)
data Connection s =
Connection
{ Connection s -> TBQueue (ReqPack s)
connQReq :: !(TBQueue (ReqPack s)),
Connection s -> TVar ConnectionState
connState :: !(TVar ConnectionState),
Connection s -> Async ()
connWSThread :: !(Async ()),
Connection s -> Codec s
connCodec :: !(Codec s)
}
data GeneralException =
UnexpectedRequestId UUID
| ResponseParseFailure String
deriving (Int -> GeneralException -> ShowS
[GeneralException] -> ShowS
GeneralException -> String
(Int -> GeneralException -> ShowS)
-> (GeneralException -> String)
-> ([GeneralException] -> ShowS)
-> Show GeneralException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GeneralException] -> ShowS
$cshowList :: [GeneralException] -> ShowS
show :: GeneralException -> String
$cshow :: GeneralException -> String
showsPrec :: Int -> GeneralException -> ShowS
$cshowsPrec :: Int -> GeneralException -> ShowS
Show,GeneralException -> GeneralException -> Bool
(GeneralException -> GeneralException -> Bool)
-> (GeneralException -> GeneralException -> Bool)
-> Eq GeneralException
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GeneralException -> GeneralException -> Bool
$c/= :: GeneralException -> GeneralException -> Bool
== :: GeneralException -> GeneralException -> Bool
$c== :: GeneralException -> GeneralException -> Bool
Eq,Typeable)
instance Exception GeneralException