]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/serial.c
Load cups into easysw/current.
[thirdparty/cups.git] / backend / serial.c
index 0e613b49057fb652e5474077bbf7001ccb3b11db..901df26590682a062738bd9bfa7614239b5f558d 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id$"
+ * "$Id: serial.c 6403 2007-03-27 16:00:56Z mike $"
  *
  *   Serial port backend for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
  *   property of Easy Software Products and are protected by Federal
@@ -27,6 +27,7 @@
  *
  *   main()         - Send a file to the printer or server.
  *   list_devices() - List all serial devices.
+ *   side_cb()      - Handle side-channel requests...
  */
 
 /*
@@ -91,7 +92,8 @@
  * Local functions...
  */
 
-void   list_devices(void);
+static void    list_devices(void);
+static void    side_cb(int print_fd, int device_fd, int use_bc);
 
 
 /*
@@ -168,7 +170,8 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
   }
   else if (argc < 6 || argc > 7)
   {
-    fputs("Usage: serial job-id user title copies options [file]\n", stderr);
+    fprintf(stderr, _("Usage: %s job-id user title copies options [file]\n"),
+           argv[0]);
     return (CUPS_BACKEND_FAILED);
   }
 
@@ -240,8 +243,8 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
        * available printer in the class.
        */
 
-        fputs("INFO: Unable to open serial port, queuing on next printer in class...\n",
-             stderr);
+        fputs(_("INFO: Unable to contact printer, queuing on next "
+               "printer in class...\n"), stderr);
 
        /*
         * Sleep 5 seconds to keep the job from requeuing too rapidly...
@@ -254,12 +257,12 @@ main(int  argc,                           /* I - Number of command-line arguments (6 or 7) */
 
       if (errno == EBUSY)
       {
-        fputs("INFO: Serial port busy; will retry in 30 seconds...\n", stderr);
+        fputs(_("INFO: Printer busy; will retry in 30 seconds...\n"), stderr);
        sleep(30);
       }
       else
       {
-       fprintf(stderr, "ERROR: Unable to open serial port device file \"%s\": %s\n",
+       fprintf(stderr, _("ERROR: Unable to open device file \"%s\": %s\n"),
                resource, strerror(errno));
        return (CUPS_BACKEND_FAILED);
       }
@@ -376,7 +379,8 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
              break;
 #  endif /* B230400 */
           default :
-             fprintf(stderr, "WARNING: Unsupported baud rate %s!\n", value);
+             fprintf(stderr, _("WARNING: Unsupported baud rate %s!\n"),
+                     value);
              break;
        }
 #endif /* B19200 == 19200 */
@@ -556,6 +560,7 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
       if (!print_bytes)
        FD_SET(print_fd, &input);
       FD_SET(device_fd, &input);
+      FD_SET(CUPS_SC_FD, &input);
 
       FD_ZERO(&output);
       if (print_bytes)
@@ -564,6 +569,13 @@ main(int  argc,                            /* I - Number of command-line arguments (6 or 7) */
       if (select(nfds, &input, &output, NULL, NULL) < 0)
        continue;                       /* Ignore errors here */
 
+     /*
+      * Check if we have a side-channel request ready...
+      */
+
+      if (FD_ISSET(CUPS_SC_FD, &input))
+        side_cb(print_fd, device_fd, 1);
+
      /*
       * Check if we have back-channel data ready...
       */
@@ -712,7 +724,7 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
  * 'list_devices()' - List all serial devices.
  */
 
-void
+static void
 list_devices(void)
 {
 #if defined(__hpux) || defined(__sgi) || defined(__sun) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
@@ -778,6 +790,14 @@ list_devices(void)
       printf("serial serial:%s?baud=230400 \"Unknown\" \"USB Serial Port #%d\"\n",
              device, i + 1);
     }
+
+    sprintf(device, "/dev/ttyUSB%d", i);
+    if ((fd = open(device, O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0)
+    {
+      close(fd);
+      printf("serial serial:%s?baud=230400 \"Unknown\" \"USB Serial Port #%d\"\n",
+             device, i + 1);
+    }
   }
 
   for (i = 0; i < 64; i ++)
@@ -1218,5 +1238,54 @@ list_devices(void)
 
 
 /*
- * End of "$Id$".
+ * 'side_cb()' - Handle side-channel requests...
+ */
+
+static void
+side_cb(int print_fd,                  /* I - Print file */
+        int device_fd,                 /* I - Device file */
+       int use_bc)                     /* I - Using back-channel? */
+{
+  cups_sc_command_t    command;        /* Request command */
+  cups_sc_status_t     status;         /* Request/response status */
+  char                 data[2048];     /* Request/response data */
+  int                  datalen;        /* Request/response data size */
+
+
+  datalen = sizeof(data);
+
+  if (cupsSideChannelRead(&command, &status, data, &datalen, 1.0))
+  {
+    fputs(_("WARNING: Failed to read side-channel request!\n"), stderr);
+    return;
+  }
+
+  switch (command)
+  {
+    case CUPS_SC_CMD_DRAIN_OUTPUT :
+        if (tcdrain(device_fd))
+         status = CUPS_SC_STATUS_IO_ERROR;
+       else
+         status = CUPS_SC_STATUS_OK;
+
+       datalen = 0;
+        break;
+
+    case CUPS_SC_CMD_GET_BIDI :
+        data[0] = use_bc;
+        datalen = 1;
+        break;
+
+    default :
+        status  = CUPS_SC_STATUS_NOT_IMPLEMENTED;
+       datalen = 0;
+       break;
+  }
+
+  cupsSideChannelWrite(command, status, data, datalen, 1.0);
+}
+
+
+/*
+ * End of "$Id: serial.c 6403 2007-03-27 16:00:56Z mike $".
  */