control_ret_t control_init_xscope(const char *host_str, const char *port_str) { if (xscope_ep_set_print_cb(xscope_print) != XSCOPE_EP_SUCCESS) { fprintf(stderr, "xscope_ep_set_print_cb failed\n"); return CONTROL_ERROR; } if (xscope_ep_set_register_cb(register_callback) != XSCOPE_EP_SUCCESS) { fprintf(stderr, "xscope_ep_set_register_cb failed\n"); return CONTROL_ERROR; } if (xscope_ep_set_record_cb(record_callback) != XSCOPE_EP_SUCCESS) { fprintf(stderr, "xscope_ep_set_record_cb failed\n"); return CONTROL_ERROR; } if (xscope_ep_connect(host_str, port_str) != XSCOPE_EP_SUCCESS) { return CONTROL_ERROR; } DBG(printf("connected to server at port %s\n", port_str)); // wait for xSCOPE probe registration while (probe_id == -1) { pause_short(); } return CONTROL_SUCCESS; }
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { JNIEnv *env; jclass cls; jvm = vm; if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_6)) { return JNI_ERR; } cls = (*env)->FindClass(env, "com/synapticon/somanetconnect/XscopeSocket"); if (cls == NULL) { printf("\nERROR: Failed to find the desired jclass\n"); fflush(stdout); return JNI_ERR; } clazz = (*env)->NewGlobalRef(env, cls); (*env)->DeleteLocalRef(env, cls); if (clazz == NULL) { printf("\nERROR: Failed to create a new global reference for the jclass object\n"); fflush(stdout); return JNI_ERR; } registrationReceivedMethodID = (*env)->GetMethodID(env, clazz, "registrationReceived", "(ILjava/lang/String;)V"); if (registrationReceivedMethodID == NULL) { printf("\nERROR: Failed to get the registrationReceived method ID\n"); fflush(stdout); return JNI_ERR; } dataReceivedMethodID = (*env)->GetMethodID(env, clazz, "dataReceived", "(IJJ)V"); if (dataReceivedMethodID == NULL) { printf("\nERROR: Failed to get the dataReceived method ID\n"); fflush(stdout); return JNI_ERR; } infoDataReceivedMethodID = (*env)->GetMethodID(env, clazz, "infoDataReceived", "([B)V"); if (infoDataReceivedMethodID == NULL) { printf("\nERROR: Failed to get the infoDataReceived method ID\n"); fflush(stdout); return JNI_ERR; } printMethodID = (*env)->GetMethodID(env, clazz, "print", "(Ljava/lang/String;)V"); if (printMethodID == NULL) { printf("\nERROR: Failed to get the print method ID\n"); fflush(stdout); return JNI_ERR; } xscope_ep_set_register_cb(xscope_register); xscope_ep_set_record_cb(xscope_record); xscope_ep_set_print_cb(xscope_print); return JNI_VERSION_1_6; }