{- | 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.SocketConnection ( -- * Exported types SocketConnection(..) , SocketConnectionK , toSocketConnection , noSocketConnection , -- * Methods -- ** socketConnectionConnect socketConnectionConnect , -- ** socketConnectionConnectAsync socketConnectionConnectAsync , -- ** socketConnectionConnectFinish socketConnectionConnectFinish , -- ** socketConnectionFactoryLookupType socketConnectionFactoryLookupType , -- ** socketConnectionFactoryRegisterType socketConnectionFactoryRegisterType , -- ** socketConnectionGetLocalAddress socketConnectionGetLocalAddress , -- ** socketConnectionGetRemoteAddress socketConnectionGetRemoteAddress , -- ** socketConnectionGetSocket socketConnectionGetSocket , -- ** socketConnectionIsConnected socketConnectionIsConnected , -- * Properties -- ** Socket SocketConnectionSocketPropertyInfo , constructSocketConnectionSocket , getSocketConnectionSocket , ) 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 SocketConnection = SocketConnection (ForeignPtr SocketConnection) foreign import ccall "g_socket_connection_get_type" c_g_socket_connection_get_type :: IO GType type instance ParentTypes SocketConnection = SocketConnectionParentTypes type SocketConnectionParentTypes = '[IOStream, GObject.Object] instance GObject SocketConnection where gobjectIsInitiallyUnowned _ = False gobjectType _ = c_g_socket_connection_get_type class GObject o => SocketConnectionK o instance (GObject o, IsDescendantOf SocketConnection o) => SocketConnectionK o toSocketConnection :: SocketConnectionK o => o -> IO SocketConnection toSocketConnection = unsafeCastTo SocketConnection noSocketConnection :: Maybe SocketConnection noSocketConnection = Nothing -- VVV Prop "socket" -- Type: TInterface "Gio" "Socket" -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly] getSocketConnectionSocket :: (MonadIO m, SocketConnectionK o) => o -> m Socket getSocketConnectionSocket obj = liftIO $ getObjectPropertyObject obj "socket" Socket constructSocketConnectionSocket :: (SocketK a) => a -> IO ([Char], GValue) constructSocketConnectionSocket val = constructObjectPropertyObject "socket" val data SocketConnectionSocketPropertyInfo instance AttrInfo SocketConnectionSocketPropertyInfo where type AttrAllowedOps SocketConnectionSocketPropertyInfo = '[ 'AttrConstruct, 'AttrGet] type AttrSetTypeConstraint SocketConnectionSocketPropertyInfo = SocketK type AttrBaseTypeConstraint SocketConnectionSocketPropertyInfo = SocketConnectionK type AttrGetType SocketConnectionSocketPropertyInfo = Socket type AttrLabel SocketConnectionSocketPropertyInfo = "SocketConnection::socket" attrGet _ = getSocketConnectionSocket attrSet _ = undefined attrConstruct _ = constructSocketConnectionSocket type instance AttributeList SocketConnection = SocketConnectionAttributeList type SocketConnectionAttributeList = ('[ '("closed", IOStreamClosedPropertyInfo), '("input-stream", IOStreamInputStreamPropertyInfo), '("output-stream", IOStreamOutputStreamPropertyInfo), '("socket", SocketConnectionSocketPropertyInfo)] :: [(Symbol, *)]) type instance SignalList SocketConnection = SocketConnectionSignalList type SocketConnectionSignalList = ('[ '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)]) -- method SocketConnection::connect -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "address", argType = TInterface "Gio" "SocketAddress", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "address", argType = TInterface "Gio" "SocketAddress", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TBasicType TBoolean -- throws : True -- Skip return : False foreign import ccall "g_socket_connection_connect" g_socket_connection_connect :: Ptr SocketConnection -> -- _obj : TInterface "Gio" "SocketConnection" Ptr SocketAddress -> -- address : TInterface "Gio" "SocketAddress" Ptr Cancellable -> -- cancellable : TInterface "Gio" "Cancellable" Ptr (Ptr GError) -> -- error IO CInt socketConnectionConnect :: (MonadIO m, SocketConnectionK a, SocketAddressK b, CancellableK c) => a -> -- _obj b -> -- address Maybe (c) -> -- cancellable m () socketConnectionConnect _obj address cancellable = liftIO $ do let _obj' = unsafeManagedPtrCastPtr _obj let address' = unsafeManagedPtrCastPtr address maybeCancellable <- case cancellable of Nothing -> return nullPtr Just jCancellable -> do let jCancellable' = unsafeManagedPtrCastPtr jCancellable return jCancellable' onException (do _ <- propagateGError $ g_socket_connection_connect _obj' address' maybeCancellable touchManagedPtr _obj touchManagedPtr address whenJust cancellable touchManagedPtr return () ) (do return () ) -- method SocketConnection::connect_async -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "address", argType = TInterface "Gio" "SocketAddress", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "callback", argType = TInterface "Gio" "AsyncReadyCallback", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeAsync, argClosure = 4, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user_data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "address", argType = TInterface "Gio" "SocketAddress", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "callback", argType = TInterface "Gio" "AsyncReadyCallback", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeAsync, argClosure = 4, argDestroy = -1, transfer = TransferNothing}] -- returnType : TBasicType TVoid -- throws : False -- Skip return : False foreign import ccall "g_socket_connection_connect_async" g_socket_connection_connect_async :: Ptr SocketConnection -> -- _obj : TInterface "Gio" "SocketConnection" Ptr SocketAddress -> -- address : TInterface "Gio" "SocketAddress" Ptr Cancellable -> -- cancellable : TInterface "Gio" "Cancellable" FunPtr AsyncReadyCallbackC -> -- callback : TInterface "Gio" "AsyncReadyCallback" Ptr () -> -- user_data : TBasicType TVoid IO () socketConnectionConnectAsync :: (MonadIO m, SocketConnectionK a, SocketAddressK b, CancellableK c) => a -> -- _obj b -> -- address Maybe (c) -> -- cancellable Maybe (AsyncReadyCallback) -> -- callback m () socketConnectionConnectAsync _obj address cancellable callback = liftIO $ do let _obj' = unsafeManagedPtrCastPtr _obj let address' = unsafeManagedPtrCastPtr address maybeCancellable <- case cancellable of Nothing -> return nullPtr Just jCancellable -> do let jCancellable' = unsafeManagedPtrCastPtr jCancellable return jCancellable' ptrcallback <- callocMem :: IO (Ptr (FunPtr AsyncReadyCallbackC)) maybeCallback <- case callback of Nothing -> return (castPtrToFunPtr nullPtr) Just jCallback -> do jCallback' <- mkAsyncReadyCallback (asyncReadyCallbackWrapper (Just ptrcallback) jCallback) poke ptrcallback jCallback' return jCallback' let user_data = nullPtr g_socket_connection_connect_async _obj' address' maybeCancellable maybeCallback user_data touchManagedPtr _obj touchManagedPtr address whenJust cancellable touchManagedPtr return () -- method SocketConnection::connect_finish -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "result", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "result", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TBasicType TBoolean -- throws : True -- Skip return : False foreign import ccall "g_socket_connection_connect_finish" g_socket_connection_connect_finish :: Ptr SocketConnection -> -- _obj : TInterface "Gio" "SocketConnection" Ptr AsyncResult -> -- result : TInterface "Gio" "AsyncResult" Ptr (Ptr GError) -> -- error IO CInt socketConnectionConnectFinish :: (MonadIO m, SocketConnectionK a, AsyncResultK b) => a -> -- _obj b -> -- result m () socketConnectionConnectFinish _obj result_ = liftIO $ do let _obj' = unsafeManagedPtrCastPtr _obj let result_' = unsafeManagedPtrCastPtr result_ onException (do _ <- propagateGError $ g_socket_connection_connect_finish _obj' result_' touchManagedPtr _obj touchManagedPtr result_ return () ) (do return () ) -- method SocketConnection::get_local_address -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TInterface "Gio" "SocketAddress" -- throws : True -- Skip return : False foreign import ccall "g_socket_connection_get_local_address" g_socket_connection_get_local_address :: Ptr SocketConnection -> -- _obj : TInterface "Gio" "SocketConnection" Ptr (Ptr GError) -> -- error IO (Ptr SocketAddress) socketConnectionGetLocalAddress :: (MonadIO m, SocketConnectionK a) => a -> -- _obj m SocketAddress socketConnectionGetLocalAddress _obj = liftIO $ do let _obj' = unsafeManagedPtrCastPtr _obj onException (do result <- propagateGError $ g_socket_connection_get_local_address _obj' checkUnexpectedReturnNULL "g_socket_connection_get_local_address" result result' <- (wrapObject SocketAddress) result touchManagedPtr _obj return result' ) (do return () ) -- method SocketConnection::get_remote_address -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TInterface "Gio" "SocketAddress" -- throws : True -- Skip return : False foreign import ccall "g_socket_connection_get_remote_address" g_socket_connection_get_remote_address :: Ptr SocketConnection -> -- _obj : TInterface "Gio" "SocketConnection" Ptr (Ptr GError) -> -- error IO (Ptr SocketAddress) socketConnectionGetRemoteAddress :: (MonadIO m, SocketConnectionK a) => a -> -- _obj m SocketAddress socketConnectionGetRemoteAddress _obj = liftIO $ do let _obj' = unsafeManagedPtrCastPtr _obj onException (do result <- propagateGError $ g_socket_connection_get_remote_address _obj' checkUnexpectedReturnNULL "g_socket_connection_get_remote_address" result result' <- (wrapObject SocketAddress) result touchManagedPtr _obj return result' ) (do return () ) -- method SocketConnection::get_socket -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TInterface "Gio" "Socket" -- throws : False -- Skip return : False foreign import ccall "g_socket_connection_get_socket" g_socket_connection_get_socket :: Ptr SocketConnection -> -- _obj : TInterface "Gio" "SocketConnection" IO (Ptr Socket) socketConnectionGetSocket :: (MonadIO m, SocketConnectionK a) => a -> -- _obj m Socket socketConnectionGetSocket _obj = liftIO $ do let _obj' = unsafeManagedPtrCastPtr _obj result <- g_socket_connection_get_socket _obj' checkUnexpectedReturnNULL "g_socket_connection_get_socket" result result' <- (newObject Socket) result touchManagedPtr _obj return result' -- method SocketConnection::is_connected -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "SocketConnection", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TBasicType TBoolean -- throws : False -- Skip return : False foreign import ccall "g_socket_connection_is_connected" g_socket_connection_is_connected :: Ptr SocketConnection -> -- _obj : TInterface "Gio" "SocketConnection" IO CInt socketConnectionIsConnected :: (MonadIO m, SocketConnectionK a) => a -> -- _obj m Bool socketConnectionIsConnected _obj = liftIO $ do let _obj' = unsafeManagedPtrCastPtr _obj result <- g_socket_connection_is_connected _obj' let result' = (/= 0) result touchManagedPtr _obj return result' -- method SocketConnection::factory_lookup_type -- method type : MemberFunction -- Args : [Arg {argName = "family", argType = TInterface "Gio" "SocketFamily", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "type", argType = TInterface "Gio" "SocketType", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "protocol_id", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "family", argType = TInterface "Gio" "SocketFamily", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "type", argType = TInterface "Gio" "SocketType", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "protocol_id", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TBasicType TGType -- throws : False -- Skip return : False foreign import ccall "g_socket_connection_factory_lookup_type" g_socket_connection_factory_lookup_type :: CUInt -> -- family : TInterface "Gio" "SocketFamily" CUInt -> -- type : TInterface "Gio" "SocketType" Int32 -> -- protocol_id : TBasicType TInt32 IO CGType socketConnectionFactoryLookupType :: (MonadIO m) => SocketFamily -> -- family SocketType -> -- type Int32 -> -- protocol_id m GType socketConnectionFactoryLookupType family type_ protocol_id = liftIO $ do let family' = (fromIntegral . fromEnum) family let type_' = (fromIntegral . fromEnum) type_ result <- g_socket_connection_factory_lookup_type family' type_' protocol_id let result' = GType result return result' -- method SocketConnection::factory_register_type -- method type : MemberFunction -- Args : [Arg {argName = "g_type", argType = TBasicType TGType, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "family", argType = TInterface "Gio" "SocketFamily", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "type", argType = TInterface "Gio" "SocketType", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "protocol", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "g_type", argType = TBasicType TGType, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "family", argType = TInterface "Gio" "SocketFamily", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "type", argType = TInterface "Gio" "SocketType", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "protocol", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TBasicType TVoid -- throws : False -- Skip return : False foreign import ccall "g_socket_connection_factory_register_type" g_socket_connection_factory_register_type :: CGType -> -- g_type : TBasicType TGType CUInt -> -- family : TInterface "Gio" "SocketFamily" CUInt -> -- type : TInterface "Gio" "SocketType" Int32 -> -- protocol : TBasicType TInt32 IO () socketConnectionFactoryRegisterType :: (MonadIO m) => GType -> -- g_type SocketFamily -> -- family SocketType -> -- type Int32 -> -- protocol m () socketConnectionFactoryRegisterType g_type family type_ protocol = liftIO $ do let g_type' = gtypeToCGType g_type let family' = (fromIntegral . fromEnum) family let type_' = (fromIntegral . fromEnum) type_ g_socket_connection_factory_register_type g_type' family' type_' protocol return ()