12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #define SHAREMEMORY_CIRCLE_API
- #define SHAREMEMORY_CIRCLE_C_API extern "C"
- #include <string>
- //#include"DiosThread.h"
- #include "ShareMemory_Client.h"
- using namespace std;
- #define SMCWaitTimeout 2000
- #define ShareMemoryNameLen 16
- //typedef struct _ShareMemoryCircleBlock
- //{
- // SHRAREMEMBLOCKID g_ID;
- // size_t BlockSize;
- //}SMCBLOCK;
- class SHAREMEMORY_CIRCLE_API CShareMemory_Circle{
- SMClientID m_SMinfo;
- char m_SMname[ShareMemoryNameLen];
- unsigned char m_ShareMemoryId;
- unsigned long m_BlockSize;
- int m_nMaxLimit;
- void* m_pLog;
- //void CreateLogger();
- unsigned char m_ResetCount;
- unsigned int * m_pBlockSize;
- unsigned int * m_pMainCount;
- unsigned int * m_pMainFirstIdx;
- unsigned int * m_pMainLastIdx;
- unsigned int * m_pMainCurrentIdx;
- bool * m_pMainListEmpty;
- char * m_pClearUseTmpBuff;
- bool SetSMCctrl(int First, int Last, int Current);
- bool GetSMCctrl();
- bool UpdateSMCctrlCrrent(bool IncOrDec);
- bool UpdateSMCctrlPush(bool ForceFlag);
- bool UpdateSMCctrlPop(bool ForceFlag);
- bool SMCBidIsValid(ShareMemoryBlockID &SMCBid);
- bool APILock();
- bool APIUnLock();
- bool BlockLock(unsigned long position);
- bool BlockUnLock(unsigned long position);
- bool ClearFullBlock();
- bool CircleIsFull();
- public:
- CShareMemory_Circle();
- ~CShareMemory_Circle();
- //static BYTE m_type;
- int Create(const char * path, unsigned long DataSize, unsigned long DataCount, int Authority);
- bool Destroy();
- int Open(const char * path, int Authority);
- int Open(ShareMemoryBlockID &SMCBid, int Authority);
- bool Close();
- ShareMemoryBlockID Push(void* buff, unsigned long size, bool ForceFlag);//Write
- ShareMemoryBlockID Push(ShareMemoryBlockID SMBid, bool ForceFlag);//Write
- ShareMemoryBlockID PushRaw(string imageHead, void* RawData, unsigned long size, bool ForceFlag);//Write Raw and imageHead
- bool Pop(void* & buff, unsigned long& size);//Read
- ShareMemoryBlockID Pop();//Read
- bool PopLast(void* & buff, unsigned long& size);//Read
- ShareMemoryBlockID PopLast();//Read
- bool GetCurrent(void* & buff, unsigned long& size);
- ShareMemoryBlockID GetCurrent();
- bool GetCurrent(void* & buff, unsigned long& size, bool IncOrDec);
- ShareMemoryBlockID GetCurrent(bool IncOrDec);
- bool SetCurrent(int CurrentFlag, ShareMemoryBlockID & CurrentSMBid);
- unsigned long ResetCircle(unsigned long newBlockSize);
- bool Clear();
- bool Seek(UINT64 position);
- unsigned long GetSize();
- unsigned long GetDataCount();//有效数据个数
- unsigned long GetLeftCount();//未读有效数据个数
- unsigned long GetLimitCount();//能保存的最大数据个数
- bool Read(ShareMemoryBlockID &SMCBid, void* buff, unsigned long size);
- bool Write(ShareMemoryBlockID &SMCBid, void* buff, unsigned long size);
- bool Lock();
- bool UnLock();
- static bool SM_Circle_BlockIDVerify(ShareMemoryBlockID &SMCBid);
- bool GetBlockDataAddr(ShareMemoryBlockID &SMCBid, void* & buff, unsigned long& size);//获取到的buff是去除SMCELEMENTHEAD的整块block的首地址,size为去除SMCELEMENTHEAD的整块block大小
- };
|