2023-10-31 06:51:14 +00:00
|
|
|
|
#include "base_opt.h"
|
|
|
|
|
|
2023-11-10 06:38:12 +00:00
|
|
|
|
#include <json/gb_json.h>
|
2023-10-31 06:51:14 +00:00
|
|
|
|
#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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 03:30:32 +00:00
|
|
|
|
const char* sane_opt_provider::get_opt_json(void)
|
2023-10-31 06:51:14 +00:00
|
|
|
|
{
|
2023-11-15 03:30:32 +00:00
|
|
|
|
return opt_jsn_txt_.c_str();
|
2023-10-31 06:51:14 +00:00
|
|
|
|
}
|
2023-11-15 03:30:32 +00:00
|
|
|
|
const char* sane_opt_provider::from(void)
|
2023-10-31 06:51:14 +00:00
|
|
|
|
{
|
2023-11-15 03:30:32 +00:00
|
|
|
|
return where_.c_str();
|
2023-10-31 06:51:14 +00:00
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
2023-11-15 03:30:32 +00:00
|
|
|
|
char* sane_opt_provider::get_value(const char* name, void* value, size_t* size, int* err)
|
2023-10-31 06:51:14 +00:00
|
|
|
|
{
|
|
|
|
|
if (err)
|
|
|
|
|
*err = SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
|
|
|
|
|
2023-11-15 03:30:32 +00:00
|
|
|
|
if (size)
|
|
|
|
|
*size = 0;
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
2023-10-31 06:51:14 +00:00
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
{}
|