{- |
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.Interfaces.NetworkMonitor.NetworkMonitor' provides an easy-to-use cross-platform API
for monitoring network connectivity. On Linux, the implementation
is based on the kernel\'s netlink interface.
-}

module GI.Gio.Interfaces.NetworkMonitor
    ( 

-- * Exported types
    NetworkMonitor(..)                      ,
    noNetworkMonitor                        ,
    IsNetworkMonitor                        ,
    toNetworkMonitor                        ,


 -- * Methods
-- ** canReach #method:canReach#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NetworkMonitorCanReachMethodInfo        ,
#endif
    networkMonitorCanReach                  ,


-- ** canReachAsync #method:canReachAsync#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NetworkMonitorCanReachAsyncMethodInfo   ,
#endif
    networkMonitorCanReachAsync             ,


-- ** canReachFinish #method:canReachFinish#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NetworkMonitorCanReachFinishMethodInfo  ,
#endif
    networkMonitorCanReachFinish            ,


-- ** getConnectivity #method:getConnectivity#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NetworkMonitorGetConnectivityMethodInfo ,
#endif
    networkMonitorGetConnectivity           ,


-- ** getDefault #method:getDefault#
    networkMonitorGetDefault                ,


-- ** getNetworkAvailable #method:getNetworkAvailable#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NetworkMonitorGetNetworkAvailableMethodInfo,
#endif
    networkMonitorGetNetworkAvailable       ,


-- ** getNetworkMetered #method:getNetworkMetered#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NetworkMonitorGetNetworkMeteredMethodInfo,
#endif
    networkMonitorGetNetworkMetered         ,




 -- * Properties
-- ** connectivity #attr:connectivity#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NetworkMonitorConnectivityPropertyInfo  ,
#endif
    getNetworkMonitorConnectivity           ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    networkMonitorConnectivity              ,
#endif


-- ** networkAvailable #attr:networkAvailable#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NetworkMonitorNetworkAvailablePropertyInfo,
#endif
    getNetworkMonitorNetworkAvailable       ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    networkMonitorNetworkAvailable          ,
#endif


-- ** networkMetered #attr:networkMetered#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NetworkMonitorNetworkMeteredPropertyInfo,
#endif
    getNetworkMonitorNetworkMetered         ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    networkMonitorNetworkMetered            ,
#endif




 -- * Signals
-- ** networkChanged #signal:networkChanged#
    C_NetworkMonitorNetworkChangedCallback  ,
    NetworkMonitorNetworkChangedCallback    ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NetworkMonitorNetworkChangedSignalInfo  ,
#endif
    afterNetworkMonitorNetworkChanged       ,
    genClosure_NetworkMonitorNetworkChanged ,
    mk_NetworkMonitorNetworkChangedCallback ,
    noNetworkMonitorNetworkChangedCallback  ,
    onNetworkMonitorNetworkChanged          ,
    wrap_NetworkMonitorNetworkChangedCallback,




    ) 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.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Callbacks as Gio.Callbacks
