{-# LANGUAGE ImplicitParams, RankNTypes, TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- A t'GI.Gio.Objects.SocketService.SocketService' is an object that represents a service that
-- is provided to the network or over local sockets.  When a new
-- connection is made to the service the [SocketService::incoming]("GI.Gio.Objects.SocketService#g:signal:incoming")
-- signal is emitted.
-- 
-- A t'GI.Gio.Objects.SocketService.SocketService' is a subclass of t'GI.Gio.Objects.SocketListener.SocketListener' and you need
-- to add the addresses you want to accept connections on with the
-- t'GI.Gio.Objects.SocketListener.SocketListener' APIs.
-- 
-- There are two options for implementing a network service based on
-- t'GI.Gio.Objects.SocketService.SocketService'. The first is to create the service using
-- 'GI.Gio.Objects.SocketService.socketServiceNew' and to connect to the [SocketService::incoming]("GI.Gio.Objects.SocketService#g:signal:incoming")
-- signal. The second is to subclass t'GI.Gio.Objects.SocketService.SocketService' and override the
-- default signal handler implementation.
-- 
-- In either case, the handler must immediately return, or else it
-- will block additional incoming connections from being serviced.
-- If you are interested in writing connection handlers that contain
-- blocking code then see t'GI.Gio.Objects.ThreadedSocketService.ThreadedSocketService'.
-- 
-- The socket service runs on the main loop of the
-- [thread-default context][g-main-context-push-thread-default-context]
-- of the thread it is created in, and is not
-- threadsafe in general. However, the calls to start and stop the
-- service are thread-safe so these can be used from threads that
-- handle incoming clients.
-- 
-- /Since: 2.22/

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

module GI.Gio.Objects.SocketService
    ( 

-- * Exported types
    SocketService(..)                       ,
    IsSocketService                         ,
    toSocketService                         ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [accept]("GI.Gio.Objects.SocketListener#g:method:accept"), [acceptAsync]("GI.Gio.Objects.SocketListener#g:method:acceptAsync"), [acceptFinish]("GI.Gio.Objects.SocketListener#g:method:acceptFinish"), [acceptSocket]("GI.Gio.Objects.SocketListener#g:method:acceptSocket"), [acceptSocketAsync]("GI.Gio.Objects.SocketListener#g:method:acceptSocketAsync"), [acceptSocketFinish]("GI.Gio.Objects.SocketListener#g:method:acceptSocketFinish"), [addAddress]("GI.Gio.Objects.SocketListener#g:method:addAddress"), [addAnyInetPort]("GI.Gio.Objects.SocketListener#g:method:addAnyInetPort"), [addInetPort]("GI.Gio.Objects.SocketListener#g:method:addInetPort"), [addSocket]("GI.Gio.Objects.SocketListener#g:method:addSocket"), [bindProperty]("GI.GObject.Objects.Object#g:method:bindProperty"), [bindPropertyFull]("GI.GObject.Objects.Object#g:method:bindPropertyFull"), [close]("GI.Gio.Objects.SocketListener#g:method:close"), [forceFloating]("GI.GObject.Objects.Object#g:method:forceFloating"), [freezeNotify]("GI.GObject.Objects.Object#g:method:freezeNotify"), [getv]("GI.GObject.Objects.Object#g:method:getv"), [isActive]("GI.Gio.Objects.SocketService#g:method:isActive"), [isFloating]("GI.GObject.Objects.Object#g:method:isFloating"), [notify]("GI.GObject.Objects.Object#g:method:notify"), [notifyByPspec]("GI.GObject.Objects.Object#g:method:notifyByPspec"), [ref]("GI.GObject.Objects.Object#g:method:ref"), [refSink]("GI.GObject.Objects.Object#g:method:refSink"), [runDispose]("GI.GObject.Objects.Object#g:method:runDispose"), [start]("GI.Gio.Objects.SocketService#g:method:start"), [stealData]("GI.GObject.Objects.Object#g:method:stealData"), [stealQdata]("GI.GObject.Objects.Object#g:method:stealQdata"), [stop]("GI.Gio.Objects.SocketService#g:method:stop"), [thawNotify]("GI.GObject.Objects.Object#g:method:thawNotify"), [unref]("GI.GObject.Objects.Object#g:method:unref"), [watchClosure]("GI.GObject.Objects.Object#g:method:watchClosure").
-- 
-- ==== Getters
-- [getData]("GI.GObject.Objects.Object#g:method:getData"), [getProperty]("GI.GObject.Objects.Object#g:method:getProperty"), [getQdata]("GI.GObject.Objects.Object#g:method:getQdata").
-- 
-- ==== Setters
-- [setBacklog]("GI.Gio.Objects.SocketListener#g:method:setBacklog"), [setData]("GI.GObject.Objects.Object#g:method:setData"), [setDataFull]("GI.GObject.Objects.Object#g:method:setDataFull"), [setProperty]("GI.GObject.Objects.Object#g:method:setProperty").

#if defined(ENABLE_OVERLOADING)
    ResolveSocketServiceMethod              ,
#endif

-- ** isActive #method:isActive#

#if defined(ENABLE_OVERLOADING)
    SocketServiceIsActiveMethodInfo         ,
#endif
    socketServiceIsActive                   ,


-- ** new #method:new#

    socketServiceNew                        ,


-- ** start #method:start#

#if defined(ENABLE_OVERLOADING)
    SocketServiceStartMethodInfo            ,
#endif
    socketServiceStart                      ,


-- ** stop #method:stop#

#if defined(ENABLE_OVERLOADING)
    SocketServiceStopMethodInfo             ,
#endif
    socketServiceStop                       ,




 -- * Properties


-- ** active #attr:active#
-- | Whether the service is currently accepting connections.
-- 
-- /Since: 2.46/

#if defined(ENABLE_OVERLOADING)
    SocketServiceActivePropertyInfo         ,
#endif
    constructSocketServiceActive            ,
    getSocketServiceActive                  ,
    setSocketServiceActive                  ,
#if defined(ENABLE_OVERLOADING)
    socketServiceActive                     ,
#endif




 -- * Signals


-- ** incoming #signal:incoming#

    SocketServiceIncomingCallback           ,
#if defined(ENABLE_OVERLOADING)
    SocketServiceIncomingSignalInfo         ,
#endif
    afterSocketServiceIncoming              ,
    onSocketServiceIncoming                 ,




    ) 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.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
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.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
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 GHC.Records as R

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Objects.SocketConnection as Gio.SocketConnection
import {-# SOURCE #-} qualified GI.Gio.Objects.SocketListener as Gio.SocketListener

-- | Memory-managed wrapper type.
newtype SocketService = SocketService (SP.ManagedPtr SocketService)
    deriving (SocketService -> SocketService -> Bool
(SocketService -> SocketService -> Bool)
-> (SocketService -> SocketService -> Bool) -> Eq SocketService
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SocketService -> SocketService -> Bool
$c/= :: SocketService -> SocketService -> Bool
== :: SocketService -> SocketService -> Bool
$c== :: SocketService -> SocketService -> Bool
Eq)

instance SP.ManagedPtrNewtype SocketService where
    toManagedPtr :: SocketService -> ManagedPtr SocketService
toManagedPtr (SocketService ManagedPtr SocketService
p) = ManagedPtr SocketService
p

foreign import ccall "g_socket_service_get_type"
    c_g_socket_service_get_type :: IO B.Types.GType

instance B.Types.TypedObject SocketService where
    glibType :: IO GType
glibType = IO GType
c_g_socket_service_get_type

instance B.Types.GObject SocketService

-- | Type class for types which can be safely cast to `SocketService`, for instance with `toSocketService`.
class (SP.GObject o, O.IsDescendantOf SocketService o) => IsSocketService o
instance (SP.GObject o, O.IsDescendantOf SocketService o) => IsSocketService o

instance O.HasParentTypes SocketService
type instance O.ParentTypes SocketService = '[Gio.SocketListener.SocketListener, GObject.Object.Object]

-- | Cast to `SocketService`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toSocketService :: (MIO.MonadIO m, IsSocketService o) => o -> m SocketService
toSocketService :: forall (m :: * -> *) o.
(MonadIO m, IsSocketService o) =>
o -> m SocketService
toSocketService = IO SocketService -> m SocketService
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO SocketService -> m SocketService)
-> (o -> IO SocketService) -> o -> m SocketService
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr SocketService -> SocketService)
-> o -> IO SocketService
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
 ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
