Changeset 13959


Ignore:
Timestamp:
11/14/12 20:27:06 (12 years ago)
Author:
Eric.Larour
Message:

CHG: pushed Lan's changes to avoid using Javah on Main.cpp

Location:
issm/trunk-jpl/src/android/ISSM/jni
Files:
2 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/android/ISSM/jni/Main.cpp

    r13931 r13959  
     1#include <jni.h>
    12#include "../../../c/android/fac.h"
    2 #include "com_example_issm_IssmJni.h"
    3 #include <cstddef>
     3namespace com_example_issm
     4{
     5        static jlong factorial(JNIEnv *env, jclass clazz, jlong n)
     6        {
     7                fac *f = new fac();
     8                jlong result = (jlong) (f->factorial(n));
     9                delete(f);
     10                return (jlong) result;
     11        }
     12//------------------------------------------------------------------------------------
     13        static JNINativeMethod method_table[] = {
     14                        {"fac" ,"(J)J" , (void *) factorial},
     15        };
     16}
    417
    5 JNIEXPORT jlong JNICALL Java_com_example_issm_IssmJni_fac(JNIEnv *env, jclass clazz, jlong n)
     18using namespace com_example_issm;
     19
     20extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
    621{
    7         fac *f = new fac();
    8         jlong result = (jlong) (f->factorial(n));
    9         delete(f);
    10         return (jlong) result;
     22    JNIEnv* env;
     23    if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
     24        return -1;
     25    }
     26    else
     27    {
     28        jclass clazz = env->FindClass("com/example/issm/IssmJni");
     29        if(clazz)
     30        {
     31                env->RegisterNatives(clazz, method_table, 1);
     32                env->DeleteLocalRef(clazz);
     33                return JNI_VERSION_1_6;
     34        }
     35        else return -1;
     36    }
     37
     38    // Get jclass with env->FindClass.
     39    // Register methods with env->RegisterNatives.
    1140}
Note: See TracChangeset for help on using the changeset viewer.