From: Bastian Dehn Date: Sun, 28 Jan 2024 20:49:49 +0000 (+0100) Subject: refactor load options method X-Git-Tag: v1.0.0^2~392 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=a5932a4120663b8e9bbcee8e2f058bca24413232;p=sane-kds-s2000w-net.git refactor load options method --- diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index f21bf00..c59962b 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -38,6 +38,28 @@ void _write_int_value_to_json(json_object* value_object, void* value) json_object_set_int(value_object, *int_value_ptr); } +void _load_options() +{ + json_object_put(resObj); + resObj = NULL; + + resp = kds_s2000w_client_response_init(); + int result = kds_s2000w_client_get_option(state->sessionid, resp); + resObj = json_tokener_parse(resp->data); + config = json_object_object_get(resObj, "Configuration"); + + if (result != 0 || resp->code == 404) { + kds_s2000w_client_response_free(resp); + resp = NULL; + json_object_put(resObj); + resObj = NULL; + return; + } + + kds_s2000w_client_response_free(resp); + resp = NULL; +} + current_state* kds_s2000w_handler_open() { state = malloc(sizeof(current_state)); @@ -102,23 +124,9 @@ void kds_s2000w_handler_get_option(int option, void* value) json_object* value_object = NULL; switch(option) { case 0: - resp = kds_s2000w_client_response_init(); - int result = kds_s2000w_client_get_option(state->sessionid, resp); - resObj = json_tokener_parse(resp->data); - config = json_object_object_get(resObj, "Configuration"); - - if (result != 0 || resp->code == 404) { - kds_s2000w_client_response_free(resp); - resp = NULL; - json_object_put(resObj); - resObj = NULL; - return; - } - + _load_options(); int* int_value_ptr = (int*) value; *int_value_ptr = json_object_object_length(config) + 3; - kds_s2000w_client_response_free(resp); - resp = NULL; break; case 2: value_object = json_object_object_get(config, "DPI"); @@ -330,7 +338,10 @@ void kds_s2000w_handler_set_option(int option, void* value, int* info) resp = NULL; json_object_put(capabilities); + capabilities = NULL; *info = RELOAD_OPTIONS; + _load_options(); + return; break; default: break;