B.ManagedPtr.unsafeCastTo ManagedPtr SocketService -> SocketService
SocketService

-- | Convert 'SocketService' to and from 'Data.GI.Base.GValue.GValue'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue (Maybe SocketService) where
    gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_g_socket_service_get_type
    gvalueSet_ :: Ptr GValue -> Maybe SocketService -> IO ()
gvalueSet_ Ptr GValue
gv Maybe SocketService
P.Nothing = Ptr GValue -> Ptr SocketService -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv (Ptr SocketService
forall a. Ptr a
FP.nullPtr :: FP.Ptr SocketService)
    gvalueSet_ Ptr GValue
gv (P.Just SocketService
obj) = SocketService -> (Ptr SocketService -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr SocketService
obj (Ptr GValue -> Ptr SocketService -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv)
    gvalueGet_ :: Ptr GValue -> IO (Maybe SocketService)
gvalueGet_ Ptr GValue
gv = do
        Ptr SocketService
ptr <- Ptr GValue -> IO (Ptr SocketService)
forall a. GObject a => Ptr GValue -> IO (Ptr a)
B.GValue.get_object Ptr GValue
gv :: IO (FP.Ptr SocketService)
        if Ptr SocketService
ptr Ptr SocketService -> Ptr SocketService -> Bool
forall a. Eq a => a -> a -> Bool
/= Ptr SocketService
forall a. Ptr a
FP.nullPtr
        then SocketService -> Maybe SocketService
forall a. a -> Maybe a
P.Just (SocketService -> Maybe SocketService)
-> IO SocketService -> IO (Maybe SocketService)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ManagedPtr SocketService -> SocketService)
-> Ptr SocketService -> IO SocketService
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr SocketService -> SocketService
SocketService Ptr SocketService
ptr
        else Maybe SocketService -> IO (Maybe SocketService)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe SocketService
