/** * Retrives error message clears error state. * <p>Java declaration: * <pre> * private native String getErrorMessage0(); * </pre> * @return Error message string */ KNIEXPORT KNI_RETURNTYPE_OBJECT KNIDECL(com_sun_cardreader_PlatformCardDevice_getErrorMessage0) { jbyte err_msg[1024]; KNI_StartHandles(1); KNI_DeclareHandle(err_msg_handle); if (javacall_carddevice_get_error(err_msg, sizeof err_msg) == JAVACALL_TRUE) { KNI_NewStringUTF(err_msg, err_msg_handle); } KNI_EndHandlesAndReturnObject(err_msg_handle); }
/** * Retrives error message into provided buffer and clears state. * @param buf Buffer to store message * @param buf_size Size of the buffer in bytes * @return PCSL_TRUE if error messages were returned, PCSL_FALSE otherwise */ jboolean jsr177_get_error(jbyte *buf, jsize buf_size) { return javacall_carddevice_get_error(buf, buf_size) == JAVACALL_FALSE ? PCSL_FALSE : PCSL_TRUE; }
/** * Initializes the device. * <p>Java declaration: * <pre> * private native boolean init0(); * </pre> * @return KNI_TRUE in case of success, else KNI_FALSE * @throws CardDeviceException If configuration failed. */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL (com_sun_cardreader_PlatformCardDevice_init0) { jboolean retcode = KNI_FALSE; javacall_result status; char *err_msg; char *buffer; const char *prop_value; prop_value = getInternalProperty(hostsandports); if (prop_value != NULL) { status = javacall_carddevice_set_property(hostsandports, prop_value); if (status != JAVACALL_OK) { goto err; } prop_value = getInternalProperty(satselectapdu); status = javacall_carddevice_set_property(satselectapdu, prop_value); if (status != JAVACALL_OK) { goto err; } } if ((status = javacall_carddevice_init()) == JAVACALL_OK) { javacall_carddevice_clear_error(); retcode = KNI_TRUE; } else if (status == JAVACALL_NOT_IMPLEMENTED) { /* We throw special exception to tell i3tests to skip real testing*/ KNI_ThrowNew(cardDeviceException, "stub"); retcode = KNI_TRUE; } goto end; err: #define BUFFER_SIZE 128 buffer = malloc(BUFFER_SIZE); if (buffer == NULL) { err_msg = "init0()"; KNI_ThrowNew(jsropOutOfMemoryError, err_msg); goto end; } switch (status) { case JAVACALL_NOT_IMPLEMENTED: if (javacall_carddevice_get_error(buffer, BUFFER_SIZE)) { err_msg = buffer; } else { err_msg = "Required property not supported"; } KNI_ThrowNew(cardDeviceException, err_msg); break; case JAVACALL_OUT_OF_MEMORY: if (javacall_carddevice_get_error(buffer, BUFFER_SIZE)) { err_msg = buffer; } else { err_msg = "init0()"; } KNI_ThrowNew(jsropOutOfMemoryError, err_msg); break; default: if (javacall_carddevice_get_error(buffer, BUFFER_SIZE)) { err_msg = buffer; } else { err_msg = "Invalid internal property"; } KNI_ThrowNew(cardDeviceException, err_msg); break; } free(buffer); end: KNI_ReturnInt(retcode); }