From 9f1c3c20fd8bf8c9f71aa0ade5b11e52d0449965 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 18 Feb 2024 17:49:44 +0100 Subject: [PATCH] change scan status per ptr --- src/kds_s2000w_handler.c | 43 +++++++++++++++++++++------------------- src/kds_s2000w_handler.h | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index a81b841..10977c5 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -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 diff --git a/src/kds_s2000w_handler.h b/src/kds_s2000w_handler.h index c4d7c41..14edb3d 100644 --- a/src/kds_s2000w_handler.h +++ b/src/kds_s2000w_handler.h @@ -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; -- 2.39.5