code_app/sane_user/HGSaneImpl.hpp

93 lines
2.5 KiB
C++
Raw Normal View History

2022-05-03 10:25:52 +00:00
#ifndef __HGSANEIMPL_HPP__
#define __HGSANEIMPL_HPP__
#include "HGSane.h"
#include "../base/HGDll.h"
#include "../base/HGThread.h"
#include "../base/HGLock.h"
#include "sane.h"
#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);
struct HGSaneDeviceImpl
{
HGSaneDeviceImpl(class HGSaneManagerImpl* mgr)
{
mgrImpl = mgr;
HGBase_CreateLock(&lock);
devHandle = NULL;
func = NULL;
param = NULL;
stopThread = HGFALSE;
thread = NULL;
imgReady = HGFALSE;
}
~HGSaneDeviceImpl()
{
HGBase_DestroyLock(lock);
lock = NULL;
}
class HGSaneManagerImpl* mgrImpl;
HGLock lock;
SANE_Handle devHandle;
HGSane_DeviceEventCallback func;
HGPointer param;
HGBool stopThread;
HGThread thread;
HGBool imgReady;
std::vector<SANE_Byte> recvData;
};
class HGSaneManagerImpl
{
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, HGSaneDeviceImpl **device);
HGResult CloseDevice(HGSaneDeviceImpl *device);
HGResult StartDevice(HGSaneDeviceImpl* device, HGSane_DeviceEventCallback func, HGPointer param);
HGResult StopDevice(HGSaneDeviceImpl* device);
HGResult GetImage(HGSaneDeviceImpl* device, HGUInt type, HGUInt origin, HGImage* image);
private:
static void ThreadFunc(HGThread thread, HGPointer param);
HGResult FindFunctions();
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;
std::list<HGSaneDeviceImpl*> m_devList;
};
#endif /* __HGSANEIMPL_HPP__ */