实现设置和获取设备参数功能
This commit is contained in:
parent
7ae1968e47
commit
d94c216286
|
@ -73,7 +73,8 @@ namespace ver_2
|
|||
|
||||
ManagerV2::~ManagerV2()
|
||||
{
|
||||
DeinitDevice();
|
||||
std::string errInfo;
|
||||
DeinitDevice(errInfo);
|
||||
|
||||
HGBase_DestroyLock(m_lock);
|
||||
m_lock = NULL;
|
||||
|
@ -85,7 +86,8 @@ namespace ver_2
|
|||
|
||||
if (m_devName == param->devName)
|
||||
{
|
||||
CloseDevice();
|
||||
std::string errInfo;
|
||||
CloseDevice(errInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,55 +127,117 @@ namespace ver_2
|
|||
HGBase_LeaveLock(m_lock);
|
||||
}
|
||||
|
||||
int ManagerV2::SetGlobalConfig(const GlobalConfig& cfg)
|
||||
int ManagerV2::SetGlobalConfig(const GlobalConfig& cfg, HGUInt mask, std::string& errInfo)
|
||||
{
|
||||
if ("date_time" != cfg.fileNameMode && "random" != cfg.fileNameMode)
|
||||
errInfo = "参数错误";
|
||||
|
||||
if ((mask & GlobalConfig::fileSavePathMask) && cfg.fileSavePath.empty())
|
||||
return -1;
|
||||
if ("jpg" != cfg.imageFormat && "bmp" != cfg.imageFormat && "png" != cfg.imageFormat && "tif" != cfg.imageFormat
|
||||
&& "pdf" != cfg.imageFormat && "ofd" != cfg.imageFormat && "ocr-pdf" != cfg.imageFormat && "ocr-ofd" != cfg.imageFormat)
|
||||
if ((mask & GlobalConfig::fileNameModeMask) && ("date_time" != cfg.fileNameMode && "random" != cfg.fileNameMode))
|
||||
return -1;
|
||||
if (cfg.imageJpegQuality < 0 || cfg.imageJpegQuality > 100)
|
||||
if ((mask & GlobalConfig::imageFormatMask) && ("jpg" != cfg.imageFormat && "bmp" != cfg.imageFormat && "png" != cfg.imageFormat && "tif" != cfg.imageFormat
|
||||
&& "pdf" != cfg.imageFormat && "ofd" != cfg.imageFormat && "ocr-pdf" != cfg.imageFormat && "ocr-ofd" != cfg.imageFormat))
|
||||
return -1;
|
||||
if ("none" != cfg.imageTiffCompression && "lzw" != cfg.imageTiffCompression
|
||||
&& "jpeg" != cfg.imageTiffCompression && "ccitt-g4" != cfg.imageTiffCompression)
|
||||
if ((mask & GlobalConfig::imageJpegQualityMask) && (cfg.imageJpegQuality < 0 || cfg.imageJpegQuality > 100))
|
||||
return -1;
|
||||
if (cfg.imageTiffJpegQuality < 0 || cfg.imageTiffJpegQuality > 100)
|
||||
if ((mask & GlobalConfig::imageTiffCompressionMask) && ("none" != cfg.imageTiffCompression && "lzw" != cfg.imageTiffCompression
|
||||
&& "jpeg" != cfg.imageTiffCompression && "ccitt-g4" != cfg.imageTiffCompression))
|
||||
return -1;
|
||||
if ((mask & GlobalConfig::imageTiffJpegQualityMask) && (cfg.imageTiffJpegQuality < 0 || cfg.imageTiffJpegQuality > 100))
|
||||
return -1;
|
||||
|
||||
HGBase_EnterLock(m_lock);
|
||||
m_globalCfg = cfg;
|
||||
m_globalCfg.fileSavePath.push_back('/');
|
||||
HGChar stdSavePath[256];
|
||||
HGBase_StandardiseFileName(m_globalCfg.fileSavePath.c_str(), stdSavePath, 256);
|
||||
m_globalCfg.fileSavePath = stdSavePath;
|
||||
HGBase_EnterLock(m_lock);
|
||||
if (mask & GlobalConfig::fileSavePathMask)
|
||||
{
|
||||
std::string fileSavePath = cfg.fileSavePath;
|
||||
fileSavePath.push_back('/');
|
||||
HGChar stdFileSavePath[256];
|
||||
HGBase_StandardiseFileName(fileSavePath.c_str(), stdFileSavePath, 256);
|
||||
m_globalCfg.fileSavePath = stdFileSavePath;
|
||||
SetCfgStringValue("global", "fileSavePath", m_globalCfg.fileSavePath);
|
||||
}
|
||||
if (mask & GlobalConfig::fileNamePrefixMask)
|
||||
{
|
||||
m_globalCfg.fileNamePrefix = cfg.fileNamePrefix;
|
||||
SetCfgStringValue("global", "fileNamePrefix", m_globalCfg.fileNamePrefix);
|
||||
}
|
||||
if (mask & GlobalConfig::fileNameModeMask)
|
||||
{
|
||||
m_globalCfg.fileNameMode = cfg.fileNameMode;
|
||||
SetCfgStringValue("global", "fileNameMode", m_globalCfg.fileNameMode);
|
||||
}
|
||||
if (mask & GlobalConfig::imageFormatMask)
|
||||
{
|
||||
m_globalCfg.imageFormat = cfg.imageFormat;
|
||||
SetCfgStringValue("global", "imageFormat", m_globalCfg.imageFormat);
|
||||
}
|
||||
if (mask & GlobalConfig::imageJpegQualityMask)
|
||||
{
|
||||
m_globalCfg.imageJpegQuality = cfg.imageJpegQuality;
|
||||
SetCfgIntValue("global", "imageJpegQuality", m_globalCfg.imageJpegQuality);
|
||||
}
|
||||
if (mask & GlobalConfig::imageTiffCompressionMask)
|
||||
{
|
||||
m_globalCfg.imageTiffCompression = cfg.imageTiffCompression;
|
||||
SetCfgStringValue("global", "imageTiffCompression", m_globalCfg.imageTiffCompression);
|
||||
}
|
||||
if (mask & GlobalConfig::imageTiffJpegQualityMask)
|
||||
{
|
||||
m_globalCfg.imageTiffJpegQuality = cfg.imageTiffJpegQuality;
|
||||
SetCfgIntValue("global", "imageTiffJpegQuality", m_globalCfg.imageTiffJpegQuality);
|
||||
}
|
||||
if (mask & GlobalConfig::uploadHttpHostMask)
|
||||
{
|
||||
m_globalCfg.uploadHttpHost = cfg.uploadHttpHost;
|
||||
SetCfgStringValue("global", "uploadHttpHost", m_globalCfg.uploadHttpHost);
|
||||
}
|
||||
if (mask & GlobalConfig::uploadHttpPortMask)
|
||||
{
|
||||
m_globalCfg.uploadHttpPort = cfg.uploadHttpPort;
|
||||
SetCfgIntValue("global", "uploadHttpPort", m_globalCfg.uploadHttpPort);
|
||||
}
|
||||
if (mask & GlobalConfig::uploadHttpPathMask)
|
||||
{
|
||||
m_globalCfg.uploadHttpPath = cfg.uploadHttpPath;
|
||||
SetCfgStringValue("global", "uploadHttpPath", m_globalCfg.uploadHttpPath);
|
||||
}
|
||||
if (mask & GlobalConfig::uploadFtpUserMask)
|
||||
{
|
||||
m_globalCfg.uploadFtpUser = cfg.uploadFtpUser;
|
||||
SetCfgStringValue("global", "uploadFtpUser", m_globalCfg.uploadFtpUser);
|
||||
}
|
||||
if (mask & GlobalConfig::uploadFtpPasswordMask)
|
||||
{
|
||||
m_globalCfg.uploadFtpPassword = cfg.uploadFtpPassword;
|
||||
SetCfgStringValue("global", "uploadFtpPassword", m_globalCfg.uploadFtpPassword);
|
||||
}
|
||||
if (mask & GlobalConfig::uploadFtpHostMask)
|
||||
{
|
||||
m_globalCfg.uploadFtpHost = cfg.uploadFtpHost;
|
||||
SetCfgStringValue("global", "uploadFtpHost", m_globalCfg.uploadFtpHost);
|
||||
}
|
||||
if (mask & GlobalConfig::uploadFtpPortMask)
|
||||
{
|
||||
m_globalCfg.uploadFtpPort = cfg.uploadFtpPort;
|
||||
SetCfgIntValue("global", "uploadFtpPort", m_globalCfg.uploadFtpPort);
|
||||
}
|
||||
HGBase_LeaveLock(m_lock);
|
||||
|
||||
SetCfgStringValue("global", "fileSavePath", m_globalCfg.fileSavePath);
|
||||
SetCfgStringValue("global", "fileNamePrefix", m_globalCfg.fileNamePrefix);
|
||||
SetCfgStringValue("global", "fileNameMode", m_globalCfg.fileNameMode);
|
||||
SetCfgStringValue("global", "imageFormat", m_globalCfg.imageFormat);
|
||||
SetCfgIntValue("global", "imageJpegQuality", m_globalCfg.imageJpegQuality);
|
||||
SetCfgStringValue("global", "imageTiffCompression", m_globalCfg.imageTiffCompression);
|
||||
SetCfgIntValue("global", "imageTiffJpegQuality", m_globalCfg.imageTiffJpegQuality);
|
||||
SetCfgStringValue("global", "uploadHttpHost", m_globalCfg.uploadHttpHost);
|
||||
SetCfgIntValue("global", "uploadHttpPort", m_globalCfg.uploadHttpPort);
|
||||
SetCfgStringValue("global", "uploadHttpPath", m_globalCfg.uploadHttpPath);
|
||||
SetCfgStringValue("global", "uploadFtpUser", m_globalCfg.uploadFtpUser);
|
||||
SetCfgStringValue("global", "uploadFtpPassword", m_globalCfg.uploadFtpPassword);
|
||||
SetCfgStringValue("global", "uploadFtpHost", m_globalCfg.uploadFtpHost);
|
||||
SetCfgIntValue("global", "uploadFtpPort", m_globalCfg.uploadFtpPort);
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::GetGlobalConfig(GlobalConfig& cfg)
|
||||
int ManagerV2::GetGlobalConfig(GlobalConfig& cfg, std::string& errInfo)
|
||||
{
|
||||
cfg = m_globalCfg;
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::LoadLocalImage(const std::string& imagePath, std::string& imgBase64)
|
||||
int ManagerV2::LoadLocalImage(const std::string& imagePath, std::string& imgBase64, std::string& errInfo)
|
||||
{
|
||||
imgBase64.clear();
|
||||
errInfo = "错误";
|
||||
|
||||
HGUInt imgType = 0;
|
||||
HGImgFmt_GetImgFmtType(imagePath.c_str(), &imgType);
|
||||
|
@ -196,12 +260,15 @@ namespace ver_2
|
|||
else if (HGIMGFMT_TYPE_OFD == imgType)
|
||||
prefix = "data:image/ofd;base64,";
|
||||
imgBase64.insert(0, prefix);
|
||||
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::SaveLocalImage(const std::string& imgBase64, std::string& imagePath)
|
||||
int ManagerV2::SaveLocalImage(const std::string& imgBase64, std::string& imagePath, std::string& errInfo)
|
||||
{
|
||||
imagePath.clear();
|
||||
errInfo = "错误";
|
||||
|
||||
size_t pos = imgBase64.find(',');
|
||||
if (std::string::npos == pos)
|
||||
|
@ -231,12 +298,15 @@ namespace ver_2
|
|||
m_saveFilePathList.push_back(imagePath);
|
||||
RestoreSaveFilePathList(m_saveFilePathList);
|
||||
HGBase_LeaveLock(m_lock);
|
||||
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::DeleteLocalFile(const std::string& filePath)
|
||||
int ManagerV2::DeleteLocalFile(const std::string& filePath, std::string& errInfo)
|
||||
{
|
||||
int ret = -1;
|
||||
errInfo = "错误";
|
||||
|
||||
HGBase_EnterLock(m_lock);
|
||||
for (int i = 0; i < (int)m_saveFilePathList.size(); ++i)
|
||||
|
@ -246,6 +316,7 @@ namespace ver_2
|
|||
if (HGBASE_ERR_OK == HGBase_DeleteFile(filePath.c_str()))
|
||||
{
|
||||
m_saveFilePathList.erase(m_saveFilePathList.begin() + i);
|
||||
errInfo.clear();
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
|
@ -258,7 +329,7 @@ namespace ver_2
|
|||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::ClearGlobalFileSavePath()
|
||||
int ManagerV2::ClearGlobalFileSavePath(std::string& errInfo)
|
||||
{
|
||||
HGBase_EnterLock(m_lock);
|
||||
int i = 0;
|
||||
|
@ -286,13 +357,15 @@ namespace ver_2
|
|||
HGBase_LeaveLock(m_lock);
|
||||
|
||||
HGBase_DeleteDir(m_globalCfg.fileSavePath.c_str());
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::MergeLocalImage(const std::vector<std::string>& imagePathList, const std::string& mode,
|
||||
const std::string& align, int interval, std::string& outImagePath)
|
||||
const std::string& align, int interval, std::string& outImagePath, std::string& errInfo)
|
||||
{
|
||||
outImagePath.clear();
|
||||
errInfo = "错误";
|
||||
|
||||
if (imagePathList.empty() || interval < 0)
|
||||
return -1;
|
||||
|
@ -402,6 +475,7 @@ namespace ver_2
|
|||
m_saveFilePathList.push_back(outImagePath);
|
||||
RestoreSaveFilePathList(m_saveFilePathList);
|
||||
HGBase_LeaveLock(m_lock);
|
||||
errInfo.clear();
|
||||
}
|
||||
|
||||
HGBase_DestroyImage(outImage);
|
||||
|
@ -409,9 +483,10 @@ namespace ver_2
|
|||
}
|
||||
|
||||
int ManagerV2::LocalMakeMultiImage(const std::vector<std::string>& imagePathList, const std::string& format,
|
||||
const std::string& tiffCompression, int tiffJpegQuality, std::string& outImagePath)
|
||||
const std::string& tiffCompression, int tiffJpegQuality, std::string& outImagePath, std::string& errInfo)
|
||||
{
|
||||
outImagePath.clear();
|
||||
errInfo = "错误";
|
||||
|
||||
if (imagePathList.empty())
|
||||
return -1;
|
||||
|
@ -448,6 +523,7 @@ namespace ver_2
|
|||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4;
|
||||
if (HGBASE_ERR_OK == HGImgFmt_SaveImageToWriter(writer, img, &saveInfo))
|
||||
{
|
||||
errInfo.clear();
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
|
@ -473,9 +549,10 @@ namespace ver_2
|
|||
}
|
||||
|
||||
int ManagerV2::SplitLocalImage(const std::string& imagePath, const std::string& mode, int location,
|
||||
std::vector<std::string>& outImagePathList)
|
||||
std::vector<std::string>& outImagePathList, std::string& errInfo)
|
||||
{
|
||||
outImagePathList.clear();
|
||||
errInfo = "错误";
|
||||
|
||||
if (imagePath.empty() || location < 0)
|
||||
return -1;
|
||||
|
@ -540,6 +617,7 @@ namespace ver_2
|
|||
m_saveFilePathList.push_back(imgPath);
|
||||
RestoreSaveFilePathList(m_saveFilePathList);
|
||||
HGBase_LeaveLock(m_lock);
|
||||
errInfo.clear();
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
|
@ -556,9 +634,10 @@ namespace ver_2
|
|||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::LocalMakeZipFile(const std::vector<std::string>& filePathList, std::string& outZipPath)
|
||||
int ManagerV2::LocalMakeZipFile(const std::vector<std::string>& filePathList, std::string& outZipPath, std::string& errInfo)
|
||||
{
|
||||
outZipPath.clear();
|
||||
errInfo = "错误";
|
||||
|
||||
if (filePathList.empty())
|
||||
return -1;
|
||||
|
@ -582,6 +661,7 @@ namespace ver_2
|
|||
HGBase_GetFileName(filePathList[i].c_str(), name, 256);
|
||||
if (zip_file_add(z, StdStringToUtf8(name).c_str(), s, ZIP_FL_OVERWRITE) >= 0)
|
||||
{
|
||||
errInfo.clear();
|
||||
ret = 0;
|
||||
}
|
||||
else
|
||||
|
@ -608,9 +688,10 @@ namespace ver_2
|
|||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::LocalImageDeskew(const std::string& imagePath, std::string& outImagePath)
|
||||
int ManagerV2::LocalImageDeskew(const std::string& imagePath, std::string& outImagePath, std::string& errInfo)
|
||||
{
|
||||
outImagePath.clear();
|
||||
errInfo = "错误";
|
||||
|
||||
if (imagePath.empty())
|
||||
return -1;
|
||||
|
@ -630,6 +711,7 @@ namespace ver_2
|
|||
m_saveFilePathList.push_back(outImagePath);
|
||||
RestoreSaveFilePathList(m_saveFilePathList);
|
||||
HGBase_LeaveLock(m_lock);
|
||||
errInfo.clear();
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
|
@ -642,8 +724,10 @@ namespace ver_2
|
|||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::UploadLocalFile(const std::string& filePath, const std::string& mode, const std::string& remoteFilePath)
|
||||
int ManagerV2::UploadLocalFile(const std::string& filePath, const std::string& mode, const std::string& remoteFilePath, std::string& errInfo)
|
||||
{
|
||||
errInfo = "错误";
|
||||
|
||||
if (filePath.empty() || remoteFilePath.empty())
|
||||
return -1;
|
||||
if ("http" != mode && "ftp" != mode)
|
||||
|
@ -661,11 +745,15 @@ namespace ver_2
|
|||
m_globalCfg.uploadFtpPort, filePath, remoteFilePath);
|
||||
}
|
||||
|
||||
if (0 == ret)
|
||||
errInfo.clear();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::InitDevice()
|
||||
int ManagerV2::InitDevice(std::string& errInfo)
|
||||
{
|
||||
errInfo = "错误";
|
||||
|
||||
if (m_initDevice)
|
||||
return -1;
|
||||
|
||||
|
@ -674,25 +762,29 @@ namespace ver_2
|
|||
assert(SANE_STATUS_GOOD == status);
|
||||
|
||||
m_initDevice = true;
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::DeinitDevice()
|
||||
int ManagerV2::DeinitDevice(std::string& errInfo)
|
||||
{
|
||||
if (m_initDevice)
|
||||
{
|
||||
CloseDevice();
|
||||
std::string errInfo;
|
||||
CloseDevice(errInfo);
|
||||
sane_exit();
|
||||
m_devNameList.clear();
|
||||
m_initDevice = false;
|
||||
}
|
||||
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::GetDeviceNameList(std::vector<std::string>& deviceNameList)
|
||||
int ManagerV2::GetDeviceNameList(std::vector<std::string>& deviceNameList, std::string& errInfo)
|
||||
{
|
||||
deviceNameList.clear();
|
||||
errInfo = "错误";
|
||||
|
||||
if (!m_initDevice)
|
||||
return -1;
|
||||
|
@ -700,37 +792,45 @@ namespace ver_2
|
|||
HGBase_EnterLock(m_lock);
|
||||
deviceNameList = m_devNameList;
|
||||
HGBase_LeaveLock(m_lock);
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::OpenDevice(const std::string& deviceName)
|
||||
int ManagerV2::OpenDevice(const std::string& deviceName, std::string& errInfo)
|
||||
{
|
||||
errInfo = "错误";
|
||||
|
||||
if (!m_initDevice || m_openDevice)
|
||||
return -1;
|
||||
|
||||
std::string devName = deviceName;
|
||||
HGBase_EnterLock(m_lock);
|
||||
if (devName.empty() && m_devNameList.size() > 0)
|
||||
devName = m_devNameList[0];
|
||||
HGBase_LeaveLock(m_lock);
|
||||
|
||||
SANE_Handle dev = NULL;
|
||||
SANE_Status status = sane_open(devName.c_str(), &dev);
|
||||
SANE_Status status = sane_open(deviceName.c_str(), &dev);
|
||||
if (SANE_STATUS_GOOD != status)
|
||||
return -1;
|
||||
|
||||
// 从配置文件加载devParam
|
||||
DeviceParam devParam;
|
||||
LoadDeviceParam(deviceName, devParam);
|
||||
// 设置devParam到设备
|
||||
SetParamToDevice(dev, devParam, 0xFFFFFFFF);
|
||||
// 从设备获取,并设置m_devParam
|
||||
GetParamFromDevice(dev, m_devParam);
|
||||
// 保存到配置文件
|
||||
RestoreDeviceParam(deviceName, m_devParam);
|
||||
|
||||
m_devHandle = dev;
|
||||
m_devName = devName;
|
||||
// 加载m_devParam,并设置到设备
|
||||
m_devName = deviceName;
|
||||
m_openDevice = true;
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::CloseDevice()
|
||||
int ManagerV2::CloseDevice(std::string& errInfo)
|
||||
{
|
||||
if (m_openDevice)
|
||||
{
|
||||
StopScan();
|
||||
std::string errInfo;
|
||||
StopScan(errInfo);
|
||||
|
||||
sane_close(m_devHandle);
|
||||
m_devHandle = NULL;
|
||||
|
@ -739,38 +839,53 @@ namespace ver_2
|
|||
m_openDevice = false;
|
||||
}
|
||||
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::SetDeviceParam(const DeviceParam& param)
|
||||
int ManagerV2::SetDeviceParam(const DeviceParam& param, HGUInt mask, std::string& errInfo)
|
||||
{
|
||||
errInfo = "错误";
|
||||
|
||||
if (!m_openDevice || m_scanning)
|
||||
return -1;
|
||||
|
||||
m_devParam = param;
|
||||
// 设置到设备
|
||||
return 0;
|
||||
// 设置devParam到设备
|
||||
int ret = SetParamToDevice(m_devHandle, param, mask);
|
||||
// 从设备获取,并设置m_devParam
|
||||
GetParamFromDevice(m_devHandle, m_devParam);
|
||||
// 保存到配置文件
|
||||
RestoreDeviceParam(m_devName, m_devParam);
|
||||
|
||||
if (0 == ret)
|
||||
errInfo.clear();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::GetDeviceParam(DeviceParam& param)
|
||||
int ManagerV2::GetDeviceParam(DeviceParam& param, std::string& errInfo)
|
||||
{
|
||||
param.Reset();
|
||||
errInfo = "错误";
|
||||
|
||||
if (!m_openDevice)
|
||||
return -1;
|
||||
|
||||
param = m_devParam;
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::GetCurrDeviceName(std::string& deviceName)
|
||||
int ManagerV2::GetCurrDeviceName(std::string& deviceName, std::string& errInfo)
|
||||
{
|
||||
deviceName = m_devName;
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::StartScan()
|
||||
int ManagerV2::StartScan(std::string& errInfo)
|
||||
{
|
||||
errInfo = "错误";
|
||||
|
||||
if (!m_openDevice || m_scanning)
|
||||
return -1;
|
||||
|
||||
|
@ -781,10 +896,11 @@ namespace ver_2
|
|||
m_scanning = true;
|
||||
HGBase_CreateEvent(HGFALSE, HGFALSE, &m_scanEvent);
|
||||
assert(NULL != m_scanEvent);
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::StopScan()
|
||||
int ManagerV2::StopScan(std::string& errInfo)
|
||||
{
|
||||
if (m_scanning)
|
||||
{
|
||||
|
@ -798,6 +914,7 @@ namespace ver_2
|
|||
m_scanning = false;
|
||||
}
|
||||
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -823,6 +940,20 @@ namespace ver_2
|
|||
return val;
|
||||
}
|
||||
|
||||
double ManagerV2::GetCfgDoubleValue(const std::string& app, const std::string& key, double def)
|
||||
{
|
||||
HGChar cfgPath[256];
|
||||
HGBase_GetConfigPath(cfgPath, 256);
|
||||
strcat(cfgPath, "config2.ini");
|
||||
|
||||
char defStr[32];
|
||||
sprintf(defStr, "%f", def);
|
||||
|
||||
HGChar val[256] = { 0 };
|
||||
HGBase_GetProfileString(cfgPath, app.c_str(), key.c_str(), defStr, val, 256);
|
||||
return atof(val);
|
||||
}
|
||||
|
||||
bool ManagerV2::GetCfgBoolValue(const std::string& app, const std::string& key, bool def)
|
||||
{
|
||||
HGChar cfgPath[256];
|
||||
|
@ -854,6 +985,19 @@ namespace ver_2
|
|||
return (HGBASE_ERR_OK == HGBase_SetProfileInt(cfgPath, app.c_str(), key.c_str(), val));
|
||||
}
|
||||
|
||||
bool ManagerV2::SetCfgDoubleValue(const std::string& app, const std::string& key, double val)
|
||||
{
|
||||
HGChar cfgPath[256];
|
||||
HGBase_GetConfigPath(cfgPath, 256);
|
||||
HGBase_CreateDir(cfgPath);
|
||||
strcat(cfgPath, "config2.ini");
|
||||
|
||||
char valStr[32];
|
||||
sprintf(valStr, "%f", val);
|
||||
|
||||
return (HGBASE_ERR_OK == HGBase_SetProfileString(cfgPath, app.c_str(), key.c_str(), valStr));
|
||||
}
|
||||
|
||||
bool ManagerV2::SetCfgBoolValue(const std::string& app, const std::string& key, bool val)
|
||||
{
|
||||
HGChar cfgPath[256];
|
||||
|
@ -1173,6 +1317,314 @@ namespace ver_2
|
|||
}
|
||||
}
|
||||
|
||||
void ManagerV2::LoadDeviceParam(const std::string& devName, DeviceParam& devParam)
|
||||
{
|
||||
assert(!devName.empty());
|
||||
devParam.Reset();
|
||||
|
||||
devParam.colorMode = StdStringToUtf8(GetCfgStringValue(devName.c_str(), "colorMode", "24位彩色"));
|
||||
devParam.pageMode = StdStringToUtf8(GetCfgStringValue(devName.c_str(), "pageMode", "双面"));
|
||||
devParam.resolution = GetCfgIntValue(devName.c_str(), "resolution", 200);
|
||||
devParam.brightness = GetCfgIntValue(devName.c_str(), "brightness", 100);
|
||||
devParam.contrast = GetCfgIntValue(devName.c_str(), "contrast", 4);
|
||||
devParam.gamma = GetCfgDoubleValue(devName.c_str(), "gamma", 1.00f);
|
||||
devParam.paperSize = StdStringToUtf8(GetCfgStringValue(devName.c_str(), "paperSize", "匹配原始尺寸"));
|
||||
devParam.paperCutEnabled = GetCfgBoolValue(devName.c_str(), "paperCutEnabled", false);
|
||||
devParam.paperCutLeft = GetCfgDoubleValue(devName.c_str(), "paperCutLeft", 0.0f);
|
||||
devParam.paperCutTop = GetCfgDoubleValue(devName.c_str(), "paperCutTop", 0.0f);
|
||||
devParam.paperCutRight = GetCfgDoubleValue(devName.c_str(), "paperCutRight", 0.0f);
|
||||
devParam.paperCutBottom = GetCfgDoubleValue(devName.c_str(), "paperCutBottom", 0.0f);
|
||||
devParam.autoCrop = GetCfgBoolValue(devName.c_str(), "autoCrop", false);
|
||||
}
|
||||
|
||||
void ManagerV2::RestoreDeviceParam(const std::string& devName, const DeviceParam& devParam)
|
||||
{
|
||||
assert(!devName.empty());
|
||||
|
||||
SetCfgStringValue(devName.c_str(), "colorMode", Utf8ToStdString(devParam.colorMode));
|
||||
SetCfgStringValue(devName.c_str(), "pageMode", Utf8ToStdString(devParam.pageMode));
|
||||
SetCfgIntValue(devName.c_str(), "resolution", devParam.resolution);
|
||||
SetCfgIntValue(devName.c_str(), "brightness", devParam.brightness);
|
||||
SetCfgIntValue(devName.c_str(), "contrast", devParam.contrast);
|
||||
SetCfgDoubleValue(devName.c_str(), "gamma", devParam.gamma);
|
||||
SetCfgStringValue(devName.c_str(), "paperSize", Utf8ToStdString(devParam.paperSize));
|
||||
SetCfgBoolValue(devName.c_str(), "paperCutEnabled", devParam.paperCutEnabled);
|
||||
SetCfgDoubleValue(devName.c_str(), "paperCutLeft", devParam.paperCutLeft);
|
||||
SetCfgDoubleValue(devName.c_str(), "paperCutTop", devParam.paperCutTop);
|
||||
SetCfgDoubleValue(devName.c_str(), "paperCutRight", devParam.paperCutRight);
|
||||
SetCfgDoubleValue(devName.c_str(), "paperCutBottom", devParam.paperCutBottom);
|
||||
SetCfgBoolValue(devName.c_str(), "autoCrop", devParam.autoCrop);
|
||||
}
|
||||
|
||||
int ManagerV2::SetParamToDevice(SANE_Handle hdev, const DeviceParam& devParam, HGUInt mask)
|
||||
{
|
||||
assert(NULL != hdev);
|
||||
|
||||
int ret = 0;
|
||||
|
||||
SANE_Int num_dev_options = 0;
|
||||
sane_control_option(hdev, 0, SANE_ACTION_GET_VALUE, &num_dev_options, NULL);
|
||||
for (int i = 1; i < num_dev_options; ++i)
|
||||
{
|
||||
const SANE_Option_Descriptor* desp = sane_get_option_descriptor(hdev, i);
|
||||
if (NULL == desp)
|
||||
continue;
|
||||
|
||||
if (SANE_TYPE_STRING == desp->type)
|
||||
{
|
||||
if (0 == strcmp(OPTION_TITLE_YSMS, desp->title) && (mask & DeviceParam::colorModeMask))
|
||||
{
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, (void*)devParam.colorMode.c_str(), NULL))
|
||||
ret = -1;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_SMYM, desp->title) && (mask & DeviceParam::pageModeMask))
|
||||
{
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, (void*)devParam.pageMode.c_str(), NULL))
|
||||
ret = -1;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_ZZCC, desp->title) && (mask & DeviceParam::paperSizeMask))
|
||||
{
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, (void*)devParam.paperSize.c_str(), NULL))
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
else if (SANE_TYPE_INT == desp->type)
|
||||
{
|
||||
if (0 == strcmp(OPTION_TITLE_FBL, desp->title) && (mask & DeviceParam::resolutionMask))
|
||||
{
|
||||
SANE_Int value = devParam.resolution;
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, &value, NULL))
|
||||
ret = -1;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_LDZ, desp->title) && (mask & DeviceParam::brightnessMask))
|
||||
{
|
||||
SANE_Int value = devParam.brightness;
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, &value, NULL))
|
||||
ret = -1;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_DBD, desp->title) && (mask & DeviceParam::contrastMask))
|
||||
{
|
||||
SANE_Int value = devParam.contrast;
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, &value, NULL))
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
else if (SANE_TYPE_FIXED == desp->type)
|
||||
{
|
||||
if (0 == strcmp(OPTION_TITLE_JMZ, desp->title) && (mask & DeviceParam::gammaMask))
|
||||
{
|
||||
SANE_Fixed value = SANE_FIX(devParam.gamma);
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, &value, NULL))
|
||||
ret = -1;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_SMQYZCmm, desp->title) && (mask & DeviceParam::paperCutLeftMask))
|
||||
{
|
||||
SANE_Fixed value = SANE_FIX(devParam.paperCutLeft);
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, &value, NULL))
|
||||
ret = -1;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_SMQYYCmm, desp->title) && (mask & DeviceParam::paperCutRightMask))
|
||||
{
|
||||
SANE_Fixed value = SANE_FIX(devParam.paperCutRight);
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, &value, NULL))
|
||||
ret = -1;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_SMQYSCmm, desp->title) && (mask & DeviceParam::paperCutTopMask))
|
||||
{
|
||||
SANE_Fixed value = SANE_FIX(devParam.paperCutTop);
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, &value, NULL))
|
||||
ret = -1;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_SMQYXCmm, desp->title) && (mask & DeviceParam::paperCutBottomMask))
|
||||
{
|
||||
SANE_Fixed value = SANE_FIX(devParam.paperCutBottom);
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, &value, NULL))
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
else if (SANE_TYPE_BOOL == desp->type)
|
||||
{
|
||||
if (0 == strcmp(OPTION_TITLE_ZDJP, desp->title) && (mask & DeviceParam::autoCropMask))
|
||||
{
|
||||
SANE_Bool value = (SANE_Bool)devParam.autoCrop;
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, &value, NULL))
|
||||
ret = -1;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_ZDYSMQY, desp->title) && (mask & DeviceParam::paperCutEnabledMask))
|
||||
{
|
||||
SANE_Bool value = (SANE_Bool)devParam.paperCutEnabled;
|
||||
if (SANE_STATUS_GOOD != sane_control_option(hdev, i, SANE_ACTION_SET_VALUE, &value, NULL))
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::GetParamFromDevice(SANE_Handle hdev, DeviceParam& devParam)
|
||||
{
|
||||
assert(NULL != hdev);
|
||||
devParam.Reset();
|
||||
|
||||
int ret = 0;
|
||||
|
||||
SANE_Int num_dev_options = 0;
|
||||
sane_control_option(hdev, 0, SANE_ACTION_GET_VALUE, &num_dev_options, NULL);
|
||||
for (int i = 1; i < num_dev_options; ++i)
|
||||
{
|
||||
const SANE_Option_Descriptor* desp = sane_get_option_descriptor(hdev, i);
|
||||
if (NULL == desp)
|
||||
continue;
|
||||
|
||||
if (SANE_TYPE_STRING == desp->type)
|
||||
{
|
||||
char value[256] = { 0 };
|
||||
sane_control_option(hdev, i, SANE_ACTION_GET_VALUE, value, NULL);
|
||||
|
||||
if (0 == strcmp(OPTION_TITLE_YSMS, desp->title))
|
||||
{
|
||||
if (SANE_CONSTRAINT_STRING_LIST == desp->constraint_type)
|
||||
{
|
||||
const SANE_String_Const* p = desp->constraint.string_list;
|
||||
while (NULL != *p)
|
||||
{
|
||||
devParam.colorModeList.push_back(*p);
|
||||
++p;
|
||||
}
|
||||
}
|
||||
|
||||
devParam.colorMode = value;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_SMYM, desp->title))
|
||||
{
|
||||
if (SANE_CONSTRAINT_STRING_LIST == desp->constraint_type)
|
||||
{
|
||||
const SANE_String_Const* p = desp->constraint.string_list;
|
||||
while (NULL != *p)
|
||||
{
|
||||
devParam.pageModeList.push_back(*p);
|
||||
++p;
|
||||
}
|
||||
}
|
||||
|
||||
devParam.pageMode = value;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_ZZCC, desp->title))
|
||||
{
|
||||
if (SANE_CONSTRAINT_STRING_LIST == desp->constraint_type)
|
||||
{
|
||||
const SANE_String_Const* p = desp->constraint.string_list;
|
||||
while (NULL != *p)
|
||||
{
|
||||
devParam.paperSizeList.push_back(*p);
|
||||
++p;
|
||||
}
|
||||
}
|
||||
|
||||
devParam.paperSize = value;
|
||||
}
|
||||
}
|
||||
else if (SANE_TYPE_INT == desp->type)
|
||||
{
|
||||
SANE_Int value = 0;
|
||||
sane_control_option(hdev, i, SANE_ACTION_GET_VALUE, &value, NULL);
|
||||
|
||||
if (0 == strcmp(OPTION_TITLE_FBL, desp->title))
|
||||
{
|
||||
if (SANE_CONSTRAINT_WORD_LIST == desp->constraint_type)
|
||||
{
|
||||
const SANE_Word* p = desp->constraint.word_list;
|
||||
for (SANE_Int i = 0; i < p[0]; ++i)
|
||||
{
|
||||
devParam.resolutionList.push_back(p[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
devParam.resolution = value;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_LDZ, desp->title))
|
||||
{
|
||||
if (SANE_CONSTRAINT_RANGE == desp->constraint_type)
|
||||
{
|
||||
devParam.brightnessMin = desp->constraint.range->min;
|
||||
devParam.brightnessMax = desp->constraint.range->max;
|
||||
}
|
||||
|
||||
devParam.brightness = value;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_DBD, desp->title))
|
||||
{
|
||||
if (SANE_CONSTRAINT_RANGE == desp->constraint_type)
|
||||
{
|
||||
devParam.contrastMin = desp->constraint.range->min;
|
||||
devParam.contrastMax = desp->constraint.range->max;
|
||||
}
|
||||
|
||||
devParam.contrast = value;
|
||||
}
|
||||
}
|
||||
else if (SANE_TYPE_FIXED == desp->type)
|
||||
{
|
||||
SANE_Word value = 0;
|
||||
sane_control_option(hdev, i, SANE_ACTION_GET_VALUE, &value, NULL);
|
||||
|
||||
if (0 == strcmp(OPTION_TITLE_JMZ, desp->title))
|
||||
{
|
||||
if (SANE_CONSTRAINT_RANGE == desp->constraint_type)
|
||||
{
|
||||
devParam.gammaMin = SANE_UNFIX(desp->constraint.range->min);
|
||||
devParam.gammaMax = SANE_UNFIX(desp->constraint.range->max);
|
||||
}
|
||||
|
||||
devParam.gamma = SANE_UNFIX(value);
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_SMQYZCmm, desp->title))
|
||||
{
|
||||
devParam.paperCutLeft = SANE_UNFIX(value);
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_SMQYYCmm, desp->title))
|
||||
{
|
||||
if (SANE_CONSTRAINT_RANGE == desp->constraint_type)
|
||||
{
|
||||
devParam.paperSizeWidth = SANE_UNFIX(desp->constraint.range->max);
|
||||
}
|
||||
|
||||
devParam.paperCutRight = SANE_UNFIX(value);
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_SMQYSCmm, desp->title))
|
||||
{
|
||||
devParam.paperCutTop = SANE_UNFIX(value);
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_SMQYXCmm, desp->title))
|
||||
{
|
||||
if (SANE_CONSTRAINT_RANGE == desp->constraint_type)
|
||||
{
|
||||
devParam.paperSizeHeight = SANE_UNFIX(desp->constraint.range->max);
|
||||
}
|
||||
|
||||
devParam.paperCutBottom = SANE_UNFIX(value);
|
||||
}
|
||||
}
|
||||
else if (SANE_TYPE_BOOL == desp->type)
|
||||
{
|
||||
SANE_Bool value = 0;
|
||||
sane_control_option(hdev, i, SANE_ACTION_GET_VALUE, &value, NULL);
|
||||
|
||||
if (0 == strcmp(OPTION_TITLE_ZDJP, desp->title))
|
||||
{
|
||||
devParam.autoCrop = (bool)value;
|
||||
}
|
||||
else if (0 == strcmp(OPTION_TITLE_ZDYSMQY, desp->title))
|
||||
{
|
||||
devParam.paperCutEnabled = (bool)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param)
|
||||
{
|
||||
(void)hdev;
|
||||
|
|
|
@ -27,6 +27,24 @@ namespace ver_2
|
|||
|
||||
struct GlobalConfig
|
||||
{
|
||||
enum
|
||||
{
|
||||
fileSavePathMask = 0x00000001,
|
||||
fileNamePrefixMask = 0x00000002,
|
||||
fileNameModeMask = 0x00000004,
|
||||
imageFormatMask = 0x00000008,
|
||||
imageJpegQualityMask = 0x00000010,
|
||||
imageTiffCompressionMask = 0x00000020,
|
||||
imageTiffJpegQualityMask = 0x00000040,
|
||||
uploadHttpHostMask = 0x00000080,
|
||||
uploadHttpPortMask = 0x00000100,
|
||||
uploadHttpPathMask = 0x00000200,
|
||||
uploadFtpUserMask = 0x00000400,
|
||||
uploadFtpPasswordMask = 0x00000800,
|
||||
uploadFtpHostMask = 0x00001000,
|
||||
uploadFtpPortMask = 0x00002000,
|
||||
};
|
||||
|
||||
GlobalConfig()
|
||||
{
|
||||
imageJpegQuality = 0;
|
||||
|
@ -56,6 +74,23 @@ namespace ver_2
|
|||
|
||||
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();
|
||||
|
@ -63,7 +98,31 @@ namespace ver_2
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
// 颜色模式
|
||||
|
@ -84,20 +143,20 @@ namespace ver_2
|
|||
int contrastMax;
|
||||
int contrast;
|
||||
// 伽马
|
||||
int gammaMin;
|
||||
int gammaMax;
|
||||
int gamma;
|
||||
double gammaMin;
|
||||
double gammaMax;
|
||||
double gamma;
|
||||
// 纸张尺寸
|
||||
std::vector<std::string> paperSizeList;
|
||||
std::string pageSize;
|
||||
int paperSizeWidth;
|
||||
int paperSizeHeight;
|
||||
std::string paperSize;
|
||||
double paperSizeWidth;
|
||||
double paperSizeHeight;
|
||||
// 手动裁剪
|
||||
bool paperCutEnabled;
|
||||
float paperCutLeft;
|
||||
float paperCutTop;
|
||||
float paperCutRight;
|
||||
float paperCutBottom;
|
||||
double paperCutLeft;
|
||||
double paperCutTop;
|
||||
double paperCutRight;
|
||||
double paperCutBottom;
|
||||
// 是否纠偏
|
||||
bool autoCrop;
|
||||
};
|
||||
|
@ -122,61 +181,64 @@ namespace ver_2
|
|||
void ResetSaneImageCallback();
|
||||
|
||||
// 设置全局配置
|
||||
int SetGlobalConfig(const GlobalConfig& cfg);
|
||||
int SetGlobalConfig(const GlobalConfig& cfg, HGUInt mask, std::string &errInfo);
|
||||
// 获取全局配置
|
||||
int GetGlobalConfig(GlobalConfig& cfg);
|
||||
int GetGlobalConfig(GlobalConfig& cfg, std::string& errInfo);
|
||||
// 加载本地图像
|
||||
int LoadLocalImage(const std::string& imagePath, std::string& imgBase64);
|
||||
int LoadLocalImage(const std::string& imagePath, std::string& imgBase64, std::string& errInfo);
|
||||
// 保存本地图像
|
||||
int SaveLocalImage(const std::string& imgBase64, std::string& imagePath);
|
||||
int SaveLocalImage(const std::string& imgBase64, std::string& imagePath, std::string& errInfo);
|
||||
// 删除本地文件
|
||||
int DeleteLocalFile(const std::string& filePath);
|
||||
int DeleteLocalFile(const std::string& filePath, std::string& errInfo);
|
||||
// 清理全局文件保存目录
|
||||
int ClearGlobalFileSavePath();
|
||||
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);
|
||||
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);
|
||||
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::vector<std::string>& outImagePathList, std::string& errInfo);
|
||||
// 本地生成压缩文件
|
||||
int LocalMakeZipFile(const std::vector<std::string>& filePathList, std::string& outZipPath);
|
||||
int LocalMakeZipFile(const std::vector<std::string>& filePathList, std::string& outZipPath, std::string& errInfo);
|
||||
// 本地图像纠偏
|
||||
int LocalImageDeskew(const std::string& imagePath, std::string& outImagePath);
|
||||
int LocalImageDeskew(const std::string& imagePath, std::string& outImagePath, std::string& errInfo);
|
||||
// 上传文件
|
||||
int UploadLocalFile(const std::string& filePath, const std::string& mode, const std::string& remoteFilePath);
|
||||
int UploadLocalFile(const std::string& filePath, const std::string& mode, const std::string& remoteFilePath, std::string& errInfo);
|
||||
|
||||
// 设备初始化
|
||||
int InitDevice();
|
||||
int InitDevice(std::string& errInfo);
|
||||
// 设备反初始化
|
||||
int DeinitDevice();
|
||||
int DeinitDevice(std::string& errInfo);
|
||||
// 获取设备列表
|
||||
int GetDeviceNameList(std::vector<std::string> &deviceNameList);
|
||||
int GetDeviceNameList(std::vector<std::string> &deviceNameList, std::string& errInfo);
|
||||
// 打开设备
|
||||
int OpenDevice(const std::string& deviceName);
|
||||
int OpenDevice(const std::string& deviceName, std::string& errInfo);
|
||||
// 关闭设备
|
||||
int CloseDevice();
|
||||
int CloseDevice(std::string& errInfo);
|
||||
// 设置设备参数
|
||||
int SetDeviceParam(const DeviceParam& param);
|
||||
int SetDeviceParam(const DeviceParam& param, HGUInt mask, std::string& errInfo);
|
||||
// 获取设备参数
|
||||
int GetDeviceParam(DeviceParam& param);
|
||||
int GetDeviceParam(DeviceParam& param, std::string& errInfo);
|
||||
// 获取当前设备名
|
||||
int GetCurrDeviceName(std::string& deviceName);
|
||||
int GetCurrDeviceName(std::string& deviceName, std::string& errInfo);
|
||||
// 开始扫描
|
||||
int StartScan();
|
||||
int StartScan(std::string& errInfo);
|
||||
// 停止扫描
|
||||
int StopScan();
|
||||
int StopScan(std::string& errInfo);
|
||||
|
||||
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 LoadBase64(const std::string& fileName, std::string& base64);
|
||||
static int SaveBase64(const std::string& base64, const std::string& fileName);
|
||||
static int HttpUpload(const std::string &host, int port, const std::string &path,
|
||||
|
@ -187,6 +249,10 @@ namespace ver_2
|
|||
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);
|
||||
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param);
|
||||
|
||||
private:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "WebUser.h"
|
||||
#include "Msg.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
namespace ver_2
|
||||
{
|
||||
|
@ -31,5 +32,35 @@ namespace ver_2
|
|||
bool ShakeHand(const std::string& head);
|
||||
void Pong();
|
||||
bool SendResponse(const HGByte* data, HGUInt size, HGBool text);
|
||||
|
||||
void SetGlobalConfig(cJSON* json);
|
||||
void GetGlobalConfig(cJSON* json);
|
||||
void LoadLocalImage(cJSON* json);
|
||||
void SaveLocalImage(cJSON* json);
|
||||
void DeleteLocalFile(cJSON* json);
|
||||
void ClearGlobalFileSavePath(cJSON* json);
|
||||
void MergeLocalImage(cJSON* json);
|
||||
void LocalMakeMultiImage(cJSON* json);
|
||||
void SplitLocalImage(cJSON* json);
|
||||
void LocalMakeZipFile(cJSON* json);
|
||||
void LocalImageDeskew(cJSON* json);
|
||||
void UploadLocalFile(cJSON* json);
|
||||
|
||||
void InitDevice(cJSON* json);
|
||||
void DeinitDevice(cJSON* json);
|
||||
void GetDeviceNameList(cJSON* json);
|
||||
void OpenDevice(cJSON* json);
|
||||
void CloseDevice(cJSON* json);
|
||||
void SetDeviceParam(cJSON* json);
|
||||
void GetDeviceParam(cJSON* json);
|
||||
void GetCurrDeviceName(cJSON* json);
|
||||
void StartScan(cJSON* json);
|
||||
void StopScan(cJSON* json);
|
||||
|
||||
private:
|
||||
std::string m_initDeviceIden;
|
||||
bool m_initDeviceHaveIden;
|
||||
std::string m_startScanIden;
|
||||
bool m_startScanHaveIden;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -106,6 +106,14 @@
|
|||
{
|
||||
alert(msg.data);
|
||||
}
|
||||
else if ("set_device_param" == message['func'])
|
||||
{
|
||||
alert(msg.data);
|
||||
}
|
||||
else if ("get_device_param" == message['func'])
|
||||
{
|
||||
alert(msg.data);
|
||||
}
|
||||
else if ("get_curr_device_name" == message['func'])
|
||||
{
|
||||
alert(msg.data);
|
||||
|
@ -276,6 +284,20 @@
|
|||
}));
|
||||
}
|
||||
|
||||
function SetDeviceParam()
|
||||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'set_device_param'
|
||||
}));
|
||||
}
|
||||
|
||||
function GetDeviceParam()
|
||||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'get_device_param'
|
||||
}));
|
||||
}
|
||||
|
||||
function GetCurrDevName()
|
||||
{
|
||||
socket.send(JSON.stringify({
|
||||
|
@ -341,6 +363,8 @@
|
|||
<input type="button" value="获取设备列表" onclick="GetDevNameList()" />
|
||||
<input type="button" value="打开设备" onclick="OpenDevice()" />
|
||||
<input type="button" value="关闭设备" onclick="CloseDevice()" />
|
||||
<input type="button" value="设置设备参数" onclick="SetDeviceParam()" />
|
||||
<input type="button" value="获取设备参数" onclick="GetDeviceParam()" />
|
||||
<input type="button" value="获取当前摄像头名称" onclick="GetCurrDevName()" />
|
||||
<input type="button" value="开始扫描" onclick="StartScan()" />
|
||||
<input type="button" value="停止扫描" onclick="StopScan()" />
|
||||
|
|
Loading…
Reference in New Issue