AGCEventData.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #ifndef __AGCEventData_h__
  2. #define __AGCEventData_h__
  3. /////////////////////////////////////////////////////////////////////////////
  4. // AGCEventData.h : Declaration of the CAGCEventData class.
  5. //
  6. #include <AGC.h>
  7. #include "AGCEvent.h"
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CAGCEventData
  10. //
  11. class CAGCEventData
  12. {
  13. // Types
  14. public:
  15. typedef CAGCEvent::XProperties XProperties;
  16. // Construction / Destruction
  17. private:
  18. CAGCEventData(const CAGCEventData&); // Disable copy constructor
  19. public:
  20. CAGCEventData(UINT cbData, BYTE* pbData);
  21. CAGCEventData(AGCEventID idEvent, LPCSTR pszContext, LPCOLESTR pszSubject,
  22. long idSubject, long cArgTriplets, va_list argptr);
  23. ~CAGCEventData();
  24. void Attach(UINT cbData, BYTE* pbData);
  25. BYTE* Detach(UINT* pcbData = NULL);
  26. // Attributes
  27. public:
  28. AGCEventID GetEventID() const;
  29. DATE GetTime () const;
  30. long GetSubjectID() const;
  31. long GetArgCount () const;
  32. void GetVarData (BSTR* pbstrContext, BSTR* pbstrSubject,
  33. XProperties* pProperties) const;
  34. // Implementation
  35. protected:
  36. static UINT ComputeVariableDataSize(LPCSTR pszContext,
  37. LPCOLESTR pszSubject, long cArgTriplets, va_list argptr);
  38. void CopyVariableData(LPCSTR pszContext, LPCOLESTR pszSubject,
  39. long cArgTriplets, va_list argptr);
  40. static UINT CreateVARIANTFromData(BYTE* pbData, CComVariant& var);
  41. static UINT CreateBSTRFromData(BYTE* pbData, BSTR* pbstr);
  42. static UINT CreateBSTRFromData_LPSTR(BYTE* pbData, BSTR* pbstr);
  43. static UINT CreateBSTRFromData_LPWSTR(BYTE* pbData, BSTR* pbstr);
  44. static UINT CreateObjectFromData(BYTE* pbData, REFIID riid, void** ppvUnk);
  45. // Types
  46. protected:
  47. #pragma pack(push, 4)
  48. struct XData
  49. {
  50. AGCEventID m_id;
  51. DATE m_time;
  52. long m_idSubject;
  53. long m_cArgTriplets;
  54. };
  55. #pragma pack(pop)
  56. // Data Members
  57. protected:
  58. UINT m_cbData;
  59. BYTE* m_pbData;
  60. };
  61. /////////////////////////////////////////////////////////////////////////////
  62. // Construction / Destruction
  63. /////////////////////////////////////////////////////////////////////////////
  64. //
  65. inline CAGCEventData::CAGCEventData(UINT cbData, BYTE* pbData) :
  66. m_cbData(0),
  67. m_pbData(NULL)
  68. {
  69. Attach(cbData, pbData);
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. //
  73. inline CAGCEventData::CAGCEventData(AGCEventID idEvent, LPCSTR pszContext,
  74. LPCOLESTR pszSubject, long idSubject, long cArgTriplets, va_list argptr) :
  75. m_cbData(0),
  76. m_pbData(NULL)
  77. {
  78. // Calculate the size needed for all the variable data
  79. m_cbData = ComputeVariableDataSize(pszContext, pszSubject, cArgTriplets, argptr);
  80. m_cbData += sizeof(XData);
  81. // Allocate memory for the data
  82. m_pbData = new BYTE[m_cbData];
  83. assert(m_pbData);
  84. // Copy the fixed data to the memory
  85. XData* pFixed = reinterpret_cast<XData*>(m_pbData);
  86. pFixed->m_id = idEvent;
  87. pFixed->m_time = GetVariantDateTime();
  88. pFixed->m_idSubject = idSubject;
  89. pFixed->m_cArgTriplets = cArgTriplets;
  90. // Copy the variable data to the memory
  91. CopyVariableData(pszContext, pszSubject, cArgTriplets, argptr);
  92. }
  93. /////////////////////////////////////////////////////////////////////////////
  94. //
  95. inline CAGCEventData::~CAGCEventData()
  96. {
  97. delete [] Detach();
  98. }
  99. /////////////////////////////////////////////////////////////////////////////
  100. //
  101. inline void CAGCEventData::Attach(UINT cbData, BYTE* pbData)
  102. {
  103. delete [] Detach();
  104. m_cbData = cbData;
  105. m_pbData = pbData;
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. //
  109. inline BYTE* CAGCEventData::Detach(UINT* pcbData)
  110. {
  111. if (pcbData)
  112. *pcbData = m_cbData;
  113. BYTE* pbData = m_pbData;
  114. m_cbData = 0;
  115. m_pbData = NULL;
  116. return pbData;
  117. }
  118. /////////////////////////////////////////////////////////////////////////////
  119. // Attributes
  120. inline AGCEventID CAGCEventData::GetEventID() const
  121. {
  122. assert(m_pbData && m_cbData >= sizeof(XData));
  123. XData* pData = reinterpret_cast<XData*>(m_pbData);
  124. return pData->m_id;
  125. }
  126. inline DATE CAGCEventData::GetTime() const
  127. {
  128. assert(m_pbData && m_cbData >= sizeof(XData));
  129. XData* pData = reinterpret_cast<XData*>(m_pbData);
  130. return pData->m_time;
  131. }
  132. inline long CAGCEventData::GetSubjectID() const
  133. {
  134. assert(m_pbData && m_cbData >= sizeof(XData));
  135. XData* pData = reinterpret_cast<XData*>(m_pbData);
  136. return pData->m_idSubject;
  137. }
  138. inline long CAGCEventData::GetArgCount() const
  139. {
  140. assert(m_pbData && m_cbData >= sizeof(XData));
  141. XData* pData = reinterpret_cast<XData*>(m_pbData);
  142. return pData->m_cArgTriplets;
  143. }
  144. /////////////////////////////////////////////////////////////////////////////
  145. #endif //__AGCEventData_h__