]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
refactor download image to private method
authorBastian Dehn <hhaalo@arcor.de>
Tue, 6 Feb 2024 15:50:22 +0000 (16:50 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 6 Feb 2024 15:50:22 +0000 (16:50 +0100)
src/kds_s2000w_handler.c

index 25999897e5cb8bbed8141ae9adc101ed0457f447..8a32b5cf204d8e5e55da033f7515a50dc3eb3134 100644 (file)
@@ -23,6 +23,24 @@ typedef struct {
 
 scan_status current_scan_status;
 
+void _download_current_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++;
+       sleep(1);
+}
+
 void _get_current_scan_status()
 {
        json_object* status_resp_obj = NULL;
@@ -162,20 +180,7 @@ metadata kds_s2000w_handler_get_parameters(int image_number)
                return mdata;
        }
 
-       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++;
-       sleep(1);
+       _download_current_image();
 
        printf("current available images: %i\n", current_scan_status.available_images);
        printf("current downloaded images: %i\n", current_scan_status.downloaded_images);