MCPcopy Create free account
hub / github.com/AGenUI/AGenUI / callSync

Method callSync

core/src/jni/jni_android_platform_function.cpp:114–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112}
113
114FunctionCallResult AndroidPlatformFunction::callSync(const FunctionCallContext& context, const std::string& params) {
115 FunctionCallResult result;
116 result.status = FunctionCallStatus::Error;
117
118 JNIEnv* env = JNIHelper::getJNIEnv();
119 if (!env) {
120 result.error = "Failed to get JNIEnv";
121 AGENUI_LOG("[AndroidPlatformFunction] callSync: failed to get JNIEnv");
122 return result;
123 }
124
125 if (!_callSyncMethod || !_javaFunction) {
126 result.error = "Method or function object is null";
127 AGENUI_LOG("[AndroidPlatformFunction] callSync: method or object is null");
128 return result;
129 }
130
131 // Build Java FunctionCallContext object
132 ScopedLocalRef<jstring> jSurfaceId(env, env->NewStringUTF(context.surfaceId.c_str()));
133 ScopedLocalRef<jobject> jContext(env, env->NewObject(
134 _contextClass, _contextConstructor,
135 static_cast<jint>(context.instanceId), jSurfaceId.get()));
136 if (jContext.get() == nullptr) {
137 result.error = "Failed to create FunctionCallContext object";
138 AGENUI_LOG("[AndroidPlatformFunction] callSync: failed to create context object");
139 return result;
140 }
141
142 ScopedLocalRef<jstring> jParams(env, env->NewStringUTF(params.c_str()));
143
144 ScopedLocalRef<jstring> jResult(env, (jstring)env->CallObjectMethod(
145 _javaFunction, _callSyncMethod, jContext.get(), jParams.get()));
146
147 if (env->ExceptionCheck()) {
148 env->ExceptionDescribe();
149 env->ExceptionClear();
150 result.error = "Exception occurred during callSync";
151 AGENUI_LOG("[AndroidPlatformFunction] callSync: exception occurred");
152 return result;
153 }
154
155 if (jResult.get() == nullptr) {
156 result.error = "callSync returned null";
157 AGENUI_LOG("[AndroidPlatformFunction] callSync: returned null");
158 return result;
159 }
160
161 ScopedUtfChars resultChars(env, jResult.get());
162 return parseFunctionCallEnvelope(resultChars.c_str());
163}
164
165} // namespace agenui
166#endif

Callers

nothing calls this directly

Calls 3

c_strMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected