コード例 #1
0
ファイル: JConstructor.cpp プロジェクト: alaineman/PowerGrid
/**
 * Invokes the constructor with the given JArguments.
 * Allocates a new local reference.
 *
 * @throws JNIException if an error occurs while trying to invoke the constructor.
 * @throws a matching C++ proxy, if a java exception is thrown by the constructor.
 *
 */
jobject JConstructor::invoke( const JArguments& arguments ) {


  /* Get the methodID for the constructor matching the given arguments.
   */
//  cout << "JConstructor::invoke - Retrieving the methodID..." << endl;
  jmethodID methodID = getMethodID( mClass, arguments );
//  cout << "JConstructor::invoke - Retrieved the methodID." << endl;

  /* Call the constructor
   */
//  cout << "JConstructor::invoke - Attaching..." << endl;
  JNIEnv* env = helper::attach();
//  cout << "JConstructor::invoke - Attached." << endl;
 
//  cout << "JConstructor::invoke - Creating the object..." << endl;
  jobject result;
	vector<jvalue> argArray = toVector( arguments );

	if (argArray.size() > 0)
		result = env->NewObjectA( mClass->getClass(), methodID, &argArray[ 0 ] );
	else
		result = env->NewObject( mClass->getClass(), methodID );
//  cout << "JConstructor::invoke - Created the object..." << endl;

  /* Catch any java exception that occured during the method call,
   * and throw it as a C++ exception.
   */
//  cout << "JConstructor::invoke - Checking for exceptions..." << endl;
  helper::catchAndThrow();
//  cout << "JConstructor::invoke - Found no exceptions." << endl;

  return result;
}
コード例 #2
0
ファイル: CJNIUtil.cpp プロジェクト: Aharobot/Tools
jmethodID CJNIUtil::getMethodID(char *className, char *methodName, char *methodSig)
{
	jclass c = getClass(className);
	if (!c) return NULL;

	return getMethodID(c, methodName, methodSig);
}
コード例 #3
0
ファイル: CJNIUtil.cpp プロジェクト: Aharobot/Tools
jobjectArray CJNIUtil::X3DParser_getDefNames(jobject x3dParser)
{
	if (!m_env)
	{
		CX3DParser::printLog("java vm haven't started\n");
		return NULL;
	}

	if (!x3dParser) return NULL;

	// -----------------------------------------------
	//	get method id
	// -----------------------------------------------
	char *className = "X3DParser";
	char *methodName = "getDefNames";
	char *methodSig = "()[Ljava/lang/String;";

	jmethodID mid = getMethodID(className, methodName, methodSig);
	if (!mid)
	{
		CX3DParser::printLog("cannot get methodID of %s", methodName);
		return NULL;
	}

	// -----------------------------------------------
	//	call java's method
	// -----------------------------------------------
	jobjectArray defNames = (jobjectArray)(m_env->CallObjectMethod(x3dParser, mid));

	return defNames;
}
コード例 #4
0
ファイル: CJNIUtil.cpp プロジェクト: Aharobot/Tools
jobjectArray CJNIUtil::X3DParser_getChildrenOfRootNode(jobject x3dParser)
{
	if (!m_env)
	{
		CX3DParser::printLog("java vm haven't started\n");
		return NULL;
	}

	if (!x3dParser) return NULL;

	// -----------------------------------------------
	//	get method id
	// -----------------------------------------------
	char *className = "X3DParser";
	char *methodName = "getChildrenOfRootNode";
	char *methodSig = "()[Lorg/web3d/vrml/lang/VRMLNode;";

	jmethodID mid = getMethodID(className, methodName, methodSig);
	if (!mid)
	{
		CX3DParser::printLog("cannot get methodID of %s", methodName);
		return NULL;
	}

	// -----------------------------------------------
	//	call java's method
	// -----------------------------------------------
	jobjectArray vrmlNodeArray = (jobjectArray)(m_env->CallObjectMethod(x3dParser, mid));

	return vrmlNodeArray;
}
コード例 #5
0
ファイル: CJNIUtil.cpp プロジェクト: Aharobot/Tools
// -----------------------------------------------
// -----------------------------------------------
bool CJNIUtil::X3DParser_parse(jobject x3dParser, char *fname)
{
	if (!m_env)
	{
		CX3DParser::printLog("java vm haven't started\n");
		return false;
	}

	if (!x3dParser) return false;

	// -----------------------------------------------
	//	get method id of X3DParse.parse()
	// -----------------------------------------------
	char *className = "X3DParser";
	char *methodName = "parse";
	char *methodSig = "(Ljava/lang/String;)Z";

	jmethodID mid = getMethodID(className, methodName, methodSig);
	if (!mid)
	{
		CX3DParser::printLog("cannot get methodID of %s", methodName);
		return false;
	}

	// -----------------------------------------------
	//	make argument
	// -----------------------------------------------
	jstring utf8_fname = m_env->NewStringUTF(fname);

	// -----------------------------------------------
	//	call java's parser
	// -----------------------------------------------
	return (m_env->CallBooleanMethod(x3dParser, mid, utf8_fname) == JNI_TRUE) ? true : false;
}
コード例 #6
0
KDint xmPlatformSoundOpen ( XMSound* sound )
{
	jmethodID  method = getMethodID ( "SoundOpen", "(IILjava/lang/String;)I" );

	if ( method )
	{	
		jstring  jpath  = 0;
		jint     jasset = 0;
		
		if ( !kdStrcmp ( sound->vpath, "/res" ) )
		{
			jpath  = (*l_env)->NewStringUTF ( l_env, &sound->path [ 5 ] );
			jasset = 1;
		}
		else
		{
			jpath = (*l_env)->NewStringUTF ( l_env, sound->fpath );
			jasset = 0;
		}

		sound->device = (KDvoid*) (*l_env)->CallStaticIntMethod ( l_env, l_class, method, (jint) ( sound->mode & XM_SOUND_EFFECT ), jasset, jpath );
	}

	return sound->device ? 0 : -1;
}
コード例 #7
0
/* This returns a new java.awt.Rectangle object if everything goes
   right, with the supplied x, y, width, and height.  If anything goes
   wrong we will call handleError and return NULL. */
