HGGitLab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
app
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
luoliangyi
app
Commits
61670965
Commit
61670965
authored
Apr 19, 2022
by
luoliangyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1)websdk:增加图像合成和拆分功能
2)websdk:实现图像采集功能
parent
528f5ea8
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
797 additions
and
383 deletions
+797
-383
build/windows/HGWebService/HGWebService.vcxproj
build/windows/HGWebService/HGWebService.vcxproj
+4
-4
sdk/webservice/HttpUser.cpp
sdk/webservice/HttpUser.cpp
+118
-195
sdk/webservice/Manager.cpp
sdk/webservice/Manager.cpp
+532
-153
sdk/webservice/Manager.h
sdk/webservice/Manager.h
+43
-27
sdk/webservice/SockIoUser.cpp
sdk/webservice/SockIoUser.cpp
+72
-4
sdk/webservice/SockIoUser.h
sdk/webservice/SockIoUser.h
+2
-0
sdk/webservice/WebMsg.h
sdk/webservice/WebMsg.h
+9
-0
sdk/webservice/WebServer.cpp
sdk/webservice/WebServer.cpp
+17
-0
No files found.
build/windows/HGWebService/HGWebService.vcxproj
View file @
61670965
...
...
@@ -120,7 +120,7 @@
<Link>
<SubSystem>
Console
</SubSystem>
<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>
</Link>
</ItemDefinitionGroup>
...
...
@@ -140,7 +140,7 @@
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
<OptimizeReferences>
true
</OptimizeReferences>
<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>
</Link>
<PostBuildEvent>
...
...
@@ -159,7 +159,7 @@
<Link>
<SubSystem>
Console
</SubSystem>
<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>
</Link>
</ItemDefinitionGroup>
...
...
@@ -179,7 +179,7 @@
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
<OptimizeReferences>
true
</OptimizeReferences>
<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>
</Link>
<PostBuildEvent>
...
...
sdk/webservice/HttpUser.cpp
View file @
61670965
This diff is collapsed.
Click to expand it.
sdk/webservice/Manager.cpp
View file @
61670965
This diff is collapsed.
Click to expand it.
sdk/webservice/Manager.h
View file @
61670965
...
...
@@ -3,15 +3,30 @@
#include "../../base/HGDef.h"
#include "../../base/HGInc.h"
#include "../../base/HGLock.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"
#endif
#include <vector>
#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
{
public:
...
...
@@ -19,20 +34,20 @@ public:
~
Manager
();
// 扫描
void
Scan
(
);
bool
Scan
(
const
std
::
string
&
insertImgName
,
bool
isInsert
,
ScanEvent
event
,
void
*
param
);
// 停止扫描
void
StopScan
();
bool
StopScan
();
// 获取当前连接的设备ID
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
bool
ExportOfdFile
(
HGByte
**
data
,
HGUInt
*
size
);
// 生成PDF
...
...
@@ -42,7 +57,7 @@ public:
// 生成ZIP
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
);
// 删除图片
...
...
@@ -50,9 +65,11 @@ public:
// 删除所有图片
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
);
// 获取最后批次
...
...
@@ -60,32 +77,31 @@ public:
// 重置索引
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
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:
static
std
::
string
GetFilePath
(
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
(
const
std
::
string
&
fileName
);
static
HGByte
*
GetBuffer
(
const
std
::
string
&
fileName
,
HGUInt
*
size
);
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
);
#endif
private:
#if defined(HG_CMP_MSC) && defined(SDK_USE_TWAIN)
HGTwainDSM
m_twainDSM
;
HGTwainDS
m_twainDS
;
#else
SANE_Handle
m_saneDeviceHandle
;
#endif
HGLock
m_lock
;
std
::
string
m_devName
;
SANE_Handle
m_devHandle
;
std
::
string
m_scanInsertImgName
;
bool
m_scanIsInsert
;
ScanEvent
m_scanEvent
;
void
*
m_scanParam
;
};
#endif
/* __MANAGER_H__ */
sdk/webservice/SockIoUser.cpp
View file @
61670965
...
...
@@ -29,6 +29,10 @@ void SockIoUser::HandleCmd(const SockIoCmdParam* param)
std
::
string
user
;
std
::
string
data
;
GetMsgInfo
(
param
,
user
,
data
);
if
(
user
.
empty
())
{
return
;
}
if
(
"scan"
==
user
)
{
...
...
@@ -50,16 +54,29 @@ void SockIoUser::HandleCmd(const SockIoCmdParam* param)
cJSON_Delete
(
json
);
}
std
::
string
resp
=
"42[
\"
error
\"
,
\"
device error
\"
]"
;
SendResponse
((
const
HGByte
*
)
resp
.
c_str
(),
(
HGUInt
)
resp
.
size
(),
HGTRUE
);
bool
ret
=
g_manager
->
Scan
(
imgName
,
insert
,
ScanCallback
,
this
);
if
(
!
ret
)
{
std
::
string
resp
=
"42[
\"
error
\"
,
\"
scan error
\"
]"
;
SendResponse
((
const
HGByte
*
)
resp
.
c_str
(),
(
HGUInt
)
resp
.
size
(),
HGTRUE
);
}
}
else
if
(
"stop"
==
user
)
{
std
::
string
resp
=
"42[
\"
error
\"
,
\"
device error
\"
]"
;
SendResponse
((
const
HGByte
*
)
resp
.
c_str
(),
(
HGUInt
)
resp
.
size
(),
HGTRUE
);
bool
ret
=
g_manager
->
StopScan
();
if
(
!
ret
)
{
std
::
string
resp
=
"42[
\"
error
\"
,
\"
stop error
\"
]"
;
SendResponse
((
const
HGByte
*
)
resp
.
c_str
(),
(
HGUInt
)
resp
.
size
(),
HGTRUE
);
}
}
}
void
SockIoUser
::
HandleRet
(
const
SockIoRetParam
*
param
)
{
SendResponse
(
param
->
data
,
param
->
size
,
HGTRUE
);
}
void
SockIoUser
::
ThreadFunc
()
{
char
chBuffer
[
2048
];
...
...
@@ -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
=
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
)
{
user
.
clear
();
...
...
sdk/webservice/SockIoUser.h
View file @
61670965
...
...
@@ -15,11 +15,13 @@ public:
virtual
~
SockIoUser
();
void
HandleCmd
(
const
SockIoCmdParam
*
param
);
void
HandleRet
(
const
SockIoRetParam
*
param
);
protected:
virtual
void
ThreadFunc
();
private:
static
void
ScanCallback
(
HGUInt
event
,
void
*
value1
,
void
*
value2
,
void
*
param
);
static
void
GetMsgInfo
(
const
SockIoCmdParam
*
param
,
std
::
string
&
user
,
std
::
string
&
data
);
bool
ShakeHand
(
const
std
::
string
&
head
);
void
Pong
();
...
...
sdk/webservice/WebMsg.h
View file @
61670965
...
...
@@ -12,6 +12,9 @@
#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
struct
WebMsg
{
...
...
@@ -50,4 +53,10 @@ struct SockIoCmdParam
HGUInt
size
;
};
struct
SockIoRetParam
{
HGByte
*
data
;
HGUInt
size
;
};
#endif
/* __WEBMSG_H__ */
\ No newline at end of file
sdk/webservice/WebServer.cpp
View file @
61670965
...
...
@@ -276,6 +276,23 @@ void WebServer::HandleMsg(const WebMsg* msg)
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
;
param
->
size
=
0
;
delete
param
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment