Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
6.3 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: fwevent.cxx
  7. //
  8. // Contents: CFwEventItem Class
  9. //
  10. // History: 02-Jan-97 mohamedn Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <ciintf.h>
  16. #include <fwevent.hxx>
  17. //+-------------------------------------------------------------------------
  18. //
  19. // Method: CFwEventItem::CFwEventItem
  20. //
  21. // Purpose: Encapsulates all information pertaining to a given event
  22. // and invokes ICiCAdviseStatus::NotifyEvent method.
  23. //
  24. // Arguments: [fType ] - Type of event
  25. // [eventId] - Message file event identifier
  26. // [cArgs] - Number of substitution arguments being passed
  27. // [cbData ] - number of bytes in supplemental raw data.
  28. // [data ] - pointer to block of supplemental data.
  29. //
  30. // History: 02-Jan-97 MohamedN Created
  31. //
  32. //--------------------------------------------------------------------------
  33. CFwEventItem::CFwEventItem( WORD fType,
  34. DWORD eventId,
  35. WORD cArgs,
  36. DWORD dataSize,
  37. void * data ) :
  38. _fType(fType),
  39. _eventId(eventId),
  40. _nParams(cArgs),
  41. _nParamsUsed(0),
  42. _dataSize(dataSize),
  43. _data(data)
  44. {
  45. _pPv = new PROPVARIANT[_nParams];
  46. memset(_pPv, 0, sizeof(PROPVARIANT) * _nParams);
  47. END_CONSTRUCTION(CFwEventItem);
  48. }
  49. //+-------------------------------------------------------------------------
  50. //
  51. // Method: CFwEventItem::~CFwEventItem
  52. //
  53. // Purpose: destructor, deallocates any allocated memory.
  54. //
  55. // History: 02-Jan-97 MohamedN Created
  56. //
  57. //--------------------------------------------------------------------------
  58. CFwEventItem::~CFwEventItem()
  59. {
  60. for ( WORD i = 0; i < _nParamsUsed; i++ )
  61. {
  62. switch (_pPv[i].vt)
  63. {
  64. case VT_LPSTR:
  65. delete _pPv[i].pszVal;
  66. _pPv[i].pszVal = 0;
  67. break;
  68. case VT_LPWSTR:
  69. delete _pPv[i].pwszVal;
  70. _pPv[i].pwszVal = 0;
  71. break;
  72. case VT_UI4:
  73. break;
  74. default: // should never be hit
  75. Win4Assert( !"~CFwEventItem, default case should never be hit");
  76. }
  77. }
  78. // delete the PROPVARIANT array we allocated.
  79. delete [] _pPv;
  80. _pPv = 0;
  81. }
  82. //+-------------------------------------------------------------------------
  83. //
  84. // Member: CFwEventItem::AddArg
  85. //
  86. // Synopsis: Adds wcsString to embed in the eventlog message.
  87. //
  88. // Arguments: [wcsString] - wide char string to be added
  89. //
  90. // History: 02-Jan-97 MohamedN Created
  91. //
  92. //--------------------------------------------------------------------------
  93. void CFwEventItem::AddArg( const WCHAR * wcsString )
  94. {
  95. Win4Assert( _nParamsUsed < _nParams );
  96. Win4Assert( 0 != wcsString );
  97. _pPv[_nParamsUsed].vt = VT_LPWSTR;
  98. ULONG cc = wcslen(wcsString) + 1;
  99. _pPv[_nParamsUsed].pwszVal = new WCHAR [cc];
  100. RtlCopyMemory( _pPv[_nParamsUsed].pwszVal, wcsString, cc * sizeof(WCHAR) );
  101. _nParamsUsed++;
  102. }
  103. //+-------------------------------------------------------------------------
  104. //
  105. // Member: CFwEventItem::AddArg
  106. //
  107. // Synopsis: adds pszString to embed in the eventlog message.
  108. //
  109. // Arguments: [pszString] - null terminated ASCII string to be added
  110. //
  111. // History: 02-Jan-97 MohamedN Created
  112. //
  113. //--------------------------------------------------------------------------
  114. void CFwEventItem::AddArg( const CHAR * pszString )
  115. {
  116. Win4Assert( _nParamsUsed < _nParams );
  117. Win4Assert( 0 != pszString );
  118. _pPv[_nParamsUsed].vt = VT_LPSTR;
  119. ULONG cc = strlen(pszString) + 1;
  120. _pPv[_nParamsUsed].pszVal = new CHAR [cc];
  121. RtlCopyMemory( _pPv[_nParamsUsed].pszVal, pszString, cc * sizeof(CHAR) );
  122. _nParamsUsed++;
  123. }
  124. //+-------------------------------------------------------------------------
  125. //
  126. // Member: CFwEventItem::AddArg
  127. //
  128. // Synopsis: adds ulValue to embed in the eventlog message.
  129. //
  130. // Arguments: [ulValue] - unsigned long value to be added.
  131. //
  132. // History: 02-Jan-97 MohamedN Created
  133. //
  134. //--------------------------------------------------------------------------
  135. void CFwEventItem::AddArg( const ULONG ulValue )
  136. {
  137. Win4Assert( _nParamsUsed < _nParams );
  138. _pPv[_nParamsUsed].vt = VT_UI4;
  139. _pPv[_nParamsUsed].ulVal = ulValue;
  140. _nParamsUsed++;
  141. }
  142. //+-------------------------------------------------------------------------
  143. //
  144. // Member: CFwEventItem::ReportEvent
  145. //
  146. // Synopsis: Invokes ICiCAdviseStatus::NotifyEvent method.
  147. //
  148. // Arguments: [adviseStatus] - reference to ICiCAdviseStatus
  149. //
  150. // History: 02-Jan-96 mohamedn Created
  151. //
  152. //--------------------------------------------------------------------------
  153. void CFwEventItem::ReportEvent(ICiCAdviseStatus & adviseStatus)
  154. {
  155. Win4Assert( _nParamsUsed == _nParams );
  156. SCODE sc = 0;
  157. sc = adviseStatus.NotifyEvent( _fType,
  158. _eventId,
  159. _nParams,
  160. _pPv,
  161. _dataSize,
  162. _data);
  163. if (sc != S_OK)
  164. {
  165. // Don't throw an exception here...
  166. ciDebugOut(( DEB_ERROR, "adviseStatus.Notify() error: 0x%X\n",
  167. sc ));
  168. }
  169. }