packages feed

gi-wireplumber-0.5.14: GI/Wp/Objects/Device.hs

{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- The WpDevice class allows accessing the properties and methods of a PipeWire device object (struct pw_device).
-- A WpDevice is constructed internally when a new device appears on the PipeWire registry and it is made available through the WpObjectManager API. Alternatively, a WpDevice can also be constructed using 'GI.Wp.Objects.Device.deviceNewFromFactory', which creates a new device object on the remote PipeWire server by calling into a factory.

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

module GI.Wp.Objects.Device
    ( 

-- * Exported types
    Device(..)                              ,
    IsDevice                                ,
    toDevice                                ,


 -- * 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"), [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)
    ResolveDeviceMethod                     ,
#endif

-- ** newFromFactory #method:newFromFactory#

    deviceNewFromFactory                    ,




    ) 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.Interfaces.PipewireObject as Wp.PipewireObject
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.Proxy as Wp.Proxy
import {-# SOURCE #-} qualified GI.Wp.Structs.Properties as Wp.Properties

#endif

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

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

foreign import ccall "wp_device_get_type"
    c_wp_device_get_type :: IO B.Types.GType

instance B.Types.TypedObject Device where
    glibType = c_wp_device_get_type

instance B.Types.GObject Device

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

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

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

-- | Convert t'Device' 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 Device) where
    gvalueGType_ = c_wp_device_get_type
    gvalueSet_ gv P.Nothing = B.GValue.set_object gv (FP.nullPtr :: FP.Ptr Device)
    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 Device)
        if ptr /= FP.nullPtr
        then P.Just <$> B.ManagedPtr.newObject Device ptr
        else return P.Nothing
        
    

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

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

#endif

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

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Device
type instance O.AttributeList Device = DeviceAttributeList
type DeviceAttributeList = ('[ '("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 Device = DeviceSignalList
type DeviceSignalList = ('[ '("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 Device::new_from_factory
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "core"
--           , argType = TInterface Name { namespace = "Wp" , name = "Core" }
--           , argCType = Just "WpCore*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the wireplumber core"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "factory_name"
--           , argType = TBasicType TUTF8
--           , argCType = Just "const gchar*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "the pipewire factory name to construct the device"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "properties"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "Properties" }
--           , argCType = Just "WpProperties*"
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the properties to pass to the factory"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Wp" , name = "Device" })
-- throws : False
-- Skip return : False

foreign import ccall "wp_device_new_from_factory" wp_device_new_from_factory :: 
    Ptr Wp.Core.Core ->                     -- core : TInterface (Name {namespace = "Wp", name = "Core"})
    CString ->                              -- factory_name : TBasicType TUTF8
    Ptr Wp.Properties.Properties ->         -- properties : TInterface (Name {namespace = "Wp", name = "Properties"})
    IO (Ptr Device)

-- | Constructs a device on the PipeWire server by asking the remote factory /@factoryName@/ to create it.
-- 
-- 
-- Because of the nature of the PipeWire protocol, this operation completes asynchronously at some point in the future. In order to find out when this is done, you should call 'GI.Wp.Objects.Object.objectActivate', requesting at least WP_PROXY_FEATURE_BOUND. When this feature is ready, the device is ready for use on the server. If the device cannot be created, this activation operation will fail.
deviceNewFromFactory ::
    (B.CallStack.HasCallStack, MonadIO m, Wp.Core.IsCore a) =>
    a
    -- ^ /@core@/: the wireplumber core
    -> T.Text
    -- ^ /@factoryName@/: the pipewire factory name to construct the device
    -> Maybe (Wp.Properties.Properties)
    -- ^ /@properties@/: the properties to pass to the factory
    -> m (Maybe Device)
    -- ^ __Returns:__ the new device or NULL if the core is not connected and therefore the device cannot be created
deviceNewFromFactory core factoryName properties = liftIO $ do
    core' <- unsafeManagedPtrCastPtr core
    factoryName' <- textToCString factoryName
    maybeProperties <- case properties of
        Nothing -> return FP.nullPtr
        Just jProperties -> do
            jProperties' <- B.ManagedPtr.disownBoxed jProperties
            return jProperties'
    result <- wp_device_new_from_factory core' factoryName' maybeProperties
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject Device) result'
        return result''
    touchManagedPtr core
    whenJust properties touchManagedPtr
    freeMem factoryName'
    return maybeResult

#if defined(ENABLE_OVERLOADING)
#endif