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
97 lines
2.5 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 12/11/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgGatewaySocketClient.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgGatewaySocketClient.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LgReportSocketClient.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
CLgReportSocketClient::CLgReportSocketClient()
|
|
{
|
|
m_bConnected = FALSE;
|
|
m_bDestroying = FALSE;
|
|
}
|
|
|
|
CLgReportSocketClient::~CLgReportSocketClient()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
BOOL CLgReportSocketClient::Create( INT nProvider, LPCTSTR pAddress, WORD wPort )
|
|
{
|
|
m_nProvider = nProvider;
|
|
|
|
_tcsncpy( m_pHostAddress, pAddress, MAX_PATH );
|
|
m_nHostPort = wPort;
|
|
|
|
if( !CLgSocketClient<CLgReportSocket>::Create( pAddress, wPort ) )
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CLgReportSocketClient::Destroy()
|
|
{
|
|
m_bDestroying = TRUE;
|
|
|
|
CLgSocketClient<CLgReportSocket>::Destroy();
|
|
}
|
|
|
|
void CLgReportSocketClient::OnConnect( int nErrorCode )
|
|
{
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CLgReportSocketClient::OnConnect"), _T("%d"), nErrorCode );
|
|
|
|
if( nErrorCode )
|
|
{
|
|
// perform reconnect
|
|
if( !m_bDestroying )
|
|
{
|
|
if( !CLgSocketClient<CLgReportSocket>::Create( m_pHostAddress, m_nHostPort ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportSocketClient::OnConnect"), _T("CLgSocketClient<CLgReportSocket>::Create failed") );
|
|
}
|
|
}
|
|
|
|
CLgSocketClient<CLgReportSocket>::OnConnect( nErrorCode );
|
|
return;
|
|
}
|
|
|
|
// call base class handler
|
|
CLgSocketClient<CLgReportSocket>::OnConnect( nErrorCode );
|
|
|
|
// notify providers about connection
|
|
DispatchClientConnect( m_nProvider, TRUE );
|
|
}
|
|
|
|
void CLgReportSocketClient::OnClose( int nErrorCode )
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgReportSocketClient::OnClose"), _T("%d"), nErrorCode );
|
|
|
|
// perform reconnect
|
|
if( !m_bDestroying )
|
|
CLgSocketClient<CLgReportSocket>::Create( m_pHostAddress, m_nHostPort );
|
|
|
|
CLgSocketClient<CLgReportSocket>::OnClose( nErrorCode );
|
|
|
|
// notify providers about disconnection
|
|
DispatchClientConnect( m_nProvider, FALSE );
|
|
}
|
|
|
|
void CLgReportSocketClient::Dispatch( PLG_REPORT_PACKET pPacket )
|
|
{
|
|
DispatchClientPacket( m_nProvider, pPacket );
|
|
}
|