static jobject newRectangle(JNIEnv *env, 
			    jint x, jint y, jint width, jint height)
{
  jclass    rectangleClass;
  jmethodID rectangleConstructor;
  jobject   newRectangle;

  rectangleClass = getClass(env, "java/awt/Rectangle", 
			    "Unable to get the java.awt.Rectangle class");
  if (rectangleClass == 0) {
    return NULL;
  }

  rectangleConstructor = getMethodID(env, rectangleClass,
				     "<init>", "(IIII)V", 
				     "Unable to get the init method for the "
				     "java.awt.Rectangle class");
  if (rectangleConstructor == 0) {
    return NULL;
  }

  newRectangle = (*env)->NewObject(env, rectangleClass,
				   rectangleConstructor, x, y, width, height);
  if (newRectangle == 0) {
    handleError(env, "OpenGL/OpenGLNativeException",
		"Unable to create new Rectangle");
    return NULL;
  }
  return newRectangle;
}
コード例 #8
0
jobject JavaClass::newInstance() 
{
    jmethodID constructor = getMethodID("<init>", "()V");
	JNI_ASSERT_NOT_NULL(constructor,"JavaClass::newInstance, failed to retrieve default constructor");	
    jobject javaObject = env->NewObject(javaClass, constructor);
    JNI_ASSERT_NOT_NULL(javaObject,"JavaClass::newInstance, failed to create instance");	
    return javaObject;
}
コード例 #9
0
void Soprano::Sesame2::RepositoryConnection::close()
{
    jmethodID closeMethodId = getMethodID( "close", "()V" );
    if ( closeMethodId ) {
        callVoidMethod( closeMethodId );
        JNIWrapper::instance()->debugException();
    }
}
コード例 #10
0
u32 JdwpWalker::getMethodID(const QString& cls_name, const QString& name, const QString& signature) {
    u64 cls_id = getClassID(cls_name);
    u32 ret = 0;
    if (cls_id != 0) {
        ret = getMethodID(cls_id, name, signature);
    }
    return ret;
}
コード例 #11
0
KDvoid xmPlatformEventDetach ( KDenum mode )
{
	jmethodID  method = getMethodID ( "SetDetach", "(I)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, (jint) mode );
	}	    
}
コード例 #12
0
KDvoid xmPlatformSetFullScreen ( KDbool enable )
{
    jmethodID  method = getMethodID ( "SetFullScreen", "(I)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, enable );
	}
}
コード例 #13
0
KDvoid xmPlatformVibrate ( KDuint msec )
{
    jmethodID  method = getMethodID ( "Vibrate", "(I)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, msec );
	}
}
コード例 #14
0
KDvoid xmPlatformSetIMEKeyboardState ( KDbool show )
{
	jmethodID  method = getMethodID ( "SetIMEKeyboardState", "(I)I" );
	
	if ( method )
	{
		(*l_env)->CallStaticIntMethod ( l_env, l_class, method, (jint) show );
	}	
}
コード例 #15
0
// xmPlatformSetFrameInterval : Set Frame Interval.
// If input value is 0 then no interval timing.
KDvoid xmPlatformSetFrameInterval ( KDdouble interval )
{
	jmethodID  method = getMethodID ( "SetFrameInterval", "(D)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, interval );
	}	
}
コード例 #16
0
KDvoid xmPlatformExit ( KDint status )
{
	jmethodID  method = getMethodID ( "Exit", "(I)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, status );
	}
}
コード例 #17
0
KDvoid xmPlatformSetBrightness ( KDfloat value )
{
    jmethodID  method = getMethodID ( "SetBrightness", "(F)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, value );
	}
}
コード例 #18
0
	void stopBackgroundMusicJNI()
	{
		// void stopBackgroundMusic()
		jmethodID stopBackgroundMusicMethodID = getMethodID("stopBackgroundMusic", "()V");

		if (stopBackgroundMusicMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, stopBackgroundMusicMethodID);
		}
	}
