升龙物业 老版本 ocx IPO, 加密狗 转值班电话

ClientAssistant.cpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #include "StdAfx.h"
  2. #include "ClientAssistant.h"
  3. #include "NetClient.h"
  4. #include "NetLinkMain.h"
  5. CClientAssistant::CClientAssistant(bool IsAutoReconnect) : m_pParent(NULL), m_IsAutoReconnect(IsAutoReconnect),
  6. m_LinkType(PDU_LINK_TYPE_SERVER), m_FarPort(0), m_FarDevType(PDU_DEV_TYPE_UNKNOWN), m_FarDevId(-1)
  7. {
  8. }
  9. CClientAssistant::~CClientAssistant(void)
  10. {
  11. }
  12. /*****************************************************************
  13. **【函数名称】 __onTimerListen
  14. **【函数功能】 心跳定时器处理函数
  15. **【参数】
  16. **【返回值
  17. ****************************************************************/
  18. void CClientAssistant::__onTimerListen( void )
  19. {
  20. m_pParent->monitor();
  21. }
  22. /*****************************************************************
  23. **【函数名称】 __onTimerRecon
  24. **【函数功能】 重连定时器处理函数
  25. **【参数】
  26. **【返回值
  27. ****************************************************************/
  28. void CClientAssistant::__onTimerRecon( void )
  29. {
  30. m_pParent->__connect(m_FarIp, m_FarPort);
  31. }
  32. /*****************************************************************
  33. **【函数名称】 __setTimer
  34. **【函数功能】 设立定时器
  35. **【参数】
  36. **【返回值
  37. ****************************************************************/
  38. void CClientAssistant::__setTimer( UINT TimmerId )
  39. {
  40. if(TimmerId == PDU_RECONN_TIMER)
  41. {
  42. m_Timer.Stop();
  43. m_Timer.SetTimedEvent(this, &CClientAssistant::__onTimerRecon);
  44. m_Timer.Start(VAL_RECONNECT_INTERVAL, false, true);
  45. }
  46. else if(TimmerId == PDU_LISTEN_TIMER)
  47. {
  48. m_Timer.Stop();
  49. m_Timer.SetTimedEvent(this, &CClientAssistant::__onTimerListen);
  50. m_Timer.Start(VAL_LISTEN_INTERVAL);
  51. }
  52. else
  53. {
  54. ASSERT(FALSE);
  55. }
  56. }
  57. /*****************************************************************
  58. **【函数名称】 __killTimer
  59. **【函数功能】 删除定时器
  60. **【参数】
  61. **【返回值
  62. ****************************************************************/
  63. void CClientAssistant::__killTimer( UINT TimmerId )
  64. {
  65. m_Timer.Stop();
  66. }
  67. /*****************************************************************
  68. **【函数名称】 getFarLinkInfo
  69. **【函数功能】 读取远端连接信息
  70. **【参数】
  71. **【返回值】 a_strIp SOCKET对端IP
  72. a_nPort SOCKET对端PORT
  73. ****************************************************************/
  74. void CClientAssistant::getFarLinkInfo( CString& a_FarIp, int& a_FarPort ) const
  75. {
  76. a_FarIp = m_FarIp;
  77. a_FarPort = m_FarPort;
  78. }
  79. /*****************************************************************
  80. **【函数名称】 setFarLinkInfo
  81. **【函数功能】 设置远端连接信息
  82. **【参数】
  83. **【返回值】
  84. ****************************************************************/
  85. void CClientAssistant::setFarLinkInfo( LPCTSTR a_FarIp, int a_FarPort )
  86. {
  87. m_FarIp = a_FarIp;
  88. m_FarPort = a_FarPort;
  89. }
  90. /*****************************************************************
  91. **【函数名称】 getFarDevInfo
  92. **【函数功能】 读取远端设备信息
  93. **【参数】
  94. **【返回值】 a_nDevType 对端设备类型
  95. a_nDevId 对端设备ID
  96. ****************************************************************/
  97. void CClientAssistant::getFarDevInfo( PDU_DEV_TYPE& a_DevType, int& a_DevId ) const
  98. {
  99. a_DevType = m_FarDevType;
  100. a_DevId = m_FarDevId;
  101. }
  102. /*****************************************************************
  103. **【函数名称】 setFarDevInfo
  104. **【函数功能】 设置对端设备信息
  105. **【参数】
  106. **【返回值】
  107. ****************************************************************/
  108. void CClientAssistant::setFarDevInfo( PDU_DEV_TYPE a_DevType, int a_DevId )
  109. {
  110. m_FarDevType = a_DevType;
  111. m_FarDevId = a_DevId;
  112. }
  113. /*****************************************************************
  114. **【函数名称】 OnConnEstablisthed
  115. **【函数功能】 SOCKET连接建立事件处理
  116. **【参数】
  117. **【返回值】
  118. ****************************************************************/
  119. void CClientAssistant::onConnEstablisthed( void )
  120. {
  121. ASSERT(m_pParent != NULL);
  122. if(m_LinkType == PDU_LINK_TYPE_CLIENT) // 客户端
  123. m_pParent->regist(); // 注册连接
  124. }
  125. /*****************************************************************
  126. **【函数名称】 onConnFailed
  127. **【函数功能】 连接断开/失败事件处理
  128. **【参数】
  129. **【返回值】
  130. ****************************************************************/
  131. void CClientAssistant::onConnFailed( void )
  132. {
  133. __killTimer(PDU_LISTEN_TIMER);
  134. if(m_LinkType == PDU_LINK_TYPE_CLIENT && m_IsAutoReconnect) // 如果是客户端连接,则启动自动重连
  135. {
  136. __setTimer(PDU_RECONN_TIMER); // 启动自动重连定时器
  137. }
  138. }
  139. /*****************************************************************
  140. **【函数名称】 onConnRegistOK
  141. **【函数功能】 连接注册成功事件处理
  142. **【参数】
  143. **【返回值】
  144. ****************************************************************/
  145. void CClientAssistant::onConnRegistOK( void )
  146. {
  147. ASSERT(m_pParent != NULL);
  148. // 对OCX、SC客户端以外的所有设备端启用心跳监听
  149. PDU_DEV_TYPE a_nDevType = PDU_DEV_TYPE_UNKNOWN;
  150. int a_nDevId = 0;
  151. m_pParent->getLocalInfo(a_nDevType, a_nDevId);
  152. if(a_nDevType != PDU_DEV_TYPE_UNKNOWN && a_nDevType != PDU_DEV_TYPE_AGENT && a_nDevType != PDU_DEV_TYPE_SC_CLIENT)
  153. {
  154. __setTimer(PDU_LISTEN_TIMER);
  155. }
  156. }
  157. /*****************************************************************
  158. **【函数名称】 onConnRegistFailed
  159. **【函数功能】 连接注册失败事件处理
  160. **【参数】
  161. **【返回值】
  162. ****************************************************************/
  163. void CClientAssistant::onConnRegistFailed( void )
  164. {
  165. ASSERT(m_pParent != NULL);
  166. TRACE(_T("Do Nothing @CClientAssistant::onConnRegistFailed"));
  167. }