code_app/modules/sane_user/HGSaneImpl.hpp

104 lines
3.2 KiB
C++

#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 <list>
#include <vector>
#include <string>
class HGSaneManagerImpl
{
friend class HGSaneSourceImpl;
public:
HGSaneManagerImpl();
~HGSaneManagerImpl();
HGResult Create();
HGResult Destroy();
HGResult GetSourceCount(HGUInt *count);
HGResult GetSourceName(HGUInt index, HGChar* name, HGUInt maxLen);
HGResult OpenSource(HGUInt index, class HGSaneSourceImpl **sourceImpl);
HGResult OpenSelectedSource(HGWindow parent, class HGSaneSourceImpl **sourceImpl);
private:
void RemoveSource(class HGSaneSourceImpl* sourceImpl);
private:
std::vector<std::pair<std::string, std::string>> m_vSource;
std::list<class HGSaneSourceImpl *> m_listSourceImpl;
};
class HGSaneSourceImpl
{
friend class HGSaneDeviceImpl;
public:
HGSaneSourceImpl(HGSaneManagerImpl *managerImpl);
~HGSaneSourceImpl();
HGResult Init(const HGChar* saneManu, HGDll dll, const SANEAPI *saneAPI);
HGResult Open(const HGChar* saneManu, const HGChar* sanePath);
HGResult Close();
HGResult GetName(HGChar* name, HGUInt maxLen);
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:
static HGResult FindFunctions(HGDll dll, const HGChar* saneManu, SANEAPI *saneAPI);
void RemoveDevice(class HGSaneDeviceImpl* deviceImpl);
private:
HGSaneManagerImpl *m_managerImpl;
std::string m_manuName;
HGDll m_dll;
SANEAPI m_saneApi;
std::list<class HGSaneDeviceImpl*> m_listDeviceImpl;
};
class HGSaneDeviceImpl
{
public:
HGSaneDeviceImpl(HGSaneSourceImpl* sourceImpl);
~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 GetCustomInfo(HGSaneCustomInfo *info);
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:
HGResult GetValue(const HGChar *name, HGInt *value);
HGResult GetValue(const HGChar *name, HGChar *value, HGUInt maxLen);
static void HGAPI ThreadFunc(HGThread thread, HGPointer param);
static void ShowScanImageCallback(const SANE_Parameters* imageFormat, const SANE_Byte* imageData, void* callbackParam);
private:
HGSaneSourceImpl* m_sourceImpl;
std::string m_devName;
SANE_Handle m_devHandle;
HGByte* m_buffer;
HGInt m_bufferSize;
HGInt 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__ */