{- |
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.DBusServer.DBusServer' is a helper for listening to and accepting D-Bus
connections. This can be used to create a new D-Bus server, allowing two
peers to use the D-Bus protocol for their own specialized communication.
A server instance provided in this way will not perform message routing or
implement the org.freedesktop.DBus interface.

To just export an object on a well-known name on a message bus, such as the
session or system bus, you should instead use @/g_bus_own_name()/@.

An example of peer-to-peer communication with G-DBus can be found
in <https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-peer.c gdbus-example-peer.c>.
-}

module GI.Gio.Objects.DBusServer
    ( 

-- * Exported types
    DBusServer(..)                          ,
    IsDBusServer                            ,
    toDBusServer                            ,
    noDBusServer                            ,


 -- * Methods
-- ** getClientAddress #method:getClientAddress#
    DBusServerGetClientAddressMethodInfo    ,
    dBusServerGetClientAddress              ,


-- ** getFlags #method:getFlags#
    DBusServerGetFlagsMethodInfo            ,
    dBusServerGetFlags                      ,


-- ** getGuid #method:getGuid#
    DBusServerGetGuidMethodInfo             ,
    dBusServerGetGuid                       ,


-- ** isActive #method:isActive#
    DBusServerIsActiveMethodInfo            ,
    dBusServerIsActive                      ,


-- ** newSync #method:newSync#
    dBusServerNewSync                       ,


-- ** start #method:start#
    DBusServerStartMethodInfo               ,
    dBusServerStart                         ,


-- ** stop #method:stop#
    DBusServerStopMethodInfo                ,
    dBusServerStop                          ,




 -- * Properties
-- ** active #attr:active#
    DBusServerActivePropertyInfo            ,
    dBusServerActive                        ,
    getDBusServerActive                     ,


-- ** address #attr:address#
    DBusServerAddressPropertyInfo           ,
    constructDBusServerAddress              ,
    dBusServerAddress                       ,
    getDBusServerAddress                    ,


-- ** authenticationObserver #attr:authenticationObserver#
    DBusServerAuthenticationObserverPropertyInfo,
    constructDBusServerAuthenticationObserver,
    dBusServerAuthenticationObserver        ,
    getDBusServerAuthenticationObserver     ,


-- ** clientAddress #attr:clientAddress#
    DBusServerClientAddressPropertyInfo     ,
    dBusServerClientAddress                 ,
    getDBusServerClientAddress              ,


-- ** flags #attr:flags#
    DBusServerFlagsPropertyInfo             ,
    constructDBusServerFlags                ,
    dBusServerFlags                         ,
    getDBusServerFlags                      ,


-- ** guid #attr:guid#
    DBusServerGuidPropertyInfo              ,
    constructDBusServerGuid                 ,
    dBusServerGuid                          ,
    getDBusServerGuid                       ,




 -- * Signals
-- ** newConnection #signal:newConnection#
    C_DBusServerNewConnectionCallback       ,
    DBusServerNewConnectionCallback         ,
    DBusServerNewConnectionSignalInfo       ,
    afterDBusServerNewConnection            ,
    genClosure_DBusServerNewConnection      ,
    mk_DBusServerNewConnectionCallback      ,
    noDBusServerNewConnectionCallback       ,
    onDBusServerNewConnection               ,
    wrap_DBusServerNewConnectionCallback    ,




    ) 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.Flags as Gio.Flags
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.DBusAuthObserver as Gio.DBusAuthObserver
import {-# SOURCE #-} qualified GI.Gio.Objects.DBusConnection as Gio.DBusConnection

newtype DBusServer = DBusServer (ManagedPtr DBusServer)
foreign import ccall "g_dbus_server_get_type"
    c_g_dbus_server_get_type :: IO GType

instance GObject DBusServer where
    gobjectType _ = c_g_dbus_server_get_type
    

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

toDBusServer :: IsDBusServer o => o -> IO DBusServer
toDBusServer = unsafeCastTo DBusServer

noDBusServer :: Maybe DBusServer
noDBusServer = Nothing

type family ResolveDBusServerMethod (t :: Symbol) (o :: *) :: * where
    ResolveDBusServerMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveDBusServerMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveDBusServerMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveDBusServerMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveDBusServerMethod "init" o = Gio.Initable.InitableInitMethodInfo
    ResolveDBusServerMethod "isActive" o = DBusServerIsActiveMethodInfo
    ResolveDBusServerMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveDBusServerMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveDBusServerMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveDBusServerMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveDBusServerMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveDBusServerMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveDBusServerMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveDBusServerMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveDBusServerMethod "start" o = DBusServerStartMethodInfo
    ResolveDBusServerMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveDBusServerMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveDBusServerMethod "stop" o = DBusServerStopMethodInfo
    ResolveDBusServerMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveDBusServerMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveDBusServerMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveDBusServerMethod "getClientAddress" o = DBusServerGetClientAddressMethodInfo
    ResolveDBusServerMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveDBusServerMethod "getFlags" o = DBusServerGetFlagsMethodInfo
    ResolveDBusServerMethod "getGuid" o = DBusServerGetGuidMethodInfo
    ResolveDBusServerMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveDBusServerMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveDBusServerMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveDBusServerMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveDBusServerMethod l o = O.MethodResolutionFailed l o

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

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

-- signal DBusServer::new-connection
type DBusServerNewConnectionCallback =
    Gio.DBusConnection.DBusConnection ->
    IO Bool

noDBusServerNewConnectionCallback :: Maybe DBusServerNewConnectionCallback
noDBusServerNewConnectionCallback = Nothing

type C_DBusServerNewConnectionCallback =
    Ptr () ->                               -- object
    Ptr Gio.DBusConnection.DBusConnection ->
    Ptr () ->                               -- user_data
    IO CInt

foreign import ccall "wrapper"
    mk_DBusServerNewConnectionCallback :: C_DBusServerNewConnectionCallback -> IO (FunPtr C_DBusServerNewConnectionCallback)

genClosure_DBusServerNewConnection :: DBusServerNewConnectionCallback -> IO Closure
genClosure_DBusServerNewConnection cb = do
    let cb' = wrap_DBusServerNewConnectionCallback cb
    mk_DBusServerNewConnectionCallback cb' >>= newCClosure


wrap_DBusServerNewConnectionCallback ::
    DBusServerNewConnectionCallback ->
    Ptr () ->
    Ptr Gio.DBusConnection.DBusConnection ->
    Ptr () ->
    IO CInt
wrap_DBusServerNewConnectionCallback _cb _ connection _ = do
    connection' <- (newObject Gio.DBusConnection.DBusConnection) connection
    result <- _cb  connection'
    let result' = (fromIntegral . fromEnum) result
    return result'


onDBusServerNewConnection :: (GObject a, MonadIO m) => a -> DBusServerNewConnectionCallback -> m SignalHandlerId
onDBusServerNewConnection obj cb = liftIO $ connectDBusServerNewConnection obj cb SignalConnectBefore
afterDBusServerNewConnection :: (GObject a, MonadIO m) => a -> DBusServerNewConnectionCallback -> m SignalHandlerId
afterDBusServerNewConnection obj cb = connectDBusServerNewConnection obj cb SignalConnectAfter

connectDBusServerNewConnection :: (GObject a, MonadIO m) =>
                                  a -> DBusServerNewConnectionCallback -> SignalConnectMode -> m SignalHandlerId
connectDBusServerNewConnection obj cb after = liftIO $ do
    let cb' = wrap_DBusServerNewConnectionCallback cb
    cb'' <- mk_DBusServerNewConnectionCallback cb'
    connectSignalFunPtr obj "new-connection" cb'' after

-- VVV Prop "active"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable]
   -- Nullable: (Nothing,Nothing)

