#include "base_opt.h" #include #include "../../../sdk/include/huagao/hgscanner_error.h" sane_opt_provider::sane_opt_provider() { set_where(nullptr); } sane_opt_provider::~sane_opt_provider() { for (auto& v : following_) v.second->release(); following_.clear(); } bool sane_opt_provider::set_opt_json_text(char* txt) { gb_json* jsn = new gb_json(); bool ret = jsn->attach_text(txt); jsn->release(); if (ret) opt_jsn_txt_ = txt; else opt_jsn_txt_ = ""; return ret; } void sane_opt_provider::set_where(const char* where) { if (where && *where) { where_ = where; } else { char buf[20] = { 0 }; sprintf(buf, "%p", this); where_ = buf; } } std::string sane_opt_provider::get_opt_json(void) { return opt_jsn_txt_; } std::string sane_opt_provider::from(void) { return where_; } void sane_opt_provider::set_following_provider(const char* name, sane_opt_provider* following) { if (following_.count(name)) { following_[name]->release(); following_.erase(name); } if (following) { following_[name] = following; following->add_ref(); } } sane_opt_provider* sane_opt_provider::get_following(const char* name) { sane_opt_provider* prvd = nullptr; if (following_.count(name)) { prvd = following_[name]; if (prvd) prvd->add_ref(); } return prvd; } std::string sane_opt_provider::get_value(const char* name, void* value, int* err) { if (err) *err = SCANNER_ERR_DEVICE_NOT_SUPPORT; return ""; } 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; } void sane_opt_provider::enable(const char* name, bool able) {}