]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add debug method
authorBastian Dehn <hhaalo@arcor.de>
Fri, 16 Feb 2024 15:23:48 +0000 (16:23 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 16 Feb 2024 15:23:48 +0000 (16:23 +0100)
src/CMakeLists.txt
src/kds_s2000w_debug.c [new file with mode: 0644]
src/kds_s2000w_debug.h [new file with mode: 0644]
src/kds_s2000w_net.c

index 6d40e8fd7d963713becdac37f487958f0593861a..8d3bd61cedcba5d33dc81661c68af646a1a540a4 100644 (file)
@@ -15,7 +15,8 @@ add_library("sane-kds_s2000w_net"
        "kds_s2000w_handler.c"
        "kds_s2000w_handler_opts.c"
        "kds_s2000w_client.c"
-       "kds_s2000w_image_converter.c")
+       "kds_s2000w_image_converter.c"
+       "kds_s2000w_debug.c")
 set_target_properties("sane-kds_s2000w_net" PROPERTIES VERSION 1)
 target_link_libraries("sane-kds_s2000w_net" json-c curl MagickCore-6.Q16 m)
 
diff --git a/src/kds_s2000w_debug.c b/src/kds_s2000w_debug.c
new file mode 100644 (file)
index 0000000..713f82c
--- /dev/null
@@ -0,0 +1,8 @@
+#include <stdio.h>
+#include "kds_s2000w_debug.h"
+
+void debug_printf(int level, const char* message)
+{
+       if (level <= LOGLEVEL)
+               printf("%s\n", message);
+}
diff --git a/src/kds_s2000w_debug.h b/src/kds_s2000w_debug.h
new file mode 100644 (file)
index 0000000..c00d677
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef KDS_S2000w_DEBUG_H
+#define KDS_S2000w_DEBUG_H
+
+#define OFF 0
+#define FATAL 1
+#define ERROR 2
+#define WARN 3
+#define INFO 4
+#define DEBUG 5
+#define ALL 6
+
+#define LOGLEVEL DEBUG
+
+void debug_printf(int level, const char* message);
+#endif
\ No newline at end of file
index c0f665cf5226b4369b793c79badceb9d69f9d5c4..f185cb2c91699b01fcd6f73d60ae1672f49f7dc1 100644 (file)
@@ -5,6 +5,7 @@
 #include <sane/sane.h>
 #include "kds_s2000w_option_descriptors.h"
 #include "kds_s2000w_handler.h"
