/* * Copyright 2000 Perforce Software. All rights reserved. * * This file is part of Perforce - the FAST SCM System. * * Author: Michael Bishop * * Tabs: 4 spaces * * This is just JNI glue to make the java calls go through to the * native StrDict object. * * The philosophy behind the Java glue is that, all of the native * objects are created natively. The pointer to that object is * passed to java where it stores it as an int. The value of that * int is actually a pointer in memory to the native object. * In this way, java can pass that int back to C code where it can * be casted to a C object pointer. When the java object is garbage * collected, it calls native code to delete the native pointer. * * All methods that are exposed with a java call are simply passed * through to native code where the native call is made. * */ #include "strdict_jni.h" #include "JNIStringUtil.h" #include "stdhdrs.h" #include "strbuf.h" #include "strdict.h" /* * Class: com_perforce_client_api_StrDict * Method: nDeleteInstance * Signature: (I)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_StrDict_nDeleteInstance (JNIEnv *, jclass, jint jRef) { delete (StrDict *)jRef; } /* * Class: com_perforce_client_api_StrDict * Method: nSetVar * Signature: (ILjava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_StrDict_nSetVar (JNIEnv * env, jclass, jint jRef, jstring jName, jstring jValue) { StrDict * ref = (StrDict *)jRef; char * cName = jstring_to_cstring( env, jName ); char * cValue = jstring_to_cstring( env, jValue ); ref->SetVar( cName, cValue ); delete cName; delete cValue; } /* * Class: com_perforce_client_api_StrDict * Method: nGetVar * Signature: (ILjava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_StrDict_nGetVar (JNIEnv * env, jclass, jint jRef, jstring jName) { StrDict * ref = (StrDict *)jRef; char * cName = jstring_to_cstring( env, jName ); char * cValue = ref->GetVar( cName )->Text(); delete cName; jstring jValue = cstring_to_jstring( env, cValue ); return jValue; } /* * Class: com_perforce_client_api_StrDict * Method: nGetName * Signature: (II)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_StrDict_nGetName (JNIEnv * env, jclass, jint jRef, jint index) { StrDict * ref = (StrDict *)jRef; // // Because when we have an index, we have to get // both the name and a value (even though we are interested // only in the name) // StrPtr name; StrPtr value; ref->GetVar( index, name, value ); // // Return only the name // return cstring_to_jstring( env, name.Text() ); }
# | 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. |