| 92 | } |
| 93 | |
| 94 | JavaFunctionTrampolineHelper* JavaFunctionTrampolineHelper::make() { |
| 95 | auto cls = JavaClass::resolveOrAbort(JavaEnv(), "com/snap/valdi/callable/ValdiFunctionTrampoline"); |
| 96 | |
| 97 | auto getFunctionClassesMethod = cls.getStaticMethod( |
| 98 | "getFunctionClasses", Valdi::ValueSchema::array(Valdi::ValueSchema::untyped()), nullptr, 0, false); |
| 99 | |
| 100 | auto functionClasses = getFunctionClassesMethod.call(reinterpret_cast<jobject>(cls.getClass()), 0, nullptr); |
| 101 | |
| 102 | JavaObjectArray array(functionClasses.getObjectArray()); |
| 103 | |
| 104 | auto size = array.size(); |
| 105 | SC_ASSERT(size % 5 == 0); |
| 106 | |
| 107 | Valdi::InlineContainerAllocator<JavaFunctionTrampolineHelper, JavaFunctionTrampolineHelperEntry> allocator; |
| 108 | |
| 109 | auto entriesCount = size / 5; |
| 110 | auto* trampolineHelper = allocator.allocateUnmanaged(entriesCount, std::move(cls), entriesCount); |
| 111 | |
| 112 | size_t entryIndex = 0; |
| 113 | |
| 114 | for (size_t i = 0; i < size;) { |
| 115 | auto functionClassName = array.getObject(i++); |
| 116 | auto functionClass = array.getObject(i++); |
| 117 | auto bridgeFunctionClass = array.getObject(i++); |
| 118 | auto invokeMethod = array.getObject(i++); |
| 119 | auto constructorMethod = array.getObject(i++); |
| 120 | |
| 121 | auto invoker = AnyJavaMethod::fromReflectedMethod(invokeMethod.get(), false, JavaValueType::Object); |
| 122 | auto constructor = AnyJavaMethod::fromReflectedMethod(constructorMethod.get(), false, JavaValueType::Object); |
| 123 | |
| 124 | auto& entry = allocator.getContainerStartPtr(trampolineHelper)[entryIndex]; |
| 125 | entry.functionClassName = toInternedString(JavaEnv(), reinterpret_cast<jstring>(functionClassName.get())); |
| 126 | entry.functionClass = JavaClass(JavaEnv(), reinterpret_cast<jclass>(functionClass.get())); |
| 127 | entry.bridgeFunctionClass = JavaClass(JavaEnv(), reinterpret_cast<jclass>(bridgeFunctionClass.get())); |
| 128 | entry.invoker = invoker; |
| 129 | entry.bridgeFunctionConstructor.setMethodId(constructor.getMethodId()); |
| 130 | |
| 131 | entryIndex++; |
| 132 | } |
| 133 | |
| 134 | return trampolineHelper; |
| 135 | } |
| 136 | |
| 137 | } // namespace ValdiAndroid |
nothing calls this directly
no test coverage detected