getDBusServerActive :: (MonadIO m, IsDBusServer o) => o -> m Bool
getDBusServerActive obj = liftIO $ getObjectPropertyBool obj "active"

data DBusServerActivePropertyInfo
instance AttrInfo DBusServerActivePropertyInfo where
    type AttrAllowedOps DBusServerActivePropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DBusServerActivePropertyInfo = (~) ()
    type AttrBaseTypeConstraint DBusServerActivePropertyInfo = IsDBusServer
    type AttrGetType DBusServerActivePropertyInfo = Bool
    type AttrLabel DBusServerActivePropertyInfo = "active"
    type AttrOrigin DBusServerActivePropertyInfo = DBusServer
    attrGet _ = getDBusServerActive
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined

-- VVV Prop "address"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Nothing,Nothing)

getDBusServerAddress :: (MonadIO m, IsDBusServer o) => o -> m (Maybe T.Text)
getDBusServerAddress obj = liftIO $ getObjectPropertyString obj "address"

constructDBusServerAddress :: (IsDBusServer o) => T.Text -> IO (GValueConstruct o)
constructDBusServerAddress val = constructObjectPropertyString "address" (Just val)

data DBusServerAddressPropertyInfo
instance AttrInfo DBusServerAddressPropertyInfo where
    type AttrAllowedOps DBusServerAddressPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint DBusServerAddressPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint DBusServerAddressPropertyInfo = IsDBusServer
    type AttrGetType DBusServerAddressPropertyInfo = (Maybe T.Text)
    type AttrLabel DBusServerAddressPropertyInfo = "address"
    type AttrOrigin DBusServerAddressPropertyInfo = DBusServer
    attrGet _ = getDBusServerAddress
    attrSet _ = undefined
    attrConstruct _ = constructDBusServerAddress
    attrClear _ = undefined

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

