From a0e5482057c1c79b8818dcd619d69870ca74fd30 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 18 Feb 2024 11:17:04 +0100 Subject: [PATCH] move scan started to handler --- src/kds_s2000w_handler.h | 10 ++++++++++ src/kds_s2000w_net.c | 18 ++++++------------ tests/kds_s2000w_net_get_params_tests.c | 6 +++--- tests/kds_s2000w_net_read_tests.c | 4 +++- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/kds_s2000w_handler.h b/src/kds_s2000w_handler.h index dec9f43..aba82e3 100644 --- a/src/kds_s2000w_handler.h +++ b/src/kds_s2000w_handler.h @@ -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); diff --git a/src/kds_s2000w_net.c b/src/kds_s2000w_net.c index 04113ee..ab7754a 100644 --- a/src/kds_s2000w_net.c +++ b/src/kds_s2000w_net.c @@ -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); diff --git a/tests/kds_s2000w_net_get_params_tests.c b/tests/kds_s2000w_net_get_params_tests.c index 898b2f5..1996e54 100644 --- a/tests/kds_s2000w_net_get_params_tests.c +++ b/tests/kds_s2000w_net_get_params_tests.c @@ -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); diff --git a/tests/kds_s2000w_net_read_tests.c b/tests/kds_s2000w_net_read_tests.c index e7065f2..dca71e5 100644 --- a/tests/kds_s2000w_net_read_tests.c +++ b/tests/kds_s2000w_net_read_tests.c @@ -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); -- 2.39.5