コード例 #19
0
	void endJNI()
	{
		// void end()
		jmethodID endMethodID = getMethodID("end", "()V");

		if (endMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, endMethodID);
		}
	}
コード例 #20
0
	void setEffectsVolumeJNI(float volume)
	{
		// void setEffectsVolume(float)
		jmethodID setEffectsVolumeMethodID = getMethodID("setEffectsVolume", "(F)V");

		if (setEffectsVolumeMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, setEffectsVolumeMethodID, volume);
		}
	}
コード例 #21
0
	void rewindBackgroundMusicJNI()
	{
		// void rewindBackgroundMusic()
		jmethodID rewindBackgroundMusicMethodID = getMethodID("rewindBackgroundMusic", "()V");

		if (rewindBackgroundMusicMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, rewindBackgroundMusicMethodID);
		}
	}
コード例 #22
0
	void stopEffectJNI(unsigned int nSoundId)
	{
		// void stopEffect(int)
		jmethodID stopEffectMethodID = getMethodID("stopEffect", "(I)V");

		if (stopEffectMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, stopEffectMethodID, (int)nSoundId);
		}
	}
コード例 #23
0
	void pauseBackgroundMusicJNI()
	{
		// void pauseBackgroundMusic()
		jmethodID pauseBackgroundMusicMethodID = getMethodID("pauseBackgroundMusic", "()V");

		if (pauseBackgroundMusicMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, pauseBackgroundMusicMethodID);
		}
	}
コード例 #24
0
KDint xmPlatformTTSSetPitch ( KDfloat pitch )
{
    jmethodID  method = getMethodID ( "TTSSetPitch", "(F)I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, pitch );
	}

	return -1;
}
コード例 #25
0
KDint xmPlatformSoundSetPosition ( XMSound* sound, KDint pos )
{
	jmethodID  method = getMethodID ( "SoundSetPosition", "(II)I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, (jint) sound->device, (jint) pos );
	}

	return -1;
}
コード例 #26
0
KDint xmPlatformTTSStop ( KDvoid )
{
    jmethodID  method = getMethodID ( "TTSStop", "()I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method );
	}

	return -1;
}
コード例 #27
0
KDint xmPlatformSoundGetDuration ( XMSound* sound )
{
	jmethodID  method = getMethodID ( "SoundGetDuration", "(I)I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, (jint) sound->device );
	}

	return -1;
}
コード例 #28
0
KDint xmPlatformTTSSetLocale ( KDint locale )
{
    jmethodID  method = getMethodID ( "TTSSetLocale", "(I)I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, locale );
	}

	return -1;
}
コード例 #29
0
KDint xmPlatformTTSSetRate ( KDfloat rate )
{
    jmethodID  method = getMethodID ( "TTSSetRate", "(F)I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, rate );
	}

	return -1;
}
コード例 #30
0
KDfloat xmPlatformSoundGetVolume ( XMSound* sound )
{
	jmethodID  method = getMethodID ( "SoundGetVolume", "(I)F" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, (jint) sound->device );
	}

	return -1;
}