getDBusServerAuthenticationObserver :: (MonadIO m, IsDBusServer o) => o -> m (Maybe Gio.DBusAuthObserver.DBusAuthObserver)
getDBusServerAuthenticationObserver obj = liftIO $ getObjectPropertyObject obj "authentication-observer" Gio.DBusAuthObserver.DBusAuthObserver

constructDBusServerAuthenticationObserver :: (IsDBusServer o, Gio.DBusAuthObserver.IsDBusAuthObserver a) => a -> IO (GValueConstruct o)
constructDBusServerAuthenticationObserver val = constructObjectPropertyObject "authentication-observer" (Just val)

data DBusServerAuthenticationObserverPropertyInfo
instance AttrInfo DBusServerAuthenticationObserverPropertyInfo where
    type AttrAllowedOps DBusServerAuthenticationObserverPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint DBusServerAuthenticationObserverPropertyInfo = Gio.DBusAuthObserver.IsDBusAuthObserver
    type AttrBaseTypeConstraint DBusServerAuthenticationObserverPropertyInfo = IsDBusServer
    type AttrGetType DBusServerAuthenticationObserverPropertyInfo = (Maybe Gio.DBusAuthObserver.DBusAuthObserver)
    type AttrLabel DBusServerAuthenticationObserverPropertyInfo = "authentication-observer"
    type AttrOrigin DBusServerAuthenticationObserverPropertyInfo = DBusServer
    attrGet _ = getDBusServerAuthenticationObserver
    attrSet _ = undefined
    attrConstruct _ = constructDBusServerAuthenticationObserver
    attrClear _ = undefined

-- VVV Prop "client-address"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]
   -- Nullable: (Just False,Nothing)

getDBusServerClientAddress :: (MonadIO m, IsDBusServer o) => o -> m T.Text
getDBusServerClientAddress obj = liftIO $ checkUnexpectedNothing "getDBusServerClientAddress" $ getObjectPropertyString obj "client-address"

data DBusServerClientAddressPropertyInfo
instance AttrInfo DBusServerClientAddressPropertyInfo where
    type AttrAllowedOps DBusServerClientAddressPropertyInfo = '[ 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint DBusServerClientAddressPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DBusServerClientAddressPropertyInfo = IsDBusServer
    type AttrGetType DBusServerClientAddressPropertyInfo = T.Text
    type AttrLabel DBusServerClientAddressPropertyInfo = "client-address"
    type AttrOrigin DBusServerClientAddressPropertyInfo = DBusServer
    attrGet _ = getDBusServerClientAddress
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined

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

getDBusServerFlags :: (MonadIO m, IsDBusServer o) => o -> m [Gio.Flags.DBusServerFlags]
getDBusServerFlags obj = liftIO $ getObjectPropertyFlags obj "flags"

constructDBusServerFlags :: (IsDBusServer o) => [Gio.Flags.DBusServerFlags] -> IO (GValueConstruct o)
constructDBusServerFlags val = constructObjectPropertyFlags "flags" val

data DBusServerFlagsPropertyInfo
instance AttrInfo DBusServerFlagsPropertyInfo where
    type AttrAllowedOps DBusServerFlagsPropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint DBusServerFlagsPropertyInfo = (~) [Gio.Flags.DBusServerFlags]
    type AttrBaseTypeConstraint DBusServerFlagsPropertyInfo = IsDBusServer
    type AttrGetType DBusServerFlagsPropertyInfo = [Gio.Flags.DBusServerFlags]
    type AttrLabel DBusServerFlagsPropertyInfo = "flags"
    type AttrOrigin DBusServerFlagsPropertyInfo = DBusServer
    attrGet _ = getDBusServerFlags
    attrSet _ = undefined
    attrConstruct _ = constructDBusServerFlags
    attrClear _ = undefined

-- VVV Prop "guid"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

