Changeset 13997


Ignore:
Timestamp:
11/21/12 17:22:39 (12 years ago)
Author:
ltnguyen
Message:

new main file, with new fac routine

File:
1 edited

Legend:

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

    r13959 r13997  
    11#include <jni.h>
    22#include "../../../c/android/fac.h"
     3#include <cstddef>
     4///////////////////////////////////////////////////////////////////////////////////////////
    35namespace com_example_issm
    46{
    5         static jlong factorial(JNIEnv *env, jclass clazz, jlong n)
     7        fac* f;
     8//------------------------------------------------------------------------------------
     9        void initilizeObject(JNIEnv *env, jclass clazz)
    610        {
    7                 fac *f = new fac();
    8                 jlong result = (jlong) (f->factorial(n));
    9                 delete(f);
    10                 return (jlong) result;
     11                f = new fac();
    1112        }
    1213//------------------------------------------------------------------------------------
    13         static JNINativeMethod method_table[] = {
    14                         {"fac" ,"(J)J" , (void *) factorial},
     14        //fill out the first two slots, extract the same way in java using get(int position)
     15        void fillBuffer(JNIEnv *env, jclass clazz , jobject buf)
     16        {
     17                jdouble *bBuf = (jdouble *)env->GetDirectBufferAddress(buf);
     18                bBuf[1] = 10.67;
     19                bBuf[2] = 100.0;
     20        }
     21//------------------------------------------------------------------------------------
     22        jlong factorial(JNIEnv *env, jclass clazz, jlong n)
     23        {
     24                if( f != NULL)
     25                        return (jlong) (f->factorial(n));
     26                return 0;
     27        }
     28
     29//------------------------------------------------------------------------------------
     30        static JNINativeMethod method_table[] =
     31        {
     32                        {"fac"          ,     "(J)J"    , (void *) factorial},
     33                        {"initialize"   ,     "()V"     , (void *) initilizeObject},
     34                        {"processBuffer", "(Ljava/nio/DoubleBuffer;)V", (void *) fillBuffer}
    1535        };
    1636}
    17 
     37//------------------------------------------------------------------------------------
    1838using namespace com_example_issm;
    1939
     
    2949        if(clazz)
    3050        {
    31                 env->RegisterNatives(clazz, method_table, 1);
     51                env->RegisterNatives(clazz, method_table, 3);
    3252                env->DeleteLocalRef(clazz);
    3353                return JNI_VERSION_1_6;
     
    3959    // Register methods with env->RegisterNatives.
    4060}
     61///////////////////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.