]> git.ipfire.org Git - thirdparty/cups.git/blame - doc/help/api-filter.html
Merge changes from CUPS 1.4svn-r7282.
[thirdparty/cups.git] / doc / help / api-filter.html
CommitLineData
ef416fc2 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>
5a738aea
MS
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"><!--
9BODY {
10 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
11}
12
13H1, H2, H3, H4, H5, H6, P, TD, TH {
14 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
15}
16
17KBD {
18 font-family: monaco, courier, monospace;
19 font-weight: bold;
20}
21
22PRE {
23 font-family: monaco, courier, monospace;
24}
25
26PRE.command {
27 margin-left: 36pt;
28}
29
30PRE.example {
31 background: #eeeeee;
32 border: dotted thin #999999;
33 margin-left: 36pt;
34 padding: 10px;
35}
36
37PRE.command EM, PRE.example EM {
38 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
39}
40
41P.command {
42 font-family: monaco, courier, monospace;
43 margin-left: 36pt;
44}
45
46P.formula {
47 font-style: italic;
48 margin-left: 36pt;
49}
50
51BLOCKQUOTE {
52 background: #cccccc;
53 border: solid thin #999999;
54 padding: 10pt;
55}
56
57A:link, A:visited {
58 text-decoration: none;
59 font-weight: bold;
60}
61
62A:link:hover, A:visited:hover, A:active {
63 text-decoration: underline;
64 font-weight: bold;
65}
66
67SUB, SUP {
68 font-size: 50%;
69}
70
71DIV.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
79DIV.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
88DIV.table TABLE TD {
89 border: solid thin #cccccc;
90 padding-top: 5pt;
91}
92
93DIV.table TABLE TH {
94 background: #cccccc;
95 border: none;
96 border-bottom: solid thin #999999;
97}
98
99DIV.figure TABLE {
100 margin-left: auto;
101 margin-right: auto;
102}
103
104DIV.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
113TH.label {
114 padding-top: 5pt;
115 text-align: right;
116 vertical-align: top;
117}
118
119HR {
120 border: solid thin;
121}
122
123SPAN.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
133H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
134 float: right;
135 font-size: 100%;
136}
137
138H2.title, H3.title {
139 border-bottom: solid 2pt #000000;
140}
141
142DT {
143 margin-left: 36pt;
144 margin-top: 12pt;
145}
146
147DD {
148 margin-left: 54pt;
149}
150
151DL.category DT {
152 font-weight: bold;
153}
154
155P.summary {
156 margin-left: 36pt;
157 font-family: monaco, courier, monospace;
158}
159
160SPAN.message {
161 font-style: italic;
162 font-size: smaller;
163}
164
165DIV.summary TABLE {
166 border: solid thin #999999;
167 border-collapse: collapse;
168 border-spacing: 0;
169 margin: 10px;
170}
171
172DIV.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
179DIV.summary TABLE THEAD TH {
180 background: #eeeeee;
181}
182
183/* API documentation styles... */
184div.body h1 {
185 margin: 0;
186}
187div.body h2 {
188 margin-top: 1.5em;
189}
190div.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}
202code, p.code, pre, ul.code li {
203 font-family: monaco, courier, monospace;
204 font-size: 90%;
205}
206ul.code, ul.contents, ul.subcontents {
207 list-style-type: none;
208 margin: 0;
209 padding-left: 0;
210}
211ul.code li {
212 margin: 0;
213}
214ul.contents > li {
215 margin-top: 1em;
216}
217ul.contents li ul.code, ul.contents li ul.subcontents {
218 padding-left: 2em;
219}
220div.body dl {
221 margin-left: 0;
222 margin-top: 0;
223}
224div.body dt {
225 font-style: italic;
226 margin-left: 0;
227 margin-top: 0;
228}
229div.body dd {
230 margin-bottom: 0.5em;
231}
232
233/* This is just for the HTML files generated with the framedhelp target */
234div.contents {
235 background: #e8e8e8;
236 border: solid thin black;
237 padding: 10px;
238}
239div.contents h1 {
240 font-size: 110%;
241}
242div.contents h2 {
243 font-size: 100%;
244}
245div.contents ul.contents {
246 font-size: 80%;
247}
248--></style>
ef416fc2 249</head>
250<body>
5a738aea 251<div class='body'>
ef416fc2 252<!--
5a738aea 253 "$Id: api-cups.header 7279 2008-01-31 01:50:44Z mike $"
ef416fc2 254
5a738aea
MS
255 Filter and backend programming header for the Common UNIX Printing System
256 (CUPS).
ef416fc2 257
5a738aea 258 Copyright 2008 by Apple Inc.
ef416fc2 259
260 These coded instructions, statements, and computer programs are the
bc44d920 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/".
ef416fc2 265-->
266
5a738aea 267<h1 class="title">Filter and Backend Programming</h1>
ef416fc2 268
5a738aea
MS
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 $"
ef416fc2 324
5a738aea
MS
325 Filter and backend programming introduction for the Common UNIX Printing
326 System (CUPS).
ef416fc2 327
5a738aea
MS
328 Copyright 2007-2008 by Apple Inc.
329 Copyright 1997-2006 by Easy Software Products, all rights reserved.
ef416fc2 330
5a738aea
MS
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-->
f7deaa1a 337
5a738aea 338<h2 class='title'><a name="OVERVIEW">Overview</a></h2>
ef416fc2 339
5a738aea
MS
340<p>Filters, printer drivers, port monitors, and backends use a common interface
341for processing print jobs and communicating status information to the scheduler.
342Each filter is run with a standard set of command-line arguments:<p>
ef416fc2 343
5a738aea 344<dl class="code">
f7deaa1a 345
5a738aea
MS
346 <dt>argv[1]</dt>
347 <dd>The job ID</dd>
ef416fc2 348
5a738aea
MS
349 <dt>argv[2]</dt>
350 <dd>The user printing the job</dd>
f7deaa1a 351
5a738aea
MS
352 <dt>argv[3]</dt>
353 <dd>The job name/title</dd>
f7deaa1a 354
5a738aea
MS
355 <dt>argv[4]</dt>
356 <dd>The number of copies to print</dd>
f7deaa1a 357
5a738aea
MS
358 <dt>argv[5]</dt>
359 <dd>The options that were provided when the job was submitted</dd>
f7deaa1a 360
5a738aea
MS
361 <dt>argv[6]</dt>
362 <dd>The file to print (first filter only)</dd>
363</dl>
f7deaa1a 364
5a738aea
MS
365<p>The scheduler runs one or more of these programs to print any given job. The
366first filter reads from the print file and writes to the standard output, while
367the remaining filters read from the standard input and write to the standard
368output. The backend is the last filter in the chain and writes to the
369device.</p>
f7deaa1a 370
5a738aea 371<h3><a name="EXITCODES">Exit Codes</a></h3>
f7deaa1a 372
5a738aea
MS
373<p>Filters must exit with status 0 when they successfully generate print data
374or 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>
f7deaa1a 376
5a738aea 377<h3><a name="ENVIRONMENT">Environment Variables</a></h3>
f7deaa1a 378
5a738aea 379<p>The following environment variables are defined by the printing system:</p>
f7deaa1a 380
5a738aea 381<dl class="code">
f7deaa1a 382
5a738aea
MS
383 <dt>APPLE_LANGUAGES</dt>
384 <dd>The Apple language identifier associated with the job
385 (Mac OS X only).</dd>
f7deaa1a 386
5a738aea
MS
387 <dt>CHARSET</dt>
388 <dd>The job character set, typically "utf-8".</dd>
f7deaa1a 389
5a738aea
MS
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>
f7deaa1a 394
5a738aea
MS
395 <dt>CONTENT_TYPE</dt>
396 <dd>The MIME type associated with the file (e.g.
397 application/postscript).</dd>
f7deaa1a 398
5a738aea
MS
399 <dt>CUPS_CACHEDIR</dt>
400 <dd>The directory where cache files can be stored.</dd>
f7deaa1a 401
5a738aea
MS
402 <dt>CUPS_DATADIR</dt>
403 <dd>The directory where data files can be found.</dd>
f7deaa1a 404
5a738aea
MS
405 <dt>CUPS_SERVERROOT</dt>
406 <dd>The root directory of the server.</dd>
f7deaa1a 407
5a738aea
MS
408 <dt>DEVICE_URI</dt>
409 <dd>The device-uri associated with the printer.</dd>
f7deaa1a 410
5a738aea
MS
411 <dt>FINAL_CONTENT_TYPE</dt>
412 <dd>The MIME type associated with the printer (e.g.
413 application/vnd.cups-postscript).</dd>
f7deaa1a 414
5a738aea
MS
415 <dt>LANG</dt>
416 <dd>The language locale associated with the job.</dd>
f7deaa1a 417
5a738aea
MS
418 <dt>PPD</dt>
419 <dd>The full pathname of the PostScript Printer Description (PPD)
420 file for this printer.</dd>
f7deaa1a 421
5a738aea
MS
422 <dt>PRINTER</dt>
423 <dd>The name of the printer.</dd>
f7deaa1a 424
5a738aea
MS
425 <dt>RIP_CACHE</dt>
426 <dd>The recommended amount of memory to use for Raster Image
427 Processors (RIPs).</dd>
f7deaa1a 428
5a738aea 429</dl>
f7deaa1a 430
5a738aea 431<h3><a name="MESSAGES">Communicating with the Scheduler</a></h3>
f7deaa1a 432
5a738aea
MS
433<p>Filters and backends communicate wih the scheduler by writing messages
434to the standard error file. For example, the following code sets the current
435printer state message to "Printing page 5":</p>
f7deaa1a 436
5a738aea
MS
437<pre class="example">
438int page = 5;
f7deaa1a 439
5a738aea 440fprintf(stderr, "INFO: Printing page %d\n", page);
f7deaa1a 441</pre>
442
5a738aea
MS
443<p>Each message is a single line of text starting with one of the following
444prefix 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
511the "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>
518functions. The
519<a href="#cupsBackChannelRead"><code>cupsBackChannelRead</code></a> function
520reads data that has been sent back from the device and is typically used to
521obtain status and configuration information. For example, the following code
522polls the backend for back-channel data:</p>
523
524<pre class="example">
525#include &lt;cups/cups.h&gt;
526
527char buffer[8192];
528ssize_t bytes;
529
530/* Use a timeout of 0.0 seconds to poll for back-channel data */
531bytes = cupsBackChannelRead(buffer, sizeof(buffer), 0.0);
532</pre>
f7deaa1a 533
5a738aea
MS
534The
535<a href="#cupsSideChannelDoRequest"><code>cupsSideChannelDoRequest</code></a>
536function allows you to get out-of-band status information and do synchronization
537with the device. For example, the following code gets the current IEEE-1284
538device ID string from the backend:</p>
539
540<pre class="example">
f7deaa1a 541#include &lt;cups/sidechannel.h&gt;
542
543char data[2049];
544int datalen;
5a738aea 545<a href="#cups_sc_status_t">cups_sc_status_t</a> status;
f7deaa1a 546
547/* Tell cupsSideChannelDoRequest() how big our buffer is, less 1 byte for nul-termination... */
548datalen = sizeof(data) - 1;
549
550/* Get the IEEE-1284 device ID, waiting for up to 1 second */
5a738aea 551status = <a href="#cupsSideChannelDoRequest">cupsSideChannelDoRequest</a>(CUPS_SC_CMD_GET_DEVICE_ID, data, &amp;datalen, 1.0);
f7deaa1a 552
553/* Use the returned value if OK was returned and the length is non-zero */
554if (status == CUPS_SC_STATUS_OK && datalen > 0)
555 data[datalen] = '\0';
556else
557 data[0] = '\0';
558</pre>
559
5a738aea
MS
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
564recommend writing back-channel data using a timeout of 1.0 seconds:</p>
f7deaa1a 565
5a738aea
MS
566<pre class="example">
567#include &lt;cups/cups.h&gt;
f7deaa1a 568
5a738aea
MS
569char buffer[8192];
570ssize_t bytes;
f7deaa1a 571
5a738aea
MS
572/* Use a timeout of 1.0 seconds to give filters a chance to read */
573cupsBackChannelWrite(buffer, bytes, 1.0);
f7deaa1a 574</pre>
575
5a738aea
MS
576<p>The <a href="#cupsSideChannelRead"><code>cupsSideChannelRead</code></a>
577function reads a side-channel command from a filter, driver, or port monitor.
578Backends can either poll for commands using a <code>timeout</code> of 0.0, wait
579indefinitely for commands using a <code>timeout</code> of -1.0 (probably in a
580separate 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
582input 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
584since none of the commands sent by upstream filters contain any data at this
585time.</p>
586
587<p>Once a command is processed, the backend uses the
588<a href="#cupsSideChannelWrite"><code>cupsSideChannelWrite</code></a> function
589to send its response. For example, the following code shows how to poll for a
590side-channel command and respond to it:</p>
591
592<pre class="example">
f7deaa1a 593#include &lt;cups/sidechannel.h&gt;
594
5a738aea
MS
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;
f7deaa1a 597
598/* Poll for a command... */
5a738aea 599if (!<a href="#cupsSideChannelRead">cupsSideChannelRead</a>(&amp;command, &amp;status, NULL, NULL, 0.0))
f7deaa1a 600{
601 char data[2048];
602 int datalen;
603
604 switch (command)
605 {
5a738aea 606 /* handle supported commands, file data/datalen/status with values as needed */
f7deaa1a 607
608 default :
609 status = CUPS_SC_STATUS_NOT_IMPLEMENTED;
610 datalen = 0;
611 break;
612 }
613
614 /* Send a response... */
5a738aea 615 <a href="#cupsSideChannelWrite">cupsSideChannelWrite</a>(command, status, data, datalen, 1.0);
f7deaa1a 616}
617</pre>
5a738aea
MS
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">
622ssize_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;
ef416fc2 640parameter controls how many seconds to wait for the data - use
6410.0 to return immediately if there is no data, -1.0 to wait
642for data indefinitely.
643
5a738aea
MS
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">
648ssize_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
ef416fc2 666controls how many seconds to wait for the data to be written - use
6670.0 to return immediately if the data cannot be written, -1.0 to wait
668indefinitely.
669
5a738aea
MS
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
f7deaa1a 695monitors in order to communicate with the backend used by the current
696printer. Programs must be prepared to handle timeout or &quot;not
697implemented&quot; status codes, which indicate that the backend or device
5a738aea
MS
698do not support the specified side-channel command.<br>
699<br>
700The &quot;datalen&quot; parameter must be initialized to the size of the buffer
f7deaa1a 701pointed to by the &quot;data&quot; parameter. cupsSideChannelDoRequest() will
702update the value to contain the number of data bytes in the buffer.
703
5a738aea
MS
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">
708int 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
f7deaa1a 732commands from a filter, driver, or port monitor program. The
733caller must be prepared to handle incomplete or invalid messages
5a738aea
MS
734and return the corresponding status codes.<br>
735<br>
736The &quot;datalen&quot; parameter must be initialized to the size of the buffer
f7deaa1a 737pointed to by the &quot;data&quot; parameter. cupsSideChannelDoRequest() will
738update the value to contain the number of data bytes in the buffer.
739
5a738aea
MS
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">
744int 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
f7deaa1a 768responses to a filter, driver, or port monitor program.
769
5a738aea
MS
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">
775typedef 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">
780typedef 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">
785typedef 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">
790typedef 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">
795typedef 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>
ef416fc2 882</body>
883</html>