#include "kds_s2000w_client.h"
int64_t _sessionid = 0;
+json_object* _all_options = NULL;
+
+void _get_all_options()
+{
+ response* resp = kds_s2000w_client_response_init();
+ int result = kds_s2000w_client_get_all_options(resp);
+
+ if (result != 0 || resp->code == 404)
+ return;
+
+ _all_options = json_tokener_parse(resp->data);
+ kds_s2000w_client_response_free(resp);
+ resp = NULL;
+}
device_state kds_s2000w_handler_open()
{
kds_s2000w_client_close_session(_sessionid);
_sessionid = 0;
+ json_object_put(_all_options);
+ _all_options = NULL;
}
void kds_s2000w_handler_get_option(int option, void* value)
if (option != 0)
return;
- response* resp = kds_s2000w_client_response_init();
- int result = kds_s2000w_client_get_all_options(resp);
+ if (option == 0)
+ _get_all_options();
- if (result != 0 || resp->code == 404)
+ if (_all_options == NULL)
return;
- json_object* resObj = json_tokener_parse(resp->data);
- json_object* config = json_object_object_get(resObj, "Configuration");
+ json_object* config = json_object_object_get(_all_options, "Configuration");
int* num_options = (int*) value;
*num_options = 0;
*num_options = json_object_object_length(config);
*num_options++;
-
- kds_s2000w_client_response_free(resp);
}
void kds_s2000w_handler_set_option(int option, void* value)