]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix USB printing on Solaris (STR #1756)
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 12 Jul 2006 18:20:02 +0000 (18:20 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 12 Jul 2006 18:20:02 +0000 (18:20 +0000)
backend/runloop.c:
    - backendRunLoop(): Only use select() when use_bc is set; also add
      offline detection via error codes.

backend/usb-unix.c:
    - print_file(): Use use_bc when calling backendRunLoop().
    - list_devices(): Open USB devices write-only on Solaris.
    - open_device(): Add use_bc argument, set to 0 on Solaris and
      when unable to open the device in read-write mode.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@5720 7a7537e8-13f0-0310-91df-b6672ffda945

backend/runloop.c
backend/usb-unix.c

index 05692f1c74a80b97acba99b67acb7da8d617f1e0..6daf0f779ad9ac598f2fab5ec8418782ac1c4ca1 100644 (file)
@@ -53,6 +53,7 @@ backendRunLoop(int print_fd,          /* I - Print file descriptor */
                total_bytes,            /* Total bytes written */
                bytes;                  /* Bytes written */
   int          paperout;               /* "Paper out" status */
+  int          offline;                /* "Off-line" status */
   char         print_buffer[8192],     /* Print data buffer */
                *print_ptr,             /* Pointer into print data buffer */
                bc_buffer[1024];        /* Back-channel data buffer */
@@ -61,6 +62,9 @@ backendRunLoop(int print_fd,          /* I - Print file descriptor */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
 
 
+  fprintf(stderr, "DEBUG: backendRunLoop(print_fd=%d, device_fd=%d, use_bc=%d)\n",
+          print_fd, device_fd, use_bc);
+
  /*
   * If we are printing data from a print driver on stdin, ignore SIGTERM
   * so that the driver can finish out any page data, e.g. to eject the
@@ -93,7 +97,7 @@ backendRunLoop(int print_fd,          /* I - Print file descriptor */
   * Now loop until we are out of data from print_fd...
   */
 
-  for (print_bytes = 0, print_ptr = print_buffer, paperout = 0, total_bytes = 0;;)
+  for (print_bytes = 0, print_ptr = print_buffer, offline = 0, paperout = 0, total_bytes = 0;;)
   {
    /*
     * Use select() to determine whether we have data to copy around...
@@ -106,11 +110,35 @@ backendRunLoop(int print_fd,              /* I - Print file descriptor */
       FD_SET(device_fd, &input);
 
     FD_ZERO(&output);
-    if (print_bytes)
+    if (print_bytes || !use_bc)
       FD_SET(device_fd, &output);
 
-    if (select(nfds, &input, &output, NULL, NULL) < 0)
-      continue;                                /* Ignore errors here */
+    if (use_bc)
+    {
+      if (select(nfds, &input, &output, NULL, NULL) < 0)
+      {
+       /*
+       * Pause printing to clear any pending errors...
+       */
+
+       if (errno == ENXIO && !offline)
+       {
+         fputs("STATE: +offline-error\n", stderr);
+         fputs("INFO: Printer is currently off-line.\n", stderr);
+         offline = 1;
+       }
+
+       sleep(1);
+       continue;
+      }
+
+      if (offline)
+      {
+       fputs("STATE: -offline-error\n", stderr);
+       fputs("INFO: Printer is now on-line.\n", stderr);
+       offline = 0;
+      }
+    }
 
    /*
     * Check if we have back-channel data ready...
@@ -158,6 +186,9 @@ backendRunLoop(int print_fd,                /* I - Print file descriptor */
       }
 
       print_ptr = print_buffer;
+
+      fprintf(stderr, "DEBUG: Read %d bytes of print data...\n",
+              (int)print_bytes);
     }
 
    /*
@@ -196,7 +227,7 @@ backendRunLoop(int print_fd,                /* I - Print file descriptor */
          paperout = 0;
        }
 
-        fprintf(stderr, "DEBUG: Wrote %d bytes...\n", (int)bytes);
+        fprintf(stderr, "DEBUG: Wrote %d bytes of print data...\n", (int)bytes);
 
         print_bytes -= bytes;
        print_ptr   += bytes;
index 6c635b4764e1c41aa110333b56f534623bcfcb46..f62438274b3ac19dd9c1a4f4c9bc050753966fa3 100644 (file)
@@ -44,7 +44,7 @@
  * Local functions...
  */
 
-int    open_device(const char *uri);
+int    open_device(const char *uri, int *use_bc);
 
 
 /*
@@ -74,14 +74,6 @@ print_device(const char *uri,                /* I - Device URI */
   (void)argc;
   (void)argv;
 
- /*
-  * Disable backchannel data when printing to Canon USB printers - apparently
-  * Canon printers will return the IEEE-1284 device ID over and over and over
-  * when they get a read request...
-  */
-
-  use_bc = strcasecmp(hostname, "Canon") != 0;
-
  /*
   * Open the USB port device...
   */
@@ -90,7 +82,15 @@ print_device(const char *uri,                /* I - Device URI */
 
   do
   {
-    if ((device_fd = open_device(uri)) == -1)
+   /*
+    * Disable backchannel data when printing to Canon USB printers - apparently
+    * Canon printers will return the IEEE-1284 device ID over and over and over
+    * when they get a read request...
+    */
+
+    use_bc = strcasecmp(hostname, "Canon") != 0;
+
+    if ((device_fd = open_device(uri, &use_bc)) == -1)
     {
       if (getenv("CLASS") != NULL)
       {
@@ -195,7 +195,7 @@ print_device(const char *uri,               /* I - Device URI */
       lseek(print_fd, 0, SEEK_SET);
     }
 
-    tbytes = backendRunLoop(print_fd, device_fd, 1);
+    tbytes = backendRunLoop(print_fd, device_fd, use_bc);
 
     if (print_fd != 0 && tbytes >= 0)
       fprintf(stderr, "INFO: Sent print file, " CUPS_LLFMT " bytes...\n",
@@ -277,7 +277,7 @@ list_devices(void)
   {
     sprintf(device, "/dev/usb/printer%d", i);
 
-    if ((fd = open(device, O_RDWR | O_EXCL)) >= 0)
+    if ((fd = open(device, O_WRONLY | O_EXCL)) >= 0)
     {
       if (!backendGetDeviceID(fd, device_id, sizeof(device_id),
                               make_model, sizeof(make_model),
@@ -314,8 +314,12 @@ list_devices(void)
  */
 
 int                                    /* O - File descriptor or -1 on error */
-open_device(const char *uri)           /* I - Device URI */
+open_device(const char *uri,           /* I - Device URI */
+            int        *use_bc)                /* O - Set to 0 for unidirectional */
 {
+  int  fd;                             /* File descriptor */
+
+
  /*
   * The generic implementation just treats the URI as a device filename...
   * Specific operating systems may also support using the device serial
@@ -340,7 +344,6 @@ open_device(const char *uri)                /* I - Device URI */
 
     int                i;                      /* Looping var */
     int                busy;                   /* Are any ports busy? */
-    int                fd;                     /* File descriptor */
     char       format[255],            /* Format for device filename */
                device[255],            /* Device filename */
                device_id[1024],        /* Device ID string */
@@ -446,7 +449,6 @@ open_device(const char *uri)                /* I - Device URI */
 
     int                i;                      /* Looping var */
     int                busy;                   /* Are any ports busy? */
-    int                fd;                     /* File descriptor */
     char       device[255],            /* Device filename */
                device_id[1024],        /* Device ID string */
                make_model[1024],       /* Make and model */
@@ -463,7 +465,7 @@ open_device(const char *uri)                /* I - Device URI */
       {
        sprintf(device, "/dev/usb/printer%d", i);
 
-       if ((fd = open(device, O_RDWR | O_EXCL)) >= 0)
+       if ((fd = open(device, O_WRONLY | O_EXCL)) >= 0)
          backendGetDeviceID(fd, device_id, sizeof(device_id),
                              make_model, sizeof(make_model),
                             "usb", device_uri, sizeof(device_uri));
@@ -481,7 +483,17 @@ open_device(const char *uri)               /* I - Device URI */
         }
 
         if (!strcmp(uri, device_uri))
-         return (fd);  /* Yes, return this file descriptor... */
+       {
+        /*
+         * Yes, return this file descriptor...
+         */
+
+          fputs("DEBUG: Setting use_bc to 0!\n", stderr);
+
+          *use_bc = 0;
+
+         return (fd);
+       }
 
        /*
        * This wasn't the one...
@@ -514,7 +526,15 @@ open_device(const char *uri)               /* I - Device URI */
     return (-1);
   }
 #else
-    return (open(uri + 4, O_RDWR | O_EXCL));
+  {
+    if ((fd = open(uri + 4, O_RDWR | O_EXCL)) < 0)
+    {
+      fd      = open(uri + 4, O_WRONLY | O_EXCL);
+      *use_bc = 0;
+    }
+
+    return (fd);
+  }
 #endif /* __linux */
   else
   {