code_app/sdk/webservice/ManagerV2.h

384 lines
14 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"
2022-06-07 10:22:27 +00:00
#include "sqlite3.h"
#include <string>
#include <vector>
namespace ver_2
{
enum
{
SANEEVENT_ARRIVE = 1L,
SANEEVENT_REMOVE,
SANEEVENT_STATUS,
SANEEVENT_WORKING,
SANEEVENT_FINISH,
SANEEVENT_ERROR
};
struct GlobalConfig
{
enum
{
fileSavePathMask = 0x00000001,
fileNamePrefixMask = 0x00000002,
fileNameModeMask = 0x00000004,
imageFormatMask = 0x00000008,
imageJpegQualityMask = 0x00000010,
imageTiffCompressionMask = 0x00000020,
2022-06-13 11:56:43 +00:00
imageTiffJpegQualityMask = 0x00000040
};
GlobalConfig()
{
imageJpegQuality = 0;
imageTiffJpegQuality = 0;
}
// 文件保存
std::string fileSavePath;
std::string fileNamePrefix;
std::string fileNameMode;
// 图像保存
std::string imageFormat;
int imageJpegQuality;
std::string imageTiffCompression;
int imageTiffJpegQuality;
};
struct DeviceParam
{
enum
{
colorModeMask = 0x00000001,
pageModeMask = 0x00000002,
resolutionMask = 0x00000004,
brightnessMask = 0x00000008,
contrastMask = 0x00000010,
gammaMask = 0x00000020,
paperSizeMask = 0x00000040,
paperCutEnabledMask = 0x00000080,
paperCutLeftMask = 0x00000100,
paperCutTopMask = 0x00000200,
paperCutRightMask = 0x00000400,
paperCutBottomMask = 0x00000800,
autoCropMask = 0x00001000,
};
DeviceParam()
{
Reset();
}
void Reset()
{
colorModeList.clear();
colorMode.clear();
pageModeList.clear();
pageMode.clear();
resolutionList.clear();
resolution = 0;
brightnessMin = 0;
brightnessMax = 0;
brightness = 0;
contrastMin = 0;
contrastMax = 0;
contrast = 0;
gammaMin = 0;
gammaMax = 0;
gamma = 0;
paperSizeList.clear();
paperSize.clear();
paperSizeWidth = 0;
paperSizeHeight = 0;
paperCutEnabled = false;
paperCutLeft = 0;
paperCutTop = 0;
paperCutRight = 0;
paperCutBottom = 0;
autoCrop = false;
}
// 颜色模式
std::vector<std::string> colorModeList;
std::string colorMode;
// 扫描页面
std::vector<std::string> pageModeList;
std::string pageMode;
// 分辨率
std::vector<int> resolutionList;
int resolution;
// 亮度
int brightnessMin;
int brightnessMax;
int brightness;
// 对比度
int contrastMin;
int contrastMax;
int contrast;
// 伽马
double gammaMin;
double gammaMax;
double gamma;
// 纸张尺寸
std::vector<std::string> paperSizeList;
std::string paperSize;
double paperSizeWidth;
double paperSizeHeight;
// 手动裁剪
bool paperCutEnabled;
double paperCutLeft;
double paperCutTop;
double paperCutRight;
double paperCutBottom;
// 是否纠偏
bool autoCrop;
};
2022-06-11 06:18:33 +00:00
struct MainTableInfo
{
int id;
std::string tableName;
};
struct BatchTableInfo
{
int id;
int idx;
std::string format;
};
2022-06-09 09:30:04 +00:00
struct ImageThumbInfo
{
int idx;
std::string tag;
std::string thumbBase64;
};
typedef void (*SaneEvent)(int code, const char *str, bool err, void* param);
typedef void (*SaneImageCallback)(const char* path, void* param);
class ManagerV2 : public Manager
{
public:
ManagerV2(HGMsgPump msgPump);
virtual ~ManagerV2();
// 关闭设备
void CloseDev(const CloseDevParam* param);
// 扫描完成
void ScanFinish(const ScanFinishParam* param);
// 设置回调
void SetSaneEvent(SaneEvent event, void* param);
void SetSaneImageCallback(SaneImageCallback func, void* param);
// 清理回调
void ResetSaneEvent();
void ResetSaneImageCallback();
// 设置全局配置
int SetGlobalConfig(const GlobalConfig& cfg, HGUInt mask, std::string &errInfo);
// 获取全局配置
int GetGlobalConfig(GlobalConfig& cfg, std::string& errInfo);
// 加载本地图像
int LoadLocalImage(const std::string& imagePath, std::string& imgBase64, std::string& errInfo);
// 保存本地图像
int SaveLocalImage(const std::string& imgBase64, std::string& imagePath, std::string& errInfo);
// 删除本地文件
int DeleteLocalFile(const std::string& filePath, std::string& errInfo);
// 清理全局文件保存目录
int ClearGlobalFileSavePath(std::string& errInfo);
// 合成本地图像
int MergeLocalImage(const std::vector<std::string>& imagePathList, const std::string& mode,
const std::string& align, int interval, std::string& outImagePath, std::string& errInfo);
// 本地合成多张图像
int LocalMakeMultiImage(const std::vector<std::string>& imagePathList, const std::string& format,
const std::string& tiffCompression, int tiffJpegQuality, std::string& outImagePath, std::string& errInfo);
// 拆分本地图像
int SplitLocalImage(const std::string& imagePath, const std::string& mode, int location,
std::vector<std::string>& outImagePathList, std::string& errInfo);
// 本地生成压缩文件
int LocalMakeZipFile(const std::vector<std::string>& filePathList, const std::vector<std::string>& nameList,
std::string& outZipPath, std::string& errInfo);
// 本地图像纠偏
int LocalImageDeskew(const std::string& imagePath, std::string& outImagePath, std::string& errInfo);
2022-06-13 11:56:43 +00:00
// 本地图像添加水印
int LocalImageAddWatermark(const std::string& imagePath, const std::string& text, const std::string& textColor, int textOpacity, const std::string& textPos,
int marginLeft, int marginTop, int marginRight, int marginBottom, int locationX, int locationY, const std::string& fontName,
int fontSize, bool fontBold, bool fontUnderline, bool fontItalic, bool fontStrikeout, std::string& outImagePath, std::string& errInfo);
// 上传文件
2022-06-13 11:56:43 +00:00
int UploadLocalFile(const std::string& filePath, const std::string& remoteFilePath, const std::string& uploadMode,
const std::string &httpHost, int httpPort, const std::string& httpPath, const std::string &ftpUser, const std::string& ftpPassword,
const std::string& ftpHost, int ftpPort, std::string& errInfo);
// 设备初始化
int InitDevice(std::string& errInfo);
// 设备反初始化
int DeinitDevice(std::string& errInfo);
// 是否已经初始化
bool IsDeviceInit();
// 获取设备列表
int GetDeviceNameList(std::vector<std::string> &deviceNameList, std::string& errInfo);
// 打开设备
int OpenDevice(const std::string& deviceName, std::string& errInfo);
// 关闭设备
int CloseDevice(std::string& errInfo);
// 设置设备参数
int SetDeviceParam(const DeviceParam& param, HGUInt mask, std::string& errInfo);
// 获取设备参数
int GetDeviceParam(DeviceParam& param, std::string& errInfo);
// 获取当前设备名
int GetCurrDeviceName(std::string& deviceName, std::string& errInfo);
// 开始扫描
int StartScan(std::string& errInfo);
// 停止扫描
int StopScan(std::string& errInfo);
// 是否已经启动扫描
bool IsScanning();
// 获取批次号列表
int GetBatchIdList(std::vector<std::string> &batchIdList, std::string& errInfo);
// 打开批次
int OpenBatch(const std::string &batchId, std::string& errInfo);
// 删除批次
int DeleteBatch(const std::string& batchId, std::string& errInfo);
// 新建批次
2022-06-07 10:22:27 +00:00
int NewBatch(const std::string& batchId, std::string& errInfo);
// 获取当前批次号
int GetCurrBatchId(std::string& batchId, std::string& errInfo);
// 修改批次号
int ModifyBatchId(const std::string& batchId, const std::string& newBatchId, std::string& errInfo);
2022-06-11 06:18:33 +00:00
// 绑定文件夹
int BindFolder(const std::string &folder, const std::string &nameMode, int nameWidth, int nameBase, std::string& errInfo);
2022-06-11 06:18:33 +00:00
// 停止绑定文件夹
int StopBindFolder(std::string& errInfo);
2022-06-09 09:30:04 +00:00
// 加载图像缩略图列表
int GetImageThumbnailList(std::vector<ImageThumbInfo>& imageThumbList, std::string& errInfo);
// 获取图像数量
int GetImageCount(int& imageCount, std::string& errInfo);
// 加载图像
int LoadImage(int imageIndex, std::string& imageTag, std::string& imageBase64, std::string& errInfo);
// 保存图像
int SaveImage(int imageIndex, std::string& imagePath, std::string& errInfo);
// 插入本地图像
int InsertLocalImage(const std::string& imagePath, int insertPos, const std::string& imageTag, std::string& errInfo);
// 插入图像
int InsertImage(const std::string& imageBase64, int insertPos, const std::string& imageTag, std::string& errInfo);
// 修改图像标签
int ModifyImageTag(const std::vector<int>& imageIndexList, const std::vector<std::string>& imageTagList, std::string& errInfo);
// 删除图像
int DeleteImage(const std::vector<int>& imageIndexList, std::string& errInfo);
// 清理图像列表
int ClearImageList(std::string& errInfo);
// 修改图像
int ModifyImage(int imageIndex, const std::string& imageBase64, std::string& errInfo);
// 使用本地图像修改图像
int ModifyImageByLocal(int imageIndex, const std::string& imagePath, std::string& errInfo);
// 移动图像
int MoveImage(const std::vector<int>& imageIndexList, const std::string& mode, int target, std::string& errInfo);
2022-06-11 06:18:33 +00:00
// 图像交换位置
int ExchangeImage(int imageIndex1, int imageIndex2, std::string& errInfo);
// 图像书籍排序
int ImageBookSort(std::string& errInfo);
// 合成图像
int MergeImage(const std::vector<int>& imageIndexList, const std::string& mode,
const std::string& align, int interval, std::string& outImagePath, std::string& errInfo);
// 合成多张图像
int MakeMultiImage(const std::vector<int>& imageIndexList, const std::string& format,
const std::string& tiffCompression, int tiffJpegQuality, std::string& outImagePath, std::string& errInfo);
// 拆分图像
int SplitImage(int imageIndex, const std::string& mode, int location, std::vector<std::string>& outImagePathList,
std::string& errInfo);
// 压缩图像
int MakeZipFile(const std::vector<int>& imageIndexList, std::string& outZipPath, std::string& errInfo);
// 图像纠偏
int ImageDeskew(int imageIndex, std::string& outImagePath, std::string& errInfo);
2022-06-13 11:56:43 +00:00
// 图像添加水印
int ImageAddWatermark(int imageIndex, const std::string& text, const std::string& textColor, int textOpacity, const std::string& textPos,
int marginLeft, int marginTop, int marginRight, int marginBottom, int locationX, int locationY, const std::string& fontName,
int fontSize, bool fontBold, bool fontUnderline, bool fontItalic, bool fontStrikeout, std::string& outImagePath, std::string& errInfo);
public:
static int LoadBase64(const std::string& fileName, std::string& base64);
static int SaveBase64(const std::string& base64, const std::string& fileName);
private:
static std::string GetCfgStringValue(const std::string& app, const std::string& key, const std::string& def);
static int GetCfgIntValue(const std::string& app, const std::string& key, int def);
static double GetCfgDoubleValue(const std::string& app, const std::string& key, double def);
static bool GetCfgBoolValue(const std::string& app, const std::string& key, bool def);
static bool SetCfgStringValue(const std::string& app, const std::string& key, const std::string& val);
static bool SetCfgIntValue(const std::string& app, const std::string& key, int val);
static bool SetCfgDoubleValue(const std::string& app, const std::string& key, double val);
static bool SetCfgBoolValue(const std::string& app, const std::string& key, bool val);
static int HttpUpload(const std::string &host, int port, const std::string &path,
const std::string& filePath, const std::string& remoteFilePath);
static int FtpUpload(const std::string& user, const std::string& password, const std::string& host, int port,
const std::string& filePath, const std::string& remoteFilePath);
std::string GetFilePath(const std::string& suffix);
int SaveImage(HGImage image, std::string &imagePath);
static void LoadSaveFilePathList(std::vector<std::string> &savePathList);
static void RestoreSaveFilePathList(const std::vector<std::string>& savePathList);
static void LoadDeviceParam(const std::string &devName, DeviceParam &devParam);
static void RestoreDeviceParam(const std::string& devName, const DeviceParam& devParam);
static int SetParamToDevice(SANE_Handle hdev, const DeviceParam& devParam, HGUInt mask);
static int GetParamFromDevice(SANE_Handle hdev, DeviceParam& devParam);
int SaveImage(int imageIndex, std::string& imagePath);
2022-06-09 09:30:04 +00:00
static HGByte* LoadImageFromPath(const std::string& imagePath, HGUInt& size, std::string& format);
static HGByte* LoadImageFromBase64(const std::string& imageBase64, HGUInt& size, std::string& format);
static HGByte* LoadThumbFromPath(const std::string& imagePath, HGUInt& size);
static HGByte* LoadThumbFromBase64(const std::string& imageBase64, HGUInt& size);
static bool SaveToBase64(const HGByte* data, HGUInt size, std::string& base64);
static bool SaveToFile(const HGByte* data, HGUInt size, const std::string &filePath);
2022-06-11 06:18:33 +00:00
void GetBatchTableInfo(std::vector<BatchTableInfo>& tables);
void ClearBindFolder();
2022-06-11 06:18:33 +00:00
void UpdateBindFolder();
void InsertBindFolderImage(const std::vector<BatchTableInfo>& tables, int insertPos, const std::string imgFmt,
const HGByte *imgData, HGUInt imgSize);
void ModifyBindFolderImage(const std::vector<BatchTableInfo>& tables, int imageIndex, const std::string imgFmt,
const HGByte* imgData, HGUInt imgSize);
void DeleteBindFolderImage(const std::vector<BatchTableInfo>& tables, const std::vector<int>& imageIndexList);
void ExchangeBindFolderImage(const std::vector<BatchTableInfo>& tables, int imageIndex1, int imageIndex2);
void ClearBindFolderImageList(const std::vector<BatchTableInfo>& tables);
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param);
private:
HGLock m_lock;
GlobalConfig m_globalCfg;
std::vector<std::string> m_saveFilePathList;
SaneEvent m_saneEvent;
void* m_saneParam;
SaneImageCallback m_saneImageCallback;
void* m_saneImageParam;
bool m_initDevice;
std::vector<std::string> m_devNameList;
bool m_openDevice;
SANE_Handle m_devHandle;
std::string m_devName;
2022-06-09 09:30:04 +00:00
bool m_devParamValid;
DeviceParam m_devParam;
bool m_scanning;
HGEvent m_scanEvent;
2022-06-07 10:22:27 +00:00
sqlite3* m_sqlite;
std::string m_currBatchId;
2022-06-11 06:18:33 +00:00
std::string m_bindFolder;
std::string m_bindNameMode;
int m_bindNameWidth;
int m_bindNameBase;
};
}