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.

345 lines
11 KiB

  1. /******************************************************************
  2. CPingProvider.H -- WMI provider class definition
  3. Description:
  4. *******************************************************************/
  5. // Property set identification
  6. //============================
  7. #ifndef _CPingProvider_H_
  8. #define _CPingProvider_H_
  9. #define PROVIDER_NAME_CPINGPROVIDER L"Win32_PingStatus"
  10. // Property name externs -- defined in CPingProvider.cpp
  11. //=================================================
  12. #define MAX_BUFFER_SIZE (sizeof(ICMP_ECHO_REPLY) + 0xfff7 + MAX_OPT_SIZE)
  13. #define DEFAULT_BUFFER_SIZE (0x2000 - 8)
  14. #define DEFAULT_SEND_SIZE 32
  15. #define DEFAULT_COUNT 4
  16. #define DEFAULT_TTL 128
  17. #define DEFAULT_TOS 0
  18. #define DEFAULT_TIMEOUT 1000L
  19. #define MIN_INTERVAL 1000L
  20. #define WBEM_CLASS_EXTENDEDSTATUS L"__ExtendedStatus"
  21. #define WBEM_PROPERTY_STATUSCODE L"StatusCode"
  22. #define WBEM_PROPERTY_PROVSTATUSMESSAGE L"Description"
  23. #define PING_KEY_PROPERTY_COUNT 11
  24. _COM_SMARTPTR_TYPEDEF(IWbemClassObject, __uuidof(IWbemClassObject));
  25. class CCritSecAutoUnlock
  26. {
  27. private:
  28. CRITICAL_SECTION *m_CritSec;
  29. BOOL m_bLocked;
  30. public:
  31. CCritSecAutoUnlock(CRITICAL_SECTION *a_CritSec) : m_CritSec(NULL), m_bLocked(FALSE)
  32. {
  33. EnterCriticalSection(a_CritSec);
  34. m_CritSec = a_CritSec;
  35. m_bLocked = TRUE;
  36. }
  37. ~CCritSecAutoUnlock()
  38. {
  39. LeaveEarly();
  40. }
  41. void LeaveEarly()
  42. {
  43. if ((m_bLocked) && (m_CritSec != NULL))
  44. {
  45. LeaveCriticalSection(m_CritSec);
  46. m_CritSec = NULL;
  47. m_bLocked = FALSE;
  48. }
  49. }
  50. };
  51. class CKeyEntry
  52. {
  53. public:
  54. LPCWSTR m_key ;
  55. public:
  56. CKeyEntry ( CKeyEntry & a_key )
  57. {
  58. m_key = a_key.Get();
  59. }
  60. CKeyEntry ( LPCWSTR a_key )
  61. {
  62. m_key = a_key;
  63. }
  64. CKeyEntry (void)
  65. {
  66. m_key = NULL;
  67. }
  68. ~CKeyEntry ()
  69. {
  70. m_key = NULL ;
  71. }
  72. LPCWSTR Get ( ) const
  73. {
  74. return m_key ;
  75. }
  76. void *operator new ( size_t a_Size , CKeyEntry *a_key )
  77. {
  78. return a_key ;
  79. }
  80. void operator delete ( void *a_Ptr , CKeyEntry *a_key )
  81. {
  82. }
  83. } ;
  84. extern LONG CompareElement ( const CKeyEntry &a_Arg1 , const CKeyEntry & a_Arg2 );
  85. extern BOOL operator== ( const CKeyEntry &a_Arg1 , const CKeyEntry &a_Arg2 );
  86. extern BOOL operator< ( const CKeyEntry &a_Arg1 , const CKeyEntry &a_Arg2 );
  87. extern ULONG Hash ( const CKeyEntry & a_Arg );
  88. class CPingThread : public WmiThread < ULONG >
  89. {
  90. private:
  91. WmiAllocator &m_Allocator ;
  92. BOOL m_Init;
  93. protected:
  94. public: /* Internal */
  95. CPingThread (WmiAllocator & a_Allocator) ;
  96. ~CPingThread () ;
  97. WmiStatusCode Initialize_Callback () ;
  98. WmiStatusCode UnInitialize_Callback () ;
  99. };
  100. class CPingProvider : public IWbemServices, public IWbemProviderInit
  101. {
  102. private:
  103. LONG m_referenceCount ; //Object reference count
  104. IWbemClassObject *m_notificationClassObject ;
  105. IWbemClassObject *m_ClassObject ;
  106. IWbemServices *m_server ;
  107. BOOL m_bInitial ;
  108. protected:
  109. BOOL CreateNotificationObject ( IWbemContext *a_Ctx ) ;
  110. BOOL ImpersonateClient();
  111. public:
  112. static CRITICAL_SECTION s_CS;
  113. static CPingThread *s_PingThread ;
  114. static WmiAllocator *s_Allocator ;
  115. static WmiHashTable <CKeyEntry, ULONG, 12> *s_HashTable; // one more bucket than we have keys.
  116. static HRESULT Global_Startup();
  117. static HRESULT Global_Shutdown();
  118. static LPCWSTR s_KeyTable[PING_KEY_PROPERTY_COUNT];
  119. // Constructor/destructor
  120. //=======================
  121. CPingProvider ();
  122. ~CPingProvider () ;
  123. BOOL GetClassObject ( IWbemClassObject **a_ppClass ) ;
  124. BOOL GetNotificationObject ( IWbemContext *a_Ctx , IWbemClassObject **a_ppObj );
  125. //Non-delegating object IUnknown
  126. STDMETHODIMP QueryInterface ( REFIID , LPVOID FAR * ) ;
  127. STDMETHODIMP_( ULONG ) AddRef () ;
  128. STDMETHODIMP_( ULONG ) Release () ;
  129. /* IWbemServices methods */
  130. HRESULT STDMETHODCALLTYPE OpenNamespace(
  131. /* [in] */ const BSTR Namespace,
  132. /* [in] */ long lFlags,
  133. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  134. /* [unique][in][out] */ IWbemServices __RPC_FAR *__RPC_FAR *ppWorkingNamespace,
  135. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppResult);
  136. HRESULT STDMETHODCALLTYPE CancelAsyncCall(
  137. /* [in] */ IWbemObjectSink __RPC_FAR *pSink) ;
  138. HRESULT STDMETHODCALLTYPE QueryObjectSink(
  139. /* [in] */ long lFlags,
  140. /* [out] */ IWbemObjectSink __RPC_FAR *__RPC_FAR *ppResponseHandler) ;
  141. HRESULT STDMETHODCALLTYPE GetObject(
  142. /* [in] */ const BSTR ObjectPath,
  143. /* [in] */ long lFlags,
  144. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  145. /* [unique][in][out] */ IWbemClassObject __RPC_FAR *__RPC_FAR *ppObject,
  146. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) ;
  147. HRESULT STDMETHODCALLTYPE GetObjectAsync(
  148. /* [in] */ const BSTR ObjectPath,
  149. /* [in] */ long lFlags,
  150. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  151. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) ;
  152. HRESULT STDMETHODCALLTYPE PutClass(
  153. /* [in] */ IWbemClassObject __RPC_FAR *pObject,
  154. /* [in] */ long lFlags,
  155. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  156. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) ;
  157. HRESULT STDMETHODCALLTYPE PutClassAsync(
  158. /* [in] */ IWbemClassObject __RPC_FAR *pObject,
  159. /* [in] */ long lFlags,
  160. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  161. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) ;
  162. HRESULT STDMETHODCALLTYPE DeleteClass(
  163. /* [in] */ const BSTR Class,
  164. /* [in] */ long lFlags,
  165. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  166. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) ;
  167. HRESULT STDMETHODCALLTYPE DeleteClassAsync(
  168. /* [in] */ const BSTR Class,
  169. /* [in] */ long lFlags,
  170. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  171. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) ;
  172. HRESULT STDMETHODCALLTYPE CreateClassEnum(
  173. /* [in] */ const BSTR Superclass,
  174. /* [in] */ long lFlags,
  175. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  176. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) ;
  177. HRESULT STDMETHODCALLTYPE CreateClassEnumAsync(
  178. /* [in] */ const BSTR Superclass,
  179. /* [in] */ long lFlags,
  180. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  181. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) ;
  182. HRESULT STDMETHODCALLTYPE PutInstance(
  183. /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  184. /* [in] */ long lFlags,
  185. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  186. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) ;
  187. HRESULT STDMETHODCALLTYPE PutInstanceAsync(
  188. /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  189. /* [in] */ long lFlags,
  190. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  191. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) ;
  192. HRESULT STDMETHODCALLTYPE DeleteInstance(
  193. /* [in] */ const BSTR ObjectPath,
  194. /* [in] */ long lFlags,
  195. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  196. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) ;
  197. HRESULT STDMETHODCALLTYPE DeleteInstanceAsync(
  198. /* [in] */ const BSTR ObjectPath,
  199. /* [in] */ long lFlags,
  200. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  201. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) ;
  202. HRESULT STDMETHODCALLTYPE CreateInstanceEnum(
  203. /* [in] */ const BSTR Class,
  204. /* [in] */ long lFlags,
  205. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  206. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) ;
  207. HRESULT STDMETHODCALLTYPE CreateInstanceEnumAsync(
  208. /* [in] */ const BSTR Class,
  209. /* [in] */ long lFlags,
  210. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  211. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) ;
  212. HRESULT STDMETHODCALLTYPE ExecQuery(
  213. /* [in] */ const BSTR QueryLanguage,
  214. /* [in] */ const BSTR Query,
  215. /* [in] */ long lFlags,
  216. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  217. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) ;
  218. HRESULT STDMETHODCALLTYPE ExecQueryAsync(
  219. /* [in] */ const BSTR QueryLanguage,
  220. /* [in] */ const BSTR Query,
  221. /* [in] */ long lFlags,
  222. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  223. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) ;
  224. HRESULT STDMETHODCALLTYPE ExecNotificationQuery(
  225. /* [in] */ const BSTR QueryLanguage,
  226. /* [in] */ const BSTR Query,
  227. /* [in] */ long lFlags,
  228. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  229. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) ;
  230. HRESULT STDMETHODCALLTYPE ExecNotificationQueryAsync(
  231. /* [in] */ const BSTR QueryLanguage,
  232. /* [in] */ const BSTR Query,
  233. /* [in] */ long lFlags,
  234. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  235. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) ;
  236. HRESULT STDMETHODCALLTYPE ExecMethod(
  237. /* [in] */ const BSTR ObjectPath,
  238. /* [in] */ const BSTR MethodName,
  239. /* [in] */ long lFlags,
  240. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  241. /* [in] */ IWbemClassObject __RPC_FAR *pInParams,
  242. /* [unique][in][out] */ IWbemClassObject __RPC_FAR *__RPC_FAR *ppOutParams,
  243. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) ;
  244. HRESULT STDMETHODCALLTYPE ExecMethodAsync(
  245. /* [in] */ const BSTR ObjectPath,
  246. /* [in] */ const BSTR MethodName,
  247. /* [in] */ long lFlags,
  248. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  249. /* [in] */ IWbemClassObject __RPC_FAR *pInParams,
  250. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) ;
  251. /* IWbemProviderInit methods */
  252. HRESULT STDMETHODCALLTYPE Initialize(
  253. /* [in] */ LPWSTR pszUser,
  254. /* [in] */ LONG lFlags,
  255. /* [in] */ LPWSTR pszNamespace,
  256. /* [in] */ LPWSTR pszLocale,
  257. /* [in] */ IWbemServices *pCIMOM, // For anybody
  258. /* [in] */ IWbemContext *pCtx,
  259. /* [in] */ IWbemProviderInitSink *pInitSink // For init signals
  260. );
  261. } ;
  262. #endif