本文整理汇总了C++中JEnv::CallVoidMethod方法的典型用法代码示例。如果您正苦于以下问题:C++ JEnv::CallVoidMethod方法的具体用法?C++ JEnv::CallVoidMethod怎么用?C++ JEnv::CallVoidMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JEnv
的用法示例。
在下文中一共展示了JEnv::CallVoidMethod方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MyMessageHandler
/* *
* private method that takes debug message as json from v8
* after it gets the message the message handler passes it to enqueueMessage method in java
*/
void JsDebugger::MyMessageHandler(const v8::Debug::Message& message)
{
if (s_jsDebugger == nullptr)
{
return;
}
auto json = message.GetJSON();
auto str = ConvertToString(json);
JEnv env;
JniLocalRef s(env.NewStringUTF(str.c_str()));
env.CallVoidMethod(s_jsDebugger, s_EnqueueMessage, (jstring) s);
}
示例2: 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!");
}
}
示例3: ConsoleMessage
void JsDebugger::ConsoleMessage(const v8::FunctionCallbackInfo<v8::Value>& args)
{
if ((args.Length() > 0) && args[0]->IsString())
{
std::string message = ConvertToString(args[0]->ToString());
//jboolean isError = (jboolean) = args[1]->ToBoolean()->BooleanValue();
std:string level = "log";
if (args.Length() > 1 && args[1]->IsString())
{
level = ConvertToString(args[1]->ToString());
}
string srcFileName = "";
int lineNumber = 0;
int columnNumber = 0;
auto stackTrace = StackTrace::CurrentStackTrace(Isolate::GetCurrent(), 2, StackTrace::kOverview);
if (!stackTrace.IsEmpty())
{
auto frame = stackTrace->GetFrame(1);
if (!frame.IsEmpty())
{
auto scriptName = frame->GetScriptName();
if (!scriptName.IsEmpty())
{
srcFileName = ConvertToString(scriptName);
}
lineNumber = frame->GetLineNumber();
columnNumber = frame->GetColumn();
}
}
// var consoleEvent = {
// "seq":0,
// "type":"event",
// "event":"messageAdded",
// "success":true,
// "body":
// {
// "message":
// {
// "source":"console-api",
// "type": "log",
// "level": 'error',
// "line": 0,
// "column": 0,
// "url": "",
// "groupLevel": 7,
// "repeatCount": 1,
// "text": "My message"
// }
// }
// };
stringstream consoleEventSS;
consoleEventSS << "{\"seq\":0, \"type\":\"event\", \"event\":\"messageAdded\", \"success\":true, \"body\": { \"message\": { \"source\":\"console-api\", "
<< " \"type\": \"log\","
<< " \"level\": \"" << level << "\", "
<< " \"line\": " << lineNumber << ","
<< " \"column\": " << columnNumber << ","
<< " \"url\" : \"" << srcFileName << "\","
<< " \"groupLevel\": 7, \"repeatCount\": 1, "
<< " \"text\": \"" << message << "\" } } }";
JEnv env;
JniLocalRef s(env.NewStringUTF(consoleEventSS.str().c_str()));
env.CallVoidMethod(s_jsDebugger, s_EnqueueMessage, (jstring) s);
}
}