#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)
{
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)
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)
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:
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:
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:
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;
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);