{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

/No description available in the introspection data./
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.OSTree.Structs.KernelArgs
    (

-- * Exported types
    KernelArgs(..)                          ,
    noKernelArgs                            ,


 -- * Methods
-- ** append #method:append#

#if ENABLE_OVERLOADING
    KernelArgsAppendMethodInfo              ,
#endif
    kernelArgsAppend                        ,


-- ** appendArgv #method:appendArgv#

#if ENABLE_OVERLOADING
    KernelArgsAppendArgvMethodInfo          ,
#endif
    kernelArgsAppendArgv                    ,


-- ** appendArgvFiltered #method:appendArgvFiltered#

#if ENABLE_OVERLOADING
    KernelArgsAppendArgvFilteredMethodInfo  ,
#endif
    kernelArgsAppendArgvFiltered            ,


-- ** appendProcCmdline #method:appendProcCmdline#

#if ENABLE_OVERLOADING
    KernelArgsAppendProcCmdlineMethodInfo   ,
#endif
    kernelArgsAppendProcCmdline             ,


-- ** cleanup #method:cleanup#

    kernelArgsCleanup                       ,


-- ** delete #method:delete#

#if ENABLE_OVERLOADING
    KernelArgsDeleteMethodInfo              ,
#endif
    kernelArgsDelete                        ,


-- ** deleteKeyEntry #method:deleteKeyEntry#

#if ENABLE_OVERLOADING
    KernelArgsDeleteKeyEntryMethodInfo      ,
#endif
    kernelArgsDeleteKeyEntry                ,


-- ** free #method:free#

#if ENABLE_OVERLOADING
    KernelArgsFreeMethodInfo                ,
#endif
    kernelArgsFree                          ,


-- ** getLastValue #method:getLastValue#

#if ENABLE_OVERLOADING
    KernelArgsGetLastValueMethodInfo        ,
#endif
    kernelArgsGetLastValue                  ,


-- ** newReplace #method:newReplace#

#if ENABLE_OVERLOADING
    KernelArgsNewReplaceMethodInfo          ,
#endif
    kernelArgsNewReplace                    ,


-- ** parseAppend #method:parseAppend#

#if ENABLE_OVERLOADING
    KernelArgsParseAppendMethodInfo         ,
#endif
    kernelArgsParseAppend                   ,


-- ** replace #method:replace#

#if ENABLE_OVERLOADING
    KernelArgsReplaceMethodInfo             ,
#endif
    kernelArgsReplace                       ,


-- ** replaceArgv #method:replaceArgv#

#if ENABLE_OVERLOADING
    KernelArgsReplaceArgvMethodInfo         ,
#endif
    kernelArgsReplaceArgv                   ,


-- ** replaceTake #method:replaceTake#

#if ENABLE_OVERLOADING
    KernelArgsReplaceTakeMethodInfo         ,
#endif
    kernelArgsReplaceTake                   ,


-- ** toString #method:toString#

#if ENABLE_OVERLOADING
    KernelArgsToStringMethodInfo            ,
#endif
    kernelArgsToString                      ,


-- ** toStrv #method:toStrv#

#if ENABLE_OVERLOADING
    KernelArgsToStrvMethodInfo              ,
#endif
    kernelArgsToStrv                        ,




    ) 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.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.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP

import qualified GI.Gio.Objects.Cancellable as Gio.Cancellable

-- | Memory-managed wrapper type.
newtype KernelArgs = KernelArgs (ManagedPtr KernelArgs)
-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance WrappedPtr KernelArgs where
    wrappedPtrCalloc = return nullPtr
    wrappedPtrCopy = return
    wrappedPtrFree = Nothing

-- | A convenience alias for `Nothing` :: `Maybe` `KernelArgs`.
noKernelArgs :: Maybe KernelArgs
noKernelArgs = Nothing


#if ENABLE_OVERLOADING
instance O.HasAttributeList KernelArgs
type instance O.AttributeList KernelArgs = KernelArgsAttributeList
type KernelArgsAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method KernelArgs::append
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "arg", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "key or key/value pair to be added", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_append" ostree_kernel_args_append ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    CString ->                              -- arg : TBasicType TUTF8
    IO ()

{- |
Appends /@arg@/ which is in the form of key=value pair to the hash table kargs->table
(appends to the value list if key is already in the hash table)
and appends key to kargs->order if it is not in the hash table already.

/Since: 2019.3/
-}
kernelArgsAppend ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> T.Text
    {- ^ /@arg@/: key or key\/value pair to be added -}
    -> m ()
kernelArgsAppend kargs arg = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    arg' <- textToCString arg
    ostree_kernel_args_append kargs' arg'
    touchManagedPtr kargs
    freeMem arg'
    return ()

#if ENABLE_OVERLOADING
data KernelArgsAppendMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo KernelArgsAppendMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsAppend

#endif

-- method KernelArgs::append_argv
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "argv", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an array of key=value argument pairs", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_append_argv" ostree_kernel_args_append_argv ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    CString ->                              -- argv : TBasicType TUTF8
    IO ()

{- |
Appends each value in /@argv@/ to the corresponding value array and
appends key to kargs->order if it is not in the hash table already.

/Since: 2019.3/
-}
kernelArgsAppendArgv ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> T.Text
    {- ^ /@argv@/: an array of key=value argument pairs -}
    -> m ()
kernelArgsAppendArgv kargs argv = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    argv' <- textToCString argv
    ostree_kernel_args_append_argv kargs' argv'
    touchManagedPtr kargs
    freeMem argv'
    return ()

#if ENABLE_OVERLOADING
data KernelArgsAppendArgvMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo KernelArgsAppendArgvMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsAppendArgv

#endif

-- method KernelArgs::append_argv_filtered
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "argv", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an array of key=value argument pairs", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "prefixes", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an array of prefix strings", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_append_argv_filtered" ostree_kernel_args_append_argv_filtered ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    CString ->                              -- argv : TBasicType TUTF8
    CString ->                              -- prefixes : TBasicType TUTF8
    IO ()

{- |
Appends each argument that does not have one of the /@prefixes@/ as prefix to the /@kargs@/

/Since: 2019.3/
-}
kernelArgsAppendArgvFiltered ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> T.Text
    {- ^ /@argv@/: an array of key=value argument pairs -}
    -> T.Text
    {- ^ /@prefixes@/: an array of prefix strings -}
    -> m ()
kernelArgsAppendArgvFiltered kargs argv prefixes = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    argv' <- textToCString argv
    prefixes' <- textToCString prefixes
    ostree_kernel_args_append_argv_filtered kargs' argv' prefixes'
    touchManagedPtr kargs
    freeMem argv'
    freeMem prefixes'
    return ()

#if ENABLE_OVERLOADING
data KernelArgsAppendArgvFilteredMethodInfo
instance (signature ~ (T.Text -> T.Text -> m ()), MonadIO m) => O.MethodInfo KernelArgsAppendArgvFilteredMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsAppendArgvFiltered

#endif

-- method KernelArgs::append_proc_cmdline
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "optional GCancellable object, NULL to ignore", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "ostree_kernel_args_append_proc_cmdline" ostree_kernel_args_append_proc_cmdline ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Appends the command line arguments in the file \"\/proc\/cmdline\"
that does not have \"BOOT_IMAGE=\" and \"initrd=\" as prefixes to the /@kargs@/

/Since: 2019.3/
-}
kernelArgsAppendProcCmdline ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.Cancellable.IsCancellable a) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> Maybe (a)
    {- ^ /@cancellable@/: optional GCancellable object, NULL to ignore -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
kernelArgsAppendProcCmdline kargs cancellable = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    onException (do
        _ <- propagateGError $ ostree_kernel_args_append_proc_cmdline kargs' maybeCancellable
        touchManagedPtr kargs
        whenJust cancellable touchManagedPtr
        return ()
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
data KernelArgsAppendProcCmdlineMethodInfo
instance (signature ~ (Maybe (a) -> m ()), MonadIO m, Gio.Cancellable.IsCancellable a) => O.MethodInfo KernelArgsAppendProcCmdlineMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsAppendProcCmdline

#endif

-- method KernelArgs::delete
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "arg", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "key or key/value pair for deletion", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "ostree_kernel_args_delete" ostree_kernel_args_delete ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    CString ->                              -- arg : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
There are few scenarios being handled for deletion:

 1: for input arg with a single key(i.e without = for split),
 the key\/value pair will be deleted if there is only
 one value that is associated with the key

 2: for input arg wth key\/value pair, the specific key
 value pair will be deleted from the pointer array
 if those exist.

 3: If the found key has only one value
 associated with it, the key entry in the table will also
 be removed, and the key will be removed from order table

 Returns: 'True' on success, 'False' on failure

 Since: 2019.3
-}
kernelArgsDelete ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> T.Text
    {- ^ /@arg@/: key or key\/value pair for deletion -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
kernelArgsDelete kargs arg = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    arg' <- textToCString arg
    onException (do
        _ <- propagateGError $ ostree_kernel_args_delete kargs' arg'
        touchManagedPtr kargs
        freeMem arg'
        return ()
     ) (do
        freeMem arg'
     )

#if ENABLE_OVERLOADING
data KernelArgsDeleteMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo KernelArgsDeleteMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsDelete

#endif

-- method KernelArgs::delete_key_entry
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "key", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the key to remove", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "ostree_kernel_args_delete_key_entry" ostree_kernel_args_delete_key_entry ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    CString ->                              -- key : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
This function removes the key entry from the hashtable
as well from the order pointer array inside kargs

Note: since both table and order inside kernel args
are with free function, no extra free functions are
being called as they are done automatically by GLib

/Since: 2019.3/
-}
kernelArgsDeleteKeyEntry ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: an OstreeKernelArgs instance -}
    -> T.Text
    {- ^ /@key@/: the key to remove -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
kernelArgsDeleteKeyEntry kargs key = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    key' <- textToCString key
    onException (do
        _ <- propagateGError $ ostree_kernel_args_delete_key_entry kargs' key'
        touchManagedPtr kargs
        freeMem key'
        return ()
     ) (do
        freeMem key'
     )

#if ENABLE_OVERLOADING
data KernelArgsDeleteKeyEntryMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo KernelArgsDeleteKeyEntryMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsDeleteKeyEntry

#endif

-- method KernelArgs::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "An OstreeKernelArgs that represents kernel arguments", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_free" ostree_kernel_args_free ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    IO ()

{- |
Frees the kargs structure

/Since: 2019.3/
-}
kernelArgsFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: An OstreeKernelArgs that represents kernel arguments -}
    -> m ()
