{-# LINE 1 "src/Client/CApi/Types.hsc" #-}
{-# Language RecordWildCards #-}
module Client.CApi.Types
(
FgnExtension(..)
, StartExtension
, StopExtension
, ProcessMessage
, ProcessCommand
, ProcessChat
, TimerCallback
, TimerId
, FgnStringLen(..)
, FgnMsg(..)
, FgnCmd(..)
, FgnChat(..)
, Dynamic
, runStartExtension
, runStopExtension
, runProcessMessage
, runProcessCommand
, runProcessChat
, runTimerCallback
, MessageCode(..), normalMessage, errorMessage
, ProcessResult(..), passMessage, dropMessage
, withText0
, exportText
, poke'
) where
import Control.Monad
import Data.Text (Text)
import qualified Data.Text.Foreign as Text
import Data.Word
import Data.Int
import Foreign.C
import Foreign.Marshal.Array
import Foreign.Ptr
import Foreign.Storable
newtype MessageCode = MessageCode (Word32) deriving Eq
{-# LINE 75 "src/Client/CApi/Types.hsc" #-}
normalMessage :: MessageCode
normalMessage = MessageCode (0)
{-# LINE 80 "src/Client/CApi/Types.hsc" #-}
errorMessage :: MessageCode
errorMessage = MessageCode (1)
{-# LINE 85 "src/Client/CApi/Types.hsc" #-}
newtype ProcessResult = ProcessResult (Word32) deriving Eq
{-# LINE 91 "src/Client/CApi/Types.hsc" #-}
passMessage :: ProcessResult
passMessage = ProcessResult (0)
{-# LINE 95 "src/Client/CApi/Types.hsc" #-}
dropMessage :: ProcessResult
dropMessage = ProcessResult (1)
{-# LINE 99 "src/Client/CApi/Types.hsc" #-}
type StartExtension =
Ptr () ->
CString ->
Ptr FgnStringLen ->
CSize ->
IO (Ptr ())
type StopExtension =
Ptr () ->
IO ()
type ProcessMessage =
Ptr () ->
Ptr FgnMsg ->
IO ProcessResult
type ProcessCommand =
Ptr () ->
Ptr FgnCmd ->
IO ()
type ProcessChat =
Ptr () ->
Ptr FgnChat ->
IO ProcessResult
type TimerId = Int64
{-# LINE 133 "src/Client/CApi/Types.hsc" #-}
type TimerCallback =
Ptr () ->
TimerId ->
IO ()
type Dynamic a = FunPtr a -> a
foreign import ccall "dynamic" runStartExtension :: Dynamic StartExtension
foreign import ccall "dynamic" runStopExtension :: Dynamic StopExtension
foreign import ccall "dynamic" runProcessMessage :: Dynamic ProcessMessage
foreign import ccall "dynamic" runProcessCommand :: Dynamic ProcessCommand
foreign import ccall "dynamic" runProcessChat :: Dynamic ProcessChat
foreign import ccall "dynamic" runTimerCallback :: Dynamic TimerCallback
data FgnExtension = FgnExtension
{ fgnStart :: FunPtr StartExtension
, fgnStop :: FunPtr StopExtension
, fgnMessage :: FunPtr ProcessMessage
, fgnChat :: FunPtr ProcessChat
, fgnCommand :: FunPtr ProcessCommand
, fgnName :: CString
, fgnMajorVersion, fgnMinorVersion :: CInt
}
instance Storable FgnExtension where
alignment _ = 8
{-# LINE 173 "src/Client/CApi/Types.hsc" #-}
sizeOf _ = (56)
{-# LINE 174 "src/Client/CApi/Types.hsc" #-}
peek p = FgnExtension
<$> ((\hsc_ptr -> peekByteOff hsc_ptr 16)) p
{-# LINE 176 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 24)) p
{-# LINE 177 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 32)) p
{-# LINE 178 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 48)) p
{-# LINE 179 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 40)) p
{-# LINE 180 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p
{-# LINE 181 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 8)) p
{-# LINE 182 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 12)) p
{-# LINE 183 "src/Client/CApi/Types.hsc" #-}
poke p FgnExtension{..} =
do ((\hsc_ptr -> pokeByteOff hsc_ptr 16)) p fgnStart
{-# LINE 185 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) p fgnStop
{-# LINE 186 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 32)) p fgnMessage
{-# LINE 187 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 48)) p fgnChat
{-# LINE 188 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 40)) p fgnCommand
{-# LINE 189 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p fgnName
{-# LINE 190 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) p fgnMajorVersion
{-# LINE 191 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) p fgnMinorVersion
{-# LINE 192 "src/Client/CApi/Types.hsc" #-}
data FgnMsg = FgnMsg
{ fmNetwork :: FgnStringLen
, fmPrefixNick :: FgnStringLen
, fmPrefixUser :: FgnStringLen
, fmPrefixHost :: FgnStringLen
, fmCommand :: FgnStringLen
, fmParams :: Ptr FgnStringLen
, fmParamN :: CSize
, fmTagKeys :: Ptr FgnStringLen
, fmTagVals :: Ptr FgnStringLen
, fmTagN :: CSize
}
instance Storable FgnMsg where
alignment _ = 8
{-# LINE 211 "src/Client/CApi/Types.hsc" #-}
sizeOf _ = (120)
{-# LINE 212 "src/Client/CApi/Types.hsc" #-}
peek p = FgnMsg
<$> ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p
{-# LINE 214 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 16)) p
{-# LINE 215 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 32)) p
{-# LINE 216 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 48)) p
{-# LINE 217 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 64)) p
{-# LINE 218 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 80)) p
{-# LINE 219 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 88)) p
{-# LINE 220 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 96)) p
{-# LINE 221 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 104)) p
{-# LINE 222 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 112)) p
{-# LINE 223 "src/Client/CApi/Types.hsc" #-}
poke p FgnMsg{..} =
do ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p fmNetwork
{-# LINE 226 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) p fmPrefixNick
{-# LINE 227 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 32)) p fmPrefixUser
{-# LINE 228 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 48)) p fmPrefixHost
{-# LINE 229 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 64)) p fmCommand
{-# LINE 230 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 80)) p fmParams
{-# LINE 231 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 88)) p fmParamN
{-# LINE 232 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 96)) p fmTagKeys
{-# LINE 233 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 104)) p fmTagVals
{-# LINE 234 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 112)) p fmTagN
{-# LINE 235 "src/Client/CApi/Types.hsc" #-}
data FgnChat = FgnChat
{ fhNetwork :: FgnStringLen
, fhTarget :: FgnStringLen
, fhMessage :: FgnStringLen
}
instance Storable FgnChat where
alignment _ = 8
{-# LINE 249 "src/Client/CApi/Types.hsc" #-}
sizeOf _ = (48)
{-# LINE 250 "src/Client/CApi/Types.hsc" #-}
peek p = FgnChat
<$> ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p
{-# LINE 252 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 16)) p
{-# LINE 253 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 32)) p
{-# LINE 254 "src/Client/CApi/Types.hsc" #-}
poke p FgnChat{..} =
do ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p fhNetwork
{-# LINE 257 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) p fhTarget
{-# LINE 258 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 32)) p fhMessage
{-# LINE 259 "src/Client/CApi/Types.hsc" #-}
data FgnCmd = FgnCmd
{ fcCommand :: FgnStringLen
}
instance Storable FgnCmd where
alignment _ = 8
{-# LINE 271 "src/Client/CApi/Types.hsc" #-}
sizeOf _ = (16)
{-# LINE 272 "src/Client/CApi/Types.hsc" #-}
peek p = FgnCmd
<$> ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p
{-# LINE 274 "src/Client/CApi/Types.hsc" #-}
poke p FgnCmd{..} = ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p fcCommand
{-# LINE 276 "src/Client/CApi/Types.hsc" #-}
data FgnStringLen = FgnStringLen !CString !CSize
instance Storable FgnStringLen where
alignment _ = 8
{-# LINE 286 "src/Client/CApi/Types.hsc" #-}
sizeOf _ = (16)
{-# LINE 287 "src/Client/CApi/Types.hsc" #-}
peek p = FgnStringLen
<$> ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p
{-# LINE 289 "src/Client/CApi/Types.hsc" #-}
<*> ((\hsc_ptr -> peekByteOff hsc_ptr 8)) p
{-# LINE 290 "src/Client/CApi/Types.hsc" #-}
poke p (FgnStringLen x y) =
do ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p x
{-# LINE 292 "src/Client/CApi/Types.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) p y
{-# LINE 293 "src/Client/CApi/Types.hsc" #-}
poke' :: Storable a => Ptr a -> a -> IO ()
poke' ptr x = unless (nullPtr == ptr) (poke ptr x)
exportText :: Ptr CString -> Ptr CSize -> Text -> IO ()
exportText dstP dstL txt =
Text.withCStringLen txt $ \(srcP, srcL) ->
do poke' dstL (fromIntegral srcL)
unless (dstP == nullPtr) $
do a <- mallocArray0 srcL
copyArray a srcP srcL
pokeElemOff a srcL 0
poke dstP a
withText0 :: Text -> (CStringLen -> IO a) -> IO a
withText0 txt k =
Text.withCStringLen txt $ \(p,l) ->
allocaArray0 l $ \p' ->
do copyArray p' p l
pokeElemOff p' l 0
k (p', l)