+#include "kds_s2000w_debug.h"
 
 typedef struct {
        int cancel;
@@ -25,6 +26,7 @@ readinfo* get_read_info()
 
 int _sane_kds_s2000w_net_find_first_data_byte(const char* data)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_find_first_data_byte");
        const int header_spaces = 3;
        const char space = 0x0a;
        int space_count = 0;
@@ -43,6 +45,7 @@ int _sane_kds_s2000w_net_find_first_data_byte(const char* data)
 
 SANE_Status _sane_kds_s2000w_net_init(SANE_Int* version_code, SANE_Auth_Callback authorize)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_init");
        *version_code = SANE_VERSION_CODE(1, 0, 0);
        kds_s2000w_option_descriptor_init_option_descriptors();
        device_info = malloc(sizeof(SANE_Device));
@@ -51,6 +54,7 @@ SANE_Status _sane_kds_s2000w_net_init(SANE_Int* version_code, SANE_Auth_Callback
 
 void _sane_kds_s2000w_net_exit(void)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_exit");
        free(device_info);
        device_info = NULL;
 }
@@ -58,6 +62,7 @@ void _sane_kds_s2000w_net_exit(void)
 SANE_Status _sane_kds_s2000w_net_get_devices(SANE_Device*** device_list,
        SANE_Bool local_only)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_get_devices");
        if (local_only)
                return SANE_STATUS_NO_MEM;
 
@@ -74,6 +79,7 @@ SANE_Status _sane_kds_s2000w_net_get_devices(SANE_Device*** device_list,
 SANE_Status _sane_kds_s2000w_net_open(SANE_String_Const devicename,
        SANE_Handle handle)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_open");
        if (strcmp(devicename, "kds_s2000w_net") != 0)
                return SANE_STATUS_INVAL;
 
@@ -89,6 +95,7 @@ SANE_Status _sane_kds_s2000w_net_open(SANE_String_Const devicename,
 
 void _sane_kds_s2000w_net_close(SANE_Handle handle)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_close");
        kds_s2000w_option_descriptor_free_option_descriptors();
        kds_s2000w_handler_close();
 }
@@ -96,12 +103,14 @@ void _sane_kds_s2000w_net_close(SANE_Handle handle)
 const SANE_Option_Descriptor* _sane_kds_s2000w_net_get_option_descriptor(
        SANE_Handle handle, SANE_Int option)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_get_option_descriptor");
        return kds_s2000w_option_get_descriptor(option);
 }
 
 SANE_Status _sane_kds_s2000w_net_control_option(SANE_Handle handle,
        SANE_Int option, SANE_Action action, void* value, SANE_Int* info)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_control_option");
        if (action == SANE_ACTION_GET_VALUE)
                kds_s2000w_handler_get_option(option, value);
 
@@ -116,6 +125,7 @@ SANE_Status _sane_kds_s2000w_net_control_option(SANE_Handle handle,
 
 void _sane_kds_s2000w_net_cancel(SANE_Handle handle)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_cancel");
        read_info.cancel = 1;
        return;
 }
@@ -123,11 +133,10 @@ void _sane_kds_s2000w_net_cancel(SANE_Handle handle)
 SANE_Status _sane_kds_s2000w_net_get_parameters(SANE_Handle handle,
        SANE_Parameters* params)
 {
-       printf("get parameters 1\n");
+       debug_printf(ALL, "sane_kds_s2000w_net_get_parameters");
        if (!read_info.scan_started)
                return SANE_STATUS_GOOD;
 
-       printf("get parameters 2\n");
        for (int i = 0; i < 10; i++) {
                sleep(1);
                read_info.current_metadata = kds_s2000w_handler_get_parameters();
@@ -136,7 +145,6 @@ SANE_Status _sane_kds_s2000w_net_get_parameters(SANE_Handle handle,
                        break;
        }
 
-       printf("get parameters 3\n");
        if (!read_info.current_metadata.valid)
                return SANE_STATUS_UNSUPPORTED;
 
@@ -155,6 +163,7 @@ SANE_Status _sane_kds_s2000w_net_get_parameters(SANE_Handle handle,
 
 SANE_Status _sane_kds_s2000w_net_start(SANE_Handle handle)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_start");
        if (read_info.scan_started)
                return SANE_STATUS_GOOD;
 
@@ -167,6 +176,7 @@ SANE_Status _sane_kds_s2000w_net_start(SANE_Handle handle)
 SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
        SANE_Int max_length, SANE_Int* length)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_read");
        if (read_info.cancel) {
                read_info.scan_started = 0;
                *length = 0;
@@ -209,15 +219,18 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
 SANE_Status _sane_kds_s2000w_net_set_io_mode(SANE_Handle handle,
        SANE_Bool non_blocking)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_set_io_mode");
        return SANE_STATUS_UNSUPPORTED;
 }
 
 SANE_Status _sane_kds_s2000w_net_get_select_fd(SANE_Handle handle, SANE_Int* fd)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_get_select_fd");
        return SANE_STATUS_UNSUPPORTED;
 }
 
 SANE_String_Const _sane_kds_s2000w_net_strstatus(SANE_Status status)
 {
+       debug_printf(ALL, "sane_kds_s2000w_net_strstatus");
        return "not implemended";
 }
\ No newline at end of file