{-# language CPP #-}
-- No documentation found for Chapter "Haptics"
module OpenXR.Core10.Haptics  ( applyHapticFeedback
                              , stopHapticFeedback
                              , HapticBaseHeader(..)
                              , IsHaptic(..)
                              , HapticActionInfo(..)
                              ) where

import OpenXR.Internal.Utils (traceAroundEvent)
import Control.Monad (unless)
import Control.Monad.IO.Class (liftIO)
import Foreign.Marshal.Alloc (allocaBytesAligned)
import GHC.Base (when)
import GHC.IO (throwIO)
import GHC.Ptr (castPtr)
import GHC.Ptr (nullFunPtr)
import Foreign.Ptr (nullPtr)
import Foreign.Ptr (plusPtr)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Cont (evalContT)
import OpenXR.CStruct (FromCStruct)
import OpenXR.CStruct (FromCStruct(..))
import OpenXR.CStruct (ToCStruct)
import OpenXR.CStruct (ToCStruct(..))
import OpenXR.Zero (Zero(..))
import Control.Monad.IO.Class (MonadIO)
import Data.Typeable (Typeable)
import Foreign.Storable (Storable)
import Foreign.Storable (Storable(peek))
import Foreign.Storable (Storable(poke))
import qualified Foreign.Storable (Storable(..))
import GHC.Generics (Generic)
import GHC.IO.Exception (IOErrorType(..))
import GHC.IO.Exception (IOException(..))
import Foreign.Ptr (FunPtr)
import Foreign.Ptr (Ptr)
import Data.Kind (Type)
import Control.Monad.Trans.Cont (ContT(..))
import OpenXR.NamedType ((:::))
import OpenXR.Core10.Handles (Action_T)
import {-# SOURCE #-} OpenXR.Core10.OtherTypes (HapticVibration)
import OpenXR.CStruct.Extends (Inheritable(..))
import OpenXR.Dynamic (InstanceCmds(pXrApplyHapticFeedback))
import OpenXR.Dynamic (InstanceCmds(pXrStopHapticFeedback))
import OpenXR.Exception (OpenXrException(..))
import OpenXR.Core10.SemanticPaths (Path)
import OpenXR.Core10.Enums.Result (Result)
import OpenXR.Core10.Enums.Result (Result(..))
import OpenXR.Core10.Handles (Session)
import OpenXR.Core10.Handles (Session(..))
import OpenXR.Core10.Handles (Session_T)
import OpenXR.CStruct.Extends (SomeChild)
import OpenXR.CStruct.Extends (SomeChild(..))
import OpenXR.Core10.Enums.StructureType (StructureType)
import OpenXR.Core10.Enums.Result (Result(SUCCESS))
import OpenXR.Core10.Enums.StructureType (StructureType(TYPE_HAPTIC_ACTION_INFO))
import OpenXR.Core10.Enums.StructureType (StructureType(TYPE_HAPTIC_VIBRATION))
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkXrApplyHapticFeedback
  :: FunPtr (Ptr Session_T -> Ptr HapticActionInfo -> Ptr (SomeChild HapticBaseHeader) -> IO Result) -> Ptr Session_T -> Ptr HapticActionInfo -> Ptr (SomeChild HapticBaseHeader) -> IO Result

-- | xrApplyHapticFeedback - Apply haptic feedback
--
-- == Parameter Descriptions
--
-- = Description
--
-- Triggers a haptic event through the specified action of type
-- 'OpenXR.Core10.Enums.StructureType.TYPE_HAPTIC_VIBRATION'. The runtime
-- /should/ deliver this request to the appropriate device, but exactly
-- which device, if any, this event is sent to is up to the runtime to
-- decide. If an appropriate device is unavailable the runtime /may/ ignore
-- this request for haptic feedback.
--
-- If another haptic event from this session is currently happening on the
-- device bound to this action, the runtime /must/ interrupt that other
-- event and replace it with the new one.
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-successcodes Success>]
--
--     -   'OpenXR.Core10.Enums.Result.SUCCESS'
--
--     -   'OpenXR.Core10.Enums.Result.SESSION_LOSS_PENDING'
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-errorcodes Failure>]
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_INSTANCE_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_SESSION_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_RUNTIME_FAILURE'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_HANDLE_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_VALIDATION_FAILURE'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_ACTIONSET_NOT_ATTACHED'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_ACTION_TYPE_MISMATCH'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_PATH_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_PATH_UNSUPPORTED'
--
-- = See Also
--
-- 'HapticActionInfo', 'HapticBaseHeader',
-- 'OpenXR.Core10.OtherTypes.HapticVibration',
-- 'OpenXR.Core10.Handles.Session', 'stopHapticFeedback'
applyHapticFeedback :: forall a io
                     . (ToCStruct a, MonadIO io)
                    => -- | @session@ is the 'OpenXR.Core10.Handles.Session' to start outputting to.
                       --
                       -- #VUID-xrApplyHapticFeedback-session-parameter# @session@ /must/ be a
                       -- valid 'OpenXR.Core10.Handles.Session' handle
                       Session
                    -> -- | @hapticActionInfo@ is a pointer to 'HapticActionInfo' to provide action
                       -- and subaction paths information.
                       --
                       -- #VUID-xrApplyHapticFeedback-hapticActionInfo-parameter#
                       -- @hapticActionInfo@ /must/ be a pointer to a valid 'HapticActionInfo'
                       -- structure
                       HapticActionInfo
                    -> -- | @hapticFeedback@ is a pointer to a haptic event structure which starts
                       -- with an 'HapticBaseHeader'.
                       --
                       -- #VUID-xrApplyHapticFeedback-hapticFeedback-parameter# @hapticFeedback@
                       -- /must/ be a pointer to a valid 'HapticBaseHeader'-based structure. See
                       -- also: 'OpenXR.Core10.OtherTypes.HapticVibration'
                       ("hapticFeedback" ::: a)
                    -> io (Result)
