{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.Secret.Structs.Value
(
Value(..) ,
#if defined(ENABLE_OVERLOADING)
ResolveValueMethod ,
#endif
#if defined(ENABLE_OVERLOADING)
ValueGetMethodInfo ,
#endif
valueGet ,
#if defined(ENABLE_OVERLOADING)
ValueGetContentTypeMethodInfo ,
#endif
valueGetContentType ,
#if defined(ENABLE_OVERLOADING)
ValueGetTextMethodInfo ,
#endif
valueGetText ,
valueNew ,
valueNewFull ,
#if defined(ENABLE_OVERLOADING)
ValueRefMethodInfo ,
#endif
valueRef ,
#if defined(ENABLE_OVERLOADING)
ValueUnrefMethodInfo ,
#endif
valueUnref ,
#if defined(ENABLE_OVERLOADING)
ValueUnrefToPasswordMethodInfo ,
#endif
valueUnrefToPassword ,
) 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 qualified GI.GLib.Callbacks as GLib.Callbacks
newtype Value = Value (SP.ManagedPtr Value)
deriving (Value -> Value -> Bool
(Value -> Value -> Bool) -> (Value -> Value -> Bool) -> Eq Value
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Value -> Value -> Bool
$c/= :: Value -> Value -> Bool
== :: Value -> Value -> Bool
$c== :: Value -> Value -> Bool
Eq)
instance SP.ManagedPtrNewtype Value where
toManagedPtr :: Value -> ManagedPtr Value
toManagedPtr (Value ManagedPtr Value
p) = ManagedPtr Value
p
foreign import ccall "secret_value_get_type" c_secret_value_get_type ::
IO GType
type instance O.ParentTypes Value = '[]
instance O.HasParentTypes Value
instance B.Types.TypedObject Value where
glibType :: IO GType
glibType = IO GType
c_secret_value_get_type
instance B.Types.GBoxed Value
instance B.GValue.IsGValue Value where
toGValue :: Value -> IO GValue
toGValue Value
o = do
GType
gtype <- IO GType
c_secret_value_get_type
Value -> (Ptr Value -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Value
o (GType -> (GValue -> Ptr Value -> IO ()) -> Ptr Value -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr Value -> IO ()
forall a. GValue -> Ptr a -> IO ()
B.GValue.set_boxed)
fromGValue :: GValue -> IO Value
fromGValue GValue
gv = do
Ptr Value
ptr <- GValue -> IO (Ptr Value)
forall b. GValue -> IO (Ptr b)
B.GValue.get_boxed GValue
gv :: IO (Ptr Value)
(ManagedPtr Value -> Value) -> Ptr Value -> IO Value
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.newBoxed ManagedPtr Value -> Value
Value Ptr Value
ptr
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Value
type instance O.AttributeList Value = ValueAttributeList
type ValueAttributeList = ('[ ] :: [(Symbol, *)])
#endif
foreign import ccall "secret_value_new" secret_value_new ::
CString ->
Int64 ->
CString ->
IO (Ptr Value)
valueNew ::
(B.CallStack.HasCallStack, MonadIO m) =>
T.Text
-> Int64
-> T.Text
-> m Value
valueNew :: Text -> Int64 -> Text -> m Value
valueNew Text
secret Int64
length_ Text
contentType = IO Value -> m Value
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Value -> m Value) -> IO Value -> m Value
forall a b. (a -> b) -> a -> b
$ do
CString
secret' <- Text -> IO CString
textToCString Text
secret
CString
contentType' <- Text -> IO CString
textToCString Text
contentType
Ptr Value
result <- CString -> Int64 -> CString -> IO (Ptr Value)
secret_value_new CString
secret' Int64
length_ CString
contentType'
Text -> Ptr Value -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"valueNew" Ptr Value
result
Value
result' <- ((ManagedPtr Value -> Value) -> Ptr Value -> IO Value
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Value -> Value
Value) Ptr Value
result
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
secret'
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
contentType'
Value -> IO Value
forall (m :: * -> *) a. Monad m => a -> m a
return Value
result'
#if defined(ENABLE_OVERLOADING)
#endif
foreign import ccall "secret_value_new_full" secret_value_new_full ::
CString ->
Int64 ->
CString ->
FunPtr GLib.Callbacks.C_DestroyNotify ->
IO (Ptr Value)
valueNewFull ::
(B.CallStack.HasCallStack, MonadIO m) =>
T.Text
-> Int64
-> T.Text
-> GLib.Callbacks.DestroyNotify
-> m Value
valueNewFull :: Text -> Int64 -> Text -> DestroyNotify -> m Value
valueNewFull Text
secret Int64
length_ Text
contentType DestroyNotify
destroy = IO Value -> m Value
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Value -> m Value) -> IO Value -> m Value
forall a b. (a -> b) -> a -> b
$ do
CString
secret' <- Text -> IO CString
textToCString Text
secret
CString
contentType' <- Text -> IO CString
textToCString Text
contentType
Ptr (FunPtr DestroyNotify)
ptrdestroy <- IO (Ptr (FunPtr DestroyNotify))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr GLib.Callbacks.C_DestroyNotify))
FunPtr DestroyNotify
destroy' <- DestroyNotify -> IO (FunPtr DestroyNotify)
GLib.Callbacks.mk_DestroyNotify (Maybe (Ptr (FunPtr DestroyNotify))
-> DestroyNotify -> DestroyNotify
GLib.Callbacks.wrap_DestroyNotify (Ptr (FunPtr DestroyNotify) -> Maybe (Ptr (FunPtr DestroyNotify))
forall a. a -> Maybe a
Just Ptr (FunPtr DestroyNotify)
ptrdestroy) DestroyNotify
destroy)
Ptr (FunPtr DestroyNotify) -> FunPtr DestroyNotify -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr DestroyNotify)
ptrdestroy FunPtr DestroyNotify
destroy'
Ptr Value
result <- CString
-> Int64 -> CString -> FunPtr DestroyNotify -> IO (Ptr Value)
secret_value_new_full CString
secret' Int64
length_ CString
contentType' FunPtr DestroyNotify
destroy'
Text -> Ptr Value -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"valueNewFull" Ptr Value
result
Value
result' <- ((ManagedPtr Value -> Value) -> Ptr Value -> IO Value
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Value -> Value
Value) Ptr Value
result
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
secret'
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
contentType'
Value -> IO Value
forall (m :: * -> *) a. Monad m => a -> m a
return Value
result'
#if defined(ENABLE_OVERLOADING)
#endif
foreign import ccall "secret_value_get" secret_value_get ::
Ptr Value ->
Ptr Word64 ->
IO (Ptr Word8)
valueGet ::
(B.CallStack.HasCallStack, MonadIO m) =>
Value
-> m ByteString
valueGet :: Value -> m ByteString
valueGet Value
value = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString) -> IO ByteString -> m ByteString
forall a b. (a -> b) -> a -> b
$ do
Ptr Value
value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
Ptr Word64
length_ <- IO (Ptr Word64)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word64)
Ptr Word8
result <- Ptr Value -> Ptr Word64 -> IO (Ptr Word8)
secret_value_get Ptr Value
value' Ptr Word64
length_
Word64
length_' <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
length_
Text -> Ptr Word8 -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"valueGet" Ptr Word8
result
ByteString
result' <- (Word64 -> Ptr Word8 -> IO ByteString
forall a. Integral a => a -> Ptr Word8 -> IO ByteString
unpackByteStringWithLength Word64
length_') Ptr Word8
result
Value -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Value
value
Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
length_
ByteString -> IO ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
result'
#if defined(ENABLE_OVERLOADING)
data ValueGetMethodInfo
instance (signature ~ (m ByteString), MonadIO m) => O.MethodInfo ValueGetMethodInfo Value signature where
overloadedMethod = valueGet
#endif
foreign import ccall "secret_value_get_content_type" secret_value_get_content_type ::
Ptr Value ->
IO CString
valueGetContentType ::
(B.CallStack.HasCallStack, MonadIO m) =>
Value
-> m T.Text
valueGetContentType :: Value -> m Text
valueGetContentType Value
value = 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 Value
value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
CString
result <- Ptr Value -> IO CString
secret_value_get_content_type Ptr Value
value'
Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"valueGetContentType" CString
result
Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
Value -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Value
value
Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'
#if defined(ENABLE_OVERLOADING)
data ValueGetContentTypeMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo ValueGetContentTypeMethodInfo Value signature where
overloadedMethod = valueGetContentType
#endif
foreign import ccall "secret_value_get_text" secret_value_get_text ::
Ptr Value ->
IO CString
valueGetText ::
(B.CallStack.HasCallStack, MonadIO m) =>
Value
-> m (Maybe T.Text)
valueGetText :: Value -> m (Maybe Text)
valueGetText Value
value = 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
$ do
Ptr Value
value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
CString
result <- Ptr Value -> IO CString
secret_value_get_text Ptr Value
value'
Maybe Text
maybeResult <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull CString
result ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \CString
result' -> do
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''
Value -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Value
value
Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
maybeResult
#if defined(ENABLE_OVERLOADING)
data ValueGetTextMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo ValueGetTextMethodInfo Value signature where
overloadedMethod = valueGetText
#endif
foreign import ccall "secret_value_ref" secret_value_ref ::
Ptr Value ->
IO (Ptr Value)
valueRef ::
(B.CallStack.HasCallStack, MonadIO m) =>
Value
-> m Value
valueRef :: Value -> m Value
valueRef Value
value = IO Value -> m Value
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Value -> m Value) -> IO Value -> m Value
forall a b. (a -> b) -> a -> b
$ do
Ptr Value
value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
Ptr Value
result <- Ptr Value -> IO (Ptr Value)
secret_value_ref Ptr Value
value'
Text -> Ptr Value -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"valueRef" Ptr Value
result
Value
result' <- ((ManagedPtr Value -> Value) -> Ptr Value -> IO Value
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Value -> Value
Value) Ptr Value
result
Value -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Value
value
Value -> IO Value
forall (m :: * -> *) a. Monad m => a -> m a
return Value
result'
#if defined(ENABLE_OVERLOADING)
data ValueRefMethodInfo
instance (signature ~ (m Value), MonadIO m) => O.MethodInfo ValueRefMethodInfo Value signature where
overloadedMethod = valueRef
#endif
foreign import ccall "secret_value_unref" secret_value_unref ::
Ptr Value ->
IO ()
valueUnref ::
(B.CallStack.HasCallStack, MonadIO m) =>
Value
-> m ()
valueUnref :: Value -> m ()
valueUnref Value
value = 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 Value
value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
Ptr Value -> IO ()
secret_value_unref Ptr Value
value'
Value -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Value
value
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data ValueUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo ValueUnrefMethodInfo Value signature where
overloadedMethod = valueUnref
#endif
foreign import ccall "secret_value_unref_to_password" secret_value_unref_to_password ::
Ptr Value ->
Word64 ->
IO CString
valueUnrefToPassword ::
(B.CallStack.HasCallStack, MonadIO m) =>
Value
-> Word64
-> m T.Text
valueUnrefToPassword :: Value -> Word64 -> m Text
valueUnrefToPassword Value
value Word64
length_ = 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 Value
value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
CString
result <- Ptr Value -> Word64 -> IO CString
secret_value_unref_to_password Ptr Value
value' Word64
length_
Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"valueUnrefToPassword" CString
result
Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
Value -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Value
value
Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'
#if defined(ENABLE_OVERLOADING)
data ValueUnrefToPasswordMethodInfo
instance (signature ~ (Word64 -> m T.Text), MonadIO m) => O.MethodInfo ValueUnrefToPasswordMethodInfo Value signature where
overloadedMethod = valueUnrefToPassword
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolveValueMethod (t :: Symbol) (o :: *) :: * where
ResolveValueMethod "get" o = ValueGetMethodInfo
ResolveValueMethod "ref" o = ValueRefMethodInfo
ResolveValueMethod "unref" o = ValueUnrefMethodInfo
ResolveValueMethod "unrefToPassword" o = ValueUnrefToPasswordMethodInfo
ResolveValueMethod "getContentType" o = ValueGetContentTypeMethodInfo
ResolveValueMethod "getText" o = ValueGetTextMethodInfo
ResolveValueMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveValueMethod t Value, O.MethodInfo info Value p) => OL.IsLabel t (Value -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#endif