{-# language CPP #-}
-- No documentation found for Chapter "SemanticPaths"
module OpenXR.Core10.SemanticPaths  ( stringToPath
                                    , pathToString
                                    , Path(..)
                                    ) 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 Foreign.Ptr (nullPtr)
import GHC.Show (showParen)
import Numeric (showHex)
import Data.ByteString (packCString)
import Data.ByteString (useAsCString)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Cont (evalContT)
import Foreign.C.Types (CChar(..))
import OpenXR.Zero (Zero)
import Control.Monad.IO.Class (MonadIO)
import Foreign.C.Types (CChar)
import Foreign.Storable (Storable)
import Foreign.Storable (Storable(peek))
import GHC.IO.Exception (IOErrorType(..))
import GHC.IO.Exception (IOException(..))
import Foreign.Ptr (FunPtr)
import Foreign.Ptr (Ptr)
import Data.Word (Word32)
import Data.Word (Word64)
import Data.ByteString (ByteString)
import Control.Monad.Trans.Cont (ContT(..))
import OpenXR.NamedType ((:::))
import OpenXR.Core10.Handles (Instance)
import OpenXR.Core10.Handles (Instance(..))
import OpenXR.Dynamic (InstanceCmds(pXrPathToString))
import OpenXR.Dynamic (InstanceCmds(pXrStringToPath))
import OpenXR.Core10.Handles (Instance_T)
import OpenXR.Exception (OpenXrException(..))
import OpenXR.Core10.Enums.Result (Result)
import OpenXR.Core10.Enums.Result (Result(..))
import OpenXR.Core10.Enums.Result (Result(SUCCESS))
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkXrStringToPath
  :: FunPtr (Ptr Instance_T -> Ptr CChar -> Ptr Path -> IO Result) -> Ptr Instance_T -> Ptr CChar -> Ptr Path -> IO Result

-- | xrStringToPath - Converts a string to a semantic path
--
-- == Parameter Descriptions
--
-- = Description
--
-- 'stringToPath' retrieves the
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- value for a well-formed path string. If such a value had not yet been
-- assigned by the runtime to the provided path string in this
-- 'OpenXR.Core10.Handles.Instance', one /must/ be assigned at this point.
-- All calls to this function with the same
-- 'OpenXR.Core10.Handles.Instance' and path string /must/ retrieve the
-- same
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- value. Upon failure, 'stringToPath' /must/ return an appropriate
-- 'OpenXR.Core10.Enums.Result.Result', and /may/ set the output parameter
-- to 'OpenXR.Core10.APIConstants.NULL_PATH'. See
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#path-atom-type Path Atom Type>
-- for the conditions under which an error /may/ be returned when this
-- function is given a valid 'OpenXR.Core10.Handles.Instance' and a
-- well-formed path string.
--
-- If the runtime’s resources are exhausted and it cannot create the path,
-- a return value of 'OpenXR.Core10.Enums.Result.ERROR_PATH_COUNT_EXCEEDED'
-- /must/ be returned. If the application specifies a string that is not a
-- well-formed path string,
-- 'OpenXR.Core10.Enums.Result.ERROR_PATH_FORMAT_INVALID' /must/ be
-- returned.
--
-- A return value of 'OpenXR.Core10.Enums.Result.SUCCESS' from
-- 'stringToPath' /may/ not necessarily imply that the runtime has a
-- component or other source of data that will be accessible through that
-- semantic path. It only means that the path string supplied was
-- well-formed and that the retrieved
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- maps to the given path string within and during the lifetime of the
-- 'OpenXR.Core10.Handles.Instance' given.
--
-- == 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_HANDLE_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_INSTANCE_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_RUNTIME_FAILURE'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_PATH_FORMAT_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_PATH_COUNT_EXCEEDED'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_VALIDATION_FAILURE'
--
-- = See Also
--
-- 'OpenXR.Core10.Handles.Instance',
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >,
-- 'pathToString'
stringToPath :: forall io
              . (MonadIO io)
             => -- | @instance@ is an instance previously created.
                --
                -- #VUID-xrStringToPath-instance-parameter# @instance@ /must/ be a valid
                -- 'OpenXR.Core10.Handles.Instance' handle
                Instance
             -> -- | @pathString@ is the path name string to retrieve the associated
                -- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
                -- for.
                --
                -- #VUID-xrStringToPath-pathString-parameter# @pathString@ /must/ be a
                -- null-terminated UTF-8 string
                ("pathString" ::: ByteString)
             -> io (Path)
stringToPath :: Instance -> ("pathString" ::: ByteString) -> io Path
stringToPath instance' :: Instance
instance' pathString :: "pathString" ::: ByteString
pathString = IO Path -> io Path
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Path -> io Path)
-> (ContT Path IO Path -> IO Path) -> ContT Path IO Path -> io Path
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT Path IO Path -> IO Path
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT Path IO Path -> io Path) -> ContT Path IO Path -> io Path
forall a b. (a -> b) -> a -> b
$ do
  let xrStringToPathPtr :: FunPtr
  (Ptr Instance_T
   -> ("pathString" ::: Ptr CChar) -> Ptr Path -> IO Result)
