|
|
//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright � 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: LgRemoteServerTcpIpConnection.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of LgRemoteServerTcpIpConnection.cpp
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "..\Version.h"
#include "LgRemoteServerTcpIp.h"
#include "LgRemoteServerTcpIpConnection.h"
#include "LgRemoteServerTcpIpSession.h"
#include "..\..\LgLib\LgImageJPEG.h"
CLgRemoteServerTcpIpConnection::CLgRemoteServerTcpIpConnection( CLgRemoteServerTcpIp *pServer ) : CLgSocketServerConnection<CLgRemoteSocket>( pServer ){ m_bMasterType = FALSE;
static INT gConnectionID = 0; m_nConnectionID = gConnectionID++;
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgRemoteServerTcpIpConnection::CLgRemoteServerTcpIpConnection" );}
CLgRemoteServerTcpIpConnection::~CLgRemoteServerTcpIpConnection(){ ConnectionToSessionMasterLinkSP::Unlink(); ConnectionToSessionSlaveLinkSP::Unlink();
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgRemoteServerTcpIpConnection::~CLgRemoteServerTcpIpConnection" );}
void CLgRemoteServerTcpIpConnection::OnPacketSessionInfo( PLG_TCP_PACKET_SESSION_INFO pReceivePacket ) { CLgRemoteServerTcpIp *pServer = (CLgRemoteServerTcpIp*)GetServer(); if( !pServer ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketSessionInfo"), _T("pServer is NULL") ); return; } // prepare session list
LG_TCP_PACKET_SESSION_INFO::PSESSION_INFO_DATA pSessionInfo = NULL; INT nSessionInfoSize = 0; if( !pServer->GetSessionList( pReceivePacket->eSessionType, &pSessionInfo, &nSessionInfoSize ) ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketSessionInfo"), _T("pServer->GetSessionList failed") ); return; }
// send info back to socket
if( !SendServerSessionList( pReceivePacket->eSessionType, pSessionInfo, nSessionInfoSize ) ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketSessionInfo"), _T("SendServerSessionList failed") ); }
// free buffer
if( pSessionInfo ) free( pSessionInfo );}
void CLgRemoteServerTcpIpConnection::OnPacketConnect( PLG_TCP_PACKET_CONNECT pReceivePacket ){ CLgRemoteServerTcpIp *pServer = (CLgRemoteServerTcpIp*)GetServer(); if( !pServer ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketConnect"), _T("pServer is NULL") ); return; }
// lock links
CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() ); CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() ); // get session pointer
CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() : ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL );
// assign new session
if( !pSession ) { // assign session for this connect
BOOL bResult = pServer->AssignSession( this, &pReceivePacket->nSessionID, pReceivePacket->eConnectType, pReceivePacket->eSessionType );
SetType( pReceivePacket->eConnectType == LG_REMOTE_E_CONNECT_TYPE_MASTER );
// return data back
if( !SendServerConnect( pReceivePacket->eSessionType, bResult ? pReceivePacket->nSessionID : -1, pReceivePacket->eConnectType, GetConnectionID() ) ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketConnect"), _T("SendServerConnect 1 failed") ); } } else { if( !SendServerConnect( pReceivePacket->eSessionType, pSession->GetSessionID(), pReceivePacket->eConnectType, GetConnectionID() ) ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketConnect"), _T("SendServerConnect 2 failed") ); } }}
void CLgRemoteServerTcpIpConnection::OnPacketVideo( PLG_TCP_PACKET_VIDEO pReceivePacket ){ CLgLocker Locker( this );
// lock links
CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() ); CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() ); // get session pointer
CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() : ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL ); if( !pSession ) { LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgRemoteServerTcpIpConnection::OnPacketVideo"), _T("pSession is NULL") ); return; }
// dispatch in session
if( !pSession->Dispatch( this, pReceivePacket ) ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketVideo"), _T("pSession->Dispatch failed") ); }}
void CLgRemoteServerTcpIpConnection::OnPacketLGS( PLG_TCP_PACKET_LGS pReceivePacket ){ // lock links
CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() ); CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() ); // get session pointer
CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() : ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL ); if( !pSession ) { LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgRemoteServerTcpIpConnection::OnPacketLGS"), _T("pSession is NULL") ); return; }
// dispatch in session
if( !pSession->Dispatch( this, pReceivePacket ) ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketLGS"), _T("pSession->Dispatch failed") ); }}
void CLgRemoteServerTcpIpConnection::OnPacketPTZ( PLG_TCP_PACKET_PTZ pReceivePacket ){ // lock links
CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() ); CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() ); // get session pointer
CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() : ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL ); if( !pSession ) { LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgRemoteServerTcpIpConnection::OnPacketPTZ"), _T("pSession is NULL") ); return; }
// dispatch in session
if( !pSession->Dispatch( this, pReceivePacket ) ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketPTZ"), _T("pSession->Dispatch failed") ); }}
void CLgRemoteServerTcpIpConnection::OnPacketReport( PLG_TCP_PACKET_REPORT pReceivePacket ){ // lock links
CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() ); CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() ); // get session pointer
CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() : ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL ); if( !pSession ) { LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgRemoteServerTcpIpConnection::OnPacketReport"), _T("pSession is NULL") ); return; }
// dispatch in session
if( !pSession->Dispatch( this, pReceivePacket ) ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketReport"), _T("pSession->Dispatch failed") ); }}
void CLgRemoteServerTcpIpConnection::OnPacketBoardReceiver( PLG_TCP_PACKET_BOARD_RECEIVER pReceivePacket ) { // lock links
CLgLocker LockMaster( &ConnectionToSessionMasterLinkSP::GetLock() ); CLgLocker LockSlave( &ConnectionToSessionSlaveLinkSP::GetLock() ); // get session pointer
CLgRemoteServerTcpIpSession *pSession = ConnectionToSessionMasterLinkSP::GetLinkThis() ? ConnectionToSessionMasterLinkSP::GetLinkThis() : ( ConnectionToSessionSlaveLinkSP::GetLinkThis() ? ConnectionToSessionSlaveLinkSP::GetLinkThis() : NULL ); if( !pSession ) { LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgRemoteServerTcpIpConnection::OnPacketBoardReceiver"), _T("pSession is NULL") ); return; }
// dispatch in session
if( !pSession->Dispatch( this, pReceivePacket ) ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgRemoteServerTcpIpConnection::OnPacketBoardReceiver"), _T("pSession->Dispatch failed") ); }}
|