实现ftp上传功能
This commit is contained in:
parent
eddab192aa
commit
bfcc042cbe
|
@ -116,15 +116,15 @@
|
|||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;CURL_STATICLIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/sane/;../../../third_party/libzip/windows/include;../../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/libzip/windows/include;../../../third_party/libcurl/windows/include;../../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>../Debug/HGBase.lib;../Debug/HGImgFmt.lib;../../../../sdk/lib/win/x86/Debug/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;../../../../sdk/lib/win/x86/Debug/hgsane.lib;../../../third_party/zlib/windows/lib/x86/zlib.lib;../../../third_party/libzip/windows/lib/x86/zip.lib;../../../third_party/libcurl/windows/lib/x86/libcurld.lib;wldap32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>/ignore:4098,4099,4075 /LTCG %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
|
@ -134,17 +134,17 @@
|
|||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;CURL_STATICLIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/sane/;../../../third_party/libzip/windows/include;../../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/libzip/windows/include;../../../third_party/libcurl/windows/include;../../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>../Release/HGBase.lib;../Release/HGImgFmt.lib;../../../../sdk/lib/win/x86/Release/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;../../../../sdk/lib/win/x86/Release/hgsane.lib;../../../third_party/zlib/windows/lib/x86/zlib.lib;../../../third_party/libzip/windows/lib/x86/zip.lib;../../../third_party/libcurl/windows/lib/x86/libcurl.lib;wldap32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>/ignore:4099 /LTCG %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
|
@ -158,7 +158,7 @@
|
|||
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/sane/;../../../third_party/libzip/windows/include;../../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/libzip/windows/include;../../../third_party/libcurl/windows/include;../../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -176,7 +176,7 @@
|
|||
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_CONSOLE;_WINSOCK_DEPRECATED_NO_WARNINGS;ZIP_STATIC;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/sane/;../../../third_party/libzip/windows/include;../../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../../../third_party/sha1/;../../../third_party/base64/;../../../third_party/json/;../../../third_party/libzip/windows/include;../../../third_party/libcurl/windows/include;../../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
|
@ -8,26 +8,52 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
HGUInt width;
|
||||
HGUInt height;
|
||||
HGUShort bitCount;
|
||||
HGUInt compression;
|
||||
HGUInt width; /* 宽 */
|
||||
HGUInt height; /* 高 */
|
||||
HGUShort bitCount; /* 每像素比特数 */
|
||||
HGUInt compression; /* 压缩方式 */
|
||||
|
||||
HGUInt xPelsPerMeter;
|
||||
HGUInt yPelsPerMeter;
|
||||
HGUInt xPelsPerMeter; /* 水平每米的像素数 */
|
||||
HGUInt yPelsPerMeter; /* 垂直每米的像素数 */
|
||||
}HGBmpLoadInfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
HGUInt xPelsPerMeter;
|
||||
HGUInt yPelsPerMeter;
|
||||
HGUInt xPelsPerMeter; /* 水平每米的像素数 */
|
||||
HGUInt yPelsPerMeter; /* 垂直每米的像素数 */
|
||||
}HGBmpSaveInfo;
|
||||
|
||||
/* 检查文件是否是BMP图像
|
||||
* 参数:
|
||||
* 1) fileName: in, 文件名, windows系统上是GBK编码, linux系统上是UTF8编码
|
||||
* 2) isBmp: out, 是否是BMP图像
|
||||
* 说明:
|
||||
* 1) 该函数会打开文件判断文件头,而不是判断文件名后缀
|
||||
*/
|
||||
HGEXPORT HGResult HGAPI HGImgFmt_CheckBmpFile(const HGChar* fileName, HGBool* isBmp);
|
||||
|
||||
/* 加载BMP图像
|
||||
* 参数:
|
||||
* 1) fileName: in, 文件名, windows系统上是GBK编码, linux系统上是UTF8编码
|
||||
* 2) info: out, BMP图像加载信息, 如果不需要该信息可传NULL
|
||||
* 3) imgType: in, 要生成的图像类型, 参见HGBASE_IMGTYPE_*, 传0表示自动获取
|
||||
* 4) imgOrigin: in, 要生成的图像数据排列方式, 参见HGBASE_IMGORIGIN_*, 传0表示自动获取
|
||||
* 5) image: out, 要生成的图像句柄
|
||||
* 说明:
|
||||
* 1) 生成的图像不使用时需要调用HGBase_DestroyImage销毁
|
||||
*/
|
||||
HGEXPORT HGResult HGAPI HGImgFmt_LoadBmpImage(const HGChar* fileName, HGBmpLoadInfo* info,
|
||||
HGUInt imgType, HGUInt imgOrigin, HGImage* image);
|
||||
|
||||
/* 保存BMP图像
|
||||
* 参数:
|
||||
* 1) image: in, 要保存的图像句柄
|
||||
* 2) info: in, BMP图像保存信息, 如果没有则传NULL
|
||||
* 3) fileName: in, 文件名, windows系统上是GBK编码, linux系统上是UTF8编码
|
||||
* 说明:
|
||||
* 1) 忽略fileName的文件扩展名
|
||||
* 2) 如果info不为NULL, 保存的DPI使用info指定的; 否则使用image自带的
|
||||
*/
|
||||
HGEXPORT HGResult HGAPI HGImgFmt_SaveBmpImage(HGImage image, const HGBmpSaveInfo* info, const HGChar* fileName);
|
||||
|
||||
#endif /* __HGBMP_H__ */
|
|
@ -733,7 +733,7 @@ void HttpUser::ThreadFunc()
|
|||
// 这里跳出,可能是服务器关闭了socketConn,或者客户端关闭了socket,或者网络断开
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -775,7 +775,7 @@ void HttpUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -800,7 +800,7 @@ void HttpUser::ThreadFunc()
|
|||
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_HTTPCMD;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = param;
|
||||
bool b = GetLoop()->Send(&msg);
|
||||
|
@ -827,7 +827,7 @@ void HttpUser::ThreadFunc()
|
|||
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_HTTPCMD;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = param;
|
||||
bool b = GetLoop()->Send(&msg);
|
||||
|
|
|
@ -14,6 +14,7 @@ extern "C"
|
|||
{
|
||||
#include "zip.h"
|
||||
};
|
||||
#include <curl/curl.h>
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -211,6 +212,13 @@ void Manager::CloseDev(const CloseDevParam* param)
|
|||
m_devName.clear();
|
||||
}
|
||||
|
||||
void Manager::ScanFinish()
|
||||
{
|
||||
m_scanInsertImgName.clear();
|
||||
m_scanIsInsert = false;
|
||||
m_scanning = false;
|
||||
}
|
||||
|
||||
void Manager::SetScanEvent(ScanEvent event, void* param)
|
||||
{
|
||||
assert(NULL != event && NULL != param);
|
||||
|
@ -262,10 +270,6 @@ bool Manager::StopScan()
|
|||
{
|
||||
assert(NULL != m_devHandle);
|
||||
sane_cancel(m_devHandle);
|
||||
m_scanning = false;
|
||||
|
||||
m_scanInsertImgName.clear();
|
||||
m_scanIsInsert = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -619,15 +623,8 @@ bool Manager::ExportOfd(const std::string& devId, bool isAuto, std::string& imgB
|
|||
return !imgBase64.empty();
|
||||
}
|
||||
|
||||
bool Manager::ExportOfdFile(const std::string& devId, bool isAuto, HGByte** data, HGUInt* size)
|
||||
bool Manager::ExportOfdFile(const std::string& devId, bool isAuto, const std::string& fileName)
|
||||
{
|
||||
*data = NULL;
|
||||
*size = 0;
|
||||
if (m_scanning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string filePath = GetFilePath(devId);
|
||||
std::vector<std::string> fileNameList = GetFileNameList(devId);
|
||||
if (fileNameList.empty())
|
||||
|
@ -635,11 +632,8 @@ bool Manager::ExportOfdFile(const std::string& devId, bool isAuto, HGByte** data
|
|||
return false;
|
||||
}
|
||||
|
||||
HGChar tmpFileName[512];
|
||||
HGBase_GetTmpFileName(tmpFileName, 512);
|
||||
|
||||
HGOfdImageWriter writer = NULL;
|
||||
HGImgFmt_OpenOfdImageWriter(tmpFileName, &writer);
|
||||
HGImgFmt_OpenOfdImageWriter(fileName.c_str(), &writer);
|
||||
if (NULL == writer)
|
||||
{
|
||||
return false;
|
||||
|
@ -663,10 +657,26 @@ bool Manager::ExportOfdFile(const std::string& devId, bool isAuto, HGByte** data
|
|||
|
||||
if (!ret)
|
||||
{
|
||||
HGBase_DeleteFile(tmpFileName);
|
||||
HGBase_DeleteFile(fileName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Manager::ExportOfdFile(const std::string& devId, bool isAuto, HGByte** data, HGUInt* size)
|
||||
{
|
||||
*data = NULL;
|
||||
*size = 0;
|
||||
if (m_scanning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
HGChar tmpFileName[512];
|
||||
HGBase_GetTmpFileName(tmpFileName, 512);
|
||||
ExportOfdFile(devId, isAuto, tmpFileName);
|
||||
|
||||
*data = GetBuffer(tmpFileName, size);
|
||||
HGBase_DeleteFile(tmpFileName);
|
||||
return (NULL != *data);
|
||||
|
@ -692,15 +702,8 @@ bool Manager::ExportPdf(const std::string& devId, std::string& imgBase64)
|
|||
return !imgBase64.empty();
|
||||
}
|
||||
|
||||
bool Manager::ExportPdfFile(const std::string& devId, HGByte** data, HGUInt* size)
|
||||
bool Manager::ExportPdfFile(const std::string& devId, const std::string& fileName)
|
||||
{
|
||||
*data = NULL;
|
||||
*size = 0;
|
||||
if (m_scanning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string filePath = GetFilePath(devId);
|
||||
std::vector<std::string> fileNameList = GetFileNameList(devId);
|
||||
if (fileNameList.empty())
|
||||
|
@ -708,11 +711,8 @@ bool Manager::ExportPdfFile(const std::string& devId, HGByte** data, HGUInt* siz
|
|||
return false;
|
||||
}
|
||||
|
||||
HGChar tmpFileName[512];
|
||||
HGBase_GetTmpFileName(tmpFileName, 512);
|
||||
|
||||
HGPdfImageWriter writer = NULL;
|
||||
HGImgFmt_OpenPdfImageWriter(tmpFileName, &writer);
|
||||
HGImgFmt_OpenPdfImageWriter(fileName.c_str(), &writer);
|
||||
if (NULL == writer)
|
||||
{
|
||||
return false;
|
||||
|
@ -736,10 +736,26 @@ bool Manager::ExportPdfFile(const std::string& devId, HGByte** data, HGUInt* siz
|
|||
|
||||
if (!ret)
|
||||
{
|
||||
HGBase_DeleteFile(tmpFileName);
|
||||
HGBase_DeleteFile(fileName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Manager::ExportPdfFile(const std::string& devId, HGByte** data, HGUInt* size)
|
||||
{
|
||||
*data = NULL;
|
||||
*size = 0;
|
||||
if (m_scanning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
HGChar tmpFileName[512];
|
||||
HGBase_GetTmpFileName(tmpFileName, 512);
|
||||
ExportPdfFile(devId, tmpFileName);
|
||||
|
||||
*data = GetBuffer(tmpFileName, size);
|
||||
HGBase_DeleteFile(tmpFileName);
|
||||
return (NULL != *data);
|
||||
|
@ -765,15 +781,8 @@ bool Manager::ExportTiff(const std::string& devId, std::string& imgBase64)
|
|||
return !imgBase64.empty();
|
||||
}
|
||||
|
||||
bool Manager::ExportTiffFile(const std::string& devId, HGByte** data, HGUInt* size)
|
||||
bool Manager::ExportTiff(const std::string& devId, const std::string& fileName)
|
||||
{
|
||||
*data = NULL;
|
||||
*size = 0;
|
||||
if (m_scanning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string filePath = GetFilePath(devId);
|
||||
std::vector<std::string> fileNameList = GetFileNameList(devId);
|
||||
if (fileNameList.empty())
|
||||
|
@ -781,11 +790,8 @@ bool Manager::ExportTiffFile(const std::string& devId, HGByte** data, HGUInt* si
|
|||
return false;
|
||||
}
|
||||
|
||||
HGChar tmpFileName[512];
|
||||
HGBase_GetTmpFileName(tmpFileName, 512);
|
||||
|
||||
HGTiffWriter writer = NULL;
|
||||
HGImgFmt_OpenTiffWriter(tmpFileName, &writer);
|
||||
HGImgFmt_OpenTiffWriter(fileName.c_str(), &writer);
|
||||
if (NULL == writer)
|
||||
{
|
||||
return false;
|
||||
|
@ -809,10 +815,26 @@ bool Manager::ExportTiffFile(const std::string& devId, HGByte** data, HGUInt* si
|
|||
|
||||
if (!ret)
|
||||
{
|
||||
HGBase_DeleteFile(tmpFileName);
|
||||
HGBase_DeleteFile(fileName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Manager::ExportTiffFile(const std::string& devId, HGByte** data, HGUInt* size)
|
||||
{
|
||||
*data = NULL;
|
||||
*size = 0;
|
||||
if (m_scanning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
HGChar tmpFileName[512];
|
||||
HGBase_GetTmpFileName(tmpFileName, 512);
|
||||
ExportTiff(devId, tmpFileName);
|
||||
|
||||
*data = GetBuffer(tmpFileName, size);
|
||||
HGBase_DeleteFile(tmpFileName);
|
||||
return (NULL != *data);
|
||||
|
@ -838,15 +860,8 @@ bool Manager::ExportZip(const std::string& devId, std::string& imgBase64)
|
|||
return !imgBase64.empty();
|
||||
}
|
||||
|
||||
bool Manager::ExportZipFile(const std::string& devId, HGByte** data, HGUInt* size)
|
||||
bool Manager::ExportZipFile(const std::string& devId, const std::string& fileName)
|
||||
{
|
||||
*data = NULL;
|
||||
*size = 0;
|
||||
if (m_scanning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string filePath = GetFilePath(devId);
|
||||
std::vector<std::string> fileNameList = GetFileNameList(devId);
|
||||
if (fileNameList.empty())
|
||||
|
@ -854,11 +869,8 @@ bool Manager::ExportZipFile(const std::string& devId, HGByte** data, HGUInt* siz
|
|||
return false;
|
||||
}
|
||||
|
||||
HGChar tmpFileName[512];
|
||||
HGBase_GetTmpFileName(tmpFileName, 512);
|
||||
|
||||
int error = 0;
|
||||
zip* z = zip_open(StdStringToUtf8(tmpFileName).c_str(), ZIP_CREATE | ZIP_TRUNCATE, &error);
|
||||
zip* z = zip_open(StdStringToUtf8(fileName.c_str()).c_str(), ZIP_CREATE | ZIP_TRUNCATE, &error);
|
||||
if (NULL == z)
|
||||
{
|
||||
return false;
|
||||
|
@ -887,10 +899,26 @@ bool Manager::ExportZipFile(const std::string& devId, HGByte** data, HGUInt* siz
|
|||
|
||||
if (!ret)
|
||||
{
|
||||
HGBase_DeleteFile(tmpFileName);
|
||||
HGBase_DeleteFile(fileName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Manager::ExportZipFile(const std::string& devId, HGByte** data, HGUInt* size)
|
||||
{
|
||||
*data = NULL;
|
||||
*size = 0;
|
||||
if (m_scanning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
HGChar tmpFileName[512];
|
||||
HGBase_GetTmpFileName(tmpFileName, 512);
|
||||
ExportZipFile(devId, tmpFileName);
|
||||
|
||||
*data = GetBuffer(tmpFileName, size);
|
||||
HGBase_DeleteFile(tmpFileName);
|
||||
return (NULL != *data);
|
||||
|
@ -903,8 +931,32 @@ bool Manager::UploadImage(const UploadParam& uploadParam)
|
|||
return false;
|
||||
}
|
||||
|
||||
// 打包并上传
|
||||
return true;
|
||||
std::string devId;
|
||||
GetCurDevId(devId);
|
||||
|
||||
HGChar tmpFileName[512];
|
||||
HGBase_GetTmpFileName(tmpFileName, 512);
|
||||
if (0 == uploadParam.format)
|
||||
ExportOfdFile(devId, true, tmpFileName);
|
||||
else if (1 == uploadParam.format)
|
||||
ExportPdfFile(devId, tmpFileName);
|
||||
else
|
||||
ExportZipFile(devId, tmpFileName);
|
||||
|
||||
bool ret = false;
|
||||
if (0 == uploadParam.uploadMode) // HTTP
|
||||
{
|
||||
ret = HTTPUpload(tmpFileName, uploadParam.httpUrl, uploadParam.fileName, uploadParam.httpMethod,
|
||||
uploadParam.header, uploadParam.param);
|
||||
}
|
||||
else if (1 == uploadParam.uploadMode) // FTP
|
||||
{
|
||||
ret = FTPUpload(tmpFileName, uploadParam.ftpUrl, uploadParam.ftpPort, uploadParam.ftpPath,
|
||||
uploadParam.ftpUser, uploadParam.ftpPassword, uploadParam.ftpMode);
|
||||
}
|
||||
|
||||
HGBase_DeleteFile(tmpFileName);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Manager::SaveImage(const std::string& devId, const std::string& imgName, const std::string& imgBase64)
|
||||
|
@ -1502,6 +1554,102 @@ bool Manager::SaveBase64(const std::string& fileName, const char* base64)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool Manager::HTTPUpload(const std::string& localFileName, const std::string& httpUrl, const std::string& remoteFileName,
|
||||
const std::string& httpMethod, const std::string& header, const std::string& param)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static size_t read_callback(char* ptr, size_t size, size_t nmemb, void* stream)
|
||||
{
|
||||
unsigned long nread;
|
||||
/* in real-world cases, this would probably get this data differently
|
||||
as this fread() stuff is exactly what the library already would do
|
||||
by default internally */
|
||||
size_t retcode = fread(ptr, size, nmemb, (FILE*)stream);
|
||||
|
||||
if (retcode > 0)
|
||||
{
|
||||
nread = (unsigned long)retcode;
|
||||
fprintf(stderr, "*** We read %lu bytes from file\n", nread);
|
||||
}
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
bool Manager::FTPUpload(const std::string& localFileName, const std::string& ftpUrl, int ftpPort, const std::string& ftpPath,
|
||||
const std::string& ftpUser, const std::string& ftpPassword, int ftpMode)
|
||||
{
|
||||
FILE* file = fopen(localFileName.c_str(), "rb");
|
||||
if (NULL == file)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
long fsize = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
/* get a curl handle */
|
||||
CURL *curl = curl_easy_init();
|
||||
if (curl)
|
||||
{
|
||||
char tmpName[256];
|
||||
HGBase_GetUuid(tmpName, 256);
|
||||
char remoteName[256];
|
||||
HGBase_GetFileName(localFileName.c_str(), remoteName, 256);
|
||||
|
||||
char ftp_rnfr[256];
|
||||
sprintf(ftp_rnfr, "RNFR %s", tmpName);
|
||||
char ftp_rnto[256];
|
||||
sprintf(ftp_rnto, "RNTO %s", remoteName);
|
||||
|
||||
struct curl_slist* headerlist = NULL;
|
||||
headerlist = curl_slist_append(headerlist, ftp_rnfr);
|
||||
headerlist = curl_slist_append(headerlist, ftp_rnto);
|
||||
|
||||
/* we want to use our own read function */
|
||||
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
||||
|
||||
char url[512];
|
||||
sprintf(url, "ftp://%s:%s@%s:%d/%s/%s", ftpUser.c_str(), ftpPassword.c_str(),
|
||||
ftpUrl.c_str(), ftpPort, ftpPath.c_str(), tmpName);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
|
||||
/* pass in that last of FTP commands to run after the transfer */
|
||||
curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
|
||||
|
||||
/* now specify which file to upload */
|
||||
curl_easy_setopt(curl, CURLOPT_READDATA, file);
|
||||
|
||||
/* Set the size of the file to upload (optional). If you give a *_LARGE
|
||||
option you MUST make sure that the type of the passed-in argument is a
|
||||
curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
|
||||
make sure that to pass in a type 'long' argument. */
|
||||
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
|
||||
|
||||
/* Now run off and do what you have been told! */
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
/* Check for errors */
|
||||
if (res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||
|
||||
/* clean up the FTP commands list */
|
||||
curl_slist_free_all(headerlist);
|
||||
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
fclose(file); /* close the local file */
|
||||
|
||||
curl_global_cleanup();
|
||||
return true;
|
||||
}
|
||||
|
||||
int Manager::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param)
|
||||
{
|
||||
(void)hdev;
|
||||
|
@ -1525,7 +1673,7 @@ int Manager::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned i
|
|||
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_OPENDEV;
|
||||
msg.svrId = 0;
|
||||
msg.svrType = 0;
|
||||
msg.usrId = 0;
|
||||
msg.param = openDevParam;
|
||||
bool b = p->m_loop->Send(&msg);
|
||||
|
@ -1550,7 +1698,7 @@ int Manager::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned i
|
|||
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_CLOSEDEV;
|
||||
msg.svrId = 0;
|
||||
msg.svrType = 0;
|
||||
msg.usrId = 0;
|
||||
msg.param = closeDevParam;
|
||||
bool b = p->m_loop->Send(&msg);
|
||||
|
@ -1629,6 +1777,17 @@ int Manager::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned i
|
|||
std::string fileName = filePath + imgName;
|
||||
HGImgFmt_SaveImage(img, 0, NULL, 0, fileName.c_str());
|
||||
|
||||
if (0 == p->m_devParam.uploadMode) // HTTP
|
||||
{
|
||||
HTTPUpload(fileName, p->m_devParam.httpUrl, p->m_devParam.fileName, p->m_devParam.httpMethod,
|
||||
p->m_devParam.header, p->m_devParam.param);
|
||||
}
|
||||
else if (1 == p->m_devParam.uploadMode) // FTP
|
||||
{
|
||||
FTPUpload(fileName, p->m_devParam.ftpUrl, p->m_devParam.ftpPort, p->m_devParam.ftpPath,
|
||||
p->m_devParam.ftpUser, p->m_devParam.ftpPassword, p->m_devParam.ftpMode);
|
||||
}
|
||||
|
||||
if (p->m_scanIsInsert)
|
||||
{
|
||||
int index = -1;
|
||||
|
@ -1679,8 +1838,8 @@ int Manager::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned i
|
|||
HGBase_LeaveLock(p->m_lock);
|
||||
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_STOPSCAN;
|
||||
msg.svrId = 0;
|
||||
msg.msgId = WEB_MSGID_SCANFINISH;
|
||||
msg.svrType = 0;
|
||||
msg.usrId = 0;
|
||||
msg.param = NULL;
|
||||
p->m_loop->Send(&msg);
|
||||
|
|
|
@ -92,6 +92,8 @@ public:
|
|||
void OpenDev(const OpenDevParam *param);
|
||||
// 关闭设备
|
||||
void CloseDev(const CloseDevParam* param);
|
||||
// 扫描完成
|
||||
void ScanFinish();
|
||||
|
||||
// 设置回调
|
||||
void SetScanEvent(ScanEvent event, void* param);
|
||||
|
@ -114,15 +116,19 @@ public:
|
|||
bool SetDevParam(const std::string& devId, const DevParam& devParam);
|
||||
// 生成OFD
|
||||
bool ExportOfd(const std::string& devId, bool isAuto, std::string &imgBase64);
|
||||
bool ExportOfdFile(const std::string& devId, bool isAuto, const std::string &fileName);
|
||||
bool ExportOfdFile(const std::string& devId, bool isAuto, HGByte **data, HGUInt *size);
|
||||
// 生成PDF
|
||||
bool ExportPdf(const std::string& devId, std::string& imgBase64);
|
||||
bool ExportPdfFile(const std::string& devId, const std::string& fileName);
|
||||
bool ExportPdfFile(const std::string& devId, HGByte** data, HGUInt* size);
|
||||
// 生成TIFF
|
||||
bool ExportTiff(const std::string& devId, std::string& imgBase64);
|
||||
bool ExportTiff(const std::string& devId, const std::string& fileName);
|
||||
bool ExportTiffFile(const std::string& devId, HGByte** data, HGUInt* size);
|
||||
// 生成ZIP
|
||||
bool ExportZip(const std::string& devId, std::string& imgBase64);
|
||||
bool ExportZipFile(const std::string& devId, const std::string& fileName);
|
||||
bool ExportZipFile(const std::string& devId, HGByte** data, HGUInt* size);
|
||||
// 上传图像
|
||||
bool UploadImage(const UploadParam& uploadParam);
|
||||
|
@ -161,6 +167,10 @@ private:
|
|||
static std::string GetBase64(const std::string& fileName);
|
||||
static HGByte* GetBuffer(const std::string& fileName, HGUInt *size);
|
||||
static bool SaveBase64(const std::string& fileName, const char *base64);
|
||||
static bool HTTPUpload(const std::string& localFileName, const std::string& httpUrl, const std::string& remoteFileName,
|
||||
const std::string &httpMethod, const std::string& header, const std::string& param);
|
||||
static bool FTPUpload(const std::string& localFileName, const std::string& ftpUrl, int ftpPort, const std::string& ftpPath,
|
||||
const std::string& ftpUser, const std::string& ftpPassword, int ftpMode);
|
||||
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param);
|
||||
|
||||
private:
|
||||
|
|
|
@ -6,22 +6,44 @@ MsgLoop::MsgLoop()
|
|||
HGBase_CreateLock(&m_msgLock);
|
||||
m_bRecvMsg = HGTRUE;
|
||||
|
||||
m_manager = new Manager(this);
|
||||
m_wsServer = new WebServer(this, ServerType_Ws, 1);
|
||||
m_httpServer = new WebServer(this, ServerType_Http, 2);
|
||||
m_sockIoServer = new WebServer(this, ServerType_SockIo, 3);
|
||||
if (1) // 使用旧协议
|
||||
{
|
||||
m_manager = new Manager(this);
|
||||
m_httpServer = new WebServer(this, ServerType_Http);
|
||||
m_sockIoServer = new WebServer(this, ServerType_SockIo);
|
||||
m_wsServer = NULL;
|
||||
}
|
||||
else // 使用新协议
|
||||
{
|
||||
m_manager = NULL;
|
||||
m_httpServer = NULL;
|
||||
m_sockIoServer = NULL;
|
||||
m_wsServer = new WebServer(this, ServerType_Ws);
|
||||
}
|
||||
}
|
||||
|
||||
MsgLoop::~MsgLoop()
|
||||
{
|
||||
delete m_sockIoServer;
|
||||
m_sockIoServer = NULL;
|
||||
delete m_httpServer;
|
||||
m_httpServer = NULL;
|
||||
delete m_wsServer;
|
||||
m_wsServer = NULL;
|
||||
delete m_manager;
|
||||
m_manager = NULL;
|
||||
if (NULL != m_wsServer)
|
||||
{
|
||||
delete m_wsServer;
|
||||
m_wsServer = NULL;
|
||||
}
|
||||
if (NULL != m_sockIoServer)
|
||||
{
|
||||
delete m_sockIoServer;
|
||||
m_sockIoServer = NULL;
|
||||
}
|
||||
if (NULL != m_httpServer)
|
||||
{
|
||||
delete m_httpServer;
|
||||
m_httpServer = NULL;
|
||||
}
|
||||
if (NULL != m_manager)
|
||||
{
|
||||
delete m_manager;
|
||||
m_manager = NULL;
|
||||
}
|
||||
|
||||
HGBase_DestroyLock(m_msgLock);
|
||||
m_msgLock = NULL;
|
||||
|
@ -54,9 +76,12 @@ bool MsgLoop::Send(const WebMsg* msg)
|
|||
|
||||
void MsgLoop::Loop()
|
||||
{
|
||||
m_wsServer->Open(38999);
|
||||
m_httpServer->Open(18999);
|
||||
m_sockIoServer->Open(28999);
|
||||
if (NULL != m_httpServer)
|
||||
m_httpServer->Open(18999);
|
||||
if (NULL != m_sockIoServer)
|
||||
m_sockIoServer->Open(28999);
|
||||
if (NULL != m_wsServer)
|
||||
m_wsServer->Open(38999);
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -73,46 +98,56 @@ void MsgLoop::Loop()
|
|||
|
||||
if (0 != msg.msgId)
|
||||
{
|
||||
if (0 == msg.svrId)
|
||||
if (0 == msg.svrType)
|
||||
{
|
||||
assert(0 == msg.usrId);
|
||||
if (WEB_MSGID_QUIT == msg.msgId)
|
||||
{
|
||||
assert(NULL == msg.param);
|
||||
m_wsServer->Close();
|
||||
m_httpServer->Close();
|
||||
m_sockIoServer->Close();
|
||||
|
||||
if (NULL != m_wsServer)
|
||||
m_wsServer->Close();
|
||||
if (NULL != m_sockIoServer)
|
||||
m_sockIoServer->Close();
|
||||
if (NULL != m_httpServer)
|
||||
m_httpServer->Close();
|
||||
}
|
||||
else if (WEB_MSGID_OPENDEV == msg.msgId)
|
||||
{
|
||||
assert(NULL != msg.param);
|
||||
OpenDevParam* param = (OpenDevParam*)msg.param;
|
||||
m_manager->OpenDev(param);
|
||||
if (NULL != m_manager)
|
||||
m_manager->OpenDev(param);
|
||||
delete param;
|
||||
}
|
||||
else if (WEB_MSGID_CLOSEDEV == msg.msgId)
|
||||
{
|
||||
assert(NULL != msg.param);
|
||||
CloseDevParam* param = (CloseDevParam*)msg.param;
|
||||
m_manager->CloseDev(param);
|
||||
if (NULL != m_manager)
|
||||
m_manager->CloseDev(param);
|
||||
delete param;
|
||||
}
|
||||
else if (WEB_MSGID_STOPSCAN == msg.msgId)
|
||||
else if (WEB_MSGID_SCANFINISH == msg.msgId)
|
||||
{
|
||||
assert(NULL == msg.param);
|
||||
m_manager->StopScan();
|
||||
if (NULL != m_manager)
|
||||
m_manager->ScanFinish();
|
||||
}
|
||||
}
|
||||
else if (1 == msg.svrId)
|
||||
else if (ServerType_Ws == msg.svrType)
|
||||
{
|
||||
assert(NULL != m_wsServer);
|
||||
m_wsServer->HandleMsg(&msg);
|
||||
}
|
||||
else if (2 == msg.svrId)
|
||||
else if (ServerType_Http == msg.svrType)
|
||||
{
|
||||
assert(NULL != m_httpServer);
|
||||
m_httpServer->HandleMsg(&msg);
|
||||
}
|
||||
else if (3 == msg.svrId)
|
||||
else if (ServerType_SockIo == msg.svrType)
|
||||
{
|
||||
assert(NULL != m_sockIoServer);
|
||||
m_sockIoServer->HandleMsg(&msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@ private:
|
|||
std::list<WebMsg> m_listMsg;
|
||||
|
||||
Manager *m_manager;
|
||||
WebServer *m_wsServer;
|
||||
WebServer *m_httpServer;
|
||||
WebServer *m_sockIoServer;
|
||||
WebServer* m_wsServer;
|
||||
};
|
||||
|
||||
#endif /* __MSGLOOP_H__ */
|
||||
|
|
|
@ -109,7 +109,7 @@ void SockIoUser::ThreadFunc()
|
|||
// 这里跳出,可能是服务器关闭了socketConn,或者客户端关闭了socket,或者网络断开
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -154,7 +154,7 @@ void SockIoUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -182,7 +182,7 @@ void SockIoUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -214,7 +214,7 @@ void SockIoUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -227,7 +227,7 @@ void SockIoUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -240,7 +240,7 @@ void SockIoUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -253,7 +253,7 @@ void SockIoUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -271,7 +271,7 @@ void SockIoUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -306,7 +306,7 @@ void SockIoUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -345,7 +345,7 @@ void SockIoUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -411,7 +411,7 @@ void SockIoUser::ThreadFunc()
|
|||
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_SOCKIOCMD;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = param;
|
||||
bool b = GetLoop()->Send(&msg);
|
||||
|
@ -487,7 +487,7 @@ void SockIoUser::ScanCallback(HGUInt event, void* value1, void* value2, void* pa
|
|||
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_SOCKIORET;
|
||||
msg.svrId = p->m_server->GetId();
|
||||
msg.svrType = p->m_server->GetType();
|
||||
msg.usrId = p->m_id;
|
||||
msg.param = param;
|
||||
bool b = p->GetLoop()->Send(&msg);
|
||||
|
|
|
@ -6,24 +6,24 @@
|
|||
#include "HttpHead.h"
|
||||
#include <string>
|
||||
|
||||
#define WEB_MSGID_QUIT 1
|
||||
#define WEB_MSGID_CONNET 2
|
||||
#define WEB_MSGID_DISCONNET 3
|
||||
#define WEB_MSGID_WSCMD 4
|
||||
#define WEB_MSGID_HTTPCMD 5
|
||||
#define WEB_MSGID_SOCKIOCMD 6
|
||||
#define WEB_MSGID_WSRET 7
|
||||
#define WEB_MSGID_HTTPRET 8
|
||||
#define WEB_MSGID_SOCKIORET 9
|
||||
#define WEB_MSGID_OPENDEV 10
|
||||
#define WEB_MSGID_CLOSEDEV 11
|
||||
#define WEB_MSGID_STOPSCAN 12
|
||||
#define WEB_MSGID_QUIT 1
|
||||
#define WEB_MSGID_CONNET 2
|
||||
#define WEB_MSGID_DISCONNET 3
|
||||
#define WEB_MSGID_WSCMD 4
|
||||
#define WEB_MSGID_HTTPCMD 5
|
||||
#define WEB_MSGID_SOCKIOCMD 6
|
||||
#define WEB_MSGID_WSRET 7
|
||||
#define WEB_MSGID_HTTPRET 8
|
||||
#define WEB_MSGID_SOCKIORET 9
|
||||
#define WEB_MSGID_OPENDEV 10
|
||||
#define WEB_MSGID_CLOSEDEV 11
|
||||
#define WEB_MSGID_SCANFINISH 12
|
||||
|
||||
struct WebMsg
|
||||
{
|
||||
HGUInt msgId; /* WEB_MSGID_** */
|
||||
HGUInt svrId; /* serverId */
|
||||
HGUInt usrId; /* userId */
|
||||
HGUInt svrType; /* svrType */
|
||||
HGUInt usrId; /* usrId */
|
||||
HGPointer param; /* param */
|
||||
};
|
||||
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
#include "SockIoUser.h"
|
||||
#include "../../base/HGInfo.h"
|
||||
|
||||
WebServer::WebServer(class MsgLoop* loop, HGUInt type, HGUInt id)
|
||||
WebServer::WebServer(class MsgLoop* loop, HGUInt type)
|
||||
{
|
||||
m_loop = loop;
|
||||
m_type = type;
|
||||
m_id = id;
|
||||
|
||||
m_currUserId = 1;
|
||||
#if defined(HG_CMP_MSC)
|
||||
|
@ -35,11 +34,6 @@ HGUInt WebServer::GetType()
|
|||
return m_type;
|
||||
}
|
||||
|
||||
HGUInt WebServer::GetId()
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
bool WebServer::Open(HGUShort port)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
|
@ -140,7 +134,7 @@ bool WebServer::Close()
|
|||
void WebServer::HandleMsg(const WebMsg* msg)
|
||||
{
|
||||
assert(NULL != msg);
|
||||
assert(msg->svrId == m_id);
|
||||
assert(msg->svrType == m_type);
|
||||
|
||||
if (WEB_MSGID_CONNET == msg->msgId)
|
||||
{
|
||||
|
@ -291,7 +285,7 @@ void WebServer::ThreadFunc(HGThread thread, HGPointer param)
|
|||
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_CONNET;
|
||||
msg.svrId = p->m_id;
|
||||
msg.svrType = p->m_type;
|
||||
msg.usrId = 0;
|
||||
msg.param = param;
|
||||
bool b = p->m_loop->Send(&msg);
|
||||
|
|
|
@ -14,12 +14,11 @@
|
|||
class WebServer
|
||||
{
|
||||
public:
|
||||
WebServer(class MsgLoop *loop, HGUInt type, HGUInt id);
|
||||
WebServer(class MsgLoop *loop, HGUInt type);
|
||||
~WebServer();
|
||||
|
||||
class MsgLoop* GetLoop();
|
||||
HGUInt GetType();
|
||||
HGUInt GetId();
|
||||
|
||||
bool Open(HGUShort port);
|
||||
bool Close();
|
||||
|
@ -32,7 +31,6 @@ private:
|
|||
private:
|
||||
class MsgLoop* m_loop;
|
||||
HGUInt m_type;
|
||||
HGUInt m_id;
|
||||
|
||||
HGUInt m_currUserId;
|
||||
#if defined(HG_CMP_MSC)
|
||||
|
|
|
@ -62,7 +62,7 @@ void WsUser::ThreadFunc()
|
|||
// 这里跳出,可能是服务器关闭了socketConn,或者客户端关闭了socket,或者网络断开
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -107,7 +107,7 @@ void WsUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -135,7 +135,7 @@ void WsUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -167,7 +167,7 @@ void WsUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -180,7 +180,7 @@ void WsUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -193,7 +193,7 @@ void WsUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -206,7 +206,7 @@ void WsUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -224,7 +224,7 @@ void WsUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -259,7 +259,7 @@ void WsUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -298,7 +298,7 @@ void WsUser::ThreadFunc()
|
|||
{
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_DISCONNET;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = NULL;
|
||||
GetLoop()->Send(&msg);
|
||||
|
@ -356,7 +356,7 @@ void WsUser::ThreadFunc()
|
|||
|
||||
WebMsg msg;
|
||||
msg.msgId = WEB_MSGID_WSCMD;
|
||||
msg.svrId = m_server->GetId();
|
||||
msg.svrType = m_server->GetType();
|
||||
msg.usrId = m_id;
|
||||
msg.param = param;
|
||||
bool b = GetLoop()->Send(&msg);
|
||||
|
|
Loading…
Reference in New Issue