Find the status of printer with the api

picavet thefxp17 at yahoo.fr
Thu Aug 10 09:12:34 PDT 2006


> > picavet wrote:
> > > I search to find the method to recuperate the status of printer with the CUPS API.
> > > I try to use cupsGetDests but i don't find the "printer-state".
> > >
> > > How I can do to recuperate this status
> >
> > What version of CUPS are you using?
> >
> > For CUPS 1.2 and higher, you can use the cupsGetDests() function and
> > then look for the printer-state attribute in the options array:
> >
> >      int num_dests;
> >      cups_dest_t *dests, *dest;
> >      const char *value;
> >      ipp_pstate_t printer_state;
> >
> >
> >      num_dests = cupsGetDests(&dests);
> >      dest = cupsGetDest("myprinter", NULL, num_dests, dests);
> >      value = cupsGetOption("printer-state", dest->num_options,
> > dest->options);
> >      if (value)
> >        printer_state = (ipp_pstate_t)atoi(value);
> >      else
> >        printer_state = IPP_PRINTER_IDLE;
> >
> > For all versions of CUPS, you can also send an IPP request to the
> > scheduler (IPP_GET_PRINTER_ATTRIBUTES); the following code is for
> > CUPS 1.2, but will work with some modification for 1.1 (see the
> > 1.1 programmer's manual or the CUPS book for a template):
> >
> >      ipp_pstate_t
> >      get_printer_state(const char *printer_name)
> >      {
> >      http_t *http;
> >      ipp_t *request, *response;
> >      ipp_attribute_t *attr;
> >      ipp_pstate_t printer_state;
> >      char uri[1024];
> >
> >
> >      http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
> >      request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
> >
> >      httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp",
> >                       NULL, cupsServer(), ippPort(), "/printers/%s",
> >                       printer_name);
> >      ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
> >                   "printer-uri", NULL, uri);
> >      ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
> >                   "requested-attributes", NULL, "printer-state");
> >
> >      response = cupsDoRequest(http, request, "/");
> >      if ((attr = ippFindAttribute(response, "printer-state",
> > IPP_TAG_ENUM)) != NULL)
> >        printer_state = (ipp_pstate_t)attr->values[0].integer;
> >      else
> >        printer_state = IPP_PRINTER_IDLE;
> >
> >      ippDelete(response);
> >
> >      return (printer_state);
> >      }
> >
> > --
> > ______________________________________________________________________
> > Michael Sweet, Easy Software Products           mike at easysw dot com
> > Internet Printing and Document Software          http://www.easysw.com
>
>
>
> thanks.
> I use cups 1.1.17-13.3.37
> so i try to use ipp request
>


----------------------------------------------------------------
I have got to install 1.2.2 cups version.
But when my printer is stopped the printer_state is always iddle
why?





More information about the cups mailing list