xrStringToPathPtr = InstanceCmds
-> FunPtr
     (Ptr Instance_T
      -> ("pathString" ::: Ptr CChar) -> Ptr Path -> IO Result)
pXrStringToPath (Instance -> InstanceCmds
instanceCmds (Instance
instance' :: Instance))
  IO () -> ContT Path IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Path IO ()) -> IO () -> ContT Path IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Instance_T
   -> ("pathString" ::: Ptr CChar) -> Ptr Path -> IO Result)
xrStringToPathPtr FunPtr
  (Ptr Instance_T
   -> ("pathString" ::: Ptr CChar) -> Ptr Path -> IO Result)
-> FunPtr
     (Ptr Instance_T
      -> ("pathString" ::: Ptr CChar) -> Ptr Path -> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
  (Ptr Instance_T
   -> ("pathString" ::: Ptr CChar) -> Ptr Path -> 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 xrStringToPath is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let xrStringToPath' :: Ptr Instance_T
-> ("pathString" ::: Ptr CChar) -> Ptr Path -> IO Result
xrStringToPath' = FunPtr
  (Ptr Instance_T
   -> ("pathString" ::: Ptr CChar) -> Ptr Path -> IO Result)
-> Ptr Instance_T
-> ("pathString" ::: Ptr CChar)
-> Ptr Path
-> IO Result
mkXrStringToPath FunPtr
  (Ptr Instance_T
   -> ("pathString" ::: Ptr CChar) -> Ptr Path -> IO Result)
xrStringToPathPtr
  "pathString" ::: Ptr CChar
pathString' <- ((("pathString" ::: Ptr CChar) -> IO Path) -> IO Path)
-> ContT Path IO ("pathString" ::: Ptr CChar)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((("pathString" ::: Ptr CChar) -> IO Path) -> IO Path)
 -> ContT Path IO ("pathString" ::: Ptr CChar))
-> ((("pathString" ::: Ptr CChar) -> IO Path) -> IO Path)
-> ContT Path IO ("pathString" ::: Ptr CChar)
forall a b. (a -> b) -> a -> b
$ ("pathString" ::: ByteString)
-> (("pathString" ::: Ptr CChar) -> IO Path) -> IO Path
forall a.
("pathString" ::: ByteString)
-> (("pathString" ::: Ptr CChar) -> IO a) -> IO a
useAsCString ("pathString" ::: ByteString
pathString)
  Ptr Path
pPath <- ((Ptr Path -> IO Path) -> IO Path) -> ContT Path IO (Ptr Path)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Path -> IO Path) -> IO Path) -> ContT Path IO (Ptr Path))
-> ((Ptr Path -> IO Path) -> IO Path) -> ContT Path IO (Ptr Path)
forall a b. (a -> b) -> a -> b
$ IO (Ptr Path)
-> (Ptr Path -> IO ()) -> (Ptr Path -> IO Path) -> IO Path
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr Path)
forall a. Int -> IO (Ptr a)
callocBytes @Path 8) Ptr Path -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT Path IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT Path IO Result)
-> IO Result -> ContT Path IO Result
forall a b. (a -> b) -> a -> b
$ String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "xrStringToPath" (Ptr Instance_T
-> ("pathString" ::: Ptr CChar) -> Ptr Path -> IO Result
xrStringToPath' (Instance -> Ptr Instance_T
instanceHandle (Instance
instance')) "pathString" ::: Ptr CChar
pathString' (Ptr Path
pPath))
  IO () -> ContT Path IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Path IO ()) -> IO () -> ContT Path 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))
  Path
