Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /trunk/sml3d/src/openal/error.sml
ViewVC logotype

View of /trunk/sml3d/src/openal/error.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 879 - (download) (annotate)
Sat May 8 15:59:26 2010 UTC (8 years, 5 months ago) by jhr
File size: 2060 byte(s)
  Working on OpenAL implementation
(* error.sml
 *
 * COPYRIGHT (c) 2010 John Reppy (http://cs.uchicago.edu/~jhr)
 * All rights reserved.
 *
 * Getting the most recent error generated by the AL state machine.  This module
 * supports access to both the al.h and alc.h error APIs.
 *)

structure Error =
  struct

    local
      open ALTypes
      open ALConsts
      open ALFuncs
    in

    type error = al_enum

    datatype error
      = NO_ERROR
  (* global errors *)
      | INVALID_NAME
      | INVALID_OPERATION
  (* device errors *)
      | INVALID_DEVICE
      | INVALID_CONTEXT
  (* general errors *)
      | INVALID_ENUM
      | INVALID_VALUE
      | OUT_OF_MEMORY

    fun getError () = let
	  val err = alGetError ()
	  in
	    if (AL_NO_ERROR = err) then NO_ERROR
	    else if (AL_INVALID_NAME = err) then INVALID_NAME
	    else if (AL_INVALID_ENUM = err) then INVALID_OPERATION
	    else if (AL_INVALID_VALUE = err) then INVALID_ENUM
	    else if (AL_INVALID_OPERATION = err) then INVALID_VALUE
	    else if (AL_OUT_OF_MEMORY = err) then OUT_OF_MEMORY
	    else raise Fail("AL.Error.getError: unknown error code "^Int.toString err)
	  end

    fun getDevError (dev : alc_device) = let
	  val err = alcGetError dev
	  in
	    if (ALC_NO_ERROR = err) then NO_ERROR
	    else if (ALC_INVALID_DEVICE = err) then INVALID_DEVICE
	    else if (ALC_INVALID_CONTEXT = err) then INVALID_CONTEXT
	    else if (ALC_INVALID_ENUM = err) then INVALID_ENUM
	    else if (ALC_INVALID_VALUE = err) then INVALID_VALUE
	    else if (ALC_OUT_OF_MEMORY = err) then OUT_OF_MEMORY
	    else raise Fail("AL.Error.getDevError: unknown error code "^Int.toString err)
	  end

    fun toString err = (case err
	   of NO_ERROR => ""
	    | INVALID_NAME => "Invalid name parameter"
	    | INVALID_OPERATION => "Illegal call"
	    | INVALID_DEVICE => "Device is inaccessible"
	    | INVALID_CONTEXT => "Invalid context"
	    | INVALID_ENUM => "Invalid parameter"
	    | INVALID_VALUE => "Invalid parameter value"
	    | OUT_OF_MEMORY => "Unable to allocate memory"
	  (* end case *))

    end (* local *)
  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0