DataElementInterface.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. #pragma once
  2. #include <vector>
  3. #include <string>
  4. #include <map>
  5. #include "TmplBlockBuffer.tlh"
  6. #ifdef _DATAELEMENT_CLASSINDLL
  7. #define DATAELEMENTDLL_CLASS_DECL _declspec(dllexport)
  8. #else
  9. #define DATAELEMENTDLL_CLASS_DECL _declspec(dllimport)
  10. #endif
  11. #ifndef _DATAELEMENT_CLASSINDLL
  12. #ifdef X64
  13. #ifdef _DEBUG
  14. #pragma comment(lib, "DataElementX64D.lib")
  15. #else
  16. #pragma comment(lib, "DataElementX64.lib")
  17. #endif
  18. #else
  19. #ifdef _DEBUG
  20. #pragma comment(lib, "DataElementD.lib")
  21. #else
  22. #pragma comment(lib, "DataElement.lib")
  23. #endif
  24. #endif
  25. #endif
  26. namespace DIOS_Kernel
  27. {
  28. #define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
  29. #define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } }
  30. /*! @class
  31. ********************************************************************************
  32. <PRE>
  33. Copyright (c) E-COM 2009-2017.
  34. All rights reserved.
  35. CLASS NAME: CAuto_NomalMemPtr
  36. DESCRIPTION: 内存智能模板指针。
  37. NOTES:
  38. AUTHOR:
  39. VERSION:
  40. HISTORY: 2016-6-27 First version
  41. </PRE>
  42. *******************************************************************************/
  43. template<typename T>
  44. class CAuto_NomalMemPtr
  45. {
  46. public:
  47. explicit CAuto_NomalMemPtr(T* ptr) throw()
  48. :m_pAutoPointer(ptr)
  49. {
  50. };
  51. virtual ~CAuto_NomalMemPtr()throw()
  52. {
  53. if (m_pAutoPointer != NULL)
  54. {
  55. delete[] m_pAutoPointer;
  56. m_pAutoPointer = NULL;
  57. }
  58. };
  59. /*! @function
  60. ********************************************************************************
  61. <PRE>
  62. FUNCTION NAME: reset
  63. DESCRIPTION: 更换内存数据,并将原有内存数据.
  64. PARAM:
  65. [in]ptr :需要更换的新内存数据
  66. RETURN: void
  67. HISTORY: 2016-6-27 First version
  68. </PRE>
  69. *******************************************************************************/
  70. virtual void reset(T* ptr = NULL)throw()
  71. {
  72. if (m_pAutoPointer != ptr)
  73. {
  74. if (m_pAutoPointer != NULL)
  75. delete[] m_pAutoPointer;
  76. m_pAutoPointer = ptr;
  77. }
  78. }
  79. /*! @function
  80. ********************************************************************************
  81. <PRE>
  82. FUNCTION NAME: operator[]
  83. DESCRIPTION: []操作符重载.
  84. PARAM:
  85. [in]nIndex :内存数据单元索引
  86. RETURN: void
  87. HISTORY: 2016-6-27 First version
  88. </PRE>
  89. *******************************************************************************/
  90. T& operator[](const int &nIndex) const throw()
  91. {
  92. return m_pAutoPointer[nIndex];
  93. }
  94. /*! @function
  95. ********************************************************************************
  96. <PRE>
  97. FUNCTION NAME: operator->
  98. DESCRIPTION: ->操作符重载.
  99. PARAM:
  100. RETURN: T*
  101. HISTORY: 2016-6-27 First version
  102. </PRE>
  103. *******************************************************************************/
  104. T* operator->()const throw()
  105. {
  106. return m_pAutoPointer;
  107. }
  108. /*! @function
  109. ********************************************************************************
  110. <PRE>
  111. FUNCTION NAME: IsEmpty
  112. DESCRIPTION: 判断智能指针是否为空.
  113. PARAM:
  114. RETURN: bool
  115. HISTORY: 2016-6-27 First version
  116. </PRE>
  117. *******************************************************************************/
  118. bool IsEmpty()
  119. {
  120. return (m_pAutoPointer == NULL);
  121. }
  122. /*! @function
  123. ********************************************************************************
  124. <PRE>
  125. FUNCTION NAME: get
  126. DESCRIPTION: 获取智能指针地址.
  127. PARAM:
  128. RETURN: T*
  129. HISTORY: 2016-6-27 First version
  130. </PRE>
  131. *******************************************************************************/
  132. T* get()const throw()
  133. {
  134. return m_pAutoPointer;
  135. }
  136. /*! @function
  137. ********************************************************************************
  138. <PRE>
  139. FUNCTION NAME: release
  140. DESCRIPTION: 释放智能指针对数据地址的控制权.
  141. PARAM:
  142. RETURN: T*
  143. HISTORY: 2016-6-27 First version
  144. </PRE>
  145. *******************************************************************************/
  146. T* release()throw()
  147. {
  148. T* tmp(m_pAutoPointer);
  149. m_pAutoPointer = NULL;
  150. return tmp;
  151. }
  152. private:
  153. T* m_pAutoPointer;
  154. };
  155. template<class T>
  156. class CAuto_NormalClassPtr
  157. {
  158. public:
  159. //constructor & destructor-----------------------------------
  160. explicit CAuto_NormalClassPtr(T*ptr = 0)throw()
  161. :m_pAutoPointer(ptr)
  162. {
  163. }
  164. ~CAuto_NormalClassPtr()throw()
  165. {
  166. SAFE_DELETE(m_pAutoPointer);
  167. }
  168. /*! @function
  169. ********************************************************************************
  170. <PRE>
  171. FUNCTION NAME: operator*
  172. DESCRIPTION: *操作符重载.
  173. PARAM:
  174. RETURN: T&
  175. HISTORY: 2016-6-2 First version
  176. </PRE>
  177. *******************************************************************************/
  178. T& operator*()const throw()
  179. {
  180. return *m_pAutoPointer;
  181. }
  182. /*! @function
  183. ********************************************************************************
  184. <PRE>
  185. FUNCTION NAME: operator->
  186. DESCRIPTION: ->操作符重载.
  187. PARAM:
  188. RETURN: T*
  189. HISTORY: 2016-6-2 First version
  190. </PRE>
  191. *******************************************************************************/
  192. T* operator->()const throw()
  193. {
  194. return m_pAutoPointer;
  195. }
  196. /*! @function
  197. ********************************************************************************
  198. <PRE>
  199. FUNCTION NAME: IsEmpty
  200. DESCRIPTION: 判断智能指针是否为空.
  201. PARAM:
  202. RETURN: bool
  203. HISTORY: 2016-6-27 First version
  204. </PRE>
  205. *******************************************************************************/
  206. bool IsEmpty()
  207. {
  208. return (m_pAutoPointer == NULL);
  209. }
  210. /*! @function
  211. ********************************************************************************
  212. <PRE>
  213. FUNCTION NAME: reset
  214. DESCRIPTION: 更换数据对象,并将原有对象释放.
  215. PARAM:
  216. [in]ptr :需要更换的新数据对象
  217. RETURN: void
  218. HISTORY: 2016-6-2 First version
  219. </PRE>
  220. *******************************************************************************/
  221. virtual void reset(T*ptr = NULL)throw()
  222. {
  223. if (m_pAutoPointer != ptr)
  224. {
  225. SAFE_DELETE(m_pAutoPointer);
  226. m_pAutoPointer = ptr;
  227. }
  228. }
  229. /*! @function
  230. ********************************************************************************
  231. <PRE>
  232. FUNCTION NAME: get
  233. DESCRIPTION: 获取智能指针地址.
  234. PARAM:
  235. RETURN: T*
  236. HISTORY: 2016-6-27 First version
  237. </PRE>
  238. *******************************************************************************/
  239. T* get()const throw()
  240. {
  241. return m_pAutoPointer;
  242. }
  243. /*! @function
  244. ********************************************************************************
  245. <PRE>
  246. FUNCTION NAME: release
  247. DESCRIPTION: 释放智能指针对数据地址的控制权.
  248. PARAM:
  249. RETURN: T*
  250. HISTORY: 2016-6-27 First version
  251. </PRE>
  252. *******************************************************************************/
  253. T* release()throw()
  254. {
  255. T* tmp(m_pAutoPointer);
  256. m_pAutoPointer = NULL;
  257. return tmp;
  258. }
  259. private:
  260. T * m_pAutoPointer;
  261. };
  262. }
  263. namespace DIOS_Kernel
  264. {
  265. #ifndef _ENDIANMOD
  266. #define _ENDIANMOD
  267. enum EndianMode
  268. {
  269. ENDIAN_LITTLE,
  270. ENDIAN_BIG,
  271. ENDIAN_MAX,
  272. };
  273. #endif
  274. class CByteBuffer;
  275. class DATAELEMENTDLL_CLASS_DECL CBytesBuffer
  276. {
  277. public:
  278. CBytesBuffer();
  279. CBytesBuffer(size_t res);
  280. CBytesBuffer(const CBytesBuffer &buf);
  281. virtual ~CBytesBuffer();
  282. CBytesBuffer &operator<<(bool value);
  283. CBytesBuffer &operator<<(unsigned char value);
  284. CBytesBuffer &operator<<(unsigned short value);
  285. CBytesBuffer &operator<<(unsigned int value);
  286. CBytesBuffer &operator<<(unsigned long long value);
  287. CBytesBuffer &operator<<(char value);
  288. CBytesBuffer &operator<<(short value);
  289. CBytesBuffer &operator<<(int value);
  290. CBytesBuffer &operator<<(long long value);
  291. CBytesBuffer &operator<<(float value);
  292. CBytesBuffer &operator<<(double value);
  293. CBytesBuffer &operator<<(const char* value);
  294. CBytesBuffer &operator>>(bool &value);
  295. CBytesBuffer &operator>>(unsigned char &value);
  296. CBytesBuffer &operator>>(unsigned short &value);
  297. CBytesBuffer &operator>>(unsigned int &value);
  298. CBytesBuffer &operator>>(unsigned long long &value);
  299. void SetEndianMode(EndianMode eMode);
  300. EndianMode GetSystemEndianMode();
  301. EndianMode GetCodeEndianMode();
  302. bool Load(const wchar_t* pwstrFilePathName);
  303. bool CheckUShortValue(const unsigned short& _usValue);
  304. bool ReadUShortCheck(const unsigned short& _usValue);
  305. bool CheckSize(unsigned int nSize);
  306. bool append(const unsigned char *src, size_t cnt);
  307. bool append(const unsigned char *pSrcBuffer, unsigned int uBlockSize, unsigned int nCount, bool bCodeEndian);
  308. unsigned char* append(size_t cnt);
  309. bool NeedEndian();
  310. bool CheckString();
  311. const char* ReadString();
  312. bool CheckBufferSize();
  313. const unsigned char* ReadBuffer(unsigned int uBlockSize, bool bCodeEndian, unsigned int& nBufferLen);
  314. void clear();
  315. void ClearPos();
  316. bool resize(size_t newsize);
  317. void reserve(size_t ressize);
  318. const unsigned char *contents() const;
  319. size_t Length() const;
  320. private:
  321. CByteBuffer* Get() const;
  322. CByteBuffer* m_pBuffer;
  323. char* m_pLocalBuffer;
  324. unsigned int m_nLocalBufferLen;
  325. };
  326. class CDIOSDllOpen;
  327. }
  328. namespace DIOS_ParseXML
  329. {
  330. struct DATATYPEINFO;
  331. }
  332. namespace DIOS_DataPixel
  333. {
  334. class CDataSampleMgr;
  335. class CDataPixelMgr;
  336. class DATAELEMENTDLL_CLASS_DECL CDataSample
  337. {
  338. public:
  339. bool Init();
  340. const wchar_t* GetDataSampleName() const;
  341. unsigned int SizeofDataSample() const;
  342. bool Compare(const CDataSample& oDataSample) const;
  343. bool Compare(void* pRangList1, unsigned int nBufferLen1, void* pRangList2, unsigned int nBufferLen2) const;
  344. bool IsExistRangeCompare() const;
  345. bool IsUserDefined() const;
  346. private:
  347. CDataSample(const DIOS_ParseXML::DATATYPEINFO* stDataTypeInfo);
  348. virtual ~CDataSample();
  349. DIOS_ParseXML::DATATYPEINFO* m_pstDataTypeInfo;
  350. bool m_bInit;
  351. typedef bool(*RangeCompareFunc)(void* pRangList1, unsigned int nBufferLen1, void* pRangList2, unsigned int nBufferLen2);
  352. RangeCompareFunc m_pfnRangeCompare;
  353. DIOS_Kernel::CDIOSDllOpen* m_poDLLFunction;
  354. const wchar_t* m_pwszRangeFunctionSuffix = L"RangeCompare";
  355. friend class CDataSampleMgr;
  356. };
  357. typedef CDataSample* LPDataSample;
  358. class CDataPixelInfo;
  359. class DATAELEMENTDLL_CLASS_DECL CDataPixel
  360. {
  361. public:
  362. unsigned int GetSamplesPerPixel() const;
  363. bool IsAllSamplesSame() const;
  364. const CDataSample* GetDataSample(unsigned int uSampleId = 0) const;
  365. const wchar_t* GetUserDefSampleName(unsigned int uSampleId = 0) const;
  366. void SetUserDefSampleName(const wchar_t* wszUserDefSampleName, unsigned int uSampleId = 0);
  367. const void* GetDataSampleMinMaxArrayBuffer(unsigned int& nBufferLen, unsigned int uSampleId = 0) const;
  368. bool SetDefineValueRange(const void* pDataMinMaxArrayBuffer, unsigned int nBufferLen, unsigned int uSampleId = 0);
  369. unsigned int GetPixelDataLen() const;
  370. bool Compare(const CDataPixel& oDataPixel) const;
  371. const wchar_t* ToString() const;
  372. private:
  373. CDataPixelInfo* m_pDataPixel;
  374. bool m_bInit;
  375. friend class CDataPixelMgr;
  376. };
  377. }
  378. namespace DIOS_DataElement
  379. {
  380. class CWStringMapElement;
  381. }
  382. namespace DIOS_DataElementCommon
  383. {
  384. #define SAMPLEID_ALLSAMPLES (~(unsigned int)0)
  385. typedef struct _UserDefSampleInfo
  386. {
  387. std::wstring wstrSampleDataTypeName;
  388. void* pDataMinMaxArrayBuffer;
  389. unsigned int nBufferLen;
  390. std::wstring wstrSampleName;
  391. _UserDefSampleInfo()
  392. {
  393. wstrSampleDataTypeName = L"";
  394. pDataMinMaxArrayBuffer = NULL;
  395. nBufferLen = 0;
  396. wstrSampleName = L"";
  397. }
  398. }
  399. UserDefSampleInfo;
  400. class DATAELEMENTDLL_CLASS_DECL CUserDefPixelInfo
  401. {
  402. public:
  403. CUserDefPixelInfo(unsigned int uSamplesPerPixel, DIOS_DataElement::CWStringMapElement* pDiscriptionMap);
  404. virtual ~CUserDefPixelInfo();
  405. bool SetSampleInfo(const wchar_t* pwszSampleDataTypeName, const void* pDataMinMaxArrayBuffer, unsigned int nBufferLen, const wchar_t* pwszSampleName = L"", unsigned int nSampleId = SAMPLEID_ALLSAMPLES);
  406. bool SetSampleUserDefName(const wchar_t* pwszSampleName, unsigned int nSampleId);
  407. bool SetSampleMinMaxArrayBuffer(const void* pDataMinMaxArrayBuffer, unsigned int nBufferLen, unsigned int nSampleId = SAMPLEID_ALLSAMPLES);
  408. unsigned int GetSamplesPerPixel() const { return m_uSamplesPerPixel; };
  409. const wchar_t* GetSampleName(unsigned int nSampleId) const;
  410. const wchar_t* GetSampleTypeName(unsigned int nSampleId) const;
  411. const void* GetSampleMinMaxValueRange(unsigned int nSampleId, unsigned int& nBufferLen) const;
  412. void SetDiscription(const wchar_t* pwszKey, const wchar_t* pwszValue);
  413. unsigned int GetDiscriptionCount() const;
  414. const DIOS_DataElement::CWStringMapElement* GetDiscription() const;
  415. private:
  416. std::vector<UserDefSampleInfo>* m_pvecPixelInfo;
  417. DIOS_DataElement::CWStringMapElement* m_pDiscriptionMap;
  418. unsigned int m_uSamplesPerPixel;
  419. bool m_bStandardPixelDef;
  420. };
  421. }
  422. namespace DIOS_Description
  423. {
  424. class CDescription;
  425. class DATAELEMENTDLL_CLASS_DECL CDescriptions
  426. {
  427. public:
  428. CDescriptions();
  429. virtual ~CDescriptions();
  430. //编码
  431. virtual bool Encode(DIOS_Kernel::CBytesBuffer& oByteBuffer);
  432. //解码
  433. virtual bool Decode(DIOS_Kernel::CBytesBuffer& oByteBuffer);
  434. //
  435. const wchar_t* GetType() const;
  436. bool IsDescriptionExist(const wchar_t* pwszKey) const;
  437. void SetDescription(const wchar_t* pwszKey, const wchar_t* pwszValue);//设置描述信息
  438. const wchar_t* GetDescription(const wchar_t* pwszKey) const;//获取描述信息
  439. bool IsAttributeExist(const wchar_t* pwszKey) const;
  440. void SetAttribute(const wchar_t* pwszKey, void* pValue);//设置设备属性信息
  441. const void* GetAttribute(const wchar_t* pwszKey) const;//获取设备属性信息
  442. virtual const wchar_t* ToString() const;
  443. bool CopyTo(CDescriptions& oDescription);
  444. protected:
  445. CDescriptions(const wchar_t* pwszType);
  446. CDescription* m_pDescription;
  447. };
  448. }
  449. namespace DIOS_Kernel
  450. {
  451. class CDIOSThreadLock;
  452. }
  453. namespace DIOS_TimeStamp
  454. {
  455. class ITimeStamp;
  456. }
  457. namespace DIOS_DataElement
  458. {
  459. #ifndef _DataElement
  460. #define _DataElement
  461. enum DataElementType
  462. {
  463. TYPE_DESCRIPTION_ELEMENT = 2,
  464. TYPE_DATAELEMENT,
  465. TYPE_WSTRINGVECTOR_ELEMENT,
  466. TYPE_WSTRINGMAP_ELEMENT,
  467. TYPE_DATAELEMENTGROUP,
  468. TYPE_DATAELEMENTMAX,
  469. };
  470. enum DataCompareType
  471. {
  472. CMPTYPE_DISCRIPTION = 1,
  473. CMPTYPE_NAME = 2,
  474. CMPTYPE_DATA = 4,
  475. };
  476. #endif
  477. class IDataMgr;
  478. class DATAELEMENTDLL_CLASS_DECL IDataElement
  479. {
  480. public:
  481. bool SetElementName(const wchar_t* pwszName);
  482. const wchar_t* GetElementName() const;
  483. inline DataElementType GetElementType()const { return m_eType; };
  484. void AddRefCount(); //增加引入计数
  485. bool DeleteRefCount(); //减少引入计数
  486. void SetTimeStamp(unsigned long long ullTimeStamp);
  487. void SetDataValidStatus(bool bSet);
  488. bool IsDataValid() const;
  489. virtual void Lock() const;
  490. virtual void UnLock() const;
  491. //描述设置
  492. void SetDescription(const wchar_t* pwszKey, const wchar_t* pwszValue);
  493. const wchar_t* GetDescription(const wchar_t* pwszKey) const;
  494. const void* GetAttribute(const wchar_t* pwszKey) const;
  495. void SetAttribute(const wchar_t* pwszKey, void* pValue);
  496. virtual const wchar_t* ToString() const;
  497. bool CopyDescriptionTo(IDataElement* poDataElement);
  498. virtual bool CompareElement(const IDataElement* poDataElement, DataCompareType eType) const = 0;
  499. //编码
  500. virtual bool Encode(DIOS_Kernel::CBytesBuffer& oByteBuffer) = 0;
  501. //元素单元个数
  502. virtual unsigned int Size() const = 0;
  503. virtual bool WriteData(const wchar_t* wszDataJson) { return false; };
  504. virtual const wchar_t* ReadData() const { return L""; };
  505. protected:
  506. IDataElement(DIOS_TimeStamp::ITimeStamp* m_poTimeStamp, DataElementType eType);
  507. virtual ~IDataElement();
  508. virtual bool Decode(const DIOS_Description::CDescriptions& oMgrDesp, DIOS_Kernel::CBytesBuffer& oByteBuffer) = 0;
  509. DIOS_TimeStamp::ITimeStamp* m_poTimeStamp; //时间戳
  510. DIOS_Description::CDescriptions m_oElementDescription; //数据描述
  511. DataElementType m_eType; //数据元素类型
  512. volatile long m_nRefCount; //引入计数
  513. std::wstring* m_pDiscriptionJson;
  514. std::wstring* m_pDataJson;
  515. DIOS_Kernel::CDIOSThreadLock* m_pLocker;
  516. friend class IDataMgr;
  517. };
  518. class DATAELEMENTDLL_CLASS_DECL CDataElement : public IDataElement
  519. {
  520. public:
  521. bool CreateDataBuffer(const unsigned int* puDimensionInfo, unsigned int uDimension);
  522. bool CreateDataBuffer(BlockBuffer& oBuffer, const unsigned int* puDimensionInfo, unsigned int uDimension);
  523. const unsigned int* GetDimensionInfo(unsigned int& uDimension) const;
  524. unsigned int Size() const;
  525. DIOS_DataPixel::CDataPixel* GetPixelInfo() const;
  526. virtual void Lock() const;
  527. virtual void UnLock() const;
  528. const void* ReadSampleDataBuffer(unsigned int nSampleId, unsigned int& uSampleBufferLen) const;
  529. void* WriteSampleDataBuffer(unsigned int nSampleId, unsigned int& uSampleBufferLen);
  530. void* WriteSampleDataBuffer(unsigned int& uSampleBufferLen);
  531. const void* ReadPixelDataBuffer(unsigned int& uSampleBufferLen) const;
  532. void* WritePixelDataBuffer(unsigned int& uSampleBufferLen);
  533. BlockBuffer GetBuffer() const;
  534. bool CompareElement(const IDataElement* poDataElement, DataCompareType eType) const;
  535. virtual bool WriteData(const wchar_t* wszDataJson);
  536. virtual const wchar_t* ToString() const;
  537. };
  538. class DATAELEMENTDLL_CLASS_DECL CDescriptionElement : public IDataElement
  539. {
  540. public:
  541. unsigned int GetDimension() const;
  542. unsigned int Size() const;
  543. bool CompareElement(const IDataElement* poDataElement, DataCompareType eType = CMPTYPE_DISCRIPTION) const;
  544. const DIOS_DataPixel::CDataPixel* GetPixelInfo() const;
  545. virtual const wchar_t* ToString() const;
  546. };
  547. class DATAELEMENTDLL_CLASS_DECL CDataElementGroup : public IDataElement
  548. {
  549. public:
  550. bool AddElement(IDataElement* poElement);
  551. inline const IDataElement* GetConstantElement(unsigned int nIndex) const throw();
  552. inline IDataElement* GetElement(unsigned int nIndex) const throw();
  553. void Merge(CDataElementGroup* pNewGroup);
  554. const IDataElement* GetConstantElement(const wchar_t* pwszNameURL) const throw();
  555. IDataElement* GetElement(const wchar_t* pwszNameURL) const throw();
  556. bool RemoveElement(size_t nIndex);
  557. bool AddElement(IDataElement* poElement, const wchar_t* pwszURL);
  558. bool UpdateElementByName(IDataElement* poElement);
  559. bool CompareElement(const IDataElement* poDataElement, DataCompareType eType) const;
  560. bool RemoveElement(const wchar_t* pwszElementName, const wchar_t* pwszURL = L"");
  561. bool Encode(DIOS_Kernel::CBytesBuffer& oByteBuffer);
  562. void Clear();
  563. unsigned int Size() const;
  564. virtual const wchar_t* ToString() const;
  565. const wchar_t* GetElementNameOfGroup(unsigned int nIndex) const;
  566. protected:
  567. CDataElementGroup(DIOS_TimeStamp::ITimeStamp* poTimeStamp);
  568. virtual ~CDataElementGroup();
  569. bool Decode(const DIOS_Description::CDescriptions& oMgrDesp, DIOS_Kernel::CBytesBuffer& oByteBuffer);
  570. std::vector<IDataElement*>* m_pvecElements;
  571. typedef struct _DataElementInfo
  572. {
  573. IDataElement* pElement;
  574. unsigned int nIndex;
  575. _DataElementInfo()
  576. {
  577. memset(this, 0, sizeof(_DataElementInfo));
  578. }
  579. _DataElementInfo& operator = (const _DataElementInfo& rtDataType)
  580. {
  581. memcpy(this, &rtDataType, sizeof(_DataElementInfo));
  582. return *this;
  583. }
  584. }
  585. DEInfo;
  586. std::map<std::wstring, DEInfo>* m_poDataElementMap;
  587. std::map<unsigned int, std::wstring>* m_poFastFindMap;
  588. friend class IDataMgr;
  589. };
  590. class DATAELEMENTDLL_CLASS_DECL CWStringVectorElement : public IDataElement
  591. {
  592. public:
  593. unsigned int Size() const;
  594. void AddWString(const wchar_t* pwszValue);
  595. bool CompareElement(const IDataElement* poDataElement, DataCompareType eType) const;
  596. const wchar_t* GetWString(unsigned int nIndex) const;
  597. bool Encode(DIOS_Kernel::CBytesBuffer& oByteBuffer);
  598. void Clear();
  599. protected:
  600. CWStringVectorElement(DIOS_TimeStamp::ITimeStamp* poTimeStamp);
  601. virtual ~CWStringVectorElement();
  602. bool Decode(const DIOS_Description::CDescriptions& oMgrDesp, DIOS_Kernel::CBytesBuffer& oByteBuffer);
  603. std::vector<std::wstring>* m_pvecData;
  604. friend class IDataMgr;
  605. };
  606. class DATAELEMENTDLL_CLASS_DECL CWStringMapElement : public IDataElement
  607. {
  608. public:
  609. unsigned int Size() const;
  610. void AddWString(const wchar_t* pwszKey, const wchar_t* pwszValue);
  611. bool CompareElement(const IDataElement* poDataElement, DataCompareType eType) const;
  612. const wchar_t* GetWString(const wchar_t* pwszKey) const;
  613. const CWStringVectorElement* GetKeys() const;
  614. bool Encode(DIOS_Kernel::CBytesBuffer& oByteBuffer);
  615. virtual const wchar_t* ToString() const;
  616. protected:
  617. CWStringMapElement(DIOS_TimeStamp::ITimeStamp* poTimeStamp, CWStringVectorElement* povecKeys);
  618. virtual ~CWStringMapElement();
  619. bool Decode(const DIOS_Description::CDescriptions& oMgrDesp, DIOS_Kernel::CBytesBuffer& oByteBuffer);
  620. std::map<std::wstring, std::wstring>* m_poDataMap;
  621. CWStringVectorElement* m_povecKeys;
  622. std::wstring* m_pwstrJson;
  623. friend class IDataMgr;
  624. };
  625. }
  626. namespace DIOS_PipelineDevice
  627. {
  628. typedef bool(*NOTIFY) (void* pParent, int nNotifyType, void* pInData, void* pOutData);
  629. enum FuncInfoGroupType
  630. {
  631. GROUPTYPE_INPUT,
  632. GROUPTYPE_CACHE,
  633. GROUPTYPE_OUTPUT,
  634. };
  635. enum TYPE_PROCESSMODULE :unsigned char
  636. {
  637. PROCESSMODULE_FUNCTION,
  638. PROCESSMODULE_STATICPIPELINE,
  639. PROCESSMODULE_MAX,
  640. };
  641. enum PLWorkMode
  642. {
  643. PLWORKMODE_NONE,
  644. PLWORKMODE_FORPROCESSING,
  645. PLWORKMODE_FORPRESENTATION,
  646. PLWORKMODE_MAX,
  647. };
  648. enum CHECKMODE
  649. {
  650. CKMODE_CHECKALL_ADD,
  651. CKMODE_CHECKALL,
  652. CKMODE_CHECKANY,
  653. CKMODE_MAX,
  654. };
  655. class DATAELEMENTDLL_CLASS_DECL CNodeInfo : public DIOS_Description::CDescriptions
  656. {
  657. public:
  658. CNodeInfo();
  659. virtual ~CNodeInfo();
  660. void SetType(TYPE_PROCESSMODULE eType);
  661. TYPE_PROCESSMODULE GetType() const;
  662. bool IsValid() const;
  663. size_t size(FuncInfoGroupType eType) const;
  664. const wchar_t* GetName(FuncInfoGroupType eType, unsigned int nId) const;
  665. bool Find(FuncInfoGroupType eType, const DIOS_DataElement::CDataElementGroup& oScrDataGroup, DIOS_DataElement::CDataElementGroup& oDesDataGroup, bool bUseStatus) const;
  666. bool GetOutputStatus(unsigned int nId) const;
  667. void AddInputInfo(const wchar_t* pwszName);
  668. void AddOutputInfo(const wchar_t* pwszName, bool bStatus);
  669. virtual bool Encode(DIOS_Kernel::CBytesBuffer& oByteBuffer);
  670. virtual bool Decode(DIOS_Kernel::CBytesBuffer& oByteBuffer);
  671. private:
  672. TYPE_PROCESSMODULE m_eType;
  673. std::vector<std::wstring>* m_pvecInput;
  674. std::vector<std::wstring>* m_pvecOutput;
  675. std::vector<bool>* m_pvecOutputStatus;
  676. };
  677. class DATAELEMENTDLL_CLASS_DECL CFunctionInfomation : public DIOS_Description::CDescriptions
  678. {
  679. public:
  680. void AddMemWorkMode(const wchar_t* pwszMemTypeName = L"Memory");
  681. const DIOS_DataElement::CWStringVectorElement* GetMemWorkMode() const;
  682. void SetAlgorithm(const wchar_t* pwszAlgorithm);
  683. void AddDataElement(const DIOS_DataElement::CDescriptionElement* poElement, FuncInfoGroupType eGroupType);
  684. const DIOS_DataElement::CDataElementGroup* GetDataElement(FuncInfoGroupType eGroupType) const;
  685. bool Check();
  686. const CNodeInfo* GetFunctionPinInfo() const;
  687. virtual bool Encode(DIOS_Kernel::CBytesBuffer& oByteBuffer);
  688. virtual bool Decode(DIOS_Kernel::CBytesBuffer& oByteBuffer) ;
  689. virtual const wchar_t* ToString() const;
  690. private:
  691. CFunctionInfomation(const wchar_t* pwszFunctionName, DIOS_DataElement::CDataElementGroup* m_poInputList,
  692. DIOS_DataElement::CDataElementGroup* m_poCacheList, DIOS_DataElement::CDataElementGroup* m_poOutputList, DIOS_DataElement::CWStringVectorElement* poMemTypeName);
  693. virtual ~CFunctionInfomation();
  694. DIOS_DataElement::CDataElementGroup* m_poInputList;
  695. DIOS_DataElement::CDataElementGroup* m_poCacheList;
  696. DIOS_DataElement::CDataElementGroup* m_poOutputList;
  697. DIOS_DataElement::CWStringVectorElement* m_poMemTypeName;
  698. CNodeInfo* m_pFuncionPinInfo;
  699. std::wstring* m_pwstrDescriptionJson;
  700. friend class CFunctionInfo;
  701. };
  702. class DATAELEMENTDLL_CLASS_DECL CPLTreeNode
  703. {
  704. public:
  705. bool Set(CNodeInfo* pNode, unsigned int uTTreeNodeId = CPLTreeNode::uInvalidNodeId, unsigned int uFTreeNodeId = CPLTreeNode::uInvalidNodeId);
  706. void SetSuccessTreeNodeId(unsigned int uTTreeNodeId = CPLTreeNode::uInvalidNodeId);
  707. void SetFailureTreeNodeId(unsigned int uFTreeNodeId = CPLTreeNode::uInvalidNodeId);
  708. bool Encode(DIOS_Kernel::CBytesBuffer& oByteBuffer);
  709. bool Decode(DIOS_Kernel::CBytesBuffer& oByteBuffer, unsigned int nNodeCount);
  710. bool IsValid(unsigned int uMaxTreeNodeId) const;
  711. const CNodeInfo* GetNodeInfo() const;
  712. unsigned int GetSuccessTreeNodeId() const;
  713. unsigned int GetFailureTreeNodeId() const;
  714. const static unsigned int uInvalidNodeId = (~(unsigned int)0);
  715. private:
  716. CPLTreeNode();
  717. virtual ~CPLTreeNode();
  718. CNodeInfo* m_poNode;
  719. unsigned int m_uTTreeNodeId;
  720. unsigned int m_uFTreeNodeId;
  721. friend class CPipelineInformation;
  722. };
  723. class DATAELEMENTDLL_CLASS_DECL CPipelineInformation : public DIOS_Description::CDescriptions
  724. {
  725. public:
  726. bool SetPLName(const wchar_t* pwszPLName);
  727. const wchar_t* GetPLName() const;
  728. bool LoadPLFile(const wchar_t* pwszPLFilePathName);
  729. bool SavePLFile(const wchar_t* pwszPLFilePathName, DIOS_Kernel::EndianMode eMode = DIOS_Kernel::EndianMode::ENDIAN_LITTLE);
  730. TYPE_PROCESSMODULE GetType() const;
  731. const DIOS_DataElement::CWStringVectorElement* GetMemWorkMode() const;
  732. bool Check(const DIOS_DataElement::CDataElementGroup& oInputList, CHECKMODE eMode);
  733. bool GetDataElement(FuncInfoGroupType eType, const DIOS_DataElement::CDataElementGroup& oScrDataGroup, DIOS_DataElement::CDataElementGroup& oDesDataGroup);
  734. bool AddFirstElementInfo(CNodeInfo* poElement, unsigned int& uCurrId);
  735. bool AddNextElementInfo(unsigned int uPreId, bool bPreIdRes, CNodeInfo* poElement, unsigned int& uCurrId);
  736. bool AddNextElementInfo(unsigned int uPreId, bool bPreIdRes, unsigned int uCurrId);
  737. void SetPipelineInfo(CNodeInfo* oPipeLineInfo);
  738. bool AddMemMode(const wchar_t* pwszMode);
  739. unsigned int Size() const;
  740. virtual bool Encode(DIOS_Kernel::CBytesBuffer& oByteBuffer);
  741. virtual bool Decode(DIOS_Kernel::CBytesBuffer& oByteBuffer);
  742. const CPLTreeNode* Get(unsigned int nIndex) const;
  743. static void ReleasePLTreeNode(void* pCaller, CPLTreeNode* ppPLTreeNode);
  744. virtual const wchar_t* ToString() const;
  745. private:
  746. CPipelineInformation(DIOS_DataElement::CWStringVectorElement* poMemTypeName);
  747. virtual ~CPipelineInformation();
  748. void Clear();
  749. CNodeInfo* m_poPipeLineInfo;
  750. std::vector<CPLTreeNode*>* m_pvecPLTree;
  751. bool m_bPLInfoOK;
  752. DIOS_DataElement::CWStringVectorElement* m_poMemTypeName;
  753. DIOS_Kernel::CBytesBuffer m_oPLInfo;
  754. friend class DIOS_DataElement::IDataMgr;
  755. };
  756. class DATAELEMENTDLL_CLASS_DECL CFunctionInfo
  757. {
  758. public:
  759. CFunctionInfomation* CreateFunctionInfomation(const wchar_t* pwszFunctionName);
  760. CFunctionInfomation* GetFunctionInfomation(unsigned int nIndex) const;
  761. const CFunctionInfomation* GetFunctionInfomation(const wchar_t* pwszFunctionName) const;
  762. unsigned int Size() const;
  763. private:
  764. CFunctionInfo(DIOS_DataElement::IDataMgr* poDataMgr);
  765. virtual ~CFunctionInfo();
  766. static void ReleaseInformation(void* pCaller, DIOS_Description::CDescriptions* pElement);
  767. static CFunctionInfomation* CreateFunctionInfomation(DIOS_DataElement::IDataMgr* poDataMgr, const wchar_t* pwszFunctionName);
  768. DIOS_DataElement::IDataMgr* m_poDataMgr;
  769. std::vector<CFunctionInfomation*>* m_pvecFunctionInfomations;
  770. friend class DIOS_DataElement::IDataMgr;
  771. };
  772. }
  773. namespace DIOS_DataElement
  774. {
  775. #ifndef _DataMgr
  776. #define _DataMgr
  777. enum DataMgrType
  778. {
  779. MGRTYPE_DATAMGR,
  780. MGRTYPE_USERDATAMGR,
  781. };
  782. #endif
  783. class IMemDevicesMgr;
  784. class CDataDimension;
  785. class CDataDimensionMgr;
  786. class DATAELEMENTDLL_CLASS_DECL IDataMgr
  787. {
  788. public:
  789. //获取数据管理者类型
  790. inline DataMgrType GetDataMgrType() const{ return m_eMgrType; };
  791. //用户定义pixel
  792. //获取当前用户定义的像素信息
  793. DIOS_DataElementCommon::CUserDefPixelInfo* GetUserDefPixelInfo(const wchar_t* wstrDefPixelInfo, const wchar_t* wstrName);
  794. //获取像素通道信息
  795. const DIOS_DataPixel::LPDataSample* GetSampleList(unsigned int& uSamplesCount);
  796. //创建组数据单元
  797. CDataElementGroup* CreateGroupElement(const wchar_t* pwszName = L"");
  798. CWStringVectorElement* CreateWStringVectorElement(const wchar_t* pwszName = L"");
  799. CWStringMapElement* CreateWStringMapElement(const wchar_t* pwszName = L"");
  800. CDescriptionElement* CreateDescriptionElement(const wchar_t* wstrDefPixelInfo, unsigned int uDimension,
  801. const wchar_t* pwszMemTypeName = L"AnyMemory", const wchar_t* pwszSubMemTypeName = L"Normal");
  802. //创建和释放算法信息对象
  803. DIOS_PipelineDevice::CFunctionInfo* CreateFunctionInfo();
  804. static void ReleaseFunctionInfo(DIOS_PipelineDevice::CFunctionInfo* ppElement);
  805. static void CallbackReleaseFunctionInfo(void* pCaller, DIOS_PipelineDevice::CFunctionInfo* ppElement);
  806. //初始化设备
  807. bool InitDevices();
  808. bool SupportBufferAllocated(const wchar_t* pwszMemTypeName);
  809. bool IsSupportMemDevice(const CWStringVectorElement* poDevInfo);
  810. void GetDeviceTypeNames(CWStringVectorElement& oDevInfo);
  811. //释放数据单元
  812. static void ReleaseElement(IDataElement* ppElement);
  813. static void ReleaseDiscription(void* pCaller, DIOS_Description::CDescriptions* pElement);
  814. //回调释放
  815. static void CallbackReleaseElement(void* pCaller, IDataElement* ppElement);
  816. IDataElement* CreateElement(DIOS_Kernel::CBytesBuffer& oCodeBuffer);
  817. DIOS_PipelineDevice::CPipelineInformation* CreatePipelineInfo();
  818. IDataElement* CloneElement(IDataElement* pElement);
  819. static bool SaveElement(IDataElement* pElement, DIOS_Kernel::CBytesBuffer& oCodeBuffer);
  820. IDataElement* LoadElement(DIOS_Kernel::CBytesBuffer& oCodeBuffer);
  821. static bool SaveDiscription(DIOS_Description::CDescriptions* pElement, DIOS_Kernel::CBytesBuffer& oCodeBuffer);
  822. DIOS_Description::CDescriptions* LoadDiscription(DIOS_Kernel::CBytesBuffer& oCodeBuffer);
  823. protected:
  824. //创建数据单元
  825. CDataElement* CreateElement(const DIOS_DataPixel::CDataPixel* poDataPixel, unsigned int uDimension,
  826. const wchar_t* pwszName = L"", const wchar_t* pwszMemTypeName = L"Memory",
  827. unsigned int uMemDeviceId = 0, const wchar_t* pwszSubMemTypeName = L"Normal");
  828. CDataElement* CreateElement(const wchar_t* wstrPixelDesp, unsigned int uDimension,
  829. const wchar_t* pwszName = L"", const wchar_t* pwszMemTypeName = L"Memory",
  830. unsigned int uMemDeviceId = 0, const wchar_t* pwszSubMemTypeName = L"Normal");
  831. CDataElement* CreateElement(const wchar_t* pwszPixelDataJson, const wchar_t* wstrDefPixelInfo,
  832. const wchar_t* pwszName = L"", const wchar_t* pwszMemTypeName = L"Memory",
  833. unsigned int uMemDeviceId = 0, const wchar_t* pwszSubMemTypeName = L"Normal");
  834. IDataMgr(DataMgrType eType);
  835. virtual ~IDataMgr();
  836. //初始化
  837. bool DataMgrInit(const IDataMgr* oDataMgr = NULL);
  838. DIOS_DataPixel::CDataSampleMgr* m_poDataSampleMgr;//通道管理
  839. DIOS_DataPixel::CDataPixelMgr* m_poDataPixelMgr;//像素管理
  840. CDataDimensionMgr* m_poDataDimensionMgr;//维数管理
  841. IMemDevicesMgr* m_poMemDeviceMgr;//内存设备管理
  842. DataMgrType m_eMgrType;//管理者类型
  843. bool m_bInit;//初始化状态
  844. bool m_bDeviceInit;//设备初始化状态
  845. std::map<std::wstring, DIOS_DataElementCommon::CUserDefPixelInfo*>* m_pUserDefPixelInfoMap;//用户定义像素信息
  846. std::map<std::wstring, std::wstring>* m_poMgrAttr;//属性信息
  847. };
  848. /*! @class
  849. ********************************************************************************
  850. <PRE>
  851. Copyright (c) E-COM 2009-2017.
  852. All rights reserved.
  853. CLASS NAME: CUserDataMgr
  854. DESCRIPTION: DIOS 数据单元对象管理者,用于Pipeline和算法单元。
  855. NOTES:
  856. AUTHOR: 王凯
  857. VERSION:
  858. HISTORY: 2017-6-1 First version
  859. 2017-6-20 support Pipeline and Algorithm
  860. </PRE>
  861. *******************************************************************************/
  862. class DATAELEMENTDLL_CLASS_DECL CUserDataMgr : public IDataMgr
  863. {
  864. public:
  865. const void* GetMemDeviceAttr(const wchar_t* pwszMemTypeName, const wchar_t* pwszDeviceKey);
  866. bool SetMemDeviceAttr(const wchar_t* pwszMemTypeName, const wchar_t* pwszDeviceKey, void* pDeviceAttr);
  867. CDataElement* CreateDataElement(const wchar_t* wstrPixelDesp, unsigned int uDimension,
  868. const wchar_t* pwszName = L"", const wchar_t* pwszMemTypeName = L"Memory",
  869. const wchar_t* pwszSubMemTypeName = L"Normal");
  870. CDataElement* CreateDataElement(const CDescriptionElement* poDataGroup, bool bUpdateName = false, const wchar_t* pwszName = L"");
  871. bool AddDataElementsForGroup(const CDataElementGroup* poGroupDescription, CDataElementGroup* poDataGroup);
  872. };
  873. /*! @class
  874. ********************************************************************************
  875. <PRE>
  876. Copyright (c) E-COM 2009-2017.
  877. All rights reserved.
  878. CLASS NAME: CDataMgr
  879. DESCRIPTION: DIOS 数据单元对象管理者。
  880. NOTES:
  881. AUTHOR: 王凯
  882. VERSION:
  883. HISTORY: 2017-6-1 First version
  884. </PRE>
  885. *******************************************************************************/
  886. class DATAELEMENTDLL_CLASS_DECL CDataMgr : public IDataMgr
  887. {
  888. public:
  889. CDataMgr();
  890. virtual ~CDataMgr();
  891. bool Init(const wchar_t* pwszDataTypeCfgPath = L"", const wchar_t* pwszLogDir = L"");
  892. CDataElement* CreateDataElement(const wchar_t* wstrPixelDesp,
  893. unsigned int uDimension,
  894. const wchar_t* pwszName = L"",
  895. const wchar_t* pwszMemTypeName = L"Memory",
  896. unsigned int uMemDeviceId = 0,
  897. const wchar_t* pwszSubMemTypeName = L"Normal"
  898. );
  899. CDataElement* CreateDataElement(const DIOS_DataPixel::CDataPixel* poDataPixel,
  900. unsigned int uDimension,
  901. const wchar_t* pwszName = L"",
  902. const wchar_t* pwszMemTypeName = L"Memory",
  903. unsigned int uMemDeviceId = 0,
  904. const wchar_t* pwszSubMemTypeName = L"Normal");
  905. CDataElement* CreateDataElement(
  906. const wchar_t* pwszPixelDataJson,
  907. const wchar_t* wstrDefPixelInfo,
  908. const wchar_t* pwszName = L"",
  909. const wchar_t* pwszMemTypeName = L"Memory",
  910. unsigned int uMemDeviceId = 0,
  911. const wchar_t* pwszSubMemTypeName = L"Normal");
  912. CUserDataMgr* CreateUserDataMgr(const IDataElement* poInfo);
  913. static void ReleaseUserDataMgr(void* pCaller, CUserDataMgr* ppUserDataMgr);
  914. };
  915. }
  916. #define LPPIDataElement (DIOS_DataElement::IDataElement**)