aboutsummaryrefslogtreecommitdiffstats
path: root/src/native/almisc.c
blob: 6658f64e0b347ea14902c5cd3aeb6ca29f7803ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

#include <jni.h>
#include <stdlib.h>

#include <assert.h>

 #include "al.h"
 #include "alc.h"
 #ifndef _MSC_VER /* Non-Windows platforms */
  #define __cdecl /* Trim non-standard keyword */
 #endif
 #include "efx.h"
  #ifdef _MSC_VER /* Windows, Microsoft compilers */
  /* This typedef is apparently needed for compilers before VC8 */
  #if _MSC_VER < 1400
  typedef int intptr_t;
  #endif
  #else
  /* This header seems to be available on all other platforms */
  #include <inttypes.h>
  #endif
  #include <string.h>


/*   Java->C glue code:
 *   Java package: com.jogamp.openal.impl.ALImpl
 *    Java method: long dispatch_alGetProcAddressStatic(java.lang.String fname)
 *     C function: ALproc alGetProcAddress(const ALchar *  fname);
 */
JNIEXPORT jlong JNICALL 
Java_com_jogamp_openal_impl_ALImpl_dispatch_1alGetProcAddressStatic(JNIEnv *env, jclass _unused, jstring fname, jlong procAddress) {
  LPALGETPROCADDRESS ptr_alGetProcAddress;
  const char* _strchars_fname = NULL;
  ALproc _res;
  if ( NULL != fname ) {
    _strchars_fname = (*env)->GetStringUTFChars(env, fname, (jboolean*)NULL);
  if ( NULL == _strchars_fname ) {
      (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/OutOfMemoryError"),
                       "Failed to get UTF-8 chars for argument \"fname\" in native dispatcher for \"dispatch_alGetProcAddress\"");
      return 0;
    }
  }
  ptr_alGetProcAddress = (LPALGETPROCADDRESS) (intptr_t) procAddress;
  assert(ptr_alGetProcAddress != NULL);
  _res = (* ptr_alGetProcAddress) ((ALchar *) _strchars_fname);
  if ( NULL != fname ) {
    (*env)->ReleaseStringUTFChars(env, fname, _strchars_fname);
  }
  return (jlong) (intptr_t) _res;
}

/*   Java->C glue code:
 *   Java package: com.jogamp.openal.impl.ALCAbstractImpl
 *    Java method: java.nio.ByteBuffer dispatch_alcGetStringImpl(ALCdevice device, int param)
 *     C function: const ALCchar *  alcGetString(ALCdevice *  device, ALCenum param);
 */
JNIEXPORT jobject JNICALL 
Java_com_jogamp_openal_impl_ALCImpl_dispatch_1alcGetStringImpl1(JNIEnv *env, jobject _unused, jobject device, jint param, jlong procAddress) {
  LPALCGETSTRING ptr_alcGetString;
  ALCdevice * _device_ptr = NULL;
  const ALCchar *  _res;
    if ( NULL != device ) {
        _device_ptr = (ALCdevice *) (((char*) (*env)->GetDirectBufferAddress(env, device)) + 0);
    }
  ptr_alcGetString = (LPALCGETSTRING) (intptr_t) procAddress;
  assert(ptr_alcGetString != NULL);
  _res = (* ptr_alcGetString) ((ALCdevice *) _device_ptr, (ALCenum) param);
  if (NULL == _res) return NULL;
  return (*env)->NewDirectByteBuffer(env, _res, strlen_alc(_device_ptr, param, _res));
}