181 lines
6.7 KiB
C++
181 lines
6.7 KiB
C++
#ifndef __MANAGER_H__
|
||
#define __MANAGER_H__
|
||
|
||
#include "../../base/HGDef.h"
|
||
#include "../../base/HGInc.h"
|
||
#include "../../base/HGLock.h"
|
||
#include "../../base/HGImage.h"
|
||
#include "sane_ex.h"
|
||
#include "WebMsg.h"
|
||
#include <vector>
|
||
#include <string>
|
||
|
||
#define SCANEVENT_ARRIVE 1L
|
||
#define SCANEVENT_REMOVE 2L
|
||
#define SCANEVENT_STATUS 3L
|
||
#define SCANEVENT_WORKING 4L
|
||
#define SCANEVENT_IMAGE 5L
|
||
#define SCANEVENT_FINISH 6L
|
||
#define SCANEVENT_ERROR 7L
|
||
|
||
struct DevParam
|
||
{
|
||
DevParam();
|
||
~DevParam();
|
||
|
||
void Reset();
|
||
void Load(const std::string& cfgPath);
|
||
void Save(const std::string& cfgPath);
|
||
|
||
std::string device; // 设备名称,默认null
|
||
bool autofeeder; // 自动进纸,默认true
|
||
int pixel; // 扫描模式 0:黑白 1:灰度 2:彩色,默认1
|
||
bool white; // 丢弃空白页,默认false
|
||
int discardBlankThre; // 跳过空白页阈值 1-100 默认值5
|
||
bool single; // 单页扫描,默认false
|
||
std::string format; // 输出格式 jpg png bmp tiff pdf ofd,默认jpg
|
||
int resolution; // 扫描分辨率 范围 100-600 默认值200
|
||
int orentation; // 图片旋转 0:原图 90:度 180:旋转180度 270:旋转270度,默认0
|
||
std::string paperType; // 扫描幅面 A3:A3幅面 Auto:自适应幅面 A4:A4幅面,默认Auto
|
||
int splitImage; // 图像分割 0:disable 1:垂直分割 2: 水平分割,默认0
|
||
bool noiseDetachEnable; // 去除噪点,默认true
|
||
int noiseDetach; // 噪点阈值 范围:10-50 默认值15
|
||
|
||
int uploadMode; // 是否边扫边上传 0:http 1:ftp 2: 不上传,默认2
|
||
std::string httpUrl; // 上传地址,默认null
|
||
std::string fileName; // 接收文件参数名,默认null
|
||
std::string httpMethod; // 上传方式 GET POST PUT,默认null
|
||
std::string header; // 请求头,默认null
|
||
std::string param; // 参数 json格式,默认null
|
||
std::string ftpUrl; // ftp 地址,默认null
|
||
std::string ftpPath; // 路径,默认/images
|
||
std::string ftpUser; // ftp 用户名,默认null
|
||
std::string ftpPassword; // ftp 密码,默认null
|
||
int ftpPort; // 端口号,默认21
|
||
int ftpMode; // 连接模式 1:主动 2:被动,默认2
|
||
};
|
||
|
||
struct UploadParam
|
||
{
|
||
UploadParam()
|
||
{
|
||
uploadMode = 2;
|
||
ftpPort = 21;
|
||
ftpMode = 2;
|
||
format = 2;
|
||
}
|
||
|
||
int uploadMode; // 上传模式 0:http 1:ftp 默认0
|
||
std::string httpUrl; // 上传地址,默认null
|
||
std::string fileName; // 接收文件参数名,默认null
|
||
std::string httpMethod; // 上传方式 GET POST PUT,默认null
|
||
std::string header; // 请求头,默认null
|
||
std::string param; // 参数 json格式,默认null
|
||
std::string ftpUrl; // ftp 地址,默认null
|
||
std::string ftpPath; // 路径,默认/images
|
||
std::string ftpUser; // ftp 用户名,默认null
|
||
std::string ftpPassword; // ftp 密码,默认null
|
||
int ftpPort; // 端口号,默认21
|
||
int ftpMode; // 连接模式 1:主动 2:被动,默认2
|
||
int format; // 上传格式 0: ofd 1: pdf 2: zip, 默认2
|
||
};
|
||
|
||
typedef void (*ScanEvent)(HGUInt event, void *value1, void *value2, void *param);
|
||
|
||
class Manager
|
||
{
|
||
public:
|
||
Manager(class MsgLoop* loop);
|
||
~Manager();
|
||
|
||
// 打开设备
|
||
void OpenDev(const OpenDevParam *param);
|
||
// 关闭设备
|
||
void CloseDev(const CloseDevParam* param);
|
||
|
||
// 设置回调
|
||
void SetScanEvent(ScanEvent event, void* param);
|
||
// 清理回调
|
||
void ResetScanEvent();
|
||
// 扫描
|
||
bool Scan(const std::string& insertImgName, bool isInsert);
|
||
// 停止扫描
|
||
bool StopScan();
|
||
// 获取当前连接的设备ID
|
||
bool GetCurDevId(std::string& devId);
|
||
// 获取连接的设备名列表
|
||
bool GetDevNames(std::vector<std::string> &devNameList);
|
||
// 获取上次的扫描结果
|
||
bool GetImageByDevId(const std::string& devId, std::vector<std::string> &imgNameList,
|
||
std::vector<std::string> &imgBase64List);
|
||
// 获取配置参数
|
||
bool GetDevParam(const std::string& devId, DevParam& devParam);
|
||
// 设置配置参数
|
||
bool SetDevParam(const std::string& devId, const DevParam& devParam);
|
||
// 生成OFD
|
||
bool ExportOfd(const std::string& devId, bool isAuto, std::string &imgBase64);
|
||
bool ExportOfdFile(const std::string& devId, bool isAuto, HGByte **data, HGUInt *size);
|
||
// 生成PDF
|
||
bool ExportPdf(const std::string& devId, std::string& imgBase64);
|
||
bool ExportPdfFile(const std::string& devId, HGByte** data, HGUInt* size);
|
||
// 生成TIFF
|
||
bool ExportTiff(const std::string& devId, std::string& imgBase64);
|
||
bool ExportTiffFile(const std::string& devId, HGByte** data, HGUInt* size);
|
||
// 生成ZIP
|
||
bool ExportZip(const std::string& devId, std::string& imgBase64);
|
||
bool ExportZipFile(const std::string& devId, HGByte** data, HGUInt* size);
|
||
// 上传图像
|
||
bool UploadImage(const UploadParam& uploadParam);
|
||
// 保存图片
|
||
bool SaveImage(const std::string& devId, const std::string& imgName, const std::string& imgBase64);
|
||
// 删除图片
|
||
bool DeleteImage(const std::string& devId, const std::string& imgName);
|
||
// 删除所有图片
|
||
bool DeleteAllImage(const std::string& devId);
|
||
// 图像合并
|
||
bool MergeImage(const std::string& devId, bool isHorizontal, const std::vector<int> &imgIndexList,
|
||
std::string &imgName, std::string& imgBase64);
|
||
// 自动排序
|
||
bool BookSort(const std::string& devId, std::vector<std::string>& imgNameList,
|
||
std::vector<std::string>& imgBase64List);
|
||
// 交换文件
|
||
bool ExchangeImage(const std::string& devId, int index1, int index2);
|
||
// 获取最后批次
|
||
bool GetLastBetch(std::string& devId);
|
||
// 重置索引
|
||
bool ResetPatchIndex();
|
||
// 拆分图像
|
||
bool SplitImage(const std::string& devId, const std::string& imgName, bool isHorizontal, int x1, int y1, int x2, int y2,
|
||
std::string& imgName1, std::string& imgBase64_1, std::string& imgName2, std::string& imgBase64_2);
|
||
// 获取设备序列号
|
||
bool GetDevSerialNo(const std::string& devId, std::string& serialNo);
|
||
// 获取图像Base64
|
||
bool GetImageBase64(const std::string& devId, const std::string& imgName, std::string& imgBase64);
|
||
|
||
private:
|
||
static std::string GetFilePath(const std::string& devId);
|
||
static std::vector<std::string> GetFileNameList(const std::string &devId);
|
||
static bool SaveFileNameList(const std::string& devId, const std::vector<std::string>& fileNameList);
|
||
static std::string GetBase64(HGImage image, HGUInt quality);
|
||
static std::string GetBase64(const HGByte *data, HGUInt size);
|
||
static std::string GetBase64(const std::string& fileName);
|
||
static HGByte* GetBuffer(const std::string& fileName, HGUInt *size);
|
||
static bool SaveBase64(const std::string& fileName, const char *base64);
|
||
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param);
|
||
|
||
private:
|
||
class MsgLoop* m_loop;
|
||
HGLock m_lock;
|
||
std::string m_devName;
|
||
SANE_Handle m_devHandle;
|
||
DevParam m_devParam;
|
||
ScanEvent m_scanEvent;
|
||
void* m_scanParam;
|
||
|
||
std::string m_scanInsertImgName;
|
||
bool m_scanIsInsert;
|
||
bool m_scanning;
|
||
};
|
||
|
||
#endif /* __MANAGER_H__ */
|