import {-# SOURCE #-} qualified GI.Gio.Enums as Gio.Enums
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.Interfaces.SocketConnectable as Gio.SocketConnectable
import {-# SOURCE #-} qualified GI.Gio.Objects.Cancellable as Gio.Cancellable

-- interface NetworkMonitor 
newtype NetworkMonitor = NetworkMonitor (ManagedPtr NetworkMonitor)
noNetworkMonitor :: Maybe NetworkMonitor
noNetworkMonitor = Nothing

-- signal NetworkMonitor::network-changed
type NetworkMonitorNetworkChangedCallback =
    Bool ->
    IO ()

noNetworkMonitorNetworkChangedCallback :: Maybe NetworkMonitorNetworkChangedCallback
noNetworkMonitorNetworkChangedCallback = Nothing

type C_NetworkMonitorNetworkChangedCallback =
    Ptr () ->                               -- object
    CInt ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_NetworkMonitorNetworkChangedCallback :: C_NetworkMonitorNetworkChangedCallback -> IO (FunPtr C_NetworkMonitorNetworkChangedCallback)

genClosure_NetworkMonitorNetworkChanged :: NetworkMonitorNetworkChangedCallback -> IO Closure
genClosure_NetworkMonitorNetworkChanged cb = do
    let cb' = wrap_NetworkMonitorNetworkChangedCallback cb
    mk_NetworkMonitorNetworkChangedCallback cb' >>= newCClosure


wrap_NetworkMonitorNetworkChangedCallback ::
    NetworkMonitorNetworkChangedCallback ->
    Ptr () ->
    CInt ->
    Ptr () ->
    IO ()
wrap_NetworkMonitorNetworkChangedCallback _cb _ available _ = do
    let available' = (/= 0) available
    _cb  available'


onNetworkMonitorNetworkChanged :: (IsNetworkMonitor a, MonadIO m) => a -> NetworkMonitorNetworkChangedCallback -> m SignalHandlerId
onNetworkMonitorNetworkChanged obj cb = liftIO $ do
    let cb' = wrap_NetworkMonitorNetworkChangedCallback cb
    cb'' <- mk_NetworkMonitorNetworkChangedCallback cb'
    connectSignalFunPtr obj "network-changed" cb'' SignalConnectBefore

afterNetworkMonitorNetworkChanged :: (IsNetworkMonitor a, MonadIO m) => a -> NetworkMonitorNetworkChangedCallback -> m SignalHandlerId
afterNetworkMonitorNetworkChanged obj cb = liftIO $ do
    let cb' = wrap_NetworkMonitorNetworkChangedCallback cb
    cb'' <- mk_NetworkMonitorNetworkChangedCallback cb'
    connectSignalFunPtr obj "network-changed" cb'' SignalConnectAfter


#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NetworkMonitorNetworkChangedSignalInfo
instance SignalInfo NetworkMonitorNetworkChangedSignalInfo where
    type HaskellCallbackType NetworkMonitorNetworkChangedSignalInfo = NetworkMonitorNetworkChangedCallback
    connectSignal _ obj cb connectMode = do
        let cb' = wrap_NetworkMonitorNetworkChangedCallback cb
        cb'' <- mk_NetworkMonitorNetworkChangedCallback cb'
        connectSignalFunPtr obj "network-changed" cb'' connectMode

type instance O.SignalList NetworkMonitor = NetworkMonitorSignalList
type NetworkMonitorSignalList = ('[ '("networkChanged", NetworkMonitorNetworkChangedSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

foreign import ccall "g_network_monitor_get_type"
    c_g_network_monitor_get_type :: IO GType

instance GObject NetworkMonitor where
    gobjectType _ = c_g_network_monitor_get_type
    

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

toNetworkMonitor :: (MonadIO m, IsNetworkMonitor o) => o -> m NetworkMonitor
toNetworkMonitor = liftIO . unsafeCastTo NetworkMonitor

-- VVV Prop "connectivity"
   -- Type: TInterface (Name {namespace = "Gio", name = "NetworkConnectivity"})
   -- Flags: [PropertyReadable]
   -- Nullable: (Just False,Nothing)

getNetworkMonitorConnectivity :: (MonadIO m, IsNetworkMonitor o) => o -> m Gio.Enums.NetworkConnectivity
getNetworkMonitorConnectivity obj = liftIO $ getObjectPropertyEnum obj "connectivity"

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NetworkMonitorConnectivityPropertyInfo
instance AttrInfo NetworkMonitorConnectivityPropertyInfo where
    type AttrAllowedOps NetworkMonitorConnectivityPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint NetworkMonitorConnectivityPropertyInfo = (~) ()
    type AttrBaseTypeConstraint NetworkMonitorConnectivityPropertyInfo = IsNetworkMonitor
    type AttrGetType NetworkMonitorConnectivityPropertyInfo = Gio.Enums.NetworkConnectivity
    type AttrLabel NetworkMonitorConnectivityPropertyInfo = "connectivity"
    type AttrOrigin NetworkMonitorConnectivityPropertyInfo = NetworkMonitor
    attrGet _ = getNetworkMonitorConnectivity
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined
#endif

-- VVV Prop "network-available"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable]
   -- Nullable: (Just False,Nothing)

getNetworkMonitorNetworkAvailable :: (MonadIO m, IsNetworkMonitor o) => o -> m Bool
getNetworkMonitorNetworkAvailable obj = liftIO $ getObjectPropertyBool obj "network-available"

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NetworkMonitorNetworkAvailablePropertyInfo
instance AttrInfo NetworkMonitorNetworkAvailablePropertyInfo where
    type AttrAllowedOps NetworkMonitorNetworkAvailablePropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint NetworkMonitorNetworkAvailablePropertyInfo = (~) ()
    type AttrBaseTypeConstraint NetworkMonitorNetworkAvailablePropertyInfo = IsNetworkMonitor
    type AttrGetType NetworkMonitorNetworkAvailablePropertyInfo = Bool
    type AttrLabel NetworkMonitorNetworkAvailablePropertyInfo = "network-available"
    type AttrOrigin NetworkMonitorNetworkAvailablePropertyInfo = NetworkMonitor
    attrGet _ = getNetworkMonitorNetworkAvailable
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined
#endif

-- VVV Prop "network-metered"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable]
   -- Nullable: (Just False,Nothing)

getNetworkMonitorNetworkMetered :: (MonadIO m, IsNetworkMonitor o) => o -> m Bool
getNetworkMonitorNetworkMetered obj = liftIO $ getObjectPropertyBool obj "network-metered"

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NetworkMonitorNetworkMeteredPropertyInfo
instance AttrInfo NetworkMonitorNetworkMeteredPropertyInfo where
    type AttrAllowedOps NetworkMonitorNetworkMeteredPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint NetworkMonitorNetworkMeteredPropertyInfo = (~) ()
    type AttrBaseTypeConstraint NetworkMonitorNetworkMeteredPropertyInfo = IsNetworkMonitor
    type AttrGetType NetworkMonitorNetworkMeteredPropertyInfo = Bool
    type AttrLabel NetworkMonitorNetworkMeteredPropertyInfo = "network-metered"
    type AttrOrigin NetworkMonitorNetworkMeteredPropertyInfo = NetworkMonitor
    attrGet _ = getNetworkMonitorNetworkMetered
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined
#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList NetworkMonitor
type instance O.AttributeList NetworkMonitor = NetworkMonitorAttributeList
type NetworkMonitorAttributeList = ('[ '("connectivity", NetworkMonitorConnectivityPropertyInfo), '("networkAvailable", NetworkMonitorNetworkAvailablePropertyInfo), '("networkMetered", NetworkMonitorNetworkMeteredPropertyInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
networkMonitorConnectivity :: AttrLabelProxy "connectivity"
networkMonitorConnectivity = AttrLabelProxy

networkMonitorNetworkAvailable :: AttrLabelProxy "networkAvailable"
networkMonitorNetworkAvailable = AttrLabelProxy

networkMonitorNetworkMetered :: AttrLabelProxy "networkMetered"
networkMonitorNetworkMetered = AttrLabelProxy

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveNetworkMonitorMethod (t :: Symbol) (o :: *) :: * where
    ResolveNetworkMonitorMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveNetworkMonitorMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveNetworkMonitorMethod "canReach" o = NetworkMonitorCanReachMethodInfo
    ResolveNetworkMonitorMethod "canReachAsync" o = NetworkMonitorCanReachAsyncMethodInfo
    ResolveNetworkMonitorMethod "canReachFinish" o = NetworkMonitorCanReachFinishMethodInfo
    ResolveNetworkMonitorMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveNetworkMonitorMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveNetworkMonitorMethod "init" o = Gio.Initable.InitableInitMethodInfo
    ResolveNetworkMonitorMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveNetworkMonitorMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveNetworkMonitorMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveNetworkMonitorMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveNetworkMonitorMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveNetworkMonitorMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveNetworkMonitorMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveNetworkMonitorMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveNetworkMonitorMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveNetworkMonitorMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveNetworkMonitorMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveNetworkMonitorMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveNetworkMonitorMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveNetworkMonitorMethod "getConnectivity" o = NetworkMonitorGetConnectivityMethodInfo
    ResolveNetworkMonitorMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveNetworkMonitorMethod "getNetworkAvailable" o = NetworkMonitorGetNetworkAvailableMethodInfo
    ResolveNetworkMonitorMethod "getNetworkMetered" o = NetworkMonitorGetNetworkMeteredMethodInfo
    ResolveNetworkMonitorMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveNetworkMonitorMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveNetworkMonitorMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveNetworkMonitorMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveNetworkMonitorMethod l o = O.MethodResolutionFailed l o

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

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

#endif

-- method NetworkMonitor::can_reach
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "monitor", argType = TInterface (Name {namespace = "Gio", name = "NetworkMonitor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GNetworkMonitor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "connectable", argType = TInterface (Name {namespace = "Gio", name = "SocketConnectable"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketConnectable", 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}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_network_monitor_can_reach" g_network_monitor_can_reach :: 
    Ptr NetworkMonitor ->                   -- monitor : TInterface (Name {namespace = "Gio", name = "NetworkMonitor"})
    Ptr Gio.SocketConnectable.SocketConnectable -> -- connectable : TInterface (Name {namespace = "Gio", name = "SocketConnectable"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Attempts to determine whether or not the host pointed to by
/@connectable@/ can be reached, without actually trying to connect to
it.

This may return 'True' even when 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor':@/network-available/@
is 'False', if, for example, /@monitor@/ can determine that
/@connectable@/ refers to a host on a local network.

If /@monitor@/ believes that an attempt to connect to /@connectable@/
will succeed, it will return 'True'. Otherwise, it will return
'False' and set /@error@/ to an appropriate error (such as
'GI.Gio.Enums.IOErrorEnumHostUnreachable').

Note that although this does not attempt to connect to
/@connectable@/, it may still block for a brief period of time (eg,
trying to do multicast DNS on the local network), so if you do not
want to block, you should use 'GI.Gio.Interfaces.NetworkMonitor.networkMonitorCanReachAsync'.

@since 2.32
-}
networkMonitorCanReach ::
    (B.CallStack.HasCallStack, MonadIO m, IsNetworkMonitor a, Gio.SocketConnectable.IsSocketConnectable b, Gio.Cancellable.IsCancellable c) =>
    a
    {- ^ /@monitor@/: a 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor' -}
    -> b
    {- ^ /@connectable@/: a 'GI.Gio.Interfaces.SocketConnectable.SocketConnectable' -}
    -> Maybe (c)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
networkMonitorCanReach monitor connectable cancellable = liftIO $ do
    monitor' <- unsafeManagedPtrCastPtr monitor
    connectable' <- unsafeManagedPtrCastPtr connectable
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    onException (do
        _ <- propagateGError $ g_network_monitor_can_reach monitor' connectable' maybeCancellable
        touchManagedPtr monitor
        touchManagedPtr connectable
        whenJust cancellable touchManagedPtr
        return ()
     ) (do
        return ()
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NetworkMonitorCanReachMethodInfo
instance (signature ~ (b -> Maybe (c) -> m ()), MonadIO m, IsNetworkMonitor a, Gio.SocketConnectable.IsSocketConnectable b, Gio.Cancellable.IsCancellable c) => O.MethodInfo NetworkMonitorCanReachMethodInfo a signature where
    overloadedMethod _ = networkMonitorCanReach

#endif

-- method NetworkMonitor::can_reach_async
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "monitor", argType = TInterface (Name {namespace = "Gio", name = "NetworkMonitor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GNetworkMonitor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "connectable", argType = TInterface (Name {namespace = "Gio", name = "SocketConnectable"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketConnectable", 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\n    request is satisfied", 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 "the data to pass to callback function", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_network_monitor_can_reach_async" g_network_monitor_can_reach_async :: 
    Ptr NetworkMonitor ->                   -- monitor : TInterface (Name {namespace = "Gio", name = "NetworkMonitor"})
    Ptr Gio.SocketConnectable.SocketConnectable -> -- connectable : TInterface (Name {namespace = "Gio", name = "SocketConnectable"})
    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 ()

{- |
Asynchronously attempts to determine whether or not the host
pointed to by /@connectable@/ can be reached, without actually
trying to connect to it.

For more details, see 'GI.Gio.Interfaces.NetworkMonitor.networkMonitorCanReach'.

When the operation is finished, /@callback@/ will be called.
You can then call 'GI.Gio.Interfaces.NetworkMonitor.networkMonitorCanReachFinish'
to get the result of the operation.
-}
networkMonitorCanReachAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsNetworkMonitor a, Gio.SocketConnectable.IsSocketConnectable b, Gio.Cancellable.IsCancellable c) =>
    a
    {- ^ /@monitor@/: a 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor' -}
    -> b
    {- ^ /@connectable@/: a 'GI.Gio.Interfaces.SocketConnectable.SocketConnectable' -}
    -> Maybe (c)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: a 'GI.Gio.Callbacks.AsyncReadyCallback' to call when the
    request is satisfied -}
    -> m ()
networkMonitorCanReachAsync monitor connectable cancellable callback = liftIO $ do
    monitor' <- unsafeManagedPtrCastPtr monitor
    connectable' <- unsafeManagedPtrCastPtr connectable
    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_network_monitor_can_reach_async monitor' connectable' maybeCancellable maybeCallback userData
    touchManagedPtr monitor
    touchManagedPtr connectable
    whenJust cancellable touchManagedPtr
    return ()

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NetworkMonitorCanReachAsyncMethodInfo
instance (signature ~ (b -> Maybe (c) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsNetworkMonitor a, Gio.SocketConnectable.IsSocketConnectable b, Gio.Cancellable.IsCancellable c) => O.MethodInfo NetworkMonitorCanReachAsyncMethodInfo a signature where
    overloadedMethod _ = networkMonitorCanReachAsync

#endif

-- method NetworkMonitor::can_reach_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "monitor", argType = TInterface (Name {namespace = "Gio", name = "NetworkMonitor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GNetworkMonitor", 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 "a #GAsyncResult", 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_network_monitor_can_reach_finish" g_network_monitor_can_reach_finish :: 
    Ptr NetworkMonitor ->                   -- monitor : TInterface (Name {namespace = "Gio", name = "NetworkMonitor"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Finishes an async network connectivity test.
See 'GI.Gio.Interfaces.NetworkMonitor.networkMonitorCanReachAsync'.
-}
networkMonitorCanReachFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsNetworkMonitor a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    {- ^ /@monitor@/: a 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor' -}
    -> b
    {- ^ /@result@/: a 'GI.Gio.Interfaces.AsyncResult.AsyncResult' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
networkMonitorCanReachFinish monitor result_ = liftIO $ do
    monitor' <- unsafeManagedPtrCastPtr monitor
    result_' <- unsafeManagedPtrCastPtr result_
    onException (do
        _ <- propagateGError $ g_network_monitor_can_reach_finish monitor' result_'
        touchManagedPtr monitor
        touchManagedPtr result_
        return ()
     ) (do
        return ()
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NetworkMonitorCanReachFinishMethodInfo
instance (signature ~ (b -> m ()), MonadIO m, IsNetworkMonitor a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo NetworkMonitorCanReachFinishMethodInfo a signature where
    overloadedMethod _ = networkMonitorCanReachFinish

#endif

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

foreign import ccall "g_network_monitor_get_connectivity" g_network_monitor_get_connectivity :: 
    Ptr NetworkMonitor ->                   -- monitor : TInterface (Name {namespace = "Gio", name = "NetworkMonitor"})
    IO CUInt

{- |
Gets a more detailed networking state than
'GI.Gio.Interfaces.NetworkMonitor.networkMonitorGetNetworkAvailable'.

If 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor':@/network-available/@ is 'False', then the
connectivity state will be 'GI.Gio.Enums.NetworkConnectivityLocal'.

If 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor':@/network-available/@ is 'True', then the
connectivity state will be 'GI.Gio.Enums.NetworkConnectivityFull' (if there
is full Internet connectivity), 'GI.Gio.Enums.NetworkConnectivityLimited' (if
the host has a default route, but appears to be unable to actually
reach the full Internet), or 'GI.Gio.Enums.NetworkConnectivityPortal' (if the
host is trapped behind a \"captive portal\" that requires some sort
of login or acknowledgement before allowing full Internet access).

Note that in the case of 'GI.Gio.Enums.NetworkConnectivityLimited' and
'GI.Gio.Enums.NetworkConnectivityPortal', it is possible that some sites are
reachable but others are not. In this case, applications can
attempt to connect to remote servers, but should gracefully fall
back to their \"offline\" behavior if the connection attempt fails.

@since 2.44
-}
networkMonitorGetConnectivity ::
    (B.CallStack.HasCallStack, MonadIO m, IsNetworkMonitor a) =>
    a
    {- ^ /@monitor@/: the 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor' -}
    -> m Gio.Enums.NetworkConnectivity
    {- ^ __Returns:__ the network connectivity state -}
networkMonitorGetConnectivity monitor = liftIO $ do
    monitor' <- unsafeManagedPtrCastPtr monitor
    result <- g_network_monitor_get_connectivity monitor'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr monitor
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NetworkMonitorGetConnectivityMethodInfo
instance (signature ~ (m Gio.Enums.NetworkConnectivity), MonadIO m, IsNetworkMonitor a) => O.MethodInfo NetworkMonitorGetConnectivityMethodInfo a signature where
    overloadedMethod _ = networkMonitorGetConnectivity

#endif

-- method NetworkMonitor::get_network_available
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "monitor", argType = TInterface (Name {namespace = "Gio", name = "NetworkMonitor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GNetworkMonitor", 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_network_monitor_get_network_available" g_network_monitor_get_network_available :: 
    Ptr NetworkMonitor ->                   -- monitor : TInterface (Name {namespace = "Gio", name = "NetworkMonitor"})
    IO CInt

{- |
Checks if the network is available. \"Available\" here means that the
system has a default route available for at least one of IPv4 or
IPv6. It does not necessarily imply that the public Internet is
reachable. See 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor':@/network-available/@ for more details.

@since 2.32
-}
networkMonitorGetNetworkAvailable ::
    (B.CallStack.HasCallStack, MonadIO m, IsNetworkMonitor a) =>
    a
    {- ^ /@monitor@/: the 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor' -}
    -> m Bool
    {- ^ __Returns:__ whether the network is available -}
networkMonitorGetNetworkAvailable monitor = liftIO $ do
    monitor' <- unsafeManagedPtrCastPtr monitor
    result <- g_network_monitor_get_network_available monitor'
    let result' = (/= 0) result
    touchManagedPtr monitor
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NetworkMonitorGetNetworkAvailableMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsNetworkMonitor a) => O.MethodInfo NetworkMonitorGetNetworkAvailableMethodInfo a signature where
    overloadedMethod _ = networkMonitorGetNetworkAvailable

#endif

-- method NetworkMonitor::get_network_metered
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "monitor", argType = TInterface (Name {namespace = "Gio", name = "NetworkMonitor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GNetworkMonitor", 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_network_monitor_get_network_metered" g_network_monitor_get_network_metered :: 
    Ptr NetworkMonitor ->                   -- monitor : TInterface (Name {namespace = "Gio", name = "NetworkMonitor"})
    IO CInt

{- |
Checks if the network is metered.
See 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor':@/network-metered/@ for more details.

@since 2.46
-}
networkMonitorGetNetworkMetered ::
    (B.CallStack.HasCallStack, MonadIO m, IsNetworkMonitor a) =>
    a
    {- ^ /@monitor@/: the 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor' -}
    -> m Bool
    {- ^ __Returns:__ whether the connection is metered -}
networkMonitorGetNetworkMetered monitor = liftIO $ do
    monitor' <- unsafeManagedPtrCastPtr monitor
    result <- g_network_monitor_get_network_metered monitor'
    let result' = (/= 0) result
    touchManagedPtr monitor
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NetworkMonitorGetNetworkMeteredMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsNetworkMonitor a) => O.MethodInfo NetworkMonitorGetNetworkMeteredMethodInfo a signature where
    overloadedMethod _ = networkMonitorGetNetworkMetered

#endif

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

foreign import ccall "g_network_monitor_get_default" g_network_monitor_get_default :: 
    IO (Ptr NetworkMonitor)

{- |
Gets the default 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor' for the system.

@since 2.32
-}
networkMonitorGetDefault ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m NetworkMonitor
    {- ^ __Returns:__ a 'GI.Gio.Interfaces.NetworkMonitor.NetworkMonitor' -}
networkMonitorGetDefault  = liftIO $ do
    result <- g_network_monitor_get_default
    checkUnexpectedReturnNULL "networkMonitorGetDefault" result
    result' <- (newObject NetworkMonitor) result
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#endif