[sane-devel] Using the resource manager library...

Gerhard Jaeger gerhard@gjaeger.de
Fri, 16 Jul 2004 12:44:32 +0200


--Boundary-00=_QG79Amgqh1DttHj
Content-Type: text/plain;
  charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi list,

I found that SuSE patches the SANE sources that way, that the package
will use the resource manager library to open SCSI AND USB devices.
I'd like to include this patch (see below), are the any objections?
For more information about the resource manager, see:
http://www.lst.de/~okir/resmgr

Ciao,
  Gerhard

--Boundary-00=_QG79Amgqh1DttHj
Content-Type: text/x-diff;
  charset="iso-8859-15";
  name="sane-backends-1.0.14-resmgr.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="sane-backends-1.0.14-resmgr.patch"

--- configure.in	2004-04-30 20:31:46.000000000 +0200
+++ configure.in	2004-05-15 02:03:59.874035704 +0200
@@ -113,6 +113,16 @@
 AC_CHECK_HEADERS([asm/io.h],,,[#include <sys/types.h>])
 SANE_CHECK_MISSING_HEADERS

+AC_CHECK_HEADER(resmgr.h,[
+	AC_CHECK_LIB(
+		resmgr,
+		rsm_open_device,[
+			AC_DEFINE(HAVE_RESMGR,1,[define if you have the resmgr library"])
+			LIBS="$LIBS -lresmgr"
+		]
+	)
+])
+
 dnl ***********************************************************************
 dnl Checks for types and structures
 dnl ***********************************************************************
--- sanei/sanei_scsi.c	2004-03-29 19:50:24.000000000 +0200
+++ sanei/sanei_scsi.c	2004-05-15 01:53:56.155814824 +0200
@@ -80,6 +80,10 @@
 #define MACOSX_INTERFACE	17
 #define WIN32_INTERFACE		18

+#ifdef HAVE_RESMGR
+# include <resmgr.h>
+#endif
+
 #if defined (HAVE_SCSI_SG_H)
 # define USE LINUX_INTERFACE
 # include <scsi/sg.h>
@@ -770,13 +774,17 @@
 static SANE_Status
 get_max_buffer_size (const char *file)
 {
-  int fd;
+  int fd = -1;
   int buffersize = SCSIBUFFERSIZE, i;
   size_t len;
   char *cc, *cc1, buf[32];

+#ifdef HAVE_RESMGR
+  fd = rsm_open_device(file, O_RDWR);
+#endif

-  fd = open (file, O_RDWR);
+  if (fd == -1)
+    fd = open (file, O_RDWR);

   if (fd > 0)
     {
@@ -1216,7 +1224,13 @@
   }
 #endif /* defined(SGIOCSTL) || (USE == SOLARIS_INTERFACE) */

-  fd = open (dev, O_RDWR | O_EXCL
+  fd = -1;
+#ifdef HAVE_RESMGR
+  fd = rsm_open_device(dev, O_RDWR | O_EXCL | O_NONBLOCK);
+#endif
+
+  if (fd == -1)
+    fd = open (dev, O_RDWR | O_EXCL
 #if USE == LINUX_INTERFACE
 	     | O_NONBLOCK
 #endif
@@ -2456,7 +2470,12 @@
 		    dnp->base + guess_devnum);
 	else
 	  snprintf (name, name_len, "%s%d", dnp->prefix, guess_devnum);
-	dev_fd = open (name, O_RDWR | O_NONBLOCK);
+   dev_fd = -1;
+#ifdef HAVE_RESMGR
+   dev_fd = rsm_open_device (name, O_RDWR | O_NONBLOCK);
+#endif
+   if (dev_fd == -1)
+     dev_fd = open (name, O_RDWR | O_NONBLOCK);
 	if (dev_fd >= 0)
 	  {
 	    lx_sg_dev_base = k;
--- sanei/sanei_usb.c	2004-02-04 21:24:10.000000000 +0100
+++ sanei/sanei_usb.c	2004-05-15 02:01:35.133039680 +0200
@@ -55,6 +55,9 @@
 #include <stdio.h>
 #include <dirent.h>

+#ifdef HAVE_RESMGR
+#include <resmgr.h>
+#endif
 #ifdef HAVE_LIBUSB
 #include <usb.h>
 #endif /* HAVE_LIBUSB */
@@ -268,7 +271,12 @@
 	      if (strlen (dir_name) + strlen (dir_entry->d_name) + 1 > sizeof (devname))
 		  continue;
 	      sprintf (devname, "%s%s", dir_name, dir_entry->d_name);
-	      fd = open (devname, O_RDWR);
+	      fd = -1;
+#ifdef HAVE_RESMGR
+	      fd = rsm_open_device (devname, O_RDWR);
+#endif
+	      if (fd == -1)
+	        fd = open (devname, O_RDWR);
 	      if (fd < 0)
 		{
 		  DBG (5, "sanei_usb_init: couldn't open %s: %s\n", devname,
@@ -700,7 +708,12 @@
     {
       long int flag;
       /* Using kernel scanner driver */
-      devices[devcount].fd = open (devname, O_RDWR);
+      devices[devcount].fd = -1;
+#ifdef HAVE_RESMGR
+      devices[devcount].fd = rsm_open_device (devname, O_RDWR);
+#endif
+      if (devices[devcount].fd == -1)
+        devices[devcount].fd = open (devname, O_RDWR);
       if (devices[devcount].fd < 0)
 	{
 	  SANE_Status status = SANE_STATUS_INVAL;

--Boundary-00=_QG79Amgqh1DttHj--