99 lines
3.0 KiB
C++
99 lines
3.0 KiB
C++
#pragma once
|
||
|
||
#include "sane/sane_ex.h"
|
||
#include "../sdk/hginclude/huagaoxxx_warraper_ex.h"
|
||
|
||
#include <vector>
|
||
#include <algorithm>
|
||
#include <string>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
class device_opts;
|
||
class hg_sane_middleware
|
||
{
|
||
typedef struct _dev_inst
|
||
{
|
||
scanner_handle dev;
|
||
std::string name;
|
||
device_opts* opts;
|
||
|
||
_dev_inst()
|
||
{
|
||
dev = nullptr;
|
||
name = "";
|
||
opts = nullptr;
|
||
}
|
||
}DEVINST, * LPDEVINST;
|
||
|
||
bool init_ok_;
|
||
std::vector<LPDEVINST> openning_;
|
||
LPDEVINST offline_;
|
||
|
||
static hg_sane_middleware *inst_;
|
||
static const SANE_Device** dev_list_;
|
||
|
||
|
||
|
||
static const SANE_Device** to_sane_device(ScannerInfo* hgscanner, int count); // 将驱动层传回的设备列表数据,转换为标准SANE协议的设备列表
|
||
static void free_sane_device(SANE_Device** dev); // 释放由to_sane_device返回的指针
|
||
static void device_pnp(int sig); // 热插拔事件监控
|
||
static SANE_Fixed double_2_sane_fixed(double v);
|
||
static double sane_fixed_2_double(SANE_Fixed v);
|
||
static scanner_handle sane_handle_to_scanner(SANE_Handle h);
|
||
static void free_device_instance(LPDEVINST inst);
|
||
|
||
LPDEVINST find_openning_device(SANE_Handle h, bool rmv = false);
|
||
LPDEVINST find_openning_device(const char* name, bool rmv = false);
|
||
bool reload_options(LPDEVINST inst);
|
||
|
||
scanner_err read_value(scanner_handle h, const char* name, SANE_Value_Type type, size_t len, void* value, bool to_default);
|
||
scanner_err write_value(scanner_handle h, const char* name, SANE_Value_Type type, void* value, bool to_default, LPDEVINST optinst, SANE_Int* affect);
|
||
SANE_Status get_current_value(LPDEVINST inst, const void* opt, void* value, bool default_val);
|
||
SANE_Status set_value(LPDEVINST inst, const void* opt, void* value, SANE_Int* affect, bool to_default);
|
||
SANE_Status get_option_fixed_id(LPDEVINST inst, const void* opt, void* value);
|
||
|
||
protected:
|
||
hg_sane_middleware(void);
|
||
~hg_sane_middleware();
|
||
|
||
public:
|
||
enum
|
||
{
|
||
APP_CALLBACK_AUTH = 0,
|
||
APP_CALLBACK_EX,
|
||
};
|
||
static void set_app_callback(void* cb, void* param = nullptr, int type = APP_CALLBACK_AUTH);
|
||
static void get_version(SANE_Int* ver);
|
||
static hg_sane_middleware* instance(void);
|
||
static void clear(void);
|
||
static SANE_Handle scanner_handle_to_sane(scanner_handle h);
|
||
|
||
// methods ...
|
||
public:
|
||
SANE_Status get_devices(const SANE_Device*** device_list, SANE_Bool local_only);
|
||
SANE_Status open_device(SANE_String_Const devicename, SANE_Handle* handle);
|
||
SANE_Status close_device(SANE_Handle h);
|
||
SANE_Status get_image_parameters(SANE_Handle handle, SANE_Parameters* params);
|
||
SANE_Status start(SANE_Handle h, void* async_event);
|
||
SANE_Status read(SANE_Handle h, void* buf, int* bytes);
|
||
SANE_Status stop(SANE_Handle h);
|
||
SANE_Option_Descriptor* get_option_descriptor(SANE_Handle h, const void* option);
|
||
SANE_Status control_option(SANE_Handle h, const void* option, SANE_Action action, void* value, SANE_Int* after_do);
|
||
|
||
// extension ...
|
||
SANE_Status ex_io_control(SANE_Handle h, unsigned long code, void* data, unsigned* len);
|
||
|
||
public:
|
||
bool is_ready(void);
|
||
};
|
||
|
||
namespace local_utility
|
||
{
|
||
void free_memory(void* m);
|
||
int sane_statu_2_scanner_err(int statu);
|
||
}
|