diff --git a/hgsane/sane_hg_mdw.cpp b/hgsane/sane_hg_mdw.cpp index 6375078..b0f942c 100644 --- a/hgsane/sane_hg_mdw.cpp +++ b/hgsane/sane_hg_mdw.cpp @@ -1114,7 +1114,7 @@ bool hg_sane_middleware::get_current_value(scanner_handle handle, int option, vo return ret; } -void* hg_sane_middleware::get_default_value(scanner_handle handle, int option) +void* hg_sane_middleware::get_default_value(scanner_handle handle, int option, int* bytes) { std::string val(get_option_json(handle, option)); void* data = nullptr; @@ -1128,8 +1128,10 @@ void* hg_sane_middleware::get_default_value(scanner_handle handle, int option) bool v = false; jsn->get_value("default", v); - data = local_utility::acquire_memory(/*sizeof(v)*/4, ""); + data = local_utility::acquire_memory(sizeof(SANE_Bool), ""); memcpy(data, &v, sizeof(v)); + if (bytes) + *bytes = sizeof(SANE_Bool); VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %s\n", option, v ? "true" : "false"); } else if (val == "int") @@ -1139,6 +1141,8 @@ void* hg_sane_middleware::get_default_value(scanner_handle handle, int option) data = local_utility::acquire_memory(sizeof(v), ""); memcpy(data, &v, sizeof(v)); + if (bytes) + *bytes = sizeof(v); VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %d\n", option, v); } else if (val == "float") @@ -1148,6 +1152,8 @@ void* hg_sane_middleware::get_default_value(scanner_handle handle, int option) SANE_Fixed sd = hg_sane_middleware::double_2_sane_fixed(v); data = local_utility::acquire_memory(sizeof(sd), ""); + if (bytes) + *bytes = sizeof(sd); memcpy(data, &sd, sizeof(sd)); VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %f\n", option, v); @@ -1164,6 +1170,8 @@ void* hg_sane_middleware::get_default_value(scanner_handle handle, int option) size = val.length(); data = local_utility::acquire_memory(size + 4, ""); strcpy((char*)data, val.c_str()); + if (bytes) + *bytes = val.length(); VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %s\n", option, (char*)data); } else @@ -1519,26 +1527,26 @@ bool hg_sane_middleware::get_cur_value(SANE_Handle handle, int option, void* val return get_current_value(h, option, value, type); } -void* hg_sane_middleware::get_def_value(SANE_Handle handle, int option) +void* hg_sane_middleware::get_def_value(SANE_Handle handle, int option, int* bytes) { scanner_handle h = find_openning_device(handle); if (!h) return NULL; - return get_default_value(h, option); + return get_default_value(h, option, bytes); } SANE_Status hg_sane_middleware::io_control(SANE_Handle h, unsigned long code, void* data, unsigned* len) { OPENDEV od; scanner_handle handle = find_openning_device(h, false, &od); + int ret = SANE_STATUS_GOOD; // commented at 2022-03-23 for getting app about info before open any device // //if (!handle) // return SANE_STATUS_INVAL; - - int ret = hg_scanner_control(handle, code, data, len); + ret = hg_scanner_control(handle, code, data, len); if (ret == SCANNER_ERR_CONFIGURATION_CHANGED) { int nc = code; diff --git a/hgsane/sane_hg_mdw.h b/hgsane/sane_hg_mdw.h index d4811f6..194eaf5 100644 --- a/hgsane/sane_hg_mdw.h +++ b/hgsane/sane_hg_mdw.h @@ -82,7 +82,7 @@ class hg_sane_middleware void reload_current_value(scanner_handle handle, std::vector* changed = NULL); bool get_current_value(scanner_handle handle, int option, void* value, SANE_Value_Type* type = NULL); - void* get_default_value(scanner_handle handle, int option); // caller should call local_utility::free_memory to free the returned value + void* get_default_value(scanner_handle handle, int option, int* bytes = nullptr); // caller should call local_utility::free_memory to free the returned value /// /// 关联项处理 @@ -188,7 +188,7 @@ public: SANE_Option_Descriptor* get_option_descriptor(SANE_Handle h, SANE_Int option); SANE_Status set_option(SANE_Handle h, SANE_Int option, SANE_Action action, void* value, SANE_Int* after_do); bool get_cur_value(SANE_Handle handle, int option, void* value, SANE_Value_Type* type = NULL); // SANE_type - void* get_def_value(SANE_Handle handle, int option); // caller should call local_utility::free_memory to free the returned value, SANE_type + void* get_def_value(SANE_Handle handle, int option, int* bytes = nullptr); // caller should call local_utility::free_memory to free the returned value, SANE_type // extension ... SANE_Status io_control(SANE_Handle h, unsigned long code, void* data, unsigned* len);