{-# language CPP #-}
-- | = Name
--
-- XR_MSFT_perception_anchor_interop - instance extension
--
-- = Specification
--
-- See
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XR_MSFT_perception_anchor_interop  XR_MSFT_perception_anchor_interop>
-- in the main specification for complete information.
--
-- = Registered Extension Number
--
-- 57
--
-- = Revision
--
-- 1
--
-- = Extension and Version Dependencies
--
-- -   Requires OpenXR 1.0
--
-- -   Requires @@
--
-- = See Also
--
-- 'createSpatialAnchorFromPerceptionAnchorMSFT',
-- 'tryGetPerceptionAnchorFromSpatialAnchorMSFT'
--
-- = Document Notes
--
-- For more information, see the
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XR_MSFT_perception_anchor_interop OpenXR Specification>
--
-- This page is a generated document. Fixes and changes should be made to
-- the generator scripts, not directly.
module OpenXR.Extensions.XR_MSFT_perception_anchor_interop  ( createSpatialAnchorFromPerceptionAnchorMSFT
                                                            , withSpatialAnchorFromPerceptionAnchorMSFT
                                                            , tryGetPerceptionAnchorFromSpatialAnchorMSFT
                                                            , MSFT_perception_anchor_interop_SPEC_VERSION
                                                            , pattern MSFT_perception_anchor_interop_SPEC_VERSION
                                                            , MSFT_PERCEPTION_ANCHOR_INTEROP_EXTENSION_NAME
                                                            , pattern MSFT_PERCEPTION_ANCHOR_INTEROP_EXTENSION_NAME
                                                            , IUnknown
                                                            , SpatialAnchorMSFT(..)
                                                            , destroySpatialAnchorMSFT
                                                            ) where

import OpenXR.Internal.Utils (traceAroundEvent)
import Control.Exception.Base (bracket)
import Control.Monad (unless)
import Control.Monad.IO.Class (liftIO)
import Foreign.Marshal.Alloc (callocBytes)
import Foreign.Marshal.Alloc (free)
import GHC.Base (when)
import GHC.IO (throwIO)
import GHC.Ptr (nullFunPtr)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Cont (evalContT)
import Control.Monad.IO.Class (MonadIO)
import Data.String (IsString)
import Foreign.Storable (Storable(peek))
import GHC.IO.Exception (IOErrorType(..))
import GHC.IO.Exception (IOException(..))
import Foreign.Ptr (FunPtr)
import Foreign.Ptr (Ptr)
import Control.Monad.Trans.Cont (ContT(..))
import OpenXR.Extensions.XR_MSFT_spatial_anchor (destroySpatialAnchorMSFT)
import OpenXR.NamedType ((:::))
import OpenXR.Dynamic (InstanceCmds(pXrCreateSpatialAnchorFromPerceptionAnchorMSFT))
import OpenXR.Dynamic (InstanceCmds(pXrTryGetPerceptionAnchorFromSpatialAnchorMSFT))
import OpenXR.Exception (OpenXrException(..))
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.Extensions.Handles (SpatialAnchorMSFT)
import OpenXR.Extensions.Handles (SpatialAnchorMSFT(..))
import OpenXR.Extensions.Handles (SpatialAnchorMSFT(SpatialAnchorMSFT))
import OpenXR.Extensions.Handles (SpatialAnchorMSFT_T)
import OpenXR.Core10.Enums.Result (Result(SUCCESS))
import OpenXR.Extensions.XR_MSFT_spatial_anchor (destroySpatialAnchorMSFT)
import OpenXR.Extensions.Handles (SpatialAnchorMSFT(..))
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkXrCreateSpatialAnchorFromPerceptionAnchorMSFT
  :: FunPtr (Ptr Session_T -> Ptr IUnknown -> Ptr (Ptr SpatialAnchorMSFT_T) -> IO Result) -> Ptr Session_T -> Ptr IUnknown -> Ptr (Ptr SpatialAnchorMSFT_T) -> IO Result

-- | xrCreateSpatialAnchorFromPerceptionAnchorMSFT - Create a
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT' from a Windows
-- SpatialAnchor pointer
--
-- == Parameter Descriptions
--
-- = Description
--
-- The input @perceptionAnchor@ /must/ support successful @QueryInterface@
-- to
-- <https://docs.microsoft.com/uwp/api/Windows.Perception.Spatial.SpatialAnchor Windows.Perception.Spatial.SpatialAnchor>
-- , otherwise the runtime /must/ return
-- 'OpenXR.Core10.Enums.Result.ERROR_VALIDATION_FAILURE'.
--
-- If the function successfully returned, the output @anchor@ /must/ be a
-- valid handle. This also increments the refcount of the
-- @perceptionAnchor@ object.
--
-- When application is done with the @anchor@ handle, it /can/ be destroyed
-- using
-- 'OpenXR.Extensions.XR_MSFT_spatial_anchor.destroySpatialAnchorMSFT'
-- function. This also decrements the refcount of underlying windows
-- perception anchor object.
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-xrCreateSpatialAnchorFromPerceptionAnchorMSFT-extension-notenabled#
--     The @@ extension /must/ be enabled prior to calling
--     'createSpatialAnchorFromPerceptionAnchorMSFT'
--
-- -   #VUID-xrCreateSpatialAnchorFromPerceptionAnchorMSFT-session-parameter#
--     @session@ /must/ be a valid 'OpenXR.Core10.Handles.Session' handle
--
-- -   #VUID-xrCreateSpatialAnchorFromPerceptionAnchorMSFT-perceptionAnchor-parameter#
--     @perceptionAnchor@ /must/ be a pointer to an 'IUnknown' value
--
-- -   #VUID-xrCreateSpatialAnchorFromPerceptionAnchorMSFT-anchor-parameter#
--     @anchor@ /must/ be a pointer to an
--     'OpenXR.Extensions.Handles.SpatialAnchorMSFT' handle
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-successcodes Success>]
--
--     -   'OpenXR.Core10.Enums.Result.SUCCESS'
--
-- [<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_OUT_OF_MEMORY'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_FUNCTION_UNSUPPORTED'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_VALIDATION_FAILURE'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_HANDLE_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_SESSION_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.SESSION_LOSS_PENDING'
--
-- = See Also
--
-- 'OpenXR.Core10.Handles.Session',
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT'
createSpatialAnchorFromPerceptionAnchorMSFT :: forall io
                                             . (MonadIO io)
                                            => -- | @session@ is the specified 'OpenXR.Core10.Handles.Session'.
                                               Session
                                            -> -- | @perceptionAnchor@ is an IUnknown pointer to a
                                               -- <https://docs.microsoft.com/uwp/api/Windows.Perception.Spatial.SpatialAnchor Windows.Perception.Spatial.SpatialAnchor>
                                               -- object.
                                               ("perceptionAnchor" ::: Ptr IUnknown)
                                            -> io (SpatialAnchorMSFT)
createSpatialAnchorFromPerceptionAnchorMSFT :: Session
-> ("perceptionAnchor" ::: Ptr IUnknown) -> io SpatialAnchorMSFT
createSpatialAnchorFromPerceptionAnchorMSFT session :: Session
session perceptionAnchor :: "perceptionAnchor" ::: Ptr IUnknown
perceptionAnchor = IO SpatialAnchorMSFT -> io SpatialAnchorMSFT
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SpatialAnchorMSFT -> io SpatialAnchorMSFT)
-> (ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
    -> IO SpatialAnchorMSFT)
-> ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
-> io SpatialAnchorMSFT
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
-> IO SpatialAnchorMSFT
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
 -> io SpatialAnchorMSFT)
-> ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
-> io SpatialAnchorMSFT
forall a b. (a -> b) -> a -> b
$ do
  let cmds :: InstanceCmds
cmds = Session -> InstanceCmds
instanceCmds (Session
session :: Session)
  let xrCreateSpatialAnchorFromPerceptionAnchorMSFTPtr :: FunPtr
  (Ptr Session_T
   -> ("perceptionAnchor" ::: Ptr IUnknown)
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO Result)
xrCreateSpatialAnchorFromPerceptionAnchorMSFTPtr = InstanceCmds
-> FunPtr
     (Ptr Session_T
      -> ("perceptionAnchor" ::: Ptr IUnknown)
      -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
      -> IO Result)
pXrCreateSpatialAnchorFromPerceptionAnchorMSFT InstanceCmds
cmds
  IO () -> ContT SpatialAnchorMSFT IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT SpatialAnchorMSFT IO ())
-> IO () -> ContT SpatialAnchorMSFT IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Session_T
   -> ("perceptionAnchor" ::: Ptr IUnknown)
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO Result)
xrCreateSpatialAnchorFromPerceptionAnchorMSFTPtr FunPtr
  (Ptr Session_T
   -> ("perceptionAnchor" ::: Ptr IUnknown)
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO Result)
-> FunPtr
     (Ptr Session_T
      -> ("perceptionAnchor" ::: Ptr IUnknown)
      -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
      -> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
  (Ptr Session_T
   -> ("perceptionAnchor" ::: Ptr IUnknown)
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> 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 xrCreateSpatialAnchorFromPerceptionAnchorMSFT is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let xrCreateSpatialAnchorFromPerceptionAnchorMSFT' :: Ptr Session_T
-> ("perceptionAnchor" ::: Ptr IUnknown)
-> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> IO Result
xrCreateSpatialAnchorFromPerceptionAnchorMSFT' = FunPtr
  (Ptr Session_T
   -> ("perceptionAnchor" ::: Ptr IUnknown)
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO Result)
-> Ptr Session_T
-> ("perceptionAnchor" ::: Ptr IUnknown)
-> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> IO Result
mkXrCreateSpatialAnchorFromPerceptionAnchorMSFT FunPtr
  (Ptr Session_T
   -> ("perceptionAnchor" ::: Ptr IUnknown)
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO Result)
xrCreateSpatialAnchorFromPerceptionAnchorMSFTPtr
  "anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)
pAnchor <- ((("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
  -> IO SpatialAnchorMSFT)
 -> IO SpatialAnchorMSFT)
-> ContT
     SpatialAnchorMSFT IO ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO SpatialAnchorMSFT)
  -> IO SpatialAnchorMSFT)
 -> ContT
      SpatialAnchorMSFT IO ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)))
