{-# LINE 1 "src/Database/PostgreSQL/LibPQ/Notify.hsc" #-}
module Database.PostgreSQL.LibPQ.Notify where



import Foreign (Ptr, Storable (..))
import Foreign.C.Types (CInt, CSize)
import System.Posix.Types (CPid)

import qualified Data.ByteString as B

-------------------------------------------------------------------------------
-- Notify
-------------------------------------------------------------------------------

data Notify = Notify {
      Notify -> ByteString
notifyRelname :: {-# UNPACK #-} !B.ByteString -- ^ notification channel name
    , Notify -> CPid
notifyBePid   :: {-# UNPACK #-} !CPid         -- ^ process ID of notifying server process
    , Notify -> ByteString
notifyExtra   :: {-# UNPACK #-} !B.ByteString -- ^ notification payload string
    } deriving Int -> Notify -> ShowS
[Notify] -> ShowS
Notify -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Notify] -> ShowS
$cshowList :: [Notify] -> ShowS
show :: Notify -> String
$cshow :: Notify -> String
showsPrec :: Int -> Notify -> ShowS
$cshowsPrec :: Int -> Notify -> ShowS
Show

instance Storable Notify where
  sizeOf :: Notify -> Int
sizeOf Notify
_ = (Int
32)
{-# LINE 23 "src/Database/PostgreSQL/LibPQ/Notify.hsc" #-}

  alignment :: Notify -> Int
alignment Notify
_ = Int
8
{-# LINE 25 "src/Database/PostgreSQL/LibPQ/Notify.hsc" #-}

  peek :: Ptr Notify -> IO Notify
peek Ptr Notify
ptr = do
      ByteString
relname <- CString -> IO ByteString
B.packCString forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (\Ptr Notify
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr Notify
hsc_ptr Int
0) Ptr Notify
ptr
{-# LINE 28 "src/Database/PostgreSQL/LibPQ/Notify.hsc" #-}
      extra   <- B.packCString =<< (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 29 "src/Database/PostgreSQL/LibPQ/Notify.hsc" #-}
      be_pid  <- fmap f $ (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
{-# LINE 30 "src/Database/PostgreSQL/LibPQ/Notify.hsc" #-}
      return $! Notify relname be_pid extra
      where
        f :: CInt -> CPid
        f :: CInt -> CPid
f = forall a b. (Integral a, Num b) => a -> b
fromIntegral

  poke :: Ptr Notify -> Notify -> IO ()
poke Ptr Notify
ptr (Notify ByteString
a CPid
b ByteString
c) =
      forall a. ByteString -> (CString -> IO a) -> IO a
B.useAsCString ByteString
a forall a b. (a -> b) -> a -> b
$ \CString
a' ->
        forall a. ByteString -> (CString -> IO a) -> IO a
B.useAsCString ByteString
c forall a b. (a -> b) -> a -> b
$ \CString
c' ->
            do (\Ptr Notify
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr Notify
hsc_ptr Int
0) Ptr Notify
ptr CString
a'
{-# LINE 39 "src/Database/PostgreSQL/LibPQ/Notify.hsc" #-}
               (\Ptr Notify
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr Notify
hsc_ptr Int
8)  Ptr Notify
ptr (forall a b. (Integral a, Num b) => a -> b
fromIntegral CPid
b :: CInt)
{-# LINE 40 "src/Database/PostgreSQL/LibPQ/Notify.hsc" #-}
               (\Ptr Notify
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr Notify
hsc_ptr Int
16)   Ptr Notify
ptr CString
c'
{-# LINE 41 "src/Database/PostgreSQL/LibPQ/Notify.hsc" #-}

-------------------------------------------------------------------------------
-- Notice
-------------------------------------------------------------------------------

data PGnotice

pgNoticePeekLen :: Ptr PGnotice -> IO CSize
pgNoticePeekLen :: Ptr PGnotice -> IO CSize
pgNoticePeekLen = (\Ptr PGnotice
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr PGnotice
hsc_ptr Int
8)
{-# LINE 50 "src/Database/PostgreSQL/LibPQ/Notify.hsc" #-}

pgNoticeOffsetStr :: Int
pgNoticeOffsetStr :: Int
pgNoticeOffsetStr = (Int
16)
{-# LINE 53 "src/Database/PostgreSQL/LibPQ/Notify.hsc" #-}