2022-05-03 10:25:52 +00:00
|
|
|
|
#ifndef __HGSANEIMPL_HPP__
|
|
|
|
|
#define __HGSANEIMPL_HPP__
|
|
|
|
|
|
|
|
|
|
#include "HGSane.h"
|
2022-05-24 04:02:00 +00:00
|
|
|
|
#include "../base/HGInc.h"
|
2022-05-03 10:25:52 +00:00
|
|
|
|
#include "../base/HGDll.h"
|
|
|
|
|
#include "../base/HGThread.h"
|
|
|
|
|
#include "../base/HGLock.h"
|
|
|
|
|
#include "sane.h"
|
2023-03-25 07:31:09 +00:00
|
|
|
|
#include "saneopts.h"
|
2022-05-03 10:25:52 +00:00
|
|
|
|
#include <list>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
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);
|
2023-03-25 07:31:09 +00:00
|
|
|
|
typedef SANE_Status (*f_sane_get_parameters)(SANE_Handle handle, SANE_Parameters* params);
|
|
|
|
|
typedef 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);
|
2022-05-03 10:25:52 +00:00
|
|
|
|
|
|
|
|
|
class HGSaneManagerImpl
|
|
|
|
|
{
|
2023-03-25 07:31:09 +00:00
|
|
|
|
friend class HGSaneDeviceImpl;
|
2022-05-03 10:25:52 +00:00
|
|
|
|
public:
|
|
|
|
|
HGSaneManagerImpl();
|
|
|
|
|
~HGSaneManagerImpl();
|
|
|
|
|
|
|
|
|
|
HGResult Create(const HGChar* sanePath);
|
|
|
|
|
HGResult Destroy();
|
|
|
|
|
HGResult GetDeviceCount(HGUInt *count);
|
|
|
|
|
HGResult GetDeviceName(HGUInt index, HGChar* name, HGUInt maxLen);
|
2023-03-25 07:31:09 +00:00
|
|
|
|
HGResult OpenDevice(HGUInt index, class HGSaneDeviceImpl **deviceImpl, HGChar* errInfo, HGUInt errInfoLen);
|
2022-05-03 10:25:52 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
HGResult FindFunctions();
|
2023-03-25 07:31:09 +00:00
|
|
|
|
void RemoveDevice(class HGSaneDeviceImpl* deviceImpl);
|
2022-05-03 10:25:52 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2023-03-25 07:31:09 +00:00
|
|
|
|
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;
|
|
|
|
|
std::list<class HGSaneDeviceImpl*> m_listDeviceImpl;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class HGSaneDeviceImpl
|
|
|
|
|
{
|
|
|
|
|
public:
|
2023-03-25 10:03:47 +00:00
|
|
|
|
HGSaneDeviceImpl(HGSaneManagerImpl* mgrImpl);
|
2023-03-25 07:31:09 +00:00
|
|
|
|
~HGSaneDeviceImpl();
|
|
|
|
|
|
|
|
|
|
HGResult Open(const HGChar *devName, HGChar* errInfo, HGUInt errInfoLen);
|
|
|
|
|
HGResult Close();
|
|
|
|
|
HGResult GetHandle(SANE_Handle* handle);
|
2023-03-25 10:03:47 +00:00
|
|
|
|
HGResult Start(HGSane_DeviceEventFunc eventFunc, HGPointer eventParam,
|
|
|
|
|
HGSane_DeviceImageFunc imageFunc, HGPointer imageParam, HGChar* errInfo, HGUInt errInfoLen);
|
2023-03-25 07:31:09 +00:00
|
|
|
|
HGResult Stop();
|
2022-05-03 10:25:52 +00:00
|
|
|
|
|
2023-03-25 07:31:09 +00:00
|
|
|
|
private:
|
|
|
|
|
HGUInt GetDpi();
|
|
|
|
|
static void HGAPI ThreadFunc(HGThread thread, HGPointer param);
|
|
|
|
|
|
|
|
|
|
private:
|
2023-03-25 10:03:47 +00:00
|
|
|
|
HGSaneManagerImpl* m_mgrImpl;
|
2023-03-25 07:31:09 +00:00
|
|
|
|
SANE_Handle m_devHandle;
|
|
|
|
|
HGByte* m_buffer;
|
|
|
|
|
HGInt m_bufferSize;
|
|
|
|
|
HGUInt m_dpi;
|
2023-03-25 10:03:47 +00:00
|
|
|
|
HGSane_DeviceEventFunc m_eventFunc;
|
2023-03-25 07:31:09 +00:00
|
|
|
|
HGPointer m_eventParam;
|
2023-03-25 10:03:47 +00:00
|
|
|
|
HGSane_DeviceImageFunc m_imageFunc;
|
2023-03-25 07:31:09 +00:00
|
|
|
|
HGPointer m_imageParam;
|
|
|
|
|
volatile HGBool m_stopThread;
|
|
|
|
|
HGThread m_thread;
|
2022-05-03 10:25:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-05-24 04:02:00 +00:00
|
|
|
|
#endif /* __HGSANEIMPL_HPP__ */
|