applyHapticFeedback :: Session
-> HapticActionInfo -> ("hapticFeedback" ::: a) -> io Result
applyHapticFeedback session :: Session
session hapticActionInfo :: HapticActionInfo
hapticActionInfo hapticFeedback :: "hapticFeedback" ::: a
hapticFeedback = IO Result -> io Result
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Result -> io Result)
-> (ContT Result IO Result -> IO Result)
-> ContT Result IO Result
-> io Result
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT Result IO Result -> IO Result
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT Result IO Result -> io Result)
-> ContT Result IO Result -> io Result
forall a b. (a -> b) -> a -> b
$ do
  let xrApplyHapticFeedbackPtr :: FunPtr
  (Ptr Session_T
   -> Ptr HapticActionInfo
   -> ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
   -> IO Result)
xrApplyHapticFeedbackPtr = InstanceCmds
-> FunPtr
     (Ptr Session_T
      -> Ptr HapticActionInfo
      -> ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
      -> IO Result)
pXrApplyHapticFeedback (Session -> InstanceCmds
instanceCmds (Session
session :: Session))
  IO () -> ContT Result IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Result IO ()) -> IO () -> ContT Result IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Session_T
   -> Ptr HapticActionInfo
   -> ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
   -> IO Result)
xrApplyHapticFeedbackPtr FunPtr
  (Ptr Session_T
   -> Ptr HapticActionInfo
   -> ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
   -> IO Result)
-> FunPtr
     (Ptr Session_T
      -> Ptr HapticActionInfo
      -> ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
      -> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
  (Ptr Session_T
   -> Ptr HapticActionInfo
   -> ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
   -> IO Result)
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
    IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for xrApplyHapticFeedback is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let xrApplyHapticFeedback' :: Ptr Session_T
-> Ptr HapticActionInfo
-> ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
-> IO Result
xrApplyHapticFeedback' = FunPtr
  (Ptr Session_T
   -> Ptr HapticActionInfo
   -> ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
   -> IO Result)
-> Ptr Session_T
-> Ptr HapticActionInfo
-> ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
-> IO Result
mkXrApplyHapticFeedback FunPtr
  (Ptr Session_T
   -> Ptr HapticActionInfo
   -> ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
   -> IO Result)
xrApplyHapticFeedbackPtr
  Ptr HapticActionInfo
hapticActionInfo' <- ((Ptr HapticActionInfo -> IO Result) -> IO Result)
-> ContT Result IO (Ptr HapticActionInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr HapticActionInfo -> IO Result) -> IO Result)
 -> ContT Result IO (Ptr HapticActionInfo))