-> ((("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
     -> IO SpatialAnchorMSFT)
    -> IO SpatialAnchorMSFT)
-> ContT
     SpatialAnchorMSFT IO ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
forall a b. (a -> b) -> a -> b
$ IO ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> (("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)) -> IO ())
-> (("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
    -> IO SpatialAnchorMSFT)
-> IO SpatialAnchorMSFT
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
forall a. Int -> IO (Ptr a)
callocBytes @(Ptr SpatialAnchorMSFT_T) 8) ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)) -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT SpatialAnchorMSFT IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT SpatialAnchorMSFT IO Result)
-> IO Result -> ContT SpatialAnchorMSFT IO Result
forall a b. (a -> b) -> a -> b
$ String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "xrCreateSpatialAnchorFromPerceptionAnchorMSFT" (Ptr Session_T
-> ("perceptionAnchor" ::: Ptr IUnknown)
-> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> IO Result
xrCreateSpatialAnchorFromPerceptionAnchorMSFT' (Session -> Ptr Session_T
sessionHandle (Session
session)) ("perceptionAnchor" ::: Ptr IUnknown
perceptionAnchor) ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)
pAnchor))
  IO () -> ContT SpatialAnchorMSFT IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT SpatialAnchorMSFT IO ())
-> IO () -> ContT SpatialAnchorMSFT 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))
  Ptr SpatialAnchorMSFT_T
anchor <- IO (Ptr SpatialAnchorMSFT_T)
-> ContT SpatialAnchorMSFT IO (Ptr SpatialAnchorMSFT_T)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO (Ptr SpatialAnchorMSFT_T)
 -> ContT SpatialAnchorMSFT IO (Ptr SpatialAnchorMSFT_T))
