From 01868abda76e2b25b3de41af6adf5a75d96cb60c Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Tue, 23 Sep 2025 12:28:12 +0200 Subject: [PATCH] change option count internal module --- src/kds_s2000w_handler_opts.c | 2 +- src/kds_s2000w_option_descriptors.c | 22 ++++++++++++++++------ src/kds_s2000w_option_descriptors.h | 2 +- tests/kds_s2000w_net_get_opt_tests.c | 4 ++-- tests/kds_s2000w_option_descriptor_tests.c | 10 ++++++---- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/kds_s2000w_handler_opts.c b/src/kds_s2000w_handler_opts.c index cbb7410..b2518e5 100644 --- a/src/kds_s2000w_handler_opts.c +++ b/src/kds_s2000w_handler_opts.c @@ -293,7 +293,7 @@ void kds_s2000w_handler_opts_get_option(handler* h, uint32_t option, void* value if (option == 0) { config = json_object_object_get(h->current_scanner_config, "Configuration"); int32_t* int_value_ptr = (int32_t*) value; - *int_value_ptr = MAX_OPTION_COUNT; + *int_value_ptr = kds_s2000w_option_descriptors_get_max_option_count(); return; } diff --git a/src/kds_s2000w_option_descriptors.c b/src/kds_s2000w_option_descriptors.c index 4ff7a6f..3f910ac 100644 --- a/src/kds_s2000w_option_descriptors.c +++ b/src/kds_s2000w_option_descriptors.c @@ -4,7 +4,10 @@ #include "kds_s2000w_option_descriptors.h" #include "kds_s2000w_debug.h" +#define FULL_PROFILE_MAX_OPTION_COUNT 47 + option_descriptor** descriptors = NULL; +uint8_t max_option_count = 0; SANE_Option_Descriptor _kds_s2000w_option_descriptor_standard_group() { @@ -1109,8 +1112,10 @@ SANE_Option_Descriptor _kds_s2000w_option_descriptor_feeder_group() void _kds_s2000w_option_descriptors_init_full_profile() { - descriptors = malloc(sizeof(option_descriptor*) * MAX_OPTION_COUNT); - for (int i = 0; i < MAX_OPTION_COUNT; i++) { + max_option_count = FULL_PROFILE_MAX_OPTION_COUNT; + + descriptors = malloc(sizeof(option_descriptor*) * max_option_count); + for (int i = 0; i < max_option_count; i++) { descriptors[i] = malloc(sizeof(option_descriptor)); } @@ -1222,7 +1227,7 @@ void kds_s2000w_option_descriptors_free() { kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_free_option_descriptors"); - for (int i = 0; i < MAX_OPTION_COUNT; i++) { + for (int i = 0; i < max_option_count; i++) { if (descriptors[i]->descriptor.constraint_type == SANE_CONSTRAINT_STRING_LIST) { free((void*) descriptors[i]->descriptor.constraint.string_list); descriptors[i]->descriptor.constraint.string_list = NULL; @@ -1246,11 +1251,16 @@ void kds_s2000w_option_descriptors_free() descriptors = NULL; } +uint8_t kds_s2000w_option_descriptors_get_max_option_count() +{ + return max_option_count; +} + option_descriptor* kds_s2000w_option_descriptor_full_get_by_number(uint32_t number) { kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_full_get_by_number"); - if (number >= MAX_OPTION_COUNT) + if (number >= max_option_count) return NULL; return descriptors[number]; @@ -1260,7 +1270,7 @@ SANE_Option_Descriptor* kds_s2000w_option_descriptors_get_by_number(uint32_t num { kds_s2000w_debug_printf(ALL, "kds_s2000w_option_get_descriptor"); - if (number >= MAX_OPTION_COUNT) + if (number >= max_option_count) return NULL; return &descriptors[number]->descriptor; @@ -1270,7 +1280,7 @@ SANE_Option_Descriptor* kds_s2000w_option_descriptors_get_by_name(const char* na { kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_get_by_name"); - for (int i = 0; i < MAX_OPTION_COUNT; i++) { + for (int i = 0; i < max_option_count; i++) { if (strcmp(descriptors[i]->descriptor.name, name) == 0) return &descriptors[i]->descriptor; } diff --git a/src/kds_s2000w_option_descriptors.h b/src/kds_s2000w_option_descriptors.h index 3523e2f..0d8f259 100644 --- a/src/kds_s2000w_option_descriptors.h +++ b/src/kds_s2000w_option_descriptors.h @@ -3,7 +3,6 @@ #include #include -#define MAX_OPTION_COUNT 47 #define OPTION_COUNT "OptionCount" #define STANDARD_GROUP_NUMBER 1 @@ -76,6 +75,7 @@ typedef struct { void kds_s2000w_option_descriptors_init(uint8_t profile); void kds_s2000w_option_descriptors_free(); +uint8_t kds_s2000w_option_descriptors_get_max_option_count(); option_descriptor* kds_s2000w_option_descriptor_full_get_by_number(uint32_t number); SANE_Option_Descriptor* kds_s2000w_option_descriptors_get_by_number(uint32_t number); SANE_Option_Descriptor* kds_s2000w_option_descriptors_get_by_name(const char* name); diff --git a/tests/kds_s2000w_net_get_opt_tests.c b/tests/kds_s2000w_net_get_opt_tests.c index 7fb0fdc..8f81281 100644 --- a/tests/kds_s2000w_net_get_opt_tests.c +++ b/tests/kds_s2000w_net_get_opt_tests.c @@ -7,7 +7,7 @@ #include "../src/kds_s2000w_net.h" #include "../src/kds_s2000w_handler.h" -#define MAX_OPTION_COUNT 47 +#define FULL_PROFILE_MAX_OPTION_COUNT 47 void sane_kds_s2000w_net_control_get_option_zero_test(void** state) { @@ -23,7 +23,7 @@ void sane_kds_s2000w_net_control_get_option_zero_test(void** state) sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(value, MAX_OPTION_COUNT); + assert_int_equal(value, FULL_PROFILE_MAX_OPTION_COUNT); kds_s2000w_handler_free(h); h = NULL; diff --git a/tests/kds_s2000w_option_descriptor_tests.c b/tests/kds_s2000w_option_descriptor_tests.c index 8e40f1f..31b5b23 100644 --- a/tests/kds_s2000w_option_descriptor_tests.c +++ b/tests/kds_s2000w_option_descriptor_tests.c @@ -4,8 +4,6 @@ #include "kds_s2000w_client_mock.h" #include "../src/kds_s2000w_option_descriptors.h" -#define MAX_OPTION_COUNT 47 - int setup(void** state) { kds_s2000w_option_descriptors_init(0); @@ -831,7 +829,9 @@ void kds_s2000w_option_get_descriptor_get_by_name_test() void kds_s2000w_option_get_descriptor_over_max_options_test() { - SANE_Option_Descriptor* option = kds_s2000w_option_descriptors_get_by_number(MAX_OPTION_COUNT); + uint8_t max_option_count = kds_s2000w_option_descriptors_get_max_option_count(); + + SANE_Option_Descriptor* option = kds_s2000w_option_descriptors_get_by_number(max_option_count); assert_null(option); } @@ -845,7 +845,9 @@ void kds_s2000w_option_full_get_descriptor_by_number() void kds_s2000w_option_full_get_descriptor_over_max_options_test() { - option_descriptor* option = kds_s2000w_option_descriptor_full_get_by_number(MAX_OPTION_COUNT); + uint8_t max_option_count = kds_s2000w_option_descriptors_get_max_option_count(); + + option_descriptor* option = kds_s2000w_option_descriptor_full_get_by_number(max_option_count); assert_null(option); } \ No newline at end of file -- 2.47.3