SANE_CAP_AUTOMATIC可通过配置auto(bool)属性来禁用,默认全部属性支持

This commit is contained in:
gb 2023-08-21 11:59:03 +08:00
parent 2a9ae299ee
commit 6ba36aedc2
2 changed files with 23 additions and 5 deletions

View File

@ -1149,6 +1149,9 @@ SANE_Option_Descriptor* hg_sane_middleware::from_json(scanner_handle h, const st
} }
ret->size = bytes; ret->size = bytes;
if (jsn->get_value("auto", bv) && !bv)
ret->cap &= ~SANE_CAP_AUTOMATIC;
if (jsn->get_value("readonly", bv) && bv) if (jsn->get_value("readonly", bv) && bv)
SET_CAP_READONLY(ret->cap) SET_CAP_READONLY(ret->cap)
@ -1478,7 +1481,7 @@ bool hg_sane_middleware::get_current_value(scanner_handle handle, const void* op
return ret; return ret;
} }
void* hg_sane_middleware::get_default_value(scanner_handle handle, const void* option, int* bytes, bool log) void* hg_sane_middleware::get_default_value(scanner_handle handle, const void* option, int* bytes, bool log, bool* can_auto)
{ {
std::string val(get_option_json(handle, (void *)option)); std::string val(get_option_json(handle, (void *)option));
void* data = nullptr; void* data = nullptr;
@ -1487,6 +1490,15 @@ void* hg_sane_middleware::get_default_value(scanner_handle handle, const void* o
if (jsn->attach_text(&val[0]) && if (jsn->attach_text(&val[0]) &&
jsn->get_value("type", val)) jsn->get_value("type", val))
{ {
if (can_auto)
{
bool yes = false;
*can_auto = true;
if (jsn->get_value("auto", yes))
*can_auto = yes;
}
std::string title(hg_sane_middleware::get_string_in_json(jsn, "title")); std::string title(hg_sane_middleware::get_string_in_json(jsn, "title"));
if (val == "bool") if (val == "bool")
{ {
@ -1868,10 +1880,16 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, const void* option, SA
VLOG_MINI_2(LOG_LEVEL_WARNING, "Option %d(%s) call SANE_ACTION_SET_AUTO, we set default value.\n", option, desc->title); VLOG_MINI_2(LOG_LEVEL_WARNING, "Option %d(%s) call SANE_ACTION_SET_AUTO, we set default value.\n", option, desc->title);
int len = 0; int len = 0;
void* val = get_default_value(handle, option, &len); bool can_auto = true;
void* val = get_default_value(handle, option, &len, false, &can_auto);
if (!val || !can_auto)
{
if(val)
local_utility::free_memory(val);
if (!val)
return SANE_STATUS_UNSUPPORTED; return SANE_STATUS_UNSUPPORTED;
}
if (value) if (value)
{ {

View File

@ -150,7 +150,7 @@ class hg_sane_middleware
void reload_current_value(scanner_handle handle, std::vector<std::string>* changed = NULL); void reload_current_value(scanner_handle handle, std::vector<std::string>* changed = NULL);
bool get_current_value(scanner_handle handle, const void* option, void(*setv)(void*, size_t, void*), void* value, SANE_Value_Type* type = NULL); bool get_current_value(scanner_handle handle, const void* option, void(*setv)(void*, size_t, void*), void* value, SANE_Value_Type* type = NULL);
void* get_default_value(scanner_handle handle, const void* option, int* bytes = nullptr, bool log = false); // caller should call local_utility::free_memory to free the returned value void* get_default_value(scanner_handle handle, const void* option, int* bytes = nullptr, bool log = false, bool* can_auto = nullptr); // caller should call local_utility::free_memory to free the returned value
/// <summary> /// <summary>
/// 关联项处理 /// 关联项处理