-> ((Ptr HapticActionInfo -> IO Result) -> IO Result)
-> ContT Result IO (Ptr HapticActionInfo)
forall a b. (a -> b) -> a -> b
$ HapticActionInfo
-> (Ptr HapticActionInfo -> IO Result) -> IO Result
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (HapticActionInfo
hapticActionInfo)
  "hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader)
hapticFeedback' <- (Ptr ("hapticFeedback" ::: a)
 -> "hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
-> ContT Result IO (Ptr ("hapticFeedback" ::: a))
-> ContT
     Result IO ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Ptr ("hapticFeedback" ::: a)
-> "hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader)
forall a b. Ptr a -> Ptr b
castPtr (ContT Result IO (Ptr ("hapticFeedback" ::: a))
 -> ContT
      Result IO ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader)))
-> ContT Result IO (Ptr ("hapticFeedback" ::: a))
-> ContT
     Result IO ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
forall a b. (a -> b) -> a -> b
$ ((Ptr ("hapticFeedback" ::: a) -> IO Result) -> IO Result)
-> ContT Result IO (Ptr ("hapticFeedback" ::: a))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("hapticFeedback" ::: a) -> IO Result) -> IO Result)
 -> ContT Result IO (Ptr ("hapticFeedback" ::: a)))
-> ((Ptr ("hapticFeedback" ::: a) -> IO Result) -> IO Result)
-> ContT Result IO (Ptr ("hapticFeedback" ::: a))
forall a b. (a -> b) -> a -> b
$ ("hapticFeedback" ::: a)
-> (Ptr ("hapticFeedback" ::: a) -> IO Result) -> IO Result
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct ("hapticFeedback" ::: a
hapticFeedback)
  Result
r <- IO Result -> ContT Result IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT Result IO Result)
-> IO Result -> ContT Result IO Result
forall a b. (a -> b) -> a -> b
$ String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "xrApplyHapticFeedback" (Ptr Session_T
-> Ptr HapticActionInfo
-> ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
-> IO Result
xrApplyHapticFeedback' (Session -> Ptr Session_T
sessionHandle (Session
session)) Ptr HapticActionInfo
hapticActionInfo' "hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader)
hapticFeedback')
  IO () -> ContT Result IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Result IO ()) -> IO () -> ContT Result IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (OpenXrException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> OpenXrException
OpenXrException Result
r))
  Result -> ContT Result IO Result
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Result -> ContT Result IO Result)
-> Result -> ContT Result IO Result
forall a b. (a -> b) -> a -> b
$ (Result
r)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkXrStopHapticFeedback
  :: FunPtr (Ptr Session_T -> Ptr HapticActionInfo -> IO Result) -> Ptr Session_T -> Ptr HapticActionInfo -> IO Result

-- | xrStopHapticFeedback - Stop haptic feedback
--
-- == Parameter Descriptions
--
-- = Description
--
-- If a haptic event from this 'OpenXR.Core10.Handles.Action' is in
-- progress, when this function is called the runtime /must/ stop that
-- event.
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-successcodes Success>]
--
--     -   'OpenXR.Core10.Enums.Result.SUCCESS'
--
--     -   'OpenXR.Core10.Enums.Result.SESSION_LOSS_PENDING'
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-errorcodes Failure>]
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_INSTANCE_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_SESSION_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_RUNTIME_FAILURE'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_HANDLE_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_VALIDATION_FAILURE'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_ACTIONSET_NOT_ATTACHED'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_ACTION_TYPE_MISMATCH'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_PATH_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_PATH_UNSUPPORTED'
--
-- = See Also
--
-- 'HapticActionInfo', 'OpenXR.Core10.Handles.Session',
-- 'applyHapticFeedback'
stopHapticFeedback :: forall io
                    . (MonadIO io)
                   => -- | @session@ is the 'OpenXR.Core10.Handles.Session' to stop outputting to.
                      --
                      -- #VUID-xrStopHapticFeedback-session-parameter# @session@ /must/ be a
                      -- valid 'OpenXR.Core10.Handles.Session' handle
                      Session
                   -> -- | @hapticActionInfo@ is a pointer to an 'HapticActionInfo' to provide
                      -- action and subaction path information.
                      --
                      -- #VUID-xrStopHapticFeedback-hapticActionInfo-parameter#
                      -- @hapticActionInfo@ /must/ be a pointer to a valid 'HapticActionInfo'
                      -- structure
                      HapticActionInfo
                   -> io (Result)