getDBusServerGuid :: (MonadIO m, IsDBusServer o) => o -> m T.Text
getDBusServerGuid obj = liftIO $ checkUnexpectedNothing "getDBusServerGuid" $ getObjectPropertyString obj "guid"

constructDBusServerGuid :: (IsDBusServer o) => T.Text -> IO (GValueConstruct o)
constructDBusServerGuid val = constructObjectPropertyString "guid" (Just val)

data DBusServerGuidPropertyInfo
instance AttrInfo DBusServerGuidPropertyInfo where
    type AttrAllowedOps DBusServerGuidPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint DBusServerGuidPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint DBusServerGuidPropertyInfo = IsDBusServer
    type AttrGetType DBusServerGuidPropertyInfo = T.Text
    type AttrLabel DBusServerGuidPropertyInfo = "guid"
    type AttrOrigin DBusServerGuidPropertyInfo = DBusServer
    attrGet _ = getDBusServerGuid
    attrSet _ = undefined
    attrConstruct _ = constructDBusServerGuid
    attrClear _ = undefined

instance O.HasAttributeList DBusServer
type instance O.AttributeList DBusServer = DBusServerAttributeList
type DBusServerAttributeList = ('[ '("active", DBusServerActivePropertyInfo), '("address", DBusServerAddressPropertyInfo), '("authenticationObserver", DBusServerAuthenticationObserverPropertyInfo), '("clientAddress", DBusServerClientAddressPropertyInfo), '("flags", DBusServerFlagsPropertyInfo), '("guid", DBusServerGuidPropertyInfo)] :: [(Symbol, *)])

dBusServerActive :: AttrLabelProxy "active"
dBusServerActive = AttrLabelProxy

dBusServerAddress :: AttrLabelProxy "address"
dBusServerAddress = AttrLabelProxy

dBusServerAuthenticationObserver :: AttrLabelProxy "authenticationObserver"
dBusServerAuthenticationObserver = AttrLabelProxy

dBusServerClientAddress :: AttrLabelProxy "clientAddress"
dBusServerClientAddress = AttrLabelProxy

dBusServerFlags :: AttrLabelProxy "flags"
dBusServerFlags = AttrLabelProxy

dBusServerGuid :: AttrLabelProxy "guid"
dBusServerGuid = AttrLabelProxy

data DBusServerNewConnectionSignalInfo
instance SignalInfo DBusServerNewConnectionSignalInfo where
    type HaskellCallbackType DBusServerNewConnectionSignalInfo = DBusServerNewConnectionCallback
    connectSignal _ = connectDBusServerNewConnection

type instance O.SignalList DBusServer = DBusServerSignalList
type DBusServerSignalList = ('[ '("newConnection", DBusServerNewConnectionSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method DBusServer::new_sync
-- method type : Constructor
-- Args : [Arg {argCName = "address", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A D-Bus address.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "flags", argType = TInterface (Name {namespace = "Gio", name = "DBusServerFlags"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Flags from the #GDBusServerFlags enumeration.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "guid", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A D-Bus GUID.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "observer", argType = TInterface (Name {namespace = "Gio", name = "DBusAuthObserver"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "A #GDBusAuthObserver 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 or %NULL.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "DBusServer"}))
-- throws : True
-- Skip return : False

foreign import ccall "g_dbus_server_new_sync" g_dbus_server_new_sync :: 
    CString ->                              -- address : TBasicType TUTF8
    CUInt ->                                -- flags : TInterface (Name {namespace = "Gio", name = "DBusServerFlags"})
    CString ->                              -- guid : TBasicType TUTF8
    Ptr Gio.DBusAuthObserver.DBusAuthObserver -> -- observer : TInterface (Name {namespace = "Gio", name = "DBusAuthObserver"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr DBusServer)

{- |
Creates a new D-Bus server that listens on the first address in
/@address@/ that works.

Once constructed, you can use 'GI.Gio.Objects.DBusServer.dBusServerGetClientAddress' to
get a D-Bus address string that clients can use to connect.

Connect to the 'GI.Gio.Objects.DBusServer.DBusServer'::@/new-connection/@ signal to handle
incoming connections.

The returned 'GI.Gio.Objects.DBusServer.DBusServer' isn\'t active - you have to start it with
'GI.Gio.Objects.DBusServer.dBusServerStart'.

'GI.Gio.Objects.DBusServer.DBusServer' is used in this [example][gdbus-peer-to-peer].

This is a synchronous failable constructor. See
@/g_dbus_server_new()/@ for the asynchronous version.

@since 2.26
-}
dBusServerNewSync ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.DBusAuthObserver.IsDBusAuthObserver a, Gio.Cancellable.IsCancellable b) =>
    T.Text
    {- ^ /@address@/: A D-Bus address. -}
    -> [Gio.Flags.DBusServerFlags]
    {- ^ /@flags@/: Flags from the 'GI.Gio.Flags.DBusServerFlags' enumeration. -}
    -> T.Text
    {- ^ /@guid@/: A D-Bus GUID. -}
    -> Maybe (a)
    {- ^ /@observer@/: A 'GI.Gio.Objects.DBusAuthObserver.DBusAuthObserver' or 'Nothing'. -}
    -> Maybe (b)
    {- ^ /@cancellable@/: A 'GI.Gio.Objects.Cancellable.Cancellable' or 'Nothing'. -}
    -> m DBusServer
    {- ^ __Returns:__ A 'GI.Gio.Objects.DBusServer.DBusServer' or 'Nothing' if /@error@/ is set. Free with
'GI.GObject.Objects.Object.objectUnref'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
dBusServerNewSync address flags guid observer cancellable = liftIO $ do
    address' <- textToCString address
    let flags' = gflagsToWord flags
    guid' <- textToCString guid
    maybeObserver <- case observer of
        Nothing -> return nullPtr
        Just jObserver -> do
            jObserver' <- unsafeManagedPtrCastPtr jObserver
            return jObserver'
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    onException (do
        result <- propagateGError $ g_dbus_server_new_sync address' flags' guid' maybeObserver maybeCancellable
        checkUnexpectedReturnNULL "dBusServerNewSync" result
        result' <- (wrapObject DBusServer) result
        whenJust observer touchManagedPtr
        whenJust cancellable touchManagedPtr
        freeMem address'
        freeMem guid'
        return result'
     ) (do
        freeMem address'
        freeMem guid'
     )

-- method DBusServer::get_client_address
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "server", argType = TInterface (Name {namespace = "Gio", name = "DBusServer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GDBusServer.", 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_dbus_server_get_client_address" g_dbus_server_get_client_address :: 
    Ptr DBusServer ->                       -- server : TInterface (Name {namespace = "Gio", name = "DBusServer"})
    IO CString

{- |
Gets a D-Bus address string that can be used by clients to connect
to /@server@/.

@since 2.26
-}
dBusServerGetClientAddress ::
    (B.CallStack.HasCallStack, MonadIO m, IsDBusServer a) =>
    a
    {- ^ /@server@/: A 'GI.Gio.Objects.DBusServer.DBusServer'. -}
    -> m T.Text
    {- ^ __Returns:__ A D-Bus address string. Do not free, the string is owned
by /@server@/. -}
dBusServerGetClientAddress server = liftIO $ do
    server' <- unsafeManagedPtrCastPtr server
    result <- g_dbus_server_get_client_address server'
    checkUnexpectedReturnNULL "dBusServerGetClientAddress" result
    result' <- cstringToText result
    touchManagedPtr server
    return result'

data DBusServerGetClientAddressMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsDBusServer a) => O.MethodInfo DBusServerGetClientAddressMethodInfo a signature where
    overloadedMethod _ = dBusServerGetClientAddress

-- method DBusServer::get_flags
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "server", argType = TInterface (Name {namespace = "Gio", name = "DBusServer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GDBusServer.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "DBusServerFlags"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_dbus_server_get_flags" g_dbus_server_get_flags :: 
    Ptr DBusServer ->                       -- server : TInterface (Name {namespace = "Gio", name = "DBusServer"})
    IO CUInt

{- |
Gets the flags for /@server@/.

@since 2.26
-}
dBusServerGetFlags ::
    (B.CallStack.HasCallStack, MonadIO m, IsDBusServer a) =>
    a
    {- ^ /@server@/: A 'GI.Gio.Objects.DBusServer.DBusServer'. -}
    -> m [Gio.Flags.DBusServerFlags]
    {- ^ __Returns:__ A set of flags from the 'GI.Gio.Flags.DBusServerFlags' enumeration. -}
dBusServerGetFlags server = liftIO $ do
    server' <- unsafeManagedPtrCastPtr server
    result <- g_dbus_server_get_flags server'
    let result' = wordToGFlags result
    touchManagedPtr server
    return result'

data DBusServerGetFlagsMethodInfo
instance (signature ~ (m [Gio.Flags.DBusServerFlags]), MonadIO m, IsDBusServer a) => O.MethodInfo DBusServerGetFlagsMethodInfo a signature where
    overloadedMethod _ = dBusServerGetFlags

-- method DBusServer::get_guid
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "server", argType = TInterface (Name {namespace = "Gio", name = "DBusServer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GDBusServer.", 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_dbus_server_get_guid" g_dbus_server_get_guid :: 
    Ptr DBusServer ->                       -- server : TInterface (Name {namespace = "Gio", name = "DBusServer"})
    IO CString

{- |
Gets the GUID for /@server@/.

@since 2.26
-}
dBusServerGetGuid ::
    (B.CallStack.HasCallStack, MonadIO m, IsDBusServer a) =>
    a
    {- ^ /@server@/: A 'GI.Gio.Objects.DBusServer.DBusServer'. -}
    -> m T.Text
    {- ^ __Returns:__ A D-Bus GUID. Do not free this string, it is owned by /@server@/. -}
dBusServerGetGuid server = liftIO $ do
    server' <- unsafeManagedPtrCastPtr server
    result <- g_dbus_server_get_guid server'
    checkUnexpectedReturnNULL "dBusServerGetGuid" result
    result' <- cstringToText result
    touchManagedPtr server
    return result'

data DBusServerGetGuidMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsDBusServer a) => O.MethodInfo DBusServerGetGuidMethodInfo a signature where
    overloadedMethod _ = dBusServerGetGuid

-- method DBusServer::is_active
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "server", argType = TInterface (Name {namespace = "Gio", name = "DBusServer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GDBusServer.", 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_dbus_server_is_active" g_dbus_server_is_active :: 
    Ptr DBusServer ->                       -- server : TInterface (Name {namespace = "Gio", name = "DBusServer"})
    IO CInt

{- |
Gets whether /@server@/ is active.

@since 2.26
-}
dBusServerIsActive ::
    (B.CallStack.HasCallStack, MonadIO m, IsDBusServer a) =>
    a
    {- ^ /@server@/: A 'GI.Gio.Objects.DBusServer.DBusServer'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if server is active, 'False' otherwise. -}
dBusServerIsActive server = liftIO $ do
    server' <- unsafeManagedPtrCastPtr server
    result <- g_dbus_server_is_active server'
    let result' = (/= 0) result
    touchManagedPtr server
    return result'

data DBusServerIsActiveMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsDBusServer a) => O.MethodInfo DBusServerIsActiveMethodInfo a signature where
    overloadedMethod _ = dBusServerIsActive

-- method DBusServer::start
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "server", argType = TInterface (Name {namespace = "Gio", name = "DBusServer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GDBusServer.", 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_server_start" g_dbus_server_start :: 
    Ptr DBusServer ->                       -- server : TInterface (Name {namespace = "Gio", name = "DBusServer"})
    IO ()

{- |
Starts /@server@/.

@since 2.26
-}
dBusServerStart ::
    (B.CallStack.HasCallStack, MonadIO m, IsDBusServer a) =>
    a
    {- ^ /@server@/: A 'GI.Gio.Objects.DBusServer.DBusServer'. -}
    -> m ()
dBusServerStart server = liftIO $ do
    server' <- unsafeManagedPtrCastPtr server
    g_dbus_server_start server'
    touchManagedPtr server
    return ()

data DBusServerStartMethodInfo
instance (signature ~ (m ()), MonadIO m, IsDBusServer a) => O.MethodInfo DBusServerStartMethodInfo a signature where
    overloadedMethod _ = dBusServerStart

-- method DBusServer::stop
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "server", argType = TInterface (Name {namespace = "Gio", name = "DBusServer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GDBusServer.", 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_server_stop" g_dbus_server_stop :: 
    Ptr DBusServer ->                       -- server : TInterface (Name {namespace = "Gio", name = "DBusServer"})
    IO ()

{- |
Stops /@server@/.

@since 2.26
-}
dBusServerStop ::
    (B.CallStack.HasCallStack, MonadIO m, IsDBusServer a) =>
    a
    {- ^ /@server@/: A 'GI.Gio.Objects.DBusServer.DBusServer'. -}
    -> m ()
dBusServerStop server = liftIO $ do
    server' <- unsafeManagedPtrCastPtr server
    g_dbus_server_stop server'
    touchManagedPtr server
    return ()

data DBusServerStopMethodInfo
instance (signature ~ (m ()), MonadIO m, IsDBusServer a) => O.MethodInfo DBusServerStopMethodInfo a signature where
    overloadedMethod _ = dBusServerStop