{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- The WpPort class allows accessing the properties and methods of a PipeWire port object (struct pw_port).
-- A WpPort is constructed internally when a new port appears on the PipeWire registry and it is made available through the WpObjectManager API.

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

module GI.Wp.Objects.Port
    ( 

-- * Exported types
    Port(..)                                ,
    IsPort                                  ,
    toPort                                  ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [abortActivation]("GI.Wp.Objects.Object#g:method:abortActivation"), [activate]("GI.Wp.Objects.Object#g:method:activate"), [activateClosure]("GI.Wp.Objects.Object#g:method:activateClosure"), [activateFinish]("GI.Wp.Objects.Object#g:method:activateFinish"), [bind]("GI.Wp.Objects.GlobalProxy#g:method:bind"), [bindProperty]("GI.GObject.Objects.Object#g:method:bindProperty"), [bindPropertyFull]("GI.GObject.Objects.Object#g:method:bindPropertyFull"), [deactivate]("GI.Wp.Objects.Object#g:method:deactivate"), [enumParams]("GI.Wp.Interfaces.PipewireObject#g:method:enumParams"), [enumParamsFinish]("GI.Wp.Interfaces.PipewireObject#g:method:enumParamsFinish"), [enumParamsSync]("GI.Wp.Interfaces.PipewireObject#g:method:enumParamsSync"), [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"), [newPropertiesIterator]("GI.Wp.Interfaces.PipewireObject#g:method:newPropertiesIterator"), [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"), [requestDestroy]("GI.Wp.Objects.GlobalProxy#g:method:requestDestroy"), [runDispose]("GI.GObject.Objects.Object#g:method:runDispose"), [stealData]("GI.GObject.Objects.Object#g:method:stealData"), [stealQdata]("GI.GObject.Objects.Object#g:method:stealQdata"), [testActiveFeatures]("GI.Wp.Objects.Object#g:method:testActiveFeatures"), [testSupportedFeatures]("GI.Wp.Objects.Object#g:method:testSupportedFeatures"), [thawNotify]("GI.GObject.Objects.Object#g:method:thawNotify"), [unref]("GI.GObject.Objects.Object#g:method:unref"), [updateFeatures]("GI.Wp.Objects.Object#g:method:updateFeatures"), [watchClosure]("GI.GObject.Objects.Object#g:method:watchClosure").
-- 
-- ==== Getters
-- [getActiveFeatures]("GI.Wp.Objects.Object#g:method:getActiveFeatures"), [getBoundId]("GI.Wp.Objects.Proxy#g:method:getBoundId"), [getCore]("GI.Wp.Objects.Object#g:method:getCore"), [getData]("GI.GObject.Objects.Object#g:method:getData"), [getDirection]("GI.Wp.Objects.Port#g:method:getDirection"), [getGlobalProperties]("GI.Wp.Objects.GlobalProxy#g:method:getGlobalProperties"), [getId]("GI.Wp.Objects.Object#g:method:getId"), [getInterfaceType]("GI.Wp.Objects.Proxy#g:method:getInterfaceType"), [getNativeInfo]("GI.Wp.Interfaces.PipewireObject#g:method:getNativeInfo"), [getParamInfo]("GI.Wp.Interfaces.PipewireObject#g:method:getParamInfo"), [getPermissions]("GI.Wp.Objects.GlobalProxy#g:method:getPermissions"), [getProperties]("GI.Wp.Interfaces.PipewireObject#g:method:getProperties"), [getProperty]("GI.GObject.Objects.Object#g:method:getProperty"), [getPwProxy]("GI.Wp.Objects.Proxy#g:method:getPwProxy"), [getQdata]("GI.GObject.Objects.Object#g:method:getQdata"), [getSupportedFeatures]("GI.Wp.Objects.Object#g:method:getSupportedFeatures").
-- 
-- ==== Setters
-- [setData]("GI.GObject.Objects.Object#g:method:setData"), [setDataFull]("GI.GObject.Objects.Object#g:method:setDataFull"), [setParam]("GI.Wp.Interfaces.PipewireObject#g:method:setParam"), [setProperty]("GI.GObject.Objects.Object#g:method:setProperty"), [setPwProxy]("GI.Wp.Objects.Proxy#g:method:setPwProxy").

#if defined(ENABLE_OVERLOADING)
    ResolvePortMethod                       ,
#endif

-- ** getDirection #method:getDirection#

#if defined(ENABLE_OVERLOADING)
    PortGetDirectionMethodInfo              ,
#endif
    portGetDirection                        ,




    ) 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.MainContext as GLib.MainContext
import qualified GI.GLib.Structs.Source as GLib.Source
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Callbacks as Gio.Callbacks
import qualified GI.Gio.Interfaces.AsyncResult as Gio.AsyncResult
import qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
import qualified GI.Wp.Callbacks as Wp.Callbacks
import {-# SOURCE #-} qualified GI.Wp.Enums as Wp.Enums
import {-# SOURCE #-} qualified GI.Wp.Flags as Wp.Flags
import {-# SOURCE #-} qualified GI.Wp.Interfaces.PipewireObject as Wp.PipewireObject
import {-# SOURCE #-} qualified GI.Wp.Objects.Conf as Wp.Conf
import {-# SOURCE #-} qualified GI.Wp.Objects.Core as Wp.Core
import {-# SOURCE #-} qualified GI.Wp.Objects.GlobalProxy as Wp.GlobalProxy
import {-# SOURCE #-} qualified GI.Wp.Objects.Object as Wp.Object
import {-# SOURCE #-} qualified GI.Wp.Objects.ObjectManager as Wp.ObjectManager
import {-# SOURCE #-} qualified GI.Wp.Objects.Proxy as Wp.Proxy
import {-# SOURCE #-} qualified GI.Wp.Objects.SpaType as Wp.SpaType
import {-# SOURCE #-} qualified GI.Wp.Structs.Iterator as Wp.Iterator
import {-# SOURCE #-} qualified GI.Wp.Structs.IteratorMethods as Wp.IteratorMethods
import {-# SOURCE #-} qualified GI.Wp.Structs.ObjectInterest as Wp.ObjectInterest
import {-# SOURCE #-} qualified GI.Wp.Structs.Properties as Wp.Properties
import {-# SOURCE #-} qualified GI.Wp.Structs.SpaJson as Wp.SpaJson
import {-# SOURCE #-} qualified GI.Wp.Structs.SpaPod as Wp.SpaPod

#else
import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Wp.Enums as Wp.Enums
import {-# SOURCE #-} qualified GI.Wp.Interfaces.PipewireObject as Wp.PipewireObject
import {-# SOURCE #-} qualified GI.Wp.Objects.GlobalProxy as Wp.GlobalProxy
import {-# SOURCE #-} qualified GI.Wp.Objects.Object as Wp.Object
import {-# SOURCE #-} qualified GI.Wp.Objects.Proxy as Wp.Proxy

#endif

-- | Memory-managed wrapper type.
newtype Port = Port (SP.ManagedPtr Port)
    deriving (Eq)

instance SP.ManagedPtrNewtype Port where
    toManagedPtr (Port p) = p

foreign import ccall "wp_port_get_type"
    c_wp_port_get_type :: IO B.Types.GType

instance B.Types.TypedObject Port where
    glibType = c_wp_port_get_type

instance B.Types.GObject Port

-- | Type class for types which can be safely cast to t'Port', for instance with `toPort`.
class (SP.GObject o, O.IsDescendantOf Port o) => IsPort o
instance (SP.GObject o, O.IsDescendantOf Port o) => IsPort o

instance O.HasParentTypes Port
type instance O.ParentTypes Port = '[Wp.GlobalProxy.GlobalProxy, Wp.Proxy.Proxy, Wp.Object.Object, GObject.Object.Object, Wp.PipewireObject.PipewireObject]

-- | Cast to t'Port', for types for which this is known to be safe. For general casts, use 'Data.GI.Base.ManagedPtr.castTo'.
toPort :: (MIO.MonadIO m, IsPort o) => o -> m Port
toPort = MIO.liftIO . B.ManagedPtr.unsafeCastTo Port

-- | Convert t'Port' to and from t'Data.GI.Base.GValue.GValue'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue (Maybe Port) where
    gvalueGType_ = c_wp_port_get_type
    gvalueSet_ gv P.Nothing = B.GValue.set_object gv (FP.nullPtr :: FP.Ptr Port)
    gvalueSet_ gv (P.Just obj) = B.ManagedPtr.withManagedPtr obj (B.GValue.set_object gv)
    gvalueGet_ gv = do
        ptr <- B.GValue.get_object gv :: IO (FP.Ptr Port)
        if ptr /= FP.nullPtr
        then P.Just <$> B.ManagedPtr.newObject Port ptr
        else return P.Nothing
        
    

#if defined(ENABLE_OVERLOADING)
type family ResolvePortMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolvePortMethod "abortActivation" o = Wp.Object.ObjectAbortActivationMethodInfo
    ResolvePortMethod "activate" o = Wp.Object.ObjectActivateMethodInfo
    ResolvePortMethod "activateClosure" o = Wp.Object.ObjectActivateClosureMethodInfo
    ResolvePortMethod "activateFinish" o = Wp.Object.ObjectActivateFinishMethodInfo
    ResolvePortMethod "bind" o = Wp.GlobalProxy.GlobalProxyBindMethodInfo
    ResolvePortMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolvePortMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolvePortMethod "deactivate" o = Wp.Object.ObjectDeactivateMethodInfo
    ResolvePortMethod "enumParams" o = Wp.PipewireObject.PipewireObjectEnumParamsMethodInfo
    ResolvePortMethod "enumParamsFinish" o = Wp.PipewireObject.PipewireObjectEnumParamsFinishMethodInfo
    ResolvePortMethod "enumParamsSync" o = Wp.PipewireObject.PipewireObjectEnumParamsSyncMethodInfo
    ResolvePortMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolvePortMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolvePortMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolvePortMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolvePortMethod "newPropertiesIterator" o = Wp.PipewireObject.PipewireObjectNewPropertiesIteratorMethodInfo
    ResolvePortMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolvePortMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolvePortMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolvePortMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolvePortMethod "requestDestroy" o = Wp.GlobalProxy.GlobalProxyRequestDestroyMethodInfo
    ResolvePortMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolvePortMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolvePortMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolvePortMethod "testActiveFeatures" o = Wp.Object.ObjectTestActiveFeaturesMethodInfo
    ResolvePortMethod "testSupportedFeatures" o = Wp.Object.ObjectTestSupportedFeaturesMethodInfo
    ResolvePortMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolvePortMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolvePortMethod "updateFeatures" o = Wp.Object.ObjectUpdateFeaturesMethodInfo
    ResolvePortMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolvePortMethod "getActiveFeatures" o = Wp.Object.ObjectGetActiveFeaturesMethodInfo
    ResolvePortMethod "getBoundId" o = Wp.Proxy.ProxyGetBoundIdMethodInfo
    ResolvePortMethod "getCore" o = Wp.Object.ObjectGetCoreMethodInfo
    ResolvePortMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolvePortMethod "getDirection" o = PortGetDirectionMethodInfo
    ResolvePortMethod "getGlobalProperties" o = Wp.GlobalProxy.GlobalProxyGetGlobalPropertiesMethodInfo
    ResolvePortMethod "getId" o = Wp.Object.ObjectGetIdMethodInfo
    ResolvePortMethod "getInterfaceType" o = Wp.Proxy.ProxyGetInterfaceTypeMethodInfo
    ResolvePortMethod "getNativeInfo" o = Wp.PipewireObject.PipewireObjectGetNativeInfoMethodInfo
    ResolvePortMethod "getParamInfo" o = Wp.PipewireObject.PipewireObjectGetParamInfoMethodInfo
    ResolvePortMethod "getPermissions" o = Wp.GlobalProxy.GlobalProxyGetPermissionsMethodInfo
    ResolvePortMethod "getProperties" o = Wp.PipewireObject.PipewireObjectGetPropertiesMethodInfo
    ResolvePortMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolvePortMethod "getPwProxy" o = Wp.Proxy.ProxyGetPwProxyMethodInfo
    ResolvePortMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolvePortMethod "getSupportedFeatures" o = Wp.Object.ObjectGetSupportedFeaturesMethodInfo
    ResolvePortMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolvePortMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolvePortMethod "setParam" o = Wp.PipewireObject.PipewireObjectSetParamMethodInfo
    ResolvePortMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolvePortMethod "setPwProxy" o = Wp.Proxy.ProxySetPwProxyMethodInfo
    ResolvePortMethod l o = O.MethodResolutionFailed l o

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

#endif

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

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Port
type instance O.AttributeList Port = PortAttributeList
type PortAttributeList = ('[ '("activeFeatures", Wp.Object.ObjectActiveFeaturesPropertyInfo), '("boundId", Wp.Proxy.ProxyBoundIdPropertyInfo), '("core", Wp.Object.ObjectCorePropertyInfo), '("factoryName", Wp.GlobalProxy.GlobalProxyFactoryNamePropertyInfo), '("globalProperties", Wp.GlobalProxy.GlobalProxyGlobalPropertiesPropertyInfo), '("id", Wp.Object.ObjectIdPropertyInfo), '("nativeInfo", Wp.PipewireObject.PipewireObjectNativeInfoPropertyInfo), '("paramInfo", Wp.PipewireObject.PipewireObjectParamInfoPropertyInfo), '("permissions", Wp.GlobalProxy.GlobalProxyPermissionsPropertyInfo), '("properties", Wp.PipewireObject.PipewireObjectPropertiesPropertyInfo), '("pwProxy", Wp.Proxy.ProxyPwProxyPropertyInfo), '("supportedFeatures", Wp.Object.ObjectSupportedFeaturesPropertyInfo)] :: [(Symbol, DK.Type)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList Port = PortSignalList
type PortSignalList = ('[ '("bound", Wp.Proxy.ProxyBoundSignalInfo), '("error", Wp.Proxy.ProxyErrorSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo), '("paramsChanged", Wp.PipewireObject.PipewireObjectParamsChangedSignalInfo), '("pwProxyCreated", Wp.Proxy.ProxyPwProxyCreatedSignalInfo), '("pwProxyDestroyed", Wp.Proxy.ProxyPwProxyDestroyedSignalInfo)] :: [(Symbol, DK.Type)])

#endif

-- method Port::get_direction
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType = TInterface Name { namespace = "Wp" , name = "Port" }
--           , argCType = Just "WpPort*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the port" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Wp" , name = "Direction" })
-- throws : False
-- Skip return : False

foreign import ccall "wp_port_get_direction" wp_port_get_direction :: 
    Ptr Port ->                             -- self : TInterface (Name {namespace = "Wp", name = "Port"})
    IO CUInt

-- | Gets the current direction of the port.
-- 
-- 
-- Requires WP_PIPEWIRE_OBJECT_FEATURE_INFO
portGetDirection ::
    (B.CallStack.HasCallStack, MonadIO m, IsPort a) =>
    a
    -- ^ /@self@/: the port
    -> m Wp.Enums.Direction
    -- ^ __Returns:__ the current direction of the port
portGetDirection self = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    result <- wp_port_get_direction self'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr self
    return result'

#if defined(ENABLE_OVERLOADING)
data PortGetDirectionMethodInfo
instance (signature ~ (m Wp.Enums.Direction), MonadIO m, IsPort a) => O.OverloadedMethod PortGetDirectionMethodInfo a signature where
    overloadedMethod = portGetDirection

instance O.OverloadedMethodInfo PortGetDirectionMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Objects.Port.portGetDirection",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Objects-Port.html#v:portGetDirection"
        })


#endif


