/*
 * SpeedDescriptor.java
 *
 * 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.
 */

package org.pykix.libburnia.libburn;

/**
 * Description of a speed capability as reported by the drive in conjunction
 * with eventually loaded media. There can be more than one such object per
 * drive. 
 * 
 * <p>
 * This list is set up by {@link Burn#scan()} and gets updated by 
 * {@link Drive#grab(boolean)}. A copy may be obtained by 
 * burn_drive_get_speedlist().
 * 
 * <p>
 * For technical background info see SCSI specs MMC and SPC:
 * mode page 2Ah (from SPC 5Ah MODE SENSE) , mmc3r10g.pdf , 6.3.11 Table 364
 * ACh GET PERFORMANCE, Type 03h , mmc5r03c.pdf , 6.8.5.3 Table 312
 * 
 * @author Vreixo Formoso
 * @since 0.1
 */
public class SpeedDescriptor {

	private int source;
	private Profile profile;
	private int endlba;
	private int writeSpeed;
	private int readSpeed;
	private int wrc;
	private boolean exact;
	private boolean mrw;
	
	/* to be called from JNI code */
	SpeedDescriptor(int source, short profile, int endlba, int writeSpeed, 
			int readSpeed, int wrc, boolean exact, boolean mrw) {
		super();
		this.source = source;
		this.profile = Profile.get(profile == -1 ? 0 : profile);
		this.endlba = endlba;
		this.writeSpeed = writeSpeed;
		this.readSpeed = readSpeed;
		this.wrc = wrc;
		this.exact = exact;
		this.mrw = mrw;
	}

	/**
	 * The attributed capacity of appropriate media in logical block units
	 * i.e. 2352 raw bytes or 2048 data bytes. -1 = capacity unknown.
	 */
	public int getEndlba() {
		return endlba;
	}

	/**
	 * <code>true</code> if drive promises reported performance over full 
	 * media.
	 */
	public boolean isExact() {
		return exact;
	}

	/**
	 * <code>true</code> if suitable for mixture of read and write 
	 */
	public boolean isMrw() {
		return mrw;
	}

	/**
	 * The media type that was current at the time of report.
	 * 
	 * @return
	 * 		Same as {@link Drive#getProfile()}, {@link Profile#NONE} if
	 * 		no media was loaded.
	 */
	public Profile getProfile() {
		return profile;
	}

	/**
	 * Read speed is given in 1000 bytes/s , 0 = invalid. The numbers
	 * are supposed to be usable with {@link Drive#setSpeed(int, int)}
	 */
	public int getReadSpeed() {
		return readSpeed;
	}

	/** 
	 * Get where this info comes from.
	 * 
	 * @return
	 * 		0 = misc , 1 = mode page 2Ah , 2 = ACh GET PERFORMANCE 
	 */
	public int getSource() {
		return source;
	}

	/**
	 * Expert info from ACh GET PERFORMANCE and/or mode page 2Ah.
	 * Expect values other than 0 or 1 to get a meaning in future.
	 * Rotational control: 0 = CLV/default , 1 = CAV
	 */
	public int getWrc() {
		return wrc;
	}

	/**
	 * Write speed is given in 1000 bytes/s , 0 = invalid. The numbers
	 * are supposed to be usable with {@link Drive#setSpeed(int, int)}
	 */
	public int getWriteSpeed() {
		return writeSpeed;
	}
	
}
