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

Function UpdateEventHandler

Core/ClientSMLSWIG/Java/JavaCallbackByHand.h:929–961  ·  view source on GitHub ↗

This is the C++ handler which will be called by clientSML when the event fires. Then from here we need to call back to Java to pass back the message.

Source from the content-addressed store, hash-verified

927// This is the C++ handler which will be called by clientSML when the event fires.
928// Then from here we need to call back to Java to pass back the message.
929static void UpdateEventHandler(sml::smlUpdateEventId id, void* pUserData, sml::Kernel* pKernel, sml::smlRunFlags runFlags)
930{
931 // The user data is the class we declared above, where we store the Java data to use in the callback.
932 JavaCallbackData* pJavaData = (JavaCallbackData*)pUserData ;
933
934 // Now try to call back to Java
935 JNIEnv* jenv = pJavaData->GetEnv() ;
936
937 // We start from the Java object whose method we wish to call.
938 jobject jobj = pJavaData->m_HandlerObject ;
939 jclass cls = jenv->GetObjectClass(jobj) ;
940
941 if (cls == 0)
942 {
943 printf("Failed to get Java class\n") ;
944 return ;
945 }
946
947 // Look up the Java method we want to call.
948 // The method name is passed in by the user (and needs to match exactly, including case).
949 // The method should be owned by the m_HandlerObject that the user also passed in.
950 // Any slip here and you get a NoSuchMethod exception and my Java VM shuts down.
951 jmethodID mid = jenv->GetMethodID(cls, pJavaData->m_HandlerMethod.c_str(), "(ILjava/lang/Object;Lsml/Kernel;I)V") ;
952
953 if (mid == 0)
954 {
955 printf("Failed to get Java method\n") ;
956 return ;
957 }
958
959 // Make the method call.
960 jenv->CallVoidMethod(jobj, mid, (int)id, pJavaData->m_CallbackData, pJavaData->m_KernelObject, runFlags);
961}
962
963// This is the hand-written JNI method for registering a callback.
964// I'm going to model it after the existing SWIG JNI methods so hopefully it'll be easier to patch this into SWIG eventually.

Callers

nothing calls this directly

Calls 1

GetEnvMethod · 0.80

Tested by

no test coverage detected