ShareMemory_Circle.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #define SHAREMEMORY_CIRCLE_API
  2. #define SHAREMEMORY_CIRCLE_C_API extern "C"
  3. #include <string>
  4. //#include"DiosThread.h"
  5. #include "ShareMemory_Client.h"
  6. using namespace std;
  7. #define SMCWaitTimeout 2000
  8. #define ShareMemoryNameLen 16
  9. //typedef struct _ShareMemoryCircleBlock
  10. //{
  11. // SHRAREMEMBLOCKID g_ID;
  12. // size_t BlockSize;
  13. //}SMCBLOCK;
  14. class SHAREMEMORY_CIRCLE_API CShareMemory_Circle{
  15. SMClientID m_SMinfo;
  16. char m_SMname[ShareMemoryNameLen];
  17. unsigned char m_ShareMemoryId;
  18. unsigned long m_BlockSize;
  19. int m_nMaxLimit;
  20. void* m_pLog;
  21. //void CreateLogger();
  22. unsigned char m_ResetCount;
  23. unsigned int * m_pBlockSize;
  24. unsigned int * m_pMainCount;
  25. unsigned int * m_pMainFirstIdx;
  26. unsigned int * m_pMainLastIdx;
  27. unsigned int * m_pMainCurrentIdx;
  28. bool * m_pMainListEmpty;
  29. char * m_pClearUseTmpBuff;
  30. bool SetSMCctrl(int First, int Last, int Current);
  31. bool GetSMCctrl();
  32. bool UpdateSMCctrlCrrent(bool IncOrDec);
  33. bool UpdateSMCctrlPush(bool ForceFlag);
  34. bool UpdateSMCctrlPop(bool ForceFlag);
  35. bool SMCBidIsValid(ShareMemoryBlockID &SMCBid);
  36. bool APILock();
  37. bool APIUnLock();
  38. bool BlockLock(unsigned long position);
  39. bool BlockUnLock(unsigned long position);
  40. bool ClearFullBlock();
  41. bool CircleIsFull();
  42. public:
  43. CShareMemory_Circle();
  44. ~CShareMemory_Circle();
  45. //static BYTE m_type;
  46. int Create(const char * path, unsigned long DataSize, unsigned long DataCount, int Authority);
  47. bool Destroy();
  48. int Open(const char * path, int Authority);
  49. int Open(ShareMemoryBlockID &SMCBid, int Authority);
  50. bool Close();
  51. ShareMemoryBlockID Push(void* buff, unsigned long size, bool ForceFlag);//Write
  52. ShareMemoryBlockID Push(ShareMemoryBlockID SMBid, bool ForceFlag);//Write
  53. ShareMemoryBlockID PushRaw(string imageHead, void* RawData, unsigned long size, bool ForceFlag);//Write Raw and imageHead
  54. bool Pop(void* & buff, unsigned long& size);//Read
  55. ShareMemoryBlockID Pop();//Read
  56. bool PopLast(void* & buff, unsigned long& size);//Read
  57. ShareMemoryBlockID PopLast();//Read
  58. bool GetCurrent(void* & buff, unsigned long& size);
  59. ShareMemoryBlockID GetCurrent();
  60. bool GetCurrent(void* & buff, unsigned long& size, bool IncOrDec);
  61. ShareMemoryBlockID GetCurrent(bool IncOrDec);
  62. bool SetCurrent(int CurrentFlag, ShareMemoryBlockID & CurrentSMBid);
  63. unsigned long ResetCircle(unsigned long newBlockSize);
  64. bool Clear();
  65. bool Seek(UINT64 position);
  66. unsigned long GetSize();
  67. unsigned long GetDataCount();//有效数据个数
  68. unsigned long GetLeftCount();//未读有效数据个数
  69. unsigned long GetLimitCount();//能保存的最大数据个数
  70. bool Read(ShareMemoryBlockID &SMCBid, void* buff, unsigned long size);
  71. bool Write(ShareMemoryBlockID &SMCBid, void* buff, unsigned long size);
  72. bool Lock();
  73. bool UnLock();
  74. static bool SM_Circle_BlockIDVerify(ShareMemoryBlockID &SMCBid);
  75. bool GetBlockDataAddr(ShareMemoryBlockID &SMCBid, void* & buff, unsigned long& size);//获取到的buff是去除SMCELEMENTHEAD的整块block的首地址,size为去除SMCELEMENTHEAD的整块block大小
  76. };