code_app/sdk/webservice/ManagerV1.h

194 lines
7.5 KiB
C
Raw Normal View History

#pragma once
#include "base/HGDef.h"
#include "base/HGInc.h"
#include "base/HGLock.h"
#include "base/HGImage.h"
#include "base/HGMsgPump.h"
#include "base/HGEvent.h"
#include "sane/sane_ex.h"
#include "sane/sane_option_definitions.h"
#include "Manager.h"
#include "Msg.h"
#include <string>
#include <list>
#include <vector>
namespace ver_1
{
enum
{
SANEEVENT_ARRIVE = 1L,
SANEEVENT_REMOVE,
SANEEVENT_STATUS,
SANEEVENT_WORKING,
SANEEVENT_FINISH,
SANEEVENT_ERROR
};
struct DevParam
{
DevParam();
~DevParam();
void Reset();
void Load(const std::string& devName);
void Save(const std::string& devName);
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; // 扫描幅面 A3A3幅面 Auto:自适应幅面 A4A4幅面默认Auto
int splitImage; // 图像分割 0disable 1垂直分割 2 水平分割默认0
bool noiseDetachEnable; // 去除噪点默认true
int noiseDetach; // 噪点阈值 范围10­-50 默认值15
int uploadMode; // 是否边扫边上传 0http 1ftp 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; // 上传模式 0http 1ftp 默认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
};
class ManagerV1 : public Manager
{
public:
ManagerV1(HGMsgPump msgPump);
virtual ~ManagerV1();
// 打开设备
void OpenDev(const OpenDevParam* param);
// 关闭设备
void CloseDev(const CloseDevParam* param);
// 扫描完成
void ScanFinish(const ScanFinishParam* param);
void AddUser(class SockIoUser *user);
void RemoveUser(class SockIoUser *user);
// 扫描
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, const std::string& fileName);
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, const std::string& fileName);
bool ExportPdfFile(const std::string& devId, HGByte** data, HGUInt* size);
// 生成TIFF
bool ExportTiff(const std::string& devId, std::string& imgBase64);
bool ExportTiff(const std::string& devId, const std::string& fileName);
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, const std::string& fileName);
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);
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 bool HTTPUpload(const std::string& localFileName, const std::string& httpUrl, const std::string& remoteFileName,
const std::string& httpMethod, const std::string& header, const std::string& param);
static bool FTPUpload(const std::string& localFileName, const std::string& ftpUrl, int ftpPort, const std::string& ftpPath,
const std::string& ftpUser, const std::string& ftpPassword, int ftpMode);
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param);
private:
HGLock m_lock;
std::string m_devName;
SANE_Handle m_devHandle;
DevParam m_devParam;
std::list<class SockIoUser *> m_user;
std::string m_scanInsertImgName;
bool m_scanIsInsert;
bool m_scanning;
HGEvent m_scanEvent;
};
}