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.
347 lines
8.9 KiB
347 lines
8.9 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 09/11/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgReportStorage.h
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Header file of LgReportStorage.h
|
|
//----------------------------------------------------------------------------
|
|
#ifndef __LG__REPORT__ENGINE__H__INCLUDED__
|
|
#define __LG__REPORT__ENGINE__H__INCLUDED__
|
|
|
|
#include "..\LgImageDIB.h"
|
|
#include "..\LgImageJPEG.h"
|
|
#include "..\Thread.h"
|
|
#include "LgReport.h"
|
|
#include "LgReportDlg.h"
|
|
#include "LgReportProvider.h"
|
|
#include "LgReportLoaderRemote.h"
|
|
#include "LgReportSocketServer.h"
|
|
#include "LgReportSocketServerConnection.h"
|
|
#include "LgReportSocketClient.h"
|
|
#include "lgreportsetupsettings.h"
|
|
#include "lgreportsetupdlg.h"
|
|
#include "lgsite.h"
|
|
|
|
class CLgReportRemoteProviderDispatcher
|
|
{
|
|
public:
|
|
virtual BOOL OnClientPacket( INT nProvider, BYTE bPacketType, PVOID pBuffer, INT nBufferSize ) = 0;
|
|
virtual BOOL OnClientConnect( INT nProvider, BOOL bConnected ) = 0;
|
|
};
|
|
|
|
class CLgReportRemoteProviderEx :
|
|
public CLgReportRemoteProvider,
|
|
public CLgReportSocketClient
|
|
{
|
|
public:
|
|
CLgReportRemoteProviderEx()
|
|
{
|
|
m_pDispatcher = NULL;
|
|
m_nProvider = -1;
|
|
}
|
|
virtual ~CLgReportRemoteProviderEx()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
public:
|
|
BOOL Create( CLgReportRemoteProviderDispatcher *pDispatcher, LPCTSTR pName, LPCTSTR pRootPath, INT nProvider, LPCTSTR pAddress, WORD wPort )
|
|
{
|
|
if( !CLgReportRemoteProvider::Create( pName, pRootPath ) )
|
|
return FALSE;
|
|
|
|
m_pDispatcher = pDispatcher;
|
|
m_nProvider = nProvider;
|
|
return CLgReportSocketClient::Create( nProvider, pAddress, wPort );
|
|
}
|
|
void Destroy()
|
|
{
|
|
__try
|
|
{
|
|
CLgReportRemoteProvider::Destroy();
|
|
CLgReportSocketClient::Destroy();
|
|
m_pDispatcher = NULL;
|
|
}
|
|
__except( EXCEPTION_EXECUTE_HANDLER )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportRemoteProviderEx::Destroy"), _T("Exception 0x%08X"), _exception_code() );
|
|
}
|
|
}
|
|
|
|
public:
|
|
virtual BOOL SendToClient( PVOID pBuffer, INT nCount )
|
|
{
|
|
LG_REPORT_PACKET packet;
|
|
packet.bType = 0x01;
|
|
packet.nLength = sizeof(packet) + nCount;
|
|
return Send2( &packet, sizeof(packet), pBuffer, nCount );
|
|
}
|
|
|
|
public:
|
|
virtual void DispatchClientPacket( INT nProvider, PLG_REPORT_PACKET pPacket )
|
|
{
|
|
m_pDispatcher->OnClientPacket( nProvider, pPacket->bType, pPacket + 1, pPacket->nLength );
|
|
}
|
|
|
|
virtual void DispatchClientConnect( INT nProvider, BOOL bConnected )
|
|
{
|
|
m_pDispatcher->OnClientConnect( nProvider, bConnected );
|
|
}
|
|
|
|
private:
|
|
INT m_nProvider;
|
|
CLgReportRemoteProviderDispatcher *m_pDispatcher;
|
|
};
|
|
|
|
class CLgReportRemoteClientDispatcher
|
|
{
|
|
public:
|
|
virtual BOOL OnServerPacket( PVOID pConnection, BYTE bPacketType, PVOID pBuffer, INT nBufferSize ) = 0;
|
|
virtual BOOL OnServerConnect( PVOID pConnection, BOOL bConnected ) = 0;
|
|
};
|
|
|
|
class CLgReportRemoteClientEx :
|
|
public CLgReportRemoteClient,
|
|
public CLgReportSocketServer
|
|
{
|
|
public:
|
|
CLgReportRemoteClientEx() { m_pDispatcher = NULL;}
|
|
virtual ~CLgReportRemoteClientEx() { Destroy(); }
|
|
|
|
public:
|
|
BOOL Create( CLgReportRemoteClientDispatcher *pDispatcher, BOOL bEanble, WORD wPort )
|
|
{
|
|
m_pDispatcher = pDispatcher;
|
|
return bEanble ? CLgReportSocketServer::Create( wPort ) : TRUE;
|
|
}
|
|
void Destroy()
|
|
{
|
|
__try
|
|
{
|
|
CLgReportRemoteClient::Destroy();
|
|
CLgReportSocketServer::Destroy();
|
|
m_pDispatcher = NULL;
|
|
}
|
|
__except( EXCEPTION_EXECUTE_HANDLER )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportRemoteClientEx::Destroy"), _T("Exception 0x%08X"), _exception_code() );
|
|
}
|
|
}
|
|
|
|
public:
|
|
virtual BOOL SendToProvider( PVOID pConnection, PVOID pBuffer, INT nCount )
|
|
{
|
|
LG_REPORT_PACKET packet;
|
|
packet.bType = 0x01;
|
|
packet.nLength = sizeof(packet) + nCount;
|
|
CLgReportSocketServerConnection *pServerConnection = reinterpret_cast<CLgReportSocketServerConnection*>(pConnection);
|
|
return pServerConnection->Send2( &packet, sizeof(packet), pBuffer, nCount );
|
|
}
|
|
|
|
public:
|
|
virtual void DispatchServerPacket( PVOID pConnection, PLG_REPORT_PACKET pPacket )
|
|
{
|
|
m_pDispatcher->OnServerPacket( pConnection, pPacket->bType, pPacket + 1, pPacket->nLength );
|
|
}
|
|
|
|
virtual void DispatchServerConnect( PVOID pConnection, BOOL bConnected, LPSOCKADDR_IN pSockAddr )
|
|
{
|
|
m_pDispatcher->OnServerConnect( pConnection, bConnected );
|
|
}
|
|
|
|
private:
|
|
CLgReportRemoteClientDispatcher *m_pDispatcher;
|
|
};
|
|
|
|
/*
|
|
class CLgReportRemoteLink :
|
|
public CLgThread,
|
|
public CLgReportRemoteProvider,
|
|
public CLgReportRemoteClient
|
|
{
|
|
public:
|
|
CLgReportRemoteLink()
|
|
{
|
|
}
|
|
virtual ~CLgReportRemoteLink()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
public:
|
|
BOOL Create( LPCTSTR pName, LPCTSTR pRootPath )
|
|
{
|
|
if( !CLgReportRemoteProvider::Create( pName, pRootPath ) )
|
|
return FALSE;
|
|
|
|
return Start( FALSE );
|
|
}
|
|
|
|
void Destroy()
|
|
{
|
|
Stop( TRUE );
|
|
|
|
BUFFER_HOLDER bh;
|
|
while( m_QueueClient.Pop( bh ) )
|
|
free( bh.pBuffer );
|
|
while( m_QueueProvider.Pop( bh ) )
|
|
free( bh.pBuffer );
|
|
|
|
CLgReportRemoteProvider::Destroy();
|
|
CLgReportRemoteClient::Destroy();
|
|
}
|
|
|
|
private:
|
|
typedef struct BUFFER_HOLDER
|
|
{
|
|
LPVOID pBuffer;
|
|
INT nCount;
|
|
}BUFFER_HOLDER, *PBUFFER_HOLDER;
|
|
|
|
protected:
|
|
virtual BOOL SendToClient( PVOID pBuffer, INT nCount )
|
|
{
|
|
BUFFER_HOLDER bh;
|
|
bh.pBuffer = malloc( nCount );
|
|
bh.nCount = nCount;
|
|
if( !bh.pBuffer )
|
|
return FALSE;
|
|
|
|
memcpy( bh.pBuffer, pBuffer, nCount );
|
|
|
|
return m_QueueClient.Push( bh );
|
|
// return CLgReportRemoteClient::DispatchRemoteData( 0, pBuffer, nCount );
|
|
}
|
|
|
|
virtual BOOL SendToProvider( PVOID pConnection, PVOID pBuffer, INT nCount )
|
|
{
|
|
BUFFER_HOLDER bh;
|
|
bh.pBuffer = malloc( nCount );
|
|
bh.nCount = nCount;
|
|
if( !bh.pBuffer )
|
|
return FALSE;
|
|
|
|
memcpy( bh.pBuffer, pBuffer, nCount );
|
|
return m_QueueProvider.Push( bh );
|
|
// return CLgReportRemoteProvider::DispatchRemoteData( pBuffer, nCount );
|
|
}
|
|
|
|
private:
|
|
virtual DWORD ThreadProc()
|
|
{
|
|
BUFFER_HOLDER bh;
|
|
HANDLE pHandle[] = { CLgThread::GetThreadStopEvent(), m_QueueClient, m_QueueProvider };
|
|
BOOL bLoop = TRUE;
|
|
while( bLoop )
|
|
{
|
|
switch( ::WaitForMultipleObjects( 3, pHandle, FALSE, INFINITE ) )
|
|
{
|
|
default:
|
|
case WAIT_FAILED:
|
|
|
|
case WAIT_OBJECT_0:
|
|
bLoop = FALSE;
|
|
continue;
|
|
|
|
case WAIT_OBJECT_0+1:
|
|
while( m_QueueClient.Pop( bh ) )
|
|
{
|
|
CLgReportRemoteClient::DispatchRemoteData( 0, bh.pBuffer, bh.nCount );
|
|
free( bh.pBuffer );
|
|
}
|
|
break;
|
|
|
|
case WAIT_OBJECT_0+2:
|
|
while( m_QueueProvider.Pop( bh ) )
|
|
{
|
|
CLgReportRemoteProvider::DispatchRemoteData( bh.pBuffer, bh.nCount );
|
|
free( bh.pBuffer );
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return 0UL;
|
|
}
|
|
|
|
private:
|
|
CLgQueueP<BUFFER_HOLDER,1000> m_QueueProvider;
|
|
CLgQueueP<BUFFER_HOLDER,1000> m_QueueClient;
|
|
};
|
|
*/
|
|
|
|
class CLgReportStorage :
|
|
private CLgReportStorageClient,
|
|
public CLgReportRemoteProviderDispatcher,
|
|
public CLgReportRemoteClientDispatcher
|
|
{
|
|
public:
|
|
CLgReportStorage();
|
|
virtual ~CLgReportStorage();
|
|
|
|
public:
|
|
BOOL Create( LPCTSTR pPathRoot, INT nMaxStorageDays, CLgReportInterface *pInterface );
|
|
void Destroy();
|
|
BOOL Reset();
|
|
|
|
public:
|
|
BOOL StoreEvent( SYSTEMTIME *pST, BYTE bId, BOOL bSensor, WORD wSensorIndex, BOOL bPosition, float x, float y, LARGE_INTEGER *pOffset, LPCTSTR pFormat, va_list pMarker );
|
|
BOOL StoreImage( HBITMAP hBitmap, LARGE_INTEGER *pOffset );
|
|
BOOL StoreImage( CLgImageDIB& dib, LARGE_INTEGER *pOffset );
|
|
BOOL StoreImage( CLgImageJPEG& jpeg, LARGE_INTEGER *pOffset );
|
|
BOOL StoreBackground( CBitmap *pBitmap );
|
|
BOOL StoreBackground( CLgImageDIB& dib );
|
|
BOOL StoreBackground( CLgImageJPEG& jpeg );
|
|
|
|
public:
|
|
BOOL SetMaxStoreTime( INT nDays );
|
|
BOOL OnSensor( LPCTSTR pName, float x, float y );
|
|
BOOL OnFilter( BYTE bId, LPCTSTR pName );
|
|
|
|
private:
|
|
virtual BOOL OnCreateSite();
|
|
virtual BOOL OnAskForDeleteOld();
|
|
|
|
public:
|
|
BOOL Dlg_Create( HWND hParentWnd );
|
|
BOOL Dlg_DoModal( HWND hParentWnd );
|
|
void Dlg_Destroy();
|
|
|
|
public:
|
|
BOOL DlgSetup_DoModal( HWND hParentWnd );
|
|
|
|
private:
|
|
virtual BOOL OnServerPacket( PVOID pConnection, BYTE bPacketType, PVOID pBuffer, INT nBufferSize );
|
|
virtual BOOL OnServerConnect( PVOID pConnection, BOOL bConnected );
|
|
virtual BOOL OnClientPacket( INT nProvider, BYTE bPacketType, PVOID pBuffer, INT nBufferSize );
|
|
virtual BOOL OnClientConnect( INT nProvider, BOOL bConnected );
|
|
|
|
private:
|
|
CLgReportProvider m_ReportProvider;
|
|
CLgArray<CLgReportRemoteProviderEx> m_arrReportProvider;
|
|
CLgReportRemoteClientEx m_ReportClient;
|
|
|
|
private:
|
|
CLgReportInterface *m_pInterface;
|
|
|
|
private:
|
|
CLgReportDlg m_Dialog;
|
|
|
|
private:
|
|
// CLgReportSettings m_Settings;
|
|
|
|
public:
|
|
CLgReportSettings m_SetupSettings;
|
|
CLgReportSetupDlg m_DialogSetup;
|
|
|
|
public:
|
|
CLgSiteManager *m_pSiteManager;
|
|
};
|
|
|
|
#endif
|