| 334 | } |
| 335 | |
| 336 | static void OutputNotificationHandler(void* pUserData, sml::Agent* pAgent) |
| 337 | { |
| 338 | // The user data is the class we declared above, where we store the Java data to use in the callback. |
| 339 | JavaCallbackData* pJavaData = (JavaCallbackData*)pUserData ; |
| 340 | |
| 341 | // Now try to call back to Java |
| 342 | JNIEnv* jenv = pJavaData->GetEnv(); |
| 343 | |
| 344 | // We start from the Java object whose method we wish to call. |
| 345 | jobject jobj = pJavaData->m_HandlerObject ; |
| 346 | jclass cls = jenv->GetObjectClass(jobj) ; |
| 347 | |
| 348 | if (cls == 0) |
| 349 | { |
| 350 | printf("Failed to get Java class\n") ; |
| 351 | return ; |
| 352 | } |
| 353 | |
| 354 | // Look up the Java method we want to call. |
| 355 | // The method name is passed in by the user (and needs to match exactly, including case). |
| 356 | // The method should be owned by the m_HandlerObject that the user also passed in. |
| 357 | // Any slip here and you get a NoSuchMethod exception and my Java VM shuts down. |
| 358 | jmethodID mid = jenv->GetMethodID(cls, pJavaData->m_HandlerMethod.c_str(), "(Ljava/lang/Object;Lsml/Agent;)V") ; |
| 359 | |
| 360 | if (mid == 0) |
| 361 | { |
| 362 | printf("Failed to get Java method\n") ; |
| 363 | return ; |
| 364 | } |
| 365 | |
| 366 | // Make the method call. |
| 367 | jenv->CallVoidMethod(jobj, mid, pJavaData->m_CallbackData, pJavaData->m_AgentObject); |
| 368 | } |
| 369 | |
| 370 | JNIEXPORT jlong JNICALL Java_sml_smlJNI_Agent_1RegisterForOutputNotification(JNIEnv* jenv, jclass jcls, jlong jarg1, jobject jarg3, jobject jarg4, jobject jarg6) |
| 371 | { |