MCPcopy Create free account
hub / github.com/SoarGroup/Soar / CreateJavaCallbackData

Function CreateJavaCallbackData

Core/ClientSMLSWIG/Java/JavaCallbackByHand.h:218–254  ·  view source on GitHub ↗

Collect the Java values into a single object which we'll register with our local event handler. When this handler is called we'll unpack the Java data and make a callback to the Java process.

Source from the content-addressed store, hash-verified

216// Collect the Java values into a single object which we'll register with our local event handler.
217// When this handler is called we'll unpack the Java data and make a callback to the Java process.
218static JavaCallbackData* CreateJavaCallbackData(bool storeAgent, JNIEnv* jenv, jclass jcls, jlong jarg1, jint jarg2, jobject jarg3, jobject jarg4, char const* pMethodName, jobject jarg6)
219{
220 // The trick here is we collect up all of the Java information and store that as the callback data
221 // for our local handler. When our handler is called we'll unpack the data and make the Java callback.
222
223 // This is critical: we need to make our references to the objects "global".
224 // Otherwise the JNI objects will be deleted when we exit this method making them useless
225 // to us when the eventual callback occurs.
226 jobject jglobal3 = jenv->NewGlobalRef(jarg3) ; // The Java agent or kernel object
227 jobject jglobal4 = jenv->NewGlobalRef(jarg4) ; // The Java object which will handle this callback
228 jobject jglobal6 = jenv->NewGlobalRef(jarg6) ; // Arbitrary object passed back to the caller
229
230 // Get the method name from the Java string
231 // We used to pass this in as a parameter to the callback, but now its imbedded in the interface definition.
232 //const char *pMethodName = jenv->GetStringUTFChars(jarg5, 0);
233
234 // Record the virtual machine we are using
235 JavaVM vm ;
236 JavaVM* pvm = &vm ;
237 jint result = jenv->GetJavaVM(&pvm) ;
238
239 if (result != 0)
240 {
241 printf("Error getting Java VM\n") ;
242 return 0 ;
243 }
244
245 JavaCallbackData* pJavaData = new JavaCallbackData(pvm, jenv, storeAgent ? jglobal3 : 0, storeAgent ? 0 : jglobal3, jglobal4, pMethodName, jglobal6) ;
246
247 // Save the callback data so we can free it later
248 callbackdatas.push_back(pJavaData);
249
250 // Release the string we got from Java
251 //jenv->ReleaseStringUTFChars(jarg5, pMethodName);
252
253 return pJavaData ;
254}
255
256// This is the C++ handler which will be called by clientSML when the event fires.
257// Then from here we need to call back to Java to pass back the message.

Calls 1

push_backMethod · 0.45

Tested by

no test coverage detected