From 690e0c08f6b0a1ed6560d4301ee559ff888e4ab1 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 21 Dec 2024 16:52:07 +0100 Subject: [PATCH] change handler get parameter in sub methods --- src/kds_s2000w_handler.c | 221 ++++++++++++++++----------------------- src/kds_s2000w_handler.h | 5 +- src/kds_s2000w_net.c | 9 +- 3 files changed, 103 insertions(+), 132 deletions(-) diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index ba63424..52fb2c7 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -11,7 +11,95 @@ #include "kds_s2000w_debug.h" #endif -void _get_current_metadata(handler* h) +handler* init_handler() +{ +#ifndef NODEBUG + debug_printf(ALL, "init handler"); +#endif + + handler* h = malloc(sizeof(handler)); + h->current_scanner_config = NULL; + h->current_scan_status = malloc(sizeof(scanstatus)); + h->current_metadata = malloc(sizeof(metadata)); + h->read_info = malloc(sizeof(readinfo)); + h->image = malloc(sizeof(imagedata)); + + h->sessionid = 0; + h->state = NOTCONNECTED; + h->current_scan_status->load_options = 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_scan_status->feeder = 1; + h->current_metadata->format = 1; + h->current_metadata->bytes_per_line = 0; + h->current_metadata->pixels_per_line = 0; + h->current_metadata->lines = 0; + h->current_metadata->depth = 8; + h->current_metadata->valid = 0; + h->read_info->scan_started = 0; + h->read_info->cancel = 0; + h->read_info->read_size = 0; + h->read_info->readed_bytes_per_line = 0; + h->read_info->readed_lines = 0; + h->image->size = 0; + h->image->data = NULL; + + return h; +} + +void free_handler(handler* h) +{ +#ifndef NODEBUG + debug_printf(ALL, "free handler"); +#endif + + json_object_put(h->current_scanner_config); + h->current_scanner_config = NULL; + free(h->current_scan_status); + h->current_scan_status = NULL; + free(h->current_metadata); + h->current_metadata = NULL; + free(h->read_info); + h->read_info = NULL; + free(h->image->data); + h->image->data = NULL; + free(h->image); + h->image = NULL; + free(h); + h = NULL; +} + +void reset_handler(handler* h) +{ +#ifndef NODEBUG + debug_printf(ALL, "reset handler"); +#endif + + free(h->image->data); + h->image->data = NULL; + + h->state = NOTCONNECTED; + h->current_scan_status->load_options = 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->format = 1; + h->current_metadata->bytes_per_line = 0; + h->current_metadata->pixels_per_line = 0; + h->current_metadata->lines = 0; + h->current_metadata->depth = 8; + h->current_metadata->valid = 0; + h->read_info->scan_started = 0; + h->read_info->cancel = 0; + h->read_info->read_size = 0; + h->read_info->readed_bytes_per_line = 0; + h->read_info->readed_lines = 0; +} + +void kds_s2000w_handler_get_current_metadata(handler* h) { #ifndef NODEBUG debug_printf(ALL, "get_current_metadata"); @@ -78,7 +166,7 @@ void _get_current_metadata(handler* h) scanner_image = NULL; } -void _delete_current_image(handler* h) +void kds_s2000w_handler_delete_current_image(handler* h) { #ifndef NODEBUG debug_printf(ALL, "delete_current_image"); @@ -96,7 +184,7 @@ void _delete_current_image(handler* h) resp = NULL; } -void _download_current_image(handler* h) +void kds_s2000w_handler_download_current_image(handler* h) { #ifndef NODEBUG debug_printf(ALL, "download_current_image"); @@ -121,7 +209,7 @@ void _download_current_image(handler* h) h->current_scan_status->downloaded_images++; } -void _get_current_scan_status(handler* h) +void kds_s2000w_net_handler_get_current_scan_status(handler* h) { #ifndef NODEBUG debug_printf(ALL, "get_current_scan_status"); @@ -156,94 +244,6 @@ void _get_current_scan_status(handler* h) resp = NULL; } -handler* init_handler() -{ -#ifndef NODEBUG - debug_printf(ALL, "init handler"); -#endif - - handler* h = malloc(sizeof(handler)); - h->current_scanner_config = NULL; - h->current_scan_status = malloc(sizeof(scanstatus)); - h->current_metadata = malloc(sizeof(metadata)); - h->read_info = malloc(sizeof(readinfo)); - h->image = malloc(sizeof(imagedata)); - - h->sessionid = 0; - h->state = NOTCONNECTED; - h->current_scan_status->load_options = 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_scan_status->feeder = 1; - h->current_metadata->format = 1; - h->current_metadata->bytes_per_line = 0; - h->current_metadata->pixels_per_line = 0; - h->current_metadata->lines = 0; - h->current_metadata->depth = 8; - h->current_metadata->valid = 0; - h->read_info->scan_started = 0; - h->read_info->cancel = 0; - h->read_info->read_size = 0; - h->read_info->readed_bytes_per_line = 0; - h->read_info->readed_lines = 0; - h->image->size = 0; - h->image->data = NULL; - - return h; -} - -void free_handler(handler* h) -{ -#ifndef NODEBUG - debug_printf(ALL, "free handler"); -#endif - - json_object_put(h->current_scanner_config); - h->current_scanner_config = NULL; - free(h->current_scan_status); - h->current_scan_status = NULL; - free(h->current_metadata); - h->current_metadata = NULL; - free(h->read_info); - h->read_info = NULL; - free(h->image->data); - h->image->data = NULL; - free(h->image); - h->image = NULL; - free(h); - h = NULL; -} - -void reset_handler(handler* h) -{ -#ifndef NODEBUG - debug_printf(ALL, "reset handler"); -#endif - - free(h->image->data); - h->image->data = NULL; - - h->state = NOTCONNECTED; - h->current_scan_status->load_options = 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->format = 1; - h->current_metadata->bytes_per_line = 0; - h->current_metadata->pixels_per_line = 0; - h->current_metadata->lines = 0; - h->current_metadata->depth = 8; - h->current_metadata->valid = 0; - h->read_info->scan_started = 0; - h->read_info->cancel = 0; - h->read_info->read_size = 0; - h->read_info->readed_bytes_per_line = 0; - h->read_info->readed_lines = 0; -} - void kds_s2000w_handler_recreate_session(handler* h) { kds_s2000w_client_close_session(h->sessionid); @@ -401,41 +401,4 @@ void kds_s2000w_handler_stop_scan(handler* h) kds_s2000w_client_response_free(resp); resp = NULL; -} - -void kds_s2000w_handler_get_parameters(handler* h) -{ -#ifndef NODEBUG - debug_printf(ALL, "kds_s2000w_handler_get_parameters"); -#endif - - if (h->current_scan_status->complete_scanned - && h->current_scan_status->available_images <= 0) { - h->current_metadata->valid = 1; - return; - } - -#ifndef NODEBUG - debug_printf(DEBUG, "get scanner status"); -#endif - _get_current_scan_status(h); - -#ifndef NODEBUG - debug_printf_int(DEBUG, "available images", h->current_scan_status->available_images); -#endif - if (h->current_scan_status->available_images > 0) { -#ifndef NODEBUG - debug_printf_int(DEBUG, "download image", h->current_scan_status->current_image_number); -#endif - _download_current_image(h); -#ifndef NODEBUG - debug_printf_int(DEBUG, "get metadata for image", h->current_scan_status->current_image_number); -#endif - _get_current_metadata(h); -#ifndef NODEBUG - debug_printf_int(DEBUG, "delete image", h->current_scan_status->current_image_number); -#endif - _delete_current_image(h); - h->current_scan_status->current_image_number++; - } } \ No newline at end of file diff --git a/src/kds_s2000w_handler.h b/src/kds_s2000w_handler.h index 96a495f..5212bae 100644 --- a/src/kds_s2000w_handler.h +++ b/src/kds_s2000w_handler.h @@ -57,6 +57,10 @@ typedef struct { handler* init_handler(); void free_handler(handler* h); void reset_handler(handler* h); +void kds_s2000w_handler_get_current_metadata(handler* h); +void kds_s2000w_handler_delete_current_image(handler* h); +void kds_s2000w_handler_download_current_image(handler* h); +void kds_s2000w_net_handler_get_current_scan_status(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); @@ -65,5 +69,4 @@ void kds_s2000w_handler_set_option(handler* handle, int option, void* value, int void kds_s2000w_handler_set_option_auto(int option); void kds_s2000w_handler_start_scan(handler* h); void kds_s2000w_handler_stop_scan(handler* h); -void kds_s2000w_handler_get_parameters(handler* handle); #endif \ No newline at end of file diff --git a/src/kds_s2000w_net.c b/src/kds_s2000w_net.c index fcc2949..c4e44b5 100644 --- a/src/kds_s2000w_net.c +++ b/src/kds_s2000w_net.c @@ -209,12 +209,17 @@ SANE_Status _sane_kds_s2000w_net_start(SANE_Handle handle) } for (int i = 0; i < 30; i++) { - kds_s2000w_handler_get_parameters(h); + kds_s2000w_net_handler_get_current_scan_status(h); - if (h->current_metadata->valid) + if (h->current_scan_status->available_images > 0) break; } + kds_s2000w_handler_download_current_image(h); + kds_s2000w_handler_get_current_metadata(h); + kds_s2000w_handler_delete_current_image(h); + h->current_scan_status->current_image_number++; + if (h->current_metadata->valid == 0 || h->image->size == 0) { kds_s2000w_handler_recreate_session(h); return SANE_STATUS_NO_DOCS; -- 2.39.5