]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change option count internal module
authorBastian Dehn <hhaalo@arcor.de>
Tue, 23 Sep 2025 10:28:12 +0000 (12:28 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 23 Sep 2025 10:28:12 +0000 (12:28 +0200)
src/kds_s2000w_handler_opts.c
src/kds_s2000w_option_descriptors.c
src/kds_s2000w_option_descriptors.h
tests/kds_s2000w_net_get_opt_tests.c
tests/kds_s2000w_option_descriptor_tests.c

index cbb74109ca4733f485d522ae322f4f8e696c4db2..b2518e5bfa6e6769680c39075db5a118bd0c88a0 100644 (file)
@@ -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;
        }
 
index 4ff7a6fef8e24d7f95e9fd534cb31bb9c034d863..3f910ac92b416b48ef182e502e4c02936885a52d 100644 (file)
@@ -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;
        }
index 3523e2fdcaddcac993b8e7e390be02dde918e376..0d8f2590e89b0b74a6c61083835e7fe41d40aae6 100644 (file)
@@ -3,7 +3,6 @@
 #include <stdint.h>
 #include <sane/sane.h>
 
-#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);
index 7fb0fdc4caa3a6df53d322342836800aa846bd5c..8f812816f7bd1cd8f1ea6db4f72bfc9d8520b52e 100644 (file)
@@ -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;
index 8e40f1f8082953173f19da31e5109f1e2a2f18e7..31b5b23c20015a286c41ae9c8445facef55965a0 100644 (file)
@@ -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