我正在尝试侦听打印机状态更改(例如卡纸,暂停...)以下代码给出了“错误的notify-recipient-uri”响应,然后锁定了ippReadFile,并且在打印机暂停/取消暂停。CUPS状态更改订阅
int main()
{
http_t *http = httpConnectEncrypt(cupsServer(), ippPort(),
cupsEncryption());
ipp_t *request = ippNewRequest(IPP_CREATE_PRINTER_SUBSCRIPTION);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, "ipp://localhost:631/printers/Generic-text-only");
ippAddString(request, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI, "notify-recipient-uri",
NULL, "cups_test://");
ippAddString(request, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD, "notify-events",
NULL, "printer-state-changed");
ipp_t *response = cupsDoRequest(http, request, "/");
while (1)
{
ipp_state_t state;
ipp_t *event = ippNew();
while ((state = ippReadFile(0, event)) != IPP_DATA)
{
printf("%s\n","Got Data");
}
printf("%s\n","Repeating");
ippDelete(event);
}
}
在筛选打印机属性后,我发现notify-schemes-supported
属性设置为“dbus”。我无法通过IPP_SET_PRINTER_ATTRIBUTES
更改属性。任何想法如何让这个工作?
我对杯子并不熟悉,但我注意到你正在传递文件描述符0作为'ippReadFile(int fd,ipp_t * ipp)'的第一个参数。文件描述符0是标准输入。是否有理由期望在程序的标准输入中出现任何内容?否则,正如你所描述的那样,它会挂起并不奇怪。如果你使用'ippRead(http,event)'? – MassPikeMike
'ippRead(http,event)'不会锁定,所以它只是无限循环。我从https://github.com/apple/cups/blob/master/notifier/testnotify.c和https://github.com/apple/cups/blob/master/test/create- printer-subscription.test。我完全有可能错误地做这件事,虽然我不认为是这样。 –
根据我在杯子上的书,Michael Sweet的CUPS:通用UNIX打印系统,“通知程序为CUPS通知用户或程序关于服务器,打印机或作业的状态变化的方法.ippget通知方案在CUPS服务器内部实现,而所有其他CUPS通告程序是在其标准输入文件上接收事件的外部程序。“ –