Пример #1
0
/** 
 * Initializes the driver.
 * @return JSR177_STATUSCODE_OK if all done successfuly, 
 *         JSR177_STATUSCODE_NOT_IMPLEMENTED when the stub was called
 *         JSR177_STATUSCODE_FAIL otherwise
 */
JSR177_STATUSCODE jsr177_init() {
    javacall_result result = javacall_carddevice_init();
    switch (result) {
    case JAVACALL_OK:
        return JSR177_STATUSCODE_OK;
    case JAVACALL_FAIL:
        return JSR177_STATUSCODE_FAIL;
    case JAVACALL_NOT_IMPLEMENTED:
    default:
        return JSR177_STATUSCODE_NOT_IMPLEMENTED;
    }
}
Пример #2
0
/**
 * 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);
}