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.

347 lines
8.9 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: 09/11/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgReportStorage.h
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Header file of LgReportStorage.h
  13. //----------------------------------------------------------------------------
  14. #ifndef __LG__REPORT__ENGINE__H__INCLUDED__
  15. #define __LG__REPORT__ENGINE__H__INCLUDED__
  16. #include "..\LgImageDIB.h"
  17. #include "..\LgImageJPEG.h"
  18. #include "..\Thread.h"
  19. #include "LgReport.h"
  20. #include "LgReportDlg.h"
  21. #include "LgReportProvider.h"
  22. #include "LgReportLoaderRemote.h"
  23. #include "LgReportSocketServer.h"
  24. #include "LgReportSocketServerConnection.h"
  25. #include "LgReportSocketClient.h"
  26. #include "lgreportsetupsettings.h"
  27. #include "lgreportsetupdlg.h"
  28. #include "lgsite.h"
  29. class CLgReportRemoteProviderDispatcher
  30. {
  31. public:
  32. virtual BOOL OnClientPacket( INT nProvider, BYTE bPacketType, PVOID pBuffer, INT nBufferSize ) = 0;
  33. virtual BOOL OnClientConnect( INT nProvider, BOOL bConnected ) = 0;
  34. };
  35. class CLgReportRemoteProviderEx :
  36. public CLgReportRemoteProvider,
  37. public CLgReportSocketClient
  38. {
  39. public:
  40. CLgReportRemoteProviderEx()
  41. {
  42. m_pDispatcher = NULL;
  43. m_nProvider = -1;
  44. }
  45. virtual ~CLgReportRemoteProviderEx()
  46. {
  47. Destroy();
  48. }
  49. public:
  50. BOOL Create( CLgReportRemoteProviderDispatcher *pDispatcher, LPCTSTR pName, LPCTSTR pRootPath, INT nProvider, LPCTSTR pAddress, WORD wPort )
  51. {
  52. if( !CLgReportRemoteProvider::Create( pName, pRootPath ) )
  53. return FALSE;
  54. m_pDispatcher = pDispatcher;
  55. m_nProvider = nProvider;
  56. return CLgReportSocketClient::Create( nProvider, pAddress, wPort );
  57. }
  58. void Destroy()
  59. {
  60. __try
  61. {
  62. CLgReportRemoteProvider::Destroy();
  63. CLgReportSocketClient::Destroy();
  64. m_pDispatcher = NULL;
  65. }
  66. __except( EXCEPTION_EXECUTE_HANDLER )
  67. {
  68. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportRemoteProviderEx::Destroy"), _T("Exception 0x%08X"), _exception_code() );
  69. }
  70. }
  71. public:
  72. virtual BOOL SendToClient( PVOID pBuffer, INT nCount )
  73. {
  74. LG_REPORT_PACKET packet;
  75. packet.bType = 0x01;
  76. packet.nLength = sizeof(packet) + nCount;
  77. return Send2( &packet, sizeof(packet), pBuffer, nCount );
  78. }
  79. public:
  80. virtual void DispatchClientPacket( INT nProvider, PLG_REPORT_PACKET pPacket )
  81. {
  82. m_pDispatcher->OnClientPacket( nProvider, pPacket->bType, pPacket + 1, pPacket->nLength );
  83. }
  84. virtual void DispatchClientConnect( INT nProvider, BOOL bConnected )
  85. {
  86. m_pDispatcher->OnClientConnect( nProvider, bConnected );
  87. }
  88. private:
  89. INT m_nProvider;
  90. CLgReportRemoteProviderDispatcher *m_pDispatcher;
  91. };
  92. class CLgReportRemoteClientDispatcher
  93. {
  94. public:
  95. virtual BOOL OnServerPacket( PVOID pConnection, BYTE bPacketType, PVOID pBuffer, INT nBufferSize ) = 0;
  96. virtual BOOL OnServerConnect( PVOID pConnection, BOOL bConnected ) = 0;
  97. };
  98. class CLgReportRemoteClientEx :
  99. public CLgReportRemoteClient,
  100. public CLgReportSocketServer
  101. {
  102. public:
  103. CLgReportRemoteClientEx() { m_pDispatcher = NULL;}
  104. virtual ~CLgReportRemoteClientEx() { Destroy(); }
  105. public:
  106. BOOL Create( CLgReportRemoteClientDispatcher *pDispatcher, BOOL bEanble, WORD wPort )
  107. {
  108. m_pDispatcher = pDispatcher;
  109. return bEanble ? CLgReportSocketServer::Create( wPort ) : TRUE;
  110. }
  111. void Destroy()
  112. {
  113. __try
  114. {
  115. CLgReportRemoteClient::Destroy();
  116. CLgReportSocketServer::Destroy();
  117. m_pDispatcher = NULL;
  118. }
  119. __except( EXCEPTION_EXECUTE_HANDLER )
  120. {
  121. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportRemoteClientEx::Destroy"), _T("Exception 0x%08X"), _exception_code() );
  122. }
  123. }
  124. public:
  125. virtual BOOL SendToProvider( PVOID pConnection, PVOID pBuffer, INT nCount )
  126. {
  127. LG_REPORT_PACKET packet;
  128. packet.bType = 0x01;
  129. packet.nLength = sizeof(packet) + nCount;
  130. CLgReportSocketServerConnection *pServerConnection = reinterpret_cast<CLgReportSocketServerConnection*>(pConnection);
  131. return pServerConnection->Send2( &packet, sizeof(packet), pBuffer, nCount );
  132. }
  133. public:
  134. virtual void DispatchServerPacket( PVOID pConnection, PLG_REPORT_PACKET pPacket )
  135. {
  136. m_pDispatcher->OnServerPacket( pConnection, pPacket->bType, pPacket + 1, pPacket->nLength );
  137. }
  138. virtual void DispatchServerConnect( PVOID pConnection, BOOL bConnected, LPSOCKADDR_IN pSockAddr )
  139. {
  140. m_pDispatcher->OnServerConnect( pConnection, bConnected );
  141. }
  142. private:
  143. CLgReportRemoteClientDispatcher *m_pDispatcher;
  144. };
  145. /*
  146. class CLgReportRemoteLink :
  147. public CLgThread,
  148. public CLgReportRemoteProvider,
  149. public CLgReportRemoteClient
  150. {
  151. public:
  152. CLgReportRemoteLink()
  153. {
  154. }
  155. virtual ~CLgReportRemoteLink()
  156. {
  157. Destroy();
  158. }
  159. public:
  160. BOOL Create( LPCTSTR pName, LPCTSTR pRootPath )
  161. {
  162. if( !CLgReportRemoteProvider::Create( pName, pRootPath ) )
  163. return FALSE;
  164. return Start( FALSE );
  165. }
  166. void Destroy()
  167. {
  168. Stop( TRUE );
  169. BUFFER_HOLDER bh;
  170. while( m_QueueClient.Pop( bh ) )
  171. free( bh.pBuffer );
  172. while( m_QueueProvider.Pop( bh ) )
  173. free( bh.pBuffer );
  174. CLgReportRemoteProvider::Destroy();
  175. CLgReportRemoteClient::Destroy();
  176. }
  177. private:
  178. typedef struct BUFFER_HOLDER
  179. {
  180. LPVOID pBuffer;
  181. INT nCount;
  182. }BUFFER_HOLDER, *PBUFFER_HOLDER;
  183. protected:
  184. virtual BOOL SendToClient( PVOID pBuffer, INT nCount )
  185. {
  186. BUFFER_HOLDER bh;
  187. bh.pBuffer = malloc( nCount );
  188. bh.nCount = nCount;
  189. if( !bh.pBuffer )
  190. return FALSE;
  191. memcpy( bh.pBuffer, pBuffer, nCount );
  192. return m_QueueClient.Push( bh );
  193. // return CLgReportRemoteClient::DispatchRemoteData( 0, pBuffer, nCount );
  194. }
  195. virtual BOOL SendToProvider( PVOID pConnection, PVOID pBuffer, INT nCount )
  196. {
  197. BUFFER_HOLDER bh;
  198. bh.pBuffer = malloc( nCount );
  199. bh.nCount = nCount;
  200. if( !bh.pBuffer )
  201. return FALSE;
  202. memcpy( bh.pBuffer, pBuffer, nCount );
  203. return m_QueueProvider.Push( bh );
  204. // return CLgReportRemoteProvider::DispatchRemoteData( pBuffer, nCount );
  205. }
  206. private:
  207. virtual DWORD ThreadProc()
  208. {
  209. BUFFER_HOLDER bh;
  210. HANDLE pHandle[] = { CLgThread::GetThreadStopEvent(), m_QueueClient, m_QueueProvider };
  211. BOOL bLoop = TRUE;
  212. while( bLoop )
  213. {
  214. switch( ::WaitForMultipleObjects( 3, pHandle, FALSE, INFINITE ) )
  215. {
  216. default:
  217. case WAIT_FAILED:
  218. case WAIT_OBJECT_0:
  219. bLoop = FALSE;
  220. continue;
  221. case WAIT_OBJECT_0+1:
  222. while( m_QueueClient.Pop( bh ) )
  223. {
  224. CLgReportRemoteClient::DispatchRemoteData( 0, bh.pBuffer, bh.nCount );
  225. free( bh.pBuffer );
  226. }
  227. break;
  228. case WAIT_OBJECT_0+2:
  229. while( m_QueueProvider.Pop( bh ) )
  230. {
  231. CLgReportRemoteProvider::DispatchRemoteData( bh.pBuffer, bh.nCount );
  232. free( bh.pBuffer );
  233. }
  234. break;
  235. }
  236. }
  237. return 0UL;
  238. }
  239. private:
  240. CLgQueueP<BUFFER_HOLDER,1000> m_QueueProvider;
  241. CLgQueueP<BUFFER_HOLDER,1000> m_QueueClient;
  242. };
  243. */
  244. class CLgReportStorage :
  245. private CLgReportStorageClient,
  246. public CLgReportRemoteProviderDispatcher,
  247. public CLgReportRemoteClientDispatcher
  248. {
  249. public:
  250. CLgReportStorage();
  251. virtual ~CLgReportStorage();
  252. public:
  253. BOOL Create( LPCTSTR pPathRoot, INT nMaxStorageDays, CLgReportInterface *pInterface );
  254. void Destroy();
  255. BOOL Reset();
  256. public:
  257. BOOL StoreEvent( SYSTEMTIME *pST, BYTE bId, BOOL bSensor, WORD wSensorIndex, BOOL bPosition, float x, float y, LARGE_INTEGER *pOffset, LPCTSTR pFormat, va_list pMarker );
  258. BOOL StoreImage( HBITMAP hBitmap, LARGE_INTEGER *pOffset );
  259. BOOL StoreImage( CLgImageDIB& dib, LARGE_INTEGER *pOffset );
  260. BOOL StoreImage( CLgImageJPEG& jpeg, LARGE_INTEGER *pOffset );
  261. BOOL StoreBackground( CBitmap *pBitmap );
  262. BOOL StoreBackground( CLgImageDIB& dib );
  263. BOOL StoreBackground( CLgImageJPEG& jpeg );
  264. public:
  265. BOOL SetMaxStoreTime( INT nDays );
  266. BOOL OnSensor( LPCTSTR pName, float x, float y );
  267. BOOL OnFilter( BYTE bId, LPCTSTR pName );
  268. private:
  269. virtual BOOL OnCreateSite();
  270. virtual BOOL OnAskForDeleteOld();
  271. public:
  272. BOOL Dlg_Create( HWND hParentWnd );
  273. BOOL Dlg_DoModal( HWND hParentWnd );
  274. void Dlg_Destroy();
  275. public:
  276. BOOL DlgSetup_DoModal( HWND hParentWnd );
  277. private:
  278. virtual BOOL OnServerPacket( PVOID pConnection, BYTE bPacketType, PVOID pBuffer, INT nBufferSize );
  279. virtual BOOL OnServerConnect( PVOID pConnection, BOOL bConnected );
  280. virtual BOOL OnClientPacket( INT nProvider, BYTE bPacketType, PVOID pBuffer, INT nBufferSize );
  281. virtual BOOL OnClientConnect( INT nProvider, BOOL bConnected );
  282. private:
  283. CLgReportProvider m_ReportProvider;
  284. CLgArray<CLgReportRemoteProviderEx> m_arrReportProvider;
  285. CLgReportRemoteClientEx m_ReportClient;
  286. private:
  287. CLgReportInterface *m_pInterface;
  288. private:
  289. CLgReportDlg m_Dialog;
  290. private:
  291. // CLgReportSettings m_Settings;
  292. public:
  293. CLgReportSettings m_SetupSettings;
  294. CLgReportSetupDlg m_DialogSetup;
  295. public:
  296. CLgSiteManager *m_pSiteManager;
  297. };
  298. #endif