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

module GI.Gio.Objects.NetworkAddress
    ( 

-- * Exported types
    NetworkAddress(..)                      ,
    NetworkAddressK                         ,
    toNetworkAddress                        ,
    noNetworkAddress                        ,


 -- * Methods
-- ** networkAddressGetHostname
    networkAddressGetHostname               ,


-- ** networkAddressGetPort
    networkAddressGetPort                   ,


-- ** networkAddressGetScheme
    networkAddressGetScheme                 ,


-- ** networkAddressNew
    networkAddressNew                       ,


-- ** networkAddressNewLoopback
    networkAddressNewLoopback               ,


-- ** networkAddressParse
    networkAddressParse                     ,


-- ** networkAddressParseUri
    networkAddressParseUri                  ,




 -- * Properties
-- ** Hostname
    NetworkAddressHostnamePropertyInfo      ,
    constructNetworkAddressHostname         ,
    getNetworkAddressHostname               ,


-- ** Port
    NetworkAddressPortPropertyInfo          ,
    constructNetworkAddressPort             ,
    getNetworkAddressPort                   ,


-- ** Scheme
    NetworkAddressSchemePropertyInfo        ,
    constructNetworkAddressScheme           ,
    getNetworkAddressScheme                 ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Gio.Types
import GI.Gio.Callbacks
import qualified GI.GObject as GObject

newtype NetworkAddress = NetworkAddress (ForeignPtr NetworkAddress)
foreign import ccall "g_network_address_get_type"
    c_g_network_address_get_type :: IO GType

type instance ParentTypes NetworkAddress = NetworkAddressParentTypes
type NetworkAddressParentTypes = '[GObject.Object, SocketConnectable]

instance GObject NetworkAddress where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_g_network_address_get_type
    

class GObject o => NetworkAddressK o
instance (GObject o, IsDescendantOf NetworkAddress o) => NetworkAddressK o

toNetworkAddress :: NetworkAddressK o => o -> IO NetworkAddress
toNetworkAddress = unsafeCastTo NetworkAddress

noNetworkAddress :: Maybe NetworkAddress
noNetworkAddress = Nothing

-- VVV Prop "hostname"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]

getNetworkAddressHostname :: (MonadIO m, NetworkAddressK o) => o -> m T.Text
getNetworkAddressHostname obj = liftIO $ getObjectPropertyString obj "hostname"

constructNetworkAddressHostname :: T.Text -> IO ([Char], GValue)
constructNetworkAddressHostname val = constructObjectPropertyString "hostname" val

data NetworkAddressHostnamePropertyInfo
instance AttrInfo NetworkAddressHostnamePropertyInfo where
    type AttrAllowedOps NetworkAddressHostnamePropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint NetworkAddressHostnamePropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint NetworkAddressHostnamePropertyInfo = NetworkAddressK
    type AttrGetType NetworkAddressHostnamePropertyInfo = T.Text
    type AttrLabel NetworkAddressHostnamePropertyInfo = "NetworkAddress::hostname"
    attrGet _ = getNetworkAddressHostname
    attrSet _ = undefined
    attrConstruct _ = constructNetworkAddressHostname

-- VVV Prop "port"
   -- Type: TBasicType TUInt32
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]

getNetworkAddressPort :: (MonadIO m, NetworkAddressK o) => o -> m Word32
getNetworkAddressPort obj = liftIO $ getObjectPropertyCUInt obj "port"

constructNetworkAddressPort :: Word32 -> IO ([Char], GValue)
constructNetworkAddressPort val = constructObjectPropertyCUInt "port" val

data NetworkAddressPortPropertyInfo
instance AttrInfo NetworkAddressPortPropertyInfo where
    type AttrAllowedOps NetworkAddressPortPropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint NetworkAddressPortPropertyInfo = (~) Word32
    type AttrBaseTypeConstraint NetworkAddressPortPropertyInfo = NetworkAddressK
    type AttrGetType NetworkAddressPortPropertyInfo = Word32
    type AttrLabel NetworkAddressPortPropertyInfo = "NetworkAddress::port"
    attrGet _ = getNetworkAddressPort
    attrSet _ = undefined
    attrConstruct _ = constructNetworkAddressPort

-- VVV Prop "scheme"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]

getNetworkAddressScheme :: (MonadIO m, NetworkAddressK o) => o -> m T.Text
getNetworkAddressScheme obj = liftIO $ getObjectPropertyString obj "scheme"

constructNetworkAddressScheme :: T.Text -> IO ([Char], GValue)
constructNetworkAddressScheme val = constructObjectPropertyString "scheme" val

data NetworkAddressSchemePropertyInfo
instance AttrInfo NetworkAddressSchemePropertyInfo where
    type AttrAllowedOps NetworkAddressSchemePropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint NetworkAddressSchemePropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint NetworkAddressSchemePropertyInfo = NetworkAddressK
    type AttrGetType NetworkAddressSchemePropertyInfo = T.Text
    type AttrLabel NetworkAddressSchemePropertyInfo = "NetworkAddress::scheme"
    attrGet _ = getNetworkAddressScheme
    attrSet _ = undefined
    attrConstruct _ = constructNetworkAddressScheme

type instance AttributeList NetworkAddress = NetworkAddressAttributeList
type NetworkAddressAttributeList = ('[ '("hostname", NetworkAddressHostnamePropertyInfo), '("port", NetworkAddressPortPropertyInfo), '("scheme", NetworkAddressSchemePropertyInfo)] :: [(Symbol, *)])

