{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.Gio.Interfaces.Converter
(
Converter(..) ,
noConverter ,
IsConverter ,
toConverter ,
#if defined(ENABLE_OVERLOADING)
ResolveConverterMethod ,
#endif
#if defined(ENABLE_OVERLOADING)
ConverterConvertMethodInfo ,
#endif
converterConvert ,
#if defined(ENABLE_OVERLOADING)
ConverterResetMethodInfo ,
#endif
converterReset ,
) 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.ManagedPtr as B.ManagedPtr
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 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 GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Enums as Gio.Enums
import {-# SOURCE #-} qualified GI.Gio.Flags as Gio.Flags
newtype Converter = Converter (ManagedPtr Converter)
deriving (Converter -> Converter -> Bool
(Converter -> Converter -> Bool)
-> (Converter -> Converter -> Bool) -> Eq Converter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Converter -> Converter -> Bool
$c/= :: Converter -> Converter -> Bool
== :: Converter -> Converter -> Bool
$c== :: Converter -> Converter -> Bool
Eq)
noConverter :: Maybe Converter
noConverter :: Maybe Converter
noConverter = Maybe Converter
forall a. Maybe a
Nothing
#if defined(ENABLE_OVERLOADING)
type instance O.SignalList Converter = ConverterSignalList
type ConverterSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])
#endif
foreign import ccall "g_converter_get_type"
c_g_converter_get_type :: IO GType
instance GObject Converter where
gobjectType :: IO GType
gobjectType = IO GType
c_g_converter_get_type
instance B.GValue.IsGValue Converter where
toGValue :: Converter -> IO GValue
toGValue o :: Converter
o = do
GType
gtype <- IO GType
c_g_converter_get_type
Converter -> (Ptr Converter -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Converter
o (GType
-> (GValue -> Ptr Converter -> IO ()) -> Ptr Converter -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr Converter -> IO ()
forall a. GObject a => GValue -> Ptr a -> IO ()
B.GValue.set_object)
fromGValue :: GValue -> IO Converter
fromGValue gv :: GValue
gv = do
Ptr Converter
ptr <- GValue -> IO (Ptr Converter)
forall b. GObject b => GValue -> IO (Ptr b)
B.GValue.get_object GValue
gv :: IO (Ptr Converter)
(ManagedPtr Converter -> Converter)
-> Ptr Converter -> IO Converter
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr Converter -> Converter
Converter Ptr Converter
ptr
class (GObject o, O.IsDescendantOf Converter o) => IsConverter o
instance (GObject o, O.IsDescendantOf Converter o) => IsConverter o
instance O.HasParentTypes Converter
type instance O.ParentTypes Converter = '[GObject.Object.Object]
toConverter :: (MonadIO m, IsConverter o) => o -> m Converter
toConverter :: o -> m Converter
toConverter = IO Converter -> m Converter
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Converter -> m Converter)
-> (o -> IO Converter) -> o -> m Converter
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr Converter -> Converter) -> o -> IO Converter
forall o o'.
(HasCallStack, GObject o, GObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
unsafeCastTo ManagedPtr Converter -> Converter
Converter
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Converter
type instance O.AttributeList Converter = ConverterAttributeList
type ConverterAttributeList = ('[ ] :: [(Symbol, *)])
#endif
#if defined(ENABLE_OVERLOADING)
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolveConverterMethod (t :: Symbol) (o :: *) :: * where
ResolveConverterMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
ResolveConverterMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
ResolveConverterMethod "convert" o = ConverterConvertMethodInfo
ResolveConverterMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
ResolveConverterMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
ResolveConverterMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
ResolveConverterMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
ResolveConverterMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
ResolveConverterMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
ResolveConverterMethod "ref" o = GObject.Object.ObjectRefMethodInfo
ResolveConverterMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
ResolveConverterMethod "reset" o = ConverterResetMethodInfo
ResolveConverterMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
ResolveConverterMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
ResolveConverterMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
ResolveConverterMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
ResolveConverterMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
ResolveConverterMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
ResolveConverterMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
ResolveConverterMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
ResolveConverterMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
ResolveConverterMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
ResolveConverterMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
ResolveConverterMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
ResolveConverterMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveConverterMethod t Converter, O.MethodInfo info Converter p) => OL.IsLabel t (Converter -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#endif
foreign import ccall "g_converter_convert" g_converter_convert ::
Ptr Converter ->
Ptr Word8 ->
Word64 ->
Ptr Word8 ->
Word64 ->
CUInt ->
Ptr Word64 ->
Ptr Word64 ->
Ptr (Ptr GError) ->
IO CUInt
converterConvert ::
(B.CallStack.HasCallStack, MonadIO m, IsConverter a) =>
a
-> Maybe (ByteString)
-> Maybe (ByteString)
-> [Gio.Flags.ConverterFlags]
-> m ((Gio.Enums.ConverterResult, Word64, Word64))
converterConvert :: a
-> Maybe ByteString
-> Maybe ByteString
-> [ConverterFlags]
-> m (ConverterResult, Word64, Word64)
converterConvert converter :: a
converter inbuf :: Maybe ByteString
inbuf outbuf :: Maybe ByteString
outbuf flags :: [ConverterFlags]
flags = IO (ConverterResult, Word64, Word64)
-> m (ConverterResult, Word64, Word64)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (ConverterResult, Word64, Word64)
-> m (ConverterResult, Word64, Word64))
-> IO (ConverterResult, Word64, Word64)
-> m (ConverterResult, Word64, Word64)
forall a b. (a -> b) -> a -> b
$ do
let outbufSize :: Word64
outbufSize = case Maybe ByteString
outbuf of
Nothing -> 0
Just jOutbuf :: ByteString
jOutbuf -> Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word64) -> Int -> Word64
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
jOutbuf
let inbufSize :: Word64
inbufSize = case Maybe ByteString
inbuf of
Nothing -> 0
Just jInbuf :: ByteString
jInbuf -> Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word64) -> Int -> Word64
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
jInbuf
Ptr Converter
converter' <- a -> IO (Ptr Converter)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
converter
Ptr Word8
maybeInbuf <- case Maybe ByteString
inbuf of
Nothing -> Ptr Word8 -> IO (Ptr Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Word8
forall a. Ptr a
nullPtr
Just jInbuf :: ByteString
jInbuf -> do
Ptr Word8
jInbuf' <- ByteString -> IO (Ptr Word8)
packByteString ByteString
jInbuf
Ptr Word8 -> IO (Ptr Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Word8
jInbuf'
Ptr Word8
maybeOutbuf <- case Maybe ByteString
outbuf of
Nothing -> Ptr Word8 -> IO (Ptr Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Word8
forall a. Ptr a
nullPtr
Just jOutbuf :: ByteString
jOutbuf -> do
Ptr Word8
jOutbuf' <- ByteString -> IO (Ptr Word8)
packByteString ByteString
jOutbuf
Ptr Word8 -> IO (Ptr Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Word8
jOutbuf'
let flags' :: CUInt
flags' = [ConverterFlags] -> CUInt
forall b a. (Num b, IsGFlag a) => [a] -> b
gflagsToWord [ConverterFlags]
flags
Ptr Word64
bytesRead <- IO (Ptr Word64)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word64)
Ptr Word64
bytesWritten <- IO (Ptr Word64)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word64)
IO (ConverterResult, Word64, Word64)
-> IO () -> IO (ConverterResult, Word64, Word64)
forall a b. IO a -> IO b -> IO a
onException (do
CUInt
result <- (Ptr (Ptr GError) -> IO CUInt) -> IO CUInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CUInt) -> IO CUInt)
-> (Ptr (Ptr GError) -> IO CUInt) -> IO CUInt
forall a b. (a -> b) -> a -> b
$ Ptr Converter
-> Ptr Word8
-> Word64
-> Ptr Word8
-> Word64
-> CUInt
-> Ptr Word64
-> Ptr Word64
-> Ptr (Ptr GError)
-> IO CUInt
g_converter_convert Ptr Converter
converter' Ptr Word8
maybeInbuf Word64
inbufSize Ptr Word8
maybeOutbuf Word64
outbufSize CUInt
flags' Ptr Word64
bytesRead Ptr Word64
bytesWritten
let result' :: ConverterResult
result' = (Int -> ConverterResult
forall a. Enum a => Int -> a
toEnum (Int -> ConverterResult)
-> (CUInt -> Int) -> CUInt -> ConverterResult
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) CUInt
result
Word64
bytesRead' <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
bytesRead
Word64
bytesWritten' <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
bytesWritten
a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
converter
Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
maybeInbuf
Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
maybeOutbuf
Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
bytesRead
Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
bytesWritten
(ConverterResult, Word64, Word64)
-> IO (ConverterResult, Word64, Word64)
forall (m :: * -> *) a. Monad m => a -> m a
return (ConverterResult
result', Word64
bytesRead', Word64
bytesWritten')
) (do
Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
maybeInbuf
Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
maybeOutbuf
Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
bytesRead
Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
bytesWritten
)
#if defined(ENABLE_OVERLOADING)
data ConverterConvertMethodInfo
instance (signature ~ (Maybe (ByteString) -> Maybe (ByteString) -> [Gio.Flags.ConverterFlags] -> m ((Gio.Enums.ConverterResult, Word64, Word64))), MonadIO m, IsConverter a) => O.MethodInfo ConverterConvertMethodInfo a signature where
overloadedMethod = converterConvert
#endif
foreign import ccall "g_converter_reset" g_converter_reset ::
Ptr Converter ->
IO ()
converterReset ::
(B.CallStack.HasCallStack, MonadIO m, IsConverter a) =>
a
-> m ()
converterReset :: a -> m ()
converterReset converter :: a
converter = 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 Converter
converter' <- a -> IO (Ptr Converter)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
converter
Ptr Converter -> IO ()
g_converter_reset Ptr Converter
converter'
a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
converter
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data ConverterResetMethodInfo
instance (signature ~ (m ()), MonadIO m, IsConverter a) => O.MethodInfo ConverterResetMethodInfo a signature where
overloadedMethod = converterReset
#endif