当前位置: 首页>>代码示例>>C++>>正文


C++ JEnv类代码示例

本文整理汇总了C++中JEnv的典型用法代码示例。如果您正苦于以下问题:C++ JEnv类的具体用法?C++ JEnv怎么用?C++ JEnv使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了JEnv类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

JniLocalRef::JniLocalRef(const JniLocalRef& rhs)
{
	JEnv env;

	m_obj = rhs.m_isWeak ? rhs.m_obj : env.NewLocalRef(rhs.m_obj);
	m_isWeak = rhs.m_isWeak;
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:7,代码来源:JniLocalRef.cpp

示例2: SET_PROFILER_FRAME

jobject NativeScriptRuntime::CreateJavaInstance(int objectID, const std::string& fullClassName, const ArgsWrapper& argWrapper, jclass javaClass, bool isInterface)
{
	SET_PROFILER_FRAME();

	jobject instance = nullptr;
	DEBUG_WRITE("CreateJavaInstance:  %s", fullClassName.c_str());

	JEnv env;
	auto& args = argWrapper.args;

	JsArgToArrayConverter argConverter(args, isInterface, argWrapper.outerThis);
	if (argConverter.IsValid())
	{
		jobjectArray javaArgs = argConverter.ToJavaArray();

		int ctorId = GetCachedConstructorId(env, args, fullClassName, javaArgs, javaClass);

		jobject obj = env.CallStaticObjectMethod(PlatformClass,
				CREATE_INSTANCE_METHOD_ID,
				javaArgs,
				(jint) objectID,
				ctorId);


		instance = obj;
	}
	else
	{
		JsArgToArrayConverter::Error err = argConverter.GetError();
		throw NativeScriptException(err.msg);
	}

	return instance;
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:34,代码来源:NativeScriptRuntime.cpp

示例3: DebugBreakCallback

void JsDebugger::DebugBreakCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
	if (s_jsDebugger == nullptr)
	{
		return;
	}

	try
	{
		JEnv env;
		env.CallStaticVoidMethod(s_JsDebuggerClass, s_EnableAgent);

		DebugBreak();
	}
	catch (NativeScriptException& e)
	{
		e.ReThrowToV8();
	}
	catch (std::exception e) {
		stringstream ss;
		ss << "Error: c++ exception: " << e.what() << endl;
		NativeScriptException nsEx(ss.str());
		nsEx.ReThrowToV8();
	}
	catch (...) {
		NativeScriptException nsEx(std::string("Error: c++ exception!"));
		nsEx.ReThrowToV8();
	}
}
开发者ID:atifzaidi,项目名称:android-runtime,代码行数:29,代码来源:JsDebugger.cpp

示例4: GetCachedConstructorId

int NativeScriptRuntime::GetCachedConstructorId(JEnv& env, const FunctionCallbackInfo<Value>& args, const string& fullClassName, jobjectArray javaArgs, jclass javaClass)
{
	int ctorId = -1;
	string encodedCtorArgs = MethodCache::EncodeSignature(fullClassName, "<init>", args, false);
	auto itFound = s_constructorCache.find(encodedCtorArgs);


	if (itFound != s_constructorCache.end())
	{
		ctorId = itFound->second;
	}
	else
	{
		jint id = env.CallStaticIntMethod(PlatformClass, CACHE_CONSTRUCTOR_METHOD_ID, javaClass, javaArgs);

		if (env.ExceptionCheck() == JNI_FALSE)
		{
			ctorId = id;
			s_constructorCache.insert(make_pair(encodedCtorArgs, ctorId));
		}
	}

	DEBUG_WRITE("GetCachedConstructorId: encodedCtorArgs=%s, ctorId=%d", encodedCtorArgs.c_str(), ctorId);
	return ctorId;
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:25,代码来源:NativeScriptRuntime.cpp

示例5: MakeRegularObjectsWeak

void ObjectManager::MakeRegularObjectsWeak(const set<int>& instances, DirectBuffer& inputBuff)
{
	JEnv env;

	jboolean keepAsWeak = JNI_FALSE;

	for (auto javaObjectId : instances)
	{
		bool success = inputBuff.Write(javaObjectId);

		if (!success)
		{
			int length = inputBuff.Length();
			env.CallStaticVoidMethod(PlatformClass, MAKE_INSTANCE_WEAK_BATCH_METHOD_ID, (jobject) inputBuff, length, keepAsWeak);
			inputBuff.Reset();
			success = inputBuff.Write(javaObjectId);
			assert(success);
		}
	}
	int size = inputBuff.Size();
	if (size > 0)
	{
		env.CallStaticVoidMethod(PlatformClass, MAKE_INSTANCE_WEAK_BATCH_METHOD_ID, (jobject) inputBuff, size, keepAsWeak);
	}

	inputBuff.Reset();
}
开发者ID:atifzaidi,项目名称:android-runtime,代码行数:27,代码来源:ObjectManager.cpp

示例6: ResolveClass

jclass NativeScriptRuntime::ResolveClass(const std::string& fullClassname, const Local<Object>& implementationObject) {

	auto itFound = s_classCache.find(fullClassname);

	jclass globalRefToGeneratedClass;

	if (itFound != s_classCache.end())
	{
		globalRefToGeneratedClass = itFound->second;
	}
	else
	{
		JEnv env;

		//get needed arguments in order to load binding
		JniLocalRef javaFullClassName(env.NewStringUTF(fullClassname.c_str()));

		jobjectArray methodOverrides = GetMethodOverrides(env, implementationObject);

		//create or load generated binding (java class)
		JniLocalRef generatedClass(env.CallStaticObjectMethod(PlatformClass, RESOLVE_CLASS_METHOD_ID,  (jstring)javaFullClassName, methodOverrides));
		globalRefToGeneratedClass = reinterpret_cast<jclass>(env.NewGlobalRef(generatedClass));

		s_classCache.insert(make_pair(fullClassname, globalRefToGeneratedClass));
	}

	return globalRefToGeneratedClass;
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:28,代码来源:NativeScriptRuntime.cpp

示例7: GetJavaObjectByIDImpl

jobject ObjectManager::GetJavaObjectByIDImpl(uint32_t javaObjectID)
{
	JEnv env;

	jobject object = env.CallStaticObjectMethod(PlatformClass, GET_JAVAOBJECT_BY_ID_METHOD_ID, javaObjectID);
	return object;
}
开发者ID:atifzaidi,项目名称:android-runtime,代码行数:7,代码来源:ObjectManager.cpp

示例8: MakeImplObjectsWeak

void ObjectManager::MakeImplObjectsWeak(const vector<PersistentObjectIdPair>& instances, DirectBuffer& inputBuff)
{
	JEnv env;

	jboolean keepAsWeak = JNI_TRUE;

	for (const auto& poIdPair : instances)
	{
		int javaObjectId = poIdPair.javaObjectId;

		bool success = inputBuff.Write(javaObjectId);

		if (!success)
		{
			int length = inputBuff.Length();
			jboolean keepAsWeak = JNI_TRUE;
			env.CallStaticVoidMethod(PlatformClass, MAKE_INSTANCE_WEAK_BATCH_METHOD_ID, (jobject) inputBuff, length, keepAsWeak);
			inputBuff.Reset();
			success = inputBuff.Write(javaObjectId);
			assert(success);
		}
	}
	int size = inputBuff.Size();
	if (size > 0)
	{
		jboolean keepAsWeak = JNI_TRUE;
		env.CallStaticVoidMethod(PlatformClass, MAKE_INSTANCE_WEAK_BATCH_METHOD_ID, (jobject) inputBuff, size, keepAsWeak);
	}

	inputBuff.Reset();
}
开发者ID:atifzaidi,项目名称:android-runtime,代码行数:31,代码来源:ObjectManager.cpp

示例9: DEBUG_WRITE

bool NativeScriptRuntime::RegisterInstance(const Local<Object>& jsObject, const std::string& fullClassName, const ArgsWrapper& argWrapper, const Local<Object>& implementationObject, bool isInterface)
{
	bool success;

	DEBUG_WRITE("RegisterInstance called for '%s'", fullClassName.c_str());

	JEnv env;

	jclass generatedJavaClass = ResolveClass(fullClassName, implementationObject);

	int javaObjectID = objectManager->GenerateNewObjectID();

	DEBUG_WRITE("RegisterInstance: Linking new instance");
	objectManager->Link(jsObject, javaObjectID, nullptr);

	jobject instance = CreateJavaInstance(javaObjectID, fullClassName, argWrapper, generatedJavaClass, isInterface);

	JniLocalRef localInstance(instance);
	success = !localInstance.IsNull();

	if (success)
	{
		DEBUG_WRITE("RegisterInstance: Updating linked instance with its real class");
		jclass instanceClass = env.FindClass(fullClassName);
		objectManager->SetJavaClass(jsObject, instanceClass);
	}
	else
	{
		DEBUG_WRITE("RegisterInstance failed with null new instance");
	}

	return success;
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:33,代码来源:NativeScriptRuntime.cpp

示例10: GetClassName

string ObjectManager::GetClassName(jobject javaObject)
{
	JEnv env;

	JniLocalRef objectClass(env.GetObjectClass(javaObject));

	return GetClassName((jclass) objectClass);
}
开发者ID:atifzaidi,项目名称:android-runtime,代码行数:8,代码来源:ObjectManager.cpp

示例11: clazz

Local<Object> ObjectManager::CreateJSWrapper(jint javaObjectID, const string& typeName, jobject instance)
{
	JEnv env;

	JniLocalRef clazz(env.GetObjectClass(instance));

	return CreateJSWrapperHelper(javaObjectID, typeName, clazz);
}
开发者ID:atifzaidi,项目名称:android-runtime,代码行数:8,代码来源:ObjectManager.cpp

示例12: GetOrCreateObjectId

int ObjectManager::GetOrCreateObjectId(jobject object)
{
	JEnv env;

	jint javaObjectID = env.CallStaticIntMethod(PlatformClass, GET_OR_CREATE_JAVA_OBJECT_ID_METHOD_ID, object);

	return javaObjectID;
}
开发者ID:atifzaidi,项目名称:android-runtime,代码行数:8,代码来源:ObjectManager.cpp

示例13: APP_FAIL

void NativeScriptRuntime::APP_FAIL(const char *message)
{
	//ASSERT_FAIL(message);

	JEnv env;
	jstring msg = env.NewStringUTF(message);
	env.CallStaticVoidMethod(PlatformClass, APP_FAIL_METHOD_ID, msg);
}
开发者ID:bootstraponline,项目名称:android-runtime,代码行数:8,代码来源:NativeScriptRuntime.cpp

示例14: SET_PROFILER_FRAME

void NativeScriptRuntime::RequireCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
	SET_PROFILER_FRAME();

	ASSERT_MESSAGE(args.Length() == 2, "require should be called with two parameters");
	ASSERT_MESSAGE(!args[0]->IsUndefined() && !args[0]->IsNull(), "require called with undefined moduleName parameter");
	ASSERT_MESSAGE(!args[1]->IsUndefined() && !args[1]->IsNull(), "require called with undefined callingModulePath parameter");
	ASSERT_MESSAGE(args[0]->IsString(), "require should be called with string parameter");
	ASSERT_MESSAGE(args[1]->IsString(), "require should be called with string parameter");

	string moduleName = ConvertToString(args[0].As<String>());
	string callingModuleDirName = ConvertToString(args[1].As<String>());

	JEnv env;
	JniLocalRef jsModulename(env.NewStringUTF(moduleName.c_str()));
	JniLocalRef jsCallingModuleDirName(env.NewStringUTF(callingModuleDirName.c_str()));
	JniLocalRef jsModulePath(env.CallStaticObjectMethod(RequireClass, GET_MODULE_PATH_METHOD_ID, (jstring) jsModulename, (jstring) jsCallingModuleDirName));

	auto isolate = Isolate::GetCurrent();

	// cache the required modules by full path, not name only, since there might be some collisions with relative paths and names
	string modulePath = ArgConverter::jstringToString((jstring) jsModulePath);
	if(modulePath == ""){
		// module not found
		stringstream ss;
		ss << "Module \"" << moduleName << "\" not found";
		string exception = ss.str();
		ExceptionUtil::GetInstance()->ThrowExceptionToJs(exception);
		return;
	}
	if (modulePath == "EXTERNAL_FILE_ERROR")
	{
		// module not found
		stringstream ss;
		ss << "Module \"" << moduleName << "\" is located on the external storage. Modules can be private application files ONLY";
		string exception = ss.str();
		ExceptionUtil::GetInstance()->ThrowExceptionToJs(exception);
		return;
	}

	auto it = loadedModules.find(modulePath);

	Handle<Object> moduleObj;
	bool hasError = false;

	if (it == loadedModules.end())
	{
		CompileAndRun(modulePath, hasError, moduleObj, false/*is bootstrap call*/);
	}
	else
	{
		moduleObj = Local<Object>::New(isolate, *((*it).second));
	}

	if(!hasError){
		args.GetReturnValue().Set(moduleObj);
	}
}
开发者ID:bootstraponline,项目名称:android-runtime,代码行数:58,代码来源:NativeScriptRuntime.cpp

示例15: GetArrayLength

int NativeScriptRuntime::GetArrayLength(const Local<Object>& arr)
{
	JEnv env;

	auto javaArr = reinterpret_cast<jarray>(objectManager->GetJavaObjectByJsObject(arr));

	auto length = env.GetArrayLength(javaArr);

	return length;
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:10,代码来源:NativeScriptRuntime.cpp


注:本文中的JEnv类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。