path <- IO Path -> ContT Path IO Path
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Path -> ContT Path IO Path) -> IO Path -> ContT Path IO Path
forall a b. (a -> b) -> a -> b
$ Ptr Path -> IO Path
forall a. Storable a => Ptr a -> IO a
peek @Path Ptr Path
pPath
  Path -> ContT Path IO Path
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Path -> ContT Path IO Path) -> Path -> ContT Path IO Path
forall a b. (a -> b) -> a -> b
$ (Path
path)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkXrPathToString
  :: FunPtr (Ptr Instance_T -> Path -> Word32 -> Ptr Word32 -> Ptr CChar -> IO Result) -> Ptr Instance_T -> Path -> Word32 -> Ptr Word32 -> Ptr CChar -> IO Result

-- | xrPathToString - Converts a semantic path to a string
--
-- == Parameter Descriptions
--
-- -   @instance@ is an instance previously created.
--
-- -   @path@ is the valid
--     <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
--     value to retrieve the path string for.
--
-- -   @bufferCapacityInput@ is the capacity of the buffer, or 0 to
--     indicate a request to retrieve the required capacity.
--
-- -   @bufferCountOutput@ is a pointer to the count of characters written
--     (including the terminating \'\\0\'), or a pointer to the required
--     capacity in the case that @bufferCapacityInput@ is 0.
--
-- -   @buffer@ is a pointer to an application-allocated buffer that will
--     be filled with the semantic path string. It /can/ be @NULL@ if
--     @bufferCapacityInput@ is 0.
--
-- -   See
--     <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#buffer-size-parameters Buffer Size Parameters>
--     chapter for a detailed description of retrieving the required
--     @buffer@ size.
--
-- = Description
--
-- 'pathToString' retrieves the path name string associated with an
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >,
-- in the context of a given 'OpenXR.Core10.Handles.Instance', in the form
-- of a @NULL@ terminated string placed into a /caller-allocated/ buffer.
-- Since the mapping between a well-formed path name string and an
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- is bijective, there will always be exactly one string for each valid
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- value. This can be useful if the calling application receives an
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- value that they had not previously retrieved via 'stringToPath'. During
-- the lifetime of the given 'OpenXR.Core10.Handles.Instance', the path
-- name string retrieved by this function for a given valid
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- will not change. For invalid paths, including
-- 'OpenXR.Core10.APIConstants.NULL_PATH',
-- 'OpenXR.Core10.Enums.Result.ERROR_PATH_INVALID' /must/ be returned.
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-xrPathToString-instance-parameter# @instance@ /must/ be a
--     valid 'OpenXR.Core10.Handles.Instance' handle
--
-- -   #VUID-xrPathToString-bufferCountOutput-parameter#
--     @bufferCountOutput@ /must/ be a pointer to a @uint32_t@ value
--
-- -   #VUID-xrPathToString-buffer-parameter# If @bufferCapacityInput@ is
--     not @0@, @buffer@ /must/ be a pointer to an array of
--     @bufferCapacityInput@ char values
--
-- == 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_HANDLE_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_INSTANCE_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_RUNTIME_FAILURE'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_PATH_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_SIZE_INSUFFICIENT'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_VALIDATION_FAILURE'
--
-- = See Also
--
-- 'OpenXR.Core10.Handles.Instance',
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >,
-- 'stringToPath'
pathToString :: forall io
              . (MonadIO io)
             => -- No documentation found for Nested "xrPathToString" "instance"
                Instance
             -> -- No documentation found for Nested "xrPathToString" "path"
                Path
             -> io (("buffer" ::: ByteString))
pathToString :: Instance -> Path -> io ("pathString" ::: ByteString)
pathToString instance' :: Instance
instance' path :: Path
path = IO ("pathString" ::: ByteString)
-> io ("pathString" ::: ByteString)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ("pathString" ::: ByteString)
 -> io ("pathString" ::: ByteString))
