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>
......
...@@ -51,8 +51,19 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -51,8 +51,19 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
} }
else if (requestMethod == "GET" && requestURIPath == "/WebScan/getDevices") else if (requestMethod == "GET" && requestURIPath == "/WebScan/getDevices")
{ {
std::string devNames; std::vector<std::string> devNameList;
g_manager->GetDevNames(devNames); g_manager->GetDevNames(devNameList);
std::string devNames = "[";
for (int i = 0; i < (int)devNameList.size(); ++i)
{
devNames += "\"";
devNames += devNameList[i];
devNames += "\"";
if (i != (int)devNameList.size() - 1)
devNames += ",";
}
devNames += "]";
char* result = new char[devNames.size() + 256]; char* result = new char[devNames.size() + 256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, devNames.c_str()); sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, devNames.c_str());
...@@ -62,18 +73,24 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -62,18 +73,24 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
} }
else if (requestMethod == "GET" && requestURIPath == "/WebScan/image/getImageByPid") else if (requestMethod == "GET" && requestURIPath == "/WebScan/image/getImageByPid")
{ {
std::string devId; std::string devId = HttpHead::GetValue(requestURIQueryInfos, "pid");
for (int i = 0; i < (int)requestURIQueryInfos.size(); ++i) std::vector<std::string> imgNameList;
{ std::vector<std::string> imgBase64List;
if ("pid" == requestURIQueryInfos[i].first) g_manager->GetImageByDevId(devId, imgNameList, imgBase64List);
std::string imgInfos = "[";
for (int i = 0; i < (int)imgNameList.size(); ++i)
{ {
devId = requestURIQueryInfos[i].second; imgInfos += "{\"imageName\":\"";
break; imgInfos += imgNameList[i];
} imgInfos += "\",\"src\":\"";
} imgInfos += imgBase64List[i];
imgInfos += "\"}";
std::string imgInfos; if (i != imgNameList.size() - 1)
g_manager->GetImageByDevId(devId, imgInfos); imgInfos += ",";
}
imgInfos += "]";
char *result = new char[imgInfos.size() + 256]; char *result = new char[imgInfos.size() + 256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, imgInfos.c_str()); sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, imgInfos.c_str());
...@@ -83,21 +100,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -83,21 +100,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
} }
else if (requestMethod == "GET" && requestURIPath == "/WebScan/getParams") else if (requestMethod == "GET" && requestURIPath == "/WebScan/getParams")
{ {
std::string devId; std::string devId = HttpHead::GetValue(requestURIQueryInfos, "pid");
for (int i = 0; i < (int)requestURIQueryInfos.size(); ++i) DevParam devParam;
{
if ("pid" == requestURIQueryInfos[i].first)
{
devId = requestURIQueryInfos[i].second;
break;
}
}
std::string devParam;
g_manager->GetDevParam(devId, devParam); g_manager->GetDevParam(devId, devParam);
char* result = new char[devParam.size() + 256]; char devParamStr[1024];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, devParam.c_str()); sprintf(devParamStr, "{\"device\":\"%s\", \"upload\":{\"uploadMode\":%d}}", "", 2);
char* result = new char[strlen(devParamStr) + 256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, devParamStr);
SendResponse(requestHttpVersion.c_str(), 200, "OK", SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json"); (const HGByte*)result, (HGUInt)strlen(result), "application/json");
delete[] result; delete[] result;
...@@ -107,30 +118,12 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -107,30 +118,12 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded")) if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{ {
std::string query((const char *)param->data, param->size); std::string query((const char *)param->data, param->size);
HttpPairs uriQueryInfos; HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos); HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string devId; std::string devId = HttpHead::GetValue(uriQueryInfos, "pid");
for (int i = 0; i < (int)uriQueryInfos.size(); ++i) std::string devParamStr = HttpHead::GetValue(uriQueryInfos, "params");
{ DevParam devParam;
if ("pid" == uriQueryInfos[i].first)
{
devId = uriQueryInfos[i].second;
break;
}
}
std::string devParam;
for (int i = 0; i < (int)uriQueryInfos.size(); ++i)
{
if ("params" == uriQueryInfos[i].first)
{
devParam = uriQueryInfos[i].second;
break;
}
}
g_manager->SetDevParam(devId, devParam); g_manager->SetDevParam(devId, devParam);
char result[256]; char result[256];
...@@ -176,24 +169,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -176,24 +169,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded")) if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{ {
std::string query((const char*)param->data, param->size); std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos; HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos); HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string uploadParam; std::string uploadParamStr = HttpHead::GetValue(uriQueryInfos, "formDataString");
for (int i = 0; i < (int)uriQueryInfos.size(); ++i) UploadParam uploadParam;
{
if ("formDataString" == uriQueryInfos[i].first)
{
uploadParam = uriQueryInfos[i].second;
break;
}
}
g_manager->UploadImage(uploadParam); g_manager->UploadImage(uploadParam);
char result[256]; char result[256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"\"}", 200); sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"%s\"}", 200, "success");
SendResponse(requestHttpVersion.c_str(), 200, "OK", SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json"); (const HGByte*)result, (HGUInt)strlen(result), "application/json");
} }
...@@ -203,44 +187,16 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -203,44 +187,16 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded")) if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{ {
std::string query((const char*)param->data, param->size); std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos; HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos); HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string devId; std::string devId = HttpHead::GetValue(uriQueryInfos, "pid");
for (int i = 0; i < (int)uriQueryInfos.size(); ++i) std::string imgName = HttpHead::GetValue(uriQueryInfos, "imageName");
{ std::string imgBase64 = HttpHead::GetValue(uriQueryInfos, "image");
if ("pid" == uriQueryInfos[i].first)
{
devId = uriQueryInfos[i].second;
break;
}
}
std::string imgName;
for (int i = 0; i < (int)uriQueryInfos.size(); ++i)
{
if ("imageName" == uriQueryInfos[i].first)
{
imgName = uriQueryInfos[i].second;
break;
}
}
std::string imgBase64;
for (int i = 0; i < (int)uriQueryInfos.size(); ++i)
{
if ("image" == uriQueryInfos[i].first)
{
imgBase64 = uriQueryInfos[i].second;
break;
}
}
g_manager->SaveImage(devId, imgName, imgBase64); g_manager->SaveImage(devId, imgName, imgBase64);
char result[256]; char result[256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"\"}", 200); sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"%s\"}", 200, "success");
SendResponse(requestHttpVersion.c_str(), 200, "OK", SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json"); (const HGByte*)result, (HGUInt)strlen(result), "application/json");
} }
...@@ -250,34 +206,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -250,34 +206,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded")) if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{ {
std::string query((const char*)param->data, param->size); std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos; HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos); HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string devId; std::string devId = HttpHead::GetValue(uriQueryInfos, "pid");
for (int i = 0; i < (int)uriQueryInfos.size(); ++i) std::string imgName = HttpHead::GetValue(uriQueryInfos, "imageName");
{
if ("pid" == uriQueryInfos[i].first)
{
devId = uriQueryInfos[i].second;
break;
}
}
std::string imgName;
for (int i = 0; i < (int)uriQueryInfos.size(); ++i)
{
if ("imageName" == uriQueryInfos[i].first)
{
imgName = uriQueryInfos[i].second;
break;
}
}
g_manager->DeleteImage(devId, imgName); g_manager->DeleteImage(devId, imgName);
char result[256]; char result[256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"\"}", 200); sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"%s\"}", 200, "success");
SendResponse(requestHttpVersion.c_str(), 200, "OK", SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json"); (const HGByte*)result, (HGUInt)strlen(result), "application/json");
} }
...@@ -287,24 +224,14 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -287,24 +224,14 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded")) if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{ {
std::string query((const char*)param->data, param->size); std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos; HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos); HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string devId; std::string devId = HttpHead::GetValue(uriQueryInfos, "pid");
for (int i = 0; i < (int)uriQueryInfos.size(); ++i)
{
if ("pid" == uriQueryInfos[i].first)
{
devId = uriQueryInfos[i].second;
break;
}
}
g_manager->DeleteAllImage(devId); g_manager->DeleteAllImage(devId);
char result[256]; char result[256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"\"}", 200); sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"%s\"}", 200, "success");
SendResponse(requestHttpVersion.c_str(), 200, "OK", SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json"); (const HGByte*)result, (HGUInt)strlen(result), "application/json");
} }
...@@ -314,29 +241,11 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -314,29 +241,11 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded")) if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{ {
std::string query((const char*)param->data, param->size); std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos; HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos); HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string devId; std::string devId = HttpHead::GetValue(uriQueryInfos, "pid");
for (int i = 0; i < (int)uriQueryInfos.size(); ++i) bool isHorizontal = ("false" != HttpHead::GetValue(uriQueryInfos, "isHorizontal")) ? true : false;
{
if ("pid" == uriQueryInfos[i].first)
{
devId = uriQueryInfos[i].second;
break;
}
}
bool isHorizontal = true;
for (int i = 0; i < (int)uriQueryInfos.size(); ++i)
{
if ("isHorizontal" == uriQueryInfos[i].first)
{
isHorizontal = ("true" == uriQueryInfos[i].second);
break;
}
}
std::vector<int> imgIndexs; std::vector<int> imgIndexs;
for (int i = 0; i < (int)uriQueryInfos.size(); ++i) for (int i = 0; i < (int)uriQueryInfos.size(); ++i)
...@@ -346,13 +255,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -346,13 +255,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
imgIndexs.push_back(atoi(uriQueryInfos[i].second.c_str())); imgIndexs.push_back(atoi(uriQueryInfos[i].second.c_str()));
} }
} }
std::string imgName, imgBase64;
g_manager->MergeImage(devId, isHorizontal, imgIndexs, imgName, imgBase64);
g_manager->MergeImage(devId, true, imgIndexs); char *result = new char[256 + imgName.size() + imgBase64.size()];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":{\"imageName\":\"%s\", \"src\":\"%s\"}}",
char result[256]; 200, imgName.c_str(), imgBase64.c_str());
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"\"}", 200);
SendResponse(requestHttpVersion.c_str(), 200, "OK", SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json"); (const HGByte*)result, (HGUInt)strlen(result), "application/json");
delete[] result;
} }
} }
else if (requestMethod == "POST" && requestURIPath == "/WebScan/image/bookSort") else if (requestMethod == "POST" && requestURIPath == "/WebScan/image/bookSort")
...@@ -360,22 +271,26 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -360,22 +271,26 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded")) if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{ {
std::string query((const char*)param->data, param->size); std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos; HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos); HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string devId; std::string devId = HttpHead::GetValue(uriQueryInfos, "pid");
for (int i = 0; i < (int)uriQueryInfos.size(); ++i) std::vector<std::string> imgNameList, imgBase64List;
{ g_manager->BookSort(devId, imgNameList, imgBase64List);
if ("pid" == uriQueryInfos[i].first)
std::string imgInfos = "[";
for (int i = 0; i < (int)imgNameList.size(); ++i)
{ {
devId = uriQueryInfos[i].second; imgInfos += "{\"imageName\":\"";
break; imgInfos += imgNameList[i];
} imgInfos += "\",\"src\":\"";
} imgInfos += imgBase64List[i];
imgInfos += "\"}";
std::string imgInfos; if (i != imgNameList.size() - 1)
g_manager->BookSort(devId, imgInfos); imgInfos += ",";
}
imgInfos += "]";
char* result = new char[imgInfos.size() + 256]; char* result = new char[imgInfos.size() + 256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, imgInfos.c_str()); sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, imgInfos.c_str());
...@@ -389,17 +304,14 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -389,17 +304,14 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded")) if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{ {
std::string query((const char*)param->data, param->size); std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos; HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos); HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string devId; std::string devId = HttpHead::GetValue(uriQueryInfos, "pid");
int index1 = -1, index2 = -1; int index1 = -1, index2 = -1;
for (int i = 0; i < (int)uriQueryInfos.size(); ++i) for (int i = 0; i < (int)uriQueryInfos.size(); ++i)
{ {
if ("pid" == uriQueryInfos[i].first) if ("indexs[]" == uriQueryInfos[i].first)
devId = uriQueryInfos[i].second;
else if ("indexs[]" == uriQueryInfos[i].first)
{ {
if (-1 == index1) if (-1 == index1)
index1 = atoi(uriQueryInfos[i].second.c_str()); index1 = atoi(uriQueryInfos[i].second.c_str());
...@@ -407,11 +319,10 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -407,11 +319,10 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
index2 = atoi(uriQueryInfos[i].second.c_str()); index2 = atoi(uriQueryInfos[i].second.c_str());
} }
} }
g_manager->ExchangeImage(devId, index1, index2); g_manager->ExchangeImage(devId, index1, index2);
char result[256]; char result[256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"\"}", 200); sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"%s\"}", 200, "success");
SendResponse(requestHttpVersion.c_str(), 200, "OK", SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json"); (const HGByte*)result, (HGUInt)strlen(result), "application/json");
} }
...@@ -427,12 +338,36 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -427,12 +338,36 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
(const HGByte*)result, (HGUInt)strlen(result), "application/json"); (const HGByte*)result, (HGUInt)strlen(result), "application/json");
delete[] result; delete[] result;
} }
else if (requestMethod == "GET" && requestURIPath == "/WebScan/getSerialNumber")
{
std::string devId = HttpHead::GetValue(requestURIQueryInfos, "pid");
std::string devSerialNo;
g_manager->GetDevSerialNo(devId, devSerialNo);
char* result = new char[devSerialNo.size() + 256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"%s\"}", 200, devSerialNo.c_str());
SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json");
delete[] result;
}
else if (requestMethod == "GET" && requestURIPath == "/WebScan/getImageByName")
{
std::string devId = HttpHead::GetValue(requestURIQueryInfos, "pid");
std::string imgName = HttpHead::GetValue(requestURIQueryInfos, "imageName");
std::string imgBase64;
g_manager->GetImageBase64(devId, imgName, imgBase64);
char* result = new char[imgBase64.size() + 256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"%s\"}", 200, imgBase64.c_str());
SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json");
delete[] result;
}
else if (requestMethod == "POST" && requestURIPath == "/WebScan/image/resetPatchIndex") else if (requestMethod == "POST" && requestURIPath == "/WebScan/image/resetPatchIndex")
{ {
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded")) if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{ {
std::string query((const char*)param->data, param->size); std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos; HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos); HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
} }
...@@ -440,7 +375,7 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -440,7 +375,7 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
g_manager->ResetPatchIndex(); g_manager->ResetPatchIndex();
char result[256]; char result[256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"\"}", 200); sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"%s\"}", 200, "success");
SendResponse(requestHttpVersion.c_str(), 200, "OK", SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json"); (const HGByte*)result, (HGUInt)strlen(result), "application/json");
} }
...@@ -449,38 +384,26 @@ void HttpUser::HandleCmd(const HttpCmdParam* param) ...@@ -449,38 +384,26 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded")) if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{ {
std::string query((const char*)param->data, param->size); std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos; HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos); HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string devId, imgName; std::string devId = HttpHead::GetValue(uriQueryInfos, "pid");
bool isHorizontal = true; std::string imgName = HttpHead::GetValue(uriQueryInfos, "imageName");
int x1 = -1, x2 = -1, y1 = -1, y2 = -1; bool isHorizontal = ("false" != HttpHead::GetValue(uriQueryInfos, "isHorizontal")) ? true : false;
int x1 = atoi(HttpHead::GetValue(uriQueryInfos, "x1").c_str());
for (int i = 0; i < (int)uriQueryInfos.size(); ++i) int x2 = atoi(HttpHead::GetValue(uriQueryInfos, "x2").c_str());
{ int y1 = atoi(HttpHead::GetValue(uriQueryInfos, "y1").c_str());
if ("pid" == uriQueryInfos[i].first) int y2 = atoi(HttpHead::GetValue(uriQueryInfos, "y2").c_str());
devId = uriQueryInfos[i].second; std::string imgName1, imgBase64_1, imgName2, imgBase64_2;
else if ("imageName" == uriQueryInfos[i].first) g_manager->SplitImage(devId, imgName, isHorizontal, x1, y1, x2, y2,
imgName = uriQueryInfos[i].second; imgName1, imgBase64_1, imgName2, imgBase64_2);
else if ("isHorizontal" == uriQueryInfos[i].first)
isHorizontal = ("true" == uriQueryInfos[i].second); char *result = new char[256 + imgName1.size() + imgBase64_1.size() + imgName2.size() + imgBase64_2.size()];
else if ("x1" == uriQueryInfos[i].first) sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":{\"oneSrc\":\"%s\", \"oneName\":\"%s\", \"twoSrc\":\"%s\", \"twoName\":\"%s\"}}",
x1 = atoi(uriQueryInfos[i].second.c_str()); 200, imgBase64_1.c_str(), imgName1.c_str(), imgBase64_2.c_str(), imgName2.c_str());
else if ("x2" == uriQueryInfos[i].first)
x2 = atoi(uriQueryInfos[i].second.c_str());
else if ("y1" == uriQueryInfos[i].first)
y1 = atoi(uriQueryInfos[i].second.c_str());
else if ("y2" == uriQueryInfos[i].first)
y2 = atoi(uriQueryInfos[i].second.c_str());
}
g_manager->SplitImage(devId, imgName, isHorizontal, x1, y1, x2, y2);
char result[256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":\"\"}", 200);
SendResponse(requestHttpVersion.c_str(), 200, "OK", SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json"); (const HGByte*)result, (HGUInt)strlen(result), "application/json");
delete[] result;
} }
} }
} }
......
...@@ -14,7 +14,7 @@ extern "C" ...@@ -14,7 +14,7 @@ extern "C"
#include <algorithm> #include <algorithm>
#if defined(HG_CMP_MSC) #if defined(HG_CMP_MSC)
static CHAR* AnsiToUtf8(const char* text) static std::string AnsiToUtf8(const char* text)
{ {
int wlen = ::MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0); int wlen = ::MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen]; WCHAR* pUnicode = new WCHAR[wlen];
...@@ -23,82 +23,154 @@ static CHAR* AnsiToUtf8(const char* text) ...@@ -23,82 +23,154 @@ static CHAR* AnsiToUtf8(const char* text)
CHAR* pUTF8 = new CHAR[len]; CHAR* pUTF8 = new CHAR[len];
::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, pUTF8, len, NULL, NULL); ::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, pUTF8, len, NULL, NULL);
delete[] pUnicode; delete[] pUnicode;
return pUTF8; std::string ret = pUTF8;
delete[] pUTF8;
return ret;
}
static std::string Utf8ToAnsi(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_UTF8, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pAnsi = new CHAR[len];
::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, pAnsi, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pAnsi;
delete[] pAnsi;
return ret;
} }
#endif #endif
Manager::Manager() Manager::Manager()
{ {
#if defined(HG_CMP_MSC) && defined(SDK_USE_TWAIN) HGBase_CreateLock(&m_lock);
m_twainDSM = NULL; m_devName.clear();
HGTwain_LoadDSM(&m_twainDSM);
HGTwain_OpenDSM(m_twainDSM); SANE_Int version_code = 0;
m_twainDS = NULL; SANE_Status status = sane_init_ex(&version_code, sane_ex_callback, this);
HGTwain_GetDefaultDS(m_twainDSM, &m_twainDS); assert(SANE_STATUS_GOOD == status);
#else
m_saneDeviceHandle = NULL; m_devHandle = NULL;
SANE_Int v = 0; m_scanInsertImgName.clear();
sane_init_ex(&v, sane_ex_callback, this); m_scanIsInsert = false;
#endif m_scanEvent = NULL;
m_scanParam = NULL;
} }
Manager::~Manager() Manager::~Manager()
{ {
#if defined(HG_CMP_MSC) && defined(SDK_USE_TWAIN) StopScan();
HGTwain_CloseDSM(m_twainDSM);
HGTwain_UnloadDSM(m_twainDSM);
m_twainDSM = NULL;
#else
if (nullptr != m_saneDeviceHandle)
{
sane_cancel(m_saneDeviceHandle);
sane_close(m_saneDeviceHandle);
m_saneDeviceHandle = NULL;
}
sane_exit(); sane_exit();
#endif
m_devName.clear();
HGBase_DestroyLock(m_lock);
m_lock = NULL;
} }
void Manager::Scan() bool Manager::Scan(const std::string& insertImgName, bool isInsert, ScanEvent event, void* param)
{ {
assert(NULL != event && NULL != param);
bool ret = false;
HGBase_EnterLock(m_lock);
if (NULL != m_devHandle)
{
sane_cancel(m_devHandle);
sane_close(m_devHandle);
m_devHandle = NULL;
m_scanInsertImgName.clear();
m_scanIsInsert = false;
m_scanEvent = NULL;
m_scanParam = NULL;
}
m_scanInsertImgName = insertImgName;
m_scanIsInsert = isInsert;
m_scanEvent = event;
m_scanParam = param;
SANE_Status status = sane_open(m_devName.c_str(), &m_devHandle);
if (SANE_STATUS_GOOD == status)
{
if (SANE_STATUS_GOOD == sane_start(m_devHandle))
{
ret = true;
}
else
{
sane_close(m_devHandle);
m_devHandle = NULL;
m_scanInsertImgName.clear();
m_scanIsInsert = false;
m_scanEvent = NULL;
m_scanParam = NULL;
}
}
else
{
m_scanInsertImgName.clear();
m_scanIsInsert = false;
m_scanEvent = NULL;
m_scanParam = NULL;
}
HGBase_LeaveLock(m_lock);
return ret;
} }
void Manager::StopScan() bool Manager::StopScan()
{ {
HGBase_EnterLock(m_lock);
if (NULL != m_devHandle)
{
sane_cancel(m_devHandle);
sane_close(m_devHandle);
m_devHandle = NULL;
m_scanInsertImgName.clear();
m_scanIsInsert = false;
m_scanEvent = NULL;
m_scanParam = NULL;
}
HGBase_LeaveLock(m_lock);
return true;
} }
bool Manager::GetCurDevId(std::string& devId) bool Manager::GetCurDevId(std::string& devId)
{ {
devId = "123456"; HGBase_EnterLock(m_lock);
devId = m_devName;
HGBase_LeaveLock(m_lock);
return true; return true;
} }
bool Manager::GetDevNames(std::string& devNames) bool Manager::GetDevNames(std::vector<std::string>& devNameList)
{ {
devNames = "["; devNameList.clear();
int count = 2; const SANE_Device** device_list;
for (int i = 0; i < count; ++i) if (SANE_STATUS_GOOD == sane_get_devices(&device_list, SANE_TRUE))
{ {
char devName[32]; const SANE_Device** p;
sprintf(devName, "Scanner%d", i); for (p = device_list; *p != NULL; ++p)
{
devNames += "\""; devNameList.push_back((*p)->name);
devNames += devName; }
devNames += "\"";
if (i != count - 1)
devNames += ",";
} }
devNames += "]";
return true; return true;
} }
bool Manager::GetImageByDevId(const std::string& devId, std::string& imgInfos) bool Manager::GetImageByDevId(const std::string& devId, std::vector<std::string>& imgNameList,
std::vector<std::string>& imgBase64List)
{ {
imgInfos = "["; imgNameList.clear();
imgBase64List.clear();
std::string filePath = GetFilePath(devId); std::string filePath = GetFilePath(devId);
std::vector<std::string> fileNameList = GetFileNameList(devId); std::vector<std::string> fileNameList = GetFileNameList(devId);
...@@ -111,62 +183,26 @@ bool Manager::GetImageByDevId(const std::string& devId, std::string& imgInfos) ...@@ -111,62 +183,26 @@ bool Manager::GetImageByDevId(const std::string& devId, std::string& imgInfos)
HGImgFmt_LoadJpegImage(fileName.c_str(), NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img); HGImgFmt_LoadJpegImage(fileName.c_str(), NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
if (NULL != img) if (NULL != img)
{ {
std::string base64 = GetBase64(img, 0); std::string imgBase64 = "data:image/jpeg;base64,";
HGBase_DestroyImage(img); imgBase64 += GetBase64(img, 0);
imgInfos += "{\"imageName\":\""; imgNameList.push_back(fileNameList[i]);
imgInfos += fileNameList[i]; imgBase64List.push_back(imgBase64);
imgInfos += "\",\"src\":\""; HGBase_DestroyImage(img);
imgInfos += "data:image/jpeg;base64,";
imgInfos += base64;
imgInfos += "\"}";
if (i != fileNameList.size() - 1)
imgInfos += ",";
} }
} }
imgInfos += "]";
return true; return true;
} }
bool Manager::GetDevParam(const std::string& devId, std::string& devParam) bool Manager::GetDevParam(const std::string& devId, DevParam& devParam)
{ {
devParam = "{"; return false;
devParam += "\"device\":\"Scanner0\",";
devParam += "\"autofeeder\":true,";
devParam += "\"pixel\":1,";
devParam += "\"white\":0,";
devParam += "\"single\":false,";
devParam += "\"format\":\"jpg\",";
devParam += "\"resolution\":200,";
devParam += "\"serialNum\":\"HG1060A50213P1\",";
devParam += "\"fwVersion\":\"G460210104\",";
devParam += "\"sdkVersion\":\"1.0.0.0\",";
devParam += "\"upload\":{";
devParam += "\"uploadMode\":2,";
devParam += "\"httpUrl\":null,";
devParam += "\"fileName\":null,";
devParam += "\"httpMethod\":null,";
devParam += "\"header\":null,";
devParam += "\"param\":null,";
devParam += "\"ftpUrl\":null,";
devParam += "\"ftpPath\":null,";
devParam += "\"ftpUser\":null,";
devParam += "\"ftpPassword\":null,";
devParam += "\"ftpPort\":21,";
devParam += "\"ftpMode\":2";
devParam += "}";
devParam += "}";
return true;
} }
bool Manager::SetDevParam(const std::string& devId, const std::string& devParam) bool Manager::SetDevParam(const std::string& devId, const DevParam& devParam)
{ {
return true; return false;
} }
bool Manager::ExportOfdFile(HGByte** data, HGUInt* size) bool Manager::ExportOfdFile(HGByte** data, HGUInt* size)
...@@ -345,9 +381,7 @@ bool Manager::ExportZipFile(HGByte** data, HGUInt* size) ...@@ -345,9 +381,7 @@ bool Manager::ExportZipFile(HGByte** data, HGUInt* size)
int error = 0; int error = 0;
#if defined(HG_CMP_MSC) #if defined(HG_CMP_MSC)
CHAR* pUTF8 = AnsiToUtf8(tmpFileName); zip* z = zip_open(AnsiToUtf8(tmpFileName).c_str(), ZIP_CREATE | ZIP_TRUNCATE, &error);
zip* z = zip_open(pUTF8, ZIP_CREATE | ZIP_TRUNCATE, &error);
delete[] pUTF8;
#else #else
zip* z = zip_open(tmpFileName, ZIP_CREATE | ZIP_TRUNCATE, &error); zip* z = zip_open(tmpFileName, ZIP_CREATE | ZIP_TRUNCATE, &error);
#endif #endif
...@@ -390,9 +424,9 @@ bool Manager::ExportZipFile(HGByte** data, HGUInt* size) ...@@ -390,9 +424,9 @@ bool Manager::ExportZipFile(HGByte** data, HGUInt* size)
return (NULL != *data); return (NULL != *data);
} }
bool Manager::UploadImage(const std::string& uploadParam) bool Manager::UploadImage(const UploadParam& uploadParam)
{ {
return true; return false;
} }
bool Manager::SaveImage(const std::string& devId, const std::string& imgName, const std::string& imgBase64) bool Manager::SaveImage(const std::string& devId, const std::string& imgName, const std::string& imgBase64)
...@@ -425,19 +459,7 @@ bool Manager::DeleteImage(const std::string& devId, const std::string& imgName) ...@@ -425,19 +459,7 @@ bool Manager::DeleteImage(const std::string& devId, const std::string& imgName)
} }
} }
std::string cfgName = filePath + "images.txt"; SaveFileNameList(devId, fileNameList);
FILE* file = fopen(cfgName.c_str(), "w");
if (NULL != file)
{
for (int i = 0; i < (int)fileNameList.size(); ++i)
{
fwrite(fileNameList[i].c_str(), 1, fileNameList[i].size(), file);
fwrite("\n", 1, strlen("\n"), file);
}
fclose(file);
}
ret = true; ret = true;
} }
...@@ -454,14 +476,108 @@ bool Manager::DeleteAllImage(const std::string& devId) ...@@ -454,14 +476,108 @@ bool Manager::DeleteAllImage(const std::string& devId)
std::string fileName = filePath + fileNameList[i]; std::string fileName = filePath + fileNameList[i];
HGBase_DeleteFile(fileName.c_str()); HGBase_DeleteFile(fileName.c_str());
} }
fileNameList.clear();
std::string cfgName = filePath + "images.txt"; SaveFileNameList(devId, fileNameList);
HGBase_DeleteFile(cfgName.c_str());
return true; return true;
} }
bool Manager::MergeImage(const std::string& devId, bool isHorizontal, const std::vector<int>& imgIndexs) bool Manager::MergeImage(const std::string& devId, bool isHorizontal, const std::vector<int>& imgIndexList,
std::string& imgName, std::string& imgBase64)
{ {
imgName.clear();
imgBase64.clear();
std::string filePath = GetFilePath(devId);
std::vector<std::string> fileNameList = GetFileNameList(devId);
std::vector<HGImage> imgList;
for (int i = 0; i < (int)imgIndexList.size(); ++i)
{
int index = imgIndexList[i];
if (index >= 0 && index < (int)fileNameList.size())
{
std::string fileName = filePath + fileNameList[index];
HGImage img = NULL;
HGImgFmt_LoadJpegImage(fileName.c_str(), NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
if (NULL != img)
imgList.push_back(img);
}
}
HGUInt width = 0, height = 0;
for (int i = 0; i < (int)imgList.size(); ++i)
{
HGImageInfo imgInfo;
HGBase_GetImageInfo(imgList[i], &imgInfo);
if (isHorizontal)
{
width += imgInfo.width;
if (imgInfo.height > height)
height = imgInfo.height;
}
else
{
height += imgInfo.height;
if (imgInfo.width > width)
width = imgInfo.width;
}
}
if (width > 0 && height > 0)
{
HGImage img = NULL;
HGBase_CreateImage(width, height, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
if (NULL != img)
{
HGUInt x = 0, y = 0;
for (int i = 0; i < (int)imgList.size(); ++i)
{
HGImageInfo imgInfo;
HGBase_GetImageInfo(imgList[i], &imgInfo);
HGImageRoi roi = {x, y, x + imgInfo.width, y + imgInfo.height};
HGBase_SetImageROI(img, &roi);
HGBase_CopyImage(imgList[i], img);
HGBase_ResetImageROI(img);
if (isHorizontal)
x += imgInfo.width;
else
y += imgInfo.height;
}
int maxIndex = 0;
for (int i = 0; i < (int)fileNameList.size(); ++i)
{
int index = atoi(fileNameList[i].c_str());
if (index > maxIndex)
maxIndex = index;
}
HGChar name[256];
sprintf(name, "%d.jpg", maxIndex + 1);
imgName = name;
HGBase_CreateDir(filePath.c_str());
std::string fileName = filePath + imgName;
HGImgFmt_SaveJpegImage(img, NULL, 0, fileName.c_str());
fileNameList.push_back(imgName);
SaveFileNameList(devId, fileNameList);
imgBase64 = "data:image/jpeg;base64,";
imgBase64 += GetBase64(img, 0);
HGBase_DestroyImage(img);
}
}
for (int i = 0; i < (int)imgList.size(); ++i)
{
HGBase_DestroyImage(imgList[i]);
}
return true; return true;
} }
...@@ -470,26 +586,14 @@ static bool LowerSort(const std::string &str1, const std::string& str2) ...@@ -470,26 +586,14 @@ static bool LowerSort(const std::string &str1, const std::string& str2)
return str1 < str2; return str1 < str2;
} }
bool Manager::BookSort(const std::string& devId, std::string& imgInfos) bool Manager::BookSort(const std::string& devId, std::vector<std::string>& imgNameList,
std::vector<std::string>& imgBase64List)
{ {
std::string filePath = GetFilePath(devId);
std::vector<std::string> fileNameList = GetFileNameList(devId); std::vector<std::string> fileNameList = GetFileNameList(devId);
std::sort(fileNameList.begin(), fileNameList.end(), LowerSort); std::sort(fileNameList.begin(), fileNameList.end(), LowerSort);
std::string cfgName = filePath + "images.txt"; SaveFileNameList(devId, fileNameList);
FILE* file = fopen(cfgName.c_str(), "w"); return GetImageByDevId(devId, imgNameList, imgBase64List);
if (NULL != file)
{
for (int i = 0; i < (int)fileNameList.size(); ++i)
{
fwrite(fileNameList[i].c_str(), 1, fileNameList[i].size(), file);
fwrite("\n", 1, strlen("\n"), file);
}
fclose(file);
}
return GetImageByDevId(devId, imgInfos);
} }
bool Manager::ExchangeImage(const std::string& devId, int index1, int index2) bool Manager::ExchangeImage(const std::string& devId, int index1, int index2)
...@@ -504,25 +608,15 @@ bool Manager::ExchangeImage(const std::string& devId, int index1, int index2) ...@@ -504,25 +608,15 @@ bool Manager::ExchangeImage(const std::string& devId, int index1, int index2)
fileNameList[index1] = imgName2; fileNameList[index1] = imgName2;
fileNameList[index2] = imgName1; fileNameList[index2] = imgName1;
std::string cfgName = filePath + "images.txt"; SaveFileNameList(devId, fileNameList);
FILE* file = fopen(cfgName.c_str(), "w");
if (NULL != file)
{
for (int i = 0; i < (int)fileNameList.size(); ++i)
{
fwrite(fileNameList[i].c_str(), 1, fileNameList[i].size(), file);
fwrite("\n", 1, strlen("\n"), file);
}
fclose(file);
}
return true; return true;
} }
bool Manager::GetLastBetch(std::string& devId) bool Manager::GetLastBetch(std::string& devId)
{ {
devId = "123456"; HGBase_EnterLock(m_lock);
devId = m_devName;
HGBase_LeaveLock(m_lock);
return true; return true;
} }
...@@ -531,19 +625,145 @@ bool Manager::ResetPatchIndex() ...@@ -531,19 +625,145 @@ bool Manager::ResetPatchIndex()
return true; return true;
} }
bool Manager::SplitImage(const std::string& devId, const std::string& imgName, bool isHorizontal, int x1, int y1, int x2, int y2) bool Manager::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)
{ {
imgName1.clear();
imgBase64_1.clear();
imgName2.clear();
imgBase64_2.clear();
std::string filePath = GetFilePath(devId);
std::string fileName = filePath + imgName;
HGImage img = NULL;
HGImgFmt_LoadJpegImage(fileName.c_str(), NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
if (NULL != img)
{
HGImageInfo imgInfo;
HGBase_GetImageInfo(img, &imgInfo);
for (int i = 0; i < 2; ++i)
{
HGUInt newWidth = isHorizontal ? x1 : imgInfo.width;
if (1 == i)
newWidth = isHorizontal ? (imgInfo.width - x1) : imgInfo.width;
HGUInt newHeight = isHorizontal ? imgInfo.height : y1;
if (1 == i)
newHeight = isHorizontal ? imgInfo.height : (imgInfo.height - y1);
HGImage newImg = NULL;
HGBase_CreateImage(newWidth, newHeight, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &newImg);
if (NULL != newImg)
{
HGImageRoi roi;
if (isHorizontal)
{
roi.left = 0;
roi.top = 0;
roi.right = x1;
roi.bottom = imgInfo.height;
if (1 == i)
{
roi.left = x1;
roi.right = imgInfo.width;
}
}
else
{
roi.left = 0;
roi.top = 0;
roi.right = imgInfo.width;
roi.bottom = y1;
if (1 == i)
{
roi.top = y1;
roi.bottom = imgInfo.height;
}
}
if (1 == i)
{
roi.left = x1;
roi.right = imgInfo.width;
}
HGBase_SetImageROI(img, &roi);
HGBase_CopyImage(img, newImg);
HGBase_ResetImageROI(img);
std::vector<std::string> fileNameList = GetFileNameList(devId);
int maxIndex = 0;
for (int i = 0; i < (int)fileNameList.size(); ++i)
{
int index = atoi(fileNameList[i].c_str());
if (index > maxIndex)
maxIndex = index;
}
HGChar name[256];
sprintf(name, "%d.jpg", maxIndex + 1);
std::string imgName = name;
HGBase_CreateDir(filePath.c_str());
std::string fileName = filePath + imgName;
HGImgFmt_SaveJpegImage(newImg, NULL, 0, fileName.c_str());
fileNameList.push_back(imgName);
SaveFileNameList(devId, fileNameList);
std::string imgBase64 = "data:image/jpeg;base64,";
imgBase64 += GetBase64(newImg, 0);
if (0 == i)
{
imgName1 = imgName;
imgBase64_1 = imgBase64;
}
else
{
imgName2 = imgName;
imgBase64_2 = imgBase64;
}
HGBase_DestroyImage(newImg);
}
}
HGBase_DestroyImage(img);
}
return true; return true;
} }
void Manager::GetDevSerialNo(const std::string& devId, std::string& serialNo) bool Manager::GetDevSerialNo(const std::string& devId, std::string& serialNo)
{ {
serialNo = devId;
return true;
} }
void Manager::GetImageBase64(const std::string& devId, const std::string& imgName, std::string& imgBase64) bool Manager::GetImageBase64(const std::string& devId, const std::string& imgName, std::string& imgBase64)
{ {
imgBase64.clear();
std::string filePath = GetFilePath(devId);
std::string fileName = filePath + imgName;
HGImage img = NULL;
HGImgFmt_LoadJpegImage(fileName.c_str(), NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
if (NULL != img)
{
imgBase64 = "data:image/jpeg;base64,";
imgBase64 += GetBase64(img, 0);
HGBase_DestroyImage(img);
}
return true;
} }
std::string Manager::GetFilePath(const std::string& devId) std::string Manager::GetFilePath(const std::string& devId)
...@@ -551,7 +771,11 @@ std::string Manager::GetFilePath(const std::string& devId) ...@@ -551,7 +771,11 @@ std::string Manager::GetFilePath(const std::string& devId)
HGChar docsPath[512]; HGChar docsPath[512];
HGBase_GetDocumentsPath(docsPath, 512); HGBase_GetDocumentsPath(docsPath, 512);
HGChar imgPath[512]; HGChar imgPath[512];
#if defined(HG_CMP_MSC)
sprintf(imgPath, "%sHuaGo/WebService/%s/", docsPath, Utf8ToAnsi(devId.c_str()).c_str());
#else
sprintf(imgPath, "%sHuaGo/WebService/%s/", docsPath, devId.c_str()); sprintf(imgPath, "%sHuaGo/WebService/%s/", docsPath, devId.c_str());
#endif
HGChar stdImgPath[512]; HGChar stdImgPath[512];
HGBase_StandardiseFileName(imgPath, stdImgPath, 512); HGBase_StandardiseFileName(imgPath, stdImgPath, 512);
...@@ -587,6 +811,28 @@ std::vector<std::string> Manager::GetFileNameList(const std::string& devId) ...@@ -587,6 +811,28 @@ std::vector<std::string> Manager::GetFileNameList(const std::string& devId)
return fileNameList; return fileNameList;
} }
bool Manager::SaveFileNameList(const std::string& devId, const std::vector<std::string>& fileNameList)
{
bool ret = false;
std::string filePath = GetFilePath(devId);
std::string cfgName = filePath + "images.txt";
FILE* file = fopen(cfgName.c_str(), "w");
if (NULL != file)
{
for (int i = 0; i < (int)fileNameList.size(); ++i)
{
fwrite(fileNameList[i].c_str(), 1, fileNameList[i].size(), file);
fwrite("\n", 1, strlen("\n"), file);
}
fclose(file);
ret = true;
}
return ret;
}
std::string Manager::GetBase64(HGImage image, HGUInt quality) std::string Manager::GetBase64(HGImage image, HGUInt quality)
{ {
std::string strBase64; std::string strBase64;
...@@ -710,14 +956,147 @@ bool Manager::SaveBase64(const std::string& fileName, const char* base64) ...@@ -710,14 +956,147 @@ bool Manager::SaveBase64(const std::string& fileName, const char* base64)
return ret; return ret;
} }
#if defined(HG_CMP_MSC) && defined(SDK_USE_TWAIN)
void HGAPI Manager::DSEventCallback(HGTwainDS ds, HGUInt event, HGPointer param)
{
}
#else
int Manager::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param) int Manager::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param)
{ {
(void)hdev;
(void)len;
Manager* p = (Manager*)param;
switch (code)
{
case SANE_EVENT_DEVICE_ARRIVED:
{
SANE_Device* sane_dev = (SANE_Device*)data;
HGBase_EnterLock(p->m_lock);
if (p->m_devName.empty())
{
p->m_devName = sane_dev->name;
}
HGBase_LeaveLock(p->m_lock);
}
break;
case SANE_EVENT_DEVICE_LEFT:
{
SANE_Device* sane_dev = (SANE_Device*)data;
HGBase_EnterLock(p->m_lock);
if (p->m_devName == sane_dev->name)
{
p->m_devName.clear();
}
HGBase_LeaveLock(p->m_lock);
}
break;
case SANE_EVENT_STATUS:
{
HGBase_EnterLock(p->m_lock);
if (NULL != p->m_scanEvent)
p->m_scanEvent(SCANEVENT_STATUS, (void*)data, (void*)0, p->m_scanParam);
HGBase_LeaveLock(p->m_lock);
}
break;
case SANE_EVENT_ERROR:
{
HGBase_EnterLock(p->m_lock);
if (NULL != p->m_scanEvent)
p->m_scanEvent(SCANEVENT_ERROR, (void *)data, (void*)0, p->m_scanParam);
HGBase_LeaveLock(p->m_lock);
}
break;
case SANE_EVENT_WORKING:
{
HGBase_EnterLock(p->m_lock);
if (NULL != p->m_scanEvent)
p->m_scanEvent(SCANEVENT_WORKING, (void*)data, (void*)0, p->m_scanParam);
HGBase_LeaveLock(p->m_lock);
}
break;
case SANE_EVENT_IMAGE_OK:
{
SANE_Image* sane_img = (SANE_Image*)data;
HGUInt imgType = 0;
if (sane_img->header.format == SANE_FRAME_GRAY)
imgType = HGBASE_IMGTYPE_GRAY;
else if (sane_img->header.format == SANE_FRAME_RGB)
imgType = HGBASE_IMGTYPE_RGB;
HGByte* data = sane_img->data;
HGImageInfo imgInfo = { (HGUInt)sane_img->header.pixels_per_line, (HGUInt)sane_img->header.lines,
imgType, (HGUInt)sane_img->header.bytes_per_line, HGBASE_IMGORIGIN_TOP };
HGImage img = NULL;
HGBase_CreateImageFromData(data, &imgInfo, nullptr, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
if (NULL != img)
{
HGBase_EnterLock(p->m_lock);
std::string filePath = GetFilePath(p->m_devName);
std::vector<std::string> fileNameList = GetFileNameList(p->m_devName);
int maxIndex = 0;
for (int i = 0; i < (int)fileNameList.size(); ++i)
{
int index = atoi(fileNameList[i].c_str());
if (index > maxIndex)
maxIndex = index;
}
HGChar name[256];
sprintf(name, "%d.jpg", maxIndex + 1);
std::string imgName = name;
HGBase_CreateDir(filePath.c_str());
std::string fileName = filePath + imgName;
HGImgFmt_SaveJpegImage(img, NULL, 0, fileName.c_str());
if (p->m_scanIsInsert)
{
int index = -1;
for (int i = 0; i < (int)fileNameList.size(); ++i)
{
if (fileNameList[i] == p->m_scanInsertImgName)
{
index = i;
break;
}
}
if (-1 != index)
{
fileNameList.insert(fileNameList.begin() + index, imgName);
}
else
{
fileNameList.push_back(imgName);
}
}
else
{
fileNameList.push_back(imgName);
}
SaveFileNameList(p->m_devName, fileNameList);
std::string imgBase64 = "data:image/jpeg;base64,";
imgBase64 += GetBase64(img, 0);
if (NULL != p->m_scanEvent)
p->m_scanEvent(SCANEVENT_IMAGE, (void*)imgName.c_str(), (void *)imgBase64.c_str(), p->m_scanParam);
HGBase_LeaveLock(p->m_lock);
HGBase_DestroyImage(img);
}
}
break;
case SANE_EVENT_SCAN_FINISHED:
{
HGBase_EnterLock(p->m_lock);
if (NULL != p->m_scanEvent)
p->m_scanEvent(SCANEVENT_FINISH, (void*)data, (void*)0, p->m_scanParam);
HGBase_LeaveLock(p->m_lock);
}
break;
}
return 0; return 0;
} }
#endif
\ No newline at end of file
...@@ -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,14 +54,27 @@ void SockIoUser::HandleCmd(const SockIoCmdParam* param) ...@@ -50,14 +54,27 @@ 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();
if (!ret)
{
std::string resp = "42[\"error\", \"stop error\"]";
SendResponse((const HGByte*)resp.c_str(), (HGUInt)resp.size(), HGTRUE); 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()
...@@ -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