#ifndef __HGSANEIMPL_HPP__ #define __HGSANEIMPL_HPP__ #include "HGSane.h" #include "../base/HGInc.h" #include "../base/HGDll.h" #include "../base/HGThread.h" #include "../base/HGLock.h" #include "sane/sane_ex.h" #include "saneui/HGSaneUI.h" #include #include #include typedef SANE_Status (*f_sane_init)(SANE_Int* version_code, SANE_Auth_Callback authorize); typedef void (*f_sane_exit)(void); typedef SANE_Status (*f_sane_get_devices)(const SANE_Device*** device_list, SANE_Bool local_only); typedef SANE_Status (*f_sane_open)(SANE_String_Const devicename, SANE_Handle* handle); typedef void (*f_sane_close)(SANE_Handle handle); typedef SANE_Status (*f_sane_start)(SANE_Handle handle); typedef SANE_Status (*f_sane_read)(SANE_Handle handle, SANE_Byte* data, SANE_Int max_length, SANE_Int* length); typedef void (*f_sane_cancel)(SANE_Handle handle); typedef SANE_Status (*f_sane_set_io_mode)(SANE_Handle handle, SANE_Bool non_blocking); typedef SANE_String_Const (*f_sane_strstatus)(SANE_Status status); typedef SANE_Status (*f_sane_get_parameters)(SANE_Handle handle, SANE_Parameters* params); typedef const SANE_Option_Descriptor* (*f_sane_get_option_descriptor)(SANE_Handle handle, SANE_Int option); typedef SANE_Status (*f_sane_control_option)(SANE_Handle handle, SANE_Int option, SANE_Action action, void* value, SANE_Int* info); // 非标准接口 typedef SANE_Status (*f_sane_io_control)(SANE_Handle h, unsigned long code, void* data, unsigned* len); class HGSaneManagerImpl { friend class HGSaneDeviceImpl; public: HGSaneManagerImpl(); ~HGSaneManagerImpl(); HGResult Create(const HGChar* sanePath); HGResult Destroy(); HGResult GetDeviceCount(HGUInt *count); HGResult GetDeviceName(HGUInt index, HGChar* name, HGUInt maxLen); HGResult OpenDevice(HGUInt index, class HGSaneDeviceImpl **deviceImpl, HGChar* errInfo, HGUInt errInfoLen); HGResult OpenSelectedDevice(HGWindow parent, class HGSaneDeviceImpl** deviceImpl); private: HGResult FindFunctions(); void RemoveDevice(class HGSaneDeviceImpl* deviceImpl); private: HGDll m_dll; f_sane_init m_f_sane_init; f_sane_exit m_f_sane_exit; f_sane_get_devices m_f_sane_get_devices; f_sane_open m_f_sane_open; f_sane_close m_f_sane_close; f_sane_start m_f_sane_start; f_sane_read m_f_sane_read; f_sane_cancel m_f_sane_cancel; f_sane_set_io_mode m_f_sane_set_io_mode; f_sane_strstatus m_f_sane_strstatus; f_sane_get_parameters m_f_sane_get_parameters; f_sane_get_option_descriptor m_f_sane_get_option_descriptor; f_sane_control_option m_f_sane_control_option; f_sane_io_control m_f_sane_io_control; SANEAPI m_saneApi; std::list m_listDeviceImpl; }; class HGSaneDeviceImpl { public: HGSaneDeviceImpl(HGSaneManagerImpl* mgrImpl); ~HGSaneDeviceImpl(); HGResult Init(const HGChar* devName, SANE_Handle handle); HGResult Open(const HGChar *devName, HGChar* errInfo, HGUInt errInfoLen); HGResult Close(); HGResult GetName(HGChar* name, HGUInt maxLen); HGResult ShowSettingDlg(HGWindow parent); HGResult Start(HGSane_DeviceEventFunc eventFunc, HGPointer eventParam, HGSane_DeviceImageFunc imageFunc, HGPointer imageParam, HGChar* errInfo, HGUInt errInfoLen); HGResult Stop(); HGResult StartWithUI(HGWindow parent, HGSane_DeviceImageFunc imageFunc, HGPointer imageParam); private: HGUInt GetDpi(); static void HGAPI ThreadFunc(HGThread thread, HGPointer param); static void ShowScanImageCallback(const SANE_Parameters* imageFormat, const SANE_Byte* imageData, void* callbackParam); private: HGSaneManagerImpl* m_mgrImpl; std::string m_devName; SANE_Handle m_devHandle; HGByte* m_buffer; HGInt m_bufferSize; HGUInt m_dpi; HGSane_DeviceEventFunc m_eventFunc; HGPointer m_eventParam; HGSane_DeviceImageFunc m_imageFunc; HGPointer m_imageParam; volatile HGBool m_stopThread; HGThread m_thread; }; #endif /* __HGSANEIMPL_HPP__ */