forall a. Maybe a
P.Nothing
        
    

#if defined(ENABLE_OVERLOADING)
type family ResolveSocketServiceMethod (t :: Symbol) (o :: *) :: * where
    ResolveSocketServiceMethod "accept" o = Gio.SocketListener.SocketListenerAcceptMethodInfo
    ResolveSocketServiceMethod "acceptAsync" o = Gio.SocketListener.SocketListenerAcceptAsyncMethodInfo
    ResolveSocketServiceMethod "acceptFinish" o = Gio.SocketListener.SocketListenerAcceptFinishMethodInfo
    ResolveSocketServiceMethod "acceptSocket" o = Gio.SocketListener.SocketListenerAcceptSocketMethodInfo
    ResolveSocketServiceMethod "acceptSocketAsync" o = Gio.SocketListener.SocketListenerAcceptSocketAsyncMethodInfo
    ResolveSocketServiceMethod "acceptSocketFinish" o = Gio.SocketListener.SocketListenerAcceptSocketFinishMethodInfo
    ResolveSocketServiceMethod "addAddress" o = Gio.SocketListener.SocketListenerAddAddressMethodInfo
    ResolveSocketServiceMethod "addAnyInetPort" o = Gio.SocketListener.SocketListenerAddAnyInetPortMethodInfo
    ResolveSocketServiceMethod "addInetPort" o = Gio.SocketListener.SocketListenerAddInetPortMethodInfo
    ResolveSocketServiceMethod "addSocket" o = Gio.SocketListener.SocketListenerAddSocketMethodInfo
    ResolveSocketServiceMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveSocketServiceMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveSocketServiceMethod "close" o = Gio.SocketListener.SocketListenerCloseMethodInfo
    ResolveSocketServiceMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveSocketServiceMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveSocketServiceMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveSocketServiceMethod "isActive" o = SocketServiceIsActiveMethodInfo
    ResolveSocketServiceMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveSocketServiceMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveSocketServiceMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveSocketServiceMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveSocketServiceMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveSocketServiceMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveSocketServiceMethod "start" o = SocketServiceStartMethodInfo
    ResolveSocketServiceMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveSocketServiceMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveSocketServiceMethod "stop" o = SocketServiceStopMethodInfo
    ResolveSocketServiceMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveSocketServiceMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveSocketServiceMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveSocketServiceMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveSocketServiceMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveSocketServiceMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveSocketServiceMethod "setBacklog" o = Gio.SocketListener.SocketListenerSetBacklogMethodInfo
    ResolveSocketServiceMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveSocketServiceMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveSocketServiceMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveSocketServiceMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveSocketServiceMethod t SocketService, O.OverloadedMethod info SocketService p) => OL.IsLabel t (SocketService -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveSocketServiceMethod t SocketService, O.OverloadedMethod info SocketService p, R.HasField t SocketService p) => R.HasField t SocketService p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolveSocketServiceMethod t SocketService, O.OverloadedMethodInfo info SocketService) => OL.IsLabel t (O.MethodProxy info SocketService) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif

