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
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
...
...
@@ -51,8 +51,19 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
}
else
if
(
requestMethod
==
"GET"
&&
requestURIPath
==
"/WebScan/getDevices"
)
{
std
::
string
devNames
;
g_manager
->
GetDevNames
(
devNames
);
std
::
vector
<
std
::
string
>
devNameList
;
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
];
sprintf
(
result
,
"{
\"
code
\"
:%d,
\"
msg
\"
:null,
\"
data
\"
:%s}"
,
200
,
devNames
.
c_str
());
...
...
@@ -62,18 +73,24 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
}
else
if
(
requestMethod
==
"GET"
&&
requestURIPath
==
"/WebScan/image/getImageByPid"
)
{
std
::
string
devId
;
for
(
int
i
=
0
;
i
<
(
int
)
requestURIQueryInfos
.
size
();
++
i
)
std
::
string
devId
=
HttpHead
::
GetValue
(
requestURIQueryInfos
,
"pid"
);
std
::
vector
<
std
::
string
>
imgNameList
;
std
::
vector
<
std
::
string
>
imgBase64List
;
g_manager
->
GetImageByDevId
(
devId
,
imgNameList
,
imgBase64List
);
std
::
string
imgInfos
=
"["
;
for
(
int
i
=
0
;
i
<
(
int
)
imgNameList
.
size
();
++
i
)
{
if
(
"pid"
==
requestURIQueryInfos
[
i
].
first
)
{
devId
=
requestURIQueryInfos
[
i
].
second
;
break
;
}
imgInfos
+=
"{
\"
imageName
\"
:
\"
"
;
imgInfos
+=
imgNameList
[
i
];
imgInfos
+=
"
\"
,
\"
src
\"
:
\"
"
;
imgInfos
+=
imgBase64List
[
i
];
imgInfos
+=
"
\"
}"
;
if
(
i
!=
imgNameList
.
size
()
-
1
)
imgInfos
+=
","
;
}
std
::
string
imgInfos
;
g_manager
->
GetImageByDevId
(
devId
,
imgInfos
);
imgInfos
+=
"]"
;
char
*
result
=
new
char
[
imgInfos
.
size
()
+
256
];
sprintf
(
result
,
"{
\"
code
\"
:%d,
\"
msg
\"
:null,
\"
data
\"
:%s}"
,
200
,
imgInfos
.
c_str
());
...
...
@@ -83,21 +100,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
}
else
if
(
requestMethod
==
"GET"
&&
requestURIPath
==
"/WebScan/getParams"
)
{
std
::
string
devId
;
for
(
int
i
=
0
;
i
<
(
int
)
requestURIQueryInfos
.
size
();
++
i
)
{
if
(
"pid"
==
requestURIQueryInfos
[
i
].
first
)
{
devId
=
requestURIQueryInfos
[
i
].
second
;
break
;
}
}
std
::
string
devParam
;
std
::
string
devId
=
HttpHead
::
GetValue
(
requestURIQueryInfos
,
"pid"
);
DevParam
devParam
;
g_manager
->
GetDevParam
(
devId
,
devParam
);
char
*
result
=
new
char
[
devParam
.
size
()
+
256
];
sprintf
(
result
,
"{
\"
code
\"
:%d,
\"
msg
\"
:null,
\"
data
\"
:%s}"
,
200
,
devParam
.
c_str
());
char
devParamStr
[
1024
];
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"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
delete
[]
result
;
...
...
@@ -107,30 +118,12 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
devId
;
for
(
int
i
=
0
;
i
<
(
int
)
uriQueryInfos
.
size
();
++
i
)
{
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
;
}
}
std
::
string
devId
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"pid"
);
std
::
string
devParamStr
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"params"
);
DevParam
devParam
;
g_manager
->
SetDevParam
(
devId
,
devParam
);
char
result
[
256
];
...
...
@@ -176,24 +169,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
uploadParam
;
for
(
int
i
=
0
;
i
<
(
int
)
uriQueryInfos
.
size
();
++
i
)
{
if
(
"formDataString"
==
uriQueryInfos
[
i
].
first
)
{
uploadParam
=
uriQueryInfos
[
i
].
second
;
break
;
}
}
std
::
string
uploadParamStr
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"formDataString"
);
UploadParam
uploadParam
;
g_manager
->
UploadImage
(
uploadParam
);
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"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
}
...
...
@@ -203,44 +187,16 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
devId
;
for
(
int
i
=
0
;
i
<
(
int
)
uriQueryInfos
.
size
();
++
i
)
{
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
;
}
}
std
::
string
devId
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"pid"
);
std
::
string
imgName
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"imageName"
);
std
::
string
imgBase64
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"image"
);
g_manager
->
SaveImage
(
devId
,
imgName
,
imgBase64
);
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"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
}
...
...
@@ -250,34 +206,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
devId
;
for
(
int
i
=
0
;
i
<
(
int
)
uriQueryInfos
.
size
();
++
i
)
{
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
devId
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"pid"
);
std
::
string
imgName
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"imageName"
);
g_manager
->
DeleteImage
(
devId
,
imgName
);
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"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
}
...
...
@@ -287,24 +224,14 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
devId
;
for
(
int
i
=
0
;
i
<
(
int
)
uriQueryInfos
.
size
();
++
i
)
{
if
(
"pid"
==
uriQueryInfos
[
i
].
first
)
{
devId
=
uriQueryInfos
[
i
].
second
;
break
;
}
}
std
::
string
devId
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"pid"
);
g_manager
->
DeleteAllImage
(
devId
);
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"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
}
...
...
@@ -314,29 +241,11 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
devId
;
for
(
int
i
=
0
;
i
<
(
int
)
uriQueryInfos
.
size
();
++
i
)
{
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
::
string
devId
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"pid"
);
bool
isHorizontal
=
(
"false"
!=
HttpHead
::
GetValue
(
uriQueryInfos
,
"isHorizontal"
))
?
true
:
false
;
std
::
vector
<
int
>
imgIndexs
;
for
(
int
i
=
0
;
i
<
(
int
)
uriQueryInfos
.
size
();
++
i
)
...
...
@@ -346,13 +255,15 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
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
[
256
];
sprintf
(
result
,
"{
\"
code
\"
:%d,
\"
msg
\"
:null,
\"
data
\"
:
\"\"
}"
,
200
);
char
*
result
=
new
char
[
256
+
imgName
.
size
()
+
imgBase64
.
size
()];
sprintf
(
result
,
"{
\"
code
\"
:%d,
\"
msg
\"
:null,
\"
data
\"
:{
\"
imageName
\"
:
\"
%s
\"
,
\"
src
\"
:
\"
%s
\"
}}"
,
200
,
imgName
.
c_str
(),
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/bookSort"
)
...
...
@@ -360,22 +271,26 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
devId
;
for
(
int
i
=
0
;
i
<
(
int
)
uriQueryInfos
.
size
();
++
i
)
std
::
string
devId
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"pid"
);
std
::
vector
<
std
::
string
>
imgNameList
,
imgBase64List
;
g_manager
->
BookSort
(
devId
,
imgNameList
,
imgBase64List
);
std
::
string
imgInfos
=
"["
;
for
(
int
i
=
0
;
i
<
(
int
)
imgNameList
.
size
();
++
i
)
{
if
(
"pid"
==
uriQueryInfos
[
i
].
first
)
{
devId
=
uriQueryInfos
[
i
].
second
;
break
;
}
imgInfos
+=
"{
\"
imageName
\"
:
\"
"
;
imgInfos
+=
imgNameList
[
i
];
imgInfos
+=
"
\"
,
\"
src
\"
:
\"
"
;
imgInfos
+=
imgBase64List
[
i
];
imgInfos
+=
"
\"
}"
;
if
(
i
!=
imgNameList
.
size
()
-
1
)
imgInfos
+=
","
;
}
std
::
string
imgInfos
;
g_manager
->
BookSort
(
devId
,
imgInfos
);
imgInfos
+=
"]"
;
char
*
result
=
new
char
[
imgInfos
.
size
()
+
256
];
sprintf
(
result
,
"{
\"
code
\"
:%d,
\"
msg
\"
:null,
\"
data
\"
:%s}"
,
200
,
imgInfos
.
c_str
());
...
...
@@ -389,17 +304,14 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
devId
;
std
::
string
devId
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"pid"
)
;
int
index1
=
-
1
,
index2
=
-
1
;
for
(
int
i
=
0
;
i
<
(
int
)
uriQueryInfos
.
size
();
++
i
)
{
if
(
"pid"
==
uriQueryInfos
[
i
].
first
)
devId
=
uriQueryInfos
[
i
].
second
;
else
if
(
"indexs[]"
==
uriQueryInfos
[
i
].
first
)
if
(
"indexs[]"
==
uriQueryInfos
[
i
].
first
)
{
if
(
-
1
==
index1
)
index1
=
atoi
(
uriQueryInfos
[
i
].
second
.
c_str
());
...
...
@@ -407,11 +319,10 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
index2
=
atoi
(
uriQueryInfos
[
i
].
second
.
c_str
());
}
}
g_manager
->
ExchangeImage
(
devId
,
index1
,
index2
);
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"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
}
...
...
@@ -427,12 +338,36 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
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"
)
{
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
}
...
...
@@ -440,7 +375,7 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
g_manager
->
ResetPatchIndex
();
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"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
}
...
...
@@ -449,38 +384,26 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
devId
,
imgName
;
bool
isHorizontal
=
true
;
int
x1
=
-
1
,
x2
=
-
1
,
y1
=
-
1
,
y2
=
-
1
;
for
(
int
i
=
0
;
i
<
(
int
)
uriQueryInfos
.
size
();
++
i
)
{
if
(
"pid"
==
uriQueryInfos
[
i
].
first
)
devId
=
uriQueryInfos
[
i
].
second
;
else
if
(
"imageName"
==
uriQueryInfos
[
i
].
first
)
imgName
=
uriQueryInfos
[
i
].
second
;
else
if
(
"isHorizontal"
==
uriQueryInfos
[
i
].
first
)
isHorizontal
=
(
"true"
==
uriQueryInfos
[
i
].
second
);
else
if
(
"x1"
==
uriQueryInfos
[
i
].
first
)
x1
=
atoi
(
uriQueryInfos
[
i
].
second
.
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
);
std
::
string
devId
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"pid"
);
std
::
string
imgName
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"imageName"
);
bool
isHorizontal
=
(
"false"
!=
HttpHead
::
GetValue
(
uriQueryInfos
,
"isHorizontal"
))
?
true
:
false
;
int
x1
=
atoi
(
HttpHead
::
GetValue
(
uriQueryInfos
,
"x1"
).
c_str
());
int
x2
=
atoi
(
HttpHead
::
GetValue
(
uriQueryInfos
,
"x2"
).
c_str
());
int
y1
=
atoi
(
HttpHead
::
GetValue
(
uriQueryInfos
,
"y1"
).
c_str
());
int
y2
=
atoi
(
HttpHead
::
GetValue
(
uriQueryInfos
,
"y2"
).
c_str
());
std
::
string
imgName1
,
imgBase64_1
,
imgName2
,
imgBase64_2
;
g_manager
->
SplitImage
(
devId
,
imgName
,
isHorizontal
,
x1
,
y1
,
x2
,
y2
,
imgName1
,
imgBase64_1
,
imgName2
,
imgBase64_2
);
char
*
result
=
new
char
[
256
+
imgName1
.
size
()
+
imgBase64_1
.
size
()
+
imgName2
.
size
()
+
imgBase64_2
.
size
()];
sprintf
(
result
,
"{
\"
code
\"
:%d,
\"
msg
\"
:null,
\"
data
\"
:{
\"
oneSrc
\"
:
\"
%s
\"
,
\"
oneName
\"
:
\"
%s
\"
,
\"
twoSrc
\"
:
\"
%s
\"
,
\"
twoName
\"
:
\"
%s
\"
}}"
,
200
,
imgBase64_1
.
c_str
(),
imgName1
.
c_str
(),
imgBase64_2
.
c_str
(),
imgName2
.
c_str
());
SendResponse
(
requestHttpVersion
.
c_str
(),
200
,
"OK"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
delete
[]
result
;
}
}
}
...
...
sdk/webservice/Manager.cpp
View file @
61670965
...
...
@@ -14,7 +14,7 @@ extern "C"
#include <algorithm>
#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
);
WCHAR
*
pUnicode
=
new
WCHAR
[
wlen
];
...
...
@@ -23,82 +23,154 @@ static CHAR* AnsiToUtf8(const char* text)
CHAR
*
pUTF8
=
new
CHAR
[
len
];
::
WideCharToMultiByte
(
CP_UTF8
,
0
,
pUnicode
,
-
1
,
pUTF8
,
len
,
NULL
,
NULL
);
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
Manager
::
Manager
()
{
#if defined(HG_CMP_MSC) && defined(SDK_USE_TWAIN)
m_twainDSM
=
NULL
;
HGTwain_LoadDSM
(
&
m_twainDSM
);
HGTwain_OpenDSM
(
m_twainDSM
);
m_twainDS
=
NULL
;
HGTwain_GetDefaultDS
(
m_twainDSM
,
&
m_twainDS
);
#else
m_saneDeviceHandle
=
NULL
;
SANE_Int
v
=
0
;
sane_init_ex
(
&
v
,
sane_ex_callback
,
this
);
#endif
HGBase_CreateLock
(
&
m_lock
);
m_devName
.
clear
();
SANE_Int
version_code
=
0
;
SANE_Status
status
=
sane_init_ex
(
&
version_code
,
sane_ex_callback
,
this
);
assert
(
SANE_STATUS_GOOD
==
status
);
m_devHandle
=
NULL
;
m_scanInsertImgName
.
clear
();
m_scanIsInsert
=
false
;
m_scanEvent
=
NULL
;
m_scanParam
=
NULL
;
}
Manager
::~
Manager
()
{
#if defined(HG_CMP_MSC) && defined(SDK_USE_TWAIN)
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
;
}
StopScan
();
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
)
{
devId
=
"123456"
;
HGBase_EnterLock
(
m_lock
);
devId
=
m_devName
;
HGBase_LeaveLock
(
m_lock
);
return
true
;
}
bool
Manager
::
GetDevNames
(
std
::
string
&
devNames
)
bool
Manager
::
GetDevNames
(
std
::
vector
<
std
::
string
>&
devNameList
)
{
devName
s
=
"["
;
devName
List
.
clear
()
;
int
count
=
2
;
for
(
int
i
=
0
;
i
<
count
;
++
i
)
const
SANE_Device
**
device_list
;
if
(
SANE_STATUS_GOOD
==
sane_get_devices
(
&
device_list
,
SANE_TRUE
)
)
{
char
devName
[
32
];
sprintf
(
devName
,
"Scanner%d"
,
i
);
devNames
+=
"
\"
"
;
devNames
+=
devName
;
devNames
+=
"
\"
"
;
if
(
i
!=
count
-
1
)
devNames
+=
","
;
const
SANE_Device
**
p
;
for
(
p
=
device_list
;
*
p
!=
NULL
;
++
p
)
{
devNameList
.
push_back
((
*
p
)
->
name
);
}
}
devNames
+=
"]"
;
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
::
vector
<
std
::
string
>
fileNameList
=
GetFileNameList
(
devId
);
...
...
@@ -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
);
if
(
NULL
!=
img
)
{
std
::
string
base64
=
GetBase64
(
img
,
0
);
HGBase_DestroyImage
(
img
);
imgInfos
+=
"{
\"
imageName
\"
:
\"
"
;
imgInfos
+=
fileNameList
[
i
];
imgInfos
+=
"
\"
,
\"
src
\"
:
\"
"
;
imgInfos
+=
"data:image/jpeg;base64,"
;
imgInfos
+=
base64
;
imgInfos
+=
"
\"
}"
;
std
::
string
imgBase64
=
"data:image/jpeg;base64,"
;
imgBase64
+=
GetBase64
(
img
,
0
);
if
(
i
!=
fileNameList
.
size
()
-
1
)
imgInfos
+=
","
;
imgNameList
.
push_back
(
fileNameList
[
i
]);
imgBase64List
.
push_back
(
imgBase64
);
HGBase_DestroyImage
(
img
);
}
}
imgInfos
+=
"]"
;
return
true
;
}
bool
Manager
::
GetDevParam
(
const
std
::
string
&
devId
,
std
::
string
&
devParam
)
{
devParam
=
"{"
;
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
::
GetDevParam
(
const
std
::
string
&
devId
,
DevParam
&
devParam
)
{
return
false
;
}
bool
Manager
::
SetDevParam
(
const
std
::
string
&
devId
,
const
std
::
string
&
devParam
)
bool
Manager
::
SetDevParam
(
const
std
::
string
&
devId
,
const
DevParam
&
devParam
)
{
return
tru
e
;
return
fals
e
;
}
bool
Manager
::
ExportOfdFile
(
HGByte
**
data
,
HGUInt
*
size
)
...
...
@@ -345,9 +381,7 @@ bool Manager::ExportZipFile(HGByte** data, HGUInt* size)
int
error
=
0
;
#if defined(HG_CMP_MSC)
CHAR
*
pUTF8
=
AnsiToUtf8
(
tmpFileName
);
zip
*
z
=
zip_open
(
pUTF8
,
ZIP_CREATE
|
ZIP_TRUNCATE
,
&
error
);
delete
[]
pUTF8
;
zip
*
z
=
zip_open
(
AnsiToUtf8
(
tmpFileName
).
c_str
(),
ZIP_CREATE
|
ZIP_TRUNCATE
,
&
error
);
#else
zip
*
z
=
zip_open
(
tmpFileName
,
ZIP_CREATE
|
ZIP_TRUNCATE
,
&
error
);
#endif
...
...
@@ -390,9 +424,9 @@ bool Manager::ExportZipFile(HGByte** data, HGUInt* size)
return
(
NULL
!=
*
data
);
}
bool
Manager
::
UploadImage
(
const
std
::
string
&
uploadParam
)
bool
Manager
::
UploadImage
(
const
UploadParam
&
uploadParam
)
{
return
tru
e
;
return
fals
e
;
}
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)
}
}
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
);
}
SaveFileNameList
(
devId
,
fileNameList
);
ret
=
true
;
}
...
...
@@ -454,14 +476,108 @@ bool Manager::DeleteAllImage(const std::string& devId)
std
::
string
fileName
=
filePath
+
fileNameList
[
i
];
HGBase_DeleteFile
(
fileName
.
c_str
());
}
fileNameList
.
clear
();
std
::
string
cfgName
=
filePath
+
"images.txt"
;
HGBase_DeleteFile
(
cfgName
.
c_str
());
SaveFileNameList
(
devId
,
fileNameList
);
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
;
}
...
...
@@ -470,26 +586,14 @@ static bool LowerSort(const std::string &str1, const std::string& 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
::
sort
(
fileNameList
.
begin
(),
fileNameList
.
end
(),
LowerSort
);
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
);
}
return
GetImageByDevId
(
devId
,
imgInfos
);
SaveFileNameList
(
devId
,
fileNameList
);
return
GetImageByDevId
(
devId
,
imgNameList
,
imgBase64List
);
}
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
[
index2
]
=
imgName1
;
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
);
}
SaveFileNameList
(
devId
,
fileNameList
);
return
true
;
}
bool
Manager
::
GetLastBetch
(
std
::
string
&
devId
)
{
devId
=
"123456"
;
HGBase_EnterLock
(
m_lock
);
devId
=
m_devName
;
HGBase_LeaveLock
(
m_lock
);
return
true
;
}
...
...
@@ -531,19 +625,145 @@ bool Manager::ResetPatchIndex()
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
;
}
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
)
...
...
@@ -551,7 +771,11 @@ std::string Manager::GetFilePath(const std::string& devId)
HGChar
docsPath
[
512
];
HGBase_GetDocumentsPath
(
docsPath
,
512
);
HGChar
imgPath
[
512
];
sprintf
(
imgPath
,
"%sHuaGo/WebService/%s/"
,
docsPath
,
devId
.
c_str
());
#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
().
c_str
());
#endif
HGChar
stdImgPath
[
512
];
HGBase_StandardiseFileName
(
imgPath
,
stdImgPath
,
512
);
...
...
@@ -587,6 +811,28 @@ std::vector<std::string> Manager::GetFileNameList(const std::string& devId)
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
strBase64
;
...
...
@@ -710,14 +956,147 @@ bool Manager::SaveBase64(const std::string& fileName, const char* base64)
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
)
{
(
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
;
}
#endif
\ No newline at end of file
}
\ No newline at end of file
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