Exemplo n.º 1
0
/**
 * Enrolls a finger and returns the associated fp-data.
 * 
 * @param env the Java Environment pointer. 
 * @param obj the jobject of the type jlibfprint/JlibFprint.
 * @return the jlibfprint/JlibFprint$fp_print_data with the data just given by the scanner.
 * @throws an enroll_exception is raised is something gone wrong.
 */
JNIEXPORT jobject JNICALL Java_jlibfprint_JlibFprint_enroll_1finger(JNIEnv* env, jobject ref)
{
    const jclass fpClass = env->FindClass("jlibfprint/JlibFprint$fp_print_data");
    const jclass eeClass = env->FindClass("jlibfprint/JlibFprint$EnrollException");
    
    /* Starts the library */
    if (fp_init())  // Se differente da 0 => Exception
    {
        jobject enrollException = env->AllocObject(eeClass);
        jfieldID eeExcp_id = env->GetFieldID(eeClass, "enroll_exception", "I");
        env->SetIntField(enrollException, eeExcp_id, UNABLE_TO_LOAD_LIBFPRINT);
        env->Throw((jthrowable)enrollException);
        return NULL;
    }
    fp_dev *device;
    fp_print_data* pdp;    
    
    /* Gets the pointer to the device */
    if (!get_device_id(env, ref, &device))
    {
        jobject enrollException = env->AllocObject(eeClass);
        jfieldID eeExcp_id = env->GetFieldID(eeClass, "enroll_exception", "I");
        env->SetIntField(enrollException, eeExcp_id, DEVICE_NOT_FOUND);
        env->Throw((jthrowable)enrollException);
        return NULL;
    }    
    
    /* Enrolls the finger */
    int ef = fp_enroll_finger(device, &pdp);
    /* Create a new obj to store the data */
    jobject obj = env->AllocObject(fpClass); 
    
    /* Raises an exception if the enrollment was not completed */
    if (ef != FP_ENROLL_COMPLETE)
    {
        jobject enrollException = env->AllocObject(eeClass);
        jfieldID eeExcp_id = env->GetFieldID(eeClass, "enroll_exception", "I");
        env->SetIntField(enrollException, eeExcp_id, ef);
        env->Throw((jthrowable)enrollException);
    }
    else
    {
        /* Fills the object with the enrollment data */
        cfp2jfp(env, obj, pdp);
        memset(pdp, 0, sizeof(fp_print_data));
        fp_print_data_free(pdp); 
    }
    fp_dev_close(device);
    fp_exit();
    
    return obj;
}
Exemplo n.º 2
0
struct fp_print_data *enroll(struct fp_dev *dev) {
	struct fp_print_data *enrolled_print = NULL;
	int r;

	printf("You will need to successfully scan your finger %d times to "
		"complete the process.\n", fp_dev_get_nr_enroll_stages(dev));

	do {
		sleep(1);
		printf("\nScan your finger now.\n");
		r = fp_enroll_finger(dev, &enrolled_print);
		if (r < 0) {
			printf("Enroll failed with error %d\n", r);
			return NULL;
		}
		switch (r) {
		case FP_ENROLL_COMPLETE:
			printf("Enroll complete!\n");
			break;
		case FP_ENROLL_FAIL:
			printf("Enroll failed, something wen't wrong :(\n");
			return NULL;
		case FP_ENROLL_PASS:
			printf("Enroll stage passed. Yay!\n");
			break;
		case FP_ENROLL_RETRY:
			printf("Didn't quite catch that. Please try again.\n");
			break;
		case FP_ENROLL_RETRY_TOO_SHORT:
			printf("Your swipe was too short, please try again.\n");
			break;
		case FP_ENROLL_RETRY_CENTER_FINGER:
			printf("Didn't catch that, please center your finger on the "
				"sensor and try again.\n");
			break;
		case FP_ENROLL_RETRY_REMOVE_FINGER:
			printf("Scan failed, please remove your finger and then try "
				"again.\n");
			break;
		}
	} while (r != FP_ENROLL_COMPLETE);

	if (!enrolled_print) {
		fprintf(stderr, "Enroll complete but no print?\n");
		return NULL;
	}

	printf("Enrollment completed!\n\n");
	return enrolled_print;
}