HGGitLab

Commit 7e3b95ca authored by luoliangyi's avatar luoliangyi

webservice:将Manager的回调函数和Scan函数独立开

parent ff42a488
......@@ -778,7 +778,6 @@ bool HttpUser::SendResponse(const char* httpVersion, HGUInt errCode, const char*
else
{
assert(0 == size);
assert(NULL == contentType);
sprintf(head, "%s: %s\r\n\r\n",
"Access-Control-Allow-Origin", "null");
......
This diff is collapsed.
......@@ -10,11 +10,13 @@
#include <vector>
#include <string>
#define SCANEVENT_STATUS 0L
#define SCANEVENT_WORKING 1L
#define SCANEVENT_IMAGE 2L
#define SCANEVENT_FINISH 3L
#define SCANEVENT_ERROR 4L
#define SCANEVENT_ARRIVE 1L
#define SCANEVENT_REMOVE 2L
#define SCANEVENT_STATUS 3L
#define SCANEVENT_WORKING 4L
#define SCANEVENT_IMAGE 5L
#define SCANEVENT_FINISH 6L
#define SCANEVENT_ERROR 7L
struct DevParam
{
......@@ -90,8 +92,13 @@ public:
void OpenDev(const OpenDevParam *param);
// 关闭设备
void CloseDev(const CloseDevParam* param);
// 设置回调
void SetScanEvent(ScanEvent event, void* param);
// 清理回调
void ResetScanEvent();
// 扫描
bool Scan(const std::string& insertImgName, bool isInsert, ScanEvent event, void *param);
bool Scan(const std::string& insertImgName, bool isInsert);
// 停止扫描
bool StopScan();
// 获取当前连接的设备ID
......@@ -153,14 +160,15 @@ private:
private:
class MsgLoop* m_loop;
HGLock m_lock;
std::string m_devName;
SANE_Handle m_devHandle;
DevParam m_devParam;
ScanEvent m_scanEvent;
void* m_scanParam;
std::string m_scanInsertImgName;
bool m_scanIsInsert;
ScanEvent m_scanEvent;
void* m_scanParam;
bool m_scanning;
};
......
......@@ -15,12 +15,12 @@ SockIoUser::SockIoUser(class WebServer* server, HGUInt id, const char* ip, uint1
#endif
: WebUser(server, id, ip, port, sockConn)
{
GetManager()->SetScanEvent(ScanCallback, this);
}
SockIoUser::~SockIoUser()
{
GetManager()->ResetScanEvent();
}
void SockIoUser::HandleCmd(const SockIoCmdParam* param)
......@@ -53,7 +53,7 @@ void SockIoUser::HandleCmd(const SockIoCmdParam* param)
cJSON_Delete(json);
}
bool ret = GetManager()->Scan(imgName, insert, ScanCallback, this);
bool ret = GetManager()->Scan(imgName, insert);
if (!ret)
{
std::string resp = "42[\"error\", \"scan error\"]";
......@@ -446,27 +446,36 @@ void SockIoUser::ScanCallback(HGUInt event, void* value1, void* value2, void* pa
SockIoUser* p = (SockIoUser*)param;
char *resp = NULL;
if (SCANEVENT_WORKING == event)
if (SCANEVENT_ARRIVE == event)
{
resp = new char[256];
sprintf(resp, "42[\"success\", \"%s\"]", (const char*)value1);
}
else if (SCANEVENT_REMOVE == event)
{
}
else if (SCANEVENT_WORKING == event)
{
resp = new char[256];
sprintf(resp, "42[\"event\", \"%s\"]", "scanning...");
sprintf(resp, "42[\"event\", \"%s\"]", "......");
}
else if (SCANEVENT_FINISH == event)
{
resp = new char[256];
sprintf(resp, "42[\"result\", {\"code\":204, \"msg\":\"%s\"}]", "scan finish!");
sprintf(resp, "42[\"result\", {\"code\":204, \"msg\":\"%s\"}]", (const char *)value1);
}
else if (SCANEVENT_ERROR == event)
{
resp = new char[256];
sprintf(resp, "42[\"error\", \"%s\"]", "device error");
sprintf(resp, "42[\"error\", \"%s\"]", (const char*)value1);
}
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);
sprintf(resp, "42[\"image\", {\"code\":201, \"imageName\":\"%s\", \"image\":\"%s\"}]", imgName, imgBase64);
}
if (NULL != resp)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment