]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
set autostart with one method in handler only one load config
authorBastian Dehn <hhaalo@arcor.de>
Sat, 28 Dec 2024 12:58:02 +0000 (13:58 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 28 Dec 2024 16:32:13 +0000 (17:32 +0100)
src/kds_s2000w_handler_opts.c
tests/kds_s2000w_net_get_opt_tests.c

index c82ba75cb9828ca528c0d4ce7babfeeec5012ed4..a5be246e3c4bf5a0d214a9c0454db81244969e99 100644 (file)
@@ -5,8 +5,7 @@
 #include "kds_s2000w_handler_opts.h"
 #include "kds_s2000w_debug.h"
 
-#define AUTOSTART_ALWAYS_ON 1
-#define COUNT_CUSTOM_OPTIONS 0
+#define AUTOSTART_ON 1
 
 void _write_string_value(json_object* value_object, void* value)
 {
@@ -56,34 +55,30 @@ void _load_options(handler* h)
        resp = NULL;
 }
 
+void _set_autostart_on(handler* h)
+{
+       int auto_start_value = AUTOSTART_ON;
+       json_object* config = json_object_object_get(h->current_scanner_config, "Configuration");
+       json_object* value_object = json_object_object_get(config, "AutoStart");
+       _write_int_value_to_json(value_object, &auto_start_value);
+}
+
 void _set_option_to_default(handler* h)
 {
        response* resp = kds_s2000w_client_response_init();
        kds_s2000w_client_get_capabilities(resp);
        json_object* capabilities = json_tokener_parse(resp->data);
        json_object* default_values = json_object_object_get(capabilities, "Defaults");
-       json_object* autostart = json_object_object_get(default_values, "AutoStart");
-       json_object_set_int(autostart, AUTOSTART_ALWAYS_ON);
        json_object* default_config = json_object_new_object();
        json_object_object_add(default_config, "Configuration", default_values);
 
-       const char* json_string = json_object_to_json_string_ext(default_config, JSON_C_TO_STRING_PLAIN);
-       kds_s2000w_client_response_free(resp);
-       resp = NULL;
+       json_object_put(h->current_scanner_config);
+       h->current_scanner_config = NULL;
 
-       resp = kds_s2000w_client_response_init();
-       resp->size = sizeof(char) * strlen(json_string);
-       resp->code = 0;
-       resp->data = realloc(resp->data, resp->size);
-       resp->data = memcpy(resp->data, json_string, resp->size);
-       kds_s2000w_client_set_option(h->sessionid, resp);
-       if (resp->code != 200)
-               debug_printf_int(ERROR, "set options response code", resp->code);
+       h->current_scanner_config = default_config;
 
        kds_s2000w_client_response_free(resp);
        resp = NULL;
-       json_object_put(capabilities);
-       capabilities = NULL;
 }
 
 void _set_options(handler* h)
@@ -107,9 +102,11 @@ void kds_s2000w_handler_get_option(handler* h, int option, void* value, int* inf
        json_object* config = NULL;
        json_object* value_object = NULL;
 
-       if (h->current_scan_status->load_options == 0 && option > 0) {
+       if (h->current_scan_status->load_options < 1) {
                h->current_scan_status->load_options = 1;
                _load_options(h);
+               _set_autostart_on(h);
+               _set_options(h);
        }
 
        if (h->current_scanner_config != NULL)
@@ -117,10 +114,9 @@ void kds_s2000w_handler_get_option(handler* h, int option, void* value, int* inf
 
        switch(option) {
                case 0:
-                       _load_options(h);
                        config = json_object_object_get(h->current_scanner_config, "Configuration");
                        int* int_value_ptr = (int*) value;
-                       *int_value_ptr = json_object_object_length(config) + COUNT_CUSTOM_OPTIONS;
+                       *int_value_ptr = json_object_object_length(config);
                        debug_printf_int(DEBUG, "option numbers", *int_value_ptr);
                        break;
                case 2:
@@ -218,14 +214,11 @@ void kds_s2000w_handler_set_option(handler* h, int option, void* value, int* inf
        if (h->current_scan_status->load_options == 0 && option > 0) {
                h->current_scan_status->load_options = 1;
                _load_options(h);
+               _set_autostart_on(h);
        }
 
        json_object* config = json_object_object_get(h->current_scanner_config, "Configuration");
-
-       int autostart_value = AUTOSTART_ALWAYS_ON;
-       json_object* value_object = json_object_object_get(config, "AutoStart");
-       _write_int_value_to_json(value_object, &autostart_value);
-       value_object = NULL;
+       json_object* value_object = NULL;
 
        switch(option) {
                case 2:
@@ -318,11 +311,10 @@ void kds_s2000w_handler_set_option(handler* h, int option, void* value, int* inf
                        break;
                case 21:
                        _set_option_to_default(h);
+                       _set_autostart_on(h);
 
                        if (info != NULL)
                                *info = RELOAD_OPTIONS | RELOAD_PARAMS;
-
-                       _load_options(h);
                        return;
                        break;
                default:
index 2cc3599ce5b083b3a914efc9c41d55dd83c2d27d..61dc299d120b7ddbc2fa04cebf6d81b9b7bf6214 100644 (file)
@@ -29,7 +29,10 @@ void sane_kds_s2000w_net_control_get_option_zero(void** state)
        response* resp = (response*) *state;
        will_return(mock_response, resp);
        will_return(__wrap_kds_s2000w_client_get_option, 0);
+       will_return(mock_response, resp);
+       will_return(__wrap_kds_s2000w_client_set_option, 0);
        expect_function_call(__wrap_kds_s2000w_client_get_option);
+       expect_function_call(__wrap_kds_s2000w_client_set_option);
        handler* h = init_handler();
        int value = 0;
 
@@ -43,11 +46,10 @@ void sane_kds_s2000w_net_control_get_option_zero(void** state)
 
 void sane_kds_s2000w_net_control_get_option_two(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        char value[50] = {0};
 
        _sane_kds_s2000w_net_control_option(h, 2, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -61,11 +63,10 @@ void sane_kds_s2000w_net_control_get_option_two(void** state)
 
 void sane_kds_s2000w_net_control_get_option_three(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        char value[50] = {0};
 
        _sane_kds_s2000w_net_control_option(h, 3, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -78,11 +79,10 @@ void sane_kds_s2000w_net_control_get_option_three(void** state)
 
 void sane_kds_s2000w_net_control_get_option_four(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        int value = 0;
 
        _sane_kds_s2000w_net_control_option(h, 4, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -95,12 +95,10 @@ void sane_kds_s2000w_net_control_get_option_four(void** state)
 
 void sane_kds_s2000w_net_control_get_option_five(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
-
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        char value[50] = {0};
 
        _sane_kds_s2000w_net_control_option(h, 5, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -113,11 +111,10 @@ void sane_kds_s2000w_net_control_get_option_five(void** state)
 
 void sane_kds_s2000w_net_control_get_option_seven(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        int value = -1;
 
        _sane_kds_s2000w_net_control_option(h, 7, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -130,11 +127,10 @@ void sane_kds_s2000w_net_control_get_option_seven(void** state)
 
 void sane_kds_s2000w_net_control_get_option_eight(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        char value[50] = {0};
 
        _sane_kds_s2000w_net_control_option(h, 8, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -147,11 +143,10 @@ void sane_kds_s2000w_net_control_get_option_eight(void** state)
 
 void sane_kds_s2000w_net_control_get_option_nine(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        int value = -1;
 
        _sane_kds_s2000w_net_control_option(h, 9, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -164,11 +159,10 @@ void sane_kds_s2000w_net_control_get_option_nine(void** state)
 
 void sane_kds_s2000w_net_control_get_option_ten(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        char value[50] = {0};
 
        _sane_kds_s2000w_net_control_option(h, 10, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -181,11 +175,10 @@ void sane_kds_s2000w_net_control_get_option_ten(void** state)
 
 void sane_kds_s2000w_net_control_get_option_eleven(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        char value[50] = {0};
 
        _sane_kds_s2000w_net_control_option(h, 11, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -198,11 +191,10 @@ void sane_kds_s2000w_net_control_get_option_eleven(void** state)
 
 void sane_kds_s2000w_net_control_get_option_twelve(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        int value = -1;
 
        _sane_kds_s2000w_net_control_option(h, 12, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -215,11 +207,10 @@ void sane_kds_s2000w_net_control_get_option_twelve(void** state)
 
 void sane_kds_s2000w_net_control_get_option_thirdteen(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        int value = -1;
 
        _sane_kds_s2000w_net_control_option(h, 13, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -232,11 +223,10 @@ void sane_kds_s2000w_net_control_get_option_thirdteen(void** state)
 
 void sane_kds_s2000w_net_control_get_option_fourteen(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        int value = -1;
 
        _sane_kds_s2000w_net_control_option(h, 14, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -249,11 +239,10 @@ void sane_kds_s2000w_net_control_get_option_fourteen(void** state)
 
 void sane_kds_s2000w_net_control_get_option_fifteen(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        int value = -1;
 
        _sane_kds_s2000w_net_control_option(h, 15, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -266,11 +255,10 @@ void sane_kds_s2000w_net_control_get_option_fifteen(void** state)
 
 void sane_kds_s2000w_net_control_get_option_sixteen(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        char value[50] = {0};
 
        _sane_kds_s2000w_net_control_option(h, 16, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -283,11 +271,10 @@ void sane_kds_s2000w_net_control_get_option_sixteen(void** state)
 
 void sane_kds_s2000w_net_control_get_option_seventeen(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        int value = -1;
 
        _sane_kds_s2000w_net_control_option(h, 17, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -300,11 +287,10 @@ void sane_kds_s2000w_net_control_get_option_seventeen(void** state)
 
 void sane_kds_s2000w_net_control_get_option_eightteen(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        char value[50] = {0};
 
        _sane_kds_s2000w_net_control_option(h, 18, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -317,11 +303,10 @@ void sane_kds_s2000w_net_control_get_option_eightteen(void** state)
 
 void sane_kds_s2000w_net_control_get_option_nineteen(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        int value = -1;
 
        _sane_kds_s2000w_net_control_option(h, 19, SANE_ACTION_GET_VALUE, &value, NULL);
@@ -334,11 +319,10 @@ void sane_kds_s2000w_net_control_get_option_nineteen(void** state)
 
 void sane_kds_s2000w_net_control_get_option_twenty(void** state)
 {
-       response* resp = (response*) *state;
-       will_return(mock_response, resp);
-       will_return(__wrap_kds_s2000w_client_get_option, 0);
-       expect_function_call(__wrap_kds_s2000w_client_get_option);
        handler* h = init_handler();
+       h->current_scan_status->load_options = 1;
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
        int value = -1;
 
        _sane_kds_s2000w_net_control_option(h, 20, SANE_ACTION_GET_VALUE, &value, NULL);