TSCache.h
上传用户:nameszq
上传日期:2014-08-12
资源大小:336k
文件大小:2k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. // TSCache.h: interface for the CTSCache class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_TSCACHE_H__61CC5EB5_4560_4F34_A6DA_AA35B09D79EC__INCLUDED_)
  5. #define AFX_TSCACHE_H__61CC5EB5_4560_4F34_A6DA_AA35B09D79EC__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include "Stockdrv.h"
  10. #include "SPTime.h"
  11. typedef struct _ts_packet_t {
  12. UINT m_nMsgType;
  13. PRCV_DATA m_pRCV_DATA;
  14. } TS_PACKET, PTS_PACKET;
  15. typedef CArray< TS_PACKET, TS_PACKET &> CTSPacketArray;
  16. class CTSCache  
  17. {
  18. public:
  19. CTSCache();
  20. virtual ~CTSCache();
  21. void SetLocalLatest(CSPTime t);
  22. CSPTime GetLocalLatest();
  23. static CTSCache & GetInstance();
  24. void ClearReceiveBuffer() { m_nBufLen = 0; }
  25. // decode net received data
  26. int OnReceive( BYTE * buf, size_t len );
  27. int DecodePacket( );
  28. int FindFirstPacketLength( );
  29. size_t AlignBuffer( int nStart, BOOL bRemovePrev );
  30. int TryGetPacket( int nPacketLen );
  31. int DiscardPacket( int nPacketLen );
  32. // packets operation
  33. BOOL PushPacket( UINT nMsgType, PRCV_DATA pRCV_DATA );
  34. BOOL PopPacket( UINT & nMsgType, PRCV_DATA & pRCV_DATA );
  35. void FreePacket( PRCV_DATA pRCV_DATA );
  36. // set report
  37. BOOL StoreReports( );
  38. BOOL LoadReports( );
  39. BOOL ReserveReportsSize( int size );
  40. BOOL PushReport( int nNo, RCV_REPORT_STRUCTEx * pBuf );
  41. BOOL PushReport( char * pszStockCode, RCV_REPORT_STRUCTEx * pBuf );
  42. int  PushReport( RCV_REPORT_STRUCTEx * pBuf, int size );
  43. // get report
  44. int  GetTotalNumber();
  45. BOOL GetStockByNoEx( int nNo, RCV_REPORT_STRUCTEx * pBuf );
  46. BOOL GetStockByCodeEx(char * pszStockCode,int nMarket,RCV_REPORT_STRUCTEx * pBuf);
  47. protected:
  48. CSPTime m_tmLocalLatest;
  49. BYTE m_buffer[0x80000]; // 512k bytes buffer
  50. size_t m_nBufLen;
  51. CCriticalSection m_mutexBuffer;
  52. CTSPacketArray m_aPackets;
  53. CCriticalSection m_mutexPackets;
  54. CMapStringToPtr m_mapReports;
  55. CArray<RCV_REPORT_STRUCTEx, RCV_REPORT_STRUCTEx &> m_aReports;
  56. CCriticalSection m_mutexReports;
  57. };
  58. #endif // !defined(AFX_TSCACHE_H__61CC5EB5_4560_4F34_A6DA_AA35B09D79EC__INCLUDED_)