⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prehandlemessage.cpp

📁 linux 下的sgip 协议中的消息处理部分源代码
💻 CPP
字号:
#ifndef _SOLARIS
//#include "StdAfx.h"
#endif

#include "SMGModule.h"
#include "EMSNgor.h"
#include "PublicDefine.h"
#include "IAlarm.h"
#include "RTCStime.h"
#include "IDBProxy.h"
#include "IGateWayMsg.h"
#include "ISMG.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
   
extern void PrintConsole(LPCTSTR ModuleName,char* fmt,...);
extern char * strupr(char *mystr);
extern char * strlwr(char *mystr);

TRealtimeObject * TSMGModule::OnISMGDeliver(RTCS_CTpdu& pdu)
{
    RTCS_CTuint messagelength = 0;
	unsigned char messagecoding;
	RTCS_CTbyteArray messagecontent;

	//取出短消息内容
	pdu.GetByte(RTCS_ISMA_MessageCoding,&messagecoding);
	pdu.GetByteArray(RTCS_ISMA_MessageContent,&messagecontent,&messagelength);

	//新建流程
	RTCS_CTuint SessionID = m_SessionObjectTable.GenerateSessionID(); 
	TSessionObject* pSessionObject = new TSessionObject(this, SessionID);
	pSessionObject->m_pdu = pdu;

	//根据不同的消息字冠启动流程
	char	prefix[512];
	//UnpacketMsg(messagecontent,messagelength,'#',prefix);

	//查找流程
	//TAppFlow * pFlow = m_AppFlowTable.GetAppFlow(strlwr(prefix));
	TAppFlow * pFlow = m_AppFlowTable.GetAppFlow("jf");

	if (!pFlow)
		TAppFlow * pFlow = m_AppFlowTable.GetAppFlow("default");

	if(!pFlow)
	{
		logfile->Trace(0, "找不到相应的流程, RetServiceType=%s\n", prefix);
		PrintConsole(m_ModuleName, "找不到相应的流程, RetServiceType=%s\n", prefix);

		delete pSessionObject;
		pSessionObject = NULL;
		return NULL;
	}

	//把SessionObject添加到会话对象表中
	if(m_SessionObjectTable.AddSessionObject(pSessionObject) != 0)
	{
		logfile->Trace(0, "把会话对象添加到会话对象表中失败, SessionID=%u\n", pSessionObject->m_SessionID);
		PrintConsole(m_ModuleName, "把会话对象添加到会话对象表中失败, SessionID=%u", pSessionObject->m_SessionID);

		delete pSessionObject;
		pSessionObject = NULL;
		return NULL;
	}

	//调入流程,驱动状态机运转
	pSessionObject->SetFlow( CallScript( pFlow->m_FlowID ) );
	
	PrintConsole(m_ModuleName, "流程模块<<-网关模块: 收到DELIVER消息,启动缴费流程");
	return pSessionObject;
}

TRealtimeObject * TSMGModule::OnDataAccessResp(RTCS_CTpdu& pdu)
{
	RTCS_CTuint accessid;
	pdu.GetUInt(RTCS_IDBP_DataAccessID,&accessid);
	logfile->Trace(0, "流程模块<<-应用服务器: 交易响应, MessageID=【%d】 返回结果=【%d】.\n",
		          accessid, pdu.status);
	PrintConsole(m_ModuleName, "流程模块<<-应用服务器: 交易响应, MessageID=【%d】 返回结果=【%d】.",
		          accessid, pdu.status);

	RTCS_CTuint SessionID = pdu.receiverObj;

	//查找会话对象
	TSessionObject* pSessionObject = NULL;
	pSessionObject = m_SessionObjectTable.GetSessionObject(SessionID);
	if(!pSessionObject)
	{
		logfile->Trace(0, "SessionObject not exist, SessionID=%u.\n", SessionID);
		return NULL;
	}

	if(pdu.status == RTCS_Error_IDBP_OK)
	{
		RTCS_CTstring *str;
		RTCS_CTuint fieldnum=0;
		pdu.GetStringArray(RTCS_IDBP_ParamData,&str,&fieldnum);
		for(RTCS_CTuint i=0;i<fieldnum;i++)
		{
			if(strlen((LPCTSTR)str[i])<MAX_FIELD_LEN)
				strcpy(pSessionObject->m_Field[i],(LPCTSTR)str[i]);
			else
				strcpy(pSessionObject->m_Field[i],"");
		}
	}

    pSessionObject->m_CurrResult = pdu.status;

	return pSessionObject;
}

