]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
refactor get scan status
authorBastian Dehn <hhaalo@arcor.de>
Tue, 6 Feb 2024 15:47:32 +0000 (16:47 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 6 Feb 2024 15:47:32 +0000 (16:47 +0100)
src/kds_s2000w_handler.c

index 92920c02cc4112539b20001e7499d4f843633f30..25999897e5cb8bbed8141ae9adc101ed0457f447 100644 (file)
@@ -23,6 +23,32 @@ typedef struct {
 
 scan_status current_scan_status;
 
+void _get_current_scan_status()
+{
+       json_object* status_resp_obj = NULL;
+       json_object* status_obj = NULL;
+       json_object* status_value_obj = NULL;
+
+       resp = kds_s2000w_client_response_init();
+       kds_s2000w_client_status_session(state->sessionid, resp);
+       printf("status response: %s\n", resp->data);
+       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");
+       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)
+               current_scan_status.complete_scanned = 1;
+
+       json_object_put(status_resp_obj);
+       status_resp_obj = NULL;
+       kds_s2000w_client_response_free(resp);
+       resp = NULL;
+       sleep(1);
+}
+
 current_state* kds_s2000w_handler_open()
 {
        image.size = 0;
@@ -128,24 +154,7 @@ metadata kds_s2000w_handler_get_parameters(int image_number)
 
        if (!current_scan_status.complete_scanned
                && current_scan_status.downloaded_images == current_scan_status.available_images) {
-               resp = kds_s2000w_client_response_init();
-               kds_s2000w_client_status_session(state->sessionid, resp);
-               printf("status response: %s\n", resp->data);
-               metadataResp = json_tokener_parse(resp->data);
-               metadata = json_object_object_get(metadataResp, "Status");
-               mdata_value = json_object_object_get(metadata, "NumImagesScanned");
-               current_scan_status.available_images = json_object_get_int(mdata_value);
-               mdata_value = NULL;
-               mdata_value = json_object_object_get(metadata, "State");
-               const char* scanner_state = json_object_get_string(mdata_value);
-               if (strcmp(scanner_state, "Scanning") != 0)
-                       current_scan_status.complete_scanned = 1;
-
-               json_object_put(metadataResp);
-               metadataResp = NULL;
-               kds_s2000w_client_response_free(resp);
-               resp = NULL;
-               sleep(1);
+               _get_current_scan_status();
        }
 
        if (current_scan_status.downloaded_images >= current_scan_status.available_images) {