-> (ContT
      ("pathString" ::: ByteString) IO ("pathString" ::: ByteString)
    -> IO ("pathString" ::: ByteString))
-> ContT
     ("pathString" ::: ByteString) IO ("pathString" ::: ByteString)
-> io ("pathString" ::: ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  ("pathString" ::: ByteString) IO ("pathString" ::: ByteString)
-> IO ("pathString" ::: ByteString)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   ("pathString" ::: ByteString) IO ("pathString" ::: ByteString)
 -> io ("pathString" ::: ByteString))
-> ContT
     ("pathString" ::: ByteString) IO ("pathString" ::: ByteString)
-> io ("pathString" ::: ByteString)
forall a b. (a -> b) -> a -> b
$ do
  let xrPathToStringPtr :: FunPtr
  (Ptr Instance_T
   -> Path
   -> ("bufferCapacityInput" ::: Word32)
   -> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
   -> ("pathString" ::: Ptr CChar)
   -> IO Result)
xrPathToStringPtr = InstanceCmds
-> FunPtr
     (Ptr Instance_T
      -> Path
      -> ("bufferCapacityInput" ::: Word32)
      -> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
      -> ("pathString" ::: Ptr CChar)
      -> IO Result)
pXrPathToString (Instance -> InstanceCmds
instanceCmds (Instance
instance' :: Instance))
  IO () -> ContT ("pathString" ::: ByteString) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("pathString" ::: ByteString) IO ())
-> IO () -> ContT ("pathString" ::: ByteString) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Instance_T
   -> Path
   -> ("bufferCapacityInput" ::: Word32)
   -> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
   -> ("pathString" ::: Ptr CChar)
   -> IO Result)
xrPathToStringPtr FunPtr
  (Ptr Instance_T
   -> Path
   -> ("bufferCapacityInput" ::: Word32)
   -> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
   -> ("pathString" ::: Ptr CChar)
   -> IO Result)
-> FunPtr
     (Ptr Instance_T
      -> Path
      -> ("bufferCapacityInput" ::: Word32)
      -> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
      -> ("pathString" ::: Ptr CChar)
      -> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
  (Ptr Instance_T
   -> Path
   -> ("bufferCapacityInput" ::: Word32)
   -> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
   -> ("pathString" ::: Ptr CChar)
   -> 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 xrPathToString is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let xrPathToString' :: Ptr Instance_T
-> Path
-> ("bufferCapacityInput" ::: Word32)
-> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
-> ("pathString" ::: Ptr CChar)
-> IO Result
xrPathToString' = FunPtr
  (Ptr Instance_T
   -> Path
   -> ("bufferCapacityInput" ::: Word32)
   -> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
   -> ("pathString" ::: Ptr CChar)
   -> IO Result)
-> Ptr Instance_T
-> Path
-> ("bufferCapacityInput" ::: Word32)
-> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
-> ("pathString" ::: Ptr CChar)
-> IO Result
mkXrPathToString FunPtr
  (Ptr Instance_T
   -> Path
   -> ("bufferCapacityInput" ::: Word32)
   -> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
   -> ("pathString" ::: Ptr CChar)
   -> IO Result)
xrPathToStringPtr
  let instance'' :: Ptr Instance_T
instance'' = Instance -> Ptr Instance_T
instanceHandle (Instance
instance')
  "bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32)
pBufferCountOutput <- ((("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
  -> IO ("pathString" ::: ByteString))
 -> IO ("pathString" ::: ByteString))
-> ContT
     ("pathString" ::: ByteString)
     IO
     ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
   -> IO ("pathString" ::: ByteString))
  -> IO ("pathString" ::: ByteString))
 -> ContT
      ("pathString" ::: ByteString)
      IO
      ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32)))