type instance SignalList NetworkAddress = NetworkAddressSignalList
type NetworkAddressSignalList = ('[ '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method NetworkAddress::new
-- method type : Constructor
-- Args : [Arg {argName = "hostname", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "hostname", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "NetworkAddress"
-- throws : False
-- Skip return : False

foreign import ccall "g_network_address_new" g_network_address_new :: 
    CString ->                              -- hostname : TBasicType TUTF8
    Word16 ->                               -- port : TBasicType TUInt16
    IO (Ptr NetworkAddress)


networkAddressNew ::
    (MonadIO m) =>
    T.Text ->                               -- hostname
    Word16 ->                               -- port
    m NetworkAddress
networkAddressNew hostname port = liftIO $ do
    hostname' <- textToCString hostname
    result <- g_network_address_new hostname' port
    checkUnexpectedReturnNULL "g_network_address_new" result
    result' <- (wrapObject NetworkAddress) result
    freeMem hostname'
    return result'

-- method NetworkAddress::new_loopback
-- method type : Constructor
-- Args : [Arg {argName = "port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "NetworkAddress"
-- throws : False
-- Skip return : False

foreign import ccall "g_network_address_new_loopback" g_network_address_new_loopback :: 
    Word16 ->                               -- port : TBasicType TUInt16
    IO (Ptr NetworkAddress)


networkAddressNewLoopback ::
    (MonadIO m) =>
    Word16 ->                               -- port
    m NetworkAddress
networkAddressNewLoopback port = liftIO $ do
    result <- g_network_address_new_loopback port
    checkUnexpectedReturnNULL "g_network_address_new_loopback" result
    result' <- (wrapObject NetworkAddress) result
    return result'

-- method NetworkAddress::get_hostname
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "NetworkAddress", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "NetworkAddress", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "g_network_address_get_hostname" g_network_address_get_hostname :: 
    Ptr NetworkAddress ->                   -- _obj : TInterface "Gio" "NetworkAddress"
    IO CString


networkAddressGetHostname ::
    (MonadIO m, NetworkAddressK a) =>
    a ->                                    -- _obj
    m T.Text
networkAddressGetHostname _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_network_address_get_hostname _obj'
    checkUnexpectedReturnNULL "g_network_address_get_hostname" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method NetworkAddress::get_port
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "NetworkAddress", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "NetworkAddress", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUInt16
-- throws : False
-- Skip return : False

foreign import ccall "g_network_address_get_port" g_network_address_get_port :: 
    Ptr NetworkAddress ->                   -- _obj : TInterface "Gio" "NetworkAddress"
    IO Word16


networkAddressGetPort ::
    (MonadIO m, NetworkAddressK a) =>
    a ->                                    -- _obj
    m Word16
networkAddressGetPort _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_network_address_get_port _obj'
    touchManagedPtr _obj
    return result

-- method NetworkAddress::get_scheme
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "NetworkAddress", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "NetworkAddress", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "g_network_address_get_scheme" g_network_address_get_scheme :: 
    Ptr NetworkAddress ->                   -- _obj : TInterface "Gio" "NetworkAddress"
    IO CString


networkAddressGetScheme ::
    (MonadIO m, NetworkAddressK a) =>
    a ->                                    -- _obj
    m T.Text
networkAddressGetScheme _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_network_address_get_scheme _obj'
    checkUnexpectedReturnNULL "g_network_address_get_scheme" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method NetworkAddress::parse
-- method type : MemberFunction
-- Args : [Arg {argName = "host_and_port", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "default_port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "host_and_port", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "default_port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "SocketConnectable"
-- throws : True
-- Skip return : False

foreign import ccall "g_network_address_parse" g_network_address_parse :: 
    CString ->                              -- host_and_port : TBasicType TUTF8
    Word16 ->                               -- default_port : TBasicType TUInt16
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr SocketConnectable)


networkAddressParse ::
    (MonadIO m) =>
    T.Text ->                               -- host_and_port
    Word16 ->                               -- default_port
    m SocketConnectable
networkAddressParse host_and_port default_port = liftIO $ do
    host_and_port' <- textToCString host_and_port
    onException (do
        result <- propagateGError $ g_network_address_parse host_and_port' default_port
        checkUnexpectedReturnNULL "g_network_address_parse" result
        result' <- (wrapObject SocketConnectable) result
        freeMem host_and_port'
        return result'
     ) (do
        freeMem host_and_port'
     )

-- method NetworkAddress::parse_uri
-- method type : MemberFunction
-- Args : [Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "default_port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "default_port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "SocketConnectable"
-- throws : True
-- Skip return : False

foreign import ccall "g_network_address_parse_uri" g_network_address_parse_uri :: 
    CString ->                              -- uri : TBasicType TUTF8
    Word16 ->                               -- default_port : TBasicType TUInt16
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr SocketConnectable)


networkAddressParseUri ::
    (MonadIO m) =>
    T.Text ->                               -- uri
    Word16 ->                               -- default_port
    m SocketConnectable
networkAddressParseUri uri default_port = liftIO $ do
    uri' <- textToCString uri
    onException (do
        result <- propagateGError $ g_network_address_parse_uri uri' default_port
        checkUnexpectedReturnNULL "g_network_address_parse_uri" result
        result' <- (wrapObject SocketConnectable) result
        freeMem uri'
        return result'
     ) (do
        freeMem uri'
     )