ShareMemWR.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #pragma once
  2. //#include "DIOSLogicDeviceStructure.h"
  3. #include "ShareMemClientInterface.h"
  4. #include "Definitions.h"
  5. #define SM_API_BLOCK_COUNT (15)
  6. class ImgDataInfo : public BaseJsonDataObject<bool>
  7. {
  8. public:
  9. BaseJsonDataObject<unsigned int> nImageType;
  10. BaseJsonDataObject<unsigned int> nViewType;
  11. BaseJsonDataObject<unsigned long long> nShareMemID;
  12. BaseJsonDataObject<unsigned long long> nImageID;
  13. BaseJsonDataObject<unsigned int> nWidth;
  14. BaseJsonDataObject<unsigned int> nHeight;
  15. BaseJsonDataObject<unsigned int> nBit;
  16. ImgDataInfo(void)
  17. {
  18. const char* keystring = "ImageType";
  19. nImageType.SetKey(keystring);
  20. keystring = "Viewtype";
  21. nViewType.SetKey(keystring);
  22. keystring = "Sharememid";
  23. nShareMemID.SetKey(keystring);
  24. keystring = "Imageid";
  25. nImageID.SetKey(keystring);
  26. keystring = "Width";
  27. nWidth.SetKey(keystring);
  28. keystring = "Height";
  29. nHeight.SetKey(keystring);
  30. keystring = "Bit";
  31. nBit.SetKey(keystring);
  32. }
  33. virtual ~ImgDataInfo(void)
  34. {
  35. }
  36. virtual void GetResDataObject(ResDataObject &obj)
  37. {
  38. //ResDataObject loca1;
  39. obj.add(nImageType.GetKey(), nImageType.GetVal());
  40. obj.add(nViewType.GetKey(), nViewType.GetVal());
  41. obj.add(nShareMemID.GetKey(), nShareMemID.GetVal());
  42. obj.add(nImageID.GetKey(), nImageID.GetVal());
  43. obj.add(nWidth.GetKey(), nWidth.GetVal());
  44. obj.add(nHeight.GetKey(), nHeight.GetVal());
  45. obj.add(nBit.GetKey(), nBit.GetVal());
  46. //obj.add(GetKey(), loca1);
  47. };
  48. virtual bool SetResDataObject(ResDataObject &obj)
  49. {
  50. bool ret = true;
  51. try {
  52. nImageType = obj[nImageType.GetKey()];
  53. nViewType = obj[nViewType.GetKey()];
  54. nShareMemID = obj[nShareMemID.GetKey()];
  55. nImageID = obj[nImageID.GetKey()];
  56. nWidth = obj[nWidth.GetKey()];
  57. nHeight = obj[nHeight.GetKey()];
  58. nBit = obj[nBit.GetKey()];
  59. }
  60. catch (...)
  61. {
  62. ret = false;
  63. }
  64. return ret;
  65. };
  66. virtual const char *GetVal()
  67. {
  68. ResDataObject obj;
  69. obj.add(nImageType.GetKey(), nImageType.GetVal());
  70. obj.add(nViewType.GetKey(), nViewType.GetVal());
  71. obj.add(nShareMemID.GetKey(), nShareMemID.GetVal());
  72. obj.add(nImageID.GetKey(), nImageID.GetVal());
  73. obj.add(nWidth.GetKey(), nWidth.GetVal());
  74. obj.add(nHeight.GetKey(), nHeight.GetVal());
  75. obj.add(nBit.GetKey(), nBit.GetVal());
  76. (m_ValString) = obj.encode();
  77. return m_ValString.c_str();
  78. };
  79. virtual bool SetVal(const char* pValString)
  80. {
  81. ResDataObject obj;
  82. if (obj.decode(pValString))
  83. {
  84. int idx;
  85. idx = obj.GetFirstOf(nImageType.GetKey());
  86. if (idx >= 0)
  87. {
  88. nImageType.SetVal(obj[idx]);
  89. }
  90. idx = obj.GetFirstOf(nViewType.GetKey());
  91. if (idx >= 0)
  92. {
  93. nViewType.SetVal(obj[idx]);
  94. }
  95. idx = obj.GetFirstOf(nShareMemID.GetKey());
  96. if (idx >= 0)
  97. {
  98. nShareMemID.SetVal(obj[idx]);
  99. }
  100. idx = obj.GetFirstOf(nImageID.GetKey());
  101. if (idx >= 0)
  102. {
  103. nImageID.SetVal(obj[idx]);
  104. }
  105. idx = obj.GetFirstOf(nWidth.GetKey());
  106. if (idx >= 0)
  107. {
  108. nWidth.SetVal(obj[idx]);
  109. }
  110. idx = obj.GetFirstOf(nHeight.GetKey());
  111. if (idx >= 0)
  112. {
  113. nHeight.SetVal(obj[idx]);
  114. }
  115. idx = obj.GetFirstOf(nBit.GetKey());
  116. if (idx >= 0)
  117. {
  118. nBit.SetVal(obj[idx]);
  119. }
  120. return true;
  121. }
  122. return false;
  123. };
  124. virtual void SetKey(const char* pKeyString)
  125. {
  126. BaseJsonDataObject<bool>::SetKey(pKeyString);
  127. //make key
  128. const char* keystring = "ImageType";
  129. nImageType.SetKey(keystring);
  130. keystring = "Viewtype";
  131. nViewType.SetKey(keystring);
  132. keystring = "Sharememid";
  133. nShareMemID.SetKey(keystring);
  134. keystring = "Imageid";
  135. nImageID.SetKey(keystring);
  136. keystring = "Width";
  137. nWidth.SetKey(keystring);
  138. keystring = "Height";
  139. nHeight.SetKey(keystring);
  140. keystring = "Bit";
  141. nBit.SetKey(keystring);
  142. };
  143. };
  144. class ShareMemWR {
  145. unsigned short*m_pDataPtr;
  146. CShareMemClient m_shareMemclient;
  147. C2DGrayImageData *m_pImgFull;
  148. C2DGrayImageData *m_pImgPrev;
  149. CBaseFunctionDataElement *m_pElement;
  150. unsigned int m_dwShareMemIdFullIdx;
  151. unsigned long long m_dwShareMemIdFull[SM_API_BLOCK_COUNT];
  152. unsigned long long m_dwShareMemIdPreview;
  153. ImgDataInfo *pImgData;
  154. bool GetShareMemBuf(ImgDataInfo *pImgData);
  155. int WriteImageToShareMem(unsigned long long &dwShareMemId);
  156. unsigned long long &GetNextSmId();
  157. public:
  158. ShareMemWR(void);
  159. virtual ~ShareMemWR(void);
  160. void * GetDataBuf(unsigned long long nShareMemID, char *&pBuff,DWORD &Size);
  161. void ReleaseDataBuf(void * Handle);
  162. RET_STATUS BufferToNotify(void * pOemImage, DWORD ImageSize, ImgDataInfo* PImgDataInfo);
  163. };