{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.GModule.Structs.Module
(
Module(..) ,
#if defined(ENABLE_OVERLOADING)
ResolveModuleMethod ,
#endif
moduleBuildPath ,
#if defined(ENABLE_OVERLOADING)
ModuleCloseMethodInfo ,
#endif
moduleClose ,
moduleError ,
#if defined(ENABLE_OVERLOADING)
ModuleMakeResidentMethodInfo ,
#endif
moduleMakeResident ,
#if defined(ENABLE_OVERLOADING)
ModuleNameMethodInfo ,
#endif
moduleName ,
moduleSupported ,
#if defined(ENABLE_OVERLOADING)
ModuleSymbolMethodInfo ,
#endif
moduleSymbol ,
) where
import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P
import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
import qualified GHC.Records as R
newtype Module = Module (SP.ManagedPtr Module)
deriving (Module -> Module -> Bool
(Module -> Module -> Bool)
-> (Module -> Module -> Bool) -> Eq Module
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Module -> Module -> Bool
$c/= :: Module -> Module -> Bool
== :: Module -> Module -> Bool
$c== :: Module -> Module -> Bool
Eq)
instance SP.ManagedPtrNewtype Module where
toManagedPtr :: Module -> ManagedPtr Module
toManagedPtr (Module ManagedPtr Module
p) = ManagedPtr Module
p
instance BoxedPtr Module where
boxedPtrCopy :: Module -> IO Module
boxedPtrCopy = Module -> IO Module
forall (m :: * -> *) a. Monad m => a -> m a
return
boxedPtrFree :: Module -> IO ()
boxedPtrFree = \Module
_x -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Module
type instance O.AttributeList Module = ModuleAttributeList
type ModuleAttributeList = ('[ ] :: [(Symbol, *)])
#endif
foreign import ccall "g_module_close" g_module_close ::
Ptr Module ->
IO CInt
moduleClose ::
(B.CallStack.HasCallStack, MonadIO m) =>
Module
-> m Bool
moduleClose :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Module -> m Bool
moduleClose Module
module_ = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
Ptr Module
module_' <- Module -> IO (Ptr Module)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Module
module_
CInt
result <- Ptr Module -> IO CInt
g_module_close Ptr Module
module_'
let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
Module -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Module
module_
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'
#if defined(ENABLE_OVERLOADING)
data ModuleCloseMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.OverloadedMethod ModuleCloseMethodInfo Module signature where
overloadedMethod = moduleClose
instance O.OverloadedMethodInfo ModuleCloseMethodInfo Module where
overloadedMethodInfo = O.MethodInfo {
O.overloadedMethodName = "GI.GModule.Structs.Module.moduleClose",
O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gmodule-2.0.1/docs/GI-GModule-Structs-Module.html#v:moduleClose"
}
#endif
foreign import ccall "g_module_make_resident" g_module_make_resident ::
Ptr Module ->
IO ()
moduleMakeResident ::
(B.CallStack.HasCallStack, MonadIO m) =>
Module
-> m ()
moduleMakeResident :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Module -> m ()
moduleMakeResident Module
module_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Ptr Module
module_' <- Module -> IO (Ptr Module)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Module
module_
Ptr Module -> IO ()
g_module_make_resident Ptr Module
module_'
Module -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Module
module_
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data ModuleMakeResidentMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.OverloadedMethod ModuleMakeResidentMethodInfo Module signature where
overloadedMethod = moduleMakeResident
instance O.OverloadedMethodInfo ModuleMakeResidentMethodInfo Module where
overloadedMethodInfo = O.MethodInfo {
O.overloadedMethodName = "GI.GModule.Structs.Module.moduleMakeResident",
O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gmodule-2.0.1/docs/GI-GModule-Structs-Module.html#v:moduleMakeResident"
}
#endif
foreign import ccall "g_module_name" g_module_name ::
Ptr Module ->
IO CString
moduleName ::
(B.CallStack.HasCallStack, MonadIO m) =>
Module
-> m T.Text
moduleName :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Module -> m Text
moduleName Module
module_ = IO Text -> m Text
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
Ptr Module
module_' <- Module -> IO (Ptr Module)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Module
module_
CString
result <- Ptr Module -> IO CString
g_module_name Ptr Module
module_'
Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"moduleName" CString
result
Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
Module -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Module
module_
Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'
#if defined(ENABLE_OVERLOADING)
data ModuleNameMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.OverloadedMethod ModuleNameMethodInfo Module signature where
overloadedMethod = moduleName
instance O.OverloadedMethodInfo ModuleNameMethodInfo Module where
overloadedMethodInfo = O.MethodInfo {
O.overloadedMethodName = "GI.GModule.Structs.Module.moduleName",
O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gmodule-2.0.1/docs/GI-GModule-Structs-Module.html#v:moduleName"
}
#endif
foreign import ccall "g_module_symbol" g_module_symbol ::
Ptr Module ->
CString ->
Ptr (Ptr ()) ->
IO CInt
moduleSymbol ::
(B.CallStack.HasCallStack, MonadIO m) =>
Module
-> T.Text
-> m ((Bool, Ptr ()))
moduleSymbol :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Module -> Text -> m (Bool, Ptr ())
moduleSymbol Module
module_ Text
symbolName = IO (Bool, Ptr ()) -> m (Bool, Ptr ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Bool, Ptr ()) -> m (Bool, Ptr ()))
-> IO (Bool, Ptr ()) -> m (Bool, Ptr ())
forall a b. (a -> b) -> a -> b
$ do
Ptr Module
module_' <- Module -> IO (Ptr Module)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Module
module_
CString
symbolName' <- Text -> IO CString
textToCString Text
symbolName
Ptr (Ptr ())
symbol <- IO (Ptr (Ptr ()))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (Ptr ()))
CInt
result <- Ptr Module -> CString -> Ptr (Ptr ()) -> IO CInt
g_module_symbol Ptr Module
module_' CString
symbolName' Ptr (Ptr ())
symbol
let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
Ptr ()
symbol' <- Ptr (Ptr ()) -> IO (Ptr ())
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr ())
symbol
Module -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Module
module_
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
symbolName'
Ptr (Ptr ()) -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr (Ptr ())
symbol
(Bool, Ptr ()) -> IO (Bool, Ptr ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
result', Ptr ()
symbol')
#if defined(ENABLE_OVERLOADING)
data ModuleSymbolMethodInfo
instance (signature ~ (T.Text -> m ((Bool, Ptr ()))), MonadIO m) => O.OverloadedMethod ModuleSymbolMethodInfo Module signature where
overloadedMethod = moduleSymbol
instance O.OverloadedMethodInfo ModuleSymbolMethodInfo Module where
overloadedMethodInfo = O.MethodInfo {
O.overloadedMethodName = "GI.GModule.Structs.Module.moduleSymbol",
O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gmodule-2.0.1/docs/GI-GModule-Structs-Module.html#v:moduleSymbol"
}
#endif
foreign import ccall "g_module_build_path" g_module_build_path ::
CString ->
CString ->
IO CString
moduleBuildPath ::
(B.CallStack.HasCallStack, MonadIO m) =>
Maybe (T.Text)
-> T.Text
-> m T.Text
moduleBuildPath :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Maybe Text -> Text -> m Text
moduleBuildPath Maybe Text
directory Text
moduleName = IO Text -> m Text
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
CString
maybeDirectory <- case Maybe Text
directory of
Maybe Text
Nothing -> CString -> IO CString
forall (m :: * -> *) a. Monad m => a -> m a
return CString
forall a. Ptr a
nullPtr
Just Text
jDirectory -> do
CString
jDirectory' <- Text -> IO CString
textToCString Text
jDirectory
CString -> IO CString
forall (m :: * -> *) a. Monad m => a -> m a
return CString
jDirectory'
CString
moduleName' <- Text -> IO CString
textToCString Text
moduleName
CString
result <- CString -> CString -> IO CString
g_module_build_path CString
maybeDirectory CString
moduleName'
Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"moduleBuildPath" CString
result
Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
maybeDirectory
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
moduleName'
Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'
#if defined(ENABLE_OVERLOADING)
#endif
foreign import ccall "g_module_error" g_module_error ::
IO CString
moduleError ::
(B.CallStack.HasCallStack, MonadIO m) =>
m T.Text
moduleError :: forall (m :: * -> *). (HasCallStack, MonadIO m) => m Text
moduleError = IO Text -> m Text
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
CString
result <- IO CString
g_module_error
Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"moduleError" CString
result
Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'
#if defined(ENABLE_OVERLOADING)
#endif
foreign import ccall "g_module_supported" g_module_supported ::
IO CInt
moduleSupported ::
(B.CallStack.HasCallStack, MonadIO m) =>
m Bool
moduleSupported :: forall (m :: * -> *). (HasCallStack, MonadIO m) => m Bool
moduleSupported = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
CInt
result <- IO CInt
g_module_supported
let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'
#if defined(ENABLE_OVERLOADING)
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolveModuleMethod (t :: Symbol) (o :: *) :: * where
ResolveModuleMethod "close" o = ModuleCloseMethodInfo
ResolveModuleMethod "makeResident" o = ModuleMakeResidentMethodInfo
ResolveModuleMethod "name" o = ModuleNameMethodInfo
ResolveModuleMethod "symbol" o = ModuleSymbolMethodInfo
ResolveModuleMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveModuleMethod t Module, O.OverloadedMethod info Module p) => OL.IsLabel t (Module -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveModuleMethod t Module, O.OverloadedMethod info Module p, R.HasField t Module p) => R.HasField t Module p where
getField = O.overloadedMethod @info
#endif
instance (info ~ ResolveModuleMethod t Module, O.OverloadedMethodInfo info Module) => OL.IsLabel t (O.MethodProxy info Module) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.MethodProxy
#else
fromLabel _ = O.MethodProxy
#endif
#endif