{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- A socket address of some unknown native type.
-- 
-- This corresponds to a general @struct sockaddr@ of a type not otherwise
-- handled by GLib.
-- 
-- /Since: 2.46/

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

module GI.Gio.Objects.NativeSocketAddress
    ( 

-- * Exported types
    NativeSocketAddress(..)                 ,
    IsNativeSocketAddress                   ,
    toNativeSocketAddress                   ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [bindProperty]("GI.GObject.Objects.Object#g:method:bindProperty"), [bindPropertyFull]("GI.GObject.Objects.Object#g:method:bindPropertyFull"), [enumerate]("GI.Gio.Interfaces.SocketConnectable#g:method:enumerate"), [forceFloating]("GI.GObject.Objects.Object#g:method:forceFloating"), [freezeNotify]("GI.GObject.Objects.Object#g:method:freezeNotify"), [getv]("GI.GObject.Objects.Object#g:method:getv"), [isFloating]("GI.GObject.Objects.Object#g:method:isFloating"), [notify]("GI.GObject.Objects.Object#g:method:notify"), [notifyByPspec]("GI.GObject.Objects.Object#g:method:notifyByPspec"), [proxyEnumerate]("GI.Gio.Interfaces.SocketConnectable#g:method:proxyEnumerate"), [ref]("GI.GObject.Objects.Object#g:method:ref"), [refSink]("GI.GObject.Objects.Object#g:method:refSink"), [runDispose]("GI.GObject.Objects.Object#g:method:runDispose"), [stealData]("GI.GObject.Objects.Object#g:method:stealData"), [stealQdata]("GI.GObject.Objects.Object#g:method:stealQdata"), [thawNotify]("GI.GObject.Objects.Object#g:method:thawNotify"), [toNative]("GI.Gio.Objects.SocketAddress#g:method:toNative"), [toString]("GI.Gio.Interfaces.SocketConnectable#g:method:toString"), [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"), [getFamily]("GI.Gio.Objects.SocketAddress#g:method:getFamily"), [getNativeSize]("GI.Gio.Objects.SocketAddress#g:method:getNativeSize"), [getProperty]("GI.GObject.Objects.Object#g:method:getProperty"), [getQdata]("GI.GObject.Objects.Object#g:method:getQdata").
-- 
-- ==== Setters
-- [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)
    ResolveNativeSocketAddressMethod        ,
#endif

-- ** new #method:new#

    nativeSocketAddressNew                  ,




    ) 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.GHashTable as B.GHT
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.Kind as DK
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 Data.Word as DW
import qualified Data.Int as DI
import qualified System.Posix.Types as SPT
import qualified Foreign.C.Types as FCT

-- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
#if MIN_VERSION_base(4,18,0)
import qualified GI.GLib.Callbacks as GLib.Callbacks
import qualified GI.GLib.Structs.PollFD as GLib.PollFD
import qualified GI.GLib.Structs.Source as GLib.Source
import qualified GI.GObject.Callbacks as GObject.Callbacks
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.SocketConnectable as Gio.SocketConnectable
import {-# SOURCE #-} qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
import {-# SOURCE #-} qualified GI.Gio.Objects.SocketAddress as Gio.SocketAddress
import {-# SOURCE #-} qualified GI.Gio.Objects.SocketAddressEnumerator as Gio.SocketAddressEnumerator

#else
import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Interfaces.SocketConnectable as Gio.SocketConnectable
import {-# SOURCE #-} qualified GI.Gio.Objects.SocketAddress as Gio.SocketAddress

#endif

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

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

foreign import ccall "g_native_socket_address_get_type"
    c_g_native_socket_address_get_type :: IO B.Types.GType

instance B.Types.TypedObject NativeSocketAddress where
    glibType :: IO GType
glibType = IO GType
c_g_native_socket_address_get_type

instance B.Types.GObject NativeSocketAddress

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

instance O.HasParentTypes NativeSocketAddress
type instance O.ParentTypes NativeSocketAddress = '[Gio.SocketAddress.SocketAddress, GObject.Object.Object, Gio.SocketConnectable.SocketConnectable]

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

-- | Convert 'NativeSocketAddress' 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 NativeSocketAddress) where
    gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_g_native_socket_address_get_type
    gvalueSet_ :: Ptr GValue -> Maybe NativeSocketAddress -> IO ()
gvalueSet_ Ptr GValue
gv Maybe NativeSocketAddress
P.Nothing = Ptr GValue -> Ptr NativeSocketAddress -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv (Ptr NativeSocketAddress
forall a. Ptr a
FP.nullPtr :: FP.Ptr NativeSocketAddress)
    gvalueSet_ Ptr GValue
gv (P.Just NativeSocketAddress
obj) = NativeSocketAddress -> (Ptr NativeSocketAddress -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr NativeSocketAddress
obj (Ptr GValue -> Ptr NativeSocketAddress -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv)
    gvalueGet_ :: Ptr GValue -> IO (Maybe NativeSocketAddress)
gvalueGet_ Ptr GValue
gv = do
        Ptr NativeSocketAddress
ptr <- Ptr GValue -> IO (Ptr NativeSocketAddress)
forall a. GObject a => Ptr GValue -> IO (Ptr a)
B.GValue.get_object Ptr GValue
gv :: IO (FP.Ptr NativeSocketAddress)
        if Ptr NativeSocketAddress
ptr Ptr NativeSocketAddress -> Ptr NativeSocketAddress -> Bool
forall a. Eq a => a -> a -> Bool
/= Ptr NativeSocketAddress
forall a. Ptr a
FP.nullPtr
        then NativeSocketAddress -> Maybe NativeSocketAddress
forall a. a -> Maybe a
P.Just (NativeSocketAddress -> Maybe NativeSocketAddress)
-> IO NativeSocketAddress -> IO (Maybe NativeSocketAddress)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ManagedPtr NativeSocketAddress -> NativeSocketAddress)
-> Ptr NativeSocketAddress -> IO NativeSocketAddress
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr NativeSocketAddress -> NativeSocketAddress
NativeSocketAddress Ptr NativeSocketAddress
ptr
        else Maybe NativeSocketAddress -> IO (Maybe NativeSocketAddress)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe NativeSocketAddress
forall a. Maybe a
P.Nothing
        
    

#if defined(ENABLE_OVERLOADING)
type family ResolveNativeSocketAddressMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveNativeSocketAddressMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveNativeSocketAddressMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveNativeSocketAddressMethod "enumerate" o = Gio.SocketConnectable.SocketConnectableEnumerateMethodInfo
    ResolveNativeSocketAddressMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveNativeSocketAddressMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveNativeSocketAddressMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveNativeSocketAddressMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveNativeSocketAddressMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveNativeSocketAddressMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveNativeSocketAddressMethod "proxyEnumerate" o = Gio.SocketConnectable.SocketConnectableProxyEnumerateMethodInfo
    ResolveNativeSocketAddressMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveNativeSocketAddressMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveNativeSocketAddressMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveNativeSocketAddressMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveNativeSocketAddressMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveNativeSocketAddressMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveNativeSocketAddressMethod "toNative" o = Gio.SocketAddress.SocketAddressToNativeMethodInfo
    ResolveNativeSocketAddressMethod "toString" o = Gio.SocketConnectable.SocketConnectableToStringMethodInfo
    ResolveNativeSocketAddressMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveNativeSocketAddressMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveNativeSocketAddressMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveNativeSocketAddressMethod "getFamily" o = Gio.SocketAddress.SocketAddressGetFamilyMethodInfo
    ResolveNativeSocketAddressMethod "getNativeSize" o = Gio.SocketAddress.SocketAddressGetNativeSizeMethodInfo
    ResolveNativeSocketAddressMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveNativeSocketAddressMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveNativeSocketAddressMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveNativeSocketAddressMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveNativeSocketAddressMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveNativeSocketAddressMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveNativeSocketAddressMethod t NativeSocketAddress, O.OverloadedMethod info NativeSocketAddress p) => OL.IsLabel t (NativeSocketAddress -> 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 ~ ResolveNativeSocketAddressMethod t NativeSocketAddress, O.OverloadedMethod info NativeSocketAddress p, R.HasField t NativeSocketAddress p) => R.HasField t NativeSocketAddress p where
    getField = O.overloadedMethod @info

#endif

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

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList NativeSocketAddress
type instance O.AttributeList NativeSocketAddress = NativeSocketAddressAttributeList
type NativeSocketAddressAttributeList = ('[ '("family", Gio.SocketAddress.SocketAddressFamilyPropertyInfo)] :: [(Symbol, DK.Type)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList NativeSocketAddress = NativeSocketAddressSignalList
type NativeSocketAddressSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, DK.Type)])

#endif

-- method NativeSocketAddress::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "native"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a native address object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "len"
--           , argType = TBasicType TSize
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the length of @native, in bytes"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface
--                  Name { namespace = "Gio" , name = "NativeSocketAddress" })
-- throws : False
-- Skip return : False

foreign import ccall "g_native_socket_address_new" g_native_socket_address_new :: 
    Ptr () ->                               -- native : TBasicType TPtr
    FCT.CSize ->                            -- len : TBasicType TSize
    IO (Ptr NativeSocketAddress)

-- | Creates a new t'GI.Gio.Objects.NativeSocketAddress.NativeSocketAddress' for /@native@/ and /@len@/.
-- 
-- /Since: 2.46/
nativeSocketAddressNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Ptr ()
    -- ^ /@native@/: a native address object
    -> FCT.CSize
    -- ^ /@len@/: the length of /@native@/, in bytes
    -> m NativeSocketAddress
    -- ^ __Returns:__ a new t'GI.Gio.Objects.NativeSocketAddress.NativeSocketAddress'
nativeSocketAddressNew :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Ptr () -> CSize -> m NativeSocketAddress
nativeSocketAddressNew Ptr ()
native CSize
len = IO NativeSocketAddress -> m NativeSocketAddress
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO NativeSocketAddress -> m NativeSocketAddress)
-> IO NativeSocketAddress -> m NativeSocketAddress
forall a b. (a -> b) -> a -> b
$ do
    Ptr NativeSocketAddress
result <- Ptr () -> CSize -> IO (Ptr NativeSocketAddress)
g_native_socket_address_new Ptr ()
native CSize
len
    Text -> Ptr NativeSocketAddress -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"nativeSocketAddressNew" Ptr NativeSocketAddress
result
    NativeSocketAddress
result' <- ((ManagedPtr NativeSocketAddress -> NativeSocketAddress)
-> Ptr NativeSocketAddress -> IO NativeSocketAddress
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr NativeSocketAddress -> NativeSocketAddress
NativeSocketAddress) Ptr NativeSocketAddress
result
    NativeSocketAddress -> IO NativeSocketAddress
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return NativeSocketAddress
result'

#if defined(ENABLE_OVERLOADING)
#endif