packages feed

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

{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- WpPlugin is a base class for objects that provide functionality to the WirePlumber daemon.
-- Typically, a plugin is created within a module and then registered to make it available for use by the daemon. The daemon is responsible for calling 'GI.Wp.Objects.Object.objectActivate' on it after all modules have been loaded, the core is connected and the initial discovery of global objects is done.
-- Being a WpObject subclass, the plugin inherits WpObject\'s activation system. For most implementations, there is only need for activating one feature, WP_PLUGIN_FEATURE_ENABLED, and this can be done by implementing only WpPluginClass[enable](#g:signal:enable)() and WpPluginClass[disable](#g:signal:disable)(). For more advanced plugins that need to have more features, you may implement directly the functions of WpObjectClass and ignore the ones of WpPluginClass.

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

module GI.Wp.Objects.Plugin
    ( 

-- * Exported types
    Plugin(..)                              ,
    IsPlugin                                ,
    toPlugin                                ,


 -- * 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"), [bindProperty]("GI.GObject.Objects.Object#g:method:bindProperty"), [bindPropertyFull]("GI.GObject.Objects.Object#g:method:bindPropertyFull"), [deactivate]("GI.Wp.Objects.Object#g:method:deactivate"), [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"), [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"), [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"), [getCore]("GI.Wp.Objects.Object#g:method:getCore"), [getData]("GI.GObject.Objects.Object#g:method:getData"), [getId]("GI.Wp.Objects.Object#g:method:getId"), [getName]("GI.Wp.Objects.Plugin#g:method:getName"), [getProperty]("GI.GObject.Objects.Object#g:method:getProperty"), [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"), [setProperty]("GI.GObject.Objects.Object#g:method:setProperty").

#if defined(ENABLE_OVERLOADING)
    ResolvePluginMethod                     ,
#endif

-- ** find #method:find#

    pluginFind                              ,


-- ** getName #method:getName#

#if defined(ENABLE_OVERLOADING)
    PluginGetNameMethodInfo                 ,
#endif
    pluginGetName                           ,




 -- * Properties


-- ** name #attr:name#
-- | /No description available in the introspection data./

#if defined(ENABLE_OVERLOADING)
    PluginNamePropertyInfo                  ,
#endif
    constructPluginName                     ,
    getPluginName                           ,
#if defined(ENABLE_OVERLOADING)
    pluginName                              ,
#endif




    ) 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.Objects.Conf as Wp.Conf
import {-# SOURCE #-} qualified GI.Wp.Objects.Core as Wp.Core
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.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

#else
import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Wp.Objects.Core as Wp.Core
import {-# SOURCE #-} qualified GI.Wp.Objects.Object as Wp.Object

#endif

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

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

foreign import ccall "wp_plugin_get_type"
    c_wp_plugin_get_type :: IO B.Types.GType

instance B.Types.TypedObject Plugin where
    glibType = c_wp_plugin_get_type

instance B.Types.GObject Plugin

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

instance O.HasParentTypes Plugin
type instance O.ParentTypes Plugin = '[Wp.Object.Object, GObject.Object.Object]

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

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

#if defined(ENABLE_OVERLOADING)
type family ResolvePluginMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolvePluginMethod "abortActivation" o = Wp.Object.ObjectAbortActivationMethodInfo
    ResolvePluginMethod "activate" o = Wp.Object.ObjectActivateMethodInfo
    ResolvePluginMethod "activateClosure" o = Wp.Object.ObjectActivateClosureMethodInfo
    ResolvePluginMethod "activateFinish" o = Wp.Object.ObjectActivateFinishMethodInfo
    ResolvePluginMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolvePluginMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolvePluginMethod "deactivate" o = Wp.Object.ObjectDeactivateMethodInfo
    ResolvePluginMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolvePluginMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolvePluginMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolvePluginMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolvePluginMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolvePluginMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolvePluginMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolvePluginMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolvePluginMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolvePluginMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolvePluginMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolvePluginMethod "testActiveFeatures" o = Wp.Object.ObjectTestActiveFeaturesMethodInfo
    ResolvePluginMethod "testSupportedFeatures" o = Wp.Object.ObjectTestSupportedFeaturesMethodInfo
    ResolvePluginMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolvePluginMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolvePluginMethod "updateFeatures" o = Wp.Object.ObjectUpdateFeaturesMethodInfo
    ResolvePluginMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolvePluginMethod "getActiveFeatures" o = Wp.Object.ObjectGetActiveFeaturesMethodInfo
    ResolvePluginMethod "getCore" o = Wp.Object.ObjectGetCoreMethodInfo
    ResolvePluginMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolvePluginMethod "getId" o = Wp.Object.ObjectGetIdMethodInfo
    ResolvePluginMethod "getName" o = PluginGetNameMethodInfo
    ResolvePluginMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolvePluginMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolvePluginMethod "getSupportedFeatures" o = Wp.Object.ObjectGetSupportedFeaturesMethodInfo
    ResolvePluginMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolvePluginMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolvePluginMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolvePluginMethod l o = O.MethodResolutionFailed l o

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

#endif

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

#endif

-- VVV Prop "name"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

-- | Get the value of the “@name@” property.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Attributes.get' plugin #name
-- @
getPluginName :: (MonadIO m, IsPlugin o) => o -> m T.Text
getPluginName obj = MIO.liftIO $ checkUnexpectedNothing "getPluginName" $ B.Properties.getObjectPropertyString obj "name"

-- | Construct a t'GValueConstruct' with valid value for the “@name@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
constructPluginName :: (IsPlugin o, MIO.MonadIO m) => T.Text -> m (GValueConstruct o)
constructPluginName val = MIO.liftIO $ do
    MIO.liftIO $ B.Properties.constructObjectPropertyString "name" (P.Just val)

#if defined(ENABLE_OVERLOADING)
data PluginNamePropertyInfo
instance AttrInfo PluginNamePropertyInfo where
    type AttrAllowedOps PluginNamePropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrBaseTypeConstraint PluginNamePropertyInfo = IsPlugin
    type AttrSetTypeConstraint PluginNamePropertyInfo = (~) T.Text
    type AttrTransferTypeConstraint PluginNamePropertyInfo = (~) T.Text
    type AttrTransferType PluginNamePropertyInfo = T.Text
    type AttrGetType PluginNamePropertyInfo = T.Text
    type AttrLabel PluginNamePropertyInfo = "name"
    type AttrOrigin PluginNamePropertyInfo = Plugin
    attrGet = getPluginName
    attrSet = undefined
    attrPut = undefined
    attrTransfer _ v = do
        return v
    attrConstruct = constructPluginName
    attrClear = undefined
    dbgAttrInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Objects.Plugin.name"
        , O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14/docs/GI-Wp-Objects-Plugin.html#g:attr:name"
        })
#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Plugin
type instance O.AttributeList Plugin = PluginAttributeList
type PluginAttributeList = ('[ '("activeFeatures", Wp.Object.ObjectActiveFeaturesPropertyInfo), '("core", Wp.Object.ObjectCorePropertyInfo), '("id", Wp.Object.ObjectIdPropertyInfo), '("name", PluginNamePropertyInfo), '("supportedFeatures", Wp.Object.ObjectSupportedFeaturesPropertyInfo)] :: [(Symbol, DK.Type)])
#endif

