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.

197 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Abstract:
  4. Log Engine declaration.
  5. Author:
  6. Souren Aghajanyan (sourenag) 24-Sep-2001
  7. Revision History:
  8. <alias> <date> <comments>
  9. --*/
  10. #pragma once
  11. #include "log.h"
  12. #include "sysfunc.h"
  13. #include "templ.h"
  14. #include "mem.h"
  15. #define HEADER_SIZE 4096 //PAGE_ALIGNED
  16. #define SHARED_DATA_STRUCTURE_ALIGMENT 8
  17. #define ALIGN_DATA(addr, alignment) ((addr)%(alignment)?(((addr)-((addr)%(alignment)))+(alignment)):(addr))
  18. #define INITIAL_SIZE_OF_SHARED_SECTION (HEADER_SIZE<<3)
  19. #define InlineIsEqualGUID(rguid1, rguid2) \
  20. (((PLONG) rguid1)[0] == ((PLONG) rguid2)[0] && \
  21. ((PLONG) rguid1)[1] == ((PLONG) rguid2)[1] && \
  22. ((PLONG) rguid1)[2] == ((PLONG) rguid2)[2] && \
  23. ((PLONG) rguid1)[3] == ((PLONG) rguid2)[3])
  24. #pragma warning(disable:4200)
  25. #pragma warning(disable:4103)
  26. class ILogContext
  27. {
  28. public:
  29. virtual BOOL PreAllocBuffer(UINT uiSize, DWORD dwReserved) = 0;
  30. virtual PVOID AllocBuffer(UINT uiSize, DWORD dwReserved) = 0;
  31. virtual PVOID ReAllocBuffer(UINT uiSize, DWORD dwReserved) = 0;
  32. virtual PVOID GetBuffer(UINT* puiSize, DWORD dwReserved) = 0;
  33. virtual VOID FreeBuffer() = 0;
  34. virtual BOOL GetFieldIndexFromName(PCWSTR pFieldName, UINT* puiFieldIndex) = 0;
  35. virtual const PLOG_FIELD_VALUE GetFieldValue(UINT iFieldNumber) = 0;
  36. virtual UINT GetFieldsCount() = 0;
  37. };
  38. class ILogProvider
  39. {
  40. public:
  41. virtual LOG_PROVIDER_TYPE GetType() = 0;
  42. virtual VOID GetGUID(GUID *pGUID) = 0;
  43. virtual LOGRESULT Init(PVOID pvCustomData, ILogContext * pLogContext) = 0;
  44. virtual VOID PreProcess(ILogContext * pLogContext, BOOL bFirstInstance) = 0;
  45. virtual LOGRESULT Process(ILogContext * pLogContext) = 0;
  46. virtual VOID PreDestroy(ILogContext * pLogContext, BOOL bLastInstance) = 0;
  47. virtual PCWSTR ToString() = 0;
  48. virtual VOID DestroyObject() = 0; // never call this method from provider
  49. };
  50. #pragma pack(push, log_pack)
  51. #pragma pack(8)
  52. typedef struct tagLOG_FILTER_WITH_REF_COUNT{
  53. UINT Size;
  54. UINT ReferenceCount;
  55. GUID FormatterGUID;
  56. WCHAR UniqueDestinationString[0];
  57. }LOG_FILTER_WITH_REF_COUNT, *PLOG_FILTER_WITH_REF_COUNT;
  58. typedef struct tagLOG_FIELD_INFO_WITH_REF_COUNT{
  59. UINT ReferenceCount;
  60. LOG_FIELD_INFO FieldDescription;
  61. }LOG_FIELD_INFO_WITH_REF_COUNT, *PLOG_FIELD_INFO_WITH_REF_COUNT;
  62. typedef struct tagLOG_SHARED_STRUCTURES_INFO{
  63. DWORD FirstElementOffset; //Offset from begining of shared data;
  64. DWORD SizeOfUsedMemory;
  65. DWORD MaxSizeOfMemory;
  66. }LOG_SHARED_STRUCTURES_INFO, *PLOG_SHARED_STRUCTURES_INFO;
  67. typedef struct tagLOG_SHARED_DATA{
  68. LOG_SHARED_STRUCTURES_INFO Fields;
  69. LOG_SHARED_STRUCTURES_INFO Filters;
  70. LOG_SHARED_STRUCTURES_INFO Reserved;
  71. }LOG_SHARED_DATA, *PLOG_SHARED_DATA;
  72. #pragma pack(pop, log_pack)
  73. typedef struct tagLOG_OUTPUT_STACK{
  74. ILogProvider * m_Filter;
  75. ILogProvider * m_Formater;
  76. ILogProvider * m_Device;
  77. }LOG_OUTPUT_STACK, *PLOG_OUTPUT_STACK;
  78. #define STACK_LIST_CLASS CPtrList<PLOG_OUTPUT_STACK>
  79. class CLogManager:
  80. public ILogManager,
  81. protected ILogContext
  82. {
  83. PLOG_SHARED_DATA m_SharedData;
  84. CSharedMemory m_SharedMemory;
  85. CMutualExclusionObject m_Mutex; // controls access to m_SharedData
  86. PLOG_FIELD_VALUE m_FieldsValue;
  87. UINT m_FieldsNumber;
  88. CBuffer * m_ConversionBuffers;
  89. UINT m_ConversionBuffersNumber;
  90. STACK_LIST_CLASS m_StackList;
  91. CBuffer m_CommonBuffer;
  92. protected:
  93. BOOL InitSharedData(UINT SizeForAllSharedData);
  94. BOOL GetSharedData(IN PCWSTR pLogName); // initialize SHARED_DATA structures
  95. BOOL ReleaseSharedData(VOID);
  96. BOOL ValidateAndAddFieldsIfOk(PLOG_FIELD_INFO pFields, UINT NumberOfFields);
  97. BOOL RemoveFields();
  98. VOID Close();
  99. BOOL FindSharedStack(const GUID *pFormaterGUID, PCWSTR UniqueDestString, PLOG_FILTER_WITH_REF_COUNT * ppFilterData);
  100. BOOL ShareStack(const GUID *pFormaterGUID, PCWSTR UniqueDestString, BOOL bDestAlreadyExist);
  101. BOOL UnShareStack(const GUID *pFormaterGUID, PCWSTR UniqueDestString);
  102. BOOL DestroyStack(PLOG_OUTPUT_STACK pLogStack);
  103. BOOL CreateConversionBuffers(UINT NumberOfConversionBuffers);
  104. VOID DestroyConversionBuffers();
  105. LOGRESULT LogMessage();
  106. public:
  107. CLogManager();
  108. ~CLogManager();
  109. BOOL Init(PCWSTR pLogName,
  110. LOG_FIELD_INFO * pFields,
  111. UINT NumberOfFields);
  112. BOOL STDMETHODCALLTYPE AddStack(const GUID * guidFilter, PVOID pFilterData,
  113. const GUID * guidFormater, PVOID pFormaterData,
  114. const GUID * guidDevice, PVOID pDeviceData,
  115. PVOID * pvHandle);
  116. BOOL STDMETHODCALLTYPE RemoveStack(PVOID pvHandle);
  117. LOGRESULT STDMETHODCALLTYPE LogA(UINT NumberOfFieldsToLog, ...);
  118. LOGRESULT STDMETHODCALLTYPE LogW(UINT NumberOfFieldsToLog, ...);
  119. protected:
  120. // interface ILogContext
  121. BOOL PreAllocBuffer(UINT uiSize, DWORD dwReserved){return m_CommonBuffer.PreAllocate(uiSize);};
  122. PVOID AllocBuffer(UINT uiSize, DWORD dwReserved){return m_CommonBuffer.Allocate(uiSize);};
  123. PVOID ReAllocBuffer(UINT uiSize, DWORD dwReserved){return m_CommonBuffer.ReAllocate(uiSize);};
  124. PVOID GetBuffer(UINT* puiSize, DWORD dwReserved){if(puiSize){*puiSize = m_CommonBuffer.GetSize();};return m_CommonBuffer.GetBuffer();};
  125. VOID FreeBuffer(){m_CommonBuffer.Free();};
  126. BOOL GetFieldIndexFromName(PCWSTR pFieldName, UINT* puiFieldIndex);
  127. const PLOG_FIELD_VALUE GetFieldValue(UINT iFieldNumber){ASSERT(iFieldNumber < m_FieldsNumber);return &m_FieldsValue[iFieldNumber];}
  128. UINT GetFieldsCount(){return m_FieldsNumber;}
  129. };
  130. typedef ILogProvider* (*CREATE_OBJECT_FUNC)();
  131. BOOL LogRegisterProvider(
  132. IN const GUID * pGUID,
  133. IN CREATE_OBJECT_FUNC pCreateObject
  134. );
  135. BOOL LogUnRegisterProvider(
  136. IN const GUID * pGUID
  137. );
  138. ILogProvider *
  139. LogiCreateProvider(
  140. IN const GUID * pGUID
  141. );
  142. BOOL
  143. LogiDestroyProvider(
  144. IN ILogProvider * pILogProvider
  145. );
  146. class __declspec(uuid("00000000-0000-0000-c000-000000000000")) CStandardSetupLogFilter;
  147. class __declspec(uuid("00000000-0000-0000-c000-000000000001")) CStandardSetupLogFormatter;
  148. class __declspec(uuid("00000000-0000-0000-c000-000000000002")) CFileDevice;
  149. class __declspec(uuid("00000000-0000-0000-c000-000000000003")) CDebugFormatterAndDevice;
  150. class __declspec(uuid("00000000-0000-0000-c000-000000000004")) CDebugFilter;
  151. class __declspec(uuid("00000000-0000-0000-c000-000000000005")) CXMLLogFormatter;