]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add parameter get metadata in handler
authorBastian Dehn <hhaalo@arcor.de>
Thu, 1 Feb 2024 16:54:58 +0000 (17:54 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 1 Feb 2024 16:54:58 +0000 (17:54 +0100)
src/kds_s2000w_handler.c
src/kds_s2000w_handler.h

index 64042231c454801d8aa6f3f9005801f81db089b3..c57e0bec4e65b925bb690db9c2f9b1d2c8d50897 100644 (file)
@@ -10,7 +10,7 @@
 
 response* resp = NULL;
 current_state* state = NULL;
-json_object* resObj = NULL;
+json_object* resp_config = NULL;
 json_object* config = NULL;
 
 void _write_string_value(json_object* value_object, void* value)
@@ -41,19 +41,19 @@ void _write_int_value_to_json(json_object* value_object, void* value)
 
 void _load_options()
 {
-       json_object_put(resObj);
-       resObj = NULL;
+       json_object_put(resp_config);
+       resp_config = 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");
+       resp_config = json_tokener_parse(resp->data);
+       config = json_object_object_get(resp_config, "Configuration");
 
        if (result != 0 || resp->code == 404) {
                kds_s2000w_client_response_free(resp);
                resp = NULL;
-               json_object_put(resObj);
-               resObj = NULL;
+               json_object_put(resp_config);
+               resp_config = NULL;
                return;
        }
 
@@ -142,16 +142,16 @@ current_state* kds_s2000w_handler_open()
        }
 
        if (resp->code == 200) {
-               resObj = json_tokener_parse(resp->data);
+               resp_config = json_tokener_parse(resp->data);
                json_object* value_object = NULL;
-               json_object_object_get_ex(resObj, "SessionId", &value_object);
+               json_object_object_get_ex(resp_config, "SessionId", &value_object);
                state->sessionid = json_object_get_int64(value_object);
                state->state = OPENED;
                value_object = NULL;
        }
 
-       json_object_put(resObj);
-       resObj = NULL;
+       json_object_put(resp_config);
+       resp_config = NULL;
        kds_s2000w_client_response_free(resp);
        resp = NULL;
 
@@ -168,8 +168,8 @@ void kds_s2000w_handler_close()
        state->sessionid = 0;
        free(state);
        state = NULL;
-       json_object_put(resObj);
-       resObj = NULL;
+       json_object_put(resp_config);
+       resp_config = NULL;
        kds_s2000w_client_response_free(resp);
        resp = NULL;
 }
@@ -181,7 +181,7 @@ current_state* kds_s2000w_handler_current_state()
 
 void kds_s2000w_handler_get_option(int option, void* value)
 {
-       config = json_object_object_get(resObj, "Configuration");
+       config = json_object_object_get(resp_config, "Configuration");
        json_object* value_object = NULL;
        switch(option) {
                case 0:
@@ -284,7 +284,7 @@ void kds_s2000w_handler_get_option(int option, void* value)
 
 void kds_s2000w_handler_set_option(int option, void* value, int* info)
 {
-       config = json_object_object_get(resObj, "Configuration");
+       config = json_object_object_get(resp_config, "Configuration");
        json_object* value_object = NULL;
        switch(option) {
                case 2:
@@ -424,7 +424,7 @@ void kds_s2000w_handler_set_option(int option, void* value, int* info)
                        break;
        }
 
-       const char* json_string = json_object_to_json_string_ext(resObj, JSON_C_TO_STRING_PLAIN);
+       const char* json_string = json_object_to_json_string_ext(resp_config, JSON_C_TO_STRING_PLAIN);
        resp = kds_s2000w_client_response_init();
        resp->size = sizeof(char) * strlen(json_string);
        resp->code = 0;
@@ -454,4 +454,27 @@ void kds_s2000w_handler_stop_scan()
        kds_s2000w_client_stop_scan(state->sessionid, resp);
        kds_s2000w_client_response_free(resp);
        resp = NULL;
+}
+
+metadata kds_s2000w_handler_get_parameters(int image_number)
+{
+       metadata mdata;
+       json_object* metadata = NULL;
+       json_object* mdata_value = NULL;
+       resp = kds_s2000w_client_response_init();
+       kds_s2000w_client_get_metadata(state->sessionid, image_number, resp);
+
+       metadata = json_tokener_parse(resp->data);
+       mdata_value = json_object_object_get(metadata, "BitDepth");
+       mdata.depth = json_object_get_int(mdata_value);
+       mdata_value = NULL;
+       mdata_value = json_object_object_get(metadata, "ImageSize");
+       mdata.size = json_object_get_int(mdata_value);
+       mdata_value = NULL;
+       mdata.format = 1;
+       mdata.is_last = 0;
+
+       json_object_put(metadata);
+       kds_s2000w_client_response_free(resp);
+       resp = NULL;
 }
\ No newline at end of file
index adecdcc1fe11f3707046947c8e4284ef838ececd..d3376aa232f23e04201a77257bd27a6fd64f7243 100644 (file)
@@ -30,4 +30,5 @@ void kds_s2000w_handler_set_option(int option, void* value, int* info);
 void kds_s2000w_handler_set_option_auto(int option);
 void kds_s2000w_handler_start_scan();
 void kds_s2000w_handler_stop_scan();
+metadata kds_s2000w_handler_get_parameters(int image_number);
 #endif
\ No newline at end of file