{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.Secret.Structs.Schema
(
Schema(..) ,
newZeroSchema ,
#if defined(ENABLE_OVERLOADING)
ResolveSchemaMethod ,
#endif
#if defined(ENABLE_OVERLOADING)
SchemaRefMethodInfo ,
#endif
schemaRef ,
#if defined(ENABLE_OVERLOADING)
SchemaUnrefMethodInfo ,
#endif
schemaUnref ,
getSchemaFlags ,
#if defined(ENABLE_OVERLOADING)
schema_flags ,
#endif
setSchemaFlags ,
clearSchemaName ,
getSchemaName ,
#if defined(ENABLE_OVERLOADING)
schema_name ,
#endif
setSchemaName ,
) 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.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 {-# SOURCE #-} qualified GI.Secret.Flags as Secret.Flags
newtype Schema = Schema (SP.ManagedPtr Schema)
deriving (Schema -> Schema -> Bool
(Schema -> Schema -> Bool)
-> (Schema -> Schema -> Bool) -> Eq Schema
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Schema -> Schema -> Bool
$c/= :: Schema -> Schema -> Bool
== :: Schema -> Schema -> Bool
$c== :: Schema -> Schema -> Bool
Eq)
instance SP.ManagedPtrNewtype Schema where
toManagedPtr :: Schema -> ManagedPtr Schema
toManagedPtr (Schema ManagedPtr Schema
p) = ManagedPtr Schema
p
foreign import ccall "secret_schema_get_type" c_secret_schema_get_type ::
IO GType
type instance O.ParentTypes Schema = '[]
instance O.HasParentTypes Schema
instance B.Types.TypedObject Schema where
glibType :: IO GType
glibType = IO GType
c_secret_schema_get_type
instance B.Types.GBoxed Schema
instance B.GValue.IsGValue Schema where
toGValue :: Schema -> IO GValue
toGValue Schema
o = do
GType
gtype <- IO GType
c_secret_schema_get_type
Schema -> (Ptr Schema -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Schema
o (GType -> (GValue -> Ptr Schema -> IO ()) -> Ptr Schema -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr Schema -> IO ()
forall a. GValue -> Ptr a -> IO ()
B.GValue.set_boxed)
fromGValue :: GValue -> IO Schema
fromGValue GValue
gv = do
Ptr Schema
ptr <- GValue -> IO (Ptr Schema)
forall b. GValue -> IO (Ptr b)
B.GValue.get_boxed GValue
gv :: IO (Ptr Schema)
(ManagedPtr Schema -> Schema) -> Ptr Schema -> IO Schema
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.newBoxed ManagedPtr Schema -> Schema
Schema Ptr Schema
ptr
newZeroSchema :: MonadIO m => m Schema
newZeroSchema :: m Schema
newZeroSchema = IO Schema -> m Schema
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Schema -> m Schema) -> IO Schema -> m Schema
forall a b. (a -> b) -> a -> b
$ Int -> IO (Ptr Schema)
forall a. GBoxed a => Int -> IO (Ptr a)
callocBoxedBytes Int
592 IO (Ptr Schema) -> (Ptr Schema -> IO Schema) -> IO Schema
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ManagedPtr Schema -> Schema) -> Ptr Schema -> IO Schema
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Schema -> Schema
Schema
instance tag ~ 'AttrSet => Constructible Schema tag where
new :: (ManagedPtr Schema -> Schema) -> [AttrOp Schema tag] -> m Schema
new ManagedPtr Schema -> Schema
_ [AttrOp Schema tag]
attrs = do
Schema
o <- m Schema
forall (m :: * -> *). MonadIO m => m Schema
newZeroSchema
Schema -> [AttrOp Schema 'AttrSet] -> m ()
forall o (m :: * -> *).
MonadIO m =>
o -> [AttrOp o 'AttrSet] -> m ()
GI.Attributes.set Schema
o [AttrOp Schema tag]
[AttrOp Schema 'AttrSet]
attrs
Schema -> m Schema
forall (m :: * -> *) a. Monad m => a -> m a
return Schema
o
getSchemaName :: MonadIO m => Schema -> m (Maybe T.Text)
getSchemaName :: Schema -> m (Maybe Text)
getSchemaName Schema
s = IO (Maybe Text) -> m (Maybe Text)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Text) -> m (Maybe Text))
-> IO (Maybe Text) -> m (Maybe Text)
forall a b. (a -> b) -> a -> b
$ Schema -> (Ptr Schema -> IO (Maybe Text)) -> IO (Maybe Text)
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Schema
s ((Ptr Schema -> IO (Maybe Text)) -> IO (Maybe Text))
-> (Ptr Schema -> IO (Maybe Text)) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \Ptr Schema
ptr -> do
CString
val <- Ptr CString -> IO CString
forall a. Storable a => Ptr a -> IO a
peek (Ptr Schema
ptr Ptr Schema -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) :: IO CString
Maybe Text
result <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
SP.convertIfNonNull CString
val ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \CString
val' -> do
Text
val'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
val'
Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
val''
Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
result
setSchemaName :: MonadIO m => Schema -> CString -> m ()
setSchemaName :: Schema -> CString -> m ()
setSchemaName Schema
s CString
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Schema -> (Ptr Schema -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Schema
s ((Ptr Schema -> IO ()) -> IO ()) -> (Ptr Schema -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Schema
ptr -> do
Ptr CString -> CString -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Schema
ptr Ptr Schema -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) (CString
val :: CString)
clearSchemaName :: MonadIO m => Schema -> m ()
clearSchemaName :: Schema -> m ()
clearSchemaName Schema
s = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Schema -> (Ptr Schema -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Schema
s ((Ptr Schema -> IO ()) -> IO ()) -> (Ptr Schema -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Schema
ptr -> do
Ptr CString -> CString -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Schema
ptr Ptr Schema -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) (CString
forall a. Ptr a
FP.nullPtr :: CString)
#if defined(ENABLE_OVERLOADING)
data SchemaNameFieldInfo
instance AttrInfo SchemaNameFieldInfo where
type AttrBaseTypeConstraint SchemaNameFieldInfo = (~) Schema
type AttrAllowedOps SchemaNameFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
type AttrSetTypeConstraint SchemaNameFieldInfo = (~) CString
type AttrTransferTypeConstraint SchemaNameFieldInfo = (~)CString
type AttrTransferType SchemaNameFieldInfo = CString
type AttrGetType SchemaNameFieldInfo = Maybe T.Text
type AttrLabel SchemaNameFieldInfo = "name"
type AttrOrigin SchemaNameFieldInfo = Schema
attrGet = getSchemaName
attrSet = setSchemaName
attrConstruct = undefined
attrClear = clearSchemaName
attrTransfer _ v = do
return v
schema_name :: AttrLabelProxy "name"
schema_name = AttrLabelProxy
#endif
getSchemaFlags :: MonadIO m => Schema -> m [Secret.Flags.SchemaFlags]
getSchemaFlags :: Schema -> m [SchemaFlags]
getSchemaFlags Schema
s = IO [SchemaFlags] -> m [SchemaFlags]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [SchemaFlags] -> m [SchemaFlags])
-> IO [SchemaFlags] -> m [SchemaFlags]
forall a b. (a -> b) -> a -> b
$ Schema -> (Ptr Schema -> IO [SchemaFlags]) -> IO [SchemaFlags]
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Schema
s ((Ptr Schema -> IO [SchemaFlags]) -> IO [SchemaFlags])
-> (Ptr Schema -> IO [SchemaFlags]) -> IO [SchemaFlags]
forall a b. (a -> b) -> a -> b
$ \Ptr Schema
ptr -> do
CUInt
val <- Ptr CUInt -> IO CUInt
forall a. Storable a => Ptr a -> IO a
peek (Ptr Schema
ptr Ptr Schema -> Int -> Ptr CUInt
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8) :: IO CUInt
let val' :: [SchemaFlags]
val' = CUInt -> [SchemaFlags]
forall a b. (Storable a, Integral a, Bits a, IsGFlag b) => a -> [b]
wordToGFlags CUInt
val
[SchemaFlags] -> IO [SchemaFlags]
forall (m :: * -> *) a. Monad m => a -> m a
return [SchemaFlags]
val'
setSchemaFlags :: MonadIO m => Schema -> [Secret.Flags.SchemaFlags] -> m ()
setSchemaFlags :: Schema -> [SchemaFlags] -> m ()
setSchemaFlags Schema
s [SchemaFlags]
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Schema -> (Ptr Schema -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Schema
s ((Ptr Schema -> IO ()) -> IO ()) -> (Ptr Schema -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Schema
ptr -> do
let val' :: CUInt
val' = [SchemaFlags] -> CUInt
forall b a. (Num b, IsGFlag a) => [a] -> b
gflagsToWord [SchemaFlags]
val
Ptr CUInt -> CUInt -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Schema
ptr Ptr Schema -> Int -> Ptr CUInt
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8) (CUInt
val' :: CUInt)
#if defined(ENABLE_OVERLOADING)
data SchemaFlagsFieldInfo
instance AttrInfo SchemaFlagsFieldInfo where
type AttrBaseTypeConstraint SchemaFlagsFieldInfo = (~) Schema
type AttrAllowedOps SchemaFlagsFieldInfo = '[ 'AttrSet, 'AttrGet]
type AttrSetTypeConstraint SchemaFlagsFieldInfo = (~) [Secret.Flags.SchemaFlags]
type AttrTransferTypeConstraint SchemaFlagsFieldInfo = (~)[Secret.Flags.SchemaFlags]
type AttrTransferType SchemaFlagsFieldInfo = [Secret.Flags.SchemaFlags]
type AttrGetType SchemaFlagsFieldInfo = [Secret.Flags.SchemaFlags]
type AttrLabel SchemaFlagsFieldInfo = "flags"
type AttrOrigin SchemaFlagsFieldInfo = Schema
attrGet = getSchemaFlags
attrSet = setSchemaFlags
attrConstruct = undefined
attrClear = undefined
attrTransfer _ v = do
return v
schema_flags :: AttrLabelProxy "flags"
schema_flags = AttrLabelProxy
#endif
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Schema
type instance O.AttributeList Schema = SchemaAttributeList
type SchemaAttributeList = ('[ '("name", SchemaNameFieldInfo), '("flags", SchemaFlagsFieldInfo)] :: [(Symbol, *)])
#endif
foreign import ccall "secret_schema_ref" secret_schema_ref ::
Ptr Schema ->
IO (Ptr Schema)
schemaRef ::
(B.CallStack.HasCallStack, MonadIO m) =>
Schema
-> m Schema
schemaRef :: Schema -> m Schema
schemaRef Schema
schema = IO Schema -> m Schema
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Schema -> m Schema) -> IO Schema -> m Schema
forall a b. (a -> b) -> a -> b
$ do
Ptr Schema
schema' <- Schema -> IO (Ptr Schema)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Schema
schema
Ptr Schema
result <- Ptr Schema -> IO (Ptr Schema)
secret_schema_ref Ptr Schema
schema'
Text -> Ptr Schema -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"schemaRef" Ptr Schema
result
Schema
result' <- ((ManagedPtr Schema -> Schema) -> Ptr Schema -> IO Schema
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Schema -> Schema
Schema) Ptr Schema
result
Schema -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Schema
schema
Schema -> IO Schema
forall (m :: * -> *) a. Monad m => a -> m a
return Schema
result'
#if defined(ENABLE_OVERLOADING)
data SchemaRefMethodInfo
instance (signature ~ (m Schema), MonadIO m) => O.MethodInfo SchemaRefMethodInfo Schema signature where
overloadedMethod = schemaRef
#endif
foreign import ccall "secret_schema_unref" secret_schema_unref ::
Ptr Schema ->
IO ()
schemaUnref ::
(B.CallStack.HasCallStack, MonadIO m) =>
Schema
-> m ()
schemaUnref :: Schema -> m ()
schemaUnref Schema
schema = 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 Schema
schema' <- Schema -> IO (Ptr Schema)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Schema
schema
Ptr Schema -> IO ()
secret_schema_unref Ptr Schema
schema'
Schema -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Schema
schema
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data SchemaUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo SchemaUnrefMethodInfo Schema signature where
overloadedMethod = schemaUnref
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolveSchemaMethod (t :: Symbol) (o :: *) :: * where
ResolveSchemaMethod "ref" o = SchemaRefMethodInfo
ResolveSchemaMethod "unref" o = SchemaUnrefMethodInfo
ResolveSchemaMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveSchemaMethod t Schema, O.MethodInfo info Schema p) => OL.IsLabel t (Schema -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#endif