-- signal SocketService::incoming
-- | The [incoming](#g:signal:incoming) signal is emitted when a new incoming connection
-- to /@service@/ needs to be handled. The handler must initiate the
-- handling of /@connection@/, but may not block; in essence,
-- asynchronous operations must be used.
-- 
-- /@connection@/ will be unreffed once the signal handler returns,
-- so you need to ref it yourself if you are planning to use it.
-- 
-- /Since: 2.22/
type SocketServiceIncomingCallback =
    Gio.SocketConnection.SocketConnection
    -- ^ /@connection@/: a new t'GI.Gio.Objects.SocketConnection.SocketConnection' object
    -> Maybe GObject.Object.Object
    -- ^ /@sourceObject@/: the source_object passed to
    --     'GI.Gio.Objects.SocketListener.socketListenerAddAddress'
    -> IO Bool
    -- ^ __Returns:__ 'P.True' to stop other handlers from being called

type C_SocketServiceIncomingCallback =
    Ptr SocketService ->                    -- object
    Ptr Gio.SocketConnection.SocketConnection ->
    Ptr GObject.Object.Object ->
    Ptr () ->                               -- user_data
    IO CInt

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

wrap_SocketServiceIncomingCallback :: 
    GObject a => (a -> SocketServiceIncomingCallback) ->
    C_SocketServiceIncomingCallback
wrap_SocketServiceIncomingCallback :: forall a.
GObject a =>
(a -> SocketServiceIncomingCallback)
-> C_SocketServiceIncomingCallback
wrap_SocketServiceIncomingCallback a -> SocketServiceIncomingCallback
gi'cb Ptr SocketService
gi'selfPtr Ptr SocketConnection
connection Ptr Object
sourceObject Ptr ()
_ = do
    SocketConnection
connection' <- ((ManagedPtr SocketConnection -> SocketConnection)
-> Ptr SocketConnection -> IO SocketConnection
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr SocketConnection -> SocketConnection
Gio.SocketConnection.SocketConnection) Ptr SocketConnection
connection
    Maybe Object
maybeSourceObject <-
        if Ptr Object
sourceObject Ptr Object -> Ptr Object -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr Object
forall a. Ptr a
nullPtr
        then Maybe Object -> IO (Maybe Object)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Object
forall a. Maybe a
Nothing
        else do
            Object
sourceObject' <- ((ManagedPtr Object -> Object) -> Ptr Object -> IO Object
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Object -> Object
GObject.Object.Object) Ptr Object
sourceObject
            Maybe Object -> IO (Maybe Object)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Object -> IO (Maybe Object))
-> Maybe Object -> IO (Maybe Object)
forall a b. (a -> b) -> a -> b
$ Object -> Maybe Object
forall a. a -> Maybe a
Just Object
sourceObject'
    Bool