-> IO (Ptr SpatialAnchorMSFT_T)
-> ContT SpatialAnchorMSFT IO (Ptr SpatialAnchorMSFT_T)
forall a b. (a -> b) -> a -> b
$ ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> IO (Ptr SpatialAnchorMSFT_T)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr SpatialAnchorMSFT_T) "anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)
pAnchor
  SpatialAnchorMSFT -> ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SpatialAnchorMSFT -> ContT SpatialAnchorMSFT IO SpatialAnchorMSFT)
-> SpatialAnchorMSFT
-> ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
forall a b. (a -> b) -> a -> b
$ (((\h :: Ptr SpatialAnchorMSFT_T
h -> Ptr SpatialAnchorMSFT_T -> InstanceCmds -> SpatialAnchorMSFT
SpatialAnchorMSFT Ptr SpatialAnchorMSFT_T
h InstanceCmds
cmds ) Ptr SpatialAnchorMSFT_T
anchor))

-- | A convenience wrapper to make a compatible pair of calls to
-- 'createSpatialAnchorFromPerceptionAnchorMSFT' and
-- 'destroySpatialAnchorMSFT'
--
-- To ensure that 'destroySpatialAnchorMSFT' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the last argument.
-- To just extract the pair pass '(,)' as the last argument.
--
withSpatialAnchorFromPerceptionAnchorMSFT :: forall io r . MonadIO io => Session -> Ptr IUnknown -> (io SpatialAnchorMSFT -> (SpatialAnchorMSFT -> io ()) -> r) -> r
withSpatialAnchorFromPerceptionAnchorMSFT :: Session
-> ("perceptionAnchor" ::: Ptr IUnknown)
-> (io SpatialAnchorMSFT -> (SpatialAnchorMSFT -> io ()) -> r)
-> r
withSpatialAnchorFromPerceptionAnchorMSFT session :: Session
session perceptionAnchor :: "perceptionAnchor" ::: Ptr IUnknown
perceptionAnchor b :: io SpatialAnchorMSFT -> (SpatialAnchorMSFT -> io ()) -> r
b =
  io SpatialAnchorMSFT -> (SpatialAnchorMSFT -> io ()) -> r
b (Session
-> ("perceptionAnchor" ::: Ptr IUnknown) -> io SpatialAnchorMSFT
forall (io :: * -> *).
MonadIO io =>
Session
-> ("perceptionAnchor" ::: Ptr IUnknown) -> io SpatialAnchorMSFT
createSpatialAnchorFromPerceptionAnchorMSFT Session
session "perceptionAnchor" ::: Ptr IUnknown
perceptionAnchor)
    (\(SpatialAnchorMSFT
o0) -> SpatialAnchorMSFT -> io ()
forall (io :: * -> *). MonadIO io => SpatialAnchorMSFT -> io ()
destroySpatialAnchorMSFT SpatialAnchorMSFT
o0)


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

