aboutsummaryrefslogtreecommitdiff
path: root/java/org/brotli/wrapper/dec/decoder_jni_onload.cc
blob: 12f8ebaddaffd47ca3f7f4eef8b89f1ec89e0940 (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
/* Copyright 2017 Google Inc. All Rights Reserved.

   Distributed under MIT license.
   See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/

#include <jni.h>

#include "./decoder_jni.h"

#ifdef __cplusplus
extern "C" {
#endif

static const JNINativeMethod kDecoderMethods[] = {
    {"nativeCreate", "([J)Ljava/nio/ByteBuffer;",
     reinterpret_cast<void*>(
         Java_org_brotli_wrapper_dec_DecoderJNI_nativeCreate)},
    {"nativePush", "([JI)V",
     reinterpret_cast<void*>(
         Java_org_brotli_wrapper_dec_DecoderJNI_nativePush)},
    {"nativePull", "([J)Ljava/nio/ByteBuffer;",
     reinterpret_cast<void*>(
         Java_org_brotli_wrapper_dec_DecoderJNI_nativePull)},
    {"nativeDestroy", "([J)V",
     reinterpret_cast<void*>(
         Java_org_brotli_wrapper_dec_DecoderJNI_nativeDestroy)},
    {"nativeAttachDictionary", "([JLjava/nio/ByteBuffer;)Z",
     reinterpret_cast<void*>(
         Java_org_brotli_wrapper_dec_DecoderJNI_nativeAttachDictionary)}};

JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
  JNIEnv* env;
  if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
    return -1;
  }

  jclass clazz =
      env->FindClass("com/google/compression/brotli/wrapper/dec/DecoderJNI");
  if (clazz == nullptr) {
    return -1;
  }

  if (env->RegisterNatives(
          clazz, kDecoderMethods,
          sizeof(kDecoderMethods) / sizeof(kDecoderMethods[0])) < 0) {
    return -1;
  }

  return JNI_VERSION_1_6;
}

#ifdef __cplusplus
}
#endif