#if defined(ENABLE_OVERLOADING)
pluginName :: AttrLabelProxy "name"
pluginName = AttrLabelProxy

#endif

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

#endif

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

foreign import ccall "wp_plugin_get_name" wp_plugin_get_name :: 
    Ptr Plugin ->                           -- self : TInterface (Name {namespace = "Wp", name = "Plugin"})
    IO CString

-- | Retrieves the name of a plugin.
pluginGetName ::
    (B.CallStack.HasCallStack, MonadIO m, IsPlugin a) =>
    a
    -- ^ /@self@/: the plugin
    -> m T.Text
    -- ^ __Returns:__ the name of this plugin
pluginGetName self = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    result <- wp_plugin_get_name self'
    checkUnexpectedReturnNULL "pluginGetName" result
    result' <- cstringToText result
    touchManagedPtr self
    return result'

#if defined(ENABLE_OVERLOADING)
data PluginGetNameMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsPlugin a) => O.OverloadedMethod PluginGetNameMethodInfo a signature where
    overloadedMethod = pluginGetName

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


#endif

-- method Plugin::find
-- method type : MemberFunction
-- Args: [ Arg
--           { argCName = "core"
--           , argType = TInterface Name { namespace = "Wp" , name = "Core" }
--           , argCType = Just "WpCore*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the core" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "plugin_name"
--           , argType = TBasicType TUTF8
--           , argCType = Just "const gchar*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the lookup name" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Wp" , name = "Plugin" })
-- throws : False
-- Skip return : False

foreign import ccall "wp_plugin_find" wp_plugin_find :: 
    Ptr Wp.Core.Core ->                     -- core : TInterface (Name {namespace = "Wp", name = "Core"})
    CString ->                              -- plugin_name : TBasicType TUTF8
    IO (Ptr Plugin)

-- | Looks up a plugin.
pluginFind ::
    (B.CallStack.HasCallStack, MonadIO m, Wp.Core.IsCore a) =>
    a
    -- ^ /@core@/: the core
    -> T.Text
    -- ^ /@pluginName@/: the lookup name
    -> m (Maybe Plugin)
    -- ^ __Returns:__ the plugin matching the lookup name
pluginFind core pluginName = liftIO $ do
    core' <- unsafeManagedPtrCastPtr core
    pluginName' <- textToCString pluginName
    result <- wp_plugin_find core' pluginName'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject Plugin) result'
        return result''
    touchManagedPtr core
    freeMem pluginName'
    return maybeResult

#if defined(ENABLE_OVERLOADING)
#endif