553 lines
20 KiB
C++
553 lines
20 KiB
C++
#include "scanner_manager.h"
|
|
#include "../../sdk/hginclude/hg_log.h"
|
|
#include <iostream>
|
|
#include <string.h>
|
|
#include "raw_src.h"
|
|
#include "char_const.h"
|
|
|
|
// kinds of scanners ...
|
|
#define SCAN_PTR(ptr) ((hg_scanner*)ptr)
|
|
|
|
#include "hg_scanner_200.h"
|
|
#include "hg_scanner_239.h"
|
|
#include "hg_scanner_300.h"
|
|
#include "hg_scanner_400.h"
|
|
|
|
/// <summary>
|
|
/// supporting devices :
|
|
static struct
|
|
{
|
|
uint16_t vid; // vendor ID
|
|
uint16_t pid; // product ID
|
|
std::string name; // product name
|
|
std::string type; // product type
|
|
std::string rsc; // USB resource, version-addr. e.g. "USB2.0-1"
|
|
}
|
|
g_supporting_devices[] = { {0x3072, 0x100, SCANNER_NAME_HG_G100, "GScanO200", ""}
|
|
, {0x3072, 0x200, SCANNER_NAME_HG_G200, "GScanO200", ""}
|
|
, {0x3072, 0x300, SCANNER_NAME_HG_G300, "GScanO400", ""}
|
|
, {0x3072, 0x400, SCANNER_NAME_HG_G400, "GScanO400", ""}
|
|
, {0x3072, 0x139, SCANNER_NAME_HG_G139, "GScanO1003399", ""}
|
|
, {0x3072, 0x239, SCANNER_NAME_HG_G239, "GScanO1003399", ""}
|
|
, {0x3072, 0x339, SCANNER_NAME_HG_G339, "GScanO1003399", ""}
|
|
, {0x3072, 0x439, SCANNER_NAME_HG_G439, "GScanO1003399", ""}
|
|
, {0x064B, 0x7823, SCANNER_NAME_HG_G200, "GScanO200", ""}
|
|
|
|
, {0x31c9, 0x8420, SCANNER_NAME_LSC_G42S, "G426xF", ""}
|
|
, {0x31c9, 0x8520, SCANNER_NAME_LSC_G52S, "G52x0F", ""}
|
|
, {0x31c9, 0x8620, SCANNER_NAME_LSC_G62S, "G6290U", ""}
|
|
, {0x31c9, 0x8629, SCANNER_NAME_LSC_G62S, "G6290U", ""}
|
|
, {0x31c9, 0x8730, SCANNER_NAME_LSC_G73S, "G73x0U", ""}
|
|
, {0x31c9, 0x8739, SCANNER_NAME_LSC_G73S, "G73x0U", ""}
|
|
|
|
, {0x2903, 0x7000, SCANNER_NAME_HW_7000, "HW-74x0WA", ""}
|
|
, {0x2903, 0x1000, SCANNER_NAME_HW_9110F, "HW-9110F", ""}
|
|
, {0x2903, 0x8000, SCANNER_NAME_HW_8190F, "HW-8190F", ""}
|
|
, {0x2903, 0x9000, SCANNER_NAME_HW_9110F, "HW-9110F", ""}
|
|
};
|
|
static std::string g_vendor = COMPANY_NAME;
|
|
|
|
#define BRAND_LOGO_SIZE 8 * 1024
|
|
|
|
#define MOVE_TO_NEXT_STR(str) str += strlen(str) + 1
|
|
/// </summary>
|
|
|
|
|
|
hg_scanner_mgr* hg_scanner_mgr::inst_ = NULL;
|
|
sane_callback hg_scanner_mgr::event_callback_ = NULL;
|
|
bool hg_scanner_mgr::async_io_enabled_ = false;
|
|
int hg_scanner_mgr::ver_major_ = 1;
|
|
int hg_scanner_mgr::ver_minor_ = 0;
|
|
int hg_scanner_mgr::ver_build_ = 0;
|
|
int hg_scanner_mgr::ver_patch_ = 1;
|
|
|
|
hg_scanner_mgr::hg_scanner_mgr() : same_ind_(1)
|
|
{
|
|
usb_manager::instance()->register_hotplug(&hg_scanner_mgr::usb_event_handle, this);
|
|
}
|
|
hg_scanner_mgr::~hg_scanner_mgr()
|
|
{
|
|
usb_manager::clear();
|
|
}
|
|
|
|
int hg_scanner_mgr::ui_default_callback(scanner_handle h, int ev, void* data, unsigned int* len, void* param)
|
|
{
|
|
// if (!hg_scanner_mgr::async_io_enabled_ &&
|
|
// ev == SANE_EVENT_IS_MEMORY_ENOUGH)
|
|
// {
|
|
// struct sysinfo si;
|
|
// if(sysinfo(&si) == 0)
|
|
// return si.freeram * si.mem_unit > *len + 200 * 1024 * 1024 ? HG_ERR_OK : HG_ERR_INSUFFICIENT_MEMORY;
|
|
|
|
// return HG_ERR_OK;
|
|
// }
|
|
|
|
if (hg_scanner_mgr::event_callback_)
|
|
return hg_scanner_mgr::event_callback_(h, ev, data, len, param);
|
|
|
|
return HG_ERR_OK;
|
|
}
|
|
hg_scanner_mgr* hg_scanner_mgr::instance(sane_callback cb)
|
|
{
|
|
if (!hg_scanner_mgr::inst_)
|
|
{
|
|
hg_scanner_mgr::event_callback_ = cb;
|
|
if (cb)
|
|
hg_scanner_mgr::async_io_enabled_ = cb(NULL, SANE_EVENT_SUPPORT_ASYNC_IO, NULL, NULL, NULL) == 0;
|
|
hg_scanner_mgr::inst_ = new hg_scanner_mgr();
|
|
HG_VLOG_MINI_1(HG_LOG_LEVEL_DEBUG_INFO, "async image transferring is %s\n", hg_scanner_mgr::async_io_enabled_ ? "enabled" : "disabled");
|
|
}
|
|
|
|
return hg_scanner_mgr::inst_;
|
|
}
|
|
void hg_scanner_mgr::clear(void)
|
|
{
|
|
if (hg_scanner_mgr::inst_)
|
|
{
|
|
{
|
|
std::lock_guard<std::mutex> lock(hg_scanner_mgr::inst_->mutex_dev_);
|
|
hg_scanner_mgr::event_callback_ = nullptr;
|
|
}
|
|
delete hg_scanner_mgr::inst_;
|
|
hg_scanner_mgr::inst_ = NULL;
|
|
}
|
|
}
|
|
void hg_scanner_mgr::set_version(int hh, int hl, int lh, int ll)
|
|
{
|
|
hg_scanner_mgr::ver_major_ = hh;
|
|
hg_scanner_mgr::ver_minor_ = hl;
|
|
hg_scanner_mgr::ver_build_ = lh;
|
|
hg_scanner_mgr::ver_patch_ = ll;
|
|
}
|
|
|
|
void hg_scanner_mgr::usb_event_handle(usb_event ev, libusb_device* device, int vid, int pid, int usb_ver_h, int usb_ver_l, bool* retry, void* user) // usb_ver_h.usb_ver_l
|
|
{
|
|
hg_scanner_mgr* obj = (hg_scanner_mgr*)user;
|
|
|
|
obj->on_hgscanner_pnp(ev, device, vid, pid, usb_ver_h, usb_ver_l, retry);
|
|
}
|
|
|
|
void hg_scanner_mgr::on_hgscanner_pnp(usb_event ev, libusb_device* device, int vid, int pid, int usb_ver_h, int usb_ver_l, bool* retry)
|
|
{
|
|
char model[40],
|
|
vendor[40];
|
|
SANE_Device_Ex de;
|
|
int ev_ui = 0;
|
|
scanner_handle h = NULL;
|
|
unsigned int len = sizeof(de);
|
|
std::string name(""), type("");
|
|
std::lock_guard<std::mutex> lock(mutex_dev_);
|
|
|
|
sprintf(model, "%x", pid);
|
|
sprintf(vendor, "%x", vid);
|
|
de.model = model;
|
|
de.name = NULL;
|
|
de.type = NULL;
|
|
de.vendor = vendor;
|
|
de.openned = SANE_FALSE;
|
|
|
|
if (ev == USB_EVENT_DEVICE_ARRIVED)
|
|
{
|
|
int index = -1;
|
|
for (int i = 0; i < _countof(g_supporting_devices); ++i)
|
|
{
|
|
if (g_supporting_devices[i].vid == vid && g_supporting_devices[i].pid == pid)
|
|
{
|
|
HG_VLOG_MINI_1(HG_LOG_LEVEL_DEBUG_INFO, "%s connected.\n", g_supporting_devices[i].name.c_str());
|
|
index = i;
|
|
ev_ui = SANE_EVENT_DEVICE_ARRIVED;
|
|
de.name = g_supporting_devices[i].name.c_str();
|
|
de.type = g_supporting_devices[i].type.c_str();
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (index != -1)
|
|
{
|
|
bool add = true;
|
|
for (size_t i = 0; i < online_devices_.size(); ++i)
|
|
{
|
|
if (online_devices_[i].dev == device)
|
|
{
|
|
online_devices_[i].ind = index;
|
|
add = false;
|
|
break;
|
|
}
|
|
else if (online_devices_[i].scanner && !online_devices_[i].scanner->is_online()
|
|
&& online_devices_[i].scanner->get_pid() == pid && online_devices_[i].scanner->get_vid() == vid)
|
|
{
|
|
usb_io* io = NULL;
|
|
|
|
name = online_devices_[i].display_name;
|
|
type = g_supporting_devices[index].type;
|
|
online_devices_[i].dev = device;
|
|
h = online_devices_[i].scanner;
|
|
if (pid == 0x300 || pid == 0x400)
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
|
len = usb_manager::instance()->open(device, &io);
|
|
if (len == HG_ERR_OK)
|
|
{
|
|
HG_VLOG_MINI_3(HG_LOG_LEVEL_WARNING, "[%04x:%04x]%s re-connected.\n", pid, vid, online_devices_[i].display_name.c_str());
|
|
online_devices_[i].scanner->reset_io(io);
|
|
de.openned = SANE_TRUE;
|
|
}
|
|
if (io)
|
|
io->release();
|
|
add = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (add)
|
|
{
|
|
OLSCANNER ols;
|
|
|
|
ols.dev = device;
|
|
ols.ind = index;
|
|
ols.scanner = NULL;
|
|
ols.display_name = g_supporting_devices[ols.ind].name;
|
|
if (std::find(online_devices_.begin(), online_devices_.end(), ols.ind) != online_devices_.end())
|
|
{
|
|
char buf[40];
|
|
|
|
sprintf(buf, " - %u", same_ind_++);
|
|
ols.display_name += buf;
|
|
}
|
|
online_devices_.push_back(ols);
|
|
name = ols.display_name;
|
|
type = g_supporting_devices[ols.ind].type;
|
|
}
|
|
}
|
|
}
|
|
else if (ev == USB_EVENT_DEVICE_LEFT)
|
|
{
|
|
std::vector<OLSCANNER>::iterator it = std::find(online_devices_.begin(), online_devices_.end(), device);
|
|
if (it != online_devices_.end())
|
|
{
|
|
ev_ui = SANE_EVENT_DEVICE_LEFT;
|
|
name = it->display_name;
|
|
type = g_supporting_devices[it->ind].type;
|
|
h = it->scanner;
|
|
HG_VLOG_MINI_1(HG_LOG_LEVEL_DEBUG_INFO, "%s Dis-connected.\n", name.c_str());
|
|
if (it->scanner)
|
|
it->scanner->io_disconnected();
|
|
else
|
|
online_devices_.erase(it);
|
|
}
|
|
}
|
|
|
|
if (ev_ui)
|
|
{
|
|
de.name = name.c_str();
|
|
de.type = type.c_str();
|
|
hg_scanner_mgr::ui_default_callback(h, ev_ui, &de, &len, NULL);
|
|
}
|
|
}
|
|
void hg_scanner_mgr::get_online_devices(std::vector<OLSCANNER>& devs)
|
|
{
|
|
std::lock_guard<std::mutex> lock(mutex_dev_);
|
|
|
|
devs = online_devices_;
|
|
}
|
|
|
|
void hg_scanner_mgr::set_appendix_info_for_about(SANE_About* about, char*& ptr, int& count, const char* key, const char* info, const char* url)
|
|
{
|
|
#ifdef BRAND_DISPLAY_ALL_EXPAND
|
|
if (!info || *info == 0)
|
|
info = BRAND_COMMUNICATION_FAIL;
|
|
#endif
|
|
|
|
if (info && strlen(info))
|
|
{
|
|
about->appendix[count].key = ptr;
|
|
strcpy(ptr, key);
|
|
MOVE_TO_NEXT_STR(ptr);
|
|
|
|
about->appendix[count].content = ptr;
|
|
strcpy(ptr, info);
|
|
MOVE_TO_NEXT_STR(ptr);
|
|
|
|
if (url)
|
|
{
|
|
about->appendix[count++].url = ptr;
|
|
strcpy(ptr, url);
|
|
MOVE_TO_NEXT_STR(ptr);
|
|
}
|
|
else
|
|
count++;
|
|
}
|
|
}
|
|
hg_err hg_scanner_mgr::get_about_info(scanner_handle h, void* data, unsigned* len)
|
|
{
|
|
hg_scanner* scanner = (hg_scanner*)h;
|
|
unsigned bytes = sizeof(SANE_About) + 40;
|
|
SANE_About tmp;
|
|
|
|
bytes += sizeof(g_logo);
|
|
bytes += strlen(BRAND_APP_NAME) + 8;
|
|
bytes += strlen(BRAND_TITLE_VERSION) + 8;
|
|
bytes += strlen(BRAND_TITLE_COPYRIGHT) + 8;
|
|
bytes += strlen(BRAND_COPYRIGHT) + 8;
|
|
bytes += strlen(BRAND_TITE_MANUFACTOR) + 8;
|
|
bytes += strlen(BRAND_TITLE_URL) + 8;
|
|
bytes += strlen(BRAND_COMPANY_URL) + 8;
|
|
bytes += strlen(BRAND_URL_COMPANY_URL) + 8;
|
|
bytes += strlen(BRAND_TITLE_TEL) + 8;
|
|
bytes += strlen(BRAND_COMPANY_TEL) + 8;
|
|
bytes += strlen(BRAND_TITLE_ADDRESS) + 8;
|
|
bytes += strlen(BRAND_COMPANY_ADDRESS) + 8;
|
|
bytes += strlen(BRAND_TITLE_GPS) + 8;
|
|
bytes += strlen(BRAND_COMPANY_GPS) + 8;
|
|
bytes += strlen(BRAND_URL_GPS) + 8;
|
|
// bytes += 5 * sizeof(tmp.appendix[0]);
|
|
|
|
#ifndef BRAND_DISPLAY_ALL_EXPAND
|
|
if (scanner)
|
|
#endif
|
|
{
|
|
bytes += sizeof(tmp.appendix[0]) + BRAND_INFO_MAX_LENGTH + 8 + strlen(BRAND_TITLE_FIRM_VERSION) + 8;
|
|
bytes += sizeof(tmp.appendix[0]) + BRAND_INFO_MAX_LENGTH + 8 + strlen(BRAND_TITLE_SERIAL_NUM) + 8;
|
|
bytes += sizeof(tmp.appendix[0]) + BRAND_INFO_MAX_LENGTH + 8 + strlen(BRAND_TITLE_IP) + 8;
|
|
bytes += sizeof(tmp.appendix[0]) + 28 + strlen(BRAND_TITLE_ROLLER_COUNT) + 8;
|
|
bytes += sizeof(tmp.appendix[0]);
|
|
}
|
|
|
|
if (!data || *len < bytes)
|
|
{
|
|
*len = bytes;
|
|
|
|
return HG_ERR_INSUFFICIENT_MEMORY;
|
|
}
|
|
|
|
// filling info to flat buffer ...
|
|
SANE_About* about = (SANE_About*)data;
|
|
std::string info("");
|
|
char* ptr = (char*)data + sizeof(SANE_About) + 9 * sizeof(about->appendix[0]);
|
|
|
|
about->title = ptr;
|
|
strcpy(ptr, BRAND_APP_NAME);
|
|
MOVE_TO_NEXT_STR(ptr);
|
|
|
|
about->version = ptr;
|
|
sprintf(ptr, "%d.%d.%d.%d", hg_scanner_mgr::ver_major_, hg_scanner_mgr::ver_minor_, hg_scanner_mgr::ver_build_, hg_scanner_mgr::ver_patch_);
|
|
MOVE_TO_NEXT_STR(ptr);
|
|
|
|
about->copyright = ptr;
|
|
strcpy(ptr, BRAND_COPYRIGHT);
|
|
MOVE_TO_NEXT_STR(ptr);
|
|
|
|
about->logo_bytes = sizeof(g_logo);;
|
|
memcpy(ptr, g_logo, about->logo_bytes);
|
|
ptr += about->logo_bytes + 1;
|
|
|
|
int count = 0, rolls = 0;
|
|
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITE_MANUFACTOR, g_vendor.c_str(), NULL);
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_URL, BRAND_COMPANY_URL, BRAND_URL_COMPANY_URL);
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_TEL, BRAND_COMPANY_TEL, NULL);
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_ADDRESS, BRAND_COMPANY_ADDRESS, NULL);
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_GPS, BRAND_COMPANY_GPS, BRAND_URL_GPS);
|
|
|
|
if (scanner)
|
|
{
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_FIRM_VERSION, scanner->get_firmware_version().c_str(), NULL);
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_SERIAL_NUM, scanner->get_serial_num().c_str(), NULL);
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_IP, scanner->get_ip().c_str(), NULL);
|
|
rolls = scanner->get_roller_num();
|
|
if (rolls != -1)
|
|
{
|
|
char buf[40];
|
|
sprintf(buf, "%u", rolls);
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_ROLLER_COUNT, buf, NULL);
|
|
}
|
|
#ifdef BRAND_DISPLAY_ALL_EXPAND
|
|
else
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_ROLLER_COUNT, BRAND_DEVICE_NOT_SUPPORT, NULL);
|
|
#endif
|
|
}
|
|
#ifdef BRAND_DISPLAY_ALL_EXPAND
|
|
else
|
|
{
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_FIRM_VERSION, BRAND_NO_DEVICE, NULL);
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_SERIAL_NUM, BRAND_NO_DEVICE, NULL);
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_IP, BRAND_NO_DEVICE, NULL);
|
|
set_appendix_info_for_about(about, ptr, count, BRAND_TITLE_ROLLER_COUNT, BRAND_NO_DEVICE, NULL);
|
|
}
|
|
#endif
|
|
|
|
about->appendix[count].key = NULL;
|
|
about->appendix[count].content = NULL;
|
|
about->appendix[count].url = NULL;
|
|
|
|
return HG_ERR_OK;
|
|
}
|
|
|
|
hg_err hg_scanner_mgr::hg_scanner_enum(HGScannerInfo* scanner_list, long* count, bool local_only)
|
|
{
|
|
std::vector<OLSCANNER> devusbuf;
|
|
long size = *count;
|
|
hg_err ret = HG_ERR_OK;
|
|
|
|
get_online_devices(devusbuf);
|
|
*count = devusbuf.size();
|
|
if (*count > size)
|
|
{
|
|
ret = HG_ERR_INSUFFICIENT_MEMORY;
|
|
}
|
|
else
|
|
{
|
|
for (size_t i = 0; i < devusbuf.size(); i++)
|
|
{
|
|
strcpy(scanner_list->name, g_supporting_devices[devusbuf[i].ind].name.c_str());
|
|
strcpy(scanner_list->type, g_supporting_devices[devusbuf[i].ind].type.c_str());
|
|
sprintf(scanner_list->model, "%x", g_supporting_devices[devusbuf[i].ind].pid);
|
|
strcpy(scanner_list->vendor, g_vendor.c_str());
|
|
scanner_list++;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
hg_err hg_scanner_mgr::hg_scanner_open(scanner_handle* h, const char* name, bool shared, const char* user, const char* pwd, const char* check, char* rsc)
|
|
{
|
|
std::vector<OLSCANNER> devs;
|
|
std::vector<OLSCANNER>::iterator it;
|
|
usb_io* io = NULL;
|
|
hg_err ret = HG_ERR_DEVICE_NOT_FOUND;
|
|
|
|
*h = NULL;
|
|
get_online_devices(devs);
|
|
it = std::find(devs.begin(), devs.end(), name);
|
|
if (it != devs.end())
|
|
{
|
|
std::string msg("");
|
|
ret = (hg_err)usb_manager::instance()->open(it->dev, &io, &msg);
|
|
if (ret == HG_ERR_OK)
|
|
{
|
|
hg_scanner* scanner = NULL;
|
|
if (g_supporting_devices[it->ind].pid == 0x100 || g_supporting_devices[it->ind].pid == 0x200)
|
|
{
|
|
hg_scanner_200* s200 = new hg_scanner_200(g_supporting_devices[it->ind].name.c_str(), 0x100, io);
|
|
|
|
scanner = dynamic_cast<hg_scanner*>(s200);
|
|
*h = (scanner_handle)s200;
|
|
}
|
|
else if (g_supporting_devices[it->ind].pid == 0x239 || g_supporting_devices[it->ind].pid == 0x139||g_supporting_devices[it->ind].pid == 0x8000)
|
|
{
|
|
hg_scanner_239* s239 = new hg_scanner_239(g_supporting_devices[it->ind].name.c_str(),0x239, io);
|
|
|
|
scanner = dynamic_cast<hg_scanner*>(s239);
|
|
*h = (scanner_handle)s239;
|
|
}
|
|
else if (g_supporting_devices[it->ind].pid == 0x400)
|
|
{
|
|
hg_scanner_400* s400 = new hg_scanner_400(g_supporting_devices[it->ind].name.c_str(), 0x400, io);
|
|
scanner = dynamic_cast<hg_scanner*>(s400);
|
|
*h = (scanner_handle)s400;
|
|
}
|
|
else if (g_supporting_devices[it->ind].pid == 0x300 ||g_supporting_devices[it->ind].pid == 0x1000)
|
|
{
|
|
hg_scanner_300* s300 = new hg_scanner_300(g_supporting_devices[it->ind].name.c_str(),0x300, io);
|
|
scanner = dynamic_cast<hg_scanner*>(s300);
|
|
*h = (scanner_handle)s300;
|
|
}
|
|
|
|
if (scanner)
|
|
{
|
|
scanner->set_ui_callback(&hg_scanner_mgr::ui_default_callback, hg_scanner_mgr::async_io_enabled_);
|
|
}
|
|
|
|
std::lock_guard<std::mutex> lock(mutex_dev_);
|
|
std::vector<OLSCANNER>::iterator ptr = std::find(online_devices_.begin(), online_devices_.end(), name);
|
|
if (ptr != online_devices_.end())
|
|
ptr->scanner = (hg_scanner*)*h;
|
|
}
|
|
else if(msg.length())
|
|
hg_scanner_mgr::ui_default_callback(nullptr, SANE_EVENT_ERROR, (void*)msg.c_str(), (unsigned int*)&ret, nullptr);
|
|
|
|
if(io)
|
|
io->release();
|
|
}
|
|
|
|
return *h ? ret : HG_ERR_DEVICE_NOT_SUPPORT;
|
|
}
|
|
hg_err hg_scanner_mgr::hg_scanner_close(scanner_handle h, bool force)
|
|
{
|
|
{
|
|
std::lock_guard<std::mutex> lock(mutex_dev_);
|
|
for (size_t i = 0; i < online_devices_.size(); ++i)
|
|
{
|
|
if (online_devices_[i].scanner == h)
|
|
{
|
|
online_devices_[i].scanner = NULL;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
SCAN_PTR(h)->close(force);
|
|
delete SCAN_PTR(h);
|
|
|
|
return HG_ERR_OK;
|
|
}
|
|
hg_err hg_scanner_mgr::hg_scanner_get_parameter(scanner_handle h, unsigned param_no, char* data, long* len)
|
|
{
|
|
if (!len)
|
|
return HG_ERR_INVALID_PARAMETER;
|
|
|
|
int l = *len,
|
|
err = SCAN_PTR(h)->get_setting(param_no, data, &l);
|
|
|
|
*len = l;
|
|
|
|
return (hg_err)err;
|
|
}
|
|
hg_err hg_scanner_mgr::hg_scanner_set_parameter(scanner_handle h, unsigned param_no, void* data, long len)
|
|
{
|
|
return (hg_err)SCAN_PTR(h)->set_setting(param_no, data, len);
|
|
}
|
|
hg_err hg_scanner_mgr::hg_scanner_start(scanner_handle h, void* async_event, int num)
|
|
{
|
|
return (hg_err)SCAN_PTR(h)->start();
|
|
}
|
|
hg_err hg_scanner_mgr::hg_scanner_stop(scanner_handle h)
|
|
{
|
|
return (hg_err)SCAN_PTR(h)->stop();
|
|
}
|
|
hg_err hg_scanner_mgr::hg_scanner_get_img_info(scanner_handle h, SANE_Parameters* bmi, long len)
|
|
{
|
|
return (hg_err)SCAN_PTR(h)->get_image_info(bmi);
|
|
}
|
|
hg_err hg_scanner_mgr::hg_scanner_read_img_data(scanner_handle h, unsigned char* data, long* len)
|
|
{
|
|
if (!len)
|
|
return HG_ERR_INVALID_PARAMETER;
|
|
|
|
int l = *len,
|
|
err = SCAN_PTR(h)->read_image_data(data, &l);
|
|
|
|
*len = l;
|
|
|
|
return (hg_err)err;
|
|
}
|
|
hg_err hg_scanner_mgr::hg_scanner_get_status(scanner_handle h, int setstutas)
|
|
{
|
|
return (hg_err)SCAN_PTR(h)->status();
|
|
}
|
|
hg_err hg_scanner_mgr::hg_scanner_reset(scanner_handle h)
|
|
{
|
|
return (hg_err)SCAN_PTR(h)->reset();
|
|
}
|
|
hg_err hg_scanner_mgr::hg_scanner_control(scanner_handle h, unsigned long code, void* data, unsigned* len)
|
|
{
|
|
//if (!len && code != IO_CTRL_CODE_TEST_SINGLE)
|
|
// return HG_ERR_INVALID_PARAMETER;
|
|
|
|
if (code == IO_CTRL_CODE_ABOUT_INFO)
|
|
return get_about_info(h, data, len);
|
|
else if (!h)
|
|
return HG_ERR_INVALID_PARAMETER;
|
|
else
|
|
return (hg_err)SCAN_PTR(h)->device_io_control(code, data, len);
|
|
}
|