HGGitLab

Commit 901b96d2 authored by yangjiaxuan's avatar yangjiaxuan
parents 7b8d8f86 9826a356
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
<Add directory="../../../../third_party/sane" /> <Add directory="../../../../third_party/sane" />
<Add directory="../../../../release/include" /> <Add directory="../../../../release/include" />
<Add directory="../../../../third_party/libzip/uos/amd64/include" /> <Add directory="../../../../third_party/libzip/uos/amd64/include" />
<Add directory="../../../../third_party/json" />
</Compiler> </Compiler>
<Linker> <Linker>
<Add option="-L../../../../release/bin/uos/amd64" /> <Add option="-L../../../../release/bin/uos/amd64" />
...@@ -63,6 +64,10 @@ ...@@ -63,6 +64,10 @@
<Unit filename="../../../../sdk/webservice/main.cpp" /> <Unit filename="../../../../sdk/webservice/main.cpp" />
<Unit filename="../../../../third_party/base64/base64.cpp" /> <Unit filename="../../../../third_party/base64/base64.cpp" />
<Unit filename="../../../../third_party/base64/base64.h" /> <Unit filename="../../../../third_party/base64/base64.h" />
<Unit filename="../../../../third_party/json/cJSON.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="../../../../third_party/json/cJSON.h" />
<Unit filename="../../../../third_party/sha1/sha1.cpp" /> <Unit filename="../../../../third_party/sha1/sha1.cpp" />
<Unit filename="../../../../third_party/sha1/sha1.h" /> <Unit filename="../../../../third_party/sha1/sha1.h" />
<Extensions> <Extensions>
......
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>../Debug/HGBase.lib;../Debug/HGImgFmt.lib;../Debug/HGTwainUser.lib;../../../release/lib/windows/x86/hgsane.lib;../../../third_party/zlib/windows/lib/x86/zlib.lib;../../../third_party/libzip/windows/lib/x86/zip.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>../Debug/HGBase.lib;../Debug/HGImgFmt.lib;../../../release/lib/windows/x86/hgsane.lib;../../../third_party/zlib/windows/lib/x86/zlib.lib;../../../third_party/libzip/windows/lib/x86/zip.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>/ignore:4098,4075 /LTCG %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/ignore:4098,4075 /LTCG %(AdditionalOptions)</AdditionalOptions>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>../Release/HGBase.lib;../Release/HGImgFmt.lib;../Release/HGTwainUser.lib;../../../release/lib/windows/x86/hgsane.lib;../../../third_party/zlib/windows/lib/x86/zlib.lib;../../../third_party/libzip/windows/lib/x86/zip.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>../Release/HGBase.lib;../Release/HGImgFmt.lib;../../../release/lib/windows/x86/hgsane.lib;../../../third_party/zlib/windows/lib/x86/zlib.lib;../../../third_party/libzip/windows/lib/x86/zip.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>/LTCG %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/LTCG %(AdditionalOptions)</AdditionalOptions>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>../x64/Debug/HGBase.lib;../x64/Debug/HGImgFmt.lib;../x64/Debug/HGTwainUser.lib;../../../third_party/zlib/windows/lib/x64/zlib.lib;../../../third_party/libzip/windows/lib/x64/zip.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>../x64/Debug/HGBase.lib;../x64/Debug/HGImgFmt.lib;../../../release/lib/windows/x64/hgsane.lib;../../../third_party/zlib/windows/lib/x64/zlib.lib;../../../third_party/libzip/windows/lib/x64/zip.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>/ignore:4098,4075 /LTCG %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/ignore:4098,4075 /LTCG %(AdditionalOptions)</AdditionalOptions>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
...@@ -179,7 +179,7 @@ ...@@ -179,7 +179,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>../x64/Release/HGBase.lib;../x64/Release/HGImgFmt.lib;../x64/Release/HGTwainUser.lib;../../../third_party/zlib/windows/lib/x64/zlib.lib;../../../third_party/libzip/windows/lib/x64/zip.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>../x64/Release/HGBase.lib;../x64/Release/HGImgFmt.lib;../../../release/lib/windows/x64/hgsane.lib;../../../third_party/zlib/windows/lib/x64/zlib.lib;../../../third_party/libzip/windows/lib/x64/zip.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>/LTCG %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/LTCG %(AdditionalOptions)</AdditionalOptions>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
......
This diff is collapsed.
This diff is collapsed.
...@@ -3,15 +3,30 @@ ...@@ -3,15 +3,30 @@
#include "../../base/HGDef.h" #include "../../base/HGDef.h"
#include "../../base/HGInc.h" #include "../../base/HGInc.h"
#include "../../base/HGLock.h"
#include "../../base/HGImage.h" #include "../../base/HGImage.h"
#if defined(HG_CMP_MSC) && defined(SDK_USE_TWAIN)
#include "../../twain_user/HGTwain.h"
#else
#include "sane_ex/sane_ex.h" #include "sane_ex/sane_ex.h"
#endif
#include <vector> #include <vector>
#include <string> #include <string>
#define SCANEVENT_STATUS 0L
#define SCANEVENT_WORKING 1L
#define SCANEVENT_IMAGE 2L
#define SCANEVENT_FINISH 3L
#define SCANEVENT_ERROR 4L
struct DevParam
{
};
struct UploadParam
{
};
typedef void (*ScanEvent)(HGUInt event, void *value1, void *value2, void *param);
class Manager class Manager
{ {
public: public:
...@@ -19,20 +34,20 @@ public: ...@@ -19,20 +34,20 @@ public:
~Manager(); ~Manager();
// 扫描 // 扫描
void Scan(); bool Scan(const std::string& insertImgName, bool isInsert, ScanEvent event, void *param);
// 停止扫描 // 停止扫描
void StopScan(); bool StopScan();
// 获取当前连接的设备ID // 获取当前连接的设备ID
bool GetCurDevId(std::string& devId); bool GetCurDevId(std::string& devId);
// 获取连接的设备名列表 // 获取连接的设备名列表
bool GetDevNames(std::string& devNames); bool GetDevNames(std::vector<std::string> &devNameList);
// 获取上次的扫描结果 // 获取上次的扫描结果
bool GetImageByDevId(const std::string& devId, std::string& imgInfos); bool GetImageByDevId(const std::string& devId, std::vector<std::string> &imgNameList,
std::vector<std::string> &imgBase64List);
// 获取配置参数 // 获取配置参数
bool GetDevParam(const std::string& devId, std::string& devParam); bool GetDevParam(const std::string& devId, DevParam& devParam);
// 设置配置参数 // 设置配置参数
bool SetDevParam(const std::string& devId, const std::string& devParam); bool SetDevParam(const std::string& devId, const DevParam& devParam);
// 生成OFD // 生成OFD
bool ExportOfdFile(HGByte **data, HGUInt *size); bool ExportOfdFile(HGByte **data, HGUInt *size);
// 生成PDF // 生成PDF
...@@ -42,7 +57,7 @@ public: ...@@ -42,7 +57,7 @@ public:
// 生成ZIP // 生成ZIP
bool ExportZipFile(HGByte** data, HGUInt* size); bool ExportZipFile(HGByte** data, HGUInt* size);
// 上传图像 // 上传图像
bool UploadImage(const std::string& uploadParam); bool UploadImage(const UploadParam& uploadParam);
// 保存图片 // 保存图片
bool SaveImage(const std::string& devId, const std::string& imgName, const std::string& imgBase64); bool SaveImage(const std::string& devId, const std::string& imgName, const std::string& imgBase64);
// 删除图片 // 删除图片
...@@ -50,9 +65,11 @@ public: ...@@ -50,9 +65,11 @@ public:
// 删除所有图片 // 删除所有图片
bool DeleteAllImage(const std::string& devId); bool DeleteAllImage(const std::string& devId);
// 图像合并 // 图像合并
bool MergeImage(const std::string& devId, bool isHorizontal, const std::vector<int> &imgIndexs); 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::string& imgInfos); 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 ExchangeImage(const std::string& devId, int index1, int index2);
// 获取最后批次 // 获取最后批次
...@@ -60,32 +77,31 @@ public: ...@@ -60,32 +77,31 @@ public:
// 重置索引 // 重置索引
bool ResetPatchIndex(); bool ResetPatchIndex();
// 拆分图像 // 拆分图像
bool SplitImage(const std::string& devId, const std::string& imgName, bool isHorizontal, int x1, int y1, int x2, int y2); 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);
// 获取设备序列号 // 获取设备序列号
void GetDevSerialNo(const std::string& devId, std::string& serialNo); bool GetDevSerialNo(const std::string& devId, std::string& serialNo);
// 获取图像Base64 // 获取图像Base64
void GetImageBase64(const std::string& devId, const std::string& imgName, std::string& imgBase64); bool GetImageBase64(const std::string& devId, const std::string& imgName, std::string& imgBase64);
private: private:
static std::string GetFilePath(const std::string& devId); static std::string GetFilePath(const std::string& devId);
static std::vector<std::string> GetFileNameList(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(HGImage image, HGUInt quality);
static std::string GetBase64(const std::string& fileName); static std::string GetBase64(const std::string& fileName);
static HGByte* GetBuffer(const std::string& fileName, HGUInt *size); static HGByte* GetBuffer(const std::string& fileName, HGUInt *size);
static bool SaveBase64(const std::string& fileName, const char *base64); static bool SaveBase64(const std::string& fileName, const char *base64);
#if defined(HG_CMP_MSC) && defined(SDK_USE_TWAIN)
static void HGAPI DSEventCallback(HGTwainDS ds, HGUInt event, HGPointer param);
#else
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param); static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param);
#endif
private: private:
#if defined(HG_CMP_MSC) && defined(SDK_USE_TWAIN) HGLock m_lock;
HGTwainDSM m_twainDSM; std::string m_devName;
HGTwainDS m_twainDS; SANE_Handle m_devHandle;
#else std::string m_scanInsertImgName;
SANE_Handle m_saneDeviceHandle; bool m_scanIsInsert;
#endif ScanEvent m_scanEvent;
void* m_scanParam;
}; };
#endif /* __MANAGER_H__ */ #endif /* __MANAGER_H__ */
...@@ -29,6 +29,10 @@ void SockIoUser::HandleCmd(const SockIoCmdParam* param) ...@@ -29,6 +29,10 @@ void SockIoUser::HandleCmd(const SockIoCmdParam* param)
std::string user; std::string user;
std::string data; std::string data;
GetMsgInfo(param, user, data); GetMsgInfo(param, user, data);
if (user.empty())
{
return;
}
if ("scan" == user) if ("scan" == user)
{ {
...@@ -50,16 +54,29 @@ void SockIoUser::HandleCmd(const SockIoCmdParam* param) ...@@ -50,16 +54,29 @@ void SockIoUser::HandleCmd(const SockIoCmdParam* param)
cJSON_Delete(json); cJSON_Delete(json);
} }
std::string resp = "42[\"error\", \"device error\"]"; bool ret = g_manager->Scan(imgName, insert, ScanCallback, this);
SendResponse((const HGByte *)resp.c_str(), (HGUInt)resp.size(), HGTRUE); if (!ret)
{
std::string resp = "42[\"error\", \"scan error\"]";
SendResponse((const HGByte*)resp.c_str(), (HGUInt)resp.size(), HGTRUE);
}
} }
else if ("stop" == user) else if ("stop" == user)
{ {
std::string resp = "42[\"error\", \"device error\"]"; bool ret = g_manager->StopScan();
SendResponse((const HGByte*)resp.c_str(), (HGUInt)resp.size(), HGTRUE); if (!ret)
{
std::string resp = "42[\"error\", \"stop error\"]";
SendResponse((const HGByte*)resp.c_str(), (HGUInt)resp.size(), HGTRUE);
}
} }
} }
void SockIoUser::HandleRet(const SockIoRetParam* param)
{
SendResponse(param->data, param->size, HGTRUE);
}
void SockIoUser::ThreadFunc() void SockIoUser::ThreadFunc()
{ {
char chBuffer[2048]; char chBuffer[2048];
...@@ -413,6 +430,57 @@ void SockIoUser::ThreadFunc() ...@@ -413,6 +430,57 @@ void SockIoUser::ThreadFunc()
} }
} }
void SockIoUser::ScanCallback(HGUInt event, void* value1, void* value2, void* param)
{
SockIoUser* p = (SockIoUser*)param;
char *resp = NULL;
if (SCANEVENT_WORKING == event)
{
resp = new char[256];
sprintf(resp, "42[\"event\", \"%s\"]", "scanning...");
}
else if (SCANEVENT_FINISH == event)
{
resp = new char[256];
sprintf(resp, "42[\"result\", {\"code\":204, \"msg\":\"%s\"}]", "scan finish!");
}
else if (SCANEVENT_ERROR == event)
{
resp = new char[256];
sprintf(resp, "42[\"error\", \"%s\"]", "device error");
}
else if (SCANEVENT_IMAGE == event)
{
const char* imgName = (const char*)value1;
const char* imgBase64 = (const char*)value2;
resp = new char[256 + strlen(imgName) + strlen(imgBase64)];
sprintf(resp, "42[\"image\", {\"imageName\":\"%s\", \"image\":\"%s\"}]", imgName, imgBase64);
}
if (NULL != resp)
{
SockIoRetParam* param = new SockIoRetParam;
param->data = new HGByte[strlen(resp)];
param->size = (HGUInt)strlen(resp);
memcpy(param->data, resp, strlen(resp));
WebMsg msg;
msg.msgId = WEB_MSGID_SOCKIORET;
msg.userId = p->m_id;
msg.param = param;
bool b = p->m_server->SendMsg(&msg);
if (!b)
{
delete[] param->data;
param->size = 0;
delete param;
}
delete[] resp;
}
}
void SockIoUser::GetMsgInfo(const SockIoCmdParam* param, std::string& user, std::string& data) void SockIoUser::GetMsgInfo(const SockIoCmdParam* param, std::string& user, std::string& data)
{ {
user.clear(); user.clear();
......
...@@ -15,11 +15,13 @@ public: ...@@ -15,11 +15,13 @@ public:
virtual ~SockIoUser(); virtual ~SockIoUser();
void HandleCmd(const SockIoCmdParam* param); void HandleCmd(const SockIoCmdParam* param);
void HandleRet(const SockIoRetParam* param);
protected: protected:
virtual void ThreadFunc(); virtual void ThreadFunc();
private: private:
static void ScanCallback(HGUInt event, void* value1, void *value2, void* param);
static void GetMsgInfo(const SockIoCmdParam* param, std::string &user, std::string& data); static void GetMsgInfo(const SockIoCmdParam* param, std::string &user, std::string& data);
bool ShakeHand(const std::string& head); bool ShakeHand(const std::string& head);
void Pong(); void Pong();
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#define WEB_MSGID_WSCMD 4 #define WEB_MSGID_WSCMD 4
#define WEB_MSGID_HTTPCMD 5 #define WEB_MSGID_HTTPCMD 5
#define WEB_MSGID_SOCKIOCMD 6 #define WEB_MSGID_SOCKIOCMD 6
#define WEB_MSGID_WSRET 7
#define WEB_MSGID_HTTPRET 8
#define WEB_MSGID_SOCKIORET 9
struct WebMsg struct WebMsg
{ {
...@@ -50,4 +53,10 @@ struct SockIoCmdParam ...@@ -50,4 +53,10 @@ struct SockIoCmdParam
HGUInt size; HGUInt size;
}; };
struct SockIoRetParam
{
HGByte* data;
HGUInt size;
};
#endif /* __WEBMSG_H__ */ #endif /* __WEBMSG_H__ */
\ No newline at end of file
...@@ -276,6 +276,23 @@ void WebServer::HandleMsg(const WebMsg* msg) ...@@ -276,6 +276,23 @@ void WebServer::HandleMsg(const WebMsg* msg)
user->HandleCmd(param); user->HandleCmd(param);
} }
delete[] param->data;
param->size = 0;
delete param;
}
else if (WEB_MSGID_SOCKIORET == msg->msgId)
{
HGUInt id = (HGUInt)msg->userId;
SockIoRetParam* param = (SockIoRetParam*)msg->param;
assert(NULL != param);
int nIndex = GetUserIndex(id);
if (-1 != nIndex)
{
SockIoUser* user = (SockIoUser*)m_vectorUser[nIndex];
user->HandleRet(param);
}
delete[] param->data; delete[] param->data;
param->size = 0; param->size = 0;
delete param; delete param;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment