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