-> ((("bufferCountOutput"
      ::: Ptr ("bufferCapacityInput" ::: Word32))
     -> IO ("pathString" ::: ByteString))
    -> IO ("pathString" ::: ByteString))
-> ContT
     ("pathString" ::: ByteString)
     IO
     ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
forall a b. (a -> b) -> a -> b
$ IO ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
-> (("bufferCountOutput"
     ::: Ptr ("bufferCapacityInput" ::: Word32))
    -> IO ())
-> (("bufferCountOutput"
     ::: Ptr ("bufferCapacityInput" ::: Word32))
    -> IO ("pathString" ::: ByteString))
-> IO ("pathString" ::: ByteString)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int
-> IO
     ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
forall a. Int -> IO (Ptr a)
callocBytes @Word32 4) ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
-> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT ("pathString" ::: ByteString) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT ("pathString" ::: ByteString) IO Result)
-> IO Result -> ContT ("pathString" ::: ByteString) IO Result
forall a b. (a -> b) -> a -> b
$ String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "xrPathToString" (Ptr Instance_T
-> Path
-> ("bufferCapacityInput" ::: Word32)
-> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
-> ("pathString" ::: Ptr CChar)
-> IO Result
xrPathToString' Ptr Instance_T
instance'' (Path
path) (0) ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32)
pBufferCountOutput) ("pathString" ::: Ptr CChar
forall a. Ptr a
nullPtr))
  IO () -> ContT ("pathString" ::: ByteString) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("pathString" ::: ByteString) IO ())
-> IO () -> ContT ("pathString" ::: ByteString) 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))
  "bufferCapacityInput" ::: Word32
bufferCountOutput <- IO ("bufferCapacityInput" ::: Word32)
-> ContT
     ("pathString" ::: ByteString) IO ("bufferCapacityInput" ::: Word32)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("bufferCapacityInput" ::: Word32)
 -> ContT
      ("pathString" ::: ByteString)
      IO
      ("bufferCapacityInput" ::: Word32))
-> IO ("bufferCapacityInput" ::: Word32)
-> ContT
     ("pathString" ::: ByteString) IO ("bufferCapacityInput" ::: Word32)
forall a b. (a -> b) -> a -> b
$ ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
-> IO ("bufferCapacityInput" ::: Word32)
forall a. Storable a => Ptr a -> IO a
peek @Word32 "bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32)
pBufferCountOutput
  "pathString" ::: Ptr CChar
pBuffer <- ((("pathString" ::: Ptr CChar) -> IO ("pathString" ::: ByteString))
 -> IO ("pathString" ::: ByteString))
-> ContT
     ("pathString" ::: ByteString) IO ("pathString" ::: Ptr CChar)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((("pathString" ::: Ptr CChar)
   -> IO ("pathString" ::: ByteString))
  -> IO ("pathString" ::: ByteString))
 -> ContT
      ("pathString" ::: ByteString) IO ("pathString" ::: Ptr CChar))
-> ((("pathString" ::: Ptr CChar)
     -> IO ("pathString" ::: ByteString))
    -> IO ("pathString" ::: ByteString))
-> ContT
     ("pathString" ::: ByteString) IO ("pathString" ::: Ptr CChar)
forall a b. (a -> b) -> a -> b
$ IO ("pathString" ::: Ptr CChar)
-> (("pathString" ::: Ptr CChar) -> IO ())
-> (("pathString" ::: Ptr CChar)
    -> IO ("pathString" ::: ByteString))
-> IO ("pathString" ::: ByteString)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO ("pathString" ::: Ptr CChar)
forall a. Int -> IO (Ptr a)
callocBytes @CChar (("bufferCapacityInput" ::: Word32) -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ("bufferCapacityInput" ::: Word32
bufferCountOutput))) ("pathString" ::: Ptr CChar) -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r' <- IO Result -> ContT ("pathString" ::: ByteString) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT ("pathString" ::: ByteString) IO Result)
-> IO Result -> ContT ("pathString" ::: ByteString) IO Result
forall a b. (a -> b) -> a -> b
$ String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "xrPathToString" (Ptr Instance_T
-> Path
-> ("bufferCapacityInput" ::: Word32)
-> ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32))
-> ("pathString" ::: Ptr CChar)
-> IO Result
xrPathToString' Ptr Instance_T
instance'' (Path
path) (("bufferCapacityInput" ::: Word32
bufferCountOutput)) ("bufferCountOutput" ::: Ptr ("bufferCapacityInput" ::: Word32)
pBufferCountOutput) ("pathString" ::: Ptr CChar
pBuffer))
  IO () -> ContT ("pathString" ::: ByteString) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("pathString" ::: ByteString) IO ())
