/* * 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 Error 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 "stdhdrs.h" #include "error.h" #include "strbuf.h" #include "error_jni.h" /* * Class: com_perforce_client_api_P4Error * Method: nNewInstance * Signature: ()I */ JNIEXPORT jlong JNICALL Java_com_perforce_client_api_P4Error_nNewInstance (JNIEnv *, jclass) { return (jlong)new Error(); } /* * Class: com_perforce_client_api_P4Error * Method: nDeleteInstance * Signature: (I)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_P4Error_nDeleteInstance (JNIEnv *, jclass, jlong jRef) { delete (Error *)jRef; } /* * Class: com_perforce_client_api_P4Error * Method: nFmt * Signature: (L)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_P4Error_nFmt (JNIEnv * env, jclass, jlong jRef) { Error * ref = (Error *)jRef; StrBuf msg; ref->Fmt( &msg ); return env->NewStringUTF(msg.Text()); } /* * Class: com_perforce_client_api_P4Error * Method: nId * Signature: (L)I */ JNIEXPORT jint JNICALL Java_com_perforce_client_api_P4Error_nId (JNIEnv * env, jclass, jlong jRef) { Error * ref = (Error *)jRef; ErrorId * id = ref->GetId(0); return id->code; } /* * Class: com_perforce_client_api_P4Error * Method: nSetErrorId * Signature: (LI)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_P4Error_nSetErrorId (JNIEnv *, jclass, jlong jRef, jint jErrorId) { Error * ref = (Error *)jRef; ref->Set( *((ErrorId *)jErrorId) ); } /* * Class: com_perforce_client_api_P4Error * Method: nSetMessage * Signature: (ILjava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_P4Error_nSetMessage (JNIEnv * env, jclass, jlong jRef, jstring jMessage) { const char * message = env->GetStringUTFChars(jMessage, NULL); if ( message ) { Error * ref = (Error *)jRef; *ref << message; env->ReleaseStringUTFChars(jMessage, message); } } /* * Class: com_perforce_client_api_P4Error * Method: nTest * Signature: (I)Z */ JNIEXPORT jboolean JNICALL Java_com_perforce_client_api_P4Error_nTest (JNIEnv *, jclass, jlong jRef) { Error * ref = (Error *)jRef; return (jboolean)ref->Test(); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#8 | 4197 | Paul Krause | Better error passing from Java o C | ||
#7 | 4129 | Paul Krause | use msgclient.h in place of old errclient.h | ||
#6 | 4107 | Paul Krause | fix JNI sigs for ErrorId | ||
#5 | 4103 | Paul Krause | ditch clienterror.h | ||
#4 | 4102 | Paul Krause | ditch JNIStringUtil | ||
#3 | 4100 | Paul Krause | fix type problems | ||
#2 | 4097 | Paul Krause | remove support for unimplemented abort() function | ||
#1 | 4092 | Paul Krause | Copy JNI wrapper to C++ API from //guest/michael_bishop/P4APIForJava/c-cpp | ||
//guest/michael_bishop/P4APIForJava/c-cpp/error_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. |