/* * Copyright 2000 Perforce Software. All rights reserved. * * This file is part of Perforce - the FAST SCM System. * * Author: Michael Bishop * * Tabs: 4 spaces * * Use these methods to do operations specific to the JNI environment * * You must export JNI_OnLoad() from your shared library in order * to call GetCurrentJNIEnv(). * */ #include "JNIUtils.h" /****************************************************************************** ** ** ** Globals ** ** ** *****************************************************************************/ /* ** reference to the VM that loaded this library */ static JavaVM * gJavaVM = NULL; /*===========================================================================*\ * * Routine: JNI_OnLoad() * * Comments: Method that is called when Java loads this shared library. * * NOTE: You must export this function for it to work * \*===========================================================================*/ jint JNICALL JNI_OnLoad ( JavaVM *vm, void *reserved ) { reserved; /* unused */ /* ** Save off the VM */ gJavaVM = vm; /* ** return the version of JNI we are using */ return JNI_VERSION_1_1; } /*===========================================================================*\ * * Routine: GetCurrentJNIEnv() * * Comments: Method that returns a JNIEnv * when you are in a context * that has not provided you with one. * \*===========================================================================*/ JNIEnv * GetCurrentJNIEnv() { JNIEnv * currentEnv = NULL; /* ** Using the VM reference, we can get to the JNIEnv for this thread */ gJavaVM->AttachCurrentThread( ¤tEnv, NULL ); return currentEnv; } /*===========================================================================*\ * * Routine: GetObjectMethod() * * Comments: Method that returns a method id, given an actual java object. * \*===========================================================================*/ jmethodID GetObjectMethod( JNIEnv * env, jobject object, char * methodName, char * methodSignature ) { // // The the class of the object so that we can look up the method // jclass objectClass = env->GetObjectClass( object ); // // Look up the method // return env->GetMethodID( objectClass, methodName, methodSignature ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 430 | Michael Bishop |
Initial checkin. Seems to work. Not very much testing. Not very much documentation. Some more commenting needs to take place. But, it's there to experiment with. |