stopHapticFeedback :: Session -> HapticActionInfo -> io Result
stopHapticFeedback session :: Session
session hapticActionInfo :: HapticActionInfo
hapticActionInfo = IO Result -> io Result
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Result -> io Result)
-> (ContT Result IO Result -> IO Result)
-> ContT Result IO Result
-> io Result
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT Result IO Result -> IO Result
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT Result IO Result -> io Result)
-> ContT Result IO Result -> io Result
forall a b. (a -> b) -> a -> b
$ do
  let xrStopHapticFeedbackPtr :: FunPtr (Ptr Session_T -> Ptr HapticActionInfo -> IO Result)
xrStopHapticFeedbackPtr = InstanceCmds
-> FunPtr (Ptr Session_T -> Ptr HapticActionInfo -> IO Result)
pXrStopHapticFeedback (Session -> InstanceCmds
instanceCmds (Session
session :: Session))
  IO () -> ContT Result IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Result IO ()) -> IO () -> ContT Result IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr (Ptr Session_T -> Ptr HapticActionInfo -> IO Result)
xrStopHapticFeedbackPtr FunPtr (Ptr Session_T -> Ptr HapticActionInfo -> IO Result)
-> FunPtr (Ptr Session_T -> Ptr HapticActionInfo -> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr (Ptr Session_T -> Ptr HapticActionInfo -> IO Result)
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
    IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for xrStopHapticFeedback is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let xrStopHapticFeedback' :: Ptr Session_T -> Ptr HapticActionInfo -> IO Result
xrStopHapticFeedback' = FunPtr (Ptr Session_T -> Ptr HapticActionInfo -> IO Result)
-> Ptr Session_T -> Ptr HapticActionInfo -> IO Result
mkXrStopHapticFeedback FunPtr (Ptr Session_T -> Ptr HapticActionInfo -> IO Result)
xrStopHapticFeedbackPtr
  Ptr HapticActionInfo
hapticActionInfo' <- ((Ptr HapticActionInfo -> IO Result) -> IO Result)
-> ContT Result IO (Ptr HapticActionInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr HapticActionInfo -> IO Result) -> IO Result)
 -> ContT Result IO (Ptr HapticActionInfo))
-> ((Ptr HapticActionInfo -> IO Result) -> IO Result)
-> ContT Result IO (Ptr HapticActionInfo)
forall a b. (a -> b) -> a -> b
$ HapticActionInfo
-> (Ptr HapticActionInfo -> IO Result) -> IO Result
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (HapticActionInfo
hapticActionInfo)
  Result
r <- IO Result -> ContT Result IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT Result IO Result)
-> IO Result -> ContT Result IO Result
forall a b. (a -> b) -> a -> b
$ String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "xrStopHapticFeedback" (Ptr Session_T -> Ptr HapticActionInfo -> IO Result
xrStopHapticFeedback' (Session -> Ptr Session_T
sessionHandle (Session
session)) Ptr HapticActionInfo
hapticActionInfo')
  IO () -> ContT Result IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Result IO ()) -> IO () -> ContT Result IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (OpenXrException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> OpenXrException
OpenXrException Result
r))
  Result -> ContT Result IO Result
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Result -> ContT Result IO Result)
-> Result -> ContT Result IO Result
forall a b. (a -> b) -> a -> b
$ (Result
r)


