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

📄 ~cngpconn.~h

📁 SMAL是short message abstract library的缩写,是由风起水流软件工作室(www.zealware.com)开发的一个支持短信网关系统开发的C++底层抽象接口库
💻 ~H
📖 第 1 页 / 共 2 页
字号:
	/**得到发送失败的SUBMIT消息数 
	*/
	long GetSubmitFailedCount() const
	{	return submitFailedCountTotal;		}

	/**得到失败的SUBMITResponse消息数 
	*/
	long GetRespFailedCount() const
	{	return respFailedCountTotal;		}

	/**得到成功的SUBMITResponse消息数 
	*/
	long GetRespSucceedCount() const
	{	return respSucceedCountTotal;		}

	/**得到收到的Deliver消息数 
	*/
	long GetDeliverCount() const
	{	return deliverCountTotal;		}

	/**得到收到的StatusReport消息数 
	*/
	long GetStatusReportCount() const
	{	return sreportCountTotal;		}
	//@}

	/**@name Main Functions */
	//@{
	/**创建一个连接token 
	*/
	const char * CreateToken() const;

	//virtual void DumpStatus();

	/**初始化Client函数.
	注意: 每个Client在进行所有操作之前必须调用Initialize()进行初始化操作
	*/
	void Initialize(
		unsigned nMinWorkThreadsCount = 4,
		unsigned nMaxWorkThreadsCount = 8,
		unsigned short nListenPort = 11357
		);

	/**记录Client日志信息和connection日志信息,默认将所有信息发送到调试窗口(Debug模式下) 
	*/
	virtual void OnLogWrite(const char * pchFmt, ...);

	/**建立一个连接 
	*/
	CNGPConnection * MakeConnection(
		const char * _smghost,
		const unsigned short & _smgport,
		const unsigned char	& _smgversion,
		const char * _username,
		const char * _password,
		const ConnectionType & _conntype,
		const int & _nActivetestInterval,
		const char * _localhost = NULL,
		const unsigned short & _localport = 0,
		BOOL sync = TRUE
		);

	/**停止网关服务
	 */
	virtual void Release();

	/**清除连接 
	*/
	void ClearConnection(const char * token);

	/**清除当前Client中的所有连接 
	*/
	void ClearAllConnections();

	/**找到第一个可用的连接 
	*/
	CNGPConnection * firstFitRouter(int start);

	/**循环使用可用的连接 
	*/
	CNGPConnection * roundRobinRouter();

	/**发送一条Submit消息 
	*/
	int Submit(cngp_submit & message);
	//@}

	/**@name Callback functions */
	//@{
	/**登录网关成功时调用 
	*/
	virtual void OnConnectionLogined(CNGPConnection & connection) {
		return;
	}

	/**登录网关失败时调用 
	*/
	virtual void OnConnectionLoginFailed(
		CNGPConnection & connection,
		int errorCode
		) {
		return;
	}

	/**同网关连接断开时调用 
	*/
	virtual void OnConnectionCleared(CNGPConnection & connection) {
		return;
	}

	/**发送SUBMIT消息前调用,如果返回失败,则停止发送SUBMIT消息.
	在这里,只是简单地返回TRUE.
	*/
	virtual BOOL OnConnectionSubmiting(
		CNGPConnection & connection,
		cngp_submit _message
		) {
		return TRUE;
	}

	/**发送SUBMIT消息成功时调用 
	*/
	virtual void OnConnectionSubmited(
		CNGPConnection & connection,
		cngp_submit _message
		) {
		return;
	}

	/**发送SUBMIT消息失败时调用 
	*/
	virtual void OnConnectionSubmitFailed(
		CNGPConnection & connection,
		cngp_submit _message
		) {
		return;
	}

	/**收到CONNECT_RESPONSE时调用 
	*/
	virtual void OnReceivedConnectionConnectResponse(
		CNGPConnection & connection,
		cngp_login_resp _message
		) {
		return;;
	}

	/**收到Terminate消息时调用 
	*/
	virtual void OnReceivedConnectionTerminate(CNGPConnection & connection) {
		return;
	}

	/**收到SUBMIT_RESPONSE时调用 
	*/
	virtual void OnReceivedConnectionSubmitResponse(
		CNGPConnection & connection,
		cngp_submit_deliver_resp _message
		) {
		return;
	}

	/**收到Deliver消息时调用 
	*/
	virtual void OnReceivedConnectionDeliver(
		CNGPConnection & connection,
		cngp_deliver _message
		) {
		return;
	}

	/**收到STATUS_REPORT时调用 
	*/
	virtual void OnReceivedConnectionStatusReport(
		CNGPConnection & connection,
		cngp_deliver _message
		) {
		return;
	}

	/**收到活动测试消息时调用 
	*/
	virtual void OnReceivedConnectionActiveTest(CNGPConnection & connection) {
		return;
	}

	/**收到活动测试回复消息时调用 
	*/
	virtual void OnReceivedConnectionActiveTestResponse(CNGPConnection & connection) {
		return;
	}

	/**输出日志时调用
	格式化输出日志,默认是把内容//TRACE出来
	*/
	virtual void OnConnectionLogWrite(CNGPConnection & connection, const char * str);

	/** 当没有可用连接时调用
	*/
	virtual void OnNoAvailableConnection( cngp_submit & _message ) {
		::InterlockedIncrement((long*)&submitFailedCountTotal);
		return;
	}
	//@}

