Filter - backend communication example?

Paul Newall p.newalls at ntlworld.com
Thu Feb 4 13:45:10 PST 2010


> On Feb 2, 2010, at 11:22 PM, Paul Newall wrote:
> >> I am working on a filter for the Kodak EPS 5250.
> >> Can anyone point me at an existing filter that uses =
> cupsBackChannelRead() so I can look at the source code?
> >=20

> > 3rd Feb
> > I am using the socket backend. I think I need some way to force the =
> backend to send a packet containing a command to the printer before it =
> sends the print data.
> > At the moment the command is not sent until a large quantity of print =
> data is ready to send. Then a large packet gets sent.
> > Is there a mechanism for telling the backend to send a packet now?
>
> Yes, there are two things you need to do.
> First, if you are using the C stdio stuff, do:
>     fflush(stdout);
> Second, you can use the cupsSideChannel APIs to tell the backend to =
> drain all pending data:
>     cups_sc_status_t status;
>     status =3D cupsSideChannelDoRequest(CUPS_SC_CMD_DRAIN_OUTPUT, NULL, =
> NULL, 30.0);
>
> "status" will be CUPS_SC_STATUS_OK if everything worked, =
> CUPS_SC_STATUS_TIMEOUT if the backend did't complete within the time =
> allowed (30 seconds in the code above), CUPS_SC_STATUS_IO_ERROR if the =
> backend couldn't send data to the printer, or =
> CUPS_SC_STATUS_NOT_IMPLEMENTED if the backend does not support the =
> command (all of the standard CUPS backends do...)
>
> You should also read the Filter and Backend Programming Guide, available =
> on your system and on cups.org:
>
>     http://localhost:631/help/api-filter.html
>     http://www.cups.org/documentation.php/doc-1.4/api-filter.html
>
> although looking at it we seem to have omitted what I provided above...  =
> Filed CUPS STR #3491 to add it:
>
>     http://www.cups.org/str.php?L3491
>
> Feel free to add your own comments/feedback.
>
> ___________________________________________________
> Michael Sweet, Senior Printing System Engineer
>
>
>
Thank you, That was the roughly kind of thing I was trying. My filter code is like this
fp is a FILE pointer to stdout

	fprintf(fp, "LockPrinter?");
	fflush(fp);

Then I do the cupsSideChannelDoRequest call and get CUPS_SC_STATUS_OK

But fflush(fp); is not causing the packet to be sent to the printer. I still get a large packet, starting with "LockPrinter?" followed by all my subsequent print data.

My filter, written in c, is set up in a pipeline following ghostscript by a script (maybe that's relevant?)





More information about the cups mailing list