-- | xrTryGetPerceptionAnchorFromSpatialAnchorMSFT - Convert a
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT' to a Windows SpatialAnchor
--
-- == Parameter Descriptions
--
-- = Description
--
-- If the runtime can convert the @anchor@ to a
-- <https://docs.microsoft.com/uwp/api/Windows.Perception.Spatial.SpatialAnchor Windows.Perception.Spatial.SpatialAnchor>
-- object, this function /must/ return
-- 'OpenXR.Core10.Enums.Result.SUCCESS', and the output 'IUnknown' in the
-- pointer of @perceptionAnchor@ /must/ be not @NULL@. This also increments
-- the refcount of the object. The application /can/ then use
-- @QueryInterface@ to get the pointer for
-- <https://docs.microsoft.com/uwp/api/Windows.Perception.Spatial.SpatialAnchor Windows.Perception.Spatial.SpatialAnchor>
-- object. The application /should/ release the COM pointer after done with
-- the object, or attach it to a smart COM pointer such as
-- @winrt::com_ptr@.
--
-- If the runtime cannot convert the @anchor@ to a
-- <https://docs.microsoft.com/uwp/api/Windows.Perception.Spatial.SpatialAnchor Windows.Perception.Spatial.SpatialAnchor>
-- object, the function /must/ return 'OpenXR.Core10.Enums.Result.SUCCESS',
-- and the output 'IUnknown' in the pointer of @perceptionAnchor@ /must/ be
-- @NULL@.
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-xrTryGetPerceptionAnchorFromSpatialAnchorMSFT-extension-notenabled#
--     The @@ extension /must/ be enabled prior to calling
--     'tryGetPerceptionAnchorFromSpatialAnchorMSFT'
--
-- -   #VUID-xrTryGetPerceptionAnchorFromSpatialAnchorMSFT-session-parameter#
--     @session@ /must/ be a valid 'OpenXR.Core10.Handles.Session' handle
--
-- -   #VUID-xrTryGetPerceptionAnchorFromSpatialAnchorMSFT-anchor-parameter#
--     @anchor@ /must/ be a valid
--     'OpenXR.Extensions.Handles.SpatialAnchorMSFT' handle
--
-- -   #VUID-xrTryGetPerceptionAnchorFromSpatialAnchorMSFT-perceptionAnchor-parameter#
--     @perceptionAnchor@ /must/ be a pointer to a pointer to an 'IUnknown'
--     value
--
-- -   #VUID-xrTryGetPerceptionAnchorFromSpatialAnchorMSFT-anchor-parent#
--     @anchor@ /must/ have been created, allocated, or retrieved from
--     @session@
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-successcodes Success>]
--
--     -   'OpenXR.Core10.Enums.Result.SUCCESS'
--
-- [<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_OUT_OF_MEMORY'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_FUNCTION_UNSUPPORTED'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_VALIDATION_FAILURE'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_HANDLE_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_SESSION_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.SESSION_LOSS_PENDING'
--
-- = See Also
--
-- 'OpenXR.Core10.Handles.Session',
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT'
tryGetPerceptionAnchorFromSpatialAnchorMSFT :: forall io
                                             . (MonadIO io)
                                            => -- | @session@ is the specified 'OpenXR.Core10.Handles.Session'.
                                               Session
                                            -> -- | @anchor@ is a valid 'OpenXR.Extensions.Handles.SpatialAnchorMSFT'
                                               -- handle.
                                               SpatialAnchorMSFT
                                            -> io (("perceptionAnchor" ::: Ptr IUnknown))
tryGetPerceptionAnchorFromSpatialAnchorMSFT :: Session
-> SpatialAnchorMSFT -> io ("perceptionAnchor" ::: Ptr IUnknown)
tryGetPerceptionAnchorFromSpatialAnchorMSFT session :: Session
session anchor :: SpatialAnchorMSFT
anchor = IO ("perceptionAnchor" ::: Ptr IUnknown)
-> io ("perceptionAnchor" ::: Ptr IUnknown)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ("perceptionAnchor" ::: Ptr IUnknown)
 -> io ("perceptionAnchor" ::: Ptr IUnknown))
-> (ContT
      ("perceptionAnchor" ::: Ptr IUnknown)
      IO
      ("perceptionAnchor" ::: Ptr IUnknown)
    -> IO ("perceptionAnchor" ::: Ptr IUnknown))
-> ContT
     ("perceptionAnchor" ::: Ptr IUnknown)
     IO
     ("perceptionAnchor" ::: Ptr IUnknown)
-> io ("perceptionAnchor" ::: Ptr IUnknown)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  ("perceptionAnchor" ::: Ptr IUnknown)
  IO
  ("perceptionAnchor" ::: Ptr IUnknown)
-> IO ("perceptionAnchor" ::: Ptr IUnknown)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   ("perceptionAnchor" ::: Ptr IUnknown)
   IO
   ("perceptionAnchor" ::: Ptr IUnknown)
 -> io ("perceptionAnchor" ::: Ptr IUnknown))
-> ContT
     ("perceptionAnchor" ::: Ptr IUnknown)
     IO
     ("perceptionAnchor" ::: Ptr IUnknown)
-> io ("perceptionAnchor" ::: Ptr IUnknown)
forall a b. (a -> b) -> a -> b
$ do
  let xrTryGetPerceptionAnchorFromSpatialAnchorMSFTPtr :: FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorMSFT_T
   -> ("perceptionAnchor"
       ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
   -> IO Result)