public:
	/**@name JobProcess functions */
	//@{
	/**发送SUBMIT消息前调用,如果返回失败,则停止发送SUBMIT消息.
	在这里,只是简单地返回TRUE.
	*/
	BOOL ProcessConnectionSubmiting(
		CNGPConnection & connection,
		cngp_submit _message
		);

	/**发送SUBMIT消息成功时调用 
	*/
	void ProcessConnectionSubmited(
		CNGPConnection & connection,
		cngp_submit _message
		);

	/**发送SUBMIT消息失败时调用 
	*/
	void ProcessConnectionSubmitFailed(
		CNGPConnection & connection,
		cngp_submit _message
		);

	/**收到CONNECT_RESPONSE时调用 
	*/
	void ProcessReceivedConnectionConnectResponse(
		CNGPConnection & connection,
		cngp_login_resp _message
		);

	/**收到Terminate消息时调用 
	*/
	void ProcessReceivedConnectionTerminate(CNGPConnection & connection);

	/**收到SUBMIT_RESPONSE时调用 
	*/
	void ProcessReceivedConnectionSubmitResponse(
		CNGPConnection & connection,
		cngp_submit_deliver_resp _message
		);

	/**收到Deliver消息时调用 
	*/
	void ProcessReceivedConnectionDeliver(
		CNGPConnection & connection,
		cngp_deliver _message
		);

	/**收到STATUS_REPORT时调用 
	*/
	void ProcessReceivedConnectionStatusReport(
		CNGPConnection & connection,
		cngp_deliver _message
		);

	/**收到活动测试消息时调用 
	*/
	void ProcessReceivedConnectionActiveTest(CNGPConnection & connection);

	/**收到活动测试回复消息时调用 
	*/
	void ProcessReceivedConnectionActiveTestResponse(CNGPConnection & connection);

	unsigned short GetLocalPort() {
		long returnPort = ::InterlockedIncrement((long*)&ushLocalPort);
		if (returnPort - ushLocalPort > 1000) {
			ushLocalPort -= 1000;
		}

		return 	(unsigned short)returnPort;
	}

