]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/ieee1394.c
2 * "$Id: ieee1394.c 6649 2007-07-11 21:46:42Z mike $"
4 * IEEE-1394 backend for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 2002 by Easy Software Products, all rights reserved.
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the
11 * following conditions are met:
13 * 1. Redistributions of source code must retain the above
14 * copyright notice, this list of conditions and the
15 * following disclaimer.
17 * 2. Redistributions in binary form must reproduce the
18 * above copyright notice, this list of conditions and
19 * the following disclaimer in the documentation and/or
20 * other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use
23 * of this software must display the following
26 * This product includes software developed by Easy
29 * 4. The name of Easy Software Products may not be used to
30 * endorse or promote products derived from this software
31 * without specific prior written permission.
33 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS
34 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
35 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
36 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
38 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
41 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
43 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
44 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
50 * main() - Send a file to the printer.
51 * list_devices() - List all known printer devices...
55 * Include necessary headers.
65 void list_devices(void);
69 * 'main()' - Send a file to the printer.
73 * printer-uri job-id user title copies options [file]
76 int /* O - Exit status */
77 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
78 char *argv
[]) /* I - Command-line arguments */
80 ieee1394_dev_t dev
; /* Printer device */
81 int fp
; /* Print file */
82 int copies
; /* Number of copies to print */
83 int rbytes
; /* Number of bytes read from device */
84 size_t nbytes
, /* Number of bytes read from file */
85 tbytes
; /* Total number of bytes written */
86 char buffer
[8192]; /* Input/output buffer */
87 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
88 struct sigaction action
; /* Actions for POSIX signals */
89 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
93 * Make sure status messages are not buffered...
99 * Check command-line...
108 else if (argc
< 6 || argc
> 7)
110 fprintf(stderr
, "Usage: %s job-id user title copies options [file]\n",
116 * If we have 7 arguments, print the file named on the command-line.
117 * Otherwise, send stdin instead...
128 * Try to open the print file...
131 if ((fp
= open(argv
[6], O_RDONLY
)) < 0)
133 perror("ERROR: unable to open print file");
137 copies
= atoi(argv
[4]);
141 * Try to open the printer device...
144 fputs("STATE: +connecting-to-device\n", stderr
);
148 if ((dev
= ieee1394_open(argv
[0])) == NULL
)
150 fputs("INFO: Firewire printer busy; will retry in 30 seconds...\n", stderr
);
156 fputs("STATE: -connecting-to-device\n", stderr
);
159 * Now that we are "connected" to the port, ignore SIGTERM so that we
160 * can finish out any page data the driver sends (e.g. to eject the
161 * current page... Only ignore SIGTERM if we are printing data from
162 * stdin (otherwise you can't cancel raw jobs...)
167 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
168 sigset(SIGTERM
, SIG_IGN
);
169 #elif defined(HAVE_SIGACTION)
170 memset(&action
, 0, sizeof(action
));
172 sigemptyset(&action
.sa_mask
);
173 action
.sa_handler
= SIG_IGN
;
174 sigaction(SIGTERM
, &action
, NULL
);
176 signal(SIGTERM
, SIG_IGN
);
177 #endif /* HAVE_SIGSET */
181 * Finally, send the print file...
190 fputs("PAGE: 1 1\n", stderr
);
191 lseek(fp
, 0, SEEK_SET
);
195 while ((nbytes
= read(fp
, buffer
, sizeof(buffer
))) > 0)
198 * Write the print data to the printer...
203 if (ieee1394_write(dev
, buffer
, nbytes
) < 0)
205 perror("ERROR: Unable to send print file to printer");
209 if ((rbytes
= ieee1394_read(dev
, buffer
, sizeof(buffer
))) > 0)
210 fprintf(stderr
, "INFO: Read %d bytes from printer...\n", rbytes
);
213 fprintf(stderr
, "INFO: Sending print file, %lu bytes...\n",
214 (unsigned long)tbytes
);
219 * Close the printer device and input file and return...
227 fputs("INFO: Ready to print.\n", stderr
);
234 * 'list_devices()' - List all known devices...
240 int i
, /* Looping var */
241 num_info
; /* Number of devices */
242 ieee1394_info_t
*info
; /* Devices... */
246 * Get the available devices...
249 info
= ieee1394_list(&num_info
);
252 * List them as needed...
257 for (i
= 0; i
< num_info
; i
++)
258 printf("direct %s \"%s\" \"%s\"\n", info
[i
].uri
,
259 info
[i
].make_model
, info
[i
].description
);
267 * End of "$Id: ieee1394.c 6649 2007-07-11 21:46:42Z mike $".