result <- Ptr SocketService -> (SocketService -> IO Bool) -> IO Bool
forall a b.
(HasCallStack, ManagedPtrNewtype a) =>
Ptr a -> (a -> IO b) -> IO b
B.ManagedPtr.withTransient Ptr SocketService
gi'selfPtr ((SocketService -> IO Bool) -> IO Bool)
-> (SocketService -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \SocketService
gi'self -> a -> SocketServiceIncomingCallback
gi'cb (SocketService -> a
Coerce.coerce SocketService
gi'self)  SocketConnection
connection' Maybe Object
maybeSourceObject
    let result' :: CInt
result' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum) Bool
result
    CInt -> IO CInt
forall (m :: * -> *) a. Monad m => a -> m a
return CInt
result'


-- | Connect a signal handler for the [incoming](#signal:incoming) 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' socketService #incoming callback
-- @
-- 
-- 
onSocketServiceIncoming :: (IsSocketService a, MonadIO m) => a -> ((?self :: a) => SocketServiceIncomingCallback) -> m SignalHandlerId
onSocketServiceIncoming :: forall a (m :: * -> *).
(IsSocketService a, MonadIO m) =>
a
-> ((?self::a) => SocketServiceIncomingCallback)
-> m SignalHandlerId
onSocketServiceIncoming a
obj (?self::a) => SocketServiceIncomingCallback
cb = IO SignalHandlerId -> m SignalHandlerId
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SignalHandlerId -> m SignalHandlerId)
-> IO SignalHandlerId -> m SignalHandlerId
forall a b. (a -> b) -> a -> b
$ do
    let wrapped :: a -> SocketServiceIncomingCallback
wrapped a
self = let ?self = a
?self::a
self in (?self::a) => SocketServiceIncomingCallback
SocketServiceIncomingCallback
cb
    let wrapped' :: C_SocketServiceIncomingCallback
wrapped' = (a -> SocketServiceIncomingCallback)
-> C_SocketServiceIncomingCallback
forall a.
GObject a =>
(a -> SocketServiceIncomingCallback)
-> C_SocketServiceIncomingCallback
wrap_SocketServiceIncomingCallback a -> SocketServiceIncomingCallback
wrapped
    FunPtr C_SocketServiceIncomingCallback
wrapped'' <- C_SocketServiceIncomingCallback
-> IO (FunPtr C_SocketServiceIncomingCallback)
mk_SocketServiceIncomingCallback C_SocketServiceIncomingCallback
wrapped'
    a
-> Text
-> FunPtr C_SocketServiceIncomingCallback
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
forall o a.
GObject o =>
o
-> Text
-> FunPtr a
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
connectSignalFunPtr a
obj Text
"incoming" FunPtr C_SocketServiceIncomingCallback
wrapped'' SignalConnectMode
SignalConnectBefore Maybe Text
forall a. Maybe a
Nothing

-- | Connect a signal handler for the [incoming](#signal:incoming) 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' socketService #incoming callback
-- @
-- 
-- 
-- 
-- By default the object invoking the signal is not passed to the callback.
-- If you need to access it, you can use the implit @?self@ parameter.
-- Note that this requires activating the @ImplicitParams@ GHC extension.
-- 
afterSocketServiceIncoming :: (IsSocketService a, MonadIO m) => a -> ((?self :: a) => SocketServiceIncomingCallback) -> m SignalHandlerId
afterSocketServiceIncoming :: forall a (m :: * -> *).
(IsSocketService a, MonadIO m) =>
a
-> ((?self::a) => SocketServiceIncomingCallback)
-> m SignalHandlerId
afterSocketServiceIncoming a
obj (?self::a) => SocketServiceIncomingCallback
cb = IO SignalHandlerId -> m SignalHandlerId
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SignalHandlerId -> m SignalHandlerId)
-> IO SignalHandlerId -> m SignalHandlerId
forall a b. (a -> b) -> a -> b
$ do
    let wrapped :: a -> SocketServiceIncomingCallback
wrapped a
self = let ?self = a
?self::a
self in (?self::a) => SocketServiceIncomingCallback
SocketServiceIncomingCallback
cb
    let wrapped' :: C_SocketServiceIncomingCallback
wrapped' = (a -> SocketServiceIncomingCallback)
-> C_SocketServiceIncomingCallback
forall a.
GObject a =>
(a -> SocketServiceIncomingCallback)
-> C_SocketServiceIncomingCallback
wrap_SocketServiceIncomingCallback a -> SocketServiceIncomingCallback
wrapped
    FunPtr C_SocketServiceIncomingCallback
wrapped'' <- C_SocketServiceIncomingCallback
-> IO (FunPtr C_SocketServiceIncomingCallback)
mk_SocketServiceIncomingCallback C_SocketServiceIncomingCallback
wrapped'
    a
-> Text
-> FunPtr C_SocketServiceIncomingCallback
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
forall o a.
GObject o =>
o
-> Text
-> FunPtr a
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
connectSignalFunPtr a
obj Text
"incoming" FunPtr C_SocketServiceIncomingCallback
wrapped'' SignalConnectMode
SignalConnectAfter Maybe Text
forall a. Maybe a
Nothing


#if defined(ENABLE_OVERLOADING)
data SocketServiceIncomingSignalInfo
instance SignalInfo SocketServiceIncomingSignalInfo where
    type HaskellCallbackType SocketServiceIncomingSignalInfo = SocketServiceIncomingCallback
    connectSignal obj cb connectMode detail = do
        let cb' = wrap_SocketServiceIncomingCallback cb
        cb'' <- mk_SocketServiceIncomingCallback cb'
        connectSignalFunPtr obj "incoming" cb'' connectMode detail
    dbgSignalInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gio.Objects.SocketService::incoming"
        , O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.29/docs/GI-Gio-Objects-SocketService.html#g:signal:incoming"})

#endif

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

-- | Get the value of the “@active@” property.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Attributes.get' socketService #active
-- @
getSocketServiceActive :: (MonadIO m, IsSocketService o) => o -> m Bool
getSocketServiceActive :: forall (m :: * -> *) o.
(MonadIO m, IsSocketService o) =>
o -> m Bool
getSocketServiceActive o
obj = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ o -> String -> IO Bool
forall a. GObject a => a -> String -> IO Bool
B.Properties.getObjectPropertyBool o
obj String
"active"

-- | Set the value of the “@active@” property.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Attributes.set' socketService [ #active 'Data.GI.Base.Attributes.:=' value ]
-- @
setSocketServiceActive :: (MonadIO m, IsSocketService o) => o -> Bool -> m ()
setSocketServiceActive :: forall (m :: * -> *) o.
(MonadIO m, IsSocketService o) =>
o -> Bool -> m ()
setSocketServiceActive o
obj Bool
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    o -> String -> Bool -> IO ()
forall a. GObject a => a -> String -> Bool -> IO ()
B.Properties.setObjectPropertyBool o
obj String
"active" Bool
val

-- | Construct a `GValueConstruct` with valid value for the “@active@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
constructSocketServiceActive :: (IsSocketService o, MIO.MonadIO m) => Bool -> m (GValueConstruct o)
constructSocketServiceActive :: forall o (m :: * -> *).
(IsSocketService o, MonadIO m) =>
Bool -> m (GValueConstruct o)
constructSocketServiceActive Bool
val = IO (GValueConstruct o) -> m (GValueConstruct o)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO (GValueConstruct o) -> m (GValueConstruct o))
-> IO (GValueConstruct o) -> m (GValueConstruct o)
forall a b. (a -> b) -> a -> b
$ do
    IO (GValueConstruct o) -> IO (GValueConstruct o)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO (GValueConstruct o) -> IO (GValueConstruct o))
