/* * 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 ClientApi 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 "clientapi.h" #include "clientapi_jni.h" /* * Class: com_perforce_client_api_ClientApi * Method: nNewInstance * Signature: ()L */ JNIEXPORT jlong JNICALL Java_com_perforce_client_api_ClientApi_nNewInstance (JNIEnv *, jclass) { // // Return a simple integer that is the memory location // of the native object // return (jlong) new ClientApi(); } /* * Class: com_perforce_client_api_ClientApi * Method: nDeleteInstance * Signature: (L)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nDeleteInstance (JNIEnv *, jclass, jlong ref) { // // Delete the native reference we get from the // integer // delete (ClientApi *)ref; } /* * Class: com_perforce_client_api_ClientApi * Method: nSetCwd * Signature: (LLjava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nSetCwd (JNIEnv * env, jclass, jlong jRef, jstring jcwd) { ClientApi * ref = (ClientApi *)jRef; const char * cwd = env->GetStringUTFChars(jcwd, NULL); ref->SetCwd( cwd ); env->ReleaseStringUTFChars(jcwd, cwd); } /* * Class: com_perforce_client_api_ClientApi * Method: nSetUser * Signature: (LLjava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nSetUser (JNIEnv *env, jclass, jlong jRef, jstring jUser) { ClientApi * ref = (ClientApi *)jRef; const char * user = env->GetStringUTFChars(jUser, NULL); ref->SetUser( user ); env->ReleaseStringUTFChars(jUser, user); } /* * Class: com_perforce_client_api_ClientApi * Method: nSetProtocol * Signature: (LLjava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nSetProtocol (JNIEnv *env, jclass, jlong jRef, jstring jP, jstring jV) { ClientApi * ref = (ClientApi *)jRef; const char * p = env->GetStringUTFChars(jP, NULL); const char * v = env->GetStringUTFChars(jV, NULL); ref->SetProtocol( p, v ); env->ReleaseStringUTFChars(jP, p); env->ReleaseStringUTFChars(jV, v); } /* * Class: com_perforce_client_api_ClientApi * Method: nGetProtocol * Signature: (LLjava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_ClientApi_nGetProtocol (JNIEnv *env, jclass, jlong jRef, jstring jV) { ClientApi * ref = (ClientApi *)jRef; const char * v = env->GetStringUTFChars(jV, NULL); StrPtr * temp = ref->GetProtocol( v ); env->ReleaseStringUTFChars(jV, v); // I *think* it's safe to free v now [PFK 01/12/04] return env->NewStringUTF(temp->Text()); } /* * Class: com_perforce_client_api_ClientApi * Method: nSetVar * Signature: (LLjava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nSetVar (JNIEnv * env, jclass, jlong jRef, jstring jVar, jstring jValue) { ClientApi * ref = (ClientApi *)jRef; const char * var = env->GetStringUTFChars(jVar, NULL); const char * value = env->GetStringUTFChars(jValue, NULL); { StrRef temp( value ); ref->SetVar( var, &temp ); } env->ReleaseStringUTFChars(jVar, var); env->ReleaseStringUTFChars(jValue, value); } /* * Class: com_perforce_client_api_ClientApi * Method: nSetVarV * Signature: (LLjava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nSetVarV (JNIEnv * env, jclass, jlong jRef, jstring jArg) { ClientApi * ref = (ClientApi *)jRef; const char * arg = env->GetStringUTFChars(jArg, NULL); ref->SetVarV( arg ); env->ReleaseStringUTFChars(jArg, arg); } /* * Class: com_perforce_client_api_ClientApi * Method: nSetArgv * Signature: (L[Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nSetArgv (JNIEnv * env, jclass, jlong jRef, jobjectArray jStringArray) { ClientApi * ref = (ClientApi *)jRef; jsize argc = env->GetArrayLength(jStringArray); char ** argv = new char* [argc]; jstring * strv = new jstring[argc]; jsize i; for (i = 0; i < argc; i++) { strv[i] = (jstring) env->GetObjectArrayElement(jStringArray, i); argv[i] = (char *) env->GetStringUTFChars(strv[i], NULL); } ref->SetArgv( argc, argv ); // // Dispose of our charptr array by iterating through each one // and freeing it. // for (i = 0; i < argc; i++) { env->ReleaseStringUTFChars(strv[i], argv[i]); } delete [] strv; delete [] argv; } /* * Class: com_perforce_client_api_ClientApi * Method: nGetVar * Signature: (LLjava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_ClientApi_nGetVar (JNIEnv * env, jclass, jlong jRef, jstring jName ) { ClientApi * ref = (ClientApi *)jRef; const char * cName = env->GetStringUTFChars(jName, NULL); jstring jValue = env->NewStringUTF(ref->GetVar(cName)->Text()); env->ReleaseStringUTFChars(jName, cName); return jValue; } /* * Class: com_perforce_client_api_ClientApi * Method: nInit * Signature: (LL)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nInit (JNIEnv *, jclass, jlong jRef, jlong jErrorRef) { ClientApi * ref = (ClientApi *)jRef; Error * errorRef = (Error *)jErrorRef; ref->Init( errorRef ); } /* * Class: com_perforce_client_api_ClientApi * Method: nRun * Signature: (LLjava/lang/String;L)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nRun (JNIEnv * env, jclass, jlong jRef, jstring jFunc, jlong jClientUser) { ClientApi * ref = (ClientApi *)jRef; ClientUser * ui = (ClientUser *)jClientUser; const char * func = env->GetStringUTFChars(jFunc, NULL); ref->Run( func, ui ); env->ReleaseStringUTFChars(jFunc, func); } /* * Class: com_perforce_client_api_ClientApi * Method: nEnd * Signature: (LL)L */ JNIEXPORT jlong JNICALL Java_com_perforce_client_api_ClientApi_nEnd (JNIEnv *, jclass, jlong jRef, jlong jErrorRef) { ClientApi * ref = (ClientApi *)jRef; return ref->Final( (Error *)jErrorRef ); } /* * Class: com_perforce_client_api_ClientApi * Method: nDropped * Signature: (L)L */ JNIEXPORT jlong JNICALL Java_com_perforce_client_api_ClientApi_nDropped (JNIEnv *, jclass, jlong jRef) { ClientApi * ref = (ClientApi *)jRef; return ref->Dropped(); } /* * Class: com_perforce_client_api_ClientApi * Method: nRunTag * Signature: (LLjava/lang/String;I)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nRunTag (JNIEnv * env, jclass, jlong jRef, jstring jFunc, jlong jUi) { ClientApi * ref = (ClientApi *)jRef; ClientUser * ui = (ClientUser *)jUi; const char * func = env->GetStringUTFChars(jFunc, NULL); ref->RunTag( func, ui ); env->ReleaseStringUTFChars(jFunc, func); } /* * Class: com_perforce_client_api_ClientApi * Method: nWaitTag * Signature: (L)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nWaitTag__I (JNIEnv *, jclass, jlong jRef) { ClientApi * ref = (ClientApi *)jRef; ref->WaitTag(); } /* * Class: com_perforce_client_api_ClientApi * Method: nWaitTag * Signature: (LL)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nWaitTag__II (JNIEnv *, jclass, jlong jRef, jlong jUi) { ClientApi * ref = (ClientApi *)jRef; ClientUser * ui = (ClientUser *)jUi; ref->WaitTag( ui ); } /* * Class: com_perforce_client_api_ClientApi * Method: nSetClient * Signature: (LLjava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nSetClient (JNIEnv * env, jclass, jlong jRef, jstring jClient) { ClientApi * ref = (ClientApi *)jRef; const char * client = env->GetStringUTFChars(jClient, NULL); ref->SetClient( client ); env->ReleaseStringUTFChars(jClient, client); } /* * Class: com_perforce_client_api_ClientApi * Method: nSetHost * Signature: (LLjava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nSetHost (JNIEnv * env, jclass, jlong jRef, jstring jHost) { ClientApi * ref = (ClientApi *)jRef; const char * host = env->GetStringUTFChars(jHost, NULL); ref->SetHost( host ); env->ReleaseStringUTFChars(jHost, host); } /* * Class: com_perforce_client_api_ClientApi * Method: nSetPassword * Signature: (LLjava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nSetPassword (JNIEnv * env, jclass, jlong jRef, jstring jPassword) { ClientApi * ref = (ClientApi *)jRef; const char * password = env->GetStringUTFChars(jPassword, NULL); ref->SetPassword( password ); env->ReleaseStringUTFChars(jPassword, password); } /* * Class: com_perforce_client_api_ClientApi * Method: nSetPort * Signature: (LLjava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nSetPort (JNIEnv * env, jclass, jlong jRef, jstring jPort) { ClientApi * ref = (ClientApi *)jRef; const char * port = env->GetStringUTFChars(jPort, NULL); ref->SetPassword( port ); env->ReleaseStringUTFChars(jPort, port); } /* * Class: com_perforce_client_api_ClientApi * Method: nDefineClient * Signature: (LLjava/lang/String;L)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nDefineClient (JNIEnv * env, jclass, jlong jRef, jstring jC, jlong jErrorRef) { ClientApi * ref = (ClientApi *)jRef; const char * c = env->GetStringUTFChars(jC, NULL); ref->DefineClient( c, (Error *)jErrorRef ); env->ReleaseStringUTFChars(jC, c); } /* * Class: com_perforce_client_api_ClientApi * Method: nDefineHost * Signature: (LLjava/lang/String;L)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nDefineHost (JNIEnv * env, jclass, jlong jRef, jstring jC, jlong jErrorRef) { ClientApi * ref = (ClientApi *)jRef; const char * c = env->GetStringUTFChars(jC, NULL); ref->DefineHost( c, (Error *)jErrorRef ); env->ReleaseStringUTFChars(jC, c); } /* * Class: com_perforce_client_api_ClientApi * Method: nDefinePassword * Signature: (LLjava/lang/String;L)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nDefinePassword (JNIEnv * env, jclass, jlong jRef, jstring jC, jlong jErrorRef) { ClientApi * ref = (ClientApi *)jRef; const char * c = env->GetStringUTFChars(jC, NULL); ref->DefinePassword( c, (Error *)jErrorRef ); env->ReleaseStringUTFChars(jC, c); } /* * Class: com_perforce_client_api_ClientApi * Method: nDefinePort * Signature: (LLjava/lang/String;L)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nDefinePort (JNIEnv * env, jclass, jlong jRef, jstring jC, jlong jErrorRef) { ClientApi * ref = (ClientApi *)jRef; const char * c = env->GetStringUTFChars(jC, NULL); ref->DefinePort( c, (Error *)jErrorRef ); env->ReleaseStringUTFChars(jC, c); } /* * Class: com_perforce_client_api_ClientApi * Method: nDefineUser * Signature: (ILjava/lang/String;L)V */ JNIEXPORT void JNICALL Java_com_perforce_client_api_ClientApi_nDefineUser (JNIEnv * env, jclass, jlong jRef, jstring jC, jlong jErrorRef) { ClientApi * ref = (ClientApi *)jRef; const char * c = env->GetStringUTFChars(jC, NULL); ref->DefineUser( c, (Error *)jErrorRef ); env->ReleaseStringUTFChars(jC, c); } /* * Class: com_perforce_client_api_ClientApi * Method: nGetCwd * Signature: (L)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_ClientApi_nGetCwd (JNIEnv * env, jclass, jlong jRef) { ClientApi * ref = (ClientApi *)jRef; return env->NewStringUTF(ref->GetCwd().Text()); } /* * Class: com_perforce_client_api_ClientApi * Method: nGetClient * Signature: (L)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_ClientApi_nGetClient (JNIEnv * env, jclass, jlong jRef) { ClientApi * ref = (ClientApi *)jRef; return env->NewStringUTF(ref->GetClient().Text() ); } /* * Class: com_perforce_client_api_ClientApi * Method: nGetHost * Signature: (L)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_ClientApi_nGetHost (JNIEnv * env, jclass, jlong jRef) { ClientApi * ref = (ClientApi *)jRef; return env->NewStringUTF(ref->GetHost().Text() ); } /* * Class: com_perforce_client_api_ClientApi * Method: nGetOs * Signature: (L)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_ClientApi_nGetOs (JNIEnv * env, jclass, jlong jRef) { ClientApi * ref = (ClientApi *)jRef; return env->NewStringUTF(ref->GetOs().Text() ); } /* * Class: com_perforce_client_api_ClientApi * Method: nGetPassword * Signature: (L)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_ClientApi_nGetPassword (JNIEnv * env, jclass, jlong jRef) { ClientApi * ref = (ClientApi *)jRef; return env->NewStringUTF(ref->GetPassword().Text() ); } /* * Class: com_perforce_client_api_ClientApi * Method: nGetPort * Signature: (L)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_ClientApi_nGetPort (JNIEnv * env, jclass, jlong jRef) { ClientApi * ref = (ClientApi *)jRef; return env->NewStringUTF(ref->GetPort().Text() ); } /* * Class: com_perforce_client_api_ClientApi * Method: nGetUser * Signature: (L)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_perforce_client_api_ClientApi_nGetUser (JNIEnv * env, jclass, jlong jRef) { ClientApi * ref = (ClientApi *)jRef; return env->NewStringUTF(ref->GetUser().Text() ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#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/clientapi_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. |