按新JSON改造
This commit is contained in:
parent
88846c619f
commit
91066b936a
|
@ -8,10 +8,6 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// image-processing jsons ...
|
||||
#define JSON_SANE_TYPE_BOOL "bool"
|
||||
#define JSON_SANE_TYPE_INT "int"
|
||||
#define JSON_SANE_TYPE_FIXED "float"
|
||||
#define JSON_SANE_TYPE_STRING "string"
|
||||
|
||||
template<class T, class TC>
|
||||
static void copy_simple_type(TC* dst, T& src)
|
||||
|
@ -1372,21 +1368,36 @@ int device_option::update_data(const char* name, void* value)
|
|||
now_->get_value(name, child);
|
||||
if (child)
|
||||
{
|
||||
child->get_value("type", type);
|
||||
std::string pre(device_option::option_value(child, false));
|
||||
bool changed = false;
|
||||
|
||||
child->get_value("type", type);
|
||||
if (type == JSON_SANE_TYPE_BOOL)
|
||||
{
|
||||
child->set_value("cur", *(bool*)value);
|
||||
changed = *(bool*)value != *(bool*)pre.c_str();
|
||||
}
|
||||
else if (type == JSON_SANE_TYPE_INT)
|
||||
{
|
||||
child->set_value("cur", *(int*)value);
|
||||
changed = *(int*)value != *(int*)pre.c_str();
|
||||
}
|
||||
else if (type == JSON_SANE_TYPE_FIXED)
|
||||
{
|
||||
child->set_value("cur", *(double*)value);
|
||||
changed = IS_DOUBLE_EQUAL(*(double*)value, *(double*)pre.c_str());
|
||||
}
|
||||
else if (type == JSON_SANE_TYPE_STRING)
|
||||
{
|
||||
child->set_value("cur", (char*)value);
|
||||
changed = pre != (char*)value;
|
||||
}
|
||||
child->release();
|
||||
|
||||
if (std::find(master_opts_.begin(), master_opts_.end(), name) != master_opts_.end())
|
||||
if (changed && // value has changed
|
||||
std::find(master_opts_.begin(), master_opts_.end(), name) != master_opts_.end()) // can affect others
|
||||
{
|
||||
bool changed = false;
|
||||
changed = false;
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -1402,15 +1413,39 @@ int device_option::update_data(const char* name, void* value)
|
|||
return SCANNER_ERR_OK;
|
||||
}
|
||||
|
||||
int device_option::count(void)
|
||||
{
|
||||
gb_json* jsn = now_ ? now_ : origin_;
|
||||
|
||||
if (jsn)
|
||||
return jsn->children();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
std::string device_option::get_name_by_sane_id(int sane_ind)
|
||||
{
|
||||
std::string value("");
|
||||
gb_json* jsn = now_ ? now_ : origin_;
|
||||
|
||||
if (sane_ind > 0 && sane_ind - 1 < jsn->children())
|
||||
{
|
||||
gb_json* child = now_->child(sane_ind - 1);
|
||||
child->get_value("name", value);
|
||||
child->release();
|
||||
}
|
||||
|
||||
return std::move(value);
|
||||
}
|
||||
std::string device_option::get_option_value_type(const char* name)
|
||||
{
|
||||
std::string value("");
|
||||
gb_json* jsn = now_ ? now_ : origin_;
|
||||
|
||||
if (now_)
|
||||
if (jsn)
|
||||
{
|
||||
gb_json* child = nullptr;
|
||||
|
||||
now_->get_value(name, child);
|
||||
jsn->get_value(name, child);
|
||||
if (child)
|
||||
{
|
||||
child->get_value("type", value);
|
||||
|
@ -1420,7 +1455,7 @@ std::string device_option::get_option_value_type(const char* name)
|
|||
|
||||
return std::move(value);
|
||||
}
|
||||
std::string device_option::get_option_value(const char* name, int type)
|
||||
std::string device_option::get_option_value(const char* name, int type, int* size)
|
||||
{
|
||||
std::string value("");
|
||||
|
||||
|
@ -1442,6 +1477,13 @@ std::string device_option::get_option_value(const char* name, int type)
|
|||
else
|
||||
value = device_option::option_value(child, type == OPT_VAL_DEFAULT);
|
||||
|
||||
if (size)
|
||||
{
|
||||
int n = 0;
|
||||
child->get_value("size", n);
|
||||
*size = n;
|
||||
}
|
||||
|
||||
child->release();
|
||||
}
|
||||
}
|
||||
|
@ -1449,3 +1491,68 @@ std::string device_option::get_option_value(const char* name, int type)
|
|||
|
||||
return std::move(value);
|
||||
}
|
||||
std::string device_option::get_option_field_string(const char* name, const char* key)
|
||||
{
|
||||
std::string value("");
|
||||
gb_json* jsn = now_ ? now_ : origin_;
|
||||
|
||||
if (jsn)
|
||||
{
|
||||
gb_json* child = nullptr;
|
||||
|
||||
jsn->get_value(name, child);
|
||||
if (child)
|
||||
{
|
||||
child->get_value(key, value);
|
||||
child->release();
|
||||
}
|
||||
}
|
||||
|
||||
return std::move(value);
|
||||
}
|
||||
std::string device_option::get_option_value_type(int sane_ind)
|
||||
{
|
||||
std::string value("");
|
||||
gb_json* jsn = now_ ? now_ : origin_;
|
||||
|
||||
if (sane_ind > 0 && sane_ind - 1 < jsn->children())
|
||||
{
|
||||
gb_json* child = now_->child(sane_ind - 1);
|
||||
child->get_value("type", value);
|
||||
child->release();
|
||||
}
|
||||
|
||||
return std::move(value);
|
||||
}
|
||||
std::string device_option::get_option_value(int sane_ind, int type, int* size)
|
||||
{
|
||||
std::string value("");
|
||||
|
||||
if (now_)
|
||||
{
|
||||
if (sane_ind <= 0)
|
||||
{
|
||||
value = now_->to_string();
|
||||
}
|
||||
else if(sane_ind - 1 < now_->children())
|
||||
{
|
||||
gb_json* child = now_->child(sane_ind - 1);
|
||||
|
||||
if (type == OPT_VAL_JSON)
|
||||
value = child->to_string();
|
||||
else
|
||||
value = device_option::option_value(child, type == OPT_VAL_DEFAULT);
|
||||
|
||||
if (size)
|
||||
{
|
||||
int n = 0;
|
||||
child->get_value("size", n);
|
||||
*size = n;
|
||||
}
|
||||
|
||||
child->release();
|
||||
}
|
||||
}
|
||||
|
||||
return std::move(value);
|
||||
}
|
||||
|
|
|
@ -168,10 +168,7 @@ class device_option
|
|||
gb_json* copy_opt(gb_json* from);
|
||||
bool to_now(bool init, bool* changed);
|
||||
|
||||
public:
|
||||
device_option();
|
||||
~device_option();
|
||||
|
||||
protected:
|
||||
static std::string option_value(gb_json* jsn, bool def_val);
|
||||
|
||||
template<class T>
|
||||
|
@ -198,6 +195,10 @@ public:
|
|||
return ret;
|
||||
}
|
||||
|
||||
public:
|
||||
device_option();
|
||||
~device_option();
|
||||
|
||||
static std::string trans_group(const char* utf8, bool to_title);
|
||||
static std::string get_group(int ind, bool title);
|
||||
|
||||
|
@ -206,8 +207,13 @@ public:
|
|||
bool refine_data(const char* name, void* value); // return true if the 'value' is out of range and refined it in the range
|
||||
int update_data(const char* name, void* value); // return scanner_err. name and value would be null if invoked for language changed
|
||||
|
||||
int count(void); // return option count
|
||||
std::string get_name_by_sane_id(int sane_ind);
|
||||
std::string get_option_value_type(const char* name);
|
||||
std::string get_option_value(const char* name, int type); // return whole json-text if name was null
|
||||
std::string get_option_value(const char* name, int type/*OPT_VAL_xxx*/, int* size = nullptr); // return whole json-text if name was null
|
||||
std::string get_option_field_string(const char* name, const char* key);
|
||||
std::string get_option_value_type(int sane_ind);
|
||||
std::string get_option_value(int sane_ind, int type/*OPT_VAL_xxx*/, int* size = nullptr); // return whole json-text if name was null
|
||||
};
|
||||
|
||||
//{
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -70,6 +70,7 @@ typedef HGResult(__stdcall* SDKHGVersion_Postlog_)(HGVersionMgr mgr, const HGCha
|
|||
typedef HGResult(__stdcall* SDKHGVersion_Free_)(HGVersionMgr mgr);
|
||||
|
||||
class gb_json;
|
||||
class device_option;
|
||||
class hg_scanner
|
||||
{
|
||||
HGVersionMgr HGVersion_mgr_;
|
||||
|
@ -90,7 +91,6 @@ class hg_scanner
|
|||
bool save_sizecheck;
|
||||
bool read_over_with_no_data_; // 针对第三方调用,在最后一段数据时是否返回“SCANNER_ERR_NO_DATA”
|
||||
int is_color_type_;//保存最后下发到设备的颜色类型
|
||||
bool have_max_size; //条目是否存在最大尺寸
|
||||
|
||||
|
||||
sane_callback ui_ev_cb_;
|
||||
|
@ -113,16 +113,7 @@ class hg_scanner
|
|||
void dump_image_real(hg_imgproc::HIMGPRC himg, const char* desc);
|
||||
|
||||
void init_setting_func_map(void);
|
||||
std::string setting_name_from(const char* n_or_id, int* id = nullptr);
|
||||
void get_range(const char* name, std::vector<std::string>& range, std::string& def_val, bool& is_range/*range or list*/);
|
||||
bool check_range(const char* name, bool& val);
|
||||
bool check_range(const char* name, int& val);
|
||||
bool check_range(const char* name, double& val);
|
||||
bool check_range(const char* name, std::string& val);
|
||||
bool check_paper_and_resolution(int res, int paper);
|
||||
bool check_resolution_and_quality(int res, const char* quality);
|
||||
int restore(const char* name);
|
||||
bool get_default_value(void* buf, gb_json* jsn);
|
||||
bool is_to_file(void);
|
||||
void thread_handle_image_process(void);
|
||||
|
||||
|
@ -130,9 +121,6 @@ class hg_scanner
|
|||
void working_done(void*);
|
||||
|
||||
void image_process(std::shared_ptr<tiny_buffer>& buffer, uint32_t id);
|
||||
void reset_custom_area_range(int paper);
|
||||
float reset_custom_area_jsn_value(const char* name, double& var, float range_l, float range_u, float value_l, float value_u); // return cur value
|
||||
int set_color_change(void);
|
||||
bool jsn_reorganize(); // 固件版本不同 初始化gb_json要做出相对应的删除
|
||||
public:
|
||||
|
||||
|
@ -294,7 +282,8 @@ protected:
|
|||
bool cb_mem_;
|
||||
bool test_1_paper_; // 是否为单张扫描模式
|
||||
std::vector<string> erase_depend_; //需要删除父依赖项
|
||||
gb_json *setting_jsn_;
|
||||
//gb_json *setting_jsn_;
|
||||
device_option *setting_jsn_;
|
||||
|
||||
IMGPRCFIXPARAM image_prc_param_;
|
||||
int erase_bkg_range_; // 背景移除像素范围
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -891,7 +891,7 @@ scanner_err hg_scanner_mgr::hg_scanner_get_parameter(scanner_handle h, const cha
|
|||
strcmp(SANE_STD_OPT_NAME_TOTAL_COUNT, name) == 0 ||
|
||||
strcmp(SANE_STD_OPT_NAME_MOTOR_VER, name) == 0 ||
|
||||
strcmp(SANE_STD_OPT_NAME_INITIAL_BOOT_TIME, name) == 0)
|
||||
return (scanner_err)SCAN_PTR(h)->set_setting(name, data, len);
|
||||
return (scanner_err)SCAN_PTR(h)->set_setting(name, data, false);
|
||||
}
|
||||
|
||||
if (strcmp(SANE_STD_OPT_NAME_DRIVER_LOG, name) == 0)
|
||||
|
|
|
@ -761,7 +761,7 @@ SANE_Status hg_sane_middleware::get_option_fixed_id(LPDEVINST inst, const void*
|
|||
{
|
||||
*(SANE_Int*)value = fix_id;
|
||||
|
||||
return fix_id == -1 ? SANE_STATUS_INVAL : SANE_STATUS_GOOD;
|
||||
return fix_id <= 0 ? SANE_STATUS_INVAL : SANE_STATUS_GOOD;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue