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

The 'GI.Gio.Interfaces.DBusInterface.DBusInterface' type is the base type for D-Bus interfaces both
on the service side (see 'GI.Gio.Objects.DBusInterfaceSkeleton.DBusInterfaceSkeleton') and client side
(see 'GI.Gio.Objects.DBusProxy.DBusProxy').
-}

module GI.Gio.Interfaces.DBusInterface
    ( 

-- * Exported types
    DBusInterface(..)                       ,
    noDBusInterface                         ,
    IsDBusInterface                         ,
    toDBusInterface                         ,


 -- * Methods
-- ** getInfo #method:getInfo#
    DBusInterfaceGetInfoMethodInfo          ,
    dBusInterfaceGetInfo                    ,


-- ** getObject #method:getObject#
    DBusInterfaceGetObjectMethodInfo        ,
    dBusInterfaceGetObject                  ,


-- ** setObject #method:setObject#
    DBusInterfaceSetObjectMethodInfo        ,
    dBusInterfaceSetObject                  ,




    ) 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 {-# SOURCE #-} qualified GI.Gio.Interfaces.DBusObject as Gio.DBusObject
import {-# SOURCE #-} qualified GI.Gio.Structs.DBusInterfaceInfo as Gio.DBusInterfaceInfo

-- interface DBusInterface 
newtype DBusInterface = DBusInterface (ManagedPtr DBusInterface)
noDBusInterface :: Maybe DBusInterface
noDBusInterface = Nothing

type family ResolveDBusInterfaceMethod (t :: Symbol) (o :: *) :: * where
    ResolveDBusInterfaceMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveDBusInterfaceMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveDBusInterfaceMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveDBusInterfaceMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveDBusInterfaceMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveDBusInterfaceMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveDBusInterfaceMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveDBusInterfaceMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveDBusInterfaceMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveDBusInterfaceMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveDBusInterfaceMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveDBusInterfaceMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveDBusInterfaceMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveDBusInterfaceMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveDBusInterfaceMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveDBusInterfaceMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveDBusInterfaceMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveDBusInterfaceMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveDBusInterfaceMethod "getInfo" o = DBusInterfaceGetInfoMethodInfo
    ResolveDBusInterfaceMethod "getObject" o = DBusInterfaceGetObjectMethodInfo
    ResolveDBusInterfaceMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveDBusInterfaceMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveDBusInterfaceMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveDBusInterfaceMethod "setObject" o = DBusInterfaceSetObjectMethodInfo
    ResolveDBusInterfaceMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveDBusInterfaceMethod l o = O.MethodResolutionFailed l o

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

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

instance O.HasAttributeList DBusInterface
type instance O.AttributeList DBusInterface = DBusInterfaceAttributeList
type DBusInterfaceAttributeList = ('[ ] :: [(Symbol, *)])

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

foreign import ccall "g_dbus_interface_get_type"
    c_g_dbus_interface_get_type :: IO GType

instance GObject DBusInterface where
    gobjectType _ = c_g_dbus_interface_get_type
    

class GObject o => IsDBusInterface o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError DBusInterface a) =>
    IsDBusInterface a
#endif
instance IsDBusInterface DBusInterface
instance GObject.Object.IsObject DBusInterface

toDBusInterface :: IsDBusInterface o => o -> IO DBusInterface
toDBusInterface = unsafeCastTo DBusInterface

-- method DBusInterface::get_object
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "interface_", argType = TInterface (Name {namespace = "Gio", name = "DBusInterface"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "An exported D-Bus interface.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "DBusObject"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_dbus_interface_dup_object" g_dbus_interface_dup_object :: 
    Ptr DBusInterface ->                    -- interface_ : TInterface (Name {namespace = "Gio", name = "DBusInterface"})
    IO (Ptr Gio.DBusObject.DBusObject)

{- |
Gets the 'GI.Gio.Interfaces.DBusObject.DBusObject' that /@interface_@/ belongs to, if any.

@since 2.32
-}
dBusInterfaceGetObject ::
    (B.CallStack.HasCallStack, MonadIO m, IsDBusInterface a) =>
    a
    {- ^ /@interface_@/: An exported D-Bus interface. -}
    -> m Gio.DBusObject.DBusObject
    {- ^ __Returns:__ A 'GI.Gio.Interfaces.DBusObject.DBusObject' or 'Nothing'. The returned
reference should be freed with 'GI.GObject.Objects.Object.objectUnref'. -}
dBusInterfaceGetObject interface_ = liftIO $ do
    interface_' <- unsafeManagedPtrCastPtr interface_
    result <- g_dbus_interface_dup_object interface_'
    checkUnexpectedReturnNULL "dBusInterfaceGetObject" result
    result' <- (wrapObject Gio.DBusObject.DBusObject) result
    touchManagedPtr interface_
    return result'

data DBusInterfaceGetObjectMethodInfo
instance (signature ~ (m Gio.DBusObject.DBusObject), MonadIO m, IsDBusInterface a) => O.MethodInfo DBusInterfaceGetObjectMethodInfo a signature where
    overloadedMethod _ = dBusInterfaceGetObject

-- method DBusInterface::get_info
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "interface_", argType = TInterface (Name {namespace = "Gio", name = "DBusInterface"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "An exported D-Bus interface.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "DBusInterfaceInfo"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_dbus_interface_get_info" g_dbus_interface_get_info :: 
    Ptr DBusInterface ->                    -- interface_ : TInterface (Name {namespace = "Gio", name = "DBusInterface"})
    IO (Ptr Gio.DBusInterfaceInfo.DBusInterfaceInfo)

{- |
Gets D-Bus introspection information for the D-Bus interface
implemented by /@interface_@/.

@since 2.30
-}
dBusInterfaceGetInfo ::
    (B.CallStack.HasCallStack, MonadIO m, IsDBusInterface a) =>
    a
    {- ^ /@interface_@/: An exported D-Bus interface. -}
    -> m Gio.DBusInterfaceInfo.DBusInterfaceInfo
    {- ^ __Returns:__ A 'GI.Gio.Structs.DBusInterfaceInfo.DBusInterfaceInfo'. Do not free. -}
dBusInterfaceGetInfo interface_ = liftIO $ do
    interface_' <- unsafeManagedPtrCastPtr interface_
    result <- g_dbus_interface_get_info interface_'
    checkUnexpectedReturnNULL "dBusInterfaceGetInfo" result
    result' <- (newBoxed Gio.DBusInterfaceInfo.DBusInterfaceInfo) result
    touchManagedPtr interface_
    return result'

data DBusInterfaceGetInfoMethodInfo
instance (signature ~ (m Gio.DBusInterfaceInfo.DBusInterfaceInfo), MonadIO m, IsDBusInterface a) => O.MethodInfo DBusInterfaceGetInfoMethodInfo a signature where
    overloadedMethod _ = dBusInterfaceGetInfo

-- method DBusInterface::set_object
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "interface_", argType = TInterface (Name {namespace = "Gio", name = "DBusInterface"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "An exported D-Bus interface.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "object", argType = TInterface (Name {namespace = "Gio", name = "DBusObject"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "A #GDBusObject or %NULL.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_dbus_interface_set_object" g_dbus_interface_set_object :: 
    Ptr DBusInterface ->                    -- interface_ : TInterface (Name {namespace = "Gio", name = "DBusInterface"})
    Ptr Gio.DBusObject.DBusObject ->        -- object : TInterface (Name {namespace = "Gio", name = "DBusObject"})
    IO ()

{- |
Sets the 'GI.Gio.Interfaces.DBusObject.DBusObject' for /@interface_@/ to /@object@/.

Note that /@interface_@/ will hold a weak reference to /@object@/.

@since 2.30
-}
dBusInterfaceSetObject ::
    (B.CallStack.HasCallStack, MonadIO m, IsDBusInterface a, Gio.DBusObject.IsDBusObject b) =>
    a
    {- ^ /@interface_@/: An exported D-Bus interface. -}
    -> Maybe (b)
    {- ^ /@object@/: A 'GI.Gio.Interfaces.DBusObject.DBusObject' or 'Nothing'. -}
    -> m ()
dBusInterfaceSetObject interface_ object = liftIO $ do
    interface_' <- unsafeManagedPtrCastPtr interface_
    maybeObject <- case object of
        Nothing -> return nullPtr
        Just jObject -> do
            jObject' <- unsafeManagedPtrCastPtr jObject
            return jObject'
    g_dbus_interface_set_object interface_' maybeObject
    touchManagedPtr interface_
    whenJust object touchManagedPtr
    return ()

data DBusInterfaceSetObjectMethodInfo
instance (signature ~ (Maybe (b) -> m ()), MonadIO m, IsDBusInterface a, Gio.DBusObject.IsDBusObject b) => O.MethodInfo DBusInterfaceSetObjectMethodInfo a signature where
    overloadedMethod _ = dBusInterfaceSetObject