-- | XrHapticBaseHeader - Base header for haptic feedback
--
-- == Valid Usage (Implicit)
--
-- = See Also
--
-- 'OpenXR.Core10.OtherTypes.HapticVibration',
-- 'OpenXR.Extensions.XR_VALVE_analog_threshold.InteractionProfileAnalogThresholdVALVE',
-- 'OpenXR.Core10.Enums.StructureType.StructureType', 'applyHapticFeedback'
data HapticBaseHeader = HapticBaseHeader
  { -- | @type@ is the 'OpenXR.Core10.Enums.StructureType.StructureType' of this
    -- structure. This base structure itself has no associated
    -- 'OpenXR.Core10.Enums.StructureType.StructureType' value.
    --
    -- #VUID-XrHapticBaseHeader-type-type# @type@ /must/ be
    -- 'OpenXR.Core10.Enums.StructureType.TYPE_HAPTIC_VIBRATION'
    HapticBaseHeader -> StructureType
type' :: StructureType }
  deriving (Typeable, HapticBaseHeader -> HapticBaseHeader -> Bool
(HapticBaseHeader -> HapticBaseHeader -> Bool)
-> (HapticBaseHeader -> HapticBaseHeader -> Bool)
-> Eq HapticBaseHeader
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HapticBaseHeader -> HapticBaseHeader -> Bool
$c/= :: HapticBaseHeader -> HapticBaseHeader -> Bool
== :: HapticBaseHeader -> HapticBaseHeader -> Bool
$c== :: HapticBaseHeader -> HapticBaseHeader -> Bool
Eq)
#if defined(GENERIC_INSTANCES)
deriving instance Generic (HapticBaseHeader)
#endif
deriving instance Show HapticBaseHeader

class ToCStruct a => IsHaptic a where
  toHapticBaseHeader :: a -> HapticBaseHeader

instance Inheritable HapticBaseHeader where
  peekSomeCChild :: Ptr (SomeChild HapticBaseHeader) -> IO (SomeChild HapticBaseHeader)
  peekSomeCChild :: ("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
-> IO (SomeChild HapticBaseHeader)
peekSomeCChild p :: "hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader)
p = do
    StructureType
ty <- Ptr StructureType -> IO StructureType
forall a. Storable a => Ptr a -> IO a
peek @StructureType (("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
-> Ptr StructureType
forall a b. Ptr a -> Ptr b
castPtr @(SomeChild HapticBaseHeader) @StructureType "hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader)
p)
    case StructureType
ty of
      TYPE_HAPTIC_VIBRATION -> HapticVibration -> SomeChild HapticBaseHeader
forall a b.
(Inherits a b, Typeable b, ToCStruct b, Show b) =>
b -> SomeChild a
SomeChild (HapticVibration -> SomeChild HapticBaseHeader)
-> IO HapticVibration -> IO (SomeChild HapticBaseHeader)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr HapticVibration -> IO HapticVibration
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct (("hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader))
-> Ptr HapticVibration
forall a b. Ptr a -> Ptr b
castPtr @(SomeChild HapticBaseHeader) @HapticVibration "hapticFeedback" ::: Ptr (SomeChild HapticBaseHeader)
p)
      c :: StructureType
c -> IOException -> IO (SomeChild HapticBaseHeader)
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO (SomeChild HapticBaseHeader))
-> IOException -> IO (SomeChild HapticBaseHeader)
forall a b. (a -> b) -> a -> b
$
        Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError
          Maybe Handle
forall a. Maybe a
Nothing
          IOErrorType
InvalidArgument
          "peekSomeCChild"
          ("Illegal struct inheritance of HapticBaseHeader with " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> StructureType -> String
forall a. Show a => a -> String
show StructureType
c)
          Maybe CInt
forall a. Maybe a
Nothing
          Maybe String
forall a. Maybe a
Nothing

instance ToCStruct HapticBaseHeader where
  withCStruct :: HapticBaseHeader -> (Ptr HapticBaseHeader -> IO b) -> IO b
withCStruct x :: HapticBaseHeader
x f :: Ptr HapticBaseHeader -> IO b
f = Int -> Int -> (Ptr HapticBaseHeader -> IO b) -> IO b
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned 16 8 ((Ptr HapticBaseHeader -> IO b) -> IO b)
-> (Ptr HapticBaseHeader -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \p :: Ptr HapticBaseHeader
p -> Ptr HapticBaseHeader -> HapticBaseHeader -> IO b -> IO b
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr HapticBaseHeader
p HapticBaseHeader
x (Ptr HapticBaseHeader -> IO b
f Ptr HapticBaseHeader
p)
  pokeCStruct :: Ptr HapticBaseHeader -> HapticBaseHeader -> IO b -> IO b
pokeCStruct p :: Ptr HapticBaseHeader
p HapticBaseHeader{..} f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr HapticBaseHeader
p Ptr HapticBaseHeader -> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
type')
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr HapticBaseHeader
p Ptr HapticBaseHeader -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    IO b
f
  cStructSize :: Int
cStructSize = 16
  cStructAlignment :: Int
cStructAlignment = 8
  pokeZeroCStruct :: Ptr HapticBaseHeader -> IO b -> IO b
pokeZeroCStruct p :: Ptr HapticBaseHeader
p f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr HapticBaseHeader
p Ptr HapticBaseHeader -> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
forall a. Zero a => a
zero)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr HapticBaseHeader
p Ptr HapticBaseHeader -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    IO b
f

instance FromCStruct HapticBaseHeader where
  peekCStruct :: Ptr HapticBaseHeader -> IO HapticBaseHeader
peekCStruct p :: Ptr HapticBaseHeader
p = do
    StructureType
type' <- Ptr StructureType -> IO StructureType
forall a. Storable a => Ptr a -> IO a
peek @StructureType ((Ptr HapticBaseHeader
p Ptr HapticBaseHeader -> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType))
    HapticBaseHeader -> IO HapticBaseHeader
forall (f :: * -> *) a. Applicative f => a -> f a
pure (HapticBaseHeader -> IO HapticBaseHeader)
-> HapticBaseHeader -> IO HapticBaseHeader
forall a b. (a -> b) -> a -> b
$ StructureType -> HapticBaseHeader
HapticBaseHeader
             StructureType
type'

instance Storable HapticBaseHeader where
  sizeOf :: HapticBaseHeader -> Int
sizeOf ~HapticBaseHeader
_ = 16
  alignment :: HapticBaseHeader -> Int
alignment ~HapticBaseHeader
_ = 8
  peek :: Ptr HapticBaseHeader -> IO HapticBaseHeader
peek = Ptr HapticBaseHeader -> IO HapticBaseHeader
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct
  poke :: Ptr HapticBaseHeader -> HapticBaseHeader -> IO ()
poke ptr :: Ptr HapticBaseHeader
ptr poked :: HapticBaseHeader
poked = Ptr HapticBaseHeader -> HapticBaseHeader -> IO () -> IO ()
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr HapticBaseHeader
ptr HapticBaseHeader
poked (() -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())

instance Zero HapticBaseHeader where
  zero :: HapticBaseHeader
zero = StructureType -> HapticBaseHeader
HapticBaseHeader
           StructureType
forall a. Zero a => a
zero


-- | XrHapticActionInfo - Information to output haptic feedback
--
-- == Member Descriptions
--
-- = Description
--
-- See 'OpenXR.Core10.Input.ActionCreateInfo' for a description of
-- subaction paths, and the restrictions on their use.
--
-- == Valid Usage (Implicit)
--
-- = See Also
--
-- 'OpenXR.Core10.Handles.Action',
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >,
-- 'OpenXR.Core10.Enums.StructureType.StructureType',
-- 'applyHapticFeedback', 'stopHapticFeedback'
data HapticActionInfo = HapticActionInfo
  { -- | @action@ is the 'OpenXR.Core10.Handles.Action' handle for the desired
    -- output haptic action.
    --
    -- #VUID-XrHapticActionInfo-action-parameter# @action@ /must/ be a valid
    -- 'OpenXR.Core10.Handles.Action' handle
    HapticActionInfo -> Ptr Action_T
action :: Ptr Action_T
  , -- | @subactionPath@ is the subaction path
    -- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
    -- of the device to send the haptic event to, or
    -- 'OpenXR.Core10.APIConstants.NULL_PATH' to specify all subaction paths.
    -- If the subaction path is specified, it is one of the subaction paths
    -- that were specified when the action was created. If the subaction path
    -- was not specified when the action was created, the runtime /must/ return
    -- 'OpenXR.Core10.Enums.Result.ERROR_PATH_UNSUPPORTED'. If this parameter
    -- is specified, the runtime /must/ trigger the haptic events only on the
    -- device from the subaction path.
    HapticActionInfo -> Path
subactionPath :: Path
  }
  deriving (Typeable, HapticActionInfo -> HapticActionInfo -> Bool
(HapticActionInfo -> HapticActionInfo -> Bool)
-> (HapticActionInfo -> HapticActionInfo -> Bool)
-> Eq HapticActionInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HapticActionInfo -> HapticActionInfo -> Bool
$c/= :: HapticActionInfo -> HapticActionInfo -> Bool
== :: HapticActionInfo -> HapticActionInfo -> Bool
$c== :: HapticActionInfo -> HapticActionInfo -> Bool
Eq)
#if defined(GENERIC_INSTANCES)
deriving instance Generic (HapticActionInfo)
#endif
deriving instance Show HapticActionInfo

instance ToCStruct HapticActionInfo where
  withCStruct :: HapticActionInfo -> (Ptr HapticActionInfo -> IO b) -> IO b
withCStruct x :: HapticActionInfo
x f :: Ptr HapticActionInfo -> IO b
f = Int -> Int -> (Ptr HapticActionInfo -> IO b) -> IO b
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned 32 8 ((Ptr HapticActionInfo -> IO b) -> IO b)
-> (Ptr HapticActionInfo -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \p :: Ptr HapticActionInfo
p -> Ptr HapticActionInfo -> HapticActionInfo -> IO b -> IO b
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr HapticActionInfo
p HapticActionInfo
x (Ptr HapticActionInfo -> IO b
f Ptr HapticActionInfo
p)
  pokeCStruct :: Ptr HapticActionInfo -> HapticActionInfo -> IO b -> IO b
pokeCStruct p :: Ptr HapticActionInfo
p HapticActionInfo{..} f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr HapticActionInfo
p Ptr HapticActionInfo -> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
TYPE_HAPTIC_ACTION_INFO)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr HapticActionInfo
p Ptr HapticActionInfo -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    Ptr (Ptr Action_T) -> Ptr Action_T -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr HapticActionInfo
p Ptr HapticActionInfo -> Int -> Ptr (Ptr Action_T)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr (Ptr Action_T))) (Ptr Action_T
action)
    Ptr Path -> Path -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr HapticActionInfo
p Ptr HapticActionInfo -> Int -> Ptr Path
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 24 :: Ptr Path)) (Path
subactionPath)
    IO b
