]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change handler get parameter in sub methods
authorBastian Dehn <hhaalo@arcor.de>
Sat, 21 Dec 2024 15:52:07 +0000 (16:52 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 21 Dec 2024 15:52:07 +0000 (16:52 +0100)
src/kds_s2000w_handler.c
src/kds_s2000w_handler.h
src/kds_s2000w_net.c

index ba634240f23c39ec3b91005d3c9e584dc3715265..52fb2c76fe5ba7bb03540983d4ac906aacac2fef 100644 (file)
 #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
index 96a495f057305af402a86fd49c05d7673cea7ac7..5212bae394c92f2e8206554b87644b9481799888 100644 (file)
@@ -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
index fcc2949bb7453a0f4d1e1548a227110cd93ecf00..c4e44b50a2088102e66938029230df07e3af5f6d 100644 (file)
@@ -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;