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

Watches @/GUnixMounts/@ for changes.
-}

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

module GI.Gio.Objects.UnixMountMonitor
    (

-- * Exported types
    UnixMountMonitor(..)                    ,
    IsUnixMountMonitor                      ,
    toUnixMountMonitor                      ,
    noUnixMountMonitor                      ,


 -- * Methods
-- ** get #method:get#

    unixMountMonitorGet                     ,


-- ** new #method:new#

    unixMountMonitorNew                     ,


-- ** setRateLimit #method:setRateLimit#

#if ENABLE_OVERLOADING
    UnixMountMonitorSetRateLimitMethodInfo  ,
#endif
    unixMountMonitorSetRateLimit            ,




 -- * Signals
-- ** mountpointsChanged #signal:mountpointsChanged#

    C_UnixMountMonitorMountpointsChangedCallback,
    UnixMountMonitorMountpointsChangedCallback,
#if ENABLE_OVERLOADING
    UnixMountMonitorMountpointsChangedSignalInfo,
#endif
    afterUnixMountMonitorMountpointsChanged ,
    genClosure_UnixMountMonitorMountpointsChanged,
    mk_UnixMountMonitorMountpointsChangedCallback,
    noUnixMountMonitorMountpointsChangedCallback,
    onUnixMountMonitorMountpointsChanged    ,
    wrap_UnixMountMonitorMountpointsChangedCallback,


-- ** mountsChanged #signal:mountsChanged#

    C_UnixMountMonitorMountsChangedCallback ,
    UnixMountMonitorMountsChangedCallback   ,
#if ENABLE_OVERLOADING
    UnixMountMonitorMountsChangedSignalInfo ,
#endif
    afterUnixMountMonitorMountsChanged      ,
    genClosure_UnixMountMonitorMountsChanged,
    mk_UnixMountMonitorMountsChangedCallback,
    noUnixMountMonitorMountsChangedCallback ,
    onUnixMountMonitorMountsChanged         ,
    wrap_UnixMountMonitorMountsChangedCallback,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.GObject.Objects.Object as GObject.Object

-- | Memory-managed wrapper type.
newtype UnixMountMonitor = UnixMountMonitor (ManagedPtr UnixMountMonitor)
foreign import ccall "g_unix_mount_monitor_get_type"
    c_g_unix_mount_monitor_get_type :: IO GType

instance GObject UnixMountMonitor where
    gobjectType = c_g_unix_mount_monitor_get_type


-- | Type class for types which can be safely cast to `UnixMountMonitor`, for instance with `toUnixMountMonitor`.
class (GObject o, O.IsDescendantOf UnixMountMonitor o) => IsUnixMountMonitor o
instance (GObject o, O.IsDescendantOf UnixMountMonitor o) => IsUnixMountMonitor o

instance O.HasParentTypes UnixMountMonitor
type instance O.ParentTypes UnixMountMonitor = '[GObject.Object.Object]

-- | Cast to `UnixMountMonitor`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toUnixMountMonitor :: (MonadIO m, IsUnixMountMonitor o) => o -> m UnixMountMonitor
toUnixMountMonitor = liftIO . unsafeCastTo UnixMountMonitor

-- | A convenience alias for `Nothing` :: `Maybe` `UnixMountMonitor`.
noUnixMountMonitor :: Maybe UnixMountMonitor
noUnixMountMonitor = Nothing

#if ENABLE_OVERLOADING
type family ResolveUnixMountMonitorMethod (t :: Symbol) (o :: *) :: * where
    ResolveUnixMountMonitorMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveUnixMountMonitorMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveUnixMountMonitorMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveUnixMountMonitorMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveUnixMountMonitorMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveUnixMountMonitorMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveUnixMountMonitorMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveUnixMountMonitorMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveUnixMountMonitorMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveUnixMountMonitorMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveUnixMountMonitorMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveUnixMountMonitorMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveUnixMountMonitorMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveUnixMountMonitorMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveUnixMountMonitorMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveUnixMountMonitorMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveUnixMountMonitorMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveUnixMountMonitorMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveUnixMountMonitorMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveUnixMountMonitorMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveUnixMountMonitorMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveUnixMountMonitorMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveUnixMountMonitorMethod "setRateLimit" o = UnixMountMonitorSetRateLimitMethodInfo
    ResolveUnixMountMonitorMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveUnixMountMonitorMethod t UnixMountMonitor, O.MethodInfo info UnixMountMonitor p) => OL.IsLabel t (UnixMountMonitor -> 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

-- signal UnixMountMonitor::mountpoints-changed
{- |
Emitted when the unix mount points have changed.
-}
type UnixMountMonitorMountpointsChangedCallback =
    IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `UnixMountMonitorMountpointsChangedCallback`@.
noUnixMountMonitorMountpointsChangedCallback :: Maybe UnixMountMonitorMountpointsChangedCallback
noUnixMountMonitorMountpointsChangedCallback = Nothing

-- | Type for the callback on the (unwrapped) C side.
type C_UnixMountMonitorMountpointsChangedCallback =
    Ptr () ->                               -- object
    Ptr () ->                               -- user_data
    IO ()

-- | Generate a function pointer callable from C code, from a `C_UnixMountMonitorMountpointsChangedCallback`.
foreign import ccall "wrapper"
    mk_UnixMountMonitorMountpointsChangedCallback :: C_UnixMountMonitorMountpointsChangedCallback -> IO (FunPtr C_UnixMountMonitorMountpointsChangedCallback)

-- | Wrap the callback into a `GClosure`.
genClosure_UnixMountMonitorMountpointsChanged :: MonadIO m => UnixMountMonitorMountpointsChangedCallback -> m (GClosure C_UnixMountMonitorMountpointsChangedCallback)
genClosure_UnixMountMonitorMountpointsChanged cb = liftIO $ do
    let cb' = wrap_UnixMountMonitorMountpointsChangedCallback cb
    mk_UnixMountMonitorMountpointsChangedCallback cb' >>= B.GClosure.newGClosure


-- | Wrap a `UnixMountMonitorMountpointsChangedCallback` into a `C_UnixMountMonitorMountpointsChangedCallback`.
wrap_UnixMountMonitorMountpointsChangedCallback ::
    UnixMountMonitorMountpointsChangedCallback ->
    C_UnixMountMonitorMountpointsChangedCallback
wrap_UnixMountMonitorMountpointsChangedCallback _cb _ _ = do
    _cb


{- |
Connect a signal handler for the “@mountpoints-changed@” signal, to be run before the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.on' unixMountMonitor #mountpointsChanged callback
@
-}
onUnixMountMonitorMountpointsChanged :: (IsUnixMountMonitor a, MonadIO m) => a -> UnixMountMonitorMountpointsChangedCallback -> m SignalHandlerId
onUnixMountMonitorMountpointsChanged obj cb = liftIO $ do
    let cb' = wrap_UnixMountMonitorMountpointsChangedCallback cb
    cb'' <- mk_UnixMountMonitorMountpointsChangedCallback cb'
    connectSignalFunPtr obj "mountpoints-changed" cb'' SignalConnectBefore

{- |
Connect a signal handler for the “@mountpoints-changed@” signal, to be run after the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.after' unixMountMonitor #mountpointsChanged callback
@
-}
afterUnixMountMonitorMountpointsChanged :: (IsUnixMountMonitor a, MonadIO m) => a -> UnixMountMonitorMountpointsChangedCallback -> m SignalHandlerId
afterUnixMountMonitorMountpointsChanged obj cb = liftIO $ do
    let cb' = wrap_UnixMountMonitorMountpointsChangedCallback cb
    cb'' <- mk_UnixMountMonitorMountpointsChangedCallback cb'
    connectSignalFunPtr obj "mountpoints-changed" cb'' SignalConnectAfter


-- signal UnixMountMonitor::mounts-changed
{- |
Emitted when the unix mounts have changed.
-}
type UnixMountMonitorMountsChangedCallback =
    IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `UnixMountMonitorMountsChangedCallback`@.
noUnixMountMonitorMountsChangedCallback :: Maybe UnixMountMonitorMountsChangedCallback
noUnixMountMonitorMountsChangedCallback = Nothing

-- | Type for the callback on the (unwrapped) C side.
type C_UnixMountMonitorMountsChangedCallback =
    Ptr () ->                               -- object
    Ptr () ->                               -- user_data
    IO ()

-- | Generate a function pointer callable from C code, from a `C_UnixMountMonitorMountsChangedCallback`.
foreign import ccall "wrapper"
    mk_UnixMountMonitorMountsChangedCallback :: C_UnixMountMonitorMountsChangedCallback -> IO (FunPtr C_UnixMountMonitorMountsChangedCallback)

-- | Wrap the callback into a `GClosure`.
genClosure_UnixMountMonitorMountsChanged :: MonadIO m => UnixMountMonitorMountsChangedCallback -> m (GClosure C_UnixMountMonitorMountsChangedCallback)
genClosure_UnixMountMonitorMountsChanged cb = liftIO $ do
    let cb' = wrap_UnixMountMonitorMountsChangedCallback cb
    mk_UnixMountMonitorMountsChangedCallback cb' >>= B.GClosure.newGClosure


-- | Wrap a `UnixMountMonitorMountsChangedCallback` into a `C_UnixMountMonitorMountsChangedCallback`.
wrap_UnixMountMonitorMountsChangedCallback ::
    UnixMountMonitorMountsChangedCallback ->
    C_UnixMountMonitorMountsChangedCallback
wrap_UnixMountMonitorMountsChangedCallback _cb _ _ = do
    _cb


{- |
Connect a signal handler for the “@mounts-changed@” signal, to be run before the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.on' unixMountMonitor #mountsChanged callback
@
-}
onUnixMountMonitorMountsChanged :: (IsUnixMountMonitor a, MonadIO m) => a -> UnixMountMonitorMountsChangedCallback -> m SignalHandlerId
onUnixMountMonitorMountsChanged obj cb = liftIO $ do
    let cb' = wrap_UnixMountMonitorMountsChangedCallback cb
    cb'' <- mk_UnixMountMonitorMountsChangedCallback cb'
    connectSignalFunPtr obj "mounts-changed" cb'' SignalConnectBefore

{- |
Connect a signal handler for the “@mounts-changed@” signal, to be run after the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.after' unixMountMonitor #mountsChanged callback
@
-}
afterUnixMountMonitorMountsChanged :: (IsUnixMountMonitor a, MonadIO m) => a -> UnixMountMonitorMountsChangedCallback -> m SignalHandlerId
afterUnixMountMonitorMountsChanged obj cb = liftIO $ do
    let cb' = wrap_UnixMountMonitorMountsChangedCallback cb
    cb'' <- mk_UnixMountMonitorMountsChangedCallback cb'
    connectSignalFunPtr obj "mounts-changed" cb'' SignalConnectAfter


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

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
data UnixMountMonitorMountpointsChangedSignalInfo
instance SignalInfo UnixMountMonitorMountpointsChangedSignalInfo where
    type HaskellCallbackType UnixMountMonitorMountpointsChangedSignalInfo = UnixMountMonitorMountpointsChangedCallback
    connectSignal _ obj cb connectMode = do
        let cb' = wrap_UnixMountMonitorMountpointsChangedCallback cb
        cb'' <- mk_UnixMountMonitorMountpointsChangedCallback cb'
        connectSignalFunPtr obj "mountpoints-changed" cb'' connectMode

data UnixMountMonitorMountsChangedSignalInfo
instance SignalInfo UnixMountMonitorMountsChangedSignalInfo where
    type HaskellCallbackType UnixMountMonitorMountsChangedSignalInfo = UnixMountMonitorMountsChangedCallback
    connectSignal _ obj cb connectMode = do
        let cb' = wrap_UnixMountMonitorMountsChangedCallback cb
        cb'' <- mk_UnixMountMonitorMountsChangedCallback cb'
        connectSignalFunPtr obj "mounts-changed" cb'' connectMode

type instance O.SignalList UnixMountMonitor = UnixMountMonitorSignalList
type UnixMountMonitorSignalList = ('[ '("mountpointsChanged", UnixMountMonitorMountpointsChangedSignalInfo), '("mountsChanged", UnixMountMonitorMountsChangedSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method UnixMountMonitor::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "UnixMountMonitor"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_mount_monitor_new" g_unix_mount_monitor_new ::
    IO (Ptr UnixMountMonitor)

{-# DEPRECATED unixMountMonitorNew ["(Since version 2.44)","Use 'GI.Gio.Objects.UnixMountMonitor.unixMountMonitorGet' instead."] #-}
{- |
Deprecated alias for 'GI.Gio.Objects.UnixMountMonitor.unixMountMonitorGet'.

This function was never a true constructor, which is why it was
renamed.
-}
unixMountMonitorNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m UnixMountMonitor
    {- ^ __Returns:__ a 'GI.Gio.Objects.UnixMountMonitor.UnixMountMonitor'. -}
unixMountMonitorNew  = liftIO $ do
    result <- g_unix_mount_monitor_new
    checkUnexpectedReturnNULL "unixMountMonitorNew" result
    result' <- (wrapObject UnixMountMonitor) result
    return result'

#if ENABLE_OVERLOADING
#endif

-- method UnixMountMonitor::set_rate_limit
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "mount_monitor", argType = TInterface (Name {namespace = "Gio", name = "UnixMountMonitor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GUnixMountMonitor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "limit_msec", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a integer with the limit in milliseconds to\n    poll for changes.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_mount_monitor_set_rate_limit" g_unix_mount_monitor_set_rate_limit ::
    Ptr UnixMountMonitor ->                 -- mount_monitor : TInterface (Name {namespace = "Gio", name = "UnixMountMonitor"})
    Int32 ->                                -- limit_msec : TBasicType TInt
    IO ()

{-# DEPRECATED unixMountMonitorSetRateLimit ["(Since version 2.44)","This function does nothing.  Don\\'t call it."] #-}
{- |
This function does nothing.

Before 2.44, this was a partially-effective way of controlling the
rate at which events would be reported under some uncommon
circumstances.  Since /@mountMonitor@/ is a singleton, it also meant
that calling this function would have side effects for other users of
the monitor.

/Since: 2.18/
-}
unixMountMonitorSetRateLimit ::
    (B.CallStack.HasCallStack, MonadIO m, IsUnixMountMonitor a) =>
    a
    {- ^ /@mountMonitor@/: a 'GI.Gio.Objects.UnixMountMonitor.UnixMountMonitor' -}
    -> Int32
    {- ^ /@limitMsec@/: a integer with the limit in milliseconds to
    poll for changes. -}
    -> m ()
unixMountMonitorSetRateLimit mountMonitor limitMsec = liftIO $ do
    mountMonitor' <- unsafeManagedPtrCastPtr mountMonitor
    g_unix_mount_monitor_set_rate_limit mountMonitor' limitMsec
    touchManagedPtr mountMonitor
    return ()

#if ENABLE_OVERLOADING
data UnixMountMonitorSetRateLimitMethodInfo
instance (signature ~ (Int32 -> m ()), MonadIO m, IsUnixMountMonitor a) => O.MethodInfo UnixMountMonitorSetRateLimitMethodInfo a signature where
    overloadedMethod _ = unixMountMonitorSetRateLimit

#endif

-- method UnixMountMonitor::get
-- method type : MemberFunction
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "UnixMountMonitor"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_mount_monitor_get" g_unix_mount_monitor_get ::
    IO (Ptr UnixMountMonitor)

{- |
Gets the 'GI.Gio.Objects.UnixMountMonitor.UnixMountMonitor' for the current thread-default main
context.

The mount monitor can be used to monitor for changes to the list of
mounted filesystems as well as the list of mount points (ie: fstab
entries).

You must only call 'GI.GObject.Objects.Object.objectUnref' on the return value from under
the same main context as you called this function.

/Since: 2.44/
-}
unixMountMonitorGet ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m UnixMountMonitor
    {- ^ __Returns:__ the 'GI.Gio.Objects.UnixMountMonitor.UnixMountMonitor'. -}
unixMountMonitorGet  = liftIO $ do
    result <- g_unix_mount_monitor_get
    checkUnexpectedReturnNULL "unixMountMonitorGet" result
    result' <- (wrapObject UnixMountMonitor) result
    return result'

#if ENABLE_OVERLOADING
#endif