-> IO () -> ContT ("pathString" ::: ByteString) 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'))
  "pathString" ::: ByteString
buffer' <- IO ("pathString" ::: ByteString)
-> ContT
     ("pathString" ::: ByteString) IO ("pathString" ::: ByteString)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("pathString" ::: ByteString)
 -> ContT
      ("pathString" ::: ByteString) IO ("pathString" ::: ByteString))
-> IO ("pathString" ::: ByteString)
-> ContT
     ("pathString" ::: ByteString) IO ("pathString" ::: ByteString)
forall a b. (a -> b) -> a -> b
$ ("pathString" ::: Ptr CChar) -> IO ("pathString" ::: ByteString)
packCString "pathString" ::: Ptr CChar
pBuffer
  ("pathString" ::: ByteString)
-> ContT
     ("pathString" ::: ByteString) IO ("pathString" ::: ByteString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("pathString" ::: ByteString)
 -> ContT
      ("pathString" ::: ByteString) IO ("pathString" ::: ByteString))
-> ("pathString" ::: ByteString)
-> ContT
     ("pathString" ::: ByteString) IO ("pathString" ::: ByteString)
forall a b. (a -> b) -> a -> b
$ ("pathString" ::: ByteString
buffer')


-- | XrPath - A semantic path
--
-- = Description
--
-- The
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- is an atom that connects an application with a single path, within the
-- context of a single instance. There is a bijective mapping between
-- well-formed path strings and atoms in use. This atom is used — in place
-- of the path name string it corresponds to — to retrieve state and
-- perform other operations.
--
-- As an
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- is only shorthand for a well-formed path string, they have no explicit
-- life cycle.
--
-- Lifetime is implicitly managed by the 'OpenXR.Core10.Handles.Instance'.
-- An
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- /must/ not be used unless it is received at execution time from the
-- runtime in the context of a particular 'OpenXR.Core10.Handles.Instance'.
-- Therefore, with the exception of 'OpenXR.Core10.APIConstants.NULL_PATH',
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- values /must/ not be specified as constant values in applications: the
-- corresponding path string /should/ be used instead. During the lifetime
-- of a given 'OpenXR.Core10.Handles.Instance', the
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- associated with that instance with any given well-formed path /must/ not
-- vary, and similarly the well-formed path string that corresponds to a
-- given
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- in that instance /must/ not vary. An
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath >
-- that is received from one 'OpenXR.Core10.Handles.Instance' /may/ not be
-- used with another. Such an invalid use /may/ be detected and result in
-- an error being returned, or it /may/ result in undefined behavior.
--
-- = See Also
--
-- 'OpenXR.Core10.APIConstants.NULL_PATH',
-- 'OpenXR.Core10.Input.ActionCreateInfo',
-- 'OpenXR.Core10.Space.ActionSpaceCreateInfo',
-- 'OpenXR.Core10.Input.ActionStateGetInfo',
-- 'OpenXR.Core10.Input.ActionSuggestedBinding',
-- 'OpenXR.Core10.Input.ActiveActionSet',
-- 'OpenXR.Core10.Haptics.HapticActionInfo',
-- 'OpenXR.Core10.Input.InputSourceLocalizedNameGetInfo',
-- 'OpenXR.Extensions.XR_VALVE_analog_threshold.InteractionProfileAnalogThresholdVALVE',
-- 'OpenXR.Core10.Input.InteractionProfileState',
-- 'OpenXR.Core10.Input.InteractionProfileSuggestedBinding',
-- 'OpenXR.Core10.Input.enumerateBoundSourcesForAction',
-- 'OpenXR.Extensions.XR_MSFT_controller_model.getControllerModelKeyMSFT',
-- 'OpenXR.Core10.Input.getCurrentInteractionProfile', 'pathToString',
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#xrSetInputDeviceActiveEXT xrSetInputDeviceActiveEXT>,
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#xrSetInputDeviceLocationEXT xrSetInputDeviceLocationEXT>,
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#xrSetInputDeviceStateBoolEXT xrSetInputDeviceStateBoolEXT>,
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#xrSetInputDeviceStateFloatEXT xrSetInputDeviceStateFloatEXT>,
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#xrSetInputDeviceStateVector2fEXT xrSetInputDeviceStateVector2fEXT>,
-- 'stringToPath'
newtype Path = Path Word64
  deriving newtype (Path -> Path -> Bool
(Path -> Path -> Bool) -> (Path -> Path -> Bool) -> Eq Path
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Path -> Path -> Bool
$c/= :: Path -> Path -> Bool
== :: Path -> Path -> Bool
$c== :: Path -> Path -> Bool
Eq, Eq Path
Eq Path =>
(Path -> Path -> Ordering)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Path)
-> (Path -> Path -> Path)
-> Ord Path
Path -> Path -> Bool
Path -> Path -> Ordering
Path -> Path -> Path
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Path -> Path -> Path
$cmin :: Path -> Path -> Path
max :: Path -> Path -> Path
$cmax :: Path -> Path -> Path
>= :: Path -> Path -> Bool
$c>= :: Path -> Path -> Bool
> :: Path -> Path -> Bool
$c> :: Path -> Path -> Bool
<= :: Path -> Path -> Bool
$c<= :: Path -> Path -> Bool
< :: Path -> Path -> Bool
$c< :: Path -> Path -> Bool
compare :: Path -> Path -> Ordering
$ccompare :: Path -> Path -> Ordering
$cp1Ord :: Eq Path
Ord, Ptr b -> Int -> IO Path
Ptr b -> Int -> Path -> IO ()
Ptr Path -> IO Path
Ptr Path -> Int -> IO Path
Ptr Path -> Int -> Path -> IO ()
Ptr Path -> Path -> IO ()
Path -> Int
(Path -> Int)
-> (Path -> Int)
-> (Ptr Path -> Int -> IO Path)
-> (Ptr Path -> Int -> Path -> IO ())
-> (forall b. Ptr b -> Int -> IO Path)
-> (forall b. Ptr b -> Int -> Path -> IO ())
-> (Ptr Path -> IO Path)
-> (Ptr Path -> Path -> IO ())
-> Storable Path
forall b. Ptr b -> Int -> IO Path
forall b. Ptr b -> Int -> Path -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
poke :: Ptr Path -> Path -> IO ()
$cpoke :: Ptr Path -> Path -> IO ()
peek :: Ptr Path -> IO Path
$cpeek :: Ptr Path -> IO Path
pokeByteOff :: Ptr b -> Int -> Path -> IO ()
$cpokeByteOff :: forall b. Ptr b -> Int -> Path -> IO ()
peekByteOff :: Ptr b -> Int -> IO Path
$cpeekByteOff :: forall b. Ptr b -> Int -> IO Path
pokeElemOff :: Ptr Path -> Int -> Path -> IO ()
$cpokeElemOff :: Ptr Path -> Int -> Path -> IO ()
peekElemOff :: Ptr Path -> Int -> IO Path
$cpeekElemOff :: Ptr Path -> Int -> IO Path
alignment :: Path -> Int
$calignment :: Path -> Int
sizeOf :: Path -> Int
$csizeOf :: Path -> Int
Storable, Path
Path -> Zero Path
forall a. a -> Zero a
zero :: Path
$czero :: Path
Zero)
instance Show Path where
  showsPrec :: Int -> Path -> ShowS
showsPrec p :: Int
p (Path x :: Word64
x) = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 11) (String -> ShowS
showString "Path 0x" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> ShowS
forall a. (Integral a, Show a) => a -> ShowS
showHex Word64
x)