swig/Lib/java/director.swg
William S Fulton eeca9ccf6a directorin typemap renamed javadirectorin
directorout typemap renamed javadirectorout


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5135 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-09-20 16:13:19 +00:00

70 lines
1.7 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)
*
* N.B.: This file was
adapted from the python director.swg, written by
* Mark Rose (mrose@stm.lbl.gov)
************************************************************************/
#ifdef __cplusplus
/* director base class */
class __DIRECTOR__ {
private:
/* pointer to java virtual machine */
JavaVM *__jvm;
protected:
/* pointer to the wrapped java object */
jobject __self;
/* Acquire Java VM environment from Java VM */
JNIEnv *__acquire_jenv() const {
JNIEnv *env;
__jvm->AttachCurrentThread((void **) &env, NULL);
return env;
}
public:
__DIRECTOR__(JNIEnv *jenv):
__jvm((JavaVM *) NULL),
__self(NULL)
{
/* Acquire the Java VM pointer */
jenv->GetJavaVM(&__jvm);
}
/* Remove the Java object global lock at destruction */
virtual ~__DIRECTOR__()
{
if (__self) {
JNIEnv *jenv;
jmethodID disconn_meth;
jenv = __acquire_jenv();
disconn_meth = jenv->GetMethodID(jenv->GetObjectClass(__self), "__director_disconnect", "()V");
if (disconn_meth)
jenv->CallVoidMethod(__self, disconn_meth);
jenv->DeleteGlobalRef(__self);
__self = (jobject) NULL;
}
}
/* Set __self and get Java global reference on object */
inline void __set_self(JNIEnv *jenv, jobject jself)
{
__self = jenv->NewGlobalRef(jself);
}
/* return a pointer to the wrapped java object */
inline jobject __get_self() const
{ return __self; }
};
#endif /* __cplusplus */