kernelArgsFree kargs = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    ostree_kernel_args_free kargs'
    touchManagedPtr kargs
    return ()

#if ENABLE_OVERLOADING
data KernelArgsFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo KernelArgsFreeMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsFree

#endif

-- method KernelArgs::get_last_value
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "key", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a key to look for in @kargs hash table", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_get_last_value" ostree_kernel_args_get_last_value ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    CString ->                              -- key : TBasicType TUTF8
    IO CString

{- |
Finds and returns the last element of value array
corresponding to the /@key@/ in /@kargs@/ hash table. Note that the application
will be terminated if the /@key@/ is found but the value array is empty

/Since: 2019.3/
-}
kernelArgsGetLastValue ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> T.Text
    {- ^ /@key@/: a key to look for in /@kargs@/ hash table -}
    -> m T.Text
    {- ^ __Returns:__ NULL if /@key@/ is not found in the /@kargs@/ hash table,
otherwise returns last element of value array corresponding to /@key@/ -}
kernelArgsGetLastValue kargs key = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    key' <- textToCString key
    result <- ostree_kernel_args_get_last_value kargs' key'
    checkUnexpectedReturnNULL "kernelArgsGetLastValue" result
    result' <- cstringToText result
    touchManagedPtr kargs
    freeMem key'
    return result'

