{-# LINE 1 "src/common/Foreign/JNI/NativeMethod.hsc" #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RecordWildCards #-}
module Foreign.JNI.NativeMethod where
import qualified Data.ByteString.Unsafe as BS
import Data.Coerce (coerce)
import Foreign.JNI.Internal
import qualified Foreign.JNI.String as JNI
import Foreign.Ptr (FunPtr)
import Foreign.Storable (Storable(..))
{-# LINE 20 "src/common/Foreign/JNI/NativeMethod.hsc" #-}
data JNINativeMethod = forall a. JNINativeMethod
{ JNINativeMethod -> String
jniNativeMethodName :: JNI.String
, JNINativeMethod -> MethodSignature
jniNativeMethodSignature :: MethodSignature
, ()
jniNativeMethodFunPtr :: FunPtr a
}
instance Storable JNINativeMethod where
sizeOf :: JNINativeMethod -> Int
sizeOf JNINativeMethod
_ = (Int
24)
{-# LINE 29 "src/common/Foreign/JNI/NativeMethod.hsc" #-}
alignment _ = 8
{-# LINE 30 "src/common/Foreign/JNI/NativeMethod.hsc" #-}
peek ptr = do
name <- BS.unsafePackCString =<< (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
{-# LINE 32 "src/common/Foreign/JNI/NativeMethod.hsc" #-}
sig <- BS.unsafePackCString =<< (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
{-# LINE 33 "src/common/Foreign/JNI/NativeMethod.hsc" #-}
fptr <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 34 "src/common/Foreign/JNI/NativeMethod.hsc" #-}
return $
JNINativeMethod
(JNI.unsafeFromByteString name)
(coerce (JNI.unsafeFromByteString sig))
fptr
poke :: Ptr JNINativeMethod -> JNINativeMethod -> IO ()
poke Ptr JNINativeMethod
ptr JNINativeMethod{FunPtr a
String
MethodSignature
jniNativeMethodFunPtr :: FunPtr a
jniNativeMethodSignature :: MethodSignature
jniNativeMethodName :: String
jniNativeMethodFunPtr :: ()
jniNativeMethodSignature :: JNINativeMethod -> MethodSignature
jniNativeMethodName :: JNINativeMethod -> String
..} = do
String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
JNI.withString String
jniNativeMethodName ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (\Ptr JNINativeMethod
hsc_ptr -> Ptr JNINativeMethod -> Int -> CString -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr JNINativeMethod
hsc_ptr Int
0) Ptr JNINativeMethod
ptr
{-# LINE 41 "src/common/Foreign/JNI/NativeMethod.hsc" #-}
JNI.withString (coerce jniNativeMethodSignature) $ (\hsc_ptr -> pokeByteOff hsc_ptr 8) ptr
{-# LINE 42 "src/common/Foreign/JNI/NativeMethod.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 16) ptr jniNativeMethodFunPtr
{-# LINE 43 "src/common/Foreign/JNI/NativeMethod.hsc" #-}