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.

125 lines
3.1 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2000, Microsoft Corporation, All rights reserved
  3. //
  4. // NCEvents.h
  5. //
  6. // This file is the interface to using non-COM events within ESS.
  7. //
  8. #include "precomp.h"
  9. #include "NCEvents.h"
  10. #define NUM_NC_EVENTS NCE_InvalidIndex
  11. #define MAX_BUFFER_SIZE 32000
  12. #define SEND_LATENCY 100
  13. static HANDLE g_hConnection;
  14. HANDLE g_hNCEvents[NUM_NC_EVENTS];
  15. LPCWSTR szEventSetup[NUM_NC_EVENTS * 2] =
  16. {
  17. L"MSFT_WmiRegisterNotificationSink",
  18. L"Namespace!s! QueryLanguage!s! Query!s! Sink!I64u!",
  19. L"MSFT_WmiCancelNotificationSink",
  20. L"Namespace!s! QueryLanguage!s! Query!s! Sink!I64u!",
  21. L"MSFT_WmiEventProviderLoaded",
  22. L"Namespace!s! ProviderName!s!",
  23. L"MSFT_WmiEventProviderUnloaded",
  24. L"Namespace!s! ProviderName!s!",
  25. L"MSFT_WmiEventProviderNewQuery",
  26. L"Namespace!s! ProviderName!s! QueryLanguage!s! "
  27. L"Query!s! QueryId!u! Result!u!",
  28. L"MSFT_WmiEventProviderCancelQuery",
  29. L"Namespace!s! ProviderName!s! QueryId!u! Result!u!",
  30. L"MSFT_WmiEventProviderAccessCheck",
  31. L"Namespace!s! ProviderName!s! QueryLanguage!s! "
  32. L"Query!s! Sid!c[]! Result!u!",
  33. L"MSFT_WmiConsumerProviderLoaded",
  34. L"Namespace!s! ProviderName!s! Machine!s!",
  35. L"MSFT_WmiConsumerProviderUnloaded",
  36. L"Namespace!s! ProviderName!s! Machine!s!",
  37. L"MSFT_WmiConsumerProviderSinkLoaded",
  38. L"Namespace!s! ProviderName!s! Machine!s! Consumer!s!",
  39. L"MSFT_WmiConsumerProviderSinkUnloaded",
  40. L"Namespace!s! ProviderName!s! Machine!s! Consumer!s!",
  41. L"MSFT_WmiThreadPoolThreadCreated",
  42. L"ThreadId!u!",
  43. L"MSFT_WmiThreadPoolThreadDeleted",
  44. L"ThreadId!u!",
  45. L"MSFT_WmiFilterActivated",
  46. L"Namespace!s! Name!s! QueryLanguage!s! Query!s!",
  47. L"MSFT_WmiFilterDeactivated",
  48. L"Namespace!s! Name!s! QueryLanguage!s! Query!s!",
  49. };
  50. #define WMI_SELF_PROV_NAME L"WMI Self-Instrumentation Event Provider"
  51. BOOL InitNCEvents()
  52. {
  53. #ifdef USE_NCEVENTS
  54. BOOL bRet;
  55. g_hConnection =
  56. WmiEventSourceConnect(
  57. L"root\\cimv2",
  58. WMI_SELF_PROV_NAME,
  59. TRUE,
  60. MAX_BUFFER_SIZE,
  61. SEND_LATENCY,
  62. NULL,
  63. NULL);
  64. if (g_hConnection)
  65. {
  66. for (int i = 0; i < NUM_NC_EVENTS; i++)
  67. {
  68. g_hNCEvents[i] =
  69. WmiCreateObjectWithFormat(
  70. g_hConnection,
  71. szEventSetup[i * 2],
  72. WMI_CREATEOBJ_LOCKABLE,
  73. szEventSetup[i * 2 + 1]);
  74. if (!g_hNCEvents[i])
  75. break;
  76. }
  77. bRet = i == NUM_NC_EVENTS;
  78. }
  79. else
  80. bRet = FALSE;
  81. return bRet;
  82. #else
  83. return TRUE;
  84. #endif
  85. }
  86. void DeinitNCEvents()
  87. {
  88. #ifdef USE_NCEVENTS
  89. for (int i = 0; i < NUM_NC_EVENTS; i++)
  90. {
  91. if (g_hNCEvents[i])
  92. WmiDestroyObject(g_hNCEvents[i]);
  93. }
  94. if (g_hConnection)
  95. WmiEventSourceDisconnect(g_hConnection);
  96. #endif
  97. }