]> git.ipfire.org Git - thirdparty/cups.git/blob - doc/help/api-filter.html
Merge changes from CUPS 1.4svn-r7282.
[thirdparty/cups.git] / doc / help / api-filter.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
2 <html>
3 <!-- SECTION: Programming -->
4 <head>
5 <title>Filter and Backend Programming</title>
6 <meta name="keywords" content="Programming">
7 <meta name="creator" content="Mini-XML v2.5">
8 <style type="text/css"><!--
9 BODY {
10 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
11 }
12
13 H1, H2, H3, H4, H5, H6, P, TD, TH {
14 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
15 }
16
17 KBD {
18 font-family: monaco, courier, monospace;
19 font-weight: bold;
20 }
21
22 PRE {
23 font-family: monaco, courier, monospace;
24 }
25
26 PRE.command {
27 margin-left: 36pt;
28 }
29
30 PRE.example {
31 background: #eeeeee;
32 border: dotted thin #999999;
33 margin-left: 36pt;
34 padding: 10px;
35 }
36
37 PRE.command EM, PRE.example EM {
38 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
39 }
40
41 P.command {
42 font-family: monaco, courier, monospace;
43 margin-left: 36pt;
44 }
45
46 P.formula {
47 font-style: italic;
48 margin-left: 36pt;
49 }
50
51 BLOCKQUOTE {
52 background: #cccccc;
53 border: solid thin #999999;
54 padding: 10pt;
55 }
56
57 A:link, A:visited {
58 text-decoration: none;
59 font-weight: bold;
60 }
61
62 A:link:hover, A:visited:hover, A:active {
63 text-decoration: underline;
64 font-weight: bold;
65 }
66
67 SUB, SUP {
68 font-size: 50%;
69 }
70
71 DIV.table TABLE {
72 border: solid thin #999999;
73 border-collapse: collapse;
74 border-spacing: 0;
75 margin-left: auto;
76 margin-right: auto;
77 }
78
79 DIV.table CAPTION {
80 caption-side: top;
81 font-size: 120%;
82 font-style: italic;
83 font-weight: bold;
84 margin-left: auto;
85 margin-right: auto;
86 }
87
88 DIV.table TABLE TD {
89 border: solid thin #cccccc;
90 padding-top: 5pt;
91 }
92
93 DIV.table TABLE TH {
94 background: #cccccc;
95 border: none;
96 border-bottom: solid thin #999999;
97 }
98
99 DIV.figure TABLE {
100 margin-left: auto;
101 margin-right: auto;
102 }
103
104 DIV.figure CAPTION {
105 caption-side: bottom;
106 font-size: 120%;
107 font-style: italic;
108 font-weight: bold;
109 margin-left: auto;
110 margin-right: auto;
111 }
112
113 TH.label {
114 padding-top: 5pt;
115 text-align: right;
116 vertical-align: top;
117 }
118
119 HR {
120 border: solid thin;
121 }
122
123 SPAN.info {
124 background: #000000;
125 border: thin solid #000000;
126 color: #ffffff;
127 font-size: 80%;
128 font-style: italic;
129 font-weight: bold;
130 white-space: nowrap;
131 }
132
133 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
134 float: right;
135 font-size: 100%;
136 }
137
138 H2.title, H3.title {
139 border-bottom: solid 2pt #000000;
140 }
141
142 DT {
143 margin-left: 36pt;
144 margin-top: 12pt;
145 }
146
147 DD {
148 margin-left: 54pt;
149 }
150
151 DL.category DT {
152 font-weight: bold;
153 }
154
155 P.summary {
156 margin-left: 36pt;
157 font-family: monaco, courier, monospace;
158 }
159
160 SPAN.message {
161 font-style: italic;
162 font-size: smaller;
163 }
164
165 DIV.summary TABLE {
166 border: solid thin #999999;
167 border-collapse: collapse;
168 border-spacing: 0;
169 margin: 10px;
170 }
171
172 DIV.summary TABLE TD, DIV.summary TABLE TH {
173 border: solid thin #999999;
174 padding: 5px;
175 text-align: left;
176 vertical-align: top;
177 }
178
179 DIV.summary TABLE THEAD TH {
180 background: #eeeeee;
181 }
182
183 /* API documentation styles... */
184 div.body h1 {
185 margin: 0;
186 }
187 div.body h2 {
188 margin-top: 1.5em;
189 }
190 div.body h3, div.body h4, div.body h5 {
191 margin-bottom: 0.5em;
192 margin-top: 1.5em;
193 }
194 .class, .enumeration, .function, .struct, .typedef, .union {
195 border-bottom: solid thin #999999;
196 margin-bottom: 0;
197 margin-top: 2em;
198 }
199 .description {
200 margin-top: 0.5em;
201 }
202 code, p.code, pre, ul.code li {
203 font-family: monaco, courier, monospace;
204 font-size: 90%;
205 }
206 ul.code, ul.contents, ul.subcontents {
207 list-style-type: none;
208 margin: 0;
209 padding-left: 0;
210 }
211 ul.code li {
212 margin: 0;
213 }
214 ul.contents > li {
215 margin-top: 1em;
216 }
217 ul.contents li ul.code, ul.contents li ul.subcontents {
218 padding-left: 2em;
219 }
220 div.body dl {
221 margin-left: 0;
222 margin-top: 0;
223 }
224 div.body dt {
225 font-style: italic;
226 margin-left: 0;
227 margin-top: 0;
228 }
229 div.body dd {
230 margin-bottom: 0.5em;
231 }
232
233 /* This is just for the HTML files generated with the framedhelp target */
234 div.contents {
235 background: #e8e8e8;
236 border: solid thin black;
237 padding: 10px;
238 }
239 div.contents h1 {
240 font-size: 110%;
241 }
242 div.contents h2 {
243 font-size: 100%;
244 }
245 div.contents ul.contents {
246 font-size: 80%;
247 }
248 --></style>
249 </head>
250 <body>
251 <div class='body'>
252 <!--
253 "$Id: api-cups.header 7279 2008-01-31 01:50:44Z mike $"
254
255 Filter and backend programming header for the Common UNIX Printing System
256 (CUPS).
257
258 Copyright 2008 by Apple Inc.
259
260 These coded instructions, statements, and computer programs are the
261 property of Apple Inc. and are protected by Federal copyright
262 law. Distribution and use rights are outlined in the file "LICENSE.txt"
263 which should have been included with this file. If this file is
264 file is missing or damaged, see the license at "http://www.cups.org/".
265 -->
266
267 <h1 class="title">Filter and Backend Programming</h1>
268
269 <div class='summary'><table summary='General Information'>
270 <thead>
271 <tr>
272 <th>Header</th>
273 <th>cups/backend.h<br>
274 cups/sidechannel.h</th>
275 </tr>
276 </thead>
277 <tbody>
278 <tr>
279 <th>Library</th>
280 <td>-lcups</td>
281 </tr>
282 <tr>
283 <th>See Also</th>
284 <td>Programming: <a href='api-overview.html' target='_top'>Introduction to CUPS Programming</a><br>
285 Programming: <a href='api-cups.html' target='_top'>CUPS API</a><br>
286 Programming: <a href='api-ppd.html' target='_top'>PPD API</a><br>
287 Programming: <a href='api-raster.html' target='_top'>Raster API</a></td>
288 </tr>
289 </tbody>
290 </table></div>
291 <h2 class="title">Contents</h2>
292 <ul class="contents">
293 </li>
294 <li><a href="#OVERVIEW">Overview</a><ul class="subcontents">
295 <li><a href="#EXITCODES">Exit Codes</a></li>
296 <li><a href="#ENVIRONMENT">Environment Variables</a></li>
297 <li><a href="#MESSAGES">Communicating with the Scheduler</a></li>
298 <li><a href="#COMMUNICATING">Communicating with the Backend</a></li>
299 </ul></li>
300 <li><a href="#FUNCTIONS">Functions</a><ul class="code">
301 <li><a href="#cupsBackChannelRead" title="Read data from the backchannel.">cupsBackChannelRead</a></li>
302 <li><a href="#cupsBackChannelWrite" title="Write data to the backchannel.">cupsBackChannelWrite</a></li>
303 <li><a href="#cupsSideChannelDoRequest" title="Send a side-channel command to a backend and wait for a response.">cupsSideChannelDoRequest</a></li>
304 <li><a href="#cupsSideChannelRead" title="Read a side-channel message.">cupsSideChannelRead</a></li>
305 <li><a href="#cupsSideChannelWrite" title="Write a side-channel message.">cupsSideChannelWrite</a></li>
306 </ul>
307 <li><a href="#TYPES">Data Types</a><ul class="code">
308 <li><a href="#cups_backend_t" title="Backend exit codes">cups_backend_t</a></li>
309 <li><a href="#cups_sc_bidi_t" title="Bidirectional capabilities">cups_sc_bidi_t</a></li>
310 <li><a href="#cups_sc_command_t" title="Request command codes">cups_sc_command_t</a></li>
311 <li><a href="#cups_sc_state_t" title="Printer state bits">cups_sc_state_t</a></li>
312 <li><a href="#cups_sc_status_t" title="Response status codes">cups_sc_status_t</a></li>
313 </ul></li>
314 <li><a href="#ENUMERATIONS">Constants</a><ul class="code">
315 <li><a href="#cups_backend_e" title="Backend exit codes">cups_backend_e</a></li>
316 <li><a href="#cups_sc_bidi_e" title="Bidirectional capabilities">cups_sc_bidi_e</a></li>
317 <li><a href="#cups_sc_command_e" title="Request command codes">cups_sc_command_e</a></li>
318 <li><a href="#cups_sc_state_e" title="Printer state bits">cups_sc_state_e</a></li>
319 <li><a href="#cups_sc_status_e" title="Response status codes">cups_sc_status_e</a></li>
320 </ul></li>
321 </ul>
322 <!--
323 "$Id: api-filter.shtml 6649 2007-07-11 21:46:42Z mike $"
324
325 Filter and backend programming introduction for the Common UNIX Printing
326 System (CUPS).
327
328 Copyright 2007-2008 by Apple Inc.
329 Copyright 1997-2006 by Easy Software Products, all rights reserved.
330
331 These coded instructions, statements, and computer programs are the
332 property of Apple Inc. and are protected by Federal copyright
333 law. Distribution and use rights are outlined in the file "LICENSE.txt"
334 which should have been included with this file. If this file is
335 file is missing or damaged, see the license at "http://www.cups.org/".
336 -->
337
338 <h2 class='title'><a name="OVERVIEW">Overview</a></h2>
339
340 <p>Filters, printer drivers, port monitors, and backends use a common interface
341 for processing print jobs and communicating status information to the scheduler.
342 Each filter is run with a standard set of command-line arguments:<p>
343
344 <dl class="code">
345
346 <dt>argv[1]</dt>
347 <dd>The job ID</dd>
348
349 <dt>argv[2]</dt>
350 <dd>The user printing the job</dd>
351
352 <dt>argv[3]</dt>
353 <dd>The job name/title</dd>
354
355 <dt>argv[4]</dt>
356 <dd>The number of copies to print</dd>
357
358 <dt>argv[5]</dt>
359 <dd>The options that were provided when the job was submitted</dd>
360
361 <dt>argv[6]</dt>
362 <dd>The file to print (first filter only)</dd>
363 </dl>
364
365 <p>The scheduler runs one or more of these programs to print any given job. The
366 first filter reads from the print file and writes to the standard output, while
367 the remaining filters read from the standard input and write to the standard
368 output. The backend is the last filter in the chain and writes to the
369 device.</p>
370
371 <h3><a name="EXITCODES">Exit Codes</a></h3>
372
373 <p>Filters must exit with status 0 when they successfully generate print data
374 or 1 when they encounter an error. Backends can return any of the
375 <a href="#cups_backend_t"><code>cups_backend_t</code></a> constants.</p>
376
377 <h3><a name="ENVIRONMENT">Environment Variables</a></h3>
378
379 <p>The following environment variables are defined by the printing system:</p>
380
381 <dl class="code">
382
383 <dt>APPLE_LANGUAGES</dt>
384 <dd>The Apple language identifier associated with the job
385 (Mac OS X only).</dd>
386
387 <dt>CHARSET</dt>
388 <dd>The job character set, typically "utf-8".</dd>
389
390 <dt>CLASS</dt>
391 <dd>When a job is submitted to a printer class, contains the name of
392 the destination printer class. Otherwise this environment
393 variable will not be set.</dd>
394
395 <dt>CONTENT_TYPE</dt>
396 <dd>The MIME type associated with the file (e.g.
397 application/postscript).</dd>
398
399 <dt>CUPS_CACHEDIR</dt>
400 <dd>The directory where cache files can be stored.</dd>
401
402 <dt>CUPS_DATADIR</dt>
403 <dd>The directory where data files can be found.</dd>
404
405 <dt>CUPS_SERVERROOT</dt>
406 <dd>The root directory of the server.</dd>
407
408 <dt>DEVICE_URI</dt>
409 <dd>The device-uri associated with the printer.</dd>
410
411 <dt>FINAL_CONTENT_TYPE</dt>
412 <dd>The MIME type associated with the printer (e.g.
413 application/vnd.cups-postscript).</dd>
414
415 <dt>LANG</dt>
416 <dd>The language locale associated with the job.</dd>
417
418 <dt>PPD</dt>
419 <dd>The full pathname of the PostScript Printer Description (PPD)
420 file for this printer.</dd>
421
422 <dt>PRINTER</dt>
423 <dd>The name of the printer.</dd>
424
425 <dt>RIP_CACHE</dt>
426 <dd>The recommended amount of memory to use for Raster Image
427 Processors (RIPs).</dd>
428
429 </dl>
430
431 <h3><a name="MESSAGES">Communicating with the Scheduler</a></h3>
432
433 <p>Filters and backends communicate wih the scheduler by writing messages
434 to the standard error file. For example, the following code sets the current
435 printer state message to "Printing page 5":</p>
436
437 <pre class="example">
438 int page = 5;
439
440 fprintf(stderr, "INFO: Printing page %d\n", page);
441 </pre>
442
443 <p>Each message is a single line of text starting with one of the following
444 prefix strings:</p>
445
446 <dl class="code">
447
448 <dt>ALERT: message</dt>
449 <dd>Sets the printer-state-message attribute and adds the specified
450 message to the current error log file using the "alert" log level.</dd>
451
452 <dt>ATTR: attribute=value [attribute=value]</dt>
453 <dd>Sets the named printer or job attribute(s). Typically this is used
454 to set the <code>marker-colors</code>, <code>marker-levels</code>,
455 <code>marker-names</code>, <code>marker-types</code>,
456 <code>printer-alert</code>, and <code>printer-alert-description</code>
457 printer attributes.</dd>
458
459 <dt>CRIT: message</dt>
460 <dd>Sets the printer-state-message attribute and adds the specified
461 message to the current error log file using the "critical" log
462 level.</dd>
463
464 <dt>DEBUG: message</dt>
465 <dd>Sets the printer-state-message attribute and adds the specified
466 message to the current error log file using the "debug" log level.</dd>
467
468 <dt>DEBUG2: message</dt>
469 <dd>Sets the printer-state-message attribute and adds the specified
470 message to the current error log file using the "debug2" log level.</dd>
471
472 <dt>EMERG: message</dt>
473 <dd>Sets the printer-state-message attribute and adds the specified
474 message to the current error log file using the "emergency" log
475 level.</dd>
476
477 <dt>ERROR: message</dt>
478 <dd>Sets the printer-state-message attribute and adds the specified
479 message to the current error log file using the "error" log level.</dd>
480
481 <dt>INFO: message</dt>
482 <dd>Sets the printer-state-message attribute. If the current log level
483 is set to "debug2", also adds the specified message to the current error
484 log file using the "info" log level.</dd>
485
486 <dt>NOTICE: message</dt>
487 <dd>Sets the printer-state-message attribute and adds the specified
488 message to the current error log file using the "notice" log level.</dd>
489
490 <dt>PAGE: page-number #-copies</dt>
491 <dt>PAGE: total #-pages</dt>
492 <dd>Adds an entry to the current page log file. The first form adds
493 #-copies to the job-media-sheets-completed attribute. The second
494 form sets the job-media-sheets-completed attribute to #-pages.</dd>
495
496 <dt>STATE: printer-state-reason [printer-state-reason ...]</dt>
497 <dt>STATE: + printer-state-reason [printer-state-reason ...]</dt>
498 <dt>STATE: - printer-state-reason [printer-state-reason ...]</dt>
499 <dd>Sets, adds, or removes printer-state-reason keywords to the
500 current queue. Typically this is used to indicate media, ink, and
501 toner conditions on a printer.</dd>
502
503 <dt>WARNING: message</dt>
504 <dd>Sets the printer-state-message attribute and adds the specified
505 message to the current error log file using the "warning" log
506 level.</dd>
507
508 </dl>
509
510 <p>Messages without one of these prefixes are treated as if they began with
511 the "DEBUG:" prefix string.</p>
512
513 <h3><a name="COMMUNICATING">Communicating with the Backend</a></h3>
514
515 <p>Filters can communicate with the backend via the
516 <a href="#cupsBackChannelRead"><code>cupsBackChannelRead</code></a> and
517 <a href="#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest</code></a>
518 functions. The
519 <a href="#cupsBackChannelRead"><code>cupsBackChannelRead</code></a> function
520 reads data that has been sent back from the device and is typically used to
521 obtain status and configuration information. For example, the following code
522 polls the backend for back-channel data:</p>
523
524 <pre class="example">
525 #include &lt;cups/cups.h&gt;
526
527 char buffer[8192];
528 ssize_t bytes;
529
530 /* Use a timeout of 0.0 seconds to poll for back-channel data */
531 bytes = cupsBackChannelRead(buffer, sizeof(buffer), 0.0);
532 </pre>
533
534 The
535 <a href="#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest</code></a>
536 function allows you to get out-of-band status information and do synchronization
537 with the device. For example, the following code gets the current IEEE-1284
538 device ID string from the backend:</p>
539
540 <pre class="example">
541 #include &lt;cups/sidechannel.h&gt;
542
543 char data[2049];
544 int datalen;
545 <a href="#cups_sc_status_t">cups_sc_status_t</a> status;
546
547 /* Tell cupsSideChannelDoRequest() how big our buffer is, less 1 byte for nul-termination... */
548 datalen = sizeof(data) - 1;
549
550 /* Get the IEEE-1284 device ID, waiting for up to 1 second */
551 status = <a href="#cupsSideChannelDoRequest">cupsSideChannelDoRequest</a>(CUPS_SC_CMD_GET_DEVICE_ID, data, &amp;datalen, 1.0);
552
553 /* Use the returned value if OK was returned and the length is non-zero */
554 if (status == CUPS_SC_STATUS_OK && datalen > 0)
555 data[datalen] = '\0';
556 else
557 data[0] = '\0';
558 </pre>
559
560 <p>Backends communicate with filters using the reciprocal functions
561 <a href="#cupsBackChannelWrite"><code>cupsBackChannelWrite</code></a>,
562 <a href="#cupsSideChannelRead"><code>cupsSideChannelRead</code></a>, and
563 <a href="#cupsSideChannelWrite"><code>cupsSideChannelWrite</code></a>. We
564 recommend writing back-channel data using a timeout of 1.0 seconds:</p>
565
566 <pre class="example">
567 #include &lt;cups/cups.h&gt;
568
569 char buffer[8192];
570 ssize_t bytes;
571
572 /* Use a timeout of 1.0 seconds to give filters a chance to read */
573 cupsBackChannelWrite(buffer, bytes, 1.0);
574 </pre>
575
576 <p>The <a href="#cupsSideChannelRead"><code>cupsSideChannelRead</code></a>
577 function reads a side-channel command from a filter, driver, or port monitor.
578 Backends can either poll for commands using a <code>timeout</code> of 0.0, wait
579 indefinitely for commands using a <code>timeout</code> of -1.0 (probably in a
580 separate thread for that purpose), or use <code>select</code> or
581 <code>poll</code> on the <code>CUPS_SC_FD</code> file descriptor (4) to handle
582 input and output on several file descriptors at the same time. Backends can pass
583 <code>NULL</code> for the <code>data</code> and <code>datalen</code> parameters
584 since none of the commands sent by upstream filters contain any data at this
585 time.</p>
586
587 <p>Once a command is processed, the backend uses the
588 <a href="#cupsSideChannelWrite"><code>cupsSideChannelWrite</code></a> function
589 to send its response. For example, the following code shows how to poll for a
590 side-channel command and respond to it:</p>
591
592 <pre class="example">
593 #include &lt;cups/sidechannel.h&gt;
594
595 <a href="#cups_sc_command_t">cups_sc_command_t</a> command;
596 <a href="#cups_sc_status_t">cups_sc_status_t</a> status;
597
598 /* Poll for a command... */
599 if (!<a href="#cupsSideChannelRead">cupsSideChannelRead</a>(&amp;command, &amp;status, NULL, NULL, 0.0))
600 {
601 char data[2048];
602 int datalen;
603
604 switch (command)
605 {
606 /* handle supported commands, file data/datalen/status with values as needed */
607
608 default :
609 status = CUPS_SC_STATUS_NOT_IMPLEMENTED;
610 datalen = 0;
611 break;
612 }
613
614 /* Send a response... */
615 <a href="#cupsSideChannelWrite">cupsSideChannelWrite</a>(command, status, data, datalen, 1.0);
616 }
617 </pre>
618 <h2 class="title"><a name="FUNCTIONS">Functions</a></h2>
619 <h3 class="function"><span class="info">&nbsp;CUPS 1.2&nbsp;</span><a name="cupsBackChannelRead">cupsBackChannelRead</a></h3>
620 <p class="description">Read data from the backchannel.</p>
621 <p class="code">
622 ssize_t cupsBackChannelRead (<br>
623 &nbsp;&nbsp;&nbsp;&nbsp;char *buffer,<br>
624 &nbsp;&nbsp;&nbsp;&nbsp;size_t bytes,<br>
625 &nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
626 );</p>
627 <h4 class="parameters">Parameters</h4>
628 <dl>
629 <dt>buffer</dt>
630 <dd class="description">Buffer to read</dd>
631 <dt>bytes</dt>
632 <dd class="description">Bytes to read</dd>
633 <dt>timeout</dt>
634 <dd class="description">Timeout in seconds</dd>
635 </dl>
636 <h4 class="returnvalue">Return Value</h4>
637 <p class="description">Bytes read or -1 on error</p>
638 <h4 class="discussion">Discussion</h4>
639 <p class="discussion">Reads up to &quot;bytes&quot; bytes from the backchannel. The &quot;timeout&quot;
640 parameter controls how many seconds to wait for the data - use
641 0.0 to return immediately if there is no data, -1.0 to wait
642 for data indefinitely.
643
644 </p>
645 <h3 class="function"><span class="info">&nbsp;CUPS 1.2&nbsp;</span><a name="cupsBackChannelWrite">cupsBackChannelWrite</a></h3>
646 <p class="description">Write data to the backchannel.</p>
647 <p class="code">
648 ssize_t cupsBackChannelWrite (<br>
649 &nbsp;&nbsp;&nbsp;&nbsp;const char *buffer,<br>
650 &nbsp;&nbsp;&nbsp;&nbsp;size_t bytes,<br>
651 &nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
652 );</p>
653 <h4 class="parameters">Parameters</h4>
654 <dl>
655 <dt>buffer</dt>
656 <dd class="description">Buffer to write</dd>
657 <dt>bytes</dt>
658 <dd class="description">Bytes to write</dd>
659 <dt>timeout</dt>
660 <dd class="description">Timeout in seconds</dd>
661 </dl>
662 <h4 class="returnvalue">Return Value</h4>
663 <p class="description">Bytes written or -1 on error</p>
664 <h4 class="discussion">Discussion</h4>
665 <p class="discussion">Writes &quot;bytes&quot; bytes to the backchannel. The &quot;timeout&quot; parameter
666 controls how many seconds to wait for the data to be written - use
667 0.0 to return immediately if the data cannot be written, -1.0 to wait
668 indefinitely.
669
670 </p>
671 <h3 class="function"><span class="info">&nbsp;CUPS 1.3&nbsp;</span><a name="cupsSideChannelDoRequest">cupsSideChannelDoRequest</a></h3>
672 <p class="description">Send a side-channel command to a backend and wait for a response.</p>
673 <p class="code">
674 <a href="#cups_sc_status_t">cups_sc_status_t</a> cupsSideChannelDoRequest (<br>
675 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_command_t">cups_sc_command_t</a> command,<br>
676 &nbsp;&nbsp;&nbsp;&nbsp;char *data,<br>
677 &nbsp;&nbsp;&nbsp;&nbsp;int *datalen,<br>
678 &nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
679 );</p>
680 <h4 class="parameters">Parameters</h4>
681 <dl>
682 <dt>command</dt>
683 <dd class="description">Command to send</dd>
684 <dt>data</dt>
685 <dd class="description">Response data buffer pointer</dd>
686 <dt>datalen</dt>
687 <dd class="description">Size of data buffer on entry, number of bytes in buffer on return</dd>
688 <dt>timeout</dt>
689 <dd class="description">Timeout in seconds</dd>
690 </dl>
691 <h4 class="returnvalue">Return Value</h4>
692 <p class="description">Status of command</p>
693 <h4 class="discussion">Discussion</h4>
694 <p class="discussion">This function is normally only called by filters, drivers, or port
695 monitors in order to communicate with the backend used by the current
696 printer. Programs must be prepared to handle timeout or &quot;not
697 implemented&quot; status codes, which indicate that the backend or device
698 do not support the specified side-channel command.<br>
699 <br>
700 The &quot;datalen&quot; parameter must be initialized to the size of the buffer
701 pointed to by the &quot;data&quot; parameter. cupsSideChannelDoRequest() will
702 update the value to contain the number of data bytes in the buffer.
703
704 </p>
705 <h3 class="function"><span class="info">&nbsp;CUPS 1.3&nbsp;</span><a name="cupsSideChannelRead">cupsSideChannelRead</a></h3>
706 <p class="description">Read a side-channel message.</p>
707 <p class="code">
708 int cupsSideChannelRead (<br>
709 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_command_t">cups_sc_command_t</a> *command,<br>
710 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_status_t">cups_sc_status_t</a> *status,<br>
711 &nbsp;&nbsp;&nbsp;&nbsp;char *data,<br>
712 &nbsp;&nbsp;&nbsp;&nbsp;int *datalen,<br>
713 &nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
714 );</p>
715 <h4 class="parameters">Parameters</h4>
716 <dl>
717 <dt>command</dt>
718 <dd class="description">Command code</dd>
719 <dt>status</dt>
720 <dd class="description">Status code</dd>
721 <dt>data</dt>
722 <dd class="description">Data buffer pointer</dd>
723 <dt>datalen</dt>
724 <dd class="description">Size of data buffer on entry, number of bytes in buffer on return</dd>
725 <dt>timeout</dt>
726 <dd class="description">Timeout in seconds</dd>
727 </dl>
728 <h4 class="returnvalue">Return Value</h4>
729 <p class="description">0 on success, -1 on error</p>
730 <h4 class="discussion">Discussion</h4>
731 <p class="discussion">This function is normally only called by backend programs to read
732 commands from a filter, driver, or port monitor program. The
733 caller must be prepared to handle incomplete or invalid messages
734 and return the corresponding status codes.<br>
735 <br>
736 The &quot;datalen&quot; parameter must be initialized to the size of the buffer
737 pointed to by the &quot;data&quot; parameter. cupsSideChannelDoRequest() will
738 update the value to contain the number of data bytes in the buffer.
739
740 </p>
741 <h3 class="function"><span class="info">&nbsp;CUPS 1.3&nbsp;</span><a name="cupsSideChannelWrite">cupsSideChannelWrite</a></h3>
742 <p class="description">Write a side-channel message.</p>
743 <p class="code">
744 int cupsSideChannelWrite (<br>
745 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_command_t">cups_sc_command_t</a> command,<br>
746 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#cups_sc_status_t">cups_sc_status_t</a> status,<br>
747 &nbsp;&nbsp;&nbsp;&nbsp;const char *data,<br>
748 &nbsp;&nbsp;&nbsp;&nbsp;int datalen,<br>
749 &nbsp;&nbsp;&nbsp;&nbsp;double timeout<br>
750 );</p>
751 <h4 class="parameters">Parameters</h4>
752 <dl>
753 <dt>command</dt>
754 <dd class="description">Command code</dd>
755 <dt>status</dt>
756 <dd class="description">Status code</dd>
757 <dt>data</dt>
758 <dd class="description">Data buffer pointer</dd>
759 <dt>datalen</dt>
760 <dd class="description">Number of bytes of data</dd>
761 <dt>timeout</dt>
762 <dd class="description">Timeout in seconds</dd>
763 </dl>
764 <h4 class="returnvalue">Return Value</h4>
765 <p class="description">0 on success, -1 on error</p>
766 <h4 class="discussion">Discussion</h4>
767 <p class="discussion">This function is normally only called by backend programs to send
768 responses to a filter, driver, or port monitor program.
769
770 </p>
771 <h2 class="title"><a name="TYPES">Data Types</a></h2>
772 <h3 class="typedef"><a name="cups_backend_t">cups_backend_t</a></h3>
773 <p class="description">Backend exit codes</p>
774 <p class="code">
775 typedef enum <a href="#cups_backend_e">cups_backend_e</a> cups_backend_t;
776 </p>
777 <h3 class="typedef"><a name="cups_sc_bidi_t">cups_sc_bidi_t</a></h3>
778 <p class="description">Bidirectional capabilities</p>
779 <p class="code">
780 typedef enum <a href="#cups_sc_bidi_e">cups_sc_bidi_e</a> cups_sc_bidi_t;
781 </p>
782 <h3 class="typedef"><a name="cups_sc_command_t">cups_sc_command_t</a></h3>
783 <p class="description">Request command codes</p>
784 <p class="code">
785 typedef enum <a href="#cups_sc_command_e">cups_sc_command_e</a> cups_sc_command_t;
786 </p>
787 <h3 class="typedef"><a name="cups_sc_state_t">cups_sc_state_t</a></h3>
788 <p class="description">Printer state bits</p>
789 <p class="code">
790 typedef enum <a href="#cups_sc_state_e">cups_sc_state_e</a> cups_sc_state_t;
791 </p>
792 <h3 class="typedef"><a name="cups_sc_status_t">cups_sc_status_t</a></h3>
793 <p class="description">Response status codes</p>
794 <p class="code">
795 typedef enum <a href="#cups_sc_status_e">cups_sc_status_e</a> cups_sc_status_t;
796 </p>
797 <h2 class="title"><a name="ENUMERATIONS">Constants</a></h2>
798 <h3 class="enumeration"><a name="cups_backend_e">cups_backend_e</a></h3>
799 <p class="description">Backend exit codes</p>
800 <h4 class="constants">Constants</h4>
801 <dl>
802 <dt>CUPS_BACKEND_AUTH_REQUIRED </dt>
803 <dd class="description">Job failed, authentication required</dd>
804 <dt>CUPS_BACKEND_CANCEL </dt>
805 <dd class="description">Job failed, cancel job</dd>
806 <dt>CUPS_BACKEND_FAILED </dt>
807 <dd class="description">Job failed, use error-policy</dd>
808 <dt>CUPS_BACKEND_HOLD </dt>
809 <dd class="description">Job failed, hold job</dd>
810 <dt>CUPS_BACKEND_OK </dt>
811 <dd class="description">Job completed successfully</dd>
812 <dt>CUPS_BACKEND_STOP </dt>
813 <dd class="description">Job failed, stop queue</dd>
814 </dl>
815 <h3 class="enumeration"><a name="cups_sc_bidi_e">cups_sc_bidi_e</a></h3>
816 <p class="description">Bidirectional capabilities</p>
817 <h4 class="constants">Constants</h4>
818 <dl>
819 <dt>CUPS_SC_BIDI_NOT_SUPPORTED </dt>
820 <dd class="description">Bidirectional I/O is not supported</dd>
821 <dt>CUPS_SC_BIDI_SUPPORTED </dt>
822 <dd class="description">Bidirectional I/O is supported</dd>
823 </dl>
824 <h3 class="enumeration"><a name="cups_sc_command_e">cups_sc_command_e</a></h3>
825 <p class="description">Request command codes</p>
826 <h4 class="constants">Constants</h4>
827 <dl>
828 <dt>CUPS_SC_CMD_DRAIN_OUTPUT </dt>
829 <dd class="description">Drain all pending output</dd>
830 <dt>CUPS_SC_CMD_GET_BIDI </dt>
831 <dd class="description">Return bidirectional capabilities</dd>
832 <dt>CUPS_SC_CMD_GET_DEVICE_ID </dt>
833 <dd class="description">Return the IEEE-1284 device ID</dd>
834 <dt>CUPS_SC_CMD_GET_STATE </dt>
835 <dd class="description">Return the device state</dd>
836 <dt>CUPS_SC_CMD_SOFT_RESET </dt>
837 <dd class="description">Do a soft reset</dd>
838 </dl>
839 <h3 class="enumeration"><a name="cups_sc_state_e">cups_sc_state_e</a></h3>
840 <p class="description">Printer state bits</p>
841 <h4 class="constants">Constants</h4>
842 <dl>
843 <dt>CUPS_SC_STATE_BUSY </dt>
844 <dd class="description">Device is busy</dd>
845 <dt>CUPS_SC_STATE_ERROR </dt>
846 <dd class="description">Other error condition</dd>
847 <dt>CUPS_SC_STATE_MARKER_EMPTY </dt>
848 <dd class="description">Toner/ink out condition</dd>
849 <dt>CUPS_SC_STATE_MARKER_LOW </dt>
850 <dd class="description">Toner/ink low condition</dd>
851 <dt>CUPS_SC_STATE_MEDIA_EMPTY </dt>
852 <dd class="description">Paper out condition</dd>
853 <dt>CUPS_SC_STATE_MEDIA_LOW </dt>
854 <dd class="description">Paper low condition</dd>
855 <dt>CUPS_SC_STATE_OFFLINE </dt>
856 <dd class="description">Device is off-line</dd>
857 <dt>CUPS_SC_STATE_ONLINE </dt>
858 <dd class="description">Device is on-line</dd>
859 </dl>
860 <h3 class="enumeration"><a name="cups_sc_status_e">cups_sc_status_e</a></h3>
861 <p class="description">Response status codes</p>
862 <h4 class="constants">Constants</h4>
863 <dl>
864 <dt>CUPS_SC_STATUS_BAD_MESSAGE </dt>
865 <dd class="description">The command/response message was invalid</dd>
866 <dt>CUPS_SC_STATUS_IO_ERROR </dt>
867 <dd class="description">An I/O error occurred</dd>
868 <dt>CUPS_SC_STATUS_NONE </dt>
869 <dd class="description">No status</dd>
870 <dt>CUPS_SC_STATUS_NOT_IMPLEMENTED </dt>
871 <dd class="description">Command not implemented</dd>
872 <dt>CUPS_SC_STATUS_NO_RESPONSE </dt>
873 <dd class="description">The device did not respond</dd>
874 <dt>CUPS_SC_STATUS_OK </dt>
875 <dd class="description">Operation succeeded</dd>
876 <dt>CUPS_SC_STATUS_TIMEOUT </dt>
877 <dd class="description">The backend did not respond</dd>
878 <dt>CUPS_SC_STATUS_TOO_BIG </dt>
879 <dd class="description">Response too big</dd>
880 </dl>
881 </div>
882 </body>
883 </html>