package sensicamJNI;

import java.util.HashMap;

public class SensicamException extends RuntimeException {
	private static final HashMap<Integer, String> errors = new HashMap<Integer, String>() {{
		 put(0, "NOERR: No Error. I don't know why you're reading this :p "); 
		 put(-1, "NOTINIT: Initialization failed; no camera connected"); 
		 put(-2, "TIMEOUT: Timeout in any function"); 
		 put(-3, "WRONGVAL: Function-call with wrong parameter"); 
		 put(-4, "NOPCIDEV: Cannot locate PCI card"); 
		 put(-5, "WRONGOS: Seriously, what are you doing?"); 
		 put(-6, "NODRIVER: No driver."); 
		 put(-7, "IOFAILURE: Unhelpfully non-descript IO failure"); 
		 put(-8, "NOCONNECTION: No connection. Is the camera actually on?"); 
		 put(-9, "INVMODE: Invalid Camera mode"); 
		 put(-10, "NOPCIBIOS: no PCI Bios found"); 
		 put(-11, "DEVICEBUSY: device is hold by an other process"); 
		 put(-12, "DATAERROR: Error in reading or writing data to board"); 
		 put(-13, "NOFUNCTION: Presumably this means that isn't supported."); 
		 put(-14, "NODMABUF: cannot allocate DMA buffer"); 
		 put(-15, "NORBT: Online.rbt File not found or load error"); 
		 put(-16, "POLLERR: DMA Timeout"); 
		 put(-17, "EVENTERR: creating Event failed"); 
		 put(-20, "CAMERABUSY: LOAD_COC error (Camera runs Program-Memory)"); 
		 put(-21, "OUTRAM: to many values in COC"); 
		 put(-22, "WRONGTEMP: Camera Temperatur is out of Normal-Range wrong WINDOWS-Version"); 
		 put(-23, "NOMEM: Buffer de/allocate error"); 
		 put(-24, "READOUTRUN: Readout is running"); 
		 put(-25, "NOBUFFLAG: Set/reset Buffer Flags failed"); 
		 put(-26, "BUFINUSE: buffer is used"); 
		 put(-27, "SYSERR: a call to a windows-function fails"); 
		 put(-28, "DMARUN: try to disturb dma running"); 
		 put(-29, "NOFILE: cannot open file"); 
		 put(-30, "REGERR: error in reading/writing to registry, which isn't surprising in linux."); 
		 put(-31, "NODIALOG: no open dialog"); 
		 put(-32, "WRONGVERS: need newer called vxd or dll"); 
		 put(-33, "WRONGEXTSTAT: one of extended status bits shows an error"); 
		 put(-34, "BOARDMEMERR: board memory has an error"); 
		 put(-35, "WRONGCCD: function not allowed with this ccdtyp"); 
		 put(-36, "DMAERROR: error in DMA from board to memory"); 
		 put(-37, "FILE_READ_ERR: Error while reading from a file"); 
		 put(-38, "FILE_WRITE_ERR: Error while writing to a file"); 
		 put(-39, "CLEARBUF_ERR: Error while clearing the buffer"); 
		 put(100, "NOPIC: picture-buffer empty"); 
		 put(101, "UNDERPIC: picture to dark"); 
		 put(102, "OVERPIC: picture to bright"); 
		 put(103, "VALCHANGE: values changed in TEST_COC"); 
		 put(104, "STR_SHORT: tab buffer to short in TEST_COC"); 
		 put(120, "TESTSOFT: Lattice Testsoftware is loaded"); 

	}};
	
	public static final String getErrorString(int returnCode){
			String str = errors.get(returnCode);
			return (str != null) ? str : ("Unknown sensicam error '" + returnCode + "'.");			
	}
	
	public SensicamException(String functionName, int returnCode) { this(functionName + " returned the error: " + getErrorString(returnCode));	}
	public SensicamException(String errorString) { super(errorString); }

}
