本文整理汇总了C++中JEnv::GetMethodID方法的典型用法代码示例。如果您正苦于以下问题:C++ JEnv::GetMethodID方法的具体用法?C++ JEnv::GetMethodID怎么用?C++ JEnv::GetMethodID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JEnv
的用法示例。
在下文中一共展示了JEnv::GetMethodID方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
ObjectManager::ObjectManager()
:
m_numberOfGC(0), m_currentObjectId(0), m_cache(NewWeakGlobalRefCallback, DeleteWeakGlobalRefCallback, 1000, this)
{
JEnv env;
PlatformClass = env.FindClass("com/tns/Platform");
assert(PlatformClass != nullptr);
GET_JAVAOBJECT_BY_ID_METHOD_ID = env.GetStaticMethodID(PlatformClass, "getJavaObjectByID", "(I)Ljava/lang/Object;");
assert(GET_JAVAOBJECT_BY_ID_METHOD_ID != nullptr);
GET_OR_CREATE_JAVA_OBJECT_ID_METHOD_ID = env.GetStaticMethodID(PlatformClass, "getOrCreateJavaObjectID", "(Ljava/lang/Object;)I");
assert(GET_OR_CREATE_JAVA_OBJECT_ID_METHOD_ID != nullptr);
MAKE_INSTANCE_WEAK_BATCH_METHOD_ID = env.GetStaticMethodID(PlatformClass, "makeInstanceWeak", "(Ljava/nio/ByteBuffer;IZ)V");
assert(MAKE_INSTANCE_WEAK_BATCH_METHOD_ID != nullptr);
CHECK_WEAK_OBJECTS_ARE_ALIVE_METHOD_ID = env.GetStaticMethodID(PlatformClass, "checkWeakObjectAreAlive", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;I)V");
assert(CHECK_WEAK_OBJECTS_ARE_ALIVE_METHOD_ID != nullptr);
JAVA_LANG_CLASS = env.FindClass("java/lang/Class");
assert(JAVA_LANG_CLASS != nullptr);
GET_NAME_METHOD_ID = env.GetMethodID(JAVA_LANG_CLASS, "getName", "()Ljava/lang/String;");
assert(GET_NAME_METHOD_ID != nullptr);
ObjectManager::instance = this;
}
示例2: Init
void JsDebugger::Init(v8::Isolate *isolate, const string& packageName, jobject jsDebugger)
{
s_isolate = isolate;
s_packageName = packageName;
JEnv env;
s_jsDebugger = env.NewGlobalRef(jsDebugger);
s_JsDebuggerClass = env.FindClass("com/tns/JsDebugger");
assert(s_JsDebuggerClass != nullptr);
s_EnqueueMessage = env.GetMethodID(s_JsDebuggerClass, "enqueueMessage", "(Ljava/lang/String;)V");
assert(s_EnqueueMessage != nullptr);
s_EnableAgent = env.GetMethodID(s_JsDebuggerClass, "enableAgent", "()V");
assert(s_EnableAgent != nullptr);
}
示例3: AppInitCallback
void NativePlatform::AppInitCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
try {
auto isolate = Isolate::GetCurrent();
if (args.Length() != 1)
{
throw NativeScriptException(string("Application should be initialized with single parameter"));
}
if (!args[0]->IsObject())
{
throw NativeScriptException(string("Application should be initialized with single object parameter containing overridden methods"));
}
// TODO: find another way to get "com/tns/NativeScriptApplication" metadata (move it to more appropriate place)
auto node = MetadataNode::GetOrCreate("com/tns/NativeScriptApplication");
auto appInstance = node->CreateJSWrapper(isolate);
DEBUG_WRITE("Application object created id: %d", appInstance->GetIdentityHash());
auto implementationObject = args[0]->ToObject();
implementationObject->SetHiddenValue(V8StringConstants::GetClassImplementationObject(), External::New(isolate, node));
DEBUG_WRITE("Application object implementation object is with id: %d", implementationObject->GetIdentityHash());
implementationObject->SetPrototype(appInstance->GetPrototype());
bool appSuccess = appInstance->SetPrototype(implementationObject);
if (!appSuccess)
{
throw NativeScriptException(string("Application could not be initialized correctly"));
}
jweak applicationObject = g_objectManager->GetJavaObjectByID(AppJavaObjectID);
JEnv env;
jclass appClass = env.FindClass("com/tns/NativeScriptApplication");
g_objectManager->Link(appInstance, AppJavaObjectID, appClass);
JniLocalRef applicationClass(env.GetObjectClass(applicationObject));
jmethodID setNativeScriptOverridesMethodId = env.GetMethodID((jclass)applicationClass, "setNativeScriptOverrides", "([Ljava/lang/String;)V");
jobjectArray methodOverrides = NativeScriptRuntime::GetMethodOverrides(env, implementationObject);
env.CallVoidMethod(applicationObject, setNativeScriptOverridesMethodId, methodOverrides);
} catch (NativeScriptException& e) {
e.ReThrowToV8();
}
catch (exception e) {
DEBUG_WRITE("Error: c++ exception: %s", e.what());
}
catch (...) {
DEBUG_WRITE("Error: c++ exception!");
}
}
示例4: CallJavaMethod
void NativeScriptRuntime::CallJavaMethod(const Local<Object>& caller, const string& className, const string& methodName, MetadataEntry *entry, bool isStatic, bool isSuper, const v8::FunctionCallbackInfo<v8::Value>& args)
{
SET_PROFILER_FRAME();
JEnv env;
jclass clazz;
jmethodID mid;
string *sig = nullptr;
string *returnType = nullptr;
auto retType = MethodReturnType::Unknown;
MethodCache::CacheMethodInfo mi;
if ((entry != nullptr) && entry->isResolved)
{
isStatic = entry->isStatic;
if (entry->memberId == nullptr)
{
clazz = env.FindClass(className);
if (clazz == nullptr)
{
MetadataNode* callerNode = MetadataNode::GetNodeFromHandle(caller);
const string callerClassName = callerNode->GetName();
DEBUG_WRITE("Cannot resolve class: %s while calling method: %s callerClassName: %s", className.c_str(), methodName.c_str(), callerClassName.c_str());
clazz = env.FindClass(callerClassName);
if (clazz == nullptr)
{
//todo: plamen5kov: throw exception here
DEBUG_WRITE("Cannot resolve caller's class name: %s", callerClassName.c_str());
return;
}
entry->memberId = isStatic ?
env.GetStaticMethodID(clazz, methodName, entry->sig) :
env.GetMethodID(clazz, methodName, entry->sig);
if (entry->memberId == nullptr)
{
//todo: plamen5kov: throw exception here
DEBUG_WRITE("Cannot resolve a method %s on caller class: %s", methodName.c_str(), callerClassName.c_str());
return;
}
}
else
{
entry->memberId = isStatic ?
env.GetStaticMethodID(clazz, methodName, entry->sig) :
env.GetMethodID(clazz, methodName, entry->sig);
if (entry->memberId == nullptr)
{
//todo: plamen5kov: throw exception here
DEBUG_WRITE("Cannot resolve a method %s on class: %s", methodName.c_str(), className.c_str());
return;
}
}
entry->clazz = clazz;
}
mid = reinterpret_cast<jmethodID>(entry->memberId);
clazz = entry->clazz;
sig = &entry->sig;
returnType = &entry->returnType;
retType = entry->retType;
}
else
{
DEBUG_WRITE("Resolving method: %s on className %s", methodName.c_str(), className.c_str());
clazz = env.FindClass(className);
if (clazz != nullptr)
{
mi = MethodCache::ResolveMethodSignature(className, methodName, args, isStatic);
if (mi.mid == nullptr)
{
DEBUG_WRITE("Cannot resolve class=%s, method=%s, isStatic=%d, isSuper=%d", className.c_str(), methodName.c_str(), isStatic, isSuper);
return;
}
}
else
{
MetadataNode* callerNode = MetadataNode::GetNodeFromHandle(caller);
const string callerClassName = callerNode->GetName();
DEBUG_WRITE("Resolving method on caller class: %s.%s on className %s", callerClassName.c_str(), methodName.c_str(), className.c_str());
mi = MethodCache::ResolveMethodSignature(callerClassName, methodName, args, isStatic);
if (mi.mid == nullptr)
{
DEBUG_WRITE("Cannot resolve class=%s, method=%s, isStatic=%d, isSuper=%d, callerClass=%s", className.c_str(), methodName.c_str(), isStatic, isSuper, callerClassName.c_str());
return;
}
}
clazz = mi.clazz;
mid = mi.mid;
sig = &mi.signature;
returnType = &mi.returnType;
retType = mi.retType;
}
//.........这里部分代码省略.........
示例5: CallJavaMethod
void NativeScriptRuntime::CallJavaMethod(const Handle<Object>& caller, const string& className, const string& methodName, MetadataEntry *entry, bool isStatic, bool isSuper, const v8::FunctionCallbackInfo<v8::Value>& args)
{
SET_PROFILER_FRAME();
JEnv env;
jclass clazz;
jmethodID mid;
string sig;
if ((entry != nullptr) && entry->isResolved)
{
isStatic = entry->isStatic;
if (entry->memberId == nullptr)
{
entry->clazz = env.FindClass(className);
if (entry->clazz == nullptr)
{
MetadataNode* callerNode = MetadataNode::GetNodeFromHandle(caller);
const string callerClassName = callerNode->GetName();
DEBUG_WRITE("Cannot resolve class: %s while calling method: %s callerClassName: %s", className.c_str(), methodName.c_str(), callerClassName.c_str());
clazz = env.FindClass(callerClassName);
if (clazz == nullptr)
{
DEBUG_WRITE("Cannot resolve caller's class name: %s", callerClassName.c_str());
return;
}
mid = isStatic ?
env.GetStaticMethodID(clazz, methodName, entry->sig) :
env.GetMethodID(clazz, methodName, entry->sig);
if (mid == nullptr)
{
DEBUG_WRITE("Cannot resolve a method %s on caller class: %s", methodName.c_str(), callerClassName.c_str());
return;
}
}
else
{
entry->memberId = isStatic ?
env.GetStaticMethodID(entry->clazz, methodName, entry->sig) :
env.GetMethodID(entry->clazz, methodName, entry->sig);
if (entry->memberId == nullptr)
{
DEBUG_WRITE("Cannot resolve a method %s on class: %s", methodName.c_str(), className.c_str());
return;
}
}
}
if (entry->clazz != nullptr)
{
clazz = entry->clazz;
mid = reinterpret_cast<jmethodID>(entry->memberId);
}
sig = entry->sig;
}
else
{
DEBUG_WRITE("Resolving method: %s on className %s", methodName.c_str(), className.c_str());
MethodCache::CacheMethodInfo mi;
clazz = env.FindClass(className);
if (clazz != nullptr)
{
mi = MethodCache::ResolveMethodSignature(className, methodName, args, isStatic);
if (mi.mid == nullptr)
{
DEBUG_WRITE("Cannot resolve class=%s, method=%s, isStatic=%d, isSuper=%d", className.c_str(), methodName.c_str(), isStatic, isSuper);
return;
}
}
else
{
MetadataNode* callerNode = MetadataNode::GetNodeFromHandle(caller);
const string callerClassName = callerNode->GetName();
DEBUG_WRITE("Resolving method on caller class: %s.%s on className %s", callerClassName.c_str(), methodName.c_str(), className.c_str());
mi = MethodCache::ResolveMethodSignature(callerClassName, methodName, args, isStatic);
if (mi.mid == nullptr)
{
DEBUG_WRITE("Cannot resolve class=%s, method=%s, isStatic=%d, isSuper=%d, callerClass=%s", className.c_str(), methodName.c_str(), isStatic, isSuper, callerClassName.c_str());
return;
}
}
clazz = mi.clazz;
mid = mi.mid;
sig = mi.signature;
}
//.........这里部分代码省略.........