7 Star 2 Fork 27

OpenHarmony/third_party_cups

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cups-usb-job-state-monitor.patch 2.42 KB
一键复制 编辑 原始数据 按行查看 历史
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);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony/third_party_cups.git
git@gitee.com:openharmony/third_party_cups.git
openharmony
third_party_cups
third_party_cups
master

搜索帮助