]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add recreate session when empty paper
authorBastian Dehn <hhaalo@arcor.de>
Fri, 1 Mar 2024 16:49:32 +0000 (17:49 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 1 Mar 2024 16:49:32 +0000 (17:49 +0100)
src/kds_s2000w_debug.h
src/kds_s2000w_handler.c
src/kds_s2000w_handler.h
src/kds_s2000w_net.c

index 03b00a69b549028a788f7b1a5d8f04130b5940d2..f535ead22874f789fbe9d6e64b56309ce14a13fa 100644 (file)
@@ -9,7 +9,7 @@
 #define DEBUG 5
 #define ALL 6
 
-#define LOGLEVEL DEBUG
+#define LOGLEVEL INFO
 
 void debug_printf(int level, const char* message);
 void debug_printf_int(int level, const char* message, int value);
index ea40b284a44f5d6eba36ce724392a6d2dbcce104..a618689ae2616edb46f54debaeccab7fdb9e9170 100644 (file)
@@ -231,6 +231,28 @@ void reset_handler(handler* h)
        h->read_info->readed_lines = 0;
 }
 
+void kds_s2000w_handler_recreate_session(handler* h)
+{
+       kds_s2000w_client_close_session(h->sessionid);
+       response* resp = kds_s2000w_client_response_init();
+       kds_s2000w_client_open_session("hhaalo", resp);
+
+       if (resp->code == 200) {
+               json_object* resp_config = json_tokener_parse(resp->data);
+               json_object* value_object = NULL;
+               json_object_object_get_ex(resp_config, "SessionId", &value_object);
+               h->sessionid = json_object_get_int64(value_object);
+               h->state = OPENED;
+               value_object = NULL;
+               json_object_put(resp_config);
+               resp_config = NULL;
+               debug_printf_long(INFO, "SessionId", h->sessionid);
+       }
+
+       kds_s2000w_client_response_free(resp);
+       resp = NULL;
+}
+
 void kds_s2000w_handler_open(const char* devicename, void** handle)
 {
        debug_printf(ALL, "kds_s2000w_handler_open");
@@ -275,6 +297,7 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
                json_object_object_get_ex(resp_config, "SessionId", &value_object);
                h->sessionid = json_object_get_int64(value_object);
                h->state = OPENED;
+               debug_printf_long(INFO, "SessionId", h->sessionid);
                value_object = NULL;
        }
 
@@ -282,8 +305,6 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
        resp_config = NULL;
        kds_s2000w_client_response_free(resp);
        resp = NULL;
-
-       return;
 }
 
 void kds_s2000w_handler_close(handler* h)
index 67de78c5efc28ec489bc27fa65b9b0668ed7cc1b..fd50111323aea9d1d4ed759f76c163049a1efcb7 100644 (file)
@@ -51,6 +51,7 @@ typedef struct {
 handler* init_handler();
 void free_handler(handler* h);
 void reset_handler(handler* h);
+void kds_s2000w_handler_recreate_session(handler* h);
 void kds_s2000w_handler_open(const char* devicename, void** handle);
 void kds_s2000w_handler_close(handler* h);
 void kds_s2000w_handler_get_option(handler* handle, int option, void* value, int* info);
index 477c442ffa82733282e403a68043aa1bca7b7111..ab86c8523b4df862918f8a0b75ae57661d12bb8e 100644 (file)
@@ -82,7 +82,6 @@ SANE_Status _sane_kds_s2000w_net_open(SANE_String_Const devicename,
        if (h->state == NOTCONNECTED)
                return SANE_STATUS_IO_ERROR;
 
-       debug_printf_long(INFO, "SessionId", h->sessionid);
        return SANE_STATUS_GOOD;
 }
 
@@ -185,6 +184,11 @@ SANE_Status _sane_kds_s2000w_net_start(SANE_Handle handle)
                        break;
        }
 
+       if (h->current_metadata->valid == 0) {
+               kds_s2000w_handler_recreate_session(h);
+               return SANE_STATUS_NO_DOCS;
+       }
+
        if (h->current_scan_status->complete_scanned)
                kds_s2000w_handler_stop_scan(h);