f
  cStructSize :: Int
cStructSize = 32
  cStructAlignment :: Int
cStructAlignment = 8
  pokeZeroCStruct :: Ptr HapticActionInfo -> IO b -> IO b
pokeZeroCStruct p :: Ptr HapticActionInfo
p f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr HapticActionInfo
p Ptr HapticActionInfo -> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
TYPE_HAPTIC_ACTION_INFO)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr HapticActionInfo
p Ptr HapticActionInfo -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    Ptr (Ptr Action_T) -> Ptr Action_T -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr HapticActionInfo
p Ptr HapticActionInfo -> Int -> Ptr (Ptr Action_T)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr (Ptr Action_T))) (Ptr Action_T
forall a. Zero a => a
zero)
    IO b
f

instance FromCStruct HapticActionInfo where
  peekCStruct :: Ptr HapticActionInfo -> IO HapticActionInfo
peekCStruct p :: Ptr HapticActionInfo
p = do
    Ptr Action_T
action <- Ptr (Ptr Action_T) -> IO (Ptr Action_T)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr Action_T) ((Ptr HapticActionInfo
p Ptr HapticActionInfo -> Int -> Ptr (Ptr Action_T)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr (Ptr Action_T)))
    Path
subactionPath <- Ptr Path -> IO Path
forall a. Storable a => Ptr a -> IO a
peek @Path ((Ptr HapticActionInfo
p Ptr HapticActionInfo -> Int -> Ptr Path
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 24 :: Ptr Path))
    HapticActionInfo -> IO HapticActionInfo