TRealtimeObject * TSMGModule::OnISMGBindResp(RTCS_CTpdu& pdu)
{
	//logfile->Trace(0, "流程模块<-网关模块: Bind响应, SessionID=<%u> 返回结果=<%d>.\n",
	//	          pdu.receiverObj, pdu.status);
	//PrintConsole(m_ModuleName, "流程模块<-网关模块: Bind响应, SessionID=<%u> 返回结果=<%d>.",
	//	          pdu.receiverObj, pdu.status);

	RTCS_CTuint SessionID = pdu.receiverObj;

	//查找会话对象
	TSessionObject* pSessionObject = NULL;
	pSessionObject = m_SessionObjectTable.GetSessionObject(SessionID);
	if(!pSessionObject)
	{
		logfile->Trace(0, "SessionObject not exist, SessionID=%u.\n", SessionID);
		return NULL;
	}
/*
	//停止时定时器
	if(pSessionObject->m_TimerID)
	{
		ClearTimer(pSessionObject->m_TimerID);
		pSessionObject->m_TimerID = 0;
	}
*/
	//给SessionObject赋值
	pSessionObject->m_Socket = pdu.qualifier;
    pSessionObject->m_CurrResult = pdu.status;
	return pSessionObject;
}

TRealtimeObject * TSMGModule::OnISMGUnBindResp(RTCS_CTpdu& pdu)
{
	//logfile->Trace(0, "流程模块<-网关模块: UnBind响应, SessionID=<%u> .\n",
	//	          pdu.receiverObj);
	//PrintConsole(m_ModuleName, "流程模块<-网关模块: UnBind响应, SessionID=<%u> .",
	//	          pdu.receiverObj);

	RTCS_CTuint SessionID = pdu.receiverObj;

	//查找会话对象
	TSessionObject* pSessionObject = NULL;
	pSessionObject = m_SessionObjectTable.GetSessionObject(SessionID);
	if(!pSessionObject)
	{
		logfile->Trace(0, "SessionObject not exist, SessionID=%u.\n", SessionID);
		return NULL;
	}
/*     
	//停止时定时器
	if(pSessionObject->m_TimerID)
	{
		ClearTimer(pSessionObject->m_TimerID);
		pSessionObject->m_TimerID = 0;
	}
*/
	//给SessionObject赋值
    pSessionObject->m_CurrResult = 0;
	return pSessionObject;
}

TRealtimeObject * TSMGModule::OnISMGSubmitResp(RTCS_CTpdu& pdu)
{
	//logfile->Trace(0, "流程模块<-网关模块: Submit响应, SessionID=<%u> 返回结果=<%d>.\n",
	//	          pdu.receiverObj, pdu.status);
	//PrintConsole(m_ModuleName, "流程模块<-网关模块: Submit响应, SessionID=<%u> 返回结果=<%d>.",
	//	          pdu.receiverObj, pdu.status);

	RTCS_CTuint SessionID = pdu.receiverObj;

	//查找会话对象
	TSessionObject* pSessionObject = NULL;
	pSessionObject = m_SessionObjectTable.GetSessionObject(SessionID);
	if(!pSessionObject)
	{
		logfile->Trace(0, "SessionObject not exist, SessionID=%u.\n", SessionID);
		return NULL;
	}
/*
	//停止时定时器
	if(pSessionObject->m_TimerID)
	{
		ClearTimer(pSessionObject->m_TimerID);
		pSessionObject->m_TimerID = 0;
	}
*/
	//给SessionObject赋值
	pSessionObject->m_Socket = pdu.qualifier;
    pSessionObject->m_CurrResult = pdu.status;
	return pSessionObject;
}

TRealtimeObject * TSMGModule::OnEvtReturn(RTCS_CTpdu& pdu)
{
	RTCS_CTuint SessionID = pdu.receiverObj;

	TSessionObject* pSessionObject = NULL;
	pSessionObject = m_SessionObjectTable.GetSessionObject(SessionID); 

	if(pSessionObject)
		pSessionObject->m_CurrResult = pdu.status;

	return pSessionObject;
}

TRealtimeObject * TSMGModule::OnEvtTimerExpired(RTCS_CTpdu& pdu)
{
	RTCS_CTuint SessionID = pdu.receiverObj;

	TSessionObject* pSessionObject = NULL;
	pSessionObject = m_SessionObjectTable.GetSessionObject(SessionID); 
	
	if(pSessionObject)
	{
		pSessionObject->m_TimerID = 0;
	}

	return pSessionObject;
}

TRealtimeObject * TSMGModule::OnEvtFail(RTCS_CTpdu& pdu)
{
	RTCS_CTuint SessionID = pdu.receiverObj;

	TSessionObject* pSessionObject = NULL;
	pSessionObject = m_SessionObjectTable.GetSessionObject(SessionID); 

	if(pSessionObject)
		pSessionObject->m_CurrResult = pdu.status;

	return pSessionObject;
}

RTCS_CTuint TSMGModule::UnpacketMsg(RTCS_CTbyteArray Msg_Content,RTCS_CTuint Msg_Content_lenth,RTCS_CTbyte flag,char *prefix)
{
	int i = 0;
	for (;i < (int)Msg_Content_lenth;i++)
	{
		if (Msg_Content[i] != flag)
		{
			prefix[i] = Msg_Content[i]; 
			continue;
		}
		else
			break;
	}
	prefix[i] = NULL;
	return RTCS_Error_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -