]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change scan status per ptr
authorBastian Dehn <hhaalo@arcor.de>
Sun, 18 Feb 2024 16:49:44 +0000 (17:49 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 18 Feb 2024 16:49:44 +0000 (17:49 +0100)
src/kds_s2000w_handler.c
src/kds_s2000w_handler.h

index a81b84170532b10ca32041d7b6814691802b226b..10977c5bfe6b50eaaa3b36c739c0c6a1fcdad4fc 100644 (file)
@@ -19,7 +19,7 @@ void _get_current_metadata(handler* h)
 {
        debug_printf(ALL, "get_current_metadata");
        resp = kds_s2000w_client_response_init();
-       kds_s2000w_client_get_metadata(h->sessionid, h->current_scan_status.current_image_number, resp);
+       kds_s2000w_client_get_metadata(h->sessionid, h->current_scan_status->current_image_number, resp);
        if (resp->code != 200) {
                h->current_metadata.valid = 0;
                kds_s2000w_client_response_free(resp);
@@ -103,7 +103,7 @@ void _delete_current_image(handler* h)
 {
        debug_printf(ALL, "delete_current_image");
        resp = kds_s2000w_client_response_init();
-       kds_s2000w_client_delete_image(h->sessionid, h->current_scan_status.current_image_number, resp);
+       kds_s2000w_client_delete_image(h->sessionid, h->current_scan_status->current_image_number, resp);
        kds_s2000w_client_response_free(resp);
        resp = NULL;
        sleep(1);
@@ -118,13 +118,13 @@ void _download_current_image(handler* h)
                image.size = 0;
        }
        resp = kds_s2000w_client_response_init();
-       kds_s2000w_client_get_image(h->sessionid, h->current_scan_status.current_image_number, resp);
+       kds_s2000w_client_get_image(h->sessionid, h->current_scan_status->current_image_number, resp);
        image.size = resp->size;
        image.data = malloc(sizeof(char) * resp->size);
        memcpy(image.data, resp->data, resp->size);
        kds_s2000w_client_response_free(resp);
        resp = NULL;
-       h->current_scan_status.downloaded_images++;
+       h->current_scan_status->downloaded_images++;
        sleep(1);
 }
 
@@ -140,12 +140,12 @@ void _get_current_scan_status(handler* h)
        status_resp_obj = json_tokener_parse(resp->data);
        status_obj = json_object_object_get(status_resp_obj, "Status");
        status_value_obj = json_object_object_get(status_obj, "NumImagesScanned");
-       h->current_scan_status.available_images = json_object_get_int(status_value_obj);
+       h->current_scan_status->available_images = json_object_get_int(status_value_obj);
        status_value_obj = NULL;
        status_value_obj = json_object_object_get(status_obj, "State");
        const char* scanner_state = json_object_get_string(status_value_obj);
        if (strcmp(scanner_state, "Scanning") != 0)
-               h->current_scan_status.complete_scanned = 1;
+               h->current_scan_status->complete_scanned = 1;
 
        json_object_put(status_resp_obj);
        status_resp_obj = NULL;
@@ -166,10 +166,11 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
 
        h->sessionid = 0;
        h->state = NOTCONNECTED;
-       h->current_scan_status.current_image_number = 0;
-       h->current_scan_status.available_images = 0;
-       h->current_scan_status.downloaded_images = 0;
-       h->current_scan_status.complete_scanned = 0;
+       h->current_scan_status = malloc(sizeof(scan_status));
+       h->current_scan_status->current_image_number = 0;
+       h->current_scan_status->available_images = 0;
+       h->current_scan_status->downloaded_images = 0;
+       h->current_scan_status->complete_scanned = 0;
        h->current_metadata.format = 0;
        h->current_metadata.is_last = 0;
        h->current_metadata.size = 0;
@@ -241,10 +242,10 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
        kds_s2000w_client_response_free(resp);
        resp = NULL;
 
-       h->current_scan_status.current_image_number = 1;
-       h->current_scan_status.available_images = 0;
-       h->current_scan_status.downloaded_images = 0;
-       h->current_scan_status.complete_scanned = 0;
+       h->current_scan_status->current_image_number = 1;
+       h->current_scan_status->available_images = 0;
+       h->current_scan_status->downloaded_images = 0;
+       h->current_scan_status->complete_scanned = 0;
        h->current_metadata.scanned_all_complete = 0;
        return;
 }
@@ -264,6 +265,8 @@ void kds_s2000w_handler_close(void* handle)
        resp = NULL;
        free(image.data);
        image.data = NULL;
+       free(h->current_scan_status);
+       h->current_scan_status = NULL;
        free(h);
        h = NULL;
 }
@@ -292,20 +295,20 @@ metadata kds_s2000w_handler_get_parameters(void* handle)
 {
        debug_printf(ALL, "kds_s2000w_handler_get_parameters");
        handler* h = (handler*) handle;
-       if (!h->current_scan_status.complete_scanned
-               && h->current_scan_status.downloaded_images == h->current_scan_status.available_images) {
+       if (!h->current_scan_status->complete_scanned
+               && h->current_scan_status->downloaded_images == h->current_scan_status->available_images) {
                _get_current_scan_status(h);
        }
 
-       if (h->current_scan_status.complete_scanned
-               && h->current_scan_status.downloaded_images == h->current_scan_status.available_images) {
+       if (h->current_scan_status->complete_scanned
+               && h->current_scan_status->downloaded_images == h->current_scan_status->available_images) {
                h->current_metadata.valid = 1;
                h->current_metadata.scanned_all_complete = 1;
                h->current_metadata.is_last = 1;
                return h->current_metadata;
        }
 
-       if (h->current_scan_status.downloaded_images >= h->current_scan_status.available_images) {
+       if (h->current_scan_status->downloaded_images >= h->current_scan_status->available_images) {
                h->current_metadata.valid = 0;
                return h->current_metadata;
        }
@@ -313,7 +316,7 @@ metadata kds_s2000w_handler_get_parameters(void* handle)
        _download_current_image(h);
        _get_current_metadata(h);
        _delete_current_image(h);
-       h->current_scan_status.current_image_number++;
+       h->current_scan_status->current_image_number++;
 
        return h->current_metadata;
 }
\ No newline at end of file
index c4d7c416177566651139563323b638f0ef3f9a3a..14edb3d7367882aabad4466d89c3bae7a0594179 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 typedef struct {
        long sessionid;
        int state;
-       scan_status current_scan_status;
+       scan_status* current_scan_status;
        metadata current_metadata;
        readinfo read_info;
 } handler;