-> IO (GValueConstruct o) -> IO (GValueConstruct o)
forall a b. (a -> b) -> a -> b
$ String -> Bool -> IO (GValueConstruct o)
forall o. String -> Bool -> IO (GValueConstruct o)
B.Properties.constructObjectPropertyBool String
"active" Bool
val

#if defined(ENABLE_OVERLOADING)
data SocketServiceActivePropertyInfo
instance AttrInfo SocketServiceActivePropertyInfo where
    type AttrAllowedOps SocketServiceActivePropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrBaseTypeConstraint SocketServiceActivePropertyInfo = IsSocketService
    type AttrSetTypeConstraint SocketServiceActivePropertyInfo = (~) Bool
    type AttrTransferTypeConstraint SocketServiceActivePropertyInfo = (~) Bool
    type AttrTransferType SocketServiceActivePropertyInfo = Bool
    type AttrGetType SocketServiceActivePropertyInfo = Bool
    type AttrLabel SocketServiceActivePropertyInfo = "active"
    type AttrOrigin SocketServiceActivePropertyInfo = SocketService
    attrGet = getSocketServiceActive
    attrSet = setSocketServiceActive
    attrTransfer _ v = do
        return v
    attrConstruct = constructSocketServiceActive
    attrClear = undefined
    dbgAttrInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gio.Objects.SocketService.active"
        , O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.29/docs/GI-Gio-Objects-SocketService.html#g:attr:active"
        })
