代码拉取完成,页面将自动刷新
diff --git a/backend/usb.c b/backend/usb.c
index 50c1bc3..22dc7d7 100644
--- a/backend/usb.c
+++ b/backend/usb.c
@@ -109,6 +109,50 @@ print_device(const char *uri, /* I - Device URI */
}
#endif /* HAVE_LIBUSB */
+#define HAVE_USB_MONITOR
+#define BEGIN_WAIT_TIME 2
+
+#ifdef HAVE_USB_MONITOR
+#include "usb_monitor.h"
+
+void UpdatePrinterState(PrinterStatus* jobData)
+{
+ if (jobData == NULL) {
+ fprintf(stderr, "DEBUG: USB_MONITOR UpdatePrinterState fail, jobData is NULL\n");
+ return;
+ }
+ if (strcmp(jobData->printerStateReasons, "none") != 0) {
+ fprintf(stderr, "STATE: +%s\nSTATE: -none\n", jobData->printerStateReasons);
+ } else {
+ fprintf(stderr, "STATE: cups-waiting-for-job-completed\n");
+ }
+}
+
+static void HandleTerm(int32_t sig)
+{
+ fprintf(stderr, "DEBUG: USB_MONITOR HandleTerm, set terminal singal\n");
+ SetTerminalSingal();
+}
+
+static void* MonitorPrinterThread(void* arg)
+{
+ if (arg == NULL) {
+ fprintf(stderr, "DEBUG: USB_MONITOR arg is nullptr\n");
+ return NULL;
+ }
+ sleep(BEGIN_WAIT_TIME);
+ char* uri = (char*)arg;
+ if (IsSupportIppOverUsb(uri)) {
+ if (StartMonitorIppPrinter(UpdatePrinterState, uri)) {
+ fprintf(stderr, "DEBUG: USB_MONITOR StartMonitorIppPrinter finished\n");
+ } else {
+ fprintf(stderr, "STATE: none\n");
+ }
+ }
+ free(uri);
+ return NULL;
+}
+#endif /* HAVE_USB_MONITOR */
/*
* 'main()' - Send a file to the specified USB port.
@@ -230,6 +274,13 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
copies = atoi(argv[4]);
}
+#ifdef HAVE_USB_MONITOR
+signal(SIGTERM, HandleTerm);
+fprintf(stderr, "STATE: cups-waiting-for-job-completed\n");
+char* uriCopy = strdup(uri);
+pthread_t monitorThread = _cupsThreadCreate((_cups_thread_func_t)MonitorPrinterThread, uriCopy);
+#endif /* HAVE_USB_MONITOR */
+
/*
* Finally, send the print file...
*/
@@ -244,5 +295,15 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
if (print_fd != 0)
close(print_fd);
+#ifdef HAVE_USB_MONITOR
+if (status != CUPS_BACKEND_OK) {
+ fprintf(stderr, "DEBUG: USB_MONITOR print_device fail, status = %d\n", (int)status);
+ SetTerminalSingal();
+ status = CUPS_BACKEND_FAILED;
+ fprintf(stderr, "STATE: stopped\n");
+}
+pthread_join(monitorThread, NULL);
+#endif /* HAVE_USB_MONITOR */
+
return (status);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。