123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- // 下列 ifdef 块是创建使从 DLL 导出更简单的
- // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 SHAREMEMORY_CIRCLE_EXPORTS
- // 符号编译的。在使用此 DLL 的
- // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
- // SHAREMEMORY_CIRCLE_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
- // 符号视为是被导出的。
- #pragma once
- #ifndef SHAREMEMORY_CIRCLE_EXPORTS
- #ifdef _WIN64
- #ifdef _DEBUG
- #pragma comment(lib, "ShareMemory_CircleX64D.lib")
- #else
- #pragma comment(lib, "ShareMemory_CircleX64.lib")
- #endif
- #else
- #ifdef _DEBUG
- #pragma comment(lib, "ShareMemory_CircleD.lib")
- #else
- #pragma comment(lib, "ShareMemory_Circle.lib")
- #endif
- #endif
- #endif
- #ifdef SHAREMEMORY_CIRCLE_EXPORTS
- #define SHAREMEMORY_CIRCLE_API __declspec(dllexport)
- #define SHAREMEMORY_CIRCLE_C_API extern "C" __declspec(dllexport)
- #else
- #define SHAREMEMORY_CIRCLE_API __declspec(dllimport)
- #define SHAREMEMORY_CIRCLE_C_API extern "C" __declspec(dllimport)
- #endif
- #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];
- BYTE m_ShareMemoryId;
- DWORD m_BlockSize;
- int m_nMaxLimit;
- PVOID m_pLog;
- //void CreateLogger();
- BYTE 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(DWORD position);
- bool BlockUnLock(DWORD position);
- bool ClearFullBlock();
- bool CircleIsFull();
- public:
- CShareMemory_Circle();
- ~CShareMemory_Circle();
- //static BYTE m_type;
- int Create(const char * path, DWORD DataSize, DWORD DataCount, int Authority);
- bool Destroy();
- int Open(const char * path, int Authority);
- int Open(ShareMemoryBlockID &SMCBid, int Authority);
- bool Close();
- ShareMemoryBlockID Push(LPVOID buff, DWORD size, bool ForceFlag);//Write
- ShareMemoryBlockID Push(ShareMemoryBlockID SMBid, bool ForceFlag);//Write
- ShareMemoryBlockID PushRaw(string imageHead, LPVOID RawData, DWORD size, bool ForceFlag);//Write Raw and imageHead
- bool Pop(LPVOID & buff, DWORD & size);//Read
- ShareMemoryBlockID Pop();//Read
- bool PopLast(LPVOID & buff, DWORD & size);//Read
- ShareMemoryBlockID PopLast();//Read
- bool GetCurrent(LPVOID & buff, DWORD & size);
- ShareMemoryBlockID GetCurrent();
- bool GetCurrent(LPVOID & buff, DWORD & size, bool IncOrDec);
- ShareMemoryBlockID GetCurrent(bool IncOrDec);
- bool SetCurrent(int CurrentFlag, ShareMemoryBlockID & CurrentSMBid);
- DWORD ResetCircle(DWORD newBlockSize);
- bool Clear();
- bool Seek(UINT64 position);
- DWORD GetSize();
- DWORD GetDataCount();//有效数据个数
- DWORD GetLeftCount();//未读有效数据个数
- DWORD GetLimitCount();//能保存的最大数据个数
- bool Read(ShareMemoryBlockID &SMCBid, LPVOID buff, DWORD size);
- bool Write(ShareMemoryBlockID &SMCBid, LPVOID buff, DWORD size);
- bool Lock();
- bool UnLock();
- static bool SM_Circle_BlockIDVerify(ShareMemoryBlockID &SMCBid);
- bool GetBlockDataAddr(ShareMemoryBlockID &SMCBid, LPVOID & buff, DWORD & size);//获取到的buff是去除SMCELEMENTHEAD的整块block的首地址,size为去除SMCELEMENTHEAD的整块block大小
- };
|