From 5e2d6cc2447ec8e6f296a0e566040e92a687ab86 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Fri, 16 Feb 2024 16:23:48 +0100 Subject: [PATCH] add debug method --- src/CMakeLists.txt | 3 ++- src/kds_s2000w_debug.c | 8 ++++++++ src/kds_s2000w_debug.h | 15 +++++++++++++++ src/kds_s2000w_net.c | 19 ++++++++++++++++--- 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 src/kds_s2000w_debug.c create mode 100644 src/kds_s2000w_debug.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6d40e8f..8d3bd61 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 index 0000000..713f82c --- /dev/null +++ b/src/kds_s2000w_debug.c @@ -0,0 +1,8 @@ +#include +#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 index 0000000..c00d677 --- /dev/null +++ b/src/kds_s2000w_debug.h @@ -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 diff --git a/src/kds_s2000w_net.c b/src/kds_s2000w_net.c index c0f665c..f185cb2 100644 --- a/src/kds_s2000w_net.c +++ b/src/kds_s2000w_net.c @@ -5,6 +5,7 @@ #include #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 -- 2.39.5