From 2417ae38c9c6056f5675f6703c4ad835241c5fa2 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 10 Mar 2024 16:40:15 +0100 Subject: [PATCH] change config read from one global variable --- src/kds_s2000w_handler.c | 3 ++- src/kds_s2000w_handler_opts.c | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index 577cfb1..ddf10ff 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -10,7 +10,6 @@ #include "kds_s2000w_debug.h" json_object* resp_config = NULL; -json_object* config = NULL; void _get_current_metadata(handler* h) { @@ -18,6 +17,7 @@ void _get_current_metadata(handler* h) json_object* metadataResp = NULL; json_object* metadata = NULL; json_object* mdata_value = NULL; + json_object* config = NULL; blobdata* jpg_image = NULL; blobdata* pnm_image = NULL; response* resp = NULL; @@ -55,6 +55,7 @@ void _get_current_metadata(handler* h) json_object_put(metadataResp); metadata = NULL; + config = json_object_object_get(resp_config, "Configuration"); metadata = json_object_object_get(config, "ColorMode"); const char* color_value = json_object_get_string(metadata); mdata_value = NULL; diff --git a/src/kds_s2000w_handler_opts.c b/src/kds_s2000w_handler_opts.c index 0466f74..6232f8d 100644 --- a/src/kds_s2000w_handler_opts.c +++ b/src/kds_s2000w_handler_opts.c @@ -9,7 +9,6 @@ #define COUNT_CUSTOM_OPTIONS 2 extern json_object* resp_config; -extern json_object* config; void _write_string_value(json_object* value_object, void* value) { @@ -46,7 +45,6 @@ void _load_options(handler* h) resp = kds_s2000w_client_response_init(); int result = kds_s2000w_client_get_option(h->sessionid, resp); resp_config = json_tokener_parse(resp->data); - config = json_object_object_get(resp_config, "Configuration"); if (result != 0 || resp->code != 200) { debug_printf_int(ERROR, "load options response code", resp->code); @@ -63,11 +61,15 @@ void _load_options(handler* h) void kds_s2000w_handler_get_option(handler* h, int option, void* value, int* info) { - config = json_object_object_get(resp_config, "Configuration"); + json_object* config = NULL; json_object* value_object = NULL; + if (resp_config != NULL) + config = json_object_object_get(resp_config, "Configuration"); + switch(option) { case 0: _load_options(h); + config = json_object_object_get(resp_config, "Configuration"); int* int_value_ptr = (int*) value; *int_value_ptr = json_object_object_length(config) + COUNT_CUSTOM_OPTIONS; break; @@ -168,6 +170,7 @@ void kds_s2000w_handler_set_option(handler* h, int option, void* value, int* inf json_object* default_values = NULL; json_object* autostart = NULL; json_object* default_config = NULL; + json_object* config = NULL; config = json_object_object_get(resp_config, "Configuration"); -- 2.39.5