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.

97 lines
2.5 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: 12/11/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgGatewaySocketClient.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgGatewaySocketClient.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgReportSocketClient.h"
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char THIS_FILE[]=__FILE__;
  19. #define new DEBUG_NEW
  20. #endif
  21. CLgReportSocketClient::CLgReportSocketClient()
  22. {
  23. m_bConnected = FALSE;
  24. m_bDestroying = FALSE;
  25. }
  26. CLgReportSocketClient::~CLgReportSocketClient()
  27. {
  28. Destroy();
  29. }
  30. BOOL CLgReportSocketClient::Create( INT nProvider, LPCTSTR pAddress, WORD wPort )
  31. {
  32. m_nProvider = nProvider;
  33. _tcsncpy( m_pHostAddress, pAddress, MAX_PATH );
  34. m_nHostPort = wPort;
  35. if( !CLgSocketClient<CLgReportSocket>::Create( pAddress, wPort ) )
  36. return FALSE;
  37. return TRUE;
  38. }
  39. void CLgReportSocketClient::Destroy()
  40. {
  41. m_bDestroying = TRUE;
  42. CLgSocketClient<CLgReportSocket>::Destroy();
  43. }
  44. void CLgReportSocketClient::OnConnect( int nErrorCode )
  45. {
  46. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CLgReportSocketClient::OnConnect"), _T("%d"), nErrorCode );
  47. if( nErrorCode )
  48. {
  49. // perform reconnect
  50. if( !m_bDestroying )
  51. {
  52. if( !CLgSocketClient<CLgReportSocket>::Create( m_pHostAddress, m_nHostPort ) )
  53. {
  54. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportSocketClient::OnConnect"), _T("CLgSocketClient<CLgReportSocket>::Create failed") );
  55. }
  56. }
  57. CLgSocketClient<CLgReportSocket>::OnConnect( nErrorCode );
  58. return;
  59. }
  60. // call base class handler
  61. CLgSocketClient<CLgReportSocket>::OnConnect( nErrorCode );
  62. // notify providers about connection
  63. DispatchClientConnect( m_nProvider, TRUE );
  64. }
  65. void CLgReportSocketClient::OnClose( int nErrorCode )
  66. {
  67. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgReportSocketClient::OnClose"), _T("%d"), nErrorCode );
  68. // perform reconnect
  69. if( !m_bDestroying )
  70. CLgSocketClient<CLgReportSocket>::Create( m_pHostAddress, m_nHostPort );
  71. CLgSocketClient<CLgReportSocket>::OnClose( nErrorCode );
  72. // notify providers about disconnection
  73. DispatchClientConnect( m_nProvider, FALSE );
  74. }
  75. void CLgReportSocketClient::Dispatch( PLG_REPORT_PACKET pPacket )
  76. {
  77. DispatchClientPacket( m_nProvider, pPacket );
  78. }