1141cc406Sopenharmony_ci/* sane - Scanner Access Now Easy. 2141cc406Sopenharmony_ci Copyright (C) 1997 Jeffrey S. Freedman 3141cc406Sopenharmony_ci This file is part of the SANE package. 4141cc406Sopenharmony_ci 5141cc406Sopenharmony_ci This program is free software; you can redistribute it and/or 6141cc406Sopenharmony_ci modify it under the terms of the GNU General Public License as 7141cc406Sopenharmony_ci published by the Free Software Foundation; either version 2 of the 8141cc406Sopenharmony_ci License, or (at your option) any later version. 9141cc406Sopenharmony_ci 10141cc406Sopenharmony_ci This program is distributed in the hope that it will be useful, but 11141cc406Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 12141cc406Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13141cc406Sopenharmony_ci General Public License for more details. 14141cc406Sopenharmony_ci 15141cc406Sopenharmony_ci You should have received a copy of the GNU General Public License 16141cc406Sopenharmony_ci along with this program. If not, see <https://www.gnu.org/licenses/>. 17141cc406Sopenharmony_ci 18141cc406Sopenharmony_ci As a special exception, the authors of SANE give permission for 19141cc406Sopenharmony_ci additional uses of the libraries contained in this release of SANE. 20141cc406Sopenharmony_ci 21141cc406Sopenharmony_ci The exception is that, if you link a SANE library with other files 22141cc406Sopenharmony_ci to produce an executable, this does not by itself cause the 23141cc406Sopenharmony_ci resulting executable to be covered by the GNU General Public 24141cc406Sopenharmony_ci License. Your use of that executable is in no way restricted on 25141cc406Sopenharmony_ci account of linking the SANE library code into it. 26141cc406Sopenharmony_ci 27141cc406Sopenharmony_ci This exception does not, however, invalidate any other reasons why 28141cc406Sopenharmony_ci the executable file might be covered by the GNU General Public 29141cc406Sopenharmony_ci License. 30141cc406Sopenharmony_ci 31141cc406Sopenharmony_ci If you submit changes to SANE to the maintainers to be included in 32141cc406Sopenharmony_ci a subsequent release, you agree by submitting the changes that 33141cc406Sopenharmony_ci those changes may be distributed with this exception intact. 34141cc406Sopenharmony_ci 35141cc406Sopenharmony_ci If you write modifications of your own for SANE, it is your choice 36141cc406Sopenharmony_ci whether to permit this exception to apply to your modifications. 37141cc406Sopenharmony_ci If you do not wish that, delete this exception notice. */ 38141cc406Sopenharmony_ci 39141cc406Sopenharmony_ci// 40141cc406Sopenharmony_ci// Sane.java - Java version of SANE API. 41141cc406Sopenharmony_ci// 42141cc406Sopenharmony_ci// Written: 10/9/97 - JSF 43141cc406Sopenharmony_ci// 44141cc406Sopenharmony_ci 45141cc406Sopenharmony_cipublic class Sane 46141cc406Sopenharmony_ci{ 47141cc406Sopenharmony_ci // 48141cc406Sopenharmony_ci // Public constants: 49141cc406Sopenharmony_ci // 50141cc406Sopenharmony_cipublic static int FIXED_SCALE_SHIFT = 16; 51141cc406Sopenharmony_ci // 52141cc406Sopenharmony_ci // Sane status values: 53141cc406Sopenharmony_ci // 54141cc406Sopenharmony_cipublic static int STATUS_GOOD = 0; // everything A-OK 55141cc406Sopenharmony_cipublic static int STATUS_UNSUPPORTED = 1;// operation is not supported 56141cc406Sopenharmony_cipublic static int STATUS_CANCELLED = 2; // operation was cancelled 57141cc406Sopenharmony_cipublic static int STATUS_DEVICE_BUSY = 3;// device is busy; try again later 58141cc406Sopenharmony_cipublic static int STATUS_INVAL = 4; // data is invalid (includes no 59141cc406Sopenharmony_ci // dev at open) 60141cc406Sopenharmony_cipublic static int STATUS_EOF = 5; // no more data available (end-of-file) 61141cc406Sopenharmony_cipublic static int STATUS_JAMMED = 6; // document feeder jammed 62141cc406Sopenharmony_cipublic static int STATUS_NO_DOCS = 7; // document feeder out of documents 63141cc406Sopenharmony_cipublic static int STATUS_COVER_OPEN = 8;// scanner cover is open 64141cc406Sopenharmony_cipublic static int STATUS_IO_ERROR = 9; // error during device I/O 65141cc406Sopenharmony_cipublic static int STATUS_NO_MEM = 10; // out of memory 66141cc406Sopenharmony_ci // access to resource has been denied 67141cc406Sopenharmony_cipublic static int STATUS_ACCESS_DENIED = 11; 68141cc406Sopenharmony_ci // 69141cc406Sopenharmony_ci // Initialize when class is loaded. 70141cc406Sopenharmony_ci // 71141cc406Sopenharmony_cistatic { 72141cc406Sopenharmony_ci System.loadLibrary("sanej"); 73141cc406Sopenharmony_ci } 74141cc406Sopenharmony_ci // 75141cc406Sopenharmony_ci // Private methods: 76141cc406Sopenharmony_ci // 77141cc406Sopenharmony_ci // Get list of devices. 78141cc406Sopenharmony_ciprivate native int getDevicesNative( 79141cc406Sopenharmony_ci SaneDevice[] deviceList, boolean localOnly); 80141cc406Sopenharmony_ci // Get option descriptor. 81141cc406Sopenharmony_ciprivate native void getOptionNative(int handle, int option, SaneOption opt); 82141cc406Sopenharmony_ci // 83141cc406Sopenharmony_ci // Public methods: 84141cc406Sopenharmony_ci // 85141cc406Sopenharmony_cipublic Sane() 86141cc406Sopenharmony_ci { } 87141cc406Sopenharmony_cipublic int fix(double v) 88141cc406Sopenharmony_ci { return (int) ((v) * (1 << FIXED_SCALE_SHIFT)); } 89141cc406Sopenharmony_cipublic double unfix(int v) 90141cc406Sopenharmony_ci { return (double)(v) / (1 << FIXED_SCALE_SHIFT); } 91141cc406Sopenharmony_cipublic int versionMajor(int code) 92141cc406Sopenharmony_ci { return ((code) >> 24) & 0xff; } 93141cc406Sopenharmony_cipublic int versionMinor(int code) 94141cc406Sopenharmony_ci { return ((code) >> 16) & 0xff; } 95141cc406Sopenharmony_cipublic int versionBuild(int code) 96141cc406Sopenharmony_ci { return ((code) >> 0) & 0xffff; } 97141cc406Sopenharmony_ci // 98141cc406Sopenharmony_ci // SANE interface. 99141cc406Sopenharmony_ci // 100141cc406Sopenharmony_ci // Initialize, and return STATUS_ 101141cc406Sopenharmony_cipublic native int init(int[] versionCode); 102141cc406Sopenharmony_cipublic native void exit(); // All done. 103141cc406Sopenharmony_ci // Get list of devices. 104141cc406Sopenharmony_cipublic int getDevices(SaneDevice[] deviceList, boolean localOnly) 105141cc406Sopenharmony_ci { 106141cc406Sopenharmony_ci // Create objects first. 107141cc406Sopenharmony_ci for (int i = 0; i < deviceList.length - 1; i++) 108141cc406Sopenharmony_ci deviceList[i] = new SaneDevice(); 109141cc406Sopenharmony_ci return getDevicesNative(deviceList, localOnly); 110141cc406Sopenharmony_ci } 111141cc406Sopenharmony_ci // Open a device. 112141cc406Sopenharmony_cipublic native int open(String deviceName, int[] handle); 113141cc406Sopenharmony_ci // Close a device. 114141cc406Sopenharmony_cipublic native void close(int handle); 115141cc406Sopenharmony_ci // Get option descriptor. 116141cc406Sopenharmony_cipublic SaneOption getOptionDescriptor(int handle, int option) 117141cc406Sopenharmony_ci { 118141cc406Sopenharmony_ci SaneOption opt = new SaneOption(); 119141cc406Sopenharmony_ci opt.name = null; 120141cc406Sopenharmony_ci getOptionNative(handle, option, opt); 121141cc406Sopenharmony_ci if (opt.name == null) // Error? 122141cc406Sopenharmony_ci return (null); 123141cc406Sopenharmony_ci return (opt); 124141cc406Sopenharmony_ci } 125141cc406Sopenharmony_ci // Get each type of option: 126141cc406Sopenharmony_cipublic native int getControlOption(int handle, int option, int [] value, 127141cc406Sopenharmony_ci int [] info); 128141cc406Sopenharmony_cipublic native int getControlOption(int handle, int option, byte [] value, 129141cc406Sopenharmony_ci int [] info); 130141cc406Sopenharmony_ci // Set each type of option (SET_VALUE or 131141cc406Sopenharmony_ci // SET_AUTO): 132141cc406Sopenharmony_cipublic native int setControlOption(int handle, int option, 133141cc406Sopenharmony_ci int action, int value, int [] info); 134141cc406Sopenharmony_cipublic native int setControlOption(int handle, int option, 135141cc406Sopenharmony_ci int action, String value, int [] info); 136141cc406Sopenharmony_cipublic native int getParameters(int handle, SaneParameters params); 137141cc406Sopenharmony_cipublic native int start(int handle); 138141cc406Sopenharmony_cipublic native int read(int handle, byte [] data, 139141cc406Sopenharmony_ci int maxLength, int [] length); 140141cc406Sopenharmony_cipublic native void cancel(int handle); 141141cc406Sopenharmony_cipublic native String strstatus(int status); 142141cc406Sopenharmony_ci} 143