xrTryGetPerceptionAnchorFromSpatialAnchorMSFTPtr = InstanceCmds
-> FunPtr
     (Ptr Session_T
      -> Ptr SpatialAnchorMSFT_T
      -> ("perceptionAnchor"
          ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
      -> IO Result)
pXrTryGetPerceptionAnchorFromSpatialAnchorMSFT (Session -> InstanceCmds
instanceCmds (Session
session :: Session))
  IO () -> ContT ("perceptionAnchor" ::: Ptr IUnknown) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("perceptionAnchor" ::: Ptr IUnknown) IO ())
-> IO () -> ContT ("perceptionAnchor" ::: Ptr IUnknown) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorMSFT_T
   -> ("perceptionAnchor"
       ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
   -> IO Result)
xrTryGetPerceptionAnchorFromSpatialAnchorMSFTPtr FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorMSFT_T
   -> ("perceptionAnchor"
       ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
   -> IO Result)
-> FunPtr
     (Ptr Session_T
      -> Ptr SpatialAnchorMSFT_T
      -> ("perceptionAnchor"
          ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
      -> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorMSFT_T
   -> ("perceptionAnchor"
       ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
   -> 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 xrTryGetPerceptionAnchorFromSpatialAnchorMSFT is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let xrTryGetPerceptionAnchorFromSpatialAnchorMSFT' :: Ptr Session_T
-> Ptr SpatialAnchorMSFT_T
-> ("perceptionAnchor"
    ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
-> IO Result
xrTryGetPerceptionAnchorFromSpatialAnchorMSFT' = FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorMSFT_T
   -> ("perceptionAnchor"
       ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
   -> IO Result)
-> Ptr Session_T
-> Ptr SpatialAnchorMSFT_T
-> ("perceptionAnchor"
    ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
-> IO Result
mkXrTryGetPerceptionAnchorFromSpatialAnchorMSFT FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorMSFT_T
   -> ("perceptionAnchor"
       ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
   -> IO Result)
xrTryGetPerceptionAnchorFromSpatialAnchorMSFTPtr
  "perceptionAnchor" ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown)
pPerceptionAnchor <- ((("perceptionAnchor"
   ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
  -> IO ("perceptionAnchor" ::: Ptr IUnknown))
 -> IO ("perceptionAnchor" ::: Ptr IUnknown))
-> ContT
     ("perceptionAnchor" ::: Ptr IUnknown)
     IO
     ("perceptionAnchor" ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((("perceptionAnchor"
    ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
   -> IO ("perceptionAnchor" ::: Ptr IUnknown))
  -> IO ("perceptionAnchor" ::: Ptr IUnknown))
 -> ContT
      ("perceptionAnchor" ::: Ptr IUnknown)
      IO
      ("perceptionAnchor" ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown)))
-> ((("perceptionAnchor"
      ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
     -> IO ("perceptionAnchor" ::: Ptr IUnknown))
    -> IO ("perceptionAnchor" ::: Ptr IUnknown))
-> ContT
     ("perceptionAnchor" ::: Ptr IUnknown)
     IO
     ("perceptionAnchor" ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
forall a b. (a -> b) -> a -> b
$ IO
  ("perceptionAnchor" ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
-> (("perceptionAnchor"
     ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
    -> IO ())
-> (("perceptionAnchor"
     ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
    -> IO ("perceptionAnchor" ::: Ptr IUnknown))
-> IO ("perceptionAnchor" ::: Ptr IUnknown)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int
-> IO
     ("perceptionAnchor" ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
forall a. Int -> IO (Ptr a)
callocBytes @(Ptr IUnknown) 8) ("perceptionAnchor" ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
-> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT ("perceptionAnchor" ::: Ptr IUnknown) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result
 -> ContT ("perceptionAnchor" ::: Ptr IUnknown) IO Result)
-> IO Result
-> ContT ("perceptionAnchor" ::: Ptr IUnknown) IO Result
forall a b. (a -> b) -> a -> b
$ String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "xrTryGetPerceptionAnchorFromSpatialAnchorMSFT" (Ptr Session_T
-> Ptr SpatialAnchorMSFT_T
-> ("perceptionAnchor"
    ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
-> IO Result
xrTryGetPerceptionAnchorFromSpatialAnchorMSFT' (Session -> Ptr Session_T
sessionHandle (Session
session)) (SpatialAnchorMSFT -> Ptr SpatialAnchorMSFT_T
spatialAnchorMSFTHandle (SpatialAnchorMSFT
anchor)) ("perceptionAnchor" ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown)
pPerceptionAnchor))
  IO () -> ContT ("perceptionAnchor" ::: Ptr IUnknown) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("perceptionAnchor" ::: Ptr IUnknown) IO ())
-> IO () -> ContT ("perceptionAnchor" ::: Ptr IUnknown) 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))
  "perceptionAnchor" ::: Ptr IUnknown
perceptionAnchor <- IO ("perceptionAnchor" ::: Ptr IUnknown)
-> ContT
     ("perceptionAnchor" ::: Ptr IUnknown)
     IO
     ("perceptionAnchor" ::: Ptr IUnknown)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("perceptionAnchor" ::: Ptr IUnknown)
 -> ContT
      ("perceptionAnchor" ::: Ptr IUnknown)
      IO
      ("perceptionAnchor" ::: Ptr IUnknown))
-> IO ("perceptionAnchor" ::: Ptr IUnknown)
-> ContT
     ("perceptionAnchor" ::: Ptr IUnknown)
     IO
     ("perceptionAnchor" ::: Ptr IUnknown)
forall a b. (a -> b) -> a -> b
$ ("perceptionAnchor" ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown))
-> IO ("perceptionAnchor" ::: Ptr IUnknown)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr IUnknown) "perceptionAnchor" ::: Ptr ("perceptionAnchor" ::: Ptr IUnknown)
pPerceptionAnchor
  ("perceptionAnchor" ::: Ptr IUnknown)
-> ContT
     ("perceptionAnchor" ::: Ptr IUnknown)
     IO
     ("perceptionAnchor" ::: Ptr IUnknown)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("perceptionAnchor" ::: Ptr IUnknown)
 -> ContT
      ("perceptionAnchor" ::: Ptr IUnknown)
      IO
      ("perceptionAnchor" ::: Ptr IUnknown))
-> ("perceptionAnchor" ::: Ptr IUnknown)
-> ContT
     ("perceptionAnchor" ::: Ptr IUnknown)
     IO
     ("perceptionAnchor" ::: Ptr IUnknown)
forall a b. (a -> b) -> a -> b
$ ("perceptionAnchor" ::: Ptr IUnknown
perceptionAnchor)


type MSFT_perception_anchor_interop_SPEC_VERSION = 1

-- No documentation found for TopLevel "XR_MSFT_perception_anchor_interop_SPEC_VERSION"
pattern MSFT_perception_anchor_interop_SPEC_VERSION :: forall a . Integral a => a
pattern $bMSFT_perception_anchor_interop_SPEC_VERSION :: a
$mMSFT_perception_anchor_interop_SPEC_VERSION :: forall r a. Integral a => a -> (Void# -> r) -> (Void# -> r) -> r
MSFT_perception_anchor_interop_SPEC_VERSION = 1


type MSFT_PERCEPTION_ANCHOR_INTEROP_EXTENSION_NAME = "XR_MSFT_perception_anchor_interop"

-- No documentation found for TopLevel "XR_MSFT_PERCEPTION_ANCHOR_INTEROP_EXTENSION_NAME"
pattern MSFT_PERCEPTION_ANCHOR_INTEROP_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
pattern $bMSFT_PERCEPTION_ANCHOR_INTEROP_EXTENSION_NAME :: a
$mMSFT_PERCEPTION_ANCHOR_INTEROP_EXTENSION_NAME :: forall r a.
(Eq a, IsString a) =>
a -> (Void# -> r) -> (Void# -> r) -> r
MSFT_PERCEPTION_ANCHOR_INTEROP_EXTENSION_NAME = "XR_MSFT_perception_anchor_interop"


data IUnknown