message - 如何获得 CUPS 作业停止的原因?

标签 message jobs cups

如何通过 CUPS API 获取 CUPS 打印作业失败的原因?

使用 CUPS API,我打印了两个未能打印的作业。在 CUPS 网络界面上,我可以看到失败的原因:“不支持的打印数据。”和“无法写入打印数据。”

CUPS print job error description

但是,API 似乎不包含这些原因。 cupsGetJobs() 方法返回 cups_job_s 结构体,看起来像这样:

struct cups_job_s {
    time_t completed_time;
    time_t creation_time;
    char *dest;
    char *format;
    int id;
    int priority;
    time_t processing_time;
    int size;
    ipp_jstate_t state;
    char *title;
    char *user;
};

我检查了所有这些字段,没有一个包含屏幕截图中看到的错误字符串。

最佳答案

我相信这归结为 job-state-message属性。要检索作业属性,我相信您必须使用 IPP API,例如(未经测试):

ipp_t *request = ippNewRequest(IPP_GET_JOBS);
...
ipp_t *response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
...
ipp_attribute_t *attr = ippFindAttribute(response, "job-state-message", IPP_TAG_TEXT);

需要注意的是与 job-state 相关的属性工作已被接受后,可能会在某个时候更新。由于服务器不知道打印是否真的会成功(由于墨菲定律的许多因素),作业被接受并在失败时更新 job-state和相应的相关属性。 job-state-message虽然不是强制性的。

如果您希望您的应用程序对这些事件使用react,而不是以固定的时间间隔继续查询 CUPS 服务器,您可以订阅一些 D-Bus 事件 ( see Apple's implementation )。如果你想要一个消费者实现的例子,你可以阅读 Printer's Panel code from gnome-control-center .

下面我尝试引用RFC 2911的一些相关部分(IPP 1.1):

3.1.9 就业创造操作

...

At job processing time, since the Printer object has already responded with a successful status code in the response to the create request, if the Printer object detects an error, the Printer object is unable to inform the end user of the error with an operation status code. In this case, the Printer, depending on the error, can set the job object's "job-state", "job-state-reasons", or "job- state-message" attributes to the appropriate value(s) so that later queries can report the correct job status.

Note: Asynchronous notification of events is outside the scope of this IPP/1.1 document.



4.3.7 作业状态(type1 枚举)

...

6' 'processing-stopped': The job has stopped while processing for any number of reasons and will return to the 'processing' state as soon as the reasons are no longer present.

The job's "job-state-reason" attribute MAY indicate why the job has stopped processing. For example, if the output device is stopped, the 'printer-stopped' value MAY be included in the job's "job-state-reasons" attribute.

Note: When an output device is stopped, the device usually indicates its condition in human readable form locally at the device. A client can obtain more complete device status remotely by querying the Printer object's "printer-state", "printer-state-reasons" and "printer- state-message" attributes.



4.3.9 作业状态消息(text(MAX))

This attribute specifies information about the "job-state" and "job- state-reasons" attributes in human readable text. If the Printer object supports this attribute, the Printer object MUST be able to generate this message in any of the natural languages identified by the Printer's "generated-natural-language-supported" attribute (see the "attributes-natural-language" operation attribute specified in Section 3.1.4.1).

The value SHOULD NOT contain additional information not contained in the values of the "job-state" and "job-states-reasons" attributes, such as interpreter error information. Otherwise, application programs might attempt to parse the (localized text). For such additional information such as interpreter errors for application program consumption or specific document access errors, new attributes with keyword values, needs to be developed and registered.



脚注 :我没有亲自做过,但 RFC 确实告诉你你应该期待什么。

关于message - 如何获得 CUPS 作业停止的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25456355/

相关文章:

java - Message Driven bean 可以实现除 MessageListener 之外的其他接口(interface)吗?

rabbitmq - 消息、队列和交换器有哪些限制?

linux - CUPS session 设置失败,出现 'nt_status_logon_failure'

c - 有没有办法使用 CUPS 库获取打印机的字节命令列表?

C#冒泡/传递事件

android - 在 android 对话中从收件箱中读取 SMS 消息

Bash 脚本 : Suppress job creation message

hadoop - JobTracker UI 不显示 hadoop 作业的进度

linux - BigQuery 命令行 - 列出在指定时间范围内运行的所有作业

local - CUPS @LOCAL 值