#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList SocketService
type instance O.AttributeList SocketService = SocketServiceAttributeList
type SocketServiceAttributeList = ('[ '("active", SocketServiceActivePropertyInfo), '("listenBacklog", Gio.SocketListener.SocketListenerListenBacklogPropertyInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING)
socketServiceActive :: AttrLabelProxy "active"
socketServiceActive = AttrLabelProxy

#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList SocketService = SocketServiceSignalList
type SocketServiceSignalList = ('[ '("event", Gio.SocketListener.SocketListenerEventSignalInfo), '("incoming", SocketServiceIncomingSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

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

foreign import ccall "g_socket_service_new" g_socket_service_new :: 
    IO (Ptr SocketService)

-- | Creates a new t'GI.Gio.Objects.SocketService.SocketService' with no sockets to listen for.
-- New listeners can be added with e.g. 'GI.Gio.Objects.SocketListener.socketListenerAddAddress'
-- or 'GI.Gio.Objects.SocketListener.socketListenerAddInetPort'.
-- 
-- New services are created active, there is no need to call
-- 'GI.Gio.Objects.SocketService.socketServiceStart', unless 'GI.Gio.Objects.SocketService.socketServiceStop' has been
-- called before.
-- 
-- /Since: 2.22/
socketServiceNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m SocketService
    -- ^ __Returns:__ a new t'GI.Gio.Objects.SocketService.SocketService'.
socketServiceNew :: forall (m :: * -> *). (HasCallStack, MonadIO m) => m SocketService
socketServiceNew  = IO SocketService -> m SocketService
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SocketService -> m SocketService)
-> IO SocketService -> m SocketService
forall a b. (a -> b) -> a -> b
$ do
    Ptr SocketService
result <- IO (Ptr SocketService)
g_socket_service_new
    Text -> Ptr SocketService -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"socketServiceNew" Ptr SocketService
result
    SocketService
result' <- ((ManagedPtr SocketService -> SocketService)
-> Ptr SocketService -> IO SocketService
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr SocketService -> SocketService
SocketService) Ptr SocketService
result
    SocketService -> IO SocketService
forall (m :: * -> *) a. Monad m => a -> m a
return SocketService
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method SocketService::is_active
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "service"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "SocketService" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GSocketService" , 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_socket_service_is_active" g_socket_service_is_active :: 
    Ptr SocketService ->                    -- service : TInterface (Name {namespace = "Gio", name = "SocketService"})
    IO CInt

-- | Check whether the service is active or not. An active
-- service will accept new clients that connect, while
-- a non-active service will let connecting clients queue
-- up until the service is started.
-- 
-- /Since: 2.22/
socketServiceIsActive ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketService a) =>
    a
    -- ^ /@service@/: a t'GI.Gio.Objects.SocketService.SocketService'
    -> m Bool
    -- ^ __Returns:__ 'P.True' if the service is active, 'P.False' otherwise
