/* * 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 "stdhdrs.h" #include "strbuf.h" #include "strdict.h" /* * Class: com_perforce_client_api_StrDict * Method: nDeleteInstance * Signature: (L)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_StrDict_nDeleteInstance (JNIEnv *, jclass, jlong jRef) { delete (StrDict *)jRef; } /* * Class: com_perforce_client_api_StrDict * Method: nSetVar * Signature: (LLjava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_StrDict_nSetVar (JNIEnv * env, jclass, jlong jRef, jstring jName, jstring jValue) { StrDict * ref = (StrDict *)jRef; const char * cName = env->GetStringUTFChars(jName, NULL); const char * cValue = env->GetStringUTFChars(jValue, NULL); ref->SetVar( cName, cValue ); env->ReleaseStringUTFChars(jName, cName); env->ReleaseStringUTFChars(jValue, cValue); } /* * Class: com_perforce_client_api_StrDict * Method: nGetVar * Signature: (LLjava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_StrDict_nGetVar (JNIEnv * env, jclass, jlong jRef, jstring jName) { StrDict * ref = (StrDict *)jRef; const char * cName = env->GetStringUTFChars(jName, NULL); char * cValue = ref->GetVar( cName )->Text(); env->ReleaseStringUTFChars(jName, cName); jstring jValue = env->NewStringUTF(cValue); return jValue; } /* * Class: com_perforce_client_api_StrDict * Method: nGetName * Signature: (LI)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_StrDict_nGetName (JNIEnv * env, jclass, jlong 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) // StrRef name; StrRef value; ref->GetVar( index, name, value ); // // Return only the name // return env->NewStringUTF(name.Text()); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 4131 | Paul Krause | check for NULL | ||
#5 | 4108 | Paul Krause | implement missing Map methods | ||
#4 | 4107 | Paul Krause | fix JNI sigs for ErrorId | ||
#3 | 4102 | Paul Krause | ditch JNIStringUtil | ||
#2 | 4100 | Paul Krause | fix type problems | ||
#1 | 4092 | Paul Krause | Copy JNI wrapper to C++ API from //guest/michael_bishop/P4APIForJava/c-cpp | ||
//guest/michael_bishop/P4APIForJava/c-cpp/strdict_jni.cpp | |||||
#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. |