123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #pragma once
- #include <afxwin.h>
- //#include <atlbase.h>
- #pragma warning(push)
- #pragma warning(disable:4995)
- #include <list>
- #pragma warning(pop)
- #include "CritSection.h"
- #include "SocketHandle.h"
- #include "SocketServerImpl.h"
- #if defined(SOCKHANDLE_USE_OVERLAPPED)
- #include "AsyncSocketServerImpl.h"
- #endif
- #include "Global.h"
- #include "BaseVar.h"
- namespace ServerSocket
- {
- typedef std::list<SOCKET> CSocketList;
- class CServerSocket :
- public CDialog,
- public ISocketServerHandler
- {
- #if defined(SOCKHANDLE_USE_OVERLAPPED)
- typedef ASocketServerImpl<ISocketServerHandler> CSocketServer;
- #else
- typedef SocketServerImpl<ISocketServerHandler> CSocketServer;
- #endif
- friend CSocketServer; // 模板类;
- protected:
- // ISocketServerHandler
- virtual void OnThreadBegin(CSocketHandle* pSH);
- virtual void OnThreadExit(CSocketHandle* pSH);
- virtual void OnAddConnection(CSocketHandle* pSH, SOCKET newSocket);
- virtual void OnDataReceived(CSocketHandle* pSH, const BYTE* pbData, DWORD dwCount, const SockAddrIn& addr);
- virtual void OnConnectionFailure(CSocketHandle* pSH, SOCKET newSocket);
- virtual void OnConnectionDropped(CSocketHandle* pSH);
- virtual void OnConnectionError(CSocketHandle* pSH, DWORD dwError);
- protected:
- void GetAddress(const SockAddrIn& addrIn, CString& rString) const;
- bool GetDestination(SockAddrIn& addrIn) const;
- public:
- CServerSocket(void);
- ~CServerSocket(void);
- public:
- int SvrStart(CString strPort);
- void SocketStop();
- void SocketSend(CSocketHandle &sockHandle, unsigned char *pMsg, int iLength);
- protected:
- int m_nSockType;
- int m_nMode;
- void ProcessData(CSocketHandle &sockHandle, const BYTE* pData, DWORD nLen);
- int OnCmdProcess(CSocketHandle &sockHandle, void *pData);
- int ProcessResDevOnline(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResSingleVarOnline(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResMulVarOnline(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResReadSingleVarData(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResReadMulVarData(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResWriteSingleVarData(CSocketHandle &sockHandle, void *pBuffer);
- int PrcocessResWriteMulVarData(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResSoftDog(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResAlarmConfirm(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResReadSpecSingleVarData(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessResReadSpecMulVarData(CSocketHandle &sockHandle, void *pBuffer);
- #if 0
- int ProcessHeart(CSocketHandle &sockHandle, void *pBuffer);
- #endif
- //重新读取数据库通知
- int ProcessNoticeReadDBVar(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessNoticeReadDBDev(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessNoticeReadDBUser(CSocketHandle &sockHandle, void *pBuffer);
- int ProcessNoticeTestAlarm(CSocketHandle &sockHandle, void *pBuffer);
- //主动发变量的值给客户端 没有简单变量,特殊变量之分
- int ProcessAutoSendVarDataToClient(CSocketHandle &sockHandle, CBaseVar *pBaseVar );
- //主支发报警信息给客户端
- int ProcessAutoSendAlarmDataToClient( CSocketHandle &sockHandle,CHAR *pDevUid, int nVarID, int iStatus,CHAR *pContent
- ,double dbParaValue, int nUpperLimit,int nLowerLimit, int nNormalState,int nAlarmState,int nAlarmIndex );
- public:
- void AutoSendDataToAllClient( CBaseVar *pBaseVar );
- void AutoSendAlarmDataToClient( CHAR *pDevUid, int iVarID, int iStatus,CHAR *pContent
- ,double dbParaValue, int nUpperLimit,int nLowerLimit, int nNormalState,int nAlarmState,int nAlarmIndex );
- CSocketServer m_SocketServer; // 模板类对象;
- int m_nSocketIndex;
- CRITICAL_SECTION m_csProcessData;
- };
- extern CServerSocket* g_pServerSocket[MAX_SERVER_LISTEN];
- };
|