]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
move scan started to handler
authorBastian Dehn <hhaalo@arcor.de>
Sun, 18 Feb 2024 10:17:04 +0000 (11:17 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 18 Feb 2024 10:17:25 +0000 (11:17 +0100)
src/kds_s2000w_handler.h
src/kds_s2000w_net.c
tests/kds_s2000w_net_get_params_tests.c
tests/kds_s2000w_net_read_tests.c

index dec9f433127d9c298631f753141255af4c0fe975..aba82e3e65a13c07ad0e725b10997ddaf49a88da 100644 (file)
@@ -24,9 +24,19 @@ typedef struct {
        void* image;
 } metadata;
 
+typedef struct {
+       int scan_started;
+       int cancel;
+       int read_size;
+       int readed_bytes_per_line;
+       int readed_lines;
+       metadata current_metadata;
+} readinfo;
+
 typedef struct {
        long sessionid;
        int state;
+       readinfo read_info;
 } handler;
 
 void kds_s2000w_handler_open(const char* devicename, void** handle);
index 04113ee8b1921cc8de2d92468d28e89aa7a15fc2..ab7754a4f173ca7947249dbeab219526a0cb39aa 100644 (file)
@@ -7,15 +7,6 @@
 #include "kds_s2000w_handler.h"
 #include "kds_s2000w_debug.h"
 
-typedef struct {
-       int scan_started;
-       int cancel;
-       int read_size;
-       int readed_bytes_per_line;
-       int readed_lines;
-       metadata current_metadata;
-} readinfo;
-
 readinfo read_info;
 
 readinfo* get_read_info()
@@ -133,7 +124,8 @@ SANE_Status _sane_kds_s2000w_net_get_parameters(SANE_Handle handle,
        SANE_Parameters* params)
 {
        debug_printf(ALL, "sane_kds_s2000w_net_get_parameters");
-       if (!read_info.scan_started)
+       handler* h = (handler*) handle;
+       if (!h->read_info.scan_started)
                return SANE_STATUS_INVAL;
 
        for (int i = 0; i < 10; i++) {
@@ -168,8 +160,9 @@ SANE_Status _sane_kds_s2000w_net_get_parameters(SANE_Handle handle,
 SANE_Status _sane_kds_s2000w_net_start(SANE_Handle handle)
 {
        debug_printf(ALL, "sane_kds_s2000w_net_start");
+       handler* h = (handler*) handle;
        read_info.cancel = 0;
-       read_info.scan_started = 1;
+       h->read_info.scan_started = 1;
        kds_s2000w_handler_start_scan(handle);
        return SANE_STATUS_GOOD;
 }
@@ -178,8 +171,9 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
        SANE_Int max_length, SANE_Int* length)
 {
        debug_printf(ALL, "sane_kds_s2000w_net_read");
+       handler* h = (handler*) handle;
        if (read_info.cancel) {
-               read_info.scan_started = 0;
+               h->read_info.scan_started = 0;
                *length = 0;
                kds_s2000w_handler_stop_scan(handle);
                sleep(1);
index 898b2f570bf81eafdb42da0394c846176d2f0c98..1996e54a61a955b1b4de51c9fd4ff1ef53f6bb70 100644 (file)
@@ -4,12 +4,12 @@
 
 START_TEST(kds_s2000w_net_get_parameters_invalid_metdata)
 {
-       readinfo* read_info = get_read_info();
-       read_info->scan_started = 1;
+       handler h;
+       h.read_info.scan_started = 1;
        mdata.valid = 0;
        SANE_Parameters* params = malloc(sizeof(SANE_Parameters));
 
-       SANE_Status status = _sane_kds_s2000w_net_get_parameters(NULL, params);
+       SANE_Status status = _sane_kds_s2000w_net_get_parameters(&h, params);
 
        ck_assert_int_eq(status, SANE_STATUS_UNSUPPORTED);
 
index e7065f2e5e897a733c6fe39f7f143ee3e1e4630d..dca71e50ca7f88016bcbfc30cbda47b4ea216fc6 100644 (file)
@@ -20,11 +20,13 @@ END_TEST
 START_TEST(sane_kds_s2000w_net_read_cancel_test)
 {
        readinfo* read_info = get_read_info();
+       handler h;
+       h.read_info.scan_started = 1;
        read_info->cancel = 1;
        int* length = malloc(sizeof(int));
        *length = 0;
 
-       SANE_Status status = _sane_kds_s2000w_net_read(NULL, NULL, 0, length);
+       SANE_Status status = _sane_kds_s2000w_net_read(&h, NULL, 0, length);
 
        ck_assert_int_eq(status, SANE_STATUS_CANCELLED);