content: {-# language CPP #-}
  -- | = Name
  --
  -- XR_KHR_convert_timespec_time - instance extension
  --
  -- = Specification
  --
  -- See
  -- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XR_KHR_convert_timespec_time  XR_KHR_convert_timespec_time>
  -- in the main specification for complete information.
  --
  -- = Registered Extension Number
  --
  -- 37
  --
  -- = Revision
  --
  -- 1
  --
  -- = Extension and Version Dependencies
  --
  -- -   Requires OpenXR 1.0
  --
  -- = See Also
  --
  -- 'convertTimeToTimespecTimeKHR', 'convertTimespecTimeToTimeKHR'
  --
  -- = Document Notes
  --
  -- For more information, see the
  -- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XR_KHR_convert_timespec_time OpenXR Specification>
  --
  -- This page is a generated document. Fixes and changes should be made to
  -- the generator scripts, not directly.
  module OpenXR.Extensions.XR_KHR_convert_timespec_time  ( convertTimeToTimespecTimeKHR
                                                         , convertTimespecTimeToTimeKHR
                                                         , KHR_convert_timespec_time_SPEC_VERSION
                                                         , pattern KHR_convert_timespec_time_SPEC_VERSION
                                                         , KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME
                                                         , pattern KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME
                                                         , Timespec(..)
                                                         ) 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 Foreign.Marshal.Utils (with)
  import GHC.Base (when)
  import GHC.IO (throwIO)
  import GHC.Ptr (castPtr)
  import GHC.Ptr (nullFunPtr)
  import Foreign.Ptr (plusPtr)
  import Control.Monad.Trans.Class (lift)
  import Control.Monad.Trans.Cont (evalContT)
  import Control.Monad.IO.Class (MonadIO)
  import Data.String (IsString)
  import Data.Typeable (Typeable)
  import Foreign.C.Types (CTime)
  import Foreign.Storable (Storable(..))
  import Foreign.Storable (Storable(peek))
  import GHC.Generics (Generic)
  import GHC.IO.Exception (IOErrorType(..))
  import GHC.IO.Exception (IOException(..))
  import Data.Int (Int64)
  import Foreign.Ptr (FunPtr)
  import Foreign.Ptr (Ptr)
  import Control.Monad.Trans.Cont (ContT(..))
  import OpenXR.NamedType ((:::))
  import OpenXR.Core10.Handles (Instance)
  import OpenXR.Core10.Handles (Instance(..))
  import OpenXR.Core10.Handles (Instance(Instance))
  import OpenXR.Dynamic (InstanceCmds(pXrConvertTimeToTimespecTimeKHR))
  import OpenXR.Dynamic (InstanceCmds(pXrConvertTimespecTimeToTimeKHR))
  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.FundamentalTypes (Time)
  import OpenXR.Core10.Enums.Result (Result(SUCCESS))
  foreign import ccall
  #if !defined(SAFE_FOREIGN_CALLS)
    unsafe
  #endif
    "dynamic" mkXrConvertTimeToTimespecTimeKHR
    :: FunPtr (Ptr Instance_T -> Time -> Ptr Timespec -> IO Result) -> Ptr Instance_T -> Time -> Ptr Timespec -> IO Result
  
  -- | xrConvertTimeToTimespecTimeKHR - Convert XrTime to timespec monotonic
  -- time
  --
  -- == Parameter Descriptions
  --
  -- = Description
  --
  -- The 'convertTimeToTimespecTimeKHR' function converts an
  -- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrTime >
  -- to time as if generated by @clock_gettime@.
  --
  -- If the output @unixTime@ cannot represent the input @time@, the runtime
  -- /must/ return 'OpenXR.Core10.Enums.Result.ERROR_TIME_INVALID'.
  --
  -- == Valid Usage (Implicit)
  --
  -- -   #VUID-xrConvertTimeToTimespecTimeKHR-extension-notenabled# The
  --     @XR_KHR_convert_timespec_time@ extension /must/ be enabled prior to
  --     calling 'convertTimeToTimespecTimeKHR'
  --
  -- -   #VUID-xrConvertTimeToTimespecTimeKHR-instance-parameter# @instance@
  --     /must/ be a valid 'OpenXR.Core10.Handles.Instance' handle
  --
  -- -   #VUID-xrConvertTimeToTimespecTimeKHR-timespecTime-parameter#
  --     @timespecTime@ /must/ be a pointer to a @timespec@ value
  --
  -- == 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_VALIDATION_FAILURE'
  --
  --     -   'OpenXR.Core10.Enums.Result.ERROR_TIME_INVALID'
  --
  --     -   'OpenXR.Core10.Enums.Result.ERROR_FUNCTION_UNSUPPORTED'
  --
  -- = See Also
  --
  -- 'OpenXR.Core10.Handles.Instance',
  -- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrTime >
  convertTimeToTimespecTimeKHR :: forall io
                                . (MonadIO io)
                               => -- | @instance@ is an 'OpenXR.Core10.Handles.Instance' handle previously
                                  -- created with 'OpenXR.Core10.Instance.createInstance'.
                                  Instance
                               -> -- | @time@ is an
                                  -- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrTime >.
                                  Time
                               -> io (("timespecTime" ::: Timespec))
  convertTimeToTimespecTimeKHR instance' time = liftIO . evalContT $ do
    let xrConvertTimeToTimespecTimeKHRPtr = pXrConvertTimeToTimespecTimeKHR (case instance' of Instance{instanceCmds} -> instanceCmds)
    lift $ unless (xrConvertTimeToTimespecTimeKHRPtr /= nullFunPtr) $
      throwIO $ IOError Nothing InvalidArgument "" "The function pointer for xrConvertTimeToTimespecTimeKHR is null" Nothing Nothing
    let xrConvertTimeToTimespecTimeKHR' = mkXrConvertTimeToTimespecTimeKHR xrConvertTimeToTimespecTimeKHRPtr
    pTimespecTime <- ContT $ bracket (callocBytes @Timespec 16) free
    r <- lift $ traceAroundEvent "xrConvertTimeToTimespecTimeKHR" (xrConvertTimeToTimespecTimeKHR'
                                                                     (instanceHandle (instance'))
                                                                     (time)
                                                                     (pTimespecTime))
    lift $ when (r < SUCCESS) (throwIO (OpenXrException r))
    timespecTime <- lift $ peek @Timespec pTimespecTime
    pure $ (timespecTime)
  
  
  foreign import ccall
  #if !defined(SAFE_FOREIGN_CALLS)
    unsafe
  #endif
    "dynamic" mkXrConvertTimespecTimeToTimeKHR
    :: FunPtr (Ptr Instance_T -> Ptr Timespec -> Ptr Time -> IO Result) -> Ptr Instance_T -> Ptr Timespec -> Ptr Time -> IO Result
  
  -- | xrConvertTimespecTimeToTimeKHR - Convert timespec monotonic time to
  -- XrTime
  --
  -- == Parameter Descriptions
  --
  -- = Description
  --
  -- The 'convertTimespecTimeToTimeKHR' function converts a time obtained by
  -- the @clock_gettime@ function to the equivalent
  -- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrTime >.
  --
  -- If the output @time@ cannot represent the input @unixTime@, the runtime
  -- /must/ return 'OpenXR.Core10.Enums.Result.ERROR_TIME_INVALID'.
  --
  -- == Valid Usage (Implicit)
  --
  -- -   #VUID-xrConvertTimespecTimeToTimeKHR-extension-notenabled# The
  --     @XR_KHR_convert_timespec_time@ extension /must/ be enabled prior to
  --     calling 'convertTimespecTimeToTimeKHR'
  --
  -- -   #VUID-xrConvertTimespecTimeToTimeKHR-instance-parameter# @instance@
  --     /must/ be a valid 'OpenXR.Core10.Handles.Instance' handle
  --
  -- -   #VUID-xrConvertTimespecTimeToTimeKHR-timespecTime-parameter#
  --     @timespecTime@ /must/ be a pointer to a valid @timespec@ value
  --
  -- -   #VUID-xrConvertTimespecTimeToTimeKHR-time-parameter# @time@ /must/
  --     be a pointer to an
  --     <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrTime >
  --     value
  --
  -- == 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_VALIDATION_FAILURE'
  --
  --     -   'OpenXR.Core10.Enums.Result.ERROR_TIME_INVALID'
  --
  --     -   'OpenXR.Core10.Enums.Result.ERROR_FUNCTION_UNSUPPORTED'
  --
  -- = See Also
  --
  -- 'OpenXR.Core10.Handles.Instance',
  -- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrTime >
  convertTimespecTimeToTimeKHR :: forall io
                                . (MonadIO io)
                               => -- | @instance@ is an 'OpenXR.Core10.Handles.Instance' handle previously
                                  -- created with 'OpenXR.Core10.Instance.createInstance'.
                                  Instance
                               -> -- No documentation found for Nested "xrConvertTimespecTimeToTimeKHR" "timespecTime"
                                  ("timespecTime" ::: Timespec)
                               -> io (Time)
  convertTimespecTimeToTimeKHR instance' timespecTime = liftIO . evalContT $ do
    let xrConvertTimespecTimeToTimeKHRPtr = pXrConvertTimespecTimeToTimeKHR (case instance' of Instance{instanceCmds} -> instanceCmds)
    lift $ unless (xrConvertTimespecTimeToTimeKHRPtr /= nullFunPtr) $
      throwIO $ IOError Nothing InvalidArgument "" "The function pointer for xrConvertTimespecTimeToTimeKHR is null" Nothing Nothing
    let xrConvertTimespecTimeToTimeKHR' = mkXrConvertTimespecTimeToTimeKHR xrConvertTimespecTimeToTimeKHRPtr
    timespecTime' <- ContT $ with (timespecTime)
    pTime <- ContT $ bracket (callocBytes @Time 8) free
    r <- lift $ traceAroundEvent "xrConvertTimespecTimeToTimeKHR" (xrConvertTimespecTimeToTimeKHR'
                                                                     (instanceHandle (instance'))
                                                                     timespecTime'
                                                                     (pTime))
    lift $ when (r < SUCCESS) (throwIO (OpenXrException r))
    time <- lift $ peek @Time pTime
    pure $ (time)
  
  
  type KHR_convert_timespec_time_SPEC_VERSION = 1
  
  -- No documentation found for TopLevel "XR_KHR_convert_timespec_time_SPEC_VERSION"
  pattern KHR_convert_timespec_time_SPEC_VERSION :: forall a . Integral a => a
  pattern KHR_convert_timespec_time_SPEC_VERSION = 1
  
  
  type KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME = "XR_KHR_convert_timespec_time"
  
  -- No documentation found for TopLevel "XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME"
  pattern KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
  pattern KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME = "XR_KHR_convert_timespec_time"
  
  
  data Timespec = Timespec
    { tv_sec :: CTime
    , tv_nsec :: Int64
    }
    deriving (Typeable, Generic, Read, Show, Eq, Ord)
  
  instance Storable Timespec where
    sizeOf ~_ = 16
    alignment ~_ = 8
    peek p = Timespec
      <$> peek (castPtr @Timespec @CTime p)
      <*> peek (plusPtr @Timespec @Int64 p 8)
    poke p (Timespec s n) = do
      poke (castPtr @Timespec @CTime p) s
      poke (plusPtr @Timespec @Int64 p 8) n
  
  