Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
8.7 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgRemoteServerTcpIpConnection.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgRemoteServerTcpIpConnection.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\Version.h"
  16. #include "LgRemoteServerTcpIp.h"
  17. #include "LgRemoteServerTcpIpConnection.h"
  18. #include "LgRemoteServerTcpIpSession.h"
  19. #include "..\..\LgLib\LgImageJPEG.h"
  20. CLgRemoteServerTcpIpConnection::CLgRemoteServerTcpIpConnection( CLgRemoteServerTcpIp *pServer ) :
  21. CLgSocketServerConnection<CLgRemoteSocket>( pServer )
  22. {
  23. m_bMasterType = FALSE;
  24. static INT gConnectionID = 0;
  25. m_nConnectionID = gConnectionID++;
  26. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgRemoteServerTcpIpConnection::CLgRemoteServerTcpIpConnection" );
  27. }
  28. CLgRemoteServerTcpIpConnection::~CLgRemoteServerTcpIpConnection()
  29. {
  30. ConnectionToSessionMasterLinkSP::Unlink();
  31. ConnectionToSessionSlaveLinkSP::Unlink();
  32. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgRemoteServerTcpIpConnection::~CLgRemoteServerTcpIpConnection" );
  33. }
  34. void CLgRemoteServerTcpIpConnection::OnPacketSessionInfo( PLG_TCP_PACKET_SESSION_INFO pReceivePacket )
  35. {
  36. CLgRemoteServerTcpIp *pServer = (CLgRemoteServerTcpIp*)GetServer();
  37. if( !pServer )
  38. {
  39. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketSessionInfo"), _T("pServer is NULL") );
  40. return;
  41. }
  42. // prepare session list
  43. LG_TCP_PACKET_SESSION_INFO::PSESSION_INFO_DATA pSessionInfo = NULL;
  44. INT nSessionInfoSize = 0;
  45. if( !pServer->GetSessionList( pReceivePacket->eSessionType, &pSessionInfo, &nSessionInfoSize ) )
  46. {
  47. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketSessionInfo"), _T("pServer->GetSessionList failed") );
  48. return;
  49. }
  50. // send info back to socket
  51. if( !SendServerSessionList( pReceivePacket->eSessionType, pSessionInfo, nSessionInfoSize ) )
  52. {
  53. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketSessionInfo"), _T("SendServerSessionList failed") );
  54. }
  55. // free buffer
  56. if( pSessionInfo )
  57. free( pSessionInfo );
  58. }
  59. void CLgRemoteServerTcpIpConnection::OnPacketConnect( PLG_TCP_PACKET_CONNECT pReceivePacket )
  60. {
  61. CLgRemoteServerTcpIp *pServer = (CLgRemoteServerTcpIp*)GetServer();
  62. if( !pServer )
  63. {
  64. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketConnect"), _T("pServer is NULL") );
  65. return;
  66. }
  67. // lock links
  68. CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() );
  69. CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() );
  70. // get session pointer
  71. CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() :
  72. ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL );
  73. // assign new session
  74. if( !pSession )
  75. {
  76. // assign session for this connect
  77. BOOL bResult = pServer->AssignSession( this, &pReceivePacket->nSessionID, pReceivePacket->eConnectType, pReceivePacket->eSessionType );
  78. SetType( pReceivePacket->eConnectType == LG_REMOTE_E_CONNECT_TYPE_MASTER );
  79. // return data back
  80. if( !SendServerConnect( pReceivePacket->eSessionType, bResult ? pReceivePacket->nSessionID : -1, pReceivePacket->eConnectType, GetConnectionID() ) )
  81. {
  82. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketConnect"), _T("SendServerConnect 1 failed") );
  83. }
  84. }
  85. else
  86. {
  87. if( !SendServerConnect( pReceivePacket->eSessionType, pSession->GetSessionID(), pReceivePacket->eConnectType, GetConnectionID() ) )
  88. {
  89. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketConnect"), _T("SendServerConnect 2 failed") );
  90. }
  91. }
  92. }
  93. void CLgRemoteServerTcpIpConnection::OnPacketVideo( PLG_TCP_PACKET_VIDEO pReceivePacket )
  94. {
  95. CLgLocker Locker( this );
  96. // lock links
  97. CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() );
  98. CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() );
  99. // get session pointer
  100. CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() :
  101. ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL );
  102. if( !pSession )
  103. {
  104. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgRemoteServerTcpIpConnection::OnPacketVideo"), _T("pSession is NULL") );
  105. return;
  106. }
  107. // dispatch in session
  108. if( !pSession->Dispatch( this, pReceivePacket ) )
  109. {
  110. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketVideo"), _T("pSession->Dispatch failed") );
  111. }
  112. }
  113. void CLgRemoteServerTcpIpConnection::OnPacketLGS( PLG_TCP_PACKET_LGS pReceivePacket )
  114. {
  115. // lock links
  116. CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() );
  117. CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() );
  118. // get session pointer
  119. CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() :
  120. ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL );
  121. if( !pSession )
  122. {
  123. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgRemoteServerTcpIpConnection::OnPacketLGS"), _T("pSession is NULL") );
  124. return;
  125. }
  126. // dispatch in session
  127. if( !pSession->Dispatch( this, pReceivePacket ) )
  128. {
  129. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketLGS"), _T("pSession->Dispatch failed") );
  130. }
  131. }
  132. void CLgRemoteServerTcpIpConnection::OnPacketPTZ( PLG_TCP_PACKET_PTZ pReceivePacket )
  133. {
  134. // lock links
  135. CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() );
  136. CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() );
  137. // get session pointer
  138. CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() :
  139. ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL );
  140. if( !pSession )
  141. {
  142. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgRemoteServerTcpIpConnection::OnPacketPTZ"), _T("pSession is NULL") );
  143. return;
  144. }
  145. // dispatch in session
  146. if( !pSession->Dispatch( this, pReceivePacket ) )
  147. {
  148. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketPTZ"), _T("pSession->Dispatch failed") );
  149. }
  150. }
  151. void CLgRemoteServerTcpIpConnection::OnPacketReport( PLG_TCP_PACKET_REPORT pReceivePacket )
  152. {
  153. // lock links
  154. CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() );
  155. CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() );
  156. // get session pointer
  157. CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() :
  158. ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL );
  159. if( !pSession )
  160. {
  161. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgRemoteServerTcpIpConnection::OnPacketReport"), _T("pSession is NULL") );
  162. return;
  163. }
  164. // dispatch in session
  165. if( !pSession->Dispatch( this, pReceivePacket ) )
  166. {
  167. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketReport"), _T("pSession->Dispatch failed") );
  168. }
  169. }
  170. void CLgRemoteServerTcpIpConnection::OnPacketBoardReceiver( PLG_TCP_PACKET_BOARD_RECEIVER pReceivePacket )
  171. {
  172. // lock links
  173. CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() );
  174. CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() );
  175. // get session pointer
  176. CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() :
  177. ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL );
  178. if( !pSession )
  179. {
  180. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgRemoteServerTcpIpConnection::OnPacketBoardReceiver"), _T("pSession is NULL") );
  181. return;
  182. }
  183. // dispatch in session
  184. if( !pSession->Dispatch( this, pReceivePacket ) )
  185. {
  186. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketBoardReceiver"), _T("pSession->Dispatch failed") );
  187. }
  188. }