/* * 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 "msgclient.h" #include "strbuf.h" #include "error_jni.h" /* * Class: com_perforce_client_api_P4Error * Method: nNewInstance * Signature: ()J */ 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: (J)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: (J)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: (J)J; */ JNIEXPORT jlong JNICALL Java_com_perforce_client_api_P4Error_nId (JNIEnv * env, jclass, jlong jRef) { Error * ref = (Error *)jRef; ErrorId * id = ref->GetId(0); return (jlong) id; } /* * Class: com_perforce_client_api_P4Error * Method: nCode * Signature: (J)I; */ JNIEXPORT jint JNICALL Java_com_perforce_client_api_P4Error_nCode (JNIEnv * env, jclass, jlong jRef) { Error * ref = (Error *)jRef; ErrorId * id = ref->GetId(0); return id->code; } /* * Class: com_perforce_client_api_P4Error * Method: nGetErrorIdCodes * Signature: ()[I */ JNIEXPORT jintArray JNICALL Java_com_perforce_client_api_P4Error_nGetErrorIdCodes (JNIEnv * env, jclass) { static const jint codes[] = { MsgClient::Connect.code, MsgClient::BadFlag.code, MsgClient::Fatal.code, MsgClient::ClobberFile.code, MsgClient::MkDir.code, MsgClient::Eof.code, MsgClient::CantEdit.code, MsgClient::NoMerger.code, MsgClient::ToolServer2.code, MsgClient::ToolServer.code, MsgClient::ToolCmdCreate.code, MsgClient::ToolCmdSend.code, MsgClient::Memory.code, MsgClient::CantFindApp.code, MsgClient::BadSignature.code, MsgClient::ResolveManually.code, MsgClient::NonTextFileMerge.code, MsgClient::MergeMsg2.code, MsgClient::MergeMsg3.code, MsgClient::MergeMsg32.code, MsgClient::MergePrompt.code, MsgClient::MergePrompt2.code, MsgClient::MergePrompt2Edit.code, MsgClient::ConfirmMarkers.code, MsgClient::ConfirmEdit.code, MsgClient::Confirm.code, NULL }; jintArray codeArray = env->NewIntArray(26); env->SetIntArrayRegion(codeArray, 0, 26, (jint *)codes); return codeArray; } /* * Class: com_perforce_client_api_P4Error * Method: nGetErrorIdNames * Signature: ()[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_com_perforce_client_api_P4Error_nGetErrorIdNames (JNIEnv * env, jclass) { static const char * names[] = { "Connect", "BadFlag", "Fatal", "ClobberFile", "MkDir", "Eof", "CantEdit", "NoMerger", "ToolServer2", "ToolServer", "ToolCmdCreate", "ToolCmdSend", "Memory", "CantFindApp", "BadSignature", "ResolveManually", "NonTextFileMerge", "MergeMsg2", "MergeMsg3", "MergeMsg32", "MergePrompt", "MergePrompt2", "MergePrompt2Edit", "ConfirmMarkers", "ConfirmEdit", "Confirm", NULL }; jclass c = env->FindClass("java/lang/String"); jobjectArray stringArray = env->NewObjectArray(26, c, NULL); for (int i = 0; i < 26; i++) { env->SetObjectArrayElement(stringArray, i, env->NewStringUTF(names[i])); } return stringArray; } /* * Class: com_perforce_client_api_P4Error * Method: nGetErrorIdFmts * Signature: ()[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_com_perforce_client_api_P4Error_nGetErrorIdFmts (JNIEnv * env, jclass) { static const char * fmts[] = { MsgClient::Connect.fmt, MsgClient::BadFlag.fmt, MsgClient::Fatal.fmt, MsgClient::ClobberFile.fmt, MsgClient::MkDir.fmt, MsgClient::Eof.fmt, MsgClient::CantEdit.fmt, MsgClient::NoMerger.fmt, MsgClient::ToolServer2.fmt, MsgClient::ToolServer.fmt, MsgClient::ToolCmdCreate.fmt, MsgClient::ToolCmdSend.fmt, MsgClient::Memory.fmt, MsgClient::CantFindApp.fmt, MsgClient::BadSignature.fmt, MsgClient::ResolveManually.fmt, MsgClient::NonTextFileMerge.fmt, MsgClient::MergeMsg2.fmt, MsgClient::MergeMsg3.fmt, MsgClient::MergeMsg32.fmt, MsgClient::MergePrompt.fmt, MsgClient::MergePrompt2.fmt, MsgClient::MergePrompt2Edit.fmt, MsgClient::ConfirmMarkers.fmt, MsgClient::ConfirmEdit.fmt, MsgClient::Confirm.fmt, NULL }; jclass c = env->FindClass("java/lang/String"); jobjectArray stringArray = env->NewObjectArray(26, c, NULL); for (int i = 0; i < 26; i++) { env->SetObjectArrayElement(stringArray, i, env->NewStringUTF(fmts[i])); } return stringArray; } /* * Class: com_perforce_client_api_P4Error * Method: nGetErrorIdPtrs * Signature: ()[J */ JNIEXPORT jlongArray JNICALL Java_com_perforce_client_api_P4Error_nGetErrorIdPtrs (JNIEnv * env, jclass) { static jlong errorPtrtable[] = { (jlong)&(MsgClient::Connect), (jlong)&(MsgClient::BadFlag), (jlong)&(MsgClient::Fatal), (jlong)&(MsgClient::ClobberFile), (jlong)&(MsgClient::MkDir), (jlong)&(MsgClient::Eof), (jlong)&(MsgClient::CantEdit), (jlong)&(MsgClient::NoMerger), (jlong)&(MsgClient::ToolServer2), (jlong)&(MsgClient::ToolServer), (jlong)&(MsgClient::ToolCmdCreate), (jlong)&(MsgClient::ToolCmdSend), (jlong)&(MsgClient::Memory), (jlong)&(MsgClient::CantFindApp), (jlong)&(MsgClient::BadSignature), (jlong)&(MsgClient::ResolveManually), (jlong)&(MsgClient::NonTextFileMerge), (jlong)&(MsgClient::MergeMsg2), (jlong)&(MsgClient::MergeMsg3), (jlong)&(MsgClient::MergeMsg32), (jlong)&(MsgClient::MergePrompt), (jlong)&(MsgClient::MergePrompt2), (jlong)&(MsgClient::MergePrompt2Edit), (jlong)&(MsgClient::ConfirmMarkers), (jlong)&(MsgClient::ConfirmEdit), (jlong)&(MsgClient::Confirm) }; jlongArray theArray = env->NewLongArray(26); env->SetLongArrayRegion(theArray, 0, 26, errorPtrtable); return theArray; } /* * Class: com_perforce_client_api_P4Error * Method: nSetErrorId * Signature: (JI)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_P4Error_nSetErrorId (JNIEnv *, jclass, jlong jRef, jint jErrorId) { Error * ref = (Error *)jRef; ErrorId id; id.code = jErrorId; ref->Set(id); } /* * Class: com_perforce_client_api_P4Error * Method: nSetMessage * Signature: (JLjava/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: (J)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. |