]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add download image
authorBastian Dehn <hhaalo@arcor.de>
Mon, 5 Feb 2024 19:47:36 +0000 (20:47 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 5 Feb 2024 19:48:25 +0000 (20:48 +0100)
src/kds_s2000w_handler.c

index 707a7dcd0a4b4774e7461551ded9d55a3a247b34..6496ab5132016cbd968ffaa9426402ca8990f708 100644 (file)
@@ -5,13 +5,16 @@
 #include "kds_s2000w_handler.h"
 #include "kds_s2000w_handler_opts.h"
 #include "kds_s2000w_client.h"
+#include "kds_s2000w_image_converter.h"
 
 response* resp = NULL;
 current_state* state = NULL;
 json_object* resp_config = NULL;
 json_object* config = NULL;
+blobdata image;
 
 typedef struct {
+       int current_image_number;
        int available_images;
        int downloaded_images;
        int complete_scanned;
@@ -21,6 +24,8 @@ scan_status current_scan_status;
 
 current_state* kds_s2000w_handler_open()
 {
+       image.size = 0;
+       image.data = NULL;
        state = malloc(sizeof(current_state));
        state->sessionid = 0;
        state->state = NOTCONNECTED;
@@ -63,6 +68,10 @@ current_state* kds_s2000w_handler_open()
        resp = NULL;
 
        printf("sessionid: %li\n", state->sessionid);
+       current_scan_status.current_image_number = 0;
+       current_scan_status.available_images = 0;
+       current_scan_status.downloaded_images = 0;
+       current_scan_status.complete_scanned = 0;
        return state;
 }
 
@@ -79,6 +88,8 @@ void kds_s2000w_handler_close()
        resp_config = NULL;
        kds_s2000w_client_response_free(resp);
        resp = NULL;
+       free(image.data);
+       image.data = NULL;
 }
 
 current_state* kds_s2000w_handler_current_state()
@@ -93,9 +104,6 @@ void kds_s2000w_handler_start_scan()
        resp = kds_s2000w_client_response_init();
        kds_s2000w_client_start_scan(state->sessionid, resp);
        kds_s2000w_client_response_free(resp);
-       current_scan_status.available_images = 0;
-       current_scan_status.downloaded_images = 0;
-       current_scan_status.complete_scanned = 0;
        resp = NULL;
 }
 
@@ -136,8 +144,21 @@ metadata kds_s2000w_handler_get_parameters(int image_number)
                resp = NULL;
        }
 
-       // TODO: real download image
+       if (image.size > 0) {
+               free(image.data);
+               image.data = NULL;
+               image.size = 0;
+       }
+       resp = kds_s2000w_client_response_init();
+       kds_s2000w_client_get_image(state->sessionid, 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;
        current_scan_status.downloaded_images++;
+       // TODO delete image
+
        printf("current available images: %i\n", current_scan_status.available_images);
        printf("current downloaded images: %i\n", current_scan_status.downloaded_images);
        printf("complete_scanned: %i\n", current_scan_status.complete_scanned);