/*
 * Track.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_Track.h"
#include "BindingsUtil.h"

#include "libburn.h"

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_create
 * Signature: ()J
 */
JNIEXPORT jlong JNICALL
Java_org_pykix_libburnia_libburn_Track_burn_1track_1create
(
	JNIEnv *env, jclass cls
)
{
	return (jlong) burn_track_create();
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_free
 * Signature: (J)V
 */
JNIEXPORT void JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1free
(
	JNIEnv *env, jclass cls, jlong t
)
{
	burn_track_free( (struct burn_track *) t );
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_define_data
 * Signature: (JIIZI)V
 */
JNIEXPORT void JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1define_1data
(
	JNIEnv *env, jclass cls, jlong t, jint offset, jint tail, jboolean pad, jint mode
)
{
	burn_track_define_data( (struct burn_track *) t, offset, tail, pad, mode);
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_set_byte_swap
 * Signature: (JI)I
 */
JNIEXPORT jint JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1set_1byte_1swap
(
	JNIEnv *env, jclass cls, jlong t, jint swapSourceBytes
)
{
	return burn_track_set_byte_swap( (struct burn_track *) t, swapSourceBytes);
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_set_isrc
 * Signature: (JLjava/lang/String;Ljava/lang/String;BI)V
 */
JNIEXPORT void JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1set_1isrc
(
	JNIEnv *env, jclass cls, jlong t, jstring country, jstring owner, jbyte year, jint serial
)
{
	const char *ccountry;
	const char *cowner;

	ccountry = (*env)->GetStringUTFChars(env, country, NULL);
	if ( ccountry == NULL ) {
		return; /* OutOfMemoryError already thrown */
	}

	cowner = (*env)->GetStringUTFChars(env, owner, NULL);
	if ( cowner == NULL ) {
		return; /* OutOfMemoryError already thrown */
	}	

	burn_track_set_isrc( (struct burn_track *) t, (char *) ccountry, (char *) cowner, year, serial);

	(*env)->ReleaseStringUTFChars(env, country, ccountry);
	(*env)->ReleaseStringUTFChars(env, owner, cowner);
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_clear_isrc
 * Signature: (J)V
 */
JNIEXPORT void JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1clear_1isrc
(
	JNIEnv *env, jclass cls, jlong t
)
{
	burn_track_clear_isrc( (struct burn_track *) t);
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_set_source
 * Signature: (JJ)I
 */
JNIEXPORT jint JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1set_1source
(
	JNIEnv *env, jclass cls, jlong t, jlong s
)
{
	return burn_track_set_source( (struct burn_track *) t, (struct burn_source *) s);
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_set_default_size
 * Signature: (JJ)Z
 */
JNIEXPORT jboolean JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1set_1default_1size
(
	JNIEnv *env, jclass cls, jlong t, jlong size
)
{
	return burn_track_set_default_size( (struct burn_track *) t, size);
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_get_sectors
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1get_1sectors
(
	JNIEnv *env, jclass cls, jlong t
)
{
	return burn_track_get_sectors( (struct burn_track *) t);
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_get_entry
 * Signature: (J)Lorg/pykix/libburnia/libburn/TocEntry;
 */
JNIEXPORT jobject JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1get_1entry
(
	JNIEnv *env, jclass cls, jlong t
)
{
	struct burn_toc_entry entry;

	burn_track_get_entry( (struct burn_track *) t, &entry);

	return java_libburn_toc_entry_c2java(env, &entry);
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_get_mode
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1get_1mode
(
	JNIEnv *env, jclass cls, jlong t
)
{
	return burn_track_get_mode( (struct burn_track *) t );
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_get_read_bytes
 * Signature: (J)J
 */
JNIEXPORT jlong JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1get_1read_1bytes
(
	JNIEnv *env, jclass cls, jlong t
)
{
	off_t r, w;
	burn_track_get_counters( (struct burn_track *) t, &r, &w);
	return r;
}

/*
 * Class:     org_pykix_libburnia_libburn_Track
 * Method:    burn_track_get_written_bytes
 * Signature: (J)J
 */
JNIEXPORT jlong JNICALL 
Java_org_pykix_libburnia_libburn_Track_burn_1track_1get_1written_1bytes
(
	JNIEnv *env, jclass cls, jlong t
)
{
	off_t r, w;
	burn_track_get_counters( (struct burn_track *) t, &r, &w);
	return w;
}

