Setting printer status from STOPPED to IDLE
Bawenang
benang at cs.its.ac.id
Mon Dec 18 19:09:58 PST 2006
> Bawenang wrote:
> > Hi, I've read in the development forum:
> >
> > QUOTE from
> > http://www.cups.org/newsgroups.php?s933+gcups.development+v941+T1:
> > "The standard CUPS backends only use this exit code for absolutely
> > fatal conditions such as bad URIs and other errors that require the
> > administrator/user to manually fix the problem."
> >
> > So if my application runs into this error and the admin has fixed the
> > problem manually, how do I set the status to IDLE again from STOPPED
> > in my application? My plan is I'll just make a button that can be
> > clicked by the admin to clear the jobs queue and set the status to
> > IDLE. I know that to clear the queue I'll just call cupsCancelJob().
> > But how to set the printer status? I believe there's a function
> > called SetPrinterState() in printers.h. Do I have to call that
> > function? If I do, what are the parameters? I can't find the
> > explanation anywhere.
>
> You need to use the CUPS-Add-Modify-Printer IPP operation, passing
> the printer-uri and printer-state values in addition to the
> attributes-natural-language and attributes-charset values.
>
> The CUPS web interface includes help on the CUPS API:
>
> http://localhost:631/help
>
> The following code snippet (not tested) will start the named printer:
>
> #include <cups/cups.h>
>
> void
> start_printer(const char *name)
> {
> http_t *http = httpConnectEncrypt(cupsServer(), ippPort(),
> cupsEncryption());
> ipp_t *request;
> char uri[1024];
>
>
> httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp",
> NULL, "localhost", ippPort(), "/printers/%s",
> name);
>
> request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER);
> ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
> "printer-uri", NULL, uri);
> ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM,
> "printer-state", IPP_PRINTER_IDLE);
>
> ippDelete(cupsDoRequest(http, "/admin/", request));
> httpClose(http);
>
> if (cupsLastError() != IPP_OK)
> {
> // Display error
> puts(cupsLastErrorString());
> }
> }
>
> If you are developing a GUI application, make sure you register a
> password callback function that will ask for a username and
> password (the standard callback asks on the current console/terminal
> window...)
>
> --
> ______________________________________________________________________
> Michael Sweet, Easy Software Products mike at easysw dot com
> Internet Printing and Publishing Software http://www.easysw.com
Thanks a lot. BTW, after I read Kurt Pfeifle's reply about using cupsenable printer_name, I wanted to ask about something. What's the difference of using the snippet and just simply call: system("cupsenable printer_name"); ? I've tried the cupsenable and it worked so maybe if it wasn't any different I'll try the more direct system call.
Thanks again.
More information about the cups
mailing list