DataElementInterface.h 33 KB

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