#if ENABLE_OVERLOADING
data KernelArgsGetLastValueMethodInfo
instance (signature ~ (T.Text -> m T.Text), MonadIO m) => O.MethodInfo KernelArgsGetLastValueMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsGetLastValue

#endif

-- method KernelArgs::new_replace
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "arg", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a string argument", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "ostree_kernel_args_new_replace" ostree_kernel_args_new_replace ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    CString ->                              -- arg : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
This function implements the basic logic behind key\/value pair
replacement. Do note that the arg need to be properly formatted

When replacing key with exact one value, the arg can be in
the form:
key, key=new_val, or key=old_val=new_val
The first one swaps the old_val with the key to an empty value
The second and third replace the old_val into the new_val

When replacing key with multiple values, the arg can only be
in the form of:
key=old_val=new_val. Unless there is a special case where
there is an empty value associated with the key, then
key=new_val will work because old_val is empty. The empty
val will be swapped with the new_val in that case

/Since: 2019.3/
-}
kernelArgsNewReplace ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: OstreeKernelArgs instance -}
    -> T.Text
    {- ^ /@arg@/: a string argument -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
kernelArgsNewReplace kargs arg = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    arg' <- textToCString arg
    onException (do
        _ <- propagateGError $ ostree_kernel_args_new_replace kargs' arg'
        touchManagedPtr kargs
        freeMem arg'
        return ()
     ) (do
        freeMem arg'
     )

#if ENABLE_OVERLOADING
data KernelArgsNewReplaceMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo KernelArgsNewReplaceMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsNewReplace

#endif

-- method KernelArgs::parse_append
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "options", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a string representing command line arguments", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_parse_append" ostree_kernel_args_parse_append ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    CString ->                              -- options : TBasicType TUTF8
    IO ()

{- |
Parses /@options@/ by separating it by whitespaces and appends each argument to /@kargs@/

/Since: 2019.3/
-}
kernelArgsParseAppend ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> T.Text
    {- ^ /@options@/: a string representing command line arguments -}
    -> m ()
kernelArgsParseAppend kargs options = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    options' <- textToCString options
    ostree_kernel_args_parse_append kargs' options'
    touchManagedPtr kargs
    freeMem options'
    return ()

#if ENABLE_OVERLOADING
data KernelArgsParseAppendMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo KernelArgsParseAppendMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsParseAppend

#endif

-- method KernelArgs::replace
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "arg", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "key or key/value pair for replacement", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_replace" ostree_kernel_args_replace ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    CString ->                              -- arg : TBasicType TUTF8
    IO ()

{- |
Finds and replaces the old key if /@arg@/ is already in the hash table,
otherwise adds /@arg@/ as new key and split_keyeq (arg) as value.
Note that when replacing old key value pair, the old values are freed.

/Since: 2019.3/
-}
kernelArgsReplace ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> T.Text
    {- ^ /@arg@/: key or key\/value pair for replacement -}
    -> m ()
kernelArgsReplace kargs arg = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    arg' <- textToCString arg
    ostree_kernel_args_replace kargs' arg'
    touchManagedPtr kargs
    freeMem arg'
    return ()

#if ENABLE_OVERLOADING
data KernelArgsReplaceMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo KernelArgsReplaceMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsReplace

#endif

-- method KernelArgs::replace_argv
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "argv", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an array of key or key/value pairs", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_replace_argv" ostree_kernel_args_replace_argv ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    CString ->                              -- argv : TBasicType TUTF8
    IO ()

{- |
Finds and replaces each non-null arguments of /@argv@/ in the hash table,
otherwise adds individual arg as new key and split_keyeq (arg) as value.
Note that when replacing old key value pair, the old values are freed.

/Since: 2019.3/
-}
kernelArgsReplaceArgv ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> T.Text
    {- ^ /@argv@/: an array of key or key\/value pairs -}
    -> m ()
kernelArgsReplaceArgv kargs argv = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    argv' <- textToCString argv
    ostree_kernel_args_replace_argv kargs' argv'
    touchManagedPtr kargs
    freeMem argv'
    return ()

#if ENABLE_OVERLOADING
data KernelArgsReplaceArgvMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo KernelArgsReplaceArgvMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsReplaceArgv

#endif

-- method KernelArgs::replace_take
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "arg", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "key or key/value pair for replacement", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_replace_take" ostree_kernel_args_replace_take ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    CString ->                              -- arg : TBasicType TUTF8
    IO ()

{- |
Finds and replaces the old key if /@arg@/ is already in the hash table,
otherwise adds /@arg@/ as new key and split_keyeq (arg) as value.
Note that when replacing old key, the old values are freed.

/Since: 2019.3/
-}
kernelArgsReplaceTake ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> T.Text
    {- ^ /@arg@/: key or key\/value pair for replacement -}
    -> m ()
kernelArgsReplaceTake kargs arg = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    arg' <- textToCString arg
    ostree_kernel_args_replace_take kargs' arg'
    touchManagedPtr kargs
    return ()

#if ENABLE_OVERLOADING
data KernelArgsReplaceTakeMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo KernelArgsReplaceTakeMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsReplaceTake

#endif

-- method KernelArgs::to_string
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_to_string" ostree_kernel_args_to_string ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    IO CString

{- |
Extracts all key value pairs in /@kargs@/ and appends to a temporary
GString in forms of \"key=value\" or \"key\" if value is NULL separated
by a single whitespace, and returns the temporary string with the
GString wrapper freed

Note: the application will be terminated if one of the values array
in /@kargs@/ is NULL

/Since: 2019.3/
-}
kernelArgsToString ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> m T.Text
    {- ^ __Returns:__ a string of \"key=value\" pairs or \"key\" if value is NULL,
separated by single whitespaces -}
kernelArgsToString kargs = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    result <- ostree_kernel_args_to_string kargs'
    checkUnexpectedReturnNULL "kernelArgsToString" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr kargs
    return result'

#if ENABLE_OVERLOADING
data KernelArgsToStringMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo KernelArgsToStringMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsToString

#endif

-- method KernelArgs::to_strv
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "kargs", argType = TInterface (Name {namespace = "OSTree", name = "KernelArgs"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a OstreeKernelArgs instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TCArray True (-1) (-1) (TBasicType TUTF8))
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_to_strv" ostree_kernel_args_to_strv ::
    Ptr KernelArgs ->                       -- kargs : TInterface (Name {namespace = "OSTree", name = "KernelArgs"})
    IO (Ptr CString)

{- |
Extracts all key value pairs in /@kargs@/ and appends to a temporary
array in forms of \"key=value\" or \"key\" if value is NULL, and returns
the temporary array with the GPtrArray wrapper freed

/Since: 2019.3/
-}
kernelArgsToStrv ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    KernelArgs
    {- ^ /@kargs@/: a OstreeKernelArgs instance -}
    -> m [T.Text]
    {- ^ __Returns:__ an array of \"key=value\" pairs or \"key\" if value is NULL -}
kernelArgsToStrv kargs = liftIO $ do
    kargs' <- unsafeManagedPtrGetPtr kargs
    result <- ostree_kernel_args_to_strv kargs'
    checkUnexpectedReturnNULL "kernelArgsToStrv" result
    result' <- unpackZeroTerminatedUTF8CArray result
    mapZeroTerminatedCArray freeMem result
    freeMem result
    touchManagedPtr kargs
    return result'

#if ENABLE_OVERLOADING
data KernelArgsToStrvMethodInfo
instance (signature ~ (m [T.Text]), MonadIO m) => O.MethodInfo KernelArgsToStrvMethodInfo KernelArgs signature where
    overloadedMethod _ = kernelArgsToStrv

#endif

-- method KernelArgs::cleanup
-- method type : MemberFunction
-- Args : [Arg {argCName = "loc", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "Address of an OstreeKernelArgs pointer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ostree_kernel_args_cleanup" ostree_kernel_args_cleanup ::
    Ptr () ->                               -- loc : TBasicType TPtr
    IO ()

{- |
Frees the OstreeKernelArgs structure pointed by *loc

/Since: 2019.3/
-}
kernelArgsCleanup ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Ptr ()
    {- ^ /@loc@/: Address of an OstreeKernelArgs pointer -}
    -> m ()
kernelArgsCleanup loc = liftIO $ do
    ostree_kernel_args_cleanup loc
    return ()

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type family ResolveKernelArgsMethod (t :: Symbol) (o :: *) :: * where
    ResolveKernelArgsMethod "append" o = KernelArgsAppendMethodInfo
    ResolveKernelArgsMethod "appendArgv" o = KernelArgsAppendArgvMethodInfo
    ResolveKernelArgsMethod "appendArgvFiltered" o = KernelArgsAppendArgvFilteredMethodInfo
    ResolveKernelArgsMethod "appendProcCmdline" o = KernelArgsAppendProcCmdlineMethodInfo
    ResolveKernelArgsMethod "delete" o = KernelArgsDeleteMethodInfo
    ResolveKernelArgsMethod "deleteKeyEntry" o = KernelArgsDeleteKeyEntryMethodInfo
    ResolveKernelArgsMethod "free" o = KernelArgsFreeMethodInfo
    ResolveKernelArgsMethod "newReplace" o = KernelArgsNewReplaceMethodInfo
    ResolveKernelArgsMethod "parseAppend" o = KernelArgsParseAppendMethodInfo
    ResolveKernelArgsMethod "replace" o = KernelArgsReplaceMethodInfo
    ResolveKernelArgsMethod "replaceArgv" o = KernelArgsReplaceArgvMethodInfo
    ResolveKernelArgsMethod "replaceTake" o = KernelArgsReplaceTakeMethodInfo
    ResolveKernelArgsMethod "toString" o = KernelArgsToStringMethodInfo
    ResolveKernelArgsMethod "toStrv" o = KernelArgsToStrvMethodInfo
    ResolveKernelArgsMethod "getLastValue" o = KernelArgsGetLastValueMethodInfo
    ResolveKernelArgsMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveKernelArgsMethod t KernelArgs, O.MethodInfo info KernelArgs p) => O.IsLabelProxy t (KernelArgs -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveKernelArgsMethod t KernelArgs, O.MethodInfo info KernelArgs p) => O.IsLabel t (KernelArgs -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif
#endif

#endif