]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add heartbeat one second
authorBastian Dehn <hhaalo@arcor.de>
Sat, 30 Mar 2024 18:54:29 +0000 (19:54 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 30 Mar 2024 18:54:29 +0000 (19:54 +0100)
src/CMakeLists.txt
src/kds_s2000w_handler.c
src/kds_s2000w_handler.h
src/kds_s2000w_heartbeat.c [new file with mode: 0644]
src/kds_s2000w_heartbeat.h [new file with mode: 0644]
src/kds_s2000w_net.c

index 88965bbd6ffd0fd387e162fb6ad367d714389be6..d7929e5d8cfbdf27e8997f8000c3780caf50273b 100644 (file)
@@ -38,7 +38,8 @@ ADD_LIBRARY("sane-kds_s2000w_net"
        "kds_s2000w_client.c"
        "kds_s2000w_image_converter.c"
        "kds_s2000w_debug.c"
-       "kds_s2000w_config.c")
+       "kds_s2000w_config.c"
+       "kds_s2000w_heartbeat.c")
 SET_TARGET_PROPERTIES("sane-kds_s2000w_net" PROPERTIES VERSION 1)
 TARGET_INCLUDE_DIRECTORIES("sane-kds_s2000w_net" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
 TARGET_LINK_LIBRARIES("sane-kds_s2000w_net"
@@ -46,7 +47,8 @@ TARGET_LINK_LIBRARIES("sane-kds_s2000w_net"
        ${CONFUSE}
        ${CURL_LIBRARY}
        ${ImageMagick_LIBRARIES}
-       json-c)
+       json-c
+       pthread)
 
 INSTALL(TARGETS "sane-kds_s2000w_net"
        DESTINATION ${CMAKE_LIBRARY_PATH}/sane)
index a54c234614a3d46b351d0a43e58fef7e9c0d7b9d..7e5a6bf2f9a03b3588f2dda6a114c445a574622e 100644 (file)
@@ -1,12 +1,12 @@
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <math.h>
 #include "kds_s2000w_handler.h"
 #include "kds_s2000w_handler_opts.h"
 #include "kds_s2000w_client.h"
 #include "kds_s2000w_image_converter.h"
 #include "kds_s2000w_debug.h"
+#include "kds_s2000w_heartbeat.h"
 
 void _get_current_metadata(handler* h)
 {
@@ -93,7 +93,6 @@ void _get_current_metadata(handler* h)
        metadata = NULL;
        kds_s2000w_client_response_free(resp);
        resp = NULL;
-       sleep(1);
 }
 
 void _delete_current_image(handler* h)
@@ -177,6 +176,7 @@ handler* init_handler()
 
        h->sessionid = 0;
        h->state = NOTCONNECTED;
+       h->wait = 0;
        h->current_scan_status->current_image_number = 1;
        h->current_scan_status->available_images = 0;
        h->current_scan_status->downloaded_images = 0;
@@ -206,6 +206,7 @@ handler* init_handler()
 void free_handler(handler* h)
 {
        debug_printf(ALL, "free handler");
+       while(h->wait);
        json_object_put(h->current_scanner_config);
        h->current_scanner_config = NULL;
        free(h->current_scan_status);
@@ -233,6 +234,7 @@ void reset_handler(handler* h)
        h->jpg_image->data = NULL;
 
        h->state = NOTCONNECTED;
+       h->wait = 0;
        h->current_scan_status->current_image_number = 1;
        h->current_scan_status->available_images = 0;
        h->current_scan_status->downloaded_images = 0;
@@ -318,7 +320,6 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
        if (resp->code == 408) {
                kds_s2000w_client_response_free(resp);
                resp = NULL;
-               sleep(1);
                resp = kds_s2000w_client_response_init();
                result = kds_s2000w_client_open_session(resp);
                if (resp->error_size > 0)
@@ -395,6 +396,9 @@ void kds_s2000w_handler_stop_scan(handler* h)
 void kds_s2000w_handler_get_parameters(handler* h)
 {
        debug_printf(ALL, "kds_s2000w_handler_get_parameters");
+       while(h->wait);
+       wait_a_second(&h->wait);
+
        if (h->current_scan_status->complete_scanned
                && h->current_scan_status->available_images <= 0) {
                h->current_metadata->valid = 1;
index aba0ca5a3c37e4e6fef4fe50ca452b0c0aad9ad4..d855e253de6169af5a4d8da1f803c936387df10f 100644 (file)
@@ -48,6 +48,7 @@ typedef struct {
 typedef struct {
        long sessionid;
        int state;
+       int wait;
        json_object* current_scanner_config;
        scanstatus* current_scan_status;
        metadata* current_metadata;
diff --git a/src/kds_s2000w_heartbeat.c b/src/kds_s2000w_heartbeat.c
new file mode 100644 (file)
index 0000000..62921bf
--- /dev/null
@@ -0,0 +1,18 @@
+#include <unistd.h>
+#include <pthread.h>
+#include "kds_s2000w_heartbeat.h"
+
+void* _wait_thread(void* wait)
+{
+       int* wait_bool = (int*) wait;
+       sleep(1);
+       *wait_bool = 0;
+       return NULL;
+}
+
+void wait_a_second(int* wait)
+{
+       *wait = 1;
+       pthread_t pwait;
+       pthread_create(&pwait, NULL, _wait_thread, wait);
+}
\ No newline at end of file
diff --git a/src/kds_s2000w_heartbeat.h b/src/kds_s2000w_heartbeat.h
new file mode 100644 (file)
index 0000000..82c7406
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef KDS_S2000W_HEARTBEAT_H
+#define KDS_S2000W_HEARTBEAT_H
+
+void wait_a_second(int* wait);
+
+#endif
\ No newline at end of file
index 1cc71cbc6edf24f760dfa522e0a832d13ce6432e..473d669b7e6e401ffdcafbab6d16f0b8af0b4dae 100644 (file)
@@ -171,7 +171,6 @@ SANE_Status _sane_kds_s2000w_net_start(SANE_Handle handle)
        }
 
        for (int i = 0; i < 200; i++) {
-               usleep(500000);
                kds_s2000w_handler_get_parameters(h);
                if (h->current_metadata->valid)
                        break;