MCPcopy Create free account
hub / github.com/Snapchat/Valdi / loadModule

Method loadModule

valdi/src/valdi/android/NativeBridge.cpp:368–396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

366}
367
368void ValdiAndroid::NativeBridge::loadModule( // NOLINT
369 fbjni::alias_ref<fbjni::JClass> /* clazz */, // NOLINT
370 jlong runtimeHandle,
371 jstring moduleName,
372 fbjni::alias_ref<JValdiFunction> completion) { // NOLINT
373 auto* runtime = getRuntime(runtimeHandle);
374 if (runtime == nullptr) {
375 return;
376 }
377 auto* env = fbjni::Environment::current();
378 auto javaEnv = ValdiAndroid::JavaEnv();
379 auto cppModuleName = ValdiAndroid::toInternedString(javaEnv, moduleName);
380 auto completionConverted = ValdiAndroid::toValue(javaEnv, ValdiAndroid::JavaEnv::newLocalRef(completion.get()));
381
382 if (completionConverted.getFunction() == nullptr) {
383 ValdiAndroid::throwJavaValdiException(env, "completion should be a function");
384 return;
385 }
386
387 runtime->getResourceManager().loadModuleAsync(
388 cppModuleName, Valdi::ResourceManagerLoadModuleType::Sources, [=](const auto& result) {
389 Valdi::Value parameter;
390 if (!result) {
391 parameter = Valdi::Value(result.error());
392 }
393
394 (*completionConverted.getFunction())(&parameter, 1);
395 });
396}
397
398jobject ValdiAndroid::NativeBridge::createContext( // NOLINT
399 fbjni::alias_ref<fbjni::JClass> /* clazz */, // NOLINT

Callers

nothing calls this directly

Calls 10

getRuntimeFunction · 0.85
toInternedStringFunction · 0.85
toValueFunction · 0.85
throwJavaValdiExceptionFunction · 0.85
loadModuleAsyncMethod · 0.80
getMethod · 0.65
getFunctionMethod · 0.65
errorMethod · 0.65
JavaEnvClass · 0.50
ValueClass · 0.50

Tested by

no test coverage detected