code_app/sdk/webservice/ManagerV2.h

336 lines
13 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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 "base/HGThread.h"
#include "sane/sane_ex.h"
#include "sane/sane_option_definitions.h"
#include "Manager.h"
#include "Msg.h"
#include "sqlite3.h"
#include <string>
#include <list>
#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,
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
{
DeviceParam()
{
valueType = 0;
intValue = 0;
doubleValue = 0;
boolValue = false;
rangeType = 0;
intValueMin = 0;
intValueMax = 0;
doubleValueMin = 0;
doubleValueMax = 0;
}
// 配置名
std::string name;
std::string title;
int valueType; // 0-无1-字符串2-整型3-浮点4-布尔
std::string stringValue;
int intValue;
double doubleValue;
bool boolValue;
int rangeType; // 0-无1-字符串列表2-整型列表3-浮点数列表4-整型范围5-浮点数范围
std::vector<std::string> stringValueList;
std::vector<int> intValueList;
std::vector<double> doubleValueList;
int intValueMin;
int intValueMax;
double doubleValueMin;
double doubleValueMax;
};
struct DeviceParamsGroup
{
std::string groupTitle;
std::vector<DeviceParam> devParams;
};
struct BatchTableInfo
{
int id;
std::string format;
};
struct ImageThumbInfo
{
std::string tag;
std::string thumbBase64;
};
class ManagerV2 : public Manager
{
public:
ManagerV2(HGMsgPump msgPump);
virtual ~ManagerV2();
// 反初始化
void DeinitDev(const DeinitDevParam* param);
// 关闭设备
void CloseDev(const CloseDevParam* param);
// 扫描完成
void ScanFinish(const ScanFinishParam* param);
// 添加文件
void AddSavedFile(const AddSavedFileParam* param);
// 删除文件
void RemoveSavedFile(const RemoveSavedFileParam* param);
void AddUser(class WSUser *user);
void RemoveUser(class WSUser *user);
// 设置全局配置
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, bool temp, std::string& imagePath, std::string& errInfo);
// 删除本地文件
int DeleteLocalFile(const std::string& filePath, std::string& errInfo);
// 清理全局文件保存目录
int ClearGlobalFileSavePath(std::string& errInfo);
// 上传文件
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 MergeLocalImage(const std::vector<std::string>& imagePathList, const std::string& mode,
const std::string& align, int interval, bool temp, std::string& outImagePath, std::string& errInfo);
// 本地合成多张图像
int LocalMakeMultiImage(const std::vector<std::string>& imagePathList, const std::string& format,
const std::string& tiffCompression, int tiffJpegQuality, bool temp, std::string& outImagePath, std::string& errInfo);
// 拆分本地图像
int SplitLocalImage(const std::string& imagePath, const std::string& mode, int location, bool temp,
std::vector<std::string>& outImagePathList, std::string& errInfo);
// 本地生成压缩文件
int LocalMakeZipFile(const std::vector<std::string>& filePathList, const std::vector<std::string>& nameList,
const std::string &zipPath, bool temp, std::string& outZipPath, std::string& errInfo);
// 本地图像纠偏
int LocalImageDeskew(const std::string& imagePath, bool autoCrop, bool deskew, bool fillBlank, int width, int height,
bool temp, std::string& outImagePath, std::string& errInfo);
// 本地图像添加水印
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, bool temp, std::string& outImagePath, std::string& errInfo);
// 去污
int LocalImageDecontamination(const std::string& imagePath, const std::string mode, const std::string& color,
int x, int y, int width, int height, bool temp, std::string& outImagePath, std::string& errInfo);
// 图像方向校正
int LocalImageDirectionCorrect(const std::string& imagePath, bool temp, std::string& outImagePath, std::string& errInfo);
// 裁剪图像
int LocalImageClip(const std::string& imagePath, int x, int y, int width, int height,
bool temp, std::string& outImagePath, 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 GetDeviceSN(std::string& sn, std::string& errInfo);
// 获取设备固件版本号
int GetDeviceFWVersion(std::string& fwVer, std::string& errInfo);
// 设置设备参数
int SetDeviceParam(const std::vector<DeviceParam>& devParams, std::string& errInfo);
// 获取设备参数
int GetDeviceParam(std::vector<DeviceParamsGroup>& devParams, std::string& errInfo);
// 重置设备参数
int ResetDeviceParam(std::string& errInfo);
// 获取当前设备名
int GetCurrDeviceName(std::string& deviceName, std::string& errInfo);
// 开始扫描
int StartScan(bool blankCheck, bool temp, 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);
// 新建批次
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);
// 绑定文件夹
int BindFolder(const std::string &folder, const std::string &nameMode, int nameWidth, int nameBase, std::string& errInfo);
// 停止绑定文件夹
int StopBindFolder(std::string& errInfo);
// 加载图像缩略图列表
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, bool temp, 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);
// 图像交换位置
int ExchangeImage(int imageIndex1, int imageIndex2, std::string& errInfo);
// 图像书籍排序
int ImageBookSort(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(bool temp, const std::string& suffix);
int SaveImage(HGImage image, bool temp, std::string &imagePath);
void LoadSaveFilePathList(std::list<std::string> &savePathList);
void RestoreSaveFilePathList(const std::list<std::string>& savePathList);
void LoadDeviceParams(const std::string &devName, std::vector<DeviceParam>& devParams);
void RestoreDeviceParams(const std::string& devName, const std::vector<DeviceParamsGroup>& devParams);
static int SetParamsToDevice(SANE_Handle hdev, const std::vector<DeviceParam>& devParams);
static int GetParamsFromDevice(SANE_Handle hdev, std::vector<DeviceParamsGroup>& devParams);
static int ResetParamsToDevice(SANE_Handle hdev);
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);
int GetId(int idx);
void GetBatchTableInfo(std::vector<BatchTableInfo>& tables);
void ClearBindFolder();
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);
HGUInt GetDpi();
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param);
static void HGAPI ThreadFunc(HGThread thread, HGPointer param);
private:
HGLock m_lock;
GlobalConfig m_globalCfg;
std::list<class WSUser *> m_user;
HGBool m_stopThread;
HGUInt m_timeout;
HGEvent m_event;
HGThread m_thread;
bool m_initDevice;
std::vector<std::string> m_devNameList;
bool m_openDevice;
SANE_Handle m_devHandle;
std::string m_devName;
std::vector<DeviceParamsGroup> m_devParams;
bool m_scanBlankCheck;
bool m_scanTemp;
bool m_scanning;
HGEvent m_scanEvent;
HGUInt m_dpi;
sqlite3* m_sqlite;
std::string m_currBatchId;
std::string m_bindFolder;
std::string m_bindNameMode;
int m_bindNameWidth;
int m_bindNameBase;
std::list<std::string> m_saveFilePathList;
};
}