#include "jni.h"
#include <fossil-scm/fossil.h>

/*
 * Class:     org_fossil_scm_libfossil_Checkout
 * Method:    open
 * Signature: (Ljava/lang/String;I)J
 */
JNIEXPORT jlong JNICALL Java_org_fossil_scm_libfossil_Checkout_open
  (JNIEnv *env, jobject obj, jstring dir, jint flags)
{
	fsl_cx *handle = NULL;
	const char *d = (*env)->GetStringUTFChars(env, dir, 0);

	/* Open the checkout */
	fsl_cx_init(&handle, NULL);
	if( fsl_checkout_open_dir(handle, d, -1, 1)!=0 ){
		/* TODO error-handling */
	}

	(*env)->ReleaseStringUTFChars(env, dir, d);
	return (jlong)(size_t)handle;
}

/*
 * Class:     org_fossil_scm_libfossil_Checkout
 * Method:    dispose
 * Signature: (J)V
 */
JNIEXPORT void JNICALL Java_org_fossil_scm_libfossil_Checkout_dispose
  (JNIEnv *env, jobject obj, jlong handle)
{
	fsl_cx *cx = (fsl_cx *)(size_t)handle;
	/* Close handle */
	fsl_cx_finalize(cx);
}

