From 51b93c08dfa062466f5670e02b2d600778d329a3 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Fri, 1 Dec 2023 11:28:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=9E=E6=80=A7=E6=B7=BB=E5=8A=A0=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E6=98=BE=E7=A4=BA=E4=BD=8D=E7=BD=AE=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E7=BB=84=E5=B1=9E=E6=80=A7=E5=B0=86=E4=BC=98?= =?UTF-8?q?=E5=85=88=E6=8C=89=E8=AF=A5=E5=AD=97=E6=AE=B5=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdk/sane_opt_json/base_opt.cpp | 5 +--- sdk/sane_opt_json/device_opt.cpp | 49 +++++++++++++++++++++++++++++--- sdk/sane_opt_json/device_opt.h | 4 +-- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/sdk/sane_opt_json/base_opt.cpp b/sdk/sane_opt_json/base_opt.cpp index d13572a..3a7dcca 100644 --- a/sdk/sane_opt_json/base_opt.cpp +++ b/sdk/sane_opt_json/base_opt.cpp @@ -91,10 +91,7 @@ char* sane_opt_provider::get_value(const char* name, void* value, size_t* size, } int sane_opt_provider::set_value(const char* name, void* val) { - if (following_.count(name)) - return following_[name]->set_value(name, val); - else - return SCANNER_ERR_DEVICE_NOT_SUPPORT; + return SCANNER_ERR_DEVICE_NOT_SUPPORT; } void sane_opt_provider::enable(const char* name, bool able) {} diff --git a/sdk/sane_opt_json/device_opt.cpp b/sdk/sane_opt_json/device_opt.cpp index 104bf46..9a1c87f 100644 --- a/sdk/sane_opt_json/device_opt.cpp +++ b/sdk/sane_opt_json/device_opt.cpp @@ -1152,13 +1152,42 @@ void device_option::insert_option(gb_json* opt, sane_opt_provider* from, const c } else { - int index = -1; + int index = -1, pos = -1; if (group) index = insert_group(group, group); - index = next_group(index + 1); + // insert poisition according to 'ui-pos' + if (!opt->get_value("ui-pos", pos) || pos == -1) + { + index = next_group(index + 1); + } + else + { + for (index++; index < origin_->children(); ++index) + { + gb_json* sib = origin_->child(index); + std::string t(""); + int sit = -1; + + if (!sib->get_value("type", t) || t == JSON_SANE_TYPE_GROUP) + { + sib->release(); + break; + } + if (!sib->get_value("ui-pos", sit) || sit == -1) + { + sib->release(); + break; + } + sib->release(); + + if (pos < sit) + break; + } + } origin_->insert(index, opt->key().c_str(), opt); + src_[opt->key()] = from; from->add_ref(); } @@ -1920,7 +1949,7 @@ std::string device_option::get_name_by_sane_id(int sane_ind) return std::move(value); } -std::string device_option::get_option_value_type(const char* name) +std::string device_option::get_option_value_type(const char* name, size_t* size) { std::string value(""); gb_json* jsn = now_ ? now_ : origin_; @@ -1933,6 +1962,12 @@ std::string device_option::get_option_value_type(const char* name) if (child) { child->get_value("type", value); + if (size) + { + int v = 0; + child->get_value("size", v); + *size = v; + } child->release(); } } @@ -2009,7 +2044,7 @@ std::string device_option::get_option_field_string(const char* name, const char* return std::move(value); } -std::string device_option::get_option_value_type(int sane_ind) +std::string device_option::get_option_value_type(int sane_ind, size_t* size) { std::string value(""); gb_json* jsn = now_ ? now_ : origin_; @@ -2018,6 +2053,12 @@ std::string device_option::get_option_value_type(int sane_ind) { gb_json* child = now_->child(sane_ind - 1); child->get_value("type", value); + if (size) + { + int v = 0; + child->get_value("size", v); + *size = v; + } child->release(); } diff --git a/sdk/sane_opt_json/device_opt.h b/sdk/sane_opt_json/device_opt.h index 575c175..0b4d950 100644 --- a/sdk/sane_opt_json/device_opt.h +++ b/sdk/sane_opt_json/device_opt.h @@ -362,8 +362,8 @@ public: int count(void); // return option count bool is_auto_restore_default(const char* name); std::string get_name_by_sane_id(int sane_ind); - std::string get_option_value_type(const char* name); - std::string get_option_value_type(int sane_ind); + std::string get_option_value_type(const char* name, size_t* size = nullptr); + std::string get_option_value_type(int sane_ind, size_t* size = nullptr); std::string get_option_field_string(const char* name, const char* key); std::string get_option_value(const char* name, int type/*OPT_VAL_xxx*/, int* size = nullptr, void* in_data = nullptr); // return whole json-text if name was null std::string get_option_value(int sane_ind, int type/*OPT_VAL_xxx*/, int* size = nullptr, void* in_data = nullptr); // return whole json-text if name was null