Source code of Windows XP (NT5)
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.

346 lines
9.0 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. //
  5. // File: cwbemdsp.h
  6. //
  7. // Description :
  8. // Defines the CWbemDispatchMgr class, which implements the IDispatch
  9. // interfaces for Wbem Objects. The implementation is similar to a
  10. // standard IDispatch, but there is an additional functionality ("dot notation") that allows
  11. // users to call into GetIDsOfNames() & Invoke() using an Wbem property name
  12. // or method name directly (although this is not a property or method of the CWbemObject class).
  13. //
  14. // Part of : WBEM automation interface layer
  15. //
  16. // History:
  17. // corinaf 4/3/98 Created
  18. // alanbos 03/21/00 Revised for Whistler
  19. //
  20. //***************************************************************************
  21. #ifndef _CWBEMDISPMGR_H_
  22. #define _CWBEMDISPMGR_H_
  23. class CSWbemServices;
  24. class CSWbemSecurity;
  25. class CSWbemObject;
  26. class CWbemSchemaIDCache;
  27. //***************************************************************************
  28. //
  29. // Class : CWbemDispID
  30. //
  31. // Description :
  32. // An encoded Dispatch ID for handling typelib, WMI schema
  33. // and custom interface DispId's.
  34. //
  35. //***************************************************************************
  36. typedef unsigned long classCookie;
  37. class CWbemDispID
  38. {
  39. private:
  40. DISPID m_dispId;
  41. static unsigned long s_dispIdCounter;
  42. // Static constants
  43. static const unsigned long s_wmiDispIdTypeMask;
  44. static const unsigned long s_wmiDispIdTypeStatic;
  45. static const unsigned long s_wmiDispIdTypeSchema;
  46. static const unsigned long s_wmiDispIdSchemaTypeMask;
  47. static const unsigned long s_wmiDispIdSchemaTypeProperty;
  48. static const unsigned long s_wmiDispIdSchemaTypeMethod;
  49. static const unsigned long s_wmiDispIdSchemaElementIDMask;
  50. public:
  51. CWbemDispID (void) : m_dispId (0) {}
  52. CWbemDispID (DISPID dispId) : m_dispId (dispId) {}
  53. CWbemDispID (const CWbemDispID & obj) : m_dispId (obj.m_dispId) {}
  54. virtual ~CWbemDispID (void) {}
  55. bool SetAsSchemaID (DISPID dispId, bool bIsProperty = true)
  56. {
  57. bool result = false;
  58. if (dispId <= s_wmiDispIdSchemaElementIDMask)
  59. {
  60. result = true;
  61. m_dispId = dispId;
  62. // Add the bits to identify as static
  63. m_dispId |= s_wmiDispIdTypeSchema;
  64. // Add a bit for the property
  65. if (bIsProperty)
  66. m_dispId |= s_wmiDispIdSchemaTypeMask;
  67. }
  68. return result;
  69. }
  70. bool IsStatic () const
  71. {
  72. return ((DISPID_NEWENUM == m_dispId) ||
  73. (DISPID_VALUE == m_dispId) ||
  74. s_wmiDispIdTypeStatic == (s_wmiDispIdTypeMask & m_dispId));
  75. }
  76. bool IsSchema () const
  77. {
  78. return (s_wmiDispIdTypeSchema == (s_wmiDispIdTypeMask & m_dispId));
  79. }
  80. bool IsSchemaProperty () const
  81. {
  82. return (s_wmiDispIdSchemaTypeProperty == (s_wmiDispIdSchemaTypeMask & m_dispId));
  83. }
  84. bool IsSchemaMethod () const
  85. {
  86. return (s_wmiDispIdSchemaTypeMethod == (s_wmiDispIdSchemaTypeMask & m_dispId));
  87. }
  88. DISPID GetStaticElementID () const
  89. {
  90. return m_dispId;
  91. }
  92. DISPID GetSchemaElementID () const
  93. {
  94. return m_dispId & s_wmiDispIdSchemaElementIDMask;
  95. }
  96. operator DISPID () const
  97. {
  98. return m_dispId;
  99. }
  100. bool operator < (const CWbemDispID & dispId) const
  101. {
  102. return (m_dispId < dispId.m_dispId);
  103. }
  104. };
  105. //***************************************************************************
  106. //
  107. // CLASS NAME:
  108. //
  109. // BSTRless
  110. //
  111. // DESCRIPTION:
  112. //
  113. // Simple utility struct that provides an operator for use in a map based
  114. // on CComBSTR.
  115. //
  116. //***************************************************************************
  117. struct BSTRless : std::binary_function<CComBSTR, CComBSTR, bool>
  118. {
  119. bool operator () (const CComBSTR& _X, const CComBSTR& _Y) const
  120. {
  121. bool result = false;
  122. if (_X.m_str && _Y.m_str)
  123. result = (_wcsicmp (_X.m_str, _Y.m_str) > 0);
  124. else
  125. {
  126. // Treat any string as greater than NULL
  127. if (_X.m_str && !_Y.m_str)
  128. result = true;
  129. }
  130. return result;
  131. }
  132. };
  133. //***************************************************************************
  134. //
  135. // CLASS NAME:
  136. //
  137. // IIDless
  138. //
  139. // DESCRIPTION:
  140. //
  141. // Simple utility struct that provides an operator for use in a map based
  142. // on IID.
  143. //
  144. //***************************************************************************
  145. struct GUIDless : std::binary_function<GUID, GUID, bool>
  146. {
  147. bool operator () (const GUID& _X, const GUID& _Y) const
  148. {
  149. RPC_STATUS rpcStatus;
  150. return (UuidCompare ((GUID*)&_X, (GUID*)&_Y, &rpcStatus) > 0);
  151. }
  152. };
  153. //***************************************************************************
  154. //
  155. // Class : CWbemDispatchMgr
  156. //
  157. // Description :
  158. // Implements IDispatch for Wbem objects
  159. //
  160. // Public Methods :
  161. // Constructor, Destructor
  162. // IDispatch Methods
  163. //
  164. // Public Data Members :
  165. //
  166. //***************************************************************************
  167. class CWbemDispatchMgr
  168. {
  169. public:
  170. CWbemDispatchMgr(CSWbemServices *pWbemServices,
  171. CSWbemObject *pSWbemObject);
  172. ~CWbemDispatchMgr();
  173. //Dispatch methods
  174. STDMETHOD(GetTypeInfoCount)(THIS_ UINT FAR* pctinfo);
  175. STDMETHOD(GetTypeInfo)(THIS_ UINT itinfo,
  176. LCID lcid,
  177. ITypeInfo FAR* FAR* pptinfo);
  178. STDMETHOD(GetIDsOfNames)(THIS_ REFIID riid,
  179. OLECHAR FAR* FAR* rgszNames,
  180. UINT cNames,
  181. LCID lcid,
  182. DISPID FAR* rgdispid);
  183. STDMETHOD(Invoke)(THIS_ DISPID dispidMember,
  184. REFIID riid,
  185. LCID lcid,
  186. WORD wFlags,
  187. DISPPARAMS FAR* pdispparams,
  188. VARIANT FAR* pvarResult,
  189. EXCEPINFO FAR* pexcepinfo,
  190. UINT FAR* puArgErr);
  191. // IDispatchEx methods
  192. HRESULT STDMETHODCALLTYPE GetDispID(
  193. /* [in] */ BSTR bstrName,
  194. /* [in] */ DWORD grfdex,
  195. /* [out] */ DISPID __RPC_FAR *pid);
  196. /* [local] */ HRESULT STDMETHODCALLTYPE InvokeEx(
  197. /* [in] */ DISPID id,
  198. /* [in] */ LCID lcid,
  199. /* [in] */ WORD wFlags,
  200. /* [in] */ DISPPARAMS __RPC_FAR *pdp,
  201. /* [out] */ VARIANT __RPC_FAR *pvarRes,
  202. /* [out] */ EXCEPINFO __RPC_FAR *pei,
  203. /* [unique][in] */ IServiceProvider __RPC_FAR *pspCaller)
  204. {
  205. UINT uArgErr;
  206. return Invoke(id, IID_NULL, lcid, wFlags, pdp, pvarRes, pei, &uArgErr);
  207. }
  208. HRESULT STDMETHODCALLTYPE DeleteMemberByName(
  209. /* [in] */ BSTR bstr,
  210. /* [in] */ DWORD grfdex)
  211. { return S_FALSE; }
  212. HRESULT STDMETHODCALLTYPE DeleteMemberByDispID(
  213. /* [in] */ DISPID id)
  214. { return S_FALSE; }
  215. HRESULT STDMETHODCALLTYPE GetMemberProperties(
  216. /* [in] */ DISPID id,
  217. /* [in] */ DWORD grfdexFetch,
  218. /* [out] */ DWORD __RPC_FAR *pgrfdex)
  219. { return S_FALSE; }
  220. HRESULT STDMETHODCALLTYPE GetMemberName(
  221. /* [in] */ DISPID id,
  222. /* [out] */ BSTR __RPC_FAR *pbstrName)
  223. { return S_FALSE; }
  224. HRESULT STDMETHODCALLTYPE GetNextDispID(
  225. /* [in] */ DWORD grfdex,
  226. /* [in] */ DISPID id,
  227. /* [out] */ DISPID __RPC_FAR *pid)
  228. { return S_FALSE; }
  229. HRESULT STDMETHODCALLTYPE GetNameSpaceParent(
  230. /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppunk)
  231. { return S_FALSE; }
  232. // IProvideClassInfo methods
  233. HRESULT STDMETHODCALLTYPE GetClassInfo (
  234. /* [out] */ ITypeInfo **ppTI
  235. );
  236. // Other Methods
  237. void RaiseException (HRESULT hr);
  238. void SetNewObject (IWbemClassObject *pNewObject);
  239. IWbemClassObject *GetObject ()
  240. {
  241. return m_pWbemObject;
  242. }
  243. IWbemClassObject *GetClassObject ()
  244. {
  245. EnsureClassRetrieved ();
  246. return m_pWbemClass;
  247. }
  248. ISWbemObject *GetSWbemObject ()
  249. {
  250. return (ISWbemObject *)m_pSWbemObject;
  251. }
  252. private:
  253. HRESULT m_hResult;
  254. IWbemClassObject *m_pWbemObject; //pointer to represented WBEM object
  255. CSWbemObject *m_pSWbemObject; //pointer to represented Scripting WBEM object
  256. CSWbemServices *m_pWbemServices; //pointer to WBEM services
  257. IWbemClassObject *m_pWbemClass; //used when m_pWbemObject is an instance, to hold the
  258. //class definition for browsing method signatures
  259. ITypeInfo *m_pTypeInfo; //caches the type info pointer for the interface
  260. ITypeInfo *m_pCTypeInfo; //caches the type info pointer for the coclass
  261. CWbemSchemaIDCache *m_pSchemaCache; // cache of DISPID-Name bindings for WMI schema
  262. //Invokes a WBEM property get or put
  263. HRESULT InvokeWbemProperty(DISPID dispid, unsigned short wFlags,
  264. DISPPARAMS FAR* pdispparams, VARIANT FAR* pvarResult,
  265. EXCEPINFO FAR* pexcepinfo, unsigned int FAR* puArgErr);
  266. //Invokes a WBEM method
  267. HRESULT InvokeWbemMethod(DISPID dispid, DISPPARAMS FAR* pdispparams, VARIANT FAR* pvarResult);
  268. //Helpers for WBEM method out parameter mapping
  269. HRESULT MapReturnValue (VARIANT *pDest, VARIANT *pSrc);
  270. HRESULT MapOutParameter (VARIANT *pDest, VARIANT *pSrc);
  271. HRESULT MapOutParameters (DISPPARAMS FAR* pdispparams, IWbemClassObject *pOutParameters,
  272. IWbemClassObject *pOutParamsInstance, VARIANT FAR* pvarResult);
  273. // Helpers for WBEM method in parameter mapping
  274. HRESULT MapInParameters (DISPPARAMS FAR* pdispparams, IWbemClassObject *pInParameters,
  275. IWbemClassObject **ppInParamsInstance);
  276. HRESULT MapInParameter (VARIANT FAR* pDest, VARIANT FAR* pSrc, CIMTYPE lType);
  277. //Error handling
  278. HRESULT HandleError (DISPID dispidMember, unsigned short wFlags, DISPPARAMS FAR* pdispparams,
  279. VARIANT FAR* pvarResult,UINT FAR* puArgErr,HRESULT hr);
  280. // Class retrieval
  281. void EnsureClassRetrieved ();
  282. };
  283. #endif //_CWBEMDISPMGR_H_