Exemplo n.º 1
0
javacall_result jsr177_set_property(const char *prop_name, 
                                      const char *prop_value) {

    return javacall_carddevice_set_property(prop_name, prop_value);
}
Exemplo n.º 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);
}