1 /* sane - Scanner Access Now Easy.
2    Copyright (C) 1997 Jeffrey S. Freedman
3    This file is part of the SANE package.
4 
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 
18    As a special exception, the authors of SANE give permission for
19    additional uses of the libraries contained in this release of SANE.
20 
21    The exception is that, if you link a SANE library with other files
22    to produce an executable, this does not by itself cause the
23    resulting executable to be covered by the GNU General Public
24    License.  Your use of that executable is in no way restricted on
25    account of linking the SANE library code into it.
26 
27    This exception does not, however, invalidate any other reasons why
28    the executable file might be covered by the GNU General Public
29    License.
30 
31    If you submit changes to SANE to the maintainers to be included in
32    a subsequent release, you agree by submitting the changes that
33    those changes may be distributed with this exception intact.
34 
35    If you write modifications of your own for SANE, it is your choice
36    whether to permit this exception to apply to your modifications.
37    If you do not wish that, delete this exception notice.  */
38 
39 //
40 //	Sane.java - Java version of SANE API.
41 //
42 //	Written: 10/9/97 - JSF
43 //
44 
45 public class Sane
46 {
47 	//
48 	//	Public constants:
49 	//
50 public static int FIXED_SCALE_SHIFT = 16;
51 	//
52 	//	Sane status values:
53 	//
54 public static int STATUS_GOOD = 0;	// everything A-OK
55 public static int STATUS_UNSUPPORTED = 1;// operation is not supported
56 public static int STATUS_CANCELLED = 2;	// operation was cancelled
57 public static int STATUS_DEVICE_BUSY = 3;// device is busy; try again later
58 public static int STATUS_INVAL = 4;	// data is invalid (includes no
59 					//   dev at open)
60 public static int STATUS_EOF = 5;	// no more data available (end-of-file)
61 public static int STATUS_JAMMED = 6;	// document feeder jammed
62 public static int STATUS_NO_DOCS = 7;	// document feeder out of documents
63 public static int STATUS_COVER_OPEN = 8;// scanner cover is open
64 public static int STATUS_IO_ERROR = 9;	// error during device I/O
65 public static int STATUS_NO_MEM = 10;	// out of memory
66 					// access to resource has been denied
67 public static int STATUS_ACCESS_DENIED = 11;
68 	//
69 	//	Initialize when class is loaded.
70 	//
71 static	{
72 	System.loadLibrary("sanej");
73 	}
74 	//
75 	//	Private methods:
76 	//
77 				// Get list of devices.
getDevicesNative( SaneDevice[] deviceList, boolean localOnly)78 private native int getDevicesNative(
79 				SaneDevice[] deviceList, boolean localOnly);
80 				// Get option descriptor.
getOptionNative(int handle, int option, SaneOption opt)81 private native void getOptionNative(int handle, int option, SaneOption opt);
82 	//
83 	//	Public methods:
84 	//
Sane()85 public Sane()
86 	{  }
fix(double v)87 public int fix(double v)
88 	{ return (int) ((v) * (1 << FIXED_SCALE_SHIFT)); }
unfix(int v)89 public double unfix(int v)
90 	{ return (double)(v) / (1 << FIXED_SCALE_SHIFT); }
versionMajor(int code)91 public int versionMajor(int code)
92 	{ return ((code) >> 24) &   0xff; }
versionMinor(int code)93 public int versionMinor(int code)
94 	{ return ((code) >> 16) &   0xff; }
versionBuild(int code)95 public int versionBuild(int code)
96 	{ return ((code) >>  0) & 0xffff; }
97 	//
98 	//	SANE interface.
99 	//
100 				// Initialize, and return STATUS_
init(int[] versionCode)101 public native int init(int[] versionCode);
exit()102 public native void exit();	// All done.
103 				// Get list of devices.
getDevices(SaneDevice[] deviceList, boolean localOnly)104 public int getDevices(SaneDevice[] deviceList, boolean localOnly)
105 	{
106 				// Create objects first.
107 	for (int i = 0; i < deviceList.length - 1; i++)
108 		deviceList[i] = new SaneDevice();
109 	return getDevicesNative(deviceList, localOnly);
110 	}
111 				// Open a device.
open(String deviceName, int[] handle)112 public native int open(String deviceName, int[] handle);
113 				// Close a device.
close(int handle)114 public native void close(int handle);
115 				// Get option descriptor.
getOptionDescriptor(int handle, int option)116 public SaneOption getOptionDescriptor(int handle, int option)
117 	{
118 	SaneOption opt = new SaneOption();
119 	opt.name = null;
120 	getOptionNative(handle, option, opt);
121 	if (opt.name == null)	// Error?
122 		return (null);
123 	return (opt);
124 	}
125 				// Get each type of option:
getControlOption(int handle, int option, int [] value, int [] info)126 public native int getControlOption(int handle, int option, int [] value,
127 							int [] info);
getControlOption(int handle, int option, byte [] value, int [] info)128 public native int getControlOption(int handle, int option, byte [] value,
129 							int [] info);
130 				// Set each type of option (SET_VALUE or
131 				//  SET_AUTO):
setControlOption(int handle, int option, int action, int value, int [] info)132 public native int setControlOption(int handle, int option,
133 				int action, int value, int [] info);
setControlOption(int handle, int option, int action, String value, int [] info)134 public native int setControlOption(int handle, int option,
135 				int action, String value, int [] info);
getParameters(int handle, SaneParameters params)136 public native int getParameters(int handle, SaneParameters params);
start(int handle)137 public native int start(int handle);
read(int handle, byte [] data, int maxLength, int [] length)138 public native int read(int handle, byte [] data,
139 					int maxLength, int [] length);
cancel(int handle)140 public native void cancel(int handle);
strstatus(int status)141 public native String strstatus(int status);
142 }
143