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.

227 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Abstract:
  4. API for register/unregister and using Log Providers.
  5. Author:
  6. Souren Aghajanyan (sourenag) 24-Sep-2001
  7. Revision History:
  8. <alias> <date> <comments>
  9. --*/
  10. #include "pch.h"
  11. #include "log.h"
  12. #include "log_man.h"
  13. #include "stockpr.h"
  14. #include "templ.h"
  15. const GUID GUID_STANDARD_SETUPLOG_FILTER = __uuidof(CStandardSetupLogFilter);
  16. const GUID GUID_STANDARD_SETUPLOG_FORMATTER = __uuidof(CStandardSetupLogFormatter);
  17. const GUID GUID_FILE_DEVICE = __uuidof(CFileDevice);
  18. const GUID GUID_DEBUG_FORMATTER_AND_DEVICE = __uuidof(CDebugFormatterAndDevice);
  19. const GUID GUID_DEBUG_FILTER = __uuidof(CDebugFilter);
  20. const GUID GUID_XML_FORMATTER = __uuidof(CXMLLogFormatter);
  21. typedef struct tagLOG_PROVIDER_ENTRY{
  22. UINT uiRefCount;
  23. GUID ProviderGUID;
  24. CREATE_OBJECT_FUNC pCreateObject;
  25. }LOG_PROVIDER_ENTRY, *PLOG_PROVIDER_ENTRY;
  26. #define PROV_LIST_CLASS CPtrList<PLOG_PROVIDER_ENTRY>
  27. static PROV_LIST_CLASS * g_ProviderList = NULL;
  28. BOOL
  29. LogRegisterProvider(
  30. IN const GUID * pGUID,
  31. IN CREATE_OBJECT_FUNC pCreateObject
  32. )
  33. {
  34. PLOG_PROVIDER_ENTRY pProviderEntry;
  35. if(!pGUID || !pCreateObject){
  36. ASSERT(pGUID && pCreateObject);
  37. return FALSE;
  38. }
  39. if(!g_ProviderList){
  40. g_ProviderList = new PROV_LIST_CLASS;
  41. if(!g_ProviderList){
  42. return FALSE;
  43. }
  44. }
  45. //walk through list
  46. for(pProviderEntry = g_ProviderList->BeginEnum(); pProviderEntry; pProviderEntry = g_ProviderList->Next()){
  47. ASSERT(pProviderEntry);
  48. if(InlineIsEqualGUID(&pProviderEntry->ProviderGUID, pGUID)){
  49. if(pProviderEntry->pCreateObject == pCreateObject){
  50. return TRUE;
  51. }
  52. ASSERT(FALSE);
  53. return FALSE;
  54. }
  55. }
  56. pProviderEntry = (PLOG_PROVIDER_ENTRY)MALLOC(sizeof(LOG_PROVIDER_ENTRY));
  57. if(!pProviderEntry){
  58. ASSERT(pProviderEntry);
  59. return FALSE;
  60. };
  61. //append to list
  62. pProviderEntry->uiRefCount = 0;
  63. pProviderEntry->ProviderGUID = *pGUID;
  64. pProviderEntry->pCreateObject = pCreateObject;
  65. g_ProviderList->Add(pProviderEntry);
  66. return TRUE;
  67. }
  68. BOOL
  69. LogUnRegisterProvider(
  70. IN const GUID * pGUID
  71. )
  72. {
  73. PLOG_PROVIDER_ENTRY pProviderEntry;
  74. if(!g_ProviderList){
  75. return TRUE;
  76. }
  77. if(!pGUID){
  78. ASSERT(pGUID);
  79. return FALSE;
  80. }
  81. //walk through list
  82. for(pProviderEntry = g_ProviderList->BeginEnum(); pProviderEntry; pProviderEntry = g_ProviderList->Next()){
  83. ASSERT(pProviderEntry);
  84. if(InlineIsEqualGUID(&pProviderEntry->ProviderGUID, pGUID)){
  85. if(pProviderEntry->uiRefCount){
  86. return FALSE;
  87. }
  88. //exclude and free list item
  89. g_ProviderList->Remove(pProviderEntry);
  90. FREE(pProviderEntry);
  91. if(!g_ProviderList->BeginEnum()){
  92. delete g_ProviderList;
  93. g_ProviderList = NULL;
  94. }
  95. return TRUE;
  96. }
  97. }
  98. return TRUE;
  99. }
  100. ILogProvider *
  101. LogiCreateProvider(
  102. IN const GUID * pGUID
  103. )
  104. {
  105. PLOG_PROVIDER_ENTRY pProviderEntry;
  106. ILogProvider * pLogProvider = NULL;
  107. if(!g_ProviderList){
  108. return NULL;
  109. }
  110. if(!pGUID){
  111. ASSERT(pGUID);
  112. return NULL;
  113. }
  114. //walk through list
  115. for(pProviderEntry = g_ProviderList->BeginEnum(); pProviderEntry; pProviderEntry = g_ProviderList->Next()){
  116. ASSERT(pProviderEntry);
  117. if(InlineIsEqualGUID(&pProviderEntry->ProviderGUID, pGUID)){
  118. ASSERT(pProviderEntry->pCreateObject);
  119. pLogProvider = pProviderEntry->pCreateObject();
  120. if(pLogProvider){
  121. pProviderEntry->uiRefCount++;
  122. }
  123. return pLogProvider;
  124. }
  125. }
  126. return NULL;
  127. }
  128. BOOL
  129. LogiDestroyProvider(
  130. IN ILogProvider * pILogProvider
  131. )
  132. {
  133. PLOG_PROVIDER_ENTRY pProviderEntry;
  134. GUID guidProvider;
  135. if(!g_ProviderList){
  136. return NULL;
  137. }
  138. if(!pILogProvider){
  139. ASSERT(pILogProvider);
  140. return FALSE;
  141. }
  142. pILogProvider->GetGUID(&guidProvider);
  143. //walk through list
  144. for(pProviderEntry = g_ProviderList->BeginEnum(); pProviderEntry; pProviderEntry = g_ProviderList->Next()){
  145. ASSERT(pProviderEntry);
  146. if(InlineIsEqualGUID(&pProviderEntry->ProviderGUID, &guidProvider)){
  147. pProviderEntry->uiRefCount--;
  148. pILogProvider->DestroyObject();
  149. return TRUE;
  150. }
  151. }
  152. return FALSE;
  153. }
  154. BOOL
  155. LogRegisterStockProviders(
  156. VOID
  157. )
  158. {
  159. LogRegisterProvider(&GUID_STANDARD_SETUPLOG_FILTER, CStandardSetupLogFilter::CreateObject);
  160. LogRegisterProvider(&GUID_STANDARD_SETUPLOG_FORMATTER, CStandardSetupLogFormatter::CreateObject);
  161. LogRegisterProvider(&GUID_FILE_DEVICE, CFileDevice::CreateObject);
  162. LogRegisterProvider(&GUID_DEBUG_FORMATTER_AND_DEVICE, CDebugFormatterAndDevice::CreateObject);
  163. LogRegisterProvider(&GUID_DEBUG_FILTER, CDebugFilter::CreateObject);
  164. LogRegisterProvider(&GUID_XML_FORMATTER, CXMLLogFormatter::CreateObject);
  165. return TRUE;
  166. }
  167. BOOL
  168. LogUnRegisterStockProviders(
  169. VOID
  170. )
  171. {
  172. LogUnRegisterProvider(&GUID_XML_FORMATTER);
  173. LogUnRegisterProvider(&GUID_DEBUG_FORMATTER_AND_DEVICE);
  174. LogUnRegisterProvider(&GUID_DEBUG_FILTER);
  175. LogUnRegisterProvider(&GUID_FILE_DEVICE);
  176. LogUnRegisterProvider(&GUID_STANDARD_SETUPLOG_FORMATTER);
  177. LogUnRegisterProvider(&GUID_STANDARD_SETUPLOG_FILTER);
  178. return TRUE;
  179. }