forall (f :: * -> *) a. Applicative f => a -> f a
pure (HapticActionInfo -> IO HapticActionInfo)
-> HapticActionInfo -> IO HapticActionInfo
forall a b. (a -> b) -> a -> b
$ Ptr Action_T -> Path -> HapticActionInfo
HapticActionInfo
             Ptr Action_T
action Path
subactionPath

instance Storable HapticActionInfo where
  sizeOf :: HapticActionInfo -> Int
sizeOf ~HapticActionInfo
_ = 32
  alignment :: HapticActionInfo -> Int
alignment ~HapticActionInfo
_ = 8
  peek :: Ptr HapticActionInfo -> IO HapticActionInfo
peek = Ptr HapticActionInfo -> IO HapticActionInfo
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct
  poke :: Ptr HapticActionInfo -> HapticActionInfo -> IO ()
poke ptr :: Ptr HapticActionInfo
ptr poked :: HapticActionInfo
poked = Ptr HapticActionInfo -> HapticActionInfo -> IO () -> IO ()
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr HapticActionInfo
ptr HapticActionInfo
poked (() -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())

instance Zero HapticActionInfo where
  zero :: HapticActionInfo
zero = Ptr Action_T -> Path -> HapticActionInfo
HapticActionInfo
           Ptr Action_T
forall a. Zero a => a
zero
           Path
forall a. Zero a => a
zero