#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <json-c/json.h>
#include <math.h>
#include "kds_s2000w_handler.h"
#include "kds_s2000w_handler_opts.h"
#include "kds_s2000w_image_converter.h"
#include "kds_s2000w_debug.h"
-json_object* resp_config = NULL;
-
void _get_current_metadata(handler* h)
{
debug_printf(ALL, "get_current_metadata");
json_object_put(metadataResp);
metadata = NULL;
- config = json_object_object_get(resp_config, "Configuration");
+ config = json_object_object_get(h->current_scanner_config, "Configuration");
metadata = json_object_object_get(config, "ColorMode");
const char* color_value = json_object_get_string(metadata);
mdata_value = NULL;
{
debug_printf(ALL, "init handler");
handler* h = malloc(sizeof(handler));
+ h->current_scanner_config = NULL;
h->current_scan_status = malloc(sizeof(scanstatus));
h->current_metadata = malloc(sizeof(metadata));
h->read_info = malloc(sizeof(readinfo));
void free_handler(handler* h)
{
debug_printf(ALL, "free handler");
+ json_object_put(h->current_scanner_config);
+ h->current_scanner_config = NULL;
free(h->current_scan_status);
h->current_scan_status = NULL;
free(h->current_metadata);
// set old config parameters
kds_s2000w_client_response_free(resp);
resp = NULL;
- const char* json_string = json_object_to_json_string_ext(resp_config, JSON_C_TO_STRING_PLAIN);
+ const char* json_string = json_object_to_json_string_ext(h->current_scanner_config, JSON_C_TO_STRING_PLAIN);
resp = kds_s2000w_client_response_init();
resp->size = sizeof(char) * strlen(json_string);
resp->code = 0;
}
if (resp->code == 200) {
- resp_config = json_tokener_parse(resp->data);
- json_object_object_get_ex(resp_config, "SessionId", &value_object);
+ h->current_scanner_config = json_tokener_parse(resp->data);
+ json_object_object_get_ex(h->current_scanner_config, "SessionId", &value_object);
h->sessionid = json_object_get_int64(value_object);
h->state = OPENED;
debug_printf_long(INFO, "SessionId", h->sessionid);
value_object = NULL;
}
- json_object_put(resp_config);
- resp_config = NULL;
+ json_object_put(h->current_scanner_config);
+ h->current_scanner_config = NULL;
kds_s2000w_client_response_free(resp);
resp = NULL;
}
void kds_s2000w_handler_close(handler* h)
{
debug_printf(ALL, "kds_s2000w_handler_close");
- json_object_put(resp_config);
- resp_config = NULL;
+ json_object_put(h->current_scanner_config);
+ h->current_scanner_config = NULL;
if (h == NULL)
return;
#define AUTOSTART_ALWAYS_ON 1
#define COUNT_CUSTOM_OPTIONS 2
-extern json_object* resp_config;
-
void _write_string_value(json_object* value_object, void* value)
{
const char* string_value = json_object_get_string(value_object);
void _load_options(handler* h)
{
- json_object_put(resp_config);
- resp_config = NULL;
+ json_object_put(h->current_scanner_config);
+ h->current_scanner_config = NULL;
response* resp = NULL;
resp = kds_s2000w_client_response_init();
int result = kds_s2000w_client_get_option(h->sessionid, resp);
- resp_config = json_tokener_parse(resp->data);
+ h->current_scanner_config = json_tokener_parse(resp->data);
if (result != 0 || resp->code != 200) {
debug_printf_int(ERROR, "load options response code", resp->code);
kds_s2000w_client_response_free(resp);
resp = NULL;
- json_object_put(resp_config);
- resp_config = NULL;
+ json_object_put(h->current_scanner_config);
+ h->current_scanner_config = NULL;
return;
}
{
json_object* config = NULL;
json_object* value_object = NULL;
- if (resp_config != NULL)
- config = json_object_object_get(resp_config, "Configuration");
+ if (h->current_scanner_config != NULL)
+ config = json_object_object_get(h->current_scanner_config, "Configuration");
switch(option) {
case 0:
_load_options(h);
- config = json_object_object_get(resp_config, "Configuration");
+ 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;
debug_printf_int(DEBUG, "option numbers", *int_value_ptr);
json_object* default_config = NULL;
json_object* config = NULL;
- config = json_object_object_get(resp_config, "Configuration");
+ config = json_object_object_get(h->current_scanner_config, "Configuration");
int autostart_value = AUTOSTART_ALWAYS_ON;
value_object = json_object_object_get(config, "AutoStart");
break;
}
- const char* json_string = json_object_to_json_string_ext(resp_config, JSON_C_TO_STRING_PLAIN);
+ const char* json_string = json_object_to_json_string_ext(h->current_scanner_config, JSON_C_TO_STRING_PLAIN);
resp = kds_s2000w_client_response_init();
resp->size = sizeof(char) * strlen(json_string);
resp->code = 0;