Explorar o código

Z991239-5321 #comment 恢复LivenessDetection实体服务化

80274480 hai 1 ano
pai
achega
b460edf972

+ 80 - 0
Module/mod_livenessdetection/LivenessDetection.xml

@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="gb2312" ?>
+<entity name="LivenessDetection">	
+	<!-- 活体检测服务 -->
+	<class name="LivenessDetectionService" overlap="true"  exclusive="false">
+		<!-- 启动检测接口 -->
+		<twoway name="StartLivenessDetection" overlap="true">
+			<req>
+				<!-- 活体检测ActionID 16位 -->
+				<param name="ActionID" type="wstring"/>
+				<!-- 是否为主动检测(默认false,被动) -->
+				<param name="IsActive" type="bool"/>
+				<!-- 保留参数 -->
+				<param name="Reserved" type="wstring"/>
+			</req>
+			<res>
+			</res>
+		</twoway>
+		<!-- 停止检测接口(被动检测用到返回结果) -->
+		<twoway name="StopLivenessDetection" overlap="true">
+			<req>
+				<!-- 活体检测ActionID 16位 -->
+				<param name="ActionID" type="wstring"/>
+			</req>
+			<res>
+				<!-- 活体检测ActionID 16位 -->
+				<param name="ActionID" type="wstring"/>
+				<!-- 活体判别结果 Y(活体) N(非活体) X(不确定) -->
+				<param name="VerifyResult" type="wstring"/>
+				<!-- 活体照片数据(可能多张) -->
+				<param name="LivePhotosData" type="blob"/>
+				<!-- 活体照片长度列表,以'|'分隔 -->
+				<param name="LivePhotosLength" type="wstring"/>
+			</res>
+		</twoway>
+	</class>
+	<!-- 主动检测完成消息 -->
+	<message name="ActiveDetectionDone">
+		<!-- 活体检测ActionID 16位 -->
+		<param name="ActionID" type="wstring"/>
+		<!-- 主动活体判别结果 Y(活体) N(非活体) X(不确定) -->
+		<param name="VerifyResult" type="wstring"/>
+		<!-- 自动抓拍照片数据 -->
+		<param name="SnapShotPhotoData" type="blob"/>
+		<!-- 自动抓拍照片长度 -->
+		<param name="SnapShotPhotoLength" type="int"/>
+	</message>	
+	<!-- 自动抓拍提示消息 -->
+	<message name="AutoSnapshotRemind">
+		<!-- 活体检测ActionID 16位 -->
+		<param name="ActionID" type="wstring"/>
+		<!-- 提示信息 -->
+		<param name="RemindInfo" type="wstring"/>
+	</message>	
+	<!-- 检测非正常结束消息 -->
+	<message name="DetectionStopUnExpected">
+		<!-- 活体检测ActionID 16位 -->
+		<param name="ActionID" type="wstring"/>
+		<!-- 是否为主动检测(默认false,被动) -->
+		<param name="IsActive" type="bool"/>
+		<!-- 错误码 -->
+		<param name="ErrorCode" type="wstring"/>
+		<!-- 错误消息:超时、启动检测失败... -->
+		<param name="ErrorMsg" type="wstring"/>
+	</message>
+	<!-- 活体检测心跳消息(可选) -->
+	<message name="LivenessDetectionHeartBeat">
+		<!-- 状态:0:正常 1:故障... -->
+		<param name="Status" type="int"/>
+	</message>	
+	<!-- 主动活体启动消息 -->
+	<message name="ActiveDetectionStarted">
+		<!-- 启动参数(回显窗口用) -->
+		<param name="Param" type="string"/>
+	</message>	
+	<!-- 主动活体停止消息 -->
+	<message name="ActiveDetectionStopped">
+		<!-- 停止参数(回显窗口用) -->
+		<param name="Param" type="string"/>
+	</message>	
+</entity>

+ 179 - 0
Module/mod_livenessdetection/LivenessDetection_client_g.h

