swig/Lib/java/director.swg
William S Fulton f4fac221fa - Compliance with ISO/IEC 14882:1998(E) 17.4.3.1.2 -> eg double underscores removed
- Potential member variable and method name clashes remove by preceding with 'swig'
- consistent use of C++ booleans for the swig_disown flag across and within the modules that use this it in director code.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5139 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-09-22 22:55:17 +00:00

65 lines
1.8 KiB
Text

/***********************************************************************
* director.swg
*
* This file contains support for director classes that proxy
* method calls from C++ to Java extensions.
*
* Author : Scott Michel (scottm@aero.org)
*
* This file was adapted from the python director.swg, written by
* Mark Rose (mrose@stm.lbl.gov)
************************************************************************/
#ifdef __cplusplus
namespace Swig {
/* director base class */
class Director {
private:
/* pointer to Java virtual machine */
JavaVM *swig_jvm;
protected:
/* pointer to the wrapped Java object */
jobject swig_self;
/* Acquire Java VM environment from Java VM */
JNIEnv *swig_acquire_jenv() const {
JNIEnv *env = NULL;
swig_jvm->AttachCurrentThread((void **) &env, NULL);
return env;
}
public:
Director(JNIEnv *jenv) : swig_jvm((JavaVM *) NULL), swig_self(NULL) {
/* Acquire the Java VM pointer */
jenv->GetJavaVM(&swig_jvm);
}
/* Remove the Java object global lock at destruction */
virtual ~Director() {
if (swig_self) {
JNIEnv *jenv = swig_acquire_jenv();
jmethodID disconn_meth = jenv->GetMethodID(jenv->GetObjectClass(swig_self), "swig_director_disconnect", "()V");
if (disconn_meth)
jenv->CallVoidMethod(swig_self, disconn_meth);
jenv->DeleteGlobalRef(swig_self);
swig_self = (jobject) NULL;
}
}
/* Set swig_self and get Java global reference on object */
void swig_set_self(JNIEnv *jenv, jobject jself) {
swig_self = jenv->NewGlobalRef(jself);
}
/* return a pointer to the wrapped Java object */
jobject swig_get_self() const {
return swig_self;
}
};
}
#endif /* __cplusplus */