获取默认函数增加长度参数返回值
This commit is contained in:
parent
e6f800af7c
commit
3613d7ab5a
|
@ -1114,7 +1114,7 @@ bool hg_sane_middleware::get_current_value(scanner_handle handle, int option, vo
|
||||||
|
|
||||||
return ret;
|
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));
|
std::string val(get_option_json(handle, option));
|
||||||
void* data = nullptr;
|
void* data = nullptr;
|
||||||
|
@ -1128,8 +1128,10 @@ void* hg_sane_middleware::get_default_value(scanner_handle handle, int option)
|
||||||
bool v = false;
|
bool v = false;
|
||||||
jsn->get_value("default", v);
|
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));
|
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");
|
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %s\n", option, v ? "true" : "false");
|
||||||
}
|
}
|
||||||
else if (val == "int")
|
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), "");
|
data = local_utility::acquire_memory(sizeof(v), "");
|
||||||
memcpy(data, &v, 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);
|
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %d\n", option, v);
|
||||||
}
|
}
|
||||||
else if (val == "float")
|
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);
|
SANE_Fixed sd = hg_sane_middleware::double_2_sane_fixed(v);
|
||||||
data = local_utility::acquire_memory(sizeof(sd), "");
|
data = local_utility::acquire_memory(sizeof(sd), "");
|
||||||
|
if (bytes)
|
||||||
|
*bytes = sizeof(sd);
|
||||||
|
|
||||||
memcpy(data, &sd, sizeof(sd));
|
memcpy(data, &sd, sizeof(sd));
|
||||||
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %f\n", option, v);
|
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();
|
size = val.length();
|
||||||
data = local_utility::acquire_memory(size + 4, "");
|
data = local_utility::acquire_memory(size + 4, "");
|
||||||
strcpy((char*)data, val.c_str());
|
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);
|
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %s\n", option, (char*)data);
|
||||||
}
|
}
|
||||||
else
|
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);
|
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);
|
scanner_handle h = find_openning_device(handle);
|
||||||
|
|
||||||
if (!h)
|
if (!h)
|
||||||
return NULL;
|
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)
|
SANE_Status hg_sane_middleware::io_control(SANE_Handle h, unsigned long code, void* data, unsigned* len)
|
||||||
{
|
{
|
||||||
OPENDEV od;
|
OPENDEV od;
|
||||||
scanner_handle handle = find_openning_device(h, false, &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
|
// commented at 2022-03-23 for getting app about info before open any device
|
||||||
//
|
//
|
||||||
//if (!handle)
|
//if (!handle)
|
||||||
// return SANE_STATUS_INVAL;
|
// return SANE_STATUS_INVAL;
|
||||||
|
ret = hg_scanner_control(handle, code, data, len);
|
||||||
int ret = hg_scanner_control(handle, code, data, len);
|
|
||||||
if (ret == SCANNER_ERR_CONFIGURATION_CHANGED)
|
if (ret == SCANNER_ERR_CONFIGURATION_CHANGED)
|
||||||
{
|
{
|
||||||
int nc = code;
|
int nc = code;
|
||||||
|
|
|
@ -82,7 +82,7 @@ class hg_sane_middleware
|
||||||
|
|
||||||
void reload_current_value(scanner_handle handle, std::vector<int>* changed = NULL);
|
void reload_current_value(scanner_handle handle, std::vector<int>* changed = NULL);
|
||||||
bool get_current_value(scanner_handle handle, int option, void* value, SANE_Value_Type* type = 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
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 关联项处理
|
/// 关联项处理
|
||||||
|
@ -188,7 +188,7 @@ public:
|
||||||
SANE_Option_Descriptor* get_option_descriptor(SANE_Handle h, SANE_Int option);
|
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);
|
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
|
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 ...
|
// extension ...
|
||||||
SANE_Status io_control(SANE_Handle h, unsigned long code, void* data, unsigned* len);
|
SANE_Status io_control(SANE_Handle h, unsigned long code, void* data, unsigned* len);
|
||||||
|
|
Loading…
Reference in New Issue