Closed qq645327806 closed 1 year ago
I thought for a moment, does CUPS only get printing success or not?
Once you submit a job, you can monitor the job to see its state (IPP_JSTATE_PENDING
when queued, IPP_JSTATE_PROCESSING
when it starts printing, IPP_JSTATE_COMPLETED
, `IPP_JSTATE_CANCELED
, or IPP_JSTATE_ABORTED
when the job is done.
ipp_jstate_t get_job_state(const char *printer_name, int job_id)
{
char printer_uri[1024];
ipp_t *request, *response;
ipp_jstate_t job_state;
httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri), "ipp", NULL, "localhost", 631, "/printers/%s", printer_name);
request = ippNewRequest(IPP_OP_GET_JOB_ATTRIBUTES);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printer_uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", NULL, "job-state");
response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/jobs");
job_state = (ipp_jstate_t)ippGetInteger(ippFindAttribute(response, "job-state", IPP_TAG_ENUM), 0);
ippDelete(response);
return (job_state);
}
Thank you for your reply. @michaelrsweet . I had solved my problem.
Hello, Recently, I want to write code to get printer status and result after creating the print job. But I don't know what APIs do I need. The functionality I want to implement is as follows:
When the print job is finished, how do I know if job is finished. How do I get exception information if an error occurs during printing? (Errors such as: paper jam, paper out, out of ink )
I looked at a little code and tried to write a test code, but it didn't work for my purposes. This is the code file printer.c that I have written. I was hoping someone could guide me.
Thank you.
printer_2023_08_01_151951.zip