socketServiceIsActive :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsSocketService a) =>
a -> m Bool
socketServiceIsActive a
service = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr SocketService
service' <- a -> IO (Ptr SocketService)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
service
    CInt
result <- Ptr SocketService -> IO CInt
g_socket_service_is_active Ptr SocketService
service'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
service
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if defined(ENABLE_OVERLOADING)
data SocketServiceIsActiveMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsSocketService a) => O.OverloadedMethod SocketServiceIsActiveMethodInfo a signature where
    overloadedMethod = socketServiceIsActive

instance O.OverloadedMethodInfo SocketServiceIsActiveMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gio.Objects.SocketService.socketServiceIsActive",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.29/docs/GI-Gio-Objects-SocketService.html#v:socketServiceIsActive"
        })


#endif

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

foreign import ccall "g_socket_service_start" g_socket_service_start :: 
    Ptr SocketService ->                    -- service : TInterface (Name {namespace = "Gio", name = "SocketService"})
    IO ()

-- | Restarts the service, i.e. start accepting connections
-- from the added sockets when the mainloop runs. This only needs
-- to be called after the service has been stopped from
-- 'GI.Gio.Objects.SocketService.socketServiceStop'.
-- 
-- This call is thread-safe, so it may be called from a thread
-- handling an incoming client request.
-- 
-- /Since: 2.22/
socketServiceStart ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketService a) =>
    a
    -- ^ /@service@/: a t'GI.Gio.Objects.SocketService.SocketService'
    -> m ()
socketServiceStart :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsSocketService a) =>
a -> m ()
socketServiceStart a
service = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr SocketService
service' <- a -> IO (Ptr SocketService)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
service
    Ptr SocketService -> IO ()
g_socket_service_start Ptr SocketService
service'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
service
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data SocketServiceStartMethodInfo
instance (signature ~ (m ()), MonadIO m, IsSocketService a) => O.OverloadedMethod SocketServiceStartMethodInfo a signature where
    overloadedMethod = socketServiceStart

instance O.OverloadedMethodInfo SocketServiceStartMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gio.Objects.SocketService.socketServiceStart",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.29/docs/GI-Gio-Objects-SocketService.html#v:socketServiceStart"
        })


#endif

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

foreign import ccall "g_socket_service_stop" g_socket_service_stop :: 
    Ptr SocketService ->                    -- service : TInterface (Name {namespace = "Gio", name = "SocketService"})
    IO ()

-- | Stops the service, i.e. stops accepting connections
-- from the added sockets when the mainloop runs.
-- 
-- This call is thread-safe, so it may be called from a thread
-- handling an incoming client request.
-- 
-- Note that this only stops accepting new connections; it does not
-- close the listening sockets, and you can call
-- 'GI.Gio.Objects.SocketService.socketServiceStart' again later to begin listening again. To
-- close the listening sockets, call 'GI.Gio.Objects.SocketListener.socketListenerClose'. (This
-- will happen automatically when the t'GI.Gio.Objects.SocketService.SocketService' is finalized.)
-- 
-- This must be called before calling 'GI.Gio.Objects.SocketListener.socketListenerClose' as
-- the socket service will start accepting connections immediately
-- when a new socket is added.
-- 
-- /Since: 2.22/
socketServiceStop ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketService a) =>
    a
    -- ^ /@service@/: a t'GI.Gio.Objects.SocketService.SocketService'
    -> m ()
socketServiceStop :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsSocketService a) =>
a -> m ()
socketServiceStop a
service = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr SocketService
service' <- a -> IO (Ptr SocketService)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
service
    Ptr SocketService -> IO ()
g_socket_service_stop Ptr SocketService
service'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
service
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data SocketServiceStopMethodInfo
instance (signature ~ (m ()), MonadIO m, IsSocketService a) => O.OverloadedMethod SocketServiceStopMethodInfo a signature where
    overloadedMethod = socketServiceStop

instance O.OverloadedMethodInfo SocketServiceStopMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gio.Objects.SocketService.socketServiceStop",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.29/docs/GI-Gio-Objects-SocketService.html#v:socketServiceStop"
        })


#endif