]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/ieee1394.c
cb623fff42ac0b0929e8a8645131adc689388cd4
4 * IEEE-1394 backend for the Common UNIX Printing System (CUPS).
6 * Copyright 2002 by Easy Software Products, all rights reserved.
8 * Redistribution and use in source and binary forms, with or
9 * without modification, are permitted provided that the
10 * following conditions are met:
12 * 1. Redistributions of source code must retain the above
13 * copyright notice, this list of conditions and the
14 * following disclaimer.
16 * 2. Redistributions in binary form must reproduce the
17 * above copyright notice, this list of conditions and
18 * the following disclaimer in the documentation and/or
19 * other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use
22 * of this software must display the following
25 * This product includes software developed by Easy
28 * 4. The name of Easy Software Products may not be used to
29 * endorse or promote products derived from this software
30 * without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS
33 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
34 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
37 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
43 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
49 * main() - Send a file to the printer.
50 * list_devices() - List all known printer devices...
54 * Include necessary headers.
64 void list_devices(void);
68 * 'main()' - Send a file to the printer.
72 * printer-uri job-id user title copies options [file]
75 int /* O - Exit status */
76 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
77 char *argv
[]) /* I - Command-line arguments */
79 ieee1394_dev_t dev
; /* Printer device */
80 int fp
; /* Print file */
81 int copies
; /* Number of copies to print */
82 int rbytes
; /* Number of bytes read from device */
83 size_t nbytes
, /* Number of bytes read from file */
84 tbytes
; /* Total number of bytes written */
85 char buffer
[8192]; /* Input/output buffer */
86 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
87 struct sigaction action
; /* Actions for POSIX signals */
88 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
92 * Make sure status messages are not buffered...
98 * Check command-line...
107 else if (argc
< 6 || argc
> 7)
109 fprintf(stderr
, "Usage: %s job-id user title copies options [file]\n",
115 * If we have 7 arguments, print the file named on the command-line.
116 * Otherwise, send stdin instead...
127 * Try to open the print file...
130 if ((fp
= open(argv
[6], O_RDONLY
)) < 0)
132 perror("ERROR: unable to open print file");
136 copies
= atoi(argv
[4]);
140 * Try to open the printer device...
143 fputs("STATE: +connecting-to-device\n", stderr
);
147 if ((dev
= ieee1394_open(argv
[0])) == NULL
)
149 fputs("INFO: Firewire printer busy; will retry in 30 seconds...\n", stderr
);
155 fputs("STATE: -connecting-to-device\n", stderr
);
158 * Now that we are "connected" to the port, ignore SIGTERM so that we
159 * can finish out any page data the driver sends (e.g. to eject the
160 * current page... Only ignore SIGTERM if we are printing data from
161 * stdin (otherwise you can't cancel raw jobs...)
166 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
167 sigset(SIGTERM
, SIG_IGN
);
168 #elif defined(HAVE_SIGACTION)
169 memset(&action
, 0, sizeof(action
));
171 sigemptyset(&action
.sa_mask
);
172 action
.sa_handler
= SIG_IGN
;
173 sigaction(SIGTERM
, &action
, NULL
);
175 signal(SIGTERM
, SIG_IGN
);
176 #endif /* HAVE_SIGSET */
180 * Finally, send the print file...
189 fputs("PAGE: 1 1\n", stderr
);
190 lseek(fp
, 0, SEEK_SET
);
194 while ((nbytes
= read(fp
, buffer
, sizeof(buffer
))) > 0)
197 * Write the print data to the printer...
202 if (ieee1394_write(dev
, buffer
, nbytes
) < 0)
204 perror("ERROR: Unable to send print file to printer");
208 if ((rbytes
= ieee1394_read(dev
, buffer
, sizeof(buffer
))) > 0)
209 fprintf(stderr
, "INFO: Read %d bytes from printer...\n", rbytes
);
212 fprintf(stderr
, "INFO: Sending print file, %lu bytes...\n",
213 (unsigned long)tbytes
);
218 * Close the printer device and input file and return...
226 fputs("INFO: Ready to print.\n", stderr
);
233 * 'list_devices()' - List all known devices...
239 int i
, /* Looping var */
240 num_info
; /* Number of devices */
241 ieee1394_info_t
*info
; /* Devices... */
245 * Get the available devices...
248 info
= ieee1394_list(&num_info
);
251 * List them as needed...
256 for (i
= 0; i
< num_info
; i
++)
257 printf("direct %s \"%s\" \"%s\"\n", info
[i
].uri
,
258 info
[i
].make_model
, info
[i
].description
);