/*
 * Session.c
 *
 * Copyright (c) 2007  Vreixo Formoso
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * See COPYING file for details.
 */

#include "org_pykix_libburnia_libburn_Session.h"

#include "libburn.h"
#include "BindingsUtil.h"

/*
 * Class:     org_pykix_libburnia_libburn_Session
 * Method:    burn_session_create
 * Signature: ()J
 */
JNIEXPORT jlong JNICALL 
Java_org_pykix_libburnia_libburn_Session_burn_1session_1create
(
	JNIEnv *env, jclass cls
)
{
	return (jlong) burn_session_create();
}

/*
 * Class:     org_pykix_libburnia_libburn_Session
 * Method:    burn_session_free
 * Signature: (J)V
 */
JNIEXPORT void JNICALL 
Java_org_pykix_libburnia_libburn_Session_burn_1session_1free
(
	JNIEnv *env, jclass cls, jlong s
)
{
	burn_session_free( (struct burn_session *) s);
}

/*
 * Class:     org_pykix_libburnia_libburn_Session
 * Method:    burn_session_add_track
 * Signature: (JJI)Z
 */
JNIEXPORT jboolean JNICALL 
Java_org_pykix_libburnia_libburn_Session_burn_1session_1add_1track
(
	JNIEnv *env, jclass cls, jlong s, jlong t, jint pos
)
{
	return burn_session_add_track( (struct burn_session *) s, 
		(struct burn_track *) t, pos);
}

/*
 * Class:     org_pykix_libburnia_libburn_Session
 * Method:    burn_session_remove_track
 * Signature: (JJ)Z
 */
JNIEXPORT jboolean JNICALL 
Java_org_pykix_libburnia_libburn_Session_burn_1session_1remove_1track
(
	JNIEnv *env, jclass cls, jlong s, jlong t
)
{
	return burn_session_remove_track( (struct burn_session *) s, (struct burn_track *) t);
}

/*
 * Class:     org_pykix_libburnia_libburn_Session
 * Method:    burn_session_hide_first_track
 * Signature: (JI)V
 */
JNIEXPORT void JNICALL 
Java_org_pykix_libburnia_libburn_Session_burn_1session_1hide_1first_1track
(
	JNIEnv *env, jclass cls, jlong s, jint onoff
)
{
	burn_session_hide_first_track( (struct burn_session *) s, onoff );
}

/*
 * Class:     org_pykix_libburnia_libburn_Session
 * Method:    burn_session_get_sectors
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL Java_org_pykix_libburnia_libburn_Session_burn_1session_1get_1sectors
(
	JNIEnv *env, jclass cls, jlong s
)
{
	return burn_session_get_sectors( (struct burn_session *) s);
}

/*
 * Class:     org_pykix_libburnia_libburn_Session
 * Method:    burn_session_get_leadout_entry
 * Signature: (J)Lorg/pykix/libburnia/libburn/TocEntry;
 */
JNIEXPORT jobject JNICALL 
Java_org_pykix_libburnia_libburn_Session_burn_1session_1get_1leadout_1entry
(
	JNIEnv *env, jclass cls, jlong s
)
{
	struct burn_toc_entry entry;

	burn_session_get_leadout_entry( (struct burn_session *) s, &entry);

	return java_libburn_toc_entry_c2java(env, &entry);
}

/*
 * Class:     org_pykix_libburnia_libburn_Session
 * Method:    burn_session_get_tracks
 * Signature: (J)[J
 */
JNIEXPORT jlongArray JNICALL 
Java_org_pykix_libburnia_libburn_Session_burn_1session_1get_1tracks
(
	JNIEnv *env, jclass cls, jlong s
)
{
	int num;
	struct burn_track **tracks;
	int i;
	
	tracks = burn_session_get_tracks( (struct burn_session *) s, &num);

	/* create C array to store the pointers */
	jlong cresult[num];

	for ( i = 0; i < num; ++i ) {
		struct burn_track *track = tracks[i];
		cresult[i] = (jlong) track;
	}

	/* move the pointer to a Java array */
	jlongArray result = (*env)->NewLongArray(env, num);
	if ( result == NULL) {
		return NULL; /* exception already thrown */
	}
	(*env)->SetLongArrayRegion(env, result, 0, num, cresult);

	return result;
}

/*
 * Class:     org_pykix_libburnia_libburn_Session
 * Method:    burn_session_get_hidefirst
 * Signature: (J)Z
 */
JNIEXPORT jboolean JNICALL 
Java_org_pykix_libburnia_libburn_Session_burn_1session_1get_1hidefirst
(
	JNIEnv *env, jclass cls, jlong s
)
{
	return burn_session_get_hidefirst( (struct burn_session *) s);
}