@@ -0,0 +1,179 @@
+
+#ifndef __LIVENESSDETECTION_CLIENT_G_H
+#define __LIVENESSDETECTION_CLIENT_G_H
+
+#pragma once
+
+// This code is generated by spgen tool!
+
+#include "LivenessDetection_def_g.h"
+
+namespace LivenessDetection {
+class LivenessDetectionService_ClientBase : public CClientSessionBase {
+public:
+	explicit LivenessDetectionService_ClientBase(CEntityBase *pEntity) : m_pEntityBase(pEntity), m_bSysManaged(false) {}
+
+	LivenessDetectionService_ClientBase* operator () (const linkContext &curLink) 
+	{
+		m_context = curLink;
+		return this;
+	}
+
+protected:
+	virtual ~LivenessDetectionService_ClientBase()
+	{
+		/// override by user
+	}
+public:
+
+	void OnConnectSucceed()
+	{
+		bSessionClosed = false;
+	}
+	void OnClose(ErrorCodeEnum)
+	{
+		Dbg("session closed.");
+		bSessionClosed = true;
+	}
+	bool QuerySessionClosed()
+	{
+		return bSessionClosed;
+	}
+	ErrorCodeEnum Connect(CSmartPointer<IAsynWaitSp> &spAsyncWait)
+	{
+		CSmartPointer<IEntityFunction> pFunc = m_pEntityBase->GetFunction();
+		ErrorCodeEnum Error = pFunc->ConnectRemoteEntity(this, "LivenessDetection", "LivenessDetectionService", spAsyncWait);
+		if (Error == Error_Succeed) {
+			m_bSysManaged = true;
+			bSessionClosed = false;
+		}
+		return Error;
+	}
+	ErrorCodeEnum Connect()
+	{
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = Connect(spAsyncWait);
+		if (Error == Error_Succeed) {
+			Error = spAsyncWait->WaitAnswer();
+		}
+		return Error;
+	}
+
+	ErrorCodeEnum StartLivenessDetection(LivenessDetectionService_StartLivenessDetection_Req &Req, CSmartPointer<IAsynWaitSp> &spAsyncWait, DWORD dwTimeout)
+	{
+		CSmartPointer<IClientSessionFunction> pFunc = GetFunction();
+		CAutoBuffer Buf = SpObject2Buffer(Req);
+		if (m_context.checkEmpty())
+		{
+			m_context.AutoGenerate();
+			DbgToBeidou(m_context, m_pEntityBase != NULL ? m_pEntityBase->GetEntityName() : "")();
+			m_context = m_context.upgradeLink();
+		}
+		auto ret = pFunc->AsyncRequest(LivenessDetectionService_Method_StartLivenessDetection, LivenessDetectionService_MethodSignature_StartLivenessDetection, Buf, spAsyncWait, m_context, dwTimeout);
+		m_context.clear();
+		return ret;
+	}
+	ErrorCodeEnum StartLivenessDetection(LivenessDetectionService_StartLivenessDetection_Req &Req, LivenessDetectionService_StartLivenessDetection_Ans &Ans, DWORD dwTimeout)
+	{
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = StartLivenessDetection(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
+	}
+	ErrorCodeEnum StartLivenessDetection(LivenessDetectionService_StartLivenessDetection_Req &Req, LivenessDetectionService_StartLivenessDetection_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError, CSimpleString &str)
+	{
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = StartLivenessDetection(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
+	}
+	ErrorCodeEnum StartLivenessDetection(LivenessDetectionService_StartLivenessDetection_Req &Req, LivenessDetectionService_StartLivenessDetection_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError)
+	{
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = StartLivenessDetection(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			CSimpleString str;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
+	}
+
+	ErrorCodeEnum StopLivenessDetection(LivenessDetectionService_StopLivenessDetection_Req &Req, CSmartPointer<IAsynWaitSp> &spAsyncWait, DWORD dwTimeout)
+	{
+		CSmartPointer<IClientSessionFunction> pFunc = GetFunction();
+		CAutoBuffer Buf = SpObject2Buffer(Req);
+		if (m_context.checkEmpty())
+		{
+			m_context.AutoGenerate();
+			DbgToBeidou(m_context, m_pEntityBase != NULL ? m_pEntityBase->GetEntityName() : "")();
+			m_context = m_context.upgradeLink();
+		}
+		auto ret = pFunc->AsyncRequest(LivenessDetectionService_Method_StopLivenessDetection, LivenessDetectionService_MethodSignature_StopLivenessDetection, Buf, spAsyncWait, m_context, dwTimeout);
+		m_context.clear();
+		return ret;
+	}
+	ErrorCodeEnum StopLivenessDetection(LivenessDetectionService_StopLivenessDetection_Req &Req, LivenessDetectionService_StopLivenessDetection_Ans &Ans, DWORD dwTimeout)
+	{
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = StopLivenessDetection(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
+	}
+	ErrorCodeEnum StopLivenessDetection(LivenessDetectionService_StopLivenessDetection_Req &Req, LivenessDetectionService_StopLivenessDetection_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError, CSimpleString &str)
+	{
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = StopLivenessDetection(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
+	}
+	ErrorCodeEnum StopLivenessDetection(LivenessDetectionService_StopLivenessDetection_Req &Req, LivenessDetectionService_StopLivenessDetection_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError)
+	{
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = StopLivenessDetection(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			CSimpleString str;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
+	}
+
+
+	bool SafeDelete()
+	{
+		if (!m_bSysManaged) {
+			delete this;
+		}
+		return m_bSysManaged;
+	}
+
+protected:
+	bool m_bSysManaged;
+	CEntityBase *m_pEntityBase;
+	linkContext m_context;
+	bool bSessionClosed;
+};
+
+///////////////////////////
+
+} // namespace LivenessDetection
+#endif // __LIVENESSDETECTION_CLIENT_G_H

+ 76 - 0
Module/mod_livenessdetection/LivenessDetection_def_g.h

@@ -0,0 +1,76 @@
+#ifndef __LIVENESSDETECTION_DEF_G_H
+#define __LIVENESSDETECTION_DEF_G_H
+
+#pragma once
+
+// This code is generated by spgen tool!
+
+#include "SpHelper.h"
+
+namespace LivenessDetection {
+//
+// const goes here
+//
+
+#define LivenessDetectionService_Method_StartLivenessDetection 0
+#define LivenessDetectionService_Method_StopLivenessDetection 1
+
+#define LivenessDetectionService_MethodSignature_StartLivenessDetection 1875899628
+#define LivenessDetectionService_MethodSignature_StopLivenessDetection -698442534
+
+#define LivenessDetectionService_LogCode_StartLivenessDetection "QLR040231400"
+#define LivenessDetectionService_LogCode_StopLivenessDetection "QLR040231401"
+
+struct LivenessDetectionService_StartLivenessDetection_Req
+{
+	CSimpleStringW ActionID;
+	bool IsActive;
+	CSimpleStringW Reserved;
+
+	void Serialize(SpBuffer &Buf)
+	{
+		auto & buf = Buf & ActionID & IsActive & Reserved;
+	}
+
+};
+
+struct LivenessDetectionService_StartLivenessDetection_Ans
+{
+
+	void Serialize(SpBuffer &Buf)
+	{
+	}
+
+};
+
+struct LivenessDetectionService_StopLivenessDetection_Req
+{
+	CSimpleStringW ActionID;
+
+	void Serialize(SpBuffer &Buf)
+	{
+		auto & buf = Buf & ActionID;
+	}
+
+};
+
+struct LivenessDetectionService_StopLivenessDetection_Ans
+{
+	CSimpleStringW ActionID;
+	CSimpleStringW VerifyResult;
+	CBlob LivePhotosData;
+	CSimpleStringW LivePhotosLength;
+
+	void Serialize(SpBuffer &Buf)
+	{
+		auto & buf = Buf & ActionID & VerifyResult & LivePhotosData & LivePhotosLength;
+	}
+
+};
+
+
+///////////////////////////
+
+} // namespace LivenessDetection
+
+#endif // __LIVENESSDETECTION_DEF_G_H

+ 112 - 0
Module/mod_livenessdetection/LivenessDetection_msg_g.h

@@ -0,0 +1,112 @@
+
+#ifndef __LIVENESSDETECTION_MSG_G_H
+#define __LIVENESSDETECTION_MSG_G_H
+
+#pragma once
+
+// This code is generated by spgen tool!
+
+#include "SpHelper.h"
+
+namespace LivenessDetection {
+#define eMsg_ActiveDetectionDone 0
+#define eMsg_AutoSnapshotRemind 1
+#define eMsg_DetectionStopUnExpected 2
+#define eMsg_LivenessDetectionHeartBeat 3
+#define eMsg_ActiveDetectionStarted 4
+#define eMsg_ActiveDetectionStopped 5
+
+#define eMsgSig_ActiveDetectionDone 1663036101
+#define eMsgSig_AutoSnapshotRemind -1204333518
+#define eMsgSig_DetectionStopUnExpected 135483694
+#define eMsgSig_LivenessDetectionHeartBeat -835179092
+#define eMsgSig_ActiveDetectionStarted -390712849
+#define eMsgSig_ActiveDetectionStopped 576206235
+
+struct ActiveDetectionDone
+{
+	CSimpleStringW ActionID;
+	CSimpleStringW VerifyResult;
+	CBlob SnapShotPhotoData;
+	int SnapShotPhotoLength;
+
+	void Serialize(SpBuffer &Buf)
+	{
+		auto & buf = Buf & ActionID & VerifyResult & SnapShotPhotoData & SnapShotPhotoLength;
+	}
+
+};
+
+///////////////////////////
+
+struct AutoSnapshotRemind
+{
+	CSimpleStringW ActionID;
+	CSimpleStringW RemindInfo;
+
+	void Serialize(SpBuffer &Buf)
+	{
+		auto & buf = Buf & ActionID & RemindInfo;
+	}
+
+};
+
+///////////////////////////
+
+struct DetectionStopUnExpected
+{
+	CSimpleStringW ActionID;
+	bool IsActive;
+	CSimpleStringW ErrorCode;
+	CSimpleStringW ErrorMsg;
+
+	void Serialize(SpBuffer &Buf)
+	{
+		auto & buf = Buf & ActionID & IsActive & ErrorCode & ErrorMsg;
+	}
+
+};
+
+///////////////////////////
+
+struct LivenessDetectionHeartBeat
+{
+	int Status;
+
+	void Serialize(SpBuffer &Buf)
+	{
+		auto & buf = Buf & Status;
+	}
+
+};
+
+///////////////////////////
+
+struct ActiveDetectionStarted
+{
+	CSimpleStringA Param;
+
+	void Serialize(SpBuffer &Buf)
+	{
+		auto & buf = Buf & Param;
+	}
+
+};
+
+///////////////////////////
+
+struct ActiveDetectionStopped
+{
+	CSimpleStringA Param;
+
+	void Serialize(SpBuffer &Buf)
+	{
+		auto & buf = Buf & Param;
+	}
+
+};
+
+///////////////////////////
+
+} // namespace LivenessDetection
+#endif // __LIVENESSDETECTION_MSG_G_H

+ 137 - 0
Module/mod_livenessdetection/LivenessDetection_server_g.h

@@ -0,0 +1,137 @@
+
+#ifndef __LIVENESSDETECTION_SERVER_G_H
+#define __LIVENESSDETECTION_SERVER_G_H
+
+#pragma once
+
+// This code is generated by spgen tool!
+
+#include "LivenessDetection_def_g.h"
+
+namespace LivenessDetection {
+class LivenessDetectionService_ServerSessionBase : public CServerSessionBase
+{
+public:
+	LivenessDetectionService_ServerSessionBase()
+	{
+		/// override by user
+	}
+
+	virtual ~LivenessDetectionService_ServerSessionBase()
+	{
+		/// override by user
+	}
+
+	virtual bool IsExclusive() { return false; }
+
+	virtual bool IsSessionOverlap() { return true; }
+
+	virtual ErrorCodeEnum GetMessageAttr(DWORD dwMessageID, DWORD dwSignature, bool &bOverlap)
+	{
+		ErrorCodeEnum Error = Error_Succeed;
+		switch (dwMessageID) {
+		case LivenessDetectionService_Method_StartLivenessDetection:
+			if (dwSignature == LivenessDetectionService_MethodSignature_StartLivenessDetection) {
+				bOverlap = true;
+			} else {
+				Error = Error_MethodSignatureFailed;
+			}
+			break;
+		case LivenessDetectionService_Method_StopLivenessDetection:
+			if (dwSignature == LivenessDetectionService_MethodSignature_StopLivenessDetection) {
+				bOverlap = true;
+			} else {
+				Error = Error_MethodSignatureFailed;
+			}
+			break;
+		default:
+			Error = Error_MethodNotFound;
+			break;
+		}
+		return Error;
+	}
+
+	int CheckMessageSignature(DWORD dwMessageID, DWORD dwSignature)
+	{
+		ErrorCodeEnum Error = Error_Succeed;
+		switch (dwMessageID) {
+		case LivenessDetectionService_Method_StartLivenessDetection:
+			if (dwSignature != LivenessDetectionService_MethodSignature_StartLivenessDetection) {
+				Error = Error_MethodSignatureFailed;
+			}
+			break;
+		case LivenessDetectionService_Method_StopLivenessDetection:
+			if (dwSignature != LivenessDetectionService_MethodSignature_StopLivenessDetection) {
+				Error = Error_MethodSignatureFailed;
+			}
+			break;
+		default:
+			Error = Error_MethodNotFound;
+			break;
+		}
+		return Error;
+	}
+
+	virtual void Handle_StartLivenessDetection(SpReqAnsContext<LivenessDetectionService_StartLivenessDetection_Req, LivenessDetectionService_StartLivenessDetection_Ans>::Pointer ctx)
+	{
+	/// override by user
+	}
+
+	virtual void Handle_StopLivenessDetection(SpReqAnsContext<LivenessDetectionService_StopLivenessDetection_Req, LivenessDetectionService_StopLivenessDetection_Ans>::Pointer ctx)
+	{
+	/// override by user
+	}
+
+	virtual void OnRequest(CSmartPointer<ITransactionContext> pTransactionContext)
+	{
+		CAutoBuffer Buf;
+		DWORD dwMessageID;
+		DWORD dwMessageSignature;
+		ErrorCodeEnum Error = pTransactionContext->GetReceiveBuffer(dwMessageID, dwMessageSignature, Buf);
+		if (Error == Error_Succeed) {
+#ifdef DEBUG
+			assert(CheckMessageSignature(dwMessageID, dwMessageSignature) == Error_Succeed);
+#else
+			if (CheckMessageSignature(dwMessageID, dwMessageSignature) != Error_Succeed) {
+				pTransactionContext->SendAnswer(Error_MethodSignatureFailed);
+				return;
+			}
+#endif
+			switch (dwMessageID) {
+				case LivenessDetectionService_Method_StartLivenessDetection:
+					{
+						SpReqAnsContext<LivenessDetectionService_StartLivenessDetection_Req,LivenessDetectionService_StartLivenessDetection_Ans>::Pointer ctx;
+						ctx.Attach(new SpReqAnsContext<LivenessDetectionService_StartLivenessDetection_Req,LivenessDetectionService_StartLivenessDetection_Ans>(pTransactionContext));
+						SpBuffer2Object(Buf, ctx->Req);
+						pTransactionContext->GetLinkContext(ctx->link);
+						EntityResource::setLink(ctx->link);
+						Handle_StartLivenessDetection(ctx);
+					}
+					break;
+				case LivenessDetectionService_Method_StopLivenessDetection:
+					{
+						SpReqAnsContext<LivenessDetectionService_StopLivenessDetection_Req,LivenessDetectionService_StopLivenessDetection_Ans>::Pointer ctx;
+						ctx.Attach(new SpReqAnsContext<LivenessDetectionService_StopLivenessDetection_Req,LivenessDetectionService_StopLivenessDetection_Ans>(pTransactionContext));
+						SpBuffer2Object(Buf, ctx->Req);
+						pTransactionContext->GetLinkContext(ctx->link);
+						EntityResource::setLink(ctx->link);
+						Handle_StopLivenessDetection(ctx);
+					}
+					break;
+				default:
+					assert(0);
+					break;
+			}
+			
+		} else {
+			pTransactionContext->SendAnswer(Error);
+		}
+	}
+
+};
+
+
+///////////////////////////
+
+} // namespace LivenessDetection
+#endif // __LIVENESSDETECTION_SERVER_G_H

+ 22 - 0
Module/mod_livenessdetection/mod_livenessdetection.h

@@ -13,6 +13,10 @@
 #include "mod_mediacontroller/Event.h"
 #include "mod_facetracking/sysvar.h"
 
+#include "LivenessDetection_def_g.h"
+#include "LivenessDetection_msg_g.h"
+#include "LivenessDetection_server_g.h"
+
 #include <assert.h>
 #include "EventCode.h"
 
@@ -22,6 +26,18 @@
 
 using namespace LivenessDetection;
 
+class CLivenessDetectionEntity;
+
+class LivenessDetectionServerSession : public LivenessDetectionService_ServerSessionBase
+{
+public:
+	LivenessDetectionServerSession(CLivenessDetectionEntity* pEntity) : m_pEntity(pEntity) {}
+	virtual ~LivenessDetectionServerSession() {}
+
+private:
+	CLivenessDetectionEntity* m_pEntity;
+};
+
 class CLivenessDetectionEntity : public CEntityBase, public ILogListener, public ISysVarListener
 {
 public:
@@ -47,6 +63,12 @@ public:
 	virtual bool IsService() const { return true; }
 	virtual bool IsMultiThread() const { return false; }
 
+	// 实体服务化
+	virtual CServerSessionBase* OnNewSession(const char*, const char*)
+	{
+		return new LivenessDetectionServerSession(this);
+	}
+
 	DeviceTypeEnum GetDeviceType() const { return m_eDeviceType; }
 
 	int on_get_videodata(eVideoType eType, eCameraType ecameraid, int* width, int* height, unsigned char* bmpdata, int isize);