protected:
	CThreadPool       m_pool;
	CWorkerCngp       m_worker;
	CJobCngp          * m_pJob;
	aList             connectionList;
	MyCriticalSection listLock;
	CNGPConnection    * lastPick;
	int               m_nMinWorkThreadsCount;
	int	              m_nMaxWorkThreadsCount;
	BOOL              m_fStarted;   ///< 线程池是否已经启动
	BOOL              m_fExceeded;

	long submitCountTotal;			///< 提交的SUBMIT消息数
	long submitSucceedCountTotal;	///< SUBMIT发送成功消息数
	long submitFailedCountTotal;	///< SUBMIT发送失败消息数
	long respSucceedCountTotal;		///< 收到的成功的submitresponse消息数
	long respFailedCountTotal;		///< 收到的失败的submitresponse消息数
	long deliverCountTotal;			///< 收到的Deliver消息数
	long sreportCountTotal;			///< 状态报告数

	long ushLocalPort;				///< 本地监听起始端口
};

class CNGPServer;

/**
* CJob_CngpServer
*/
class CJob_CngpServer : public IJobDesc {
public:
	CJob_CngpServer(
		cngp_sptosmg _message,
		CNGPServer	& _server, 
		JobType _type
		);

	~CJob_CngpServer();

	void OnSPMsg();

	JobType type;

protected:
	CNGPServer & server;
	cngp_sptosmg spMsg;
	int	nResult;
};

class CWorker_CngpServer : public IWorker {
	virtual void ProcessJob( IJobDesc* pJobDesc );
};

struct cngpsrvthread_param {
	CNGPServer* csServer;
	TCPSocket*	tsClient;
};

/** CNGP服务端实现
*/
class CNGPServer : public CCngp {
public:
	TCPSocket	m_TsServer;        ///< Server端SOCKET句柄
	int         m_nLocalPort;      ///< 本地监听端口
	char		m_sLocalAddr[16];  ///< 本地监听地址
	bool		m_fStop;           ///< 是否停止系统
	int			m_nSocketTimeout;  ///< SOCKET超时时间
	client_conn	conn_list[255];    ///< 客户端连接列表
	int			m_nConnectTotal;   ///< 客户端连接数
	HANDLE		m_hThread;         ///< 
	BOOL		m_fStarted;        ///< 服务端是否启动

	virtual void OnReceivedSPMessage( CNGP_SPTOSMG css ) {
		return;
	}

	virtual BOOL OnLogin( 
		cngp_login & login_message,       ///< 接收到的CNGP_LOGIN消息
		const char * clientAddress,       ///< 客户端的IP地址
		char * spid                       ///< 如果鉴权成功,返回该用户的接入号
		) 
	{
		return TRUE;
	}

	CThreadPool	        m_pool;
	CWorker_CngpServer  m_worker;
	CJob_CngpServer     * m_pJob;

protected:
	int LocalListen();

	static DWORD WINAPI CngpServFunc( LPVOID pParam );
	virtual DWORD CngpServProc();

	static DWORD WINAPI CngpClientFunc( LPVOID pParam );
	virtual DWORD CngpClientProc( TCPSocket* tsClient );


	int RecvSPMsg( 
		TCPSocket * tsClient,
		cngp_sptosmg * css, 
		unsigned & nResult 
		);

	SOCKET GetFromList( const char * sIcpid );
	void RemoveFromList( SOCKET hClient );
	void AddToList(
		SOCKET hClient, 
		const char * sIcpid, 
		const char * sSpid, 
		ConnectionType type
		);

	bool IsLogined(
		const char * sSpId, 
		SOCKET &hSock
		);

	virtual void OnLogWrite( const char * fmt, ... );
public:
	CNGPServer();
	~CNGPServer();

	void CreateCngpMsgID( unsigned seqid, unsigned char * msgid );

	int Start(
		const char     * server_addr, 
		unsigned short ushServport, 
		int            nSocketTimeout
		);

	void Release();

	int Deliver(
		char          * sMsgId, 
		unsigned char isReport,
		unsigned char uchMsgFmt, 
		char          * recvTime,
		char          * srcTermID, 
		char          * dstTermID, 
		unsigned char uchMsgLength, 
		char          * pchMsgContent
		);
};

#endif

⌨️ 快捷键说明

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