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

'GI.Gio.Objects.Subprocess.Subprocess' allows the creation of and interaction with child
processes.

Processes can be communicated with using standard GIO-style APIs (ie:
'GI.Gio.Objects.InputStream.InputStream', 'GI.Gio.Objects.OutputStream.OutputStream').  There are GIO-style APIs to wait for
process termination (ie: cancellable and with an asynchronous
variant).

There is an API to force a process to terminate, as well as a
race-free API for sending UNIX signals to a subprocess.

One major advantage that GIO brings over the core GLib library is
comprehensive API for asynchronous I\/O, such
'GI.Gio.Objects.OutputStream.outputStreamSpliceAsync'.  This makes GSubprocess
significantly more powerful and flexible than equivalent APIs in
some other languages such as the @subprocess.py@
included with Python.  For example, using 'GI.Gio.Objects.Subprocess.Subprocess' one could
create two child processes, reading standard output from the first,
processing it, and writing to the input stream of the second, all
without blocking the main loop.

A powerful 'GI.Gio.Objects.Subprocess.subprocessCommunicate' API is provided similar to the
@communicate()@ method of @subprocess.py@. This enables very easy
interaction with a subprocess that has been opened with pipes.

'GI.Gio.Objects.Subprocess.Subprocess' defaults to tight control over the file descriptors open
in the child process, avoiding dangling-fd issues that are caused by
a simple @/fork()/@\/@/exec()/@.  The only open file descriptors in the
spawned process are ones that were explicitly specified by the
'GI.Gio.Objects.Subprocess.Subprocess' API (unless 'GI.Gio.Flags.SubprocessFlagsInheritFds' was
specified).

'GI.Gio.Objects.Subprocess.Subprocess' will quickly reap all child processes as they exit,
avoiding \"zombie processes\" remaining around for long periods of
time.  'GI.Gio.Objects.Subprocess.subprocessWait' can be used to wait for this to happen,
but it will happen even without the call being explicitly made.

As a matter of principle, 'GI.Gio.Objects.Subprocess.Subprocess' has no API that accepts
shell-style space-separated strings.  It will, however, match the
typical shell behaviour of searching the PATH for executables that do
not contain a directory separator in their name.

'GI.Gio.Objects.Subprocess.Subprocess' attempts to have a very simple API for most uses (ie:
spawning a subprocess with arguments and support for most typical
kinds of input and output redirection).  See @/g_subprocess_new()/@. The
'GI.Gio.Objects.SubprocessLauncher.SubprocessLauncher' API is provided for more complicated cases
(advanced types of redirection, environment variable manipulation,
change of working directory, child setup functions, etc).

A typical use of 'GI.Gio.Objects.Subprocess.Subprocess' will involve calling
@/g_subprocess_new()/@, followed by 'GI.Gio.Objects.Subprocess.subprocessWaitAsync' or
'GI.Gio.Objects.Subprocess.subprocessWait'.  After the process exits, the status can be
checked using functions such as 'GI.Gio.Objects.Subprocess.subprocessGetIfExited' (which
are similar to the familiar WIFEXITED-style POSIX macros).
-}

module GI.Gio.Objects.Subprocess
    ( 

-- * Exported types
    Subprocess(..)                          ,
    IsSubprocess                            ,
    toSubprocess                            ,
    noSubprocess                            ,


 -- * Methods
-- ** communicate #method:communicate#
    SubprocessCommunicateMethodInfo         ,
    subprocessCommunicate                   ,


-- ** communicateAsync #method:communicateAsync#
    SubprocessCommunicateAsyncMethodInfo    ,
    subprocessCommunicateAsync              ,


-- ** communicateFinish #method:communicateFinish#
    SubprocessCommunicateFinishMethodInfo   ,
    subprocessCommunicateFinish             ,


-- ** communicateUtf8 #method:communicateUtf8#
    SubprocessCommunicateUtf8MethodInfo     ,
    subprocessCommunicateUtf8               ,


-- ** communicateUtf8Async #method:communicateUtf8Async#
    SubprocessCommunicateUtf8AsyncMethodInfo,
    subprocessCommunicateUtf8Async          ,


-- ** communicateUtf8Finish #method:communicateUtf8Finish#
    SubprocessCommunicateUtf8FinishMethodInfo,
    subprocessCommunicateUtf8Finish         ,


-- ** forceExit #method:forceExit#
    SubprocessForceExitMethodInfo           ,
    subprocessForceExit                     ,


-- ** getExitStatus #method:getExitStatus#
    SubprocessGetExitStatusMethodInfo       ,
    subprocessGetExitStatus                 ,


-- ** getIdentifier #method:getIdentifier#
    SubprocessGetIdentifierMethodInfo       ,
    subprocessGetIdentifier                 ,


-- ** getIfExited #method:getIfExited#
    SubprocessGetIfExitedMethodInfo         ,
    subprocessGetIfExited                   ,


-- ** getIfSignaled #method:getIfSignaled#
    SubprocessGetIfSignaledMethodInfo       ,
    subprocessGetIfSignaled                 ,


-- ** getStatus #method:getStatus#
    SubprocessGetStatusMethodInfo           ,
    subprocessGetStatus                     ,


-- ** getStderrPipe #method:getStderrPipe#
    SubprocessGetStderrPipeMethodInfo       ,
    subprocessGetStderrPipe                 ,


-- ** getStdinPipe #method:getStdinPipe#
    SubprocessGetStdinPipeMethodInfo        ,
    subprocessGetStdinPipe                  ,


-- ** getStdoutPipe #method:getStdoutPipe#
    SubprocessGetStdoutPipeMethodInfo       ,
    subprocessGetStdoutPipe                 ,


-- ** getSuccessful #method:getSuccessful#
    SubprocessGetSuccessfulMethodInfo       ,
    subprocessGetSuccessful                 ,


-- ** getTermSig #method:getTermSig#
    SubprocessGetTermSigMethodInfo          ,
    subprocessGetTermSig                    ,


-- ** new #method:new#
    subprocessNew                           ,


-- ** sendSignal #method:sendSignal#
    SubprocessSendSignalMethodInfo          ,
    subprocessSendSignal                    ,


-- ** wait #method:wait#
    SubprocessWaitMethodInfo                ,
    subprocessWait                          ,


-- ** waitAsync #method:waitAsync#
    SubprocessWaitAsyncMethodInfo           ,
    subprocessWaitAsync                     ,


-- ** waitCheck #method:waitCheck#
    SubprocessWaitCheckMethodInfo           ,
    subprocessWaitCheck                     ,


-- ** waitCheckAsync #method:waitCheckAsync#
    SubprocessWaitCheckAsyncMethodInfo      ,
    subprocessWaitCheckAsync                ,


-- ** waitCheckFinish #method:waitCheckFinish#
    SubprocessWaitCheckFinishMethodInfo     ,
    subprocessWaitCheckFinish               ,


-- ** waitFinish #method:waitFinish#
    SubprocessWaitFinishMethodInfo          ,
    subprocessWaitFinish                    ,




 -- * Properties
-- ** argv #attr:argv#
    SubprocessArgvPropertyInfo              ,
    constructSubprocessArgv                 ,
    subprocessArgv                          ,


-- ** flags #attr:flags#
    SubprocessFlagsPropertyInfo             ,
    constructSubprocessFlags                ,
    subprocessFlags                         ,




    ) 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.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.GLib.Structs.Bytes as GLib.Bytes
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Callbacks as Gio.Callbacks
import {-# SOURCE #-} qualified GI.Gio.Flags as Gio.Flags
import {-# SOURCE #-} qualified GI.Gio.Interfaces.AsyncResult as Gio.AsyncResult
import {-# SOURCE #-} qualified GI.Gio.Interfaces.Initable as Gio.Initable
import {-# SOURCE #-} qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
import {-# SOURCE #-} qualified GI.Gio.Objects.InputStream as Gio.InputStream
import {-# SOURCE #-} qualified GI.Gio.Objects.OutputStream as Gio.OutputStream

newtype Subprocess = Subprocess (ManagedPtr Subprocess)
foreign import ccall "g_subprocess_get_type"
    c_g_subprocess_get_type :: IO GType

instance GObject Subprocess where
    gobjectType _ = c_g_subprocess_get_type
    

class GObject o => IsSubprocess o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError Subprocess a) =>
    IsSubprocess a
#endif
instance IsSubprocess Subprocess
instance GObject.Object.IsObject Subprocess
instance Gio.Initable.IsInitable Subprocess

toSubprocess :: IsSubprocess o => o -> IO Subprocess
toSubprocess = unsafeCastTo Subprocess

noSubprocess :: Maybe Subprocess
noSubprocess = Nothing

type family ResolveSubprocessMethod (t :: Symbol) (o :: *) :: * where
    ResolveSubprocessMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveSubprocessMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveSubprocessMethod "communicate" o = SubprocessCommunicateMethodInfo
    ResolveSubprocessMethod "communicateAsync" o = SubprocessCommunicateAsyncMethodInfo
    ResolveSubprocessMethod "communicateFinish" o = SubprocessCommunicateFinishMethodInfo
    ResolveSubprocessMethod "communicateUtf8" o = SubprocessCommunicateUtf8MethodInfo
    ResolveSubprocessMethod "communicateUtf8Async" o = SubprocessCommunicateUtf8AsyncMethodInfo
    ResolveSubprocessMethod "communicateUtf8Finish" o = SubprocessCommunicateUtf8FinishMethodInfo
    ResolveSubprocessMethod "forceExit" o = SubprocessForceExitMethodInfo
    ResolveSubprocessMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveSubprocessMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveSubprocessMethod "init" o = Gio.Initable.InitableInitMethodInfo
    ResolveSubprocessMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveSubprocessMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveSubprocessMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveSubprocessMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveSubprocessMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveSubprocessMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveSubprocessMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveSubprocessMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveSubprocessMethod "sendSignal" o = SubprocessSendSignalMethodInfo
    ResolveSubprocessMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveSubprocessMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveSubprocessMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveSubprocessMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveSubprocessMethod "wait" o = SubprocessWaitMethodInfo
    ResolveSubprocessMethod "waitAsync" o = SubprocessWaitAsyncMethodInfo
    ResolveSubprocessMethod "waitCheck" o = SubprocessWaitCheckMethodInfo
    ResolveSubprocessMethod "waitCheckAsync" o = SubprocessWaitCheckAsyncMethodInfo
    ResolveSubprocessMethod "waitCheckFinish" o = SubprocessWaitCheckFinishMethodInfo
    ResolveSubprocessMethod "waitFinish" o = SubprocessWaitFinishMethodInfo
    ResolveSubprocessMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveSubprocessMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveSubprocessMethod "getExitStatus" o = SubprocessGetExitStatusMethodInfo
    ResolveSubprocessMethod "getIdentifier" o = SubprocessGetIdentifierMethodInfo
    ResolveSubprocessMethod "getIfExited" o = SubprocessGetIfExitedMethodInfo
    ResolveSubprocessMethod "getIfSignaled" o = SubprocessGetIfSignaledMethodInfo
    ResolveSubprocessMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveSubprocessMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveSubprocessMethod "getStatus" o = SubprocessGetStatusMethodInfo
    ResolveSubprocessMethod "getStderrPipe" o = SubprocessGetStderrPipeMethodInfo
    ResolveSubprocessMethod "getStdinPipe" o = SubprocessGetStdinPipeMethodInfo
    ResolveSubprocessMethod "getStdoutPipe" o = SubprocessGetStdoutPipeMethodInfo
    ResolveSubprocessMethod "getSuccessful" o = SubprocessGetSuccessfulMethodInfo
    ResolveSubprocessMethod "getTermSig" o = SubprocessGetTermSigMethodInfo
    ResolveSubprocessMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveSubprocessMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveSubprocessMethod l o = O.MethodResolutionFailed l o

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

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

-- VVV Prop "argv"
   -- Type: TCArray True (-1) (-1) (TBasicType TUTF8)
   -- Flags: [PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Nothing,Nothing)

constructSubprocessArgv :: (IsSubprocess o) => [T.Text] -> IO (GValueConstruct o)
constructSubprocessArgv val = constructObjectPropertyStringArray "argv" (Just val)

data SubprocessArgvPropertyInfo
instance AttrInfo SubprocessArgvPropertyInfo where
    type AttrAllowedOps SubprocessArgvPropertyInfo = '[ 'AttrConstruct, 'AttrClear]
    type AttrSetTypeConstraint SubprocessArgvPropertyInfo = (~) [T.Text]
    type AttrBaseTypeConstraint SubprocessArgvPropertyInfo = IsSubprocess
    type AttrGetType SubprocessArgvPropertyInfo = ()
    type AttrLabel SubprocessArgvPropertyInfo = "argv"
    type AttrOrigin SubprocessArgvPropertyInfo = Subprocess
    attrGet _ = undefined
    attrSet _ = undefined
    attrConstruct _ = constructSubprocessArgv
    attrClear _ = undefined

-- VVV Prop "flags"
   -- Type: TInterface (Name {namespace = "Gio", name = "SubprocessFlags"})
   -- Flags: [PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Nothing,Nothing)

constructSubprocessFlags :: (IsSubprocess o) => [Gio.Flags.SubprocessFlags] -> IO (GValueConstruct o)
constructSubprocessFlags val = constructObjectPropertyFlags "flags" val

data SubprocessFlagsPropertyInfo
instance AttrInfo SubprocessFlagsPropertyInfo where
    type AttrAllowedOps SubprocessFlagsPropertyInfo = '[ 'AttrConstruct]
    type AttrSetTypeConstraint SubprocessFlagsPropertyInfo = (~) [Gio.Flags.SubprocessFlags]
    type AttrBaseTypeConstraint SubprocessFlagsPropertyInfo = IsSubprocess
    type AttrGetType SubprocessFlagsPropertyInfo = ()
    type AttrLabel SubprocessFlagsPropertyInfo = "flags"
    type AttrOrigin SubprocessFlagsPropertyInfo = Subprocess
    attrGet _ = undefined
    attrSet _ = undefined
    attrConstruct _ = constructSubprocessFlags
    attrClear _ = undefined

instance O.HasAttributeList Subprocess
type instance O.AttributeList Subprocess = SubprocessAttributeList
type SubprocessAttributeList = ('[ '("argv", SubprocessArgvPropertyInfo), '("flags", SubprocessFlagsPropertyInfo)] :: [(Symbol, *)])

subprocessArgv :: AttrLabelProxy "argv"
subprocessArgv = AttrLabelProxy

subprocessFlags :: AttrLabelProxy "flags"
subprocessFlags = AttrLabelProxy

type instance O.SignalList Subprocess = SubprocessSignalList
type SubprocessSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method Subprocess::new
-- method type : Constructor
-- Args : [Arg {argCName = "argv", argType = TCArray True (-1) (-1) (TBasicType TUTF8), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "commandline arguments for the subprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "flags", argType = TInterface (Name {namespace = "Gio", name = "SubprocessFlags"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "flags that define the behaviour of the subprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "Subprocess"}))
-- throws : True
-- Skip return : False

foreign import ccall "g_subprocess_newv" g_subprocess_newv :: 
    Ptr CString ->                          -- argv : TCArray True (-1) (-1) (TBasicType TUTF8)
    CUInt ->                                -- flags : TInterface (Name {namespace = "Gio", name = "SubprocessFlags"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Subprocess)

{- |
Create a new process with the given flags and argument list.

The argument list is expected to be 'Nothing'-terminated.

@since 2.40
-}
subprocessNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    [T.Text]
    {- ^ /@argv@/: commandline arguments for the subprocess -}
    -> [Gio.Flags.SubprocessFlags]
    {- ^ /@flags@/: flags that define the behaviour of the subprocess -}
    -> m Subprocess
    {- ^ __Returns:__ A newly created 'GI.Gio.Objects.Subprocess.Subprocess', or 'Nothing' on error (and /@error@/
  will be set) /(Can throw 'Data.GI.Base.GError.GError')/ -}
subprocessNew argv flags = liftIO $ do
    argv' <- packZeroTerminatedUTF8CArray argv
    let flags' = gflagsToWord flags
    onException (do
        result <- propagateGError $ g_subprocess_newv argv' flags'
        checkUnexpectedReturnNULL "subprocessNew" result
        result' <- (wrapObject Subprocess) result
        mapZeroTerminatedCArray freeMem argv'
        freeMem argv'
        return result'
     ) (do
        mapZeroTerminatedCArray freeMem argv'
        freeMem argv'
     )

-- method Subprocess::communicate
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "stdin_buf", argType = TInterface (Name {namespace = "GLib", name = "Bytes"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "data to send to the stdin of the subprocess, or %NULL", 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 "a #GCancellable", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "stdout_buf", argType = TInterface (Name {namespace = "GLib", name = "Bytes"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "data read from the subprocess stdout", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "stderr_buf", argType = TInterface (Name {namespace = "GLib", name = "Bytes"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "data read from the subprocess stderr", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_subprocess_communicate" g_subprocess_communicate :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    Ptr GLib.Bytes.Bytes ->                 -- stdin_buf : TInterface (Name {namespace = "GLib", name = "Bytes"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GLib.Bytes.Bytes) ->           -- stdout_buf : TInterface (Name {namespace = "GLib", name = "Bytes"})
    Ptr (Ptr GLib.Bytes.Bytes) ->           -- stderr_buf : TInterface (Name {namespace = "GLib", name = "Bytes"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Communicate with the subprocess until it terminates, and all input
and output has been completed.

If /@stdinBuf@/ is given, the subprocess must have been created with
'GI.Gio.Flags.SubprocessFlagsStdinPipe'.  The given data is fed to the
stdin of the subprocess and the pipe is closed (ie: EOF).

At the same time (as not to cause blocking when dealing with large
amounts of data), if 'GI.Gio.Flags.SubprocessFlagsStdoutPipe' or
'GI.Gio.Flags.SubprocessFlagsStderrPipe' were used, reads from those
streams.  The data that was read is returned in /@stdout@/ and\/or
the /@stderr@/.

If the subprocess was created with 'GI.Gio.Flags.SubprocessFlagsStdoutPipe',
/@stdoutBuf@/ will contain the data read from stdout.  Otherwise, for
subprocesses not created with 'GI.Gio.Flags.SubprocessFlagsStdoutPipe',
/@stdoutBuf@/ will be set to 'Nothing'.  Similar provisions apply to
/@stderrBuf@/ and 'GI.Gio.Flags.SubprocessFlagsStderrPipe'.

As usual, any output variable may be given as 'Nothing' to ignore it.

If you desire the stdout and stderr data to be interleaved, create
the subprocess with 'GI.Gio.Flags.SubprocessFlagsStdoutPipe' and
'GI.Gio.Flags.SubprocessFlagsStderrMerge'.  The merged result will be returned
in /@stdoutBuf@/ and /@stderrBuf@/ will be set to 'Nothing'.

In case of any error (including cancellation), 'False' will be
returned with /@error@/ set.  Some or all of the stdin data may have
been written.  Any stdout or stderr data that has been read will be
discarded. None of the out variables (aside from /@error@/) will have
been set to anything in particular and should not be inspected.

In the case that 'True' is returned, the subprocess has exited and the
exit status inspection APIs (eg: 'GI.Gio.Objects.Subprocess.subprocessGetIfExited',
'GI.Gio.Objects.Subprocess.subprocessGetExitStatus') may be used.

You should not attempt to use any of the subprocess pipes after
starting this function, since they may be left in strange states,
even if the operation was cancelled.  You should especially not
attempt to interact with the pipes while the operation is in progress
(either from another thread or if using the asynchronous version).

@since 2.40
-}
subprocessCommunicate ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> Maybe (GLib.Bytes.Bytes)
    {- ^ /@stdinBuf@/: data to send to the stdin of the subprocess, or 'Nothing' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable' -}
    -> m (GLib.Bytes.Bytes,GLib.Bytes.Bytes)
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
subprocessCommunicate subprocess stdinBuf cancellable = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    maybeStdinBuf <- case stdinBuf of
        Nothing -> return nullPtr
        Just jStdinBuf -> do
            jStdinBuf' <- unsafeManagedPtrGetPtr jStdinBuf
            return jStdinBuf'
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    stdoutBuf <- allocMem :: IO (Ptr (Ptr GLib.Bytes.Bytes))
    stderrBuf <- allocMem :: IO (Ptr (Ptr GLib.Bytes.Bytes))
    onException (do
        _ <- propagateGError $ g_subprocess_communicate subprocess' maybeStdinBuf maybeCancellable stdoutBuf stderrBuf
        stdoutBuf' <- peek stdoutBuf
        stdoutBuf'' <- (wrapBoxed GLib.Bytes.Bytes) stdoutBuf'
        stderrBuf' <- peek stderrBuf
        stderrBuf'' <- (wrapBoxed GLib.Bytes.Bytes) stderrBuf'
        touchManagedPtr subprocess
        whenJust stdinBuf touchManagedPtr
        whenJust cancellable touchManagedPtr
        freeMem stdoutBuf
        freeMem stderrBuf
        return (stdoutBuf'', stderrBuf'')
     ) (do
        freeMem stdoutBuf
        freeMem stderrBuf
     )

data SubprocessCommunicateMethodInfo
instance (signature ~ (Maybe (GLib.Bytes.Bytes) -> Maybe (b) -> m (GLib.Bytes.Bytes,GLib.Bytes.Bytes)), MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SubprocessCommunicateMethodInfo a signature where
    overloadedMethod _ = subprocessCommunicate

-- method Subprocess::communicate_async
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Self", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "stdin_buf", argType = TInterface (Name {namespace = "GLib", name = "Bytes"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "Input data, or %NULL", 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 "Cancellable", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "Callback", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 4, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "User data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_communicate_async" g_subprocess_communicate_async :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    Ptr GLib.Bytes.Bytes ->                 -- stdin_buf : TInterface (Name {namespace = "GLib", name = "Bytes"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

{- |
Asynchronous version of 'GI.Gio.Objects.Subprocess.subprocessCommunicate'.  Complete
invocation with 'GI.Gio.Objects.Subprocess.subprocessCommunicateFinish'.
-}
subprocessCommunicateAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@subprocess@/: Self -}
    -> Maybe (GLib.Bytes.Bytes)
    {- ^ /@stdinBuf@/: Input data, or 'Nothing' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: Cancellable -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: Callback -}
    -> m ()
subprocessCommunicateAsync subprocess stdinBuf cancellable callback = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    maybeStdinBuf <- case stdinBuf of
        Nothing -> return nullPtr
        Just jStdinBuf -> do
            jStdinBuf' <- unsafeManagedPtrGetPtr jStdinBuf
            return jStdinBuf'
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
    maybeCallback <- case callback of
        Nothing -> return (castPtrToFunPtr nullPtr)
        Just jCallback -> do
            jCallback' <- Gio.Callbacks.mk_AsyncReadyCallback (Gio.Callbacks.wrap_AsyncReadyCallback (Just ptrcallback) (Gio.Callbacks.drop_closures_AsyncReadyCallback jCallback))
            poke ptrcallback jCallback'
            return jCallback'
    let userData = nullPtr
    g_subprocess_communicate_async subprocess' maybeStdinBuf maybeCancellable maybeCallback userData
    touchManagedPtr subprocess
    whenJust stdinBuf touchManagedPtr
    whenJust cancellable touchManagedPtr
    return ()

data SubprocessCommunicateAsyncMethodInfo
instance (signature ~ (Maybe (GLib.Bytes.Bytes) -> Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SubprocessCommunicateAsyncMethodInfo a signature where
    overloadedMethod _ = subprocessCommunicateAsync

-- method Subprocess::communicate_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Self", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TInterface (Name {namespace = "Gio", name = "AsyncResult"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Result", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "stdout_buf", argType = TInterface (Name {namespace = "GLib", name = "Bytes"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Return location for stdout data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "stderr_buf", argType = TInterface (Name {namespace = "GLib", name = "Bytes"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Return location for stderr data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_subprocess_communicate_finish" g_subprocess_communicate_finish :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GLib.Bytes.Bytes) ->           -- stdout_buf : TInterface (Name {namespace = "GLib", name = "Bytes"})
    Ptr (Ptr GLib.Bytes.Bytes) ->           -- stderr_buf : TInterface (Name {namespace = "GLib", name = "Bytes"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Complete an invocation of 'GI.Gio.Objects.Subprocess.subprocessCommunicateAsync'.
-}
subprocessCommunicateFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    {- ^ /@subprocess@/: Self -}
    -> b
    {- ^ /@result@/: Result -}
    -> m (GLib.Bytes.Bytes,GLib.Bytes.Bytes)
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
subprocessCommunicateFinish subprocess result_ = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result_' <- unsafeManagedPtrCastPtr result_
    stdoutBuf <- allocMem :: IO (Ptr (Ptr GLib.Bytes.Bytes))
    stderrBuf <- allocMem :: IO (Ptr (Ptr GLib.Bytes.Bytes))
    onException (do
        _ <- propagateGError $ g_subprocess_communicate_finish subprocess' result_' stdoutBuf stderrBuf
        stdoutBuf' <- peek stdoutBuf
        stdoutBuf'' <- (wrapBoxed GLib.Bytes.Bytes) stdoutBuf'
        stderrBuf' <- peek stderrBuf
        stderrBuf'' <- (wrapBoxed GLib.Bytes.Bytes) stderrBuf'
        touchManagedPtr subprocess
        touchManagedPtr result_
        freeMem stdoutBuf
        freeMem stderrBuf
        return (stdoutBuf'', stderrBuf'')
     ) (do
        freeMem stdoutBuf
        freeMem stderrBuf
     )

data SubprocessCommunicateFinishMethodInfo
instance (signature ~ (b -> m (GLib.Bytes.Bytes,GLib.Bytes.Bytes)), MonadIO m, IsSubprocess a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo SubprocessCommunicateFinishMethodInfo a signature where
    overloadedMethod _ = subprocessCommunicateFinish

-- method Subprocess::communicate_utf8
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "stdin_buf", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "data to send to the stdin of the subprocess, or %NULL", 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 "a #GCancellable", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "stdout_buf", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "data read from the subprocess stdout", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "stderr_buf", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "data read from the subprocess stderr", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_subprocess_communicate_utf8" g_subprocess_communicate_utf8 :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    CString ->                              -- stdin_buf : TBasicType TUTF8
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr CString ->                          -- stdout_buf : TBasicType TUTF8
    Ptr CString ->                          -- stderr_buf : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Like 'GI.Gio.Objects.Subprocess.subprocessCommunicate', but validates the output of the
process as UTF-8, and returns it as a regular NUL terminated string.
-}
subprocessCommunicateUtf8 ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> Maybe (T.Text)
    {- ^ /@stdinBuf@/: data to send to the stdin of the subprocess, or 'Nothing' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable' -}
    -> m (T.Text,T.Text)
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
subprocessCommunicateUtf8 subprocess stdinBuf cancellable = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    maybeStdinBuf <- case stdinBuf of
        Nothing -> return nullPtr
        Just jStdinBuf -> do
            jStdinBuf' <- textToCString jStdinBuf
            return jStdinBuf'
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    stdoutBuf <- allocMem :: IO (Ptr CString)
    stderrBuf <- allocMem :: IO (Ptr CString)
    onException (do
        _ <- propagateGError $ g_subprocess_communicate_utf8 subprocess' maybeStdinBuf maybeCancellable stdoutBuf stderrBuf
        stdoutBuf' <- peek stdoutBuf
        stdoutBuf'' <- cstringToText stdoutBuf'
        freeMem stdoutBuf'
        stderrBuf' <- peek stderrBuf
        stderrBuf'' <- cstringToText stderrBuf'
        freeMem stderrBuf'
        touchManagedPtr subprocess
        whenJust cancellable touchManagedPtr
        freeMem maybeStdinBuf
        freeMem stdoutBuf
        freeMem stderrBuf
        return (stdoutBuf'', stderrBuf'')
     ) (do
        freeMem maybeStdinBuf
        freeMem stdoutBuf
        freeMem stderrBuf
     )

data SubprocessCommunicateUtf8MethodInfo
instance (signature ~ (Maybe (T.Text) -> Maybe (b) -> m (T.Text,T.Text)), MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SubprocessCommunicateUtf8MethodInfo a signature where
    overloadedMethod _ = subprocessCommunicateUtf8

-- method Subprocess::communicate_utf8_async
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Self", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "stdin_buf", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "Input data, or %NULL", 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 "Cancellable", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "Callback", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 4, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "User data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_communicate_utf8_async" g_subprocess_communicate_utf8_async :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    CString ->                              -- stdin_buf : TBasicType TUTF8
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

{- |
Asynchronous version of 'GI.Gio.Objects.Subprocess.subprocessCommunicateUtf8'.  Complete
invocation with 'GI.Gio.Objects.Subprocess.subprocessCommunicateUtf8Finish'.
-}
subprocessCommunicateUtf8Async ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@subprocess@/: Self -}
    -> Maybe (T.Text)
    {- ^ /@stdinBuf@/: Input data, or 'Nothing' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: Cancellable -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: Callback -}
    -> m ()
subprocessCommunicateUtf8Async subprocess stdinBuf cancellable callback = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    maybeStdinBuf <- case stdinBuf of
        Nothing -> return nullPtr
        Just jStdinBuf -> do
            jStdinBuf' <- textToCString jStdinBuf
            return jStdinBuf'
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
    maybeCallback <- case callback of
        Nothing -> return (castPtrToFunPtr nullPtr)
        Just jCallback -> do
            jCallback' <- Gio.Callbacks.mk_AsyncReadyCallback (Gio.Callbacks.wrap_AsyncReadyCallback (Just ptrcallback) (Gio.Callbacks.drop_closures_AsyncReadyCallback jCallback))
            poke ptrcallback jCallback'
            return jCallback'
    let userData = nullPtr
    g_subprocess_communicate_utf8_async subprocess' maybeStdinBuf maybeCancellable maybeCallback userData
    touchManagedPtr subprocess
    whenJust cancellable touchManagedPtr
    freeMem maybeStdinBuf
    return ()

data SubprocessCommunicateUtf8AsyncMethodInfo
instance (signature ~ (Maybe (T.Text) -> Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SubprocessCommunicateUtf8AsyncMethodInfo a signature where
    overloadedMethod _ = subprocessCommunicateUtf8Async

-- method Subprocess::communicate_utf8_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Self", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TInterface (Name {namespace = "Gio", name = "AsyncResult"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Result", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "stdout_buf", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Return location for stdout data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "stderr_buf", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Return location for stderr data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_subprocess_communicate_utf8_finish" g_subprocess_communicate_utf8_finish :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr CString ->                          -- stdout_buf : TBasicType TUTF8
    Ptr CString ->                          -- stderr_buf : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Complete an invocation of 'GI.Gio.Objects.Subprocess.subprocessCommunicateUtf8Async'.
-}
subprocessCommunicateUtf8Finish ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    {- ^ /@subprocess@/: Self -}
    -> b
    {- ^ /@result@/: Result -}
    -> m (T.Text,T.Text)
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
subprocessCommunicateUtf8Finish subprocess result_ = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result_' <- unsafeManagedPtrCastPtr result_
    stdoutBuf <- allocMem :: IO (Ptr CString)
    stderrBuf <- allocMem :: IO (Ptr CString)
    onException (do
        _ <- propagateGError $ g_subprocess_communicate_utf8_finish subprocess' result_' stdoutBuf stderrBuf
        stdoutBuf' <- peek stdoutBuf
        stdoutBuf'' <- cstringToText stdoutBuf'
        freeMem stdoutBuf'
        stderrBuf' <- peek stderrBuf
        stderrBuf'' <- cstringToText stderrBuf'
        freeMem stderrBuf'
        touchManagedPtr subprocess
        touchManagedPtr result_
        freeMem stdoutBuf
        freeMem stderrBuf
        return (stdoutBuf'', stderrBuf'')
     ) (do
        freeMem stdoutBuf
        freeMem stderrBuf
     )

data SubprocessCommunicateUtf8FinishMethodInfo
instance (signature ~ (b -> m (T.Text,T.Text)), MonadIO m, IsSubprocess a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo SubprocessCommunicateUtf8FinishMethodInfo a signature where
    overloadedMethod _ = subprocessCommunicateUtf8Finish

-- method Subprocess::force_exit
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_force_exit" g_subprocess_force_exit :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    IO ()

{- |
Use an operating-system specific method to attempt an immediate,
forceful termination of the process.  There is no mechanism to
determine whether or not the request itself was successful;
however, you can use 'GI.Gio.Objects.Subprocess.subprocessWait' to monitor the status of
the process after calling this function.

On Unix, this function sends @/SIGKILL/@.

@since 2.40
-}
subprocessForceExit ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> m ()
subprocessForceExit subprocess = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    g_subprocess_force_exit subprocess'
    touchManagedPtr subprocess
    return ()

data SubprocessForceExitMethodInfo
instance (signature ~ (m ()), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessForceExitMethodInfo a signature where
    overloadedMethod _ = subprocessForceExit

-- method Subprocess::get_exit_status
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_get_exit_status" g_subprocess_get_exit_status :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    IO Int32

{- |
Check the exit status of the subprocess, given that it exited
normally.  This is the value passed to the @/exit()/@ system call or the
return value from main.

This is equivalent to the system WEXITSTATUS macro.

It is an error to call this function before 'GI.Gio.Objects.Subprocess.subprocessWait' and
unless 'GI.Gio.Objects.Subprocess.subprocessGetIfExited' returned 'True'.

@since 2.40
-}
subprocessGetExitStatus ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> m Int32
    {- ^ __Returns:__ the exit status -}
subprocessGetExitStatus subprocess = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result <- g_subprocess_get_exit_status subprocess'
    touchManagedPtr subprocess
    return result

data SubprocessGetExitStatusMethodInfo
instance (signature ~ (m Int32), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessGetExitStatusMethodInfo a signature where
    overloadedMethod _ = subprocessGetExitStatus

-- method Subprocess::get_identifier
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", 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 "g_subprocess_get_identifier" g_subprocess_get_identifier :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    IO CString

{- |
On UNIX, returns the process ID as a decimal string.
On Windows, returns the result of @/GetProcessId()/@ also as a string.
-}
subprocessGetIdentifier ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> m T.Text
subprocessGetIdentifier subprocess = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result <- g_subprocess_get_identifier subprocess'
    checkUnexpectedReturnNULL "subprocessGetIdentifier" result
    result' <- cstringToText result
    touchManagedPtr subprocess
    return result'

data SubprocessGetIdentifierMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessGetIdentifierMethodInfo a signature where
    overloadedMethod _ = subprocessGetIdentifier

-- method Subprocess::get_if_exited
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_get_if_exited" g_subprocess_get_if_exited :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    IO CInt

{- |
Check if the given subprocess exited normally (ie: by way of @/exit()/@
or return from @/main()/@).

This is equivalent to the system WIFEXITED macro.

It is an error to call this function before 'GI.Gio.Objects.Subprocess.subprocessWait' has
returned.

@since 2.40
-}
subprocessGetIfExited ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the case of a normal exit -}
subprocessGetIfExited subprocess = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result <- g_subprocess_get_if_exited subprocess'
    let result' = (/= 0) result
    touchManagedPtr subprocess
    return result'

data SubprocessGetIfExitedMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessGetIfExitedMethodInfo a signature where
    overloadedMethod _ = subprocessGetIfExited

-- method Subprocess::get_if_signaled
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_get_if_signaled" g_subprocess_get_if_signaled :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    IO CInt

{- |
Check if the given subprocess terminated in response to a signal.

This is equivalent to the system WIFSIGNALED macro.

It is an error to call this function before 'GI.Gio.Objects.Subprocess.subprocessWait' has
returned.

@since 2.40
-}
subprocessGetIfSignaled ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the case of termination due to a signal -}
subprocessGetIfSignaled subprocess = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result <- g_subprocess_get_if_signaled subprocess'
    let result' = (/= 0) result
    touchManagedPtr subprocess
    return result'

data SubprocessGetIfSignaledMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessGetIfSignaledMethodInfo a signature where
    overloadedMethod _ = subprocessGetIfSignaled

-- method Subprocess::get_status
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_get_status" g_subprocess_get_status :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    IO Int32

{- |
Gets the raw status code of the process, as from @/waitpid()/@.

This value has no particular meaning, but it can be used with the
macros defined by the system headers such as WIFEXITED.  It can also
be used with 'GI.GLib.Functions.spawnCheckExitStatus'.

It is more likely that you want to use 'GI.Gio.Objects.Subprocess.subprocessGetIfExited'
followed by 'GI.Gio.Objects.Subprocess.subprocessGetExitStatus'.

It is an error to call this function before 'GI.Gio.Objects.Subprocess.subprocessWait' has
returned.

@since 2.40
-}
subprocessGetStatus ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> m Int32
    {- ^ __Returns:__ the (meaningless) @/waitpid()/@ exit status from the kernel -}
subprocessGetStatus subprocess = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result <- g_subprocess_get_status subprocess'
    touchManagedPtr subprocess
    return result

data SubprocessGetStatusMethodInfo
instance (signature ~ (m Int32), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessGetStatusMethodInfo a signature where
    overloadedMethod _ = subprocessGetStatus

-- method Subprocess::get_stderr_pipe
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "InputStream"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_get_stderr_pipe" g_subprocess_get_stderr_pipe :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    IO (Ptr Gio.InputStream.InputStream)

{- |
Gets the 'GI.Gio.Objects.InputStream.InputStream' from which to read the stderr output of
/@subprocess@/.

The process must have been created with
'GI.Gio.Flags.SubprocessFlagsStderrPipe'.

@since 2.40
-}
subprocessGetStderrPipe ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> m Gio.InputStream.InputStream
    {- ^ __Returns:__ the stderr pipe -}
subprocessGetStderrPipe subprocess = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result <- g_subprocess_get_stderr_pipe subprocess'
    checkUnexpectedReturnNULL "subprocessGetStderrPipe" result
    result' <- (newObject Gio.InputStream.InputStream) result
    touchManagedPtr subprocess
    return result'

data SubprocessGetStderrPipeMethodInfo
instance (signature ~ (m Gio.InputStream.InputStream), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessGetStderrPipeMethodInfo a signature where
    overloadedMethod _ = subprocessGetStderrPipe

-- method Subprocess::get_stdin_pipe
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "OutputStream"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_get_stdin_pipe" g_subprocess_get_stdin_pipe :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    IO (Ptr Gio.OutputStream.OutputStream)

{- |
Gets the 'GI.Gio.Objects.OutputStream.OutputStream' that you can write to in order to give data
to the stdin of /@subprocess@/.

The process must have been created with
'GI.Gio.Flags.SubprocessFlagsStdinPipe'.

@since 2.40
-}
subprocessGetStdinPipe ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> m Gio.OutputStream.OutputStream
    {- ^ __Returns:__ the stdout pipe -}
subprocessGetStdinPipe subprocess = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result <- g_subprocess_get_stdin_pipe subprocess'
    checkUnexpectedReturnNULL "subprocessGetStdinPipe" result
    result' <- (newObject Gio.OutputStream.OutputStream) result
    touchManagedPtr subprocess
    return result'

data SubprocessGetStdinPipeMethodInfo
instance (signature ~ (m Gio.OutputStream.OutputStream), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessGetStdinPipeMethodInfo a signature where
    overloadedMethod _ = subprocessGetStdinPipe

-- method Subprocess::get_stdout_pipe
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "InputStream"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_get_stdout_pipe" g_subprocess_get_stdout_pipe :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    IO (Ptr Gio.InputStream.InputStream)

{- |
Gets the 'GI.Gio.Objects.InputStream.InputStream' from which to read the stdout output of
/@subprocess@/.

The process must have been created with
'GI.Gio.Flags.SubprocessFlagsStdoutPipe'.

@since 2.40
-}
subprocessGetStdoutPipe ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> m Gio.InputStream.InputStream
    {- ^ __Returns:__ the stdout pipe -}
subprocessGetStdoutPipe subprocess = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result <- g_subprocess_get_stdout_pipe subprocess'
    checkUnexpectedReturnNULL "subprocessGetStdoutPipe" result
    result' <- (newObject Gio.InputStream.InputStream) result
    touchManagedPtr subprocess
    return result'

data SubprocessGetStdoutPipeMethodInfo
instance (signature ~ (m Gio.InputStream.InputStream), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessGetStdoutPipeMethodInfo a signature where
    overloadedMethod _ = subprocessGetStdoutPipe

-- method Subprocess::get_successful
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_get_successful" g_subprocess_get_successful :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    IO CInt

{- |
Checks if the process was \"successful\".  A process is considered
successful if it exited cleanly with an exit status of 0, either by
way of the @/exit()/@ system call or return from @/main()/@.

It is an error to call this function before 'GI.Gio.Objects.Subprocess.subprocessWait' has
returned.

@since 2.40
-}
subprocessGetSuccessful ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the process exited cleanly with a exit status of 0 -}
subprocessGetSuccessful subprocess = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result <- g_subprocess_get_successful subprocess'
    let result' = (/= 0) result
    touchManagedPtr subprocess
    return result'

data SubprocessGetSuccessfulMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessGetSuccessfulMethodInfo a signature where
    overloadedMethod _ = subprocessGetSuccessful

-- method Subprocess::get_term_sig
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_get_term_sig" g_subprocess_get_term_sig :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    IO Int32

{- |
Get the signal number that caused the subprocess to terminate, given
that it terminated due to a signal.

This is equivalent to the system WTERMSIG macro.

It is an error to call this function before 'GI.Gio.Objects.Subprocess.subprocessWait' and
unless 'GI.Gio.Objects.Subprocess.subprocessGetIfSignaled' returned 'True'.

@since 2.40
-}
subprocessGetTermSig ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> m Int32
    {- ^ __Returns:__ the signal causing termination -}
subprocessGetTermSig subprocess = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result <- g_subprocess_get_term_sig subprocess'
    touchManagedPtr subprocess
    return result

data SubprocessGetTermSigMethodInfo
instance (signature ~ (m Int32), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessGetTermSigMethodInfo a signature where
    overloadedMethod _ = subprocessGetTermSig

-- method Subprocess::send_signal
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "signal_num", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the signal number to send", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_send_signal" g_subprocess_send_signal :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    Int32 ->                                -- signal_num : TBasicType TInt
    IO ()

{- |
Sends the UNIX signal /@signalNum@/ to the subprocess, if it is still
running.

This API is race-free.  If the subprocess has terminated, it will not
be signalled.

This API is not available on Windows.

@since 2.40
-}
subprocessSendSignal ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> Int32
    {- ^ /@signalNum@/: the signal number to send -}
    -> m ()
subprocessSendSignal subprocess signalNum = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    g_subprocess_send_signal subprocess' signalNum
    touchManagedPtr subprocess
    return ()

data SubprocessSendSignalMethodInfo
instance (signature ~ (Int32 -> m ()), MonadIO m, IsSubprocess a) => O.MethodInfo SubprocessSendSignalMethodInfo a signature where
    overloadedMethod _ = subprocessSendSignal

-- method Subprocess::wait
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", 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 "a #GCancellable", 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 "g_subprocess_wait" g_subprocess_wait :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Synchronously wait for the subprocess to terminate.

After the process terminates you can query its exit status with
functions such as 'GI.Gio.Objects.Subprocess.subprocessGetIfExited' and
'GI.Gio.Objects.Subprocess.subprocessGetExitStatus'.

This function does not fail in the case of the subprocess having
abnormal termination.  See 'GI.Gio.Objects.Subprocess.subprocessWaitCheck' for that.

Cancelling /@cancellable@/ doesn\'t kill the subprocess.  Call
'GI.Gio.Objects.Subprocess.subprocessForceExit' if it is desirable.

@since 2.40
-}
subprocessWait ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
subprocessWait subprocess cancellable = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    onException (do
        _ <- propagateGError $ g_subprocess_wait subprocess' maybeCancellable
        touchManagedPtr subprocess
        whenJust cancellable touchManagedPtr
        return ()
     ) (do
        return ()
     )

data SubprocessWaitMethodInfo
instance (signature ~ (Maybe (b) -> m ()), MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SubprocessWaitMethodInfo a signature where
    overloadedMethod _ = subprocessWait

-- method Subprocess::wait_async
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", 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 "a #GCancellable, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GAsyncReadyCallback to call when the operation is complete", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 3, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "user_data for @callback", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_wait_async" g_subprocess_wait_async :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

{- |
Wait for the subprocess to terminate.

This is the asynchronous version of 'GI.Gio.Objects.Subprocess.subprocessWait'.

@since 2.40
-}
subprocessWaitAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: a 'GI.Gio.Callbacks.AsyncReadyCallback' to call when the operation is complete -}
    -> m ()
subprocessWaitAsync subprocess cancellable callback = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
    maybeCallback <- case callback of
        Nothing -> return (castPtrToFunPtr nullPtr)
        Just jCallback -> do
            jCallback' <- Gio.Callbacks.mk_AsyncReadyCallback (Gio.Callbacks.wrap_AsyncReadyCallback (Just ptrcallback) (Gio.Callbacks.drop_closures_AsyncReadyCallback jCallback))
            poke ptrcallback jCallback'
            return jCallback'
    let userData = nullPtr
    g_subprocess_wait_async subprocess' maybeCancellable maybeCallback userData
    touchManagedPtr subprocess
    whenJust cancellable touchManagedPtr
    return ()

data SubprocessWaitAsyncMethodInfo
instance (signature ~ (Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SubprocessWaitAsyncMethodInfo a signature where
    overloadedMethod _ = subprocessWaitAsync

-- method Subprocess::wait_check
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", 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 "a #GCancellable", 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 "g_subprocess_wait_check" g_subprocess_wait_check :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Combines 'GI.Gio.Objects.Subprocess.subprocessWait' with 'GI.GLib.Functions.spawnCheckExitStatus'.

@since 2.40
-}
subprocessWaitCheck ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
subprocessWaitCheck subprocess cancellable = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    onException (do
        _ <- propagateGError $ g_subprocess_wait_check subprocess' maybeCancellable
        touchManagedPtr subprocess
        whenJust cancellable touchManagedPtr
        return ()
     ) (do
        return ()
     )

data SubprocessWaitCheckMethodInfo
instance (signature ~ (Maybe (b) -> m ()), MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SubprocessWaitCheckMethodInfo a signature where
    overloadedMethod _ = subprocessWaitCheck

-- method Subprocess::wait_check_async
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", 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 "a #GCancellable, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GAsyncReadyCallback to call when the operation is complete", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 3, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "user_data for @callback", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_subprocess_wait_check_async" g_subprocess_wait_check_async :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

{- |
Combines 'GI.Gio.Objects.Subprocess.subprocessWaitAsync' with 'GI.GLib.Functions.spawnCheckExitStatus'.

This is the asynchronous version of 'GI.Gio.Objects.Subprocess.subprocessWaitCheck'.

@since 2.40
-}
subprocessWaitCheckAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: a 'GI.Gio.Callbacks.AsyncReadyCallback' to call when the operation is complete -}
    -> m ()
subprocessWaitCheckAsync subprocess cancellable callback = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
    maybeCallback <- case callback of
        Nothing -> return (castPtrToFunPtr nullPtr)
        Just jCallback -> do
            jCallback' <- Gio.Callbacks.mk_AsyncReadyCallback (Gio.Callbacks.wrap_AsyncReadyCallback (Just ptrcallback) (Gio.Callbacks.drop_closures_AsyncReadyCallback jCallback))
            poke ptrcallback jCallback'
            return jCallback'
    let userData = nullPtr
    g_subprocess_wait_check_async subprocess' maybeCancellable maybeCallback userData
    touchManagedPtr subprocess
    whenJust cancellable touchManagedPtr
    return ()

data SubprocessWaitCheckAsyncMethodInfo
instance (signature ~ (Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsSubprocess a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SubprocessWaitCheckAsyncMethodInfo a signature where
    overloadedMethod _ = subprocessWaitCheckAsync

-- method Subprocess::wait_check_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TInterface (Name {namespace = "Gio", name = "AsyncResult"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GAsyncResult passed to your #GAsyncReadyCallback", 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 "g_subprocess_wait_check_finish" g_subprocess_wait_check_finish :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Collects the result of a previous call to
'GI.Gio.Objects.Subprocess.subprocessWaitCheckAsync'.

@since 2.40
-}
subprocessWaitCheckFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> b
    {- ^ /@result@/: the 'GI.Gio.Interfaces.AsyncResult.AsyncResult' passed to your 'GI.Gio.Callbacks.AsyncReadyCallback' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
subprocessWaitCheckFinish subprocess result_ = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result_' <- unsafeManagedPtrCastPtr result_
    onException (do
        _ <- propagateGError $ g_subprocess_wait_check_finish subprocess' result_'
        touchManagedPtr subprocess
        touchManagedPtr result_
        return ()
     ) (do
        return ()
     )

data SubprocessWaitCheckFinishMethodInfo
instance (signature ~ (b -> m ()), MonadIO m, IsSubprocess a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo SubprocessWaitCheckFinishMethodInfo a signature where
    overloadedMethod _ = subprocessWaitCheckFinish

-- method Subprocess::wait_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "subprocess", argType = TInterface (Name {namespace = "Gio", name = "Subprocess"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSubprocess", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TInterface (Name {namespace = "Gio", name = "AsyncResult"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GAsyncResult passed to your #GAsyncReadyCallback", 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 "g_subprocess_wait_finish" g_subprocess_wait_finish :: 
    Ptr Subprocess ->                       -- subprocess : TInterface (Name {namespace = "Gio", name = "Subprocess"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Collects the result of a previous call to
'GI.Gio.Objects.Subprocess.subprocessWaitAsync'.

@since 2.40
-}
subprocessWaitFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsSubprocess a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    {- ^ /@subprocess@/: a 'GI.Gio.Objects.Subprocess.Subprocess' -}
    -> b
    {- ^ /@result@/: the 'GI.Gio.Interfaces.AsyncResult.AsyncResult' passed to your 'GI.Gio.Callbacks.AsyncReadyCallback' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
subprocessWaitFinish subprocess result_ = liftIO $ do
    subprocess' <- unsafeManagedPtrCastPtr subprocess
    result_' <- unsafeManagedPtrCastPtr result_
    onException (do
        _ <- propagateGError $ g_subprocess_wait_finish subprocess' result_'
        touchManagedPtr subprocess
        touchManagedPtr result_
        return ()
     ) (do
        return ()
     )

data SubprocessWaitFinishMethodInfo
instance (signature ~ (b -> m ()), MonadIO m, IsSubprocess a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo SubprocessWaitFinishMethodInfo a signature where
    overloadedMethod _ = subprocessWaitFinish