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.

776 lines
27 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // Microsoft WMIOLE DB Provider
  3. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // CWBEMWRAP.h | CWbem* class Header file. These are classes talking to WMI
  6. //
  7. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  8. #ifndef _CWBEMWRAP_HEADER
  9. #define _CWBEMWRAP_HEADER
  10. #include <wbemcli.h>
  11. #include <oahelp.inl>
  12. BOOL UnicodeToAnsi(WCHAR * pszW, char *& pAnsi);
  13. void AllocateAndConvertAnsiToUnicode(char * pstr, WCHAR *& pszW);
  14. BOOL AllocateAndCopy( WCHAR *& pwcsDestination, WCHAR * pwcsSource );
  15. HRESULT MapWbemErrorToOLEDBError(HRESULT hrToMap);
  16. #define DEFAULT_NAMESPACE L"ROOT\\DEFAULT"
  17. #define ROOT_NAMESPACE L"ROOT"
  18. class CQuery;
  19. typedef enum _InstanceListType
  20. {
  21. NORMAL, // normal query which returns homogenous objects
  22. MIXED, // query which returns heterogenours objects
  23. SCOPE, // instance list showing list of objects in scope
  24. CONTAINER, // instance list showing list of objects in container
  25. }INSTANCELISTTYPE;
  26. template <class T> class CCOMPointer
  27. {
  28. T* p;
  29. public:
  30. CCOMPointer()
  31. {
  32. p=NULL;
  33. }
  34. CCOMPointer(T* lp)
  35. {
  36. if ((p = lp) != NULL)
  37. p->AddRef();
  38. }
  39. CCOMPointer(const CCOMPointer<T>& lp)
  40. {
  41. if ((p = lp.p) != NULL)
  42. p->AddRef();
  43. }
  44. ~CCOMPointer()
  45. {
  46. if (p)
  47. {
  48. p->Release();
  49. p = NULL;
  50. }
  51. }
  52. operator T*() const
  53. {
  54. return (T*)p;
  55. }
  56. T& operator*() const
  57. {
  58. ATLASSERT(p!=NULL);
  59. return *p;
  60. }
  61. };
  62. class CWbemSecurityDescriptor
  63. {
  64. private:
  65. IWbemClassObject * m_pAccessor;
  66. IWbemServicesEx * m_pISerEx;
  67. CVARIANT m_sd;
  68. BSTR m_strPath;
  69. IWbemContext * m_pIContext;
  70. ULONG m_lSdSize;
  71. public:
  72. CWbemSecurityDescriptor();
  73. ~CWbemSecurityDescriptor();
  74. HRESULT Init(IWbemServices *pSer,BSTR strPath,IWbemContext *pContext);
  75. PSECURITY_DESCRIPTOR GetSecurityDescriptor() { return (PSECURITY_DESCRIPTOR) &m_sd; }
  76. HRESULT PutSD();
  77. BOOL GetSID(TRUSTEE_W *pTrustee ,PSID & psid);
  78. };
  79. /////////////////////////////////////////////////////////////////////////////////////////////
  80. class CWbemConnectionWrapper
  81. {
  82. public:
  83. ~CWbemConnectionWrapper();
  84. CWbemConnectionWrapper();
  85. HRESULT FInit() { return m_PrivelagesToken.FInit();}
  86. // CWbemConnectionWrapper(CWbemConnectionWrapper *pWrap , WCHAR *pstrPath,INSTANCELISTTYPE instListType );
  87. HRESULT FInit(CWbemConnectionWrapper *pWrap , WCHAR *pstrPath,INSTANCELISTTYPE instListType );
  88. void InitVars();
  89. //=========================================================
  90. // Connection handling functions
  91. //=========================================================
  92. HRESULT GetConnectionToWbem(void);
  93. BOOL ValidConnection();
  94. //=========================================================
  95. // Namespace functions
  96. //=========================================================
  97. void SetValidNamespace(VARIANT *v);
  98. WCHAR * GetNamespace();
  99. void SetUserInfo(BSTR strUser,BSTR strPassword,BSTR strAuthority);
  100. IWbemServices* GetServicesPtr();
  101. IWbemContext * GetContext() { return m_pCtx; }
  102. void SetConnAttributes(DWORD dwAuthnLevel , DWORD dwImpLevel);
  103. HRESULT DeleteClass(BSTR strClassName);
  104. BOOL AdjustTokenPrivileges(ULONG cProps , DBPROP rgProp[])
  105. { return m_PrivelagesToken.AdjustTokenPrivileges(cProps,rgProp); }
  106. BOOL AdjustTokenPrivileges(ULONG ulProp)
  107. { return m_PrivelagesToken.AdjustTokenPrivileges(ulProp); }
  108. void SetLocale(LONG lLocaleID);
  109. // transaction related functions
  110. HRESULT BeginTransaction(ULONG uTimeout,ULONG uFlags,GUID *pTransGUID);
  111. HRESULT CompleteTransaction(BOOL bRollBack,ULONG uFlags);
  112. HRESULT CreateNameSpace();
  113. HRESULT DeleteNameSpace();
  114. HRESULT GetObjectAccessRights(BSTR strPath,
  115. ULONG *pcAccessEntries,
  116. EXPLICIT_ACCESS_W **prgAccessEntries,
  117. ULONG ulAccessEntries = 0,
  118. EXPLICIT_ACCESS_W *pAccessEntries = NULL);
  119. HRESULT SetObjectAccessRights(BSTR strPath,
  120. ULONG ulAccessEntries,
  121. EXPLICIT_ACCESS_W *pAccessEntries);
  122. HRESULT SetObjectOwner(BSTR strPath,TRUSTEE_W *pOwner);
  123. HRESULT GetObjectOwner(BSTR strPath,TRUSTEE_W ** ppOwner);
  124. BOOL IsValidObject(BSTR strPath);
  125. HRESULT IsObjectAccessAllowed( BSTR strPath,EXPLICIT_ACCESS_W *pAccessEntry,BOOL *pfResult);
  126. // function to get the class name given the object path
  127. // used in case of direct binding and UMI paths
  128. HRESULT GetParameters(BSTR strPath,BSTR &strClassName,BSTR *pstrNameSpace = NULL);
  129. HRESULT GetClassName(BSTR strPath,BSTR &strClassName);
  130. // 07/12/2000
  131. // NTRaid : 142348
  132. HRESULT ExecuteQuery(CQuery *pQuery); // function which executes Action queries
  133. HRESULT GetNodeName(BSTR &strNode); // function which gets the pointer to the
  134. // the object for which it is pointing
  135. private:
  136. IWbemServices * m_pIWbemServices;
  137. IWbemContext * m_pCtx;
  138. CVARIANT m_vNamespace;
  139. DWORD m_dwAuthnLevel; //Authentication level to use
  140. DWORD m_dwImpLevel; //Impersonation level to use
  141. BSTR m_strUser; // UserID
  142. BSTR m_strPassword; // Password
  143. BSTR m_strAuthority;
  144. CPreviligeToken m_PrivelagesToken; // For Setting Token privelege
  145. BSTR m_strLocale;
  146. CWbemConnectionWrapper *m_pDataSourceCon;
  147. };
  148. class CWbemClassWrapper;
  149. //////////////////////////////////////////////////////////////////////////////////////////////
  150. class CWbemClassParameters
  151. {
  152. public:
  153. WCHAR * m_pwcsClassName;
  154. DWORD m_dwFlags;
  155. DWORD m_dwNavFlags;
  156. DWORD m_dwQueryFlags;
  157. CWbemConnectionWrapper * m_pConnection;
  158. WCHAR * m_pwcsParentClassName;
  159. BOOL m_bSystemProperties; // Indicates , if system properties
  160. IWbemContext * m_pIContext;
  161. // to be fetched or not
  162. CWbemClassParameters(DWORD dwFlags,WCHAR * pClassName,CWbemConnectionWrapper * pWrap );
  163. // CWbemClassParameters(DWORD dwFlags,IDispatch *pDisp,CWbemConnectionWrapper * pWrap );
  164. ~CWbemClassParameters();
  165. WCHAR * GetClassName();
  166. void SetParentClassName( WCHAR * p ){ AllocateAndCopy( m_pwcsParentClassName,p);}
  167. void SetClassName( WCHAR * p ) { AllocateAndCopy( m_pwcsClassName,p);}
  168. void DeleteClassName() { SAFE_DELETE_ARRAY(m_pwcsClassName);}
  169. WCHAR * GetSuperClassName() { return m_pwcsParentClassName; }
  170. DWORD GetFlags() { return m_dwFlags; }
  171. DWORD GetNavigationFlags() { return m_dwNavFlags; }
  172. DWORD GetQueryFlags() { return m_dwQueryFlags; }
  173. HRESULT GetClassNameForWbemObject(IWbemClassObject *pInst );
  174. void SetEnumeratorFlags(DWORD dwFlags);
  175. void SetQueryFlags(DWORD dwFlags);
  176. HRESULT ParseClassName();
  177. void SetSytemPropertiesFlag(BOOL bSystemProperties) { m_bSystemProperties = bSystemProperties;}
  178. HRESULT RemoveObjectFromContainer(BSTR strContainerObj,BSTR strObject);
  179. HRESULT AddObjectFromContainer(BSTR strContainerObj,BSTR strObject);
  180. HRESULT CloneAndAddNewObjectInScope(CWbemClassWrapper *pClass,BSTR strDstObj,WCHAR *& pstrNewPath);
  181. HRESULT SetSearchPreferences(ULONG cProps , DBPROP rgProp[]);
  182. virtual IWbemServices* GetServicesPtr() { return m_pConnection->GetServicesPtr();}
  183. IWbemContext * GetContext() { return m_pIContext; }
  184. };
  185. //////////////////////////////////////////////////////////////////////////////////////////////
  186. // Class which manages the position for qualifiers
  187. class CQualiferPos
  188. {
  189. CFlexArray m_QualifierPos; // Array to store the qualifer names
  190. LONG_PTR m_lPos; // The current position
  191. FETCHDIRECTION m_FetchDir; // The current fetch direction
  192. public:
  193. CQualiferPos();
  194. ~CQualiferPos();
  195. void RemoveAll(); // Remove all the elements from the array
  196. void Remove(WCHAR *pwcsQualifier); // Remove a particular element from the array
  197. WCHAR * operator [] (DBORDINAL nIndex); // Operator overloading to get a particular elemtent
  198. HRESULT GetRelative (DBROWOFFSET lRelPos,WCHAR *&pwcsQualifier);// Get a element which is at a relative position to the current element
  199. //NTBug:111779
  200. // 06/13/00
  201. HRESULT Add(WCHAR *pwcsQualifier); // Add an element to the array
  202. HRESULT SetRelPos(DBROWOFFSET lRelative); // Set the relation position
  203. FETCHDIRECTION GetDirFlag() { return m_FetchDir ;} // Get the current fetch direction
  204. void SetDirFlag(FETCHDIRECTION DirFlag) { m_FetchDir = DirFlag;} // Set the direction of fetch
  205. };
  206. //////////////////////////////////////////////////////////////////////////////////////////////
  207. // Class to manage property qualifers for a instance/class
  208. class CWbemPropertyQualifierWrapper
  209. {
  210. public:
  211. IWbemQualifierSet* m_pIWbemPropertyQualifierSet;
  212. WCHAR * m_pwstrPropertyName;
  213. CQualiferPos m_QualifierPos;
  214. CWbemPropertyQualifierWrapper()
  215. {
  216. m_pIWbemPropertyQualifierSet = NULL;
  217. m_pwstrPropertyName = NULL;
  218. }
  219. ~CWbemPropertyQualifierWrapper()
  220. {
  221. SAFE_RELEASE_PTR(m_pIWbemPropertyQualifierSet);
  222. SAFE_DELETE_PTR(m_pwstrPropertyName);
  223. m_QualifierPos.RemoveAll();
  224. }
  225. };
  226. //////////////////////////////////////////////////////////////////////////////////////////////
  227. // Class which contains a list of Property qualifer set pointers
  228. class CWbemPropertyQualifierList
  229. {
  230. CFlexArray m_QualifierList;
  231. public:
  232. ~CWbemPropertyQualifierList();
  233. //NTBug:111779
  234. // 06/13/00
  235. HRESULT Add(IWbemQualifierSet* pQualifierSet,WCHAR *pwstrPropertyName); // Add a name to the qualifier list
  236. void Remove(WCHAR *pwstrPropertyName); // Remove a qualifier from the list
  237. IWbemQualifierSet* GetPropertyQualifierSet(WCHAR *pwstrPropertyName); // Get the qualiferset pointer
  238. void RemoveAll(); // Remove all the elements
  239. CQualiferPos * GetQualiferPosObject(WCHAR *pwcsProperty); // Get the CQualifierPos pointer
  240. };
  241. //////////////////////////////////////////////////////////////////////////////////////////////
  242. // Works with just one class
  243. class CWbemClassWrapper
  244. {
  245. protected:
  246. CWbemClassParameters * m_pParms;
  247. IWbemClassObject * m_pClass;
  248. IWbemQualifierSet* m_pIWbemClassQualifierSet;
  249. IWbemQualifierSet* m_pIWbemPropertyQualifierSet;
  250. CWbemPropertyQualifierList m_pPropQualifList;
  251. CQualiferPos m_QualifierPos;
  252. HRESULT GetClassName(IDispatch *pDisp );
  253. public:
  254. CWbemClassWrapper( CWbemClassParameters * p);
  255. ~CWbemClassWrapper();
  256. //=========================================================
  257. // Utility functions
  258. //=========================================================
  259. HRESULT SetClass(IWbemClassObject * p);
  260. IWbemClassObject * GetClass() { return m_pClass ;}
  261. IWbemClassObject ** GetClassPtr() { return &m_pClass;}
  262. virtual HRESULT ValidClass();
  263. WCHAR * GetClassName() { return m_pParms->GetClassName(); }
  264. void SetClassName( WCHAR * p ) { m_pParms->SetClassName(p); }
  265. DWORD GetFlags() { return m_pParms->GetFlags(); }
  266. DWORD GetNavigationFlags() { return m_pParms->GetNavigationFlags(); }
  267. DWORD GetQueryFlags() { return m_pParms->GetQueryFlags(); }
  268. //=========================================================
  269. // Managing Properties
  270. //=========================================================
  271. HRESULT SetProperty(BSTR pProperty, VARIANT * vValue,CIMTYPE lType = -1 );
  272. virtual HRESULT BeginPropertyEnumeration();
  273. virtual HRESULT GetNextProperty(BSTR * pProperty, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor );
  274. virtual HRESULT EndPropertyEnumeration();
  275. HRESULT DeleteProperty(BSTR pProperty );
  276. virtual HRESULT TotalPropertiesInClass(ULONG & ulPropCount, ULONG &ulSysPropCount);
  277. HRESULT GetProperty(BSTR pProperty, VARIANT * var, CIMTYPE * pType = NULL ,LONG * plFlavor = NULL );
  278. //=========================================================
  279. // Managing Qualifiers
  280. //=========================================================
  281. HRESULT SetPropertyQualifier(BSTR pProperty, BSTR Qualifier, VARIANT * vValue, LONG lQualifierFlags );
  282. HRESULT DeletePropertyQualifier(BSTR pProperty, BSTR Qualifier );
  283. HRESULT TotalPropertyQualifier(BSTR strPropName , ULONG & ulCount );
  284. HRESULT GetPropertyQualifier(BSTR pPropertyQualifier, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor );
  285. HRESULT IsValidPropertyQualifier(BSTR strProperty);
  286. void ReleaseAllPropertyQualifiers() { m_pPropQualifList.RemoveAll(); }
  287. void ReleasePropertyQualifier(BSTR strQualifier) ;
  288. virtual HRESULT BeginPropertyQualifierEnumeration(BSTR strPropName);
  289. HRESULT GetNextPropertyQualifier(BSTR pProperty,BSTR * pPropertyQualifier, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor );
  290. HRESULT GetPrevPropertyQualifier(BSTR pProperty,BSTR * pPropertyQualifier, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor );
  291. HRESULT GetPropertyQualifier(BSTR pProperty,BSTR PropertyQualifier, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor );
  292. HRESULT EndPropertyQualifierEnumeration();
  293. HRESULT IsValidClassQualifier();
  294. HRESULT GetNextClassQualifier(BSTR * pClassQualifier, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor );
  295. HRESULT GetPrevClassQualifier(BSTR * pClassQualifier, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor );
  296. HRESULT GetClassQualifier(BSTR ClassQualifier, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor );
  297. HRESULT ReleaseClassQualifier();
  298. HRESULT SetClassQualifier(BSTR Qualifier, VARIANT * vValue, LONG lQualifierFlags );
  299. HRESULT SetQualifierRelPos(DBROWOFFSET lRelPos ,BSTR strQualifierName = Wmioledb_SysAllocString(NULL));
  300. HRESULT GetKeyPropertyNames( SAFEARRAY **ppsaNames);
  301. CWbemClassWrapper * GetInstance(BSTR strPath);
  302. };
  303. //////////////////////////////////////////////////////////////////////////////////////////////
  304. // Works with just one class
  305. class CWbemClassDefinitionWrapper : public CWbemClassWrapper
  306. {
  307. protected:
  308. BOOL m_bSchema;
  309. public:
  310. CWbemClassDefinitionWrapper( CWbemClassParameters * p,BOOL bGetClass = TRUE);
  311. ~CWbemClassDefinitionWrapper();
  312. HRESULT Init(BOOL bGetClass)
  313. {
  314. if(bGetClass)
  315. return GetClass();
  316. else
  317. return S_OK;
  318. }
  319. //=========================================================
  320. // Managing classes
  321. //=========================================================
  322. HRESULT GetEmptyWbemClass();
  323. HRESULT DeleteClass();
  324. HRESULT GetClass();
  325. HRESULT CreateClass();
  326. HRESULT DeleteClassQualifier(BSTR Qualifier );
  327. HRESULT SetClass( WCHAR *pClassName);
  328. HRESULT SaveClass(BOOL bNewClass = TRUE);
  329. HRESULT GetInstanceCount(ULONG_PTR &cInstance);
  330. BOOL IsClassSchema() { return m_bSchema; }
  331. };
  332. //////////////////////////////////////////////////////////////////////////////////////////////
  333. class CWbemClassInstanceWrapper : public CWbemClassWrapper
  334. {
  335. public:
  336. CWbemClassInstanceWrapper(CWbemClassParameters * p);
  337. ~CWbemClassInstanceWrapper();
  338. IWbemClassObject * GetClassObject() { return m_pClass ;}
  339. virtual WCHAR * GetInstanceName() { return GetClassName(); }
  340. virtual HRESULT ResetInstanceFromKey(CBSTR Key);
  341. virtual HRESULT GetKey(CBSTR & Key);
  342. void SetPos(ULONG_PTR lPos) { m_lPos = lPos; }
  343. ULONG_PTR GetPos() { return m_lPos; }
  344. virtual HRESULT RefreshInstance();
  345. virtual WCHAR * GetClassName();
  346. DBSTATUS GetStatus() { return m_dwStatus;}
  347. void SetStatus(DBSTATUS dwStatus) { m_dwStatus = dwStatus; }
  348. HRESULT CloneInstance(IWbemClassObject *& pInstance);
  349. HRESULT GetRelativePath(WCHAR *& pstrRelPath);
  350. protected:
  351. ULONG_PTR m_lPos;
  352. DBSTATUS m_dwStatus;
  353. };
  354. //////////////////////////////////////////////////////////////////////////////////////////////
  355. class CWbemInstanceList
  356. {
  357. protected:
  358. CFlexArray m_List;
  359. CWbemClassParameters * m_pParms;
  360. CRITICAL_SECTION m_InstanceCs;
  361. IEnumWbemClassObject * m_ppEnum;
  362. ULONG_PTR m_lCurrentPos;
  363. FETCHDIRECTION m_FetchDir;
  364. int m_nBaseType;
  365. ULONG_PTR m_cTotalInstancesInEnum;
  366. public:
  367. CWbemInstanceList(CWbemClassParameters * p);
  368. ~CWbemInstanceList();
  369. //======================================================================
  370. // Critical section handling
  371. //======================================================================
  372. inline void Enter() {EnterCriticalSection(&m_InstanceCs);}
  373. inline void Leave() {LeaveCriticalSection(&m_InstanceCs);}
  374. int TotalInstances();
  375. HRESULT ReleaseAllInstances();
  376. HRESULT ReleaseInstance(CWbemClassInstanceWrapper *& pClass);
  377. virtual HRESULT Reset();
  378. virtual HRESULT NextInstance(CBSTR & Key, CWbemClassInstanceWrapper ** p);
  379. virtual HRESULT PrevInstance( CBSTR & Key, CWbemClassInstanceWrapper *& p);
  380. HRESULT FindInstancePosition( CWbemClassInstanceWrapper * pClass, int & nPosition );
  381. HRESULT DeleteInstance( CWbemClassInstanceWrapper *& pClass );
  382. HRESULT AddInstance( CWbemClassInstanceWrapper * pClass );
  383. HRESULT UpdateInstance(CWbemClassInstanceWrapper * pInstance , BOOL bNewInst);
  384. HRESULT AddInstanceNew( CWbemClassInstanceWrapper ** ppNewClass );
  385. HRESULT AddNewInstance(CWbemClassWrapper *pClassWrappper ,CWbemClassInstanceWrapper ** ppNewClass );
  386. HRESULT ResetRelPosition( DBROWOFFSET lPos );
  387. // CWbemClassInstanceWrapper * AddInstanceToList( IUnknown *pDisp,CBSTR & Key);
  388. CWbemClassInstanceWrapper * GetInstance( ULONG_PTR lPos );
  389. HRESULT GetNumberOfInstanceInEnumerator(ULONG_PTR *pcInstance=NULL);
  390. FETCHDIRECTION GetCurFetchDirection() { return m_FetchDir; }
  391. void SetCurFetchDirection(FETCHDIRECTION FetchDir) { m_FetchDir = FetchDir; }
  392. };
  393. //////////////////////////////////////////////////////////////////////////////////////////////
  394. // Works with just the rowsets generated by queries
  395. //////////////////////////////////////////////////////////////////////////////////////////////
  396. class CWbemCommandClassDefinitionWrapper;
  397. class CQuery;
  398. class CWbemCommandInstanceList;
  399. class CWbemCommandInstanceWrapper;
  400. class CWbemCommandParameters;
  401. ///////////////////////////////////////////////////////////////////////////////////////////////////
  402. class CWbemCommandManager
  403. {
  404. public:
  405. BOOL ValidQuery();
  406. HRESULT ValidQueryResults();
  407. CWbemCommandManager(CQuery * p);
  408. ~CWbemCommandManager();
  409. void Init(CWbemCommandInstanceList * InstanceList, CWbemCommandParameters * pParms,CWbemCommandClassDefinitionWrapper* pDef);
  410. HRESULT GetClassDefinitionForQueryResults();
  411. INSTANCELISTTYPE GetObjListType();
  412. private:
  413. CQuery * m_pQuery;
  414. CWbemCommandClassDefinitionWrapper * m_pClassDefinition;
  415. CWbemCommandInstanceList * m_pInstanceList;
  416. CWbemCommandInstanceWrapper * m_pInstance;
  417. CWbemCommandParameters * m_pParms;
  418. };
  419. //////////////////////////////////////////////////////////////////////////////////////////////
  420. class CWbemCommandClassDefinitionWrapper : public CWbemClassDefinitionWrapper
  421. {
  422. private:
  423. int m_nMaxColumns;
  424. CWbemCommandManager * m_pCmdManager;
  425. INSTANCELISTTYPE m_objListType; // Method Storing type of the command.
  426. public:
  427. CWbemCommandClassDefinitionWrapper(CWbemClassParameters * p,CWbemCommandManager * pWbemCommandManager);
  428. ~CWbemCommandClassDefinitionWrapper();
  429. HRESULT ValidClass();
  430. HRESULT TotalPropertiesInClass(ULONG & ulPropCount, ULONG &ulSysPropCount);
  431. HRESULT SetQueryType(LPCWSTR strQry,GUID QryDialect,LPCWSTR strQryLang = NULL);
  432. INSTANCELISTTYPE GetObjListType() { return m_objListType; }
  433. };
  434. ///////////////////////////////////////////////////////////////////////////////////////////////////
  435. class CWbemCommandInstanceList: public CWbemInstanceList
  436. {
  437. private:
  438. ULONG m_ulMaxRow;
  439. CWbemCommandManager * m_pCmdManager;
  440. LPWSTR m_pwstrQuery; // current Query
  441. LPWSTR m_pwstrQueryLanguage;
  442. public:
  443. CWbemCommandInstanceList(CWbemClassParameters * p,CWbemCommandManager * pWbemCommandManager);
  444. ~CWbemCommandInstanceList();
  445. HRESULT SetQuery( LPWSTR p,GUID QryDialect,LPCWSTR strQryLang = NULL);
  446. WCHAR* GetQuery() { return m_pwstrQuery;}
  447. WCHAR* GetQueryLanguage() {return m_pwstrQueryLanguage; }
  448. virtual HRESULT Reset();
  449. };
  450. //////////////////////////////////////////////////////////////////////////////////////////////
  451. class CWbemCommandInstanceWrapper : public CWbemClassInstanceWrapper
  452. {
  453. private:
  454. CWbemCommandManager * m_pCmdManager;
  455. public:
  456. CWbemCommandInstanceWrapper(CWbemClassParameters * p,CWbemCommandManager * pWbemCommandManager);
  457. ~CWbemCommandInstanceWrapper();
  458. virtual WCHAR * GetClassName();
  459. virtual HRESULT GetKey(CBSTR & Key);
  460. virtual HRESULT RefreshInstance();
  461. };
  462. ///////////////////////////////////////////////////////////////////////////////////////////////////
  463. class CWbemCommandParameters :public CWbemClassParameters
  464. {
  465. public:
  466. CWbemCommandParameters(DWORD dwFlags,CWbemConnectionWrapper * Connect,CWbemCommandManager * pWbemCommandManager);
  467. ~CWbemCommandParameters();
  468. inline CWbemCommandManager * GetCommandManagerPtr() { return m_pCmdManager;}
  469. private:
  470. CWbemCommandManager * m_pCmdManager;
  471. };
  472. //////////////////////////////////////////////////////////////////////////////////////////////
  473. // Works with just the rowsets that deal with Methods
  474. //////////////////////////////////////////////////////////////////////////////////////////////
  475. ///////////////////////////////////////////////////////////////////////////////////////////////////
  476. class CWbemMethodParameters :public CWbemClassParameters
  477. {
  478. public:
  479. CWbemMethodParameters(CQuery * p, DWORD dwFlags,CWbemConnectionWrapper * Connect);
  480. ~CWbemMethodParameters();
  481. HRESULT ExtractNamesFromQuery();
  482. HRESULT ValidMethod();
  483. WCHAR * GetInstanceName() { return m_pwcsInstance; }
  484. WCHAR * GetMethodName() { return m_pwcsMethod;}
  485. CQuery * m_pQuery;
  486. private:
  487. WCHAR * m_pwcsInstance;
  488. WCHAR * m_pwcsMethod;
  489. };
  490. class CWbemMethodClassDefinitionWrapper : public CWbemClassDefinitionWrapper
  491. {
  492. private:
  493. int m_nMaxColumns;
  494. int m_nCount;
  495. IWbemClassObject * m_pInClass;
  496. public:
  497. CWbemMethodClassDefinitionWrapper(CWbemMethodParameters * parm);
  498. ~CWbemMethodClassDefinitionWrapper();
  499. IWbemClassObject * GetInputClassPtr() { return m_pInClass; }
  500. HRESULT Init();
  501. HRESULT ValidClass();
  502. HRESULT TotalPropertiesInClass(ULONG & ulPropCount, ULONG &ulSysPropCount);
  503. };
  504. ///////////////////////////////////////////////////////////////////////////////////////////////////
  505. class CWbemMethodInstanceList: public CWbemInstanceList
  506. {
  507. private:
  508. ULONG m_ulMaxRow;
  509. CWbemMethodClassDefinitionWrapper * m_pClassDefinition;
  510. public:
  511. CWbemMethodInstanceList(CWbemMethodParameters * p,CWbemMethodClassDefinitionWrapper * pDef);
  512. ~CWbemMethodInstanceList();
  513. virtual HRESULT Reset();
  514. virtual HRESULT NextInstance(CBSTR & Key, CWbemClassInstanceWrapper ** p);
  515. virtual HRESULT PrevInstance( CBSTR & Key, CWbemClassInstanceWrapper *& p);
  516. HRESULT ProcessInputParameters(IWbemClassObject **ppParamInput);
  517. HRESULT ProcessOutputParameters();
  518. HRESULT GetInputParameterName(IWbemClassObject *pObject,DBORDINAL iOrdinal , BSTR &strPropName);
  519. };
  520. //////////////////////////////////////////////////////////////////////////////////////////////
  521. class CWbemMethodInstanceWrapper : public CWbemClassInstanceWrapper
  522. {
  523. private:
  524. public:
  525. CWbemMethodInstanceWrapper(CWbemMethodParameters * p);
  526. ~CWbemMethodInstanceWrapper();
  527. virtual HRESULT ResetInstanceFromKey(CBSTR Key);
  528. virtual HRESULT RefreshInstance();
  529. virtual WCHAR * GetClassName();
  530. virtual HRESULT GetKey(CBSTR & Key);
  531. };
  532. class CWbemCollectionInstanceList;
  533. class CWbemCollectionInstanceWrapper;
  534. //////////////////////////////////////////////////////////////////////////////////////////////
  535. // Works with just the rowsets that deal with Methods
  536. //////////////////////////////////////////////////////////////////////////////////////////////
  537. ///////////////////////////////////////////////////////////////////////////////////////////////////
  538. class CWbemCollectionParameters : public CWbemClassParameters
  539. {
  540. public:
  541. CWbemCollectionParameters(DWORD dwFlags,CWbemConnectionWrapper * pWrap ,WCHAR *pClassName);
  542. ~CWbemCollectionParameters();
  543. virtual IWbemServices* GetServicesPtr() { return m_pServices;}
  544. HRESULT Init(BSTR strPath,CWbemConnectionWrapper * pWrap);
  545. private:
  546. IWbemServices * m_pServices;
  547. };
  548. class CWbemCollectionClassDefinitionWrapper : public CWbemClassDefinitionWrapper
  549. {
  550. private:
  551. INSTANCELISTTYPE m_objListType; // Method Storing type of the command.
  552. WCHAR * m_pstrPath;
  553. public:
  554. CWbemCollectionClassDefinitionWrapper(CWbemClassParameters * p,WCHAR * pstrPath,INSTANCELISTTYPE colType);
  555. ~CWbemCollectionClassDefinitionWrapper();
  556. HRESULT Initialize(WCHAR * pstrPath);
  557. HRESULT ValidClass();
  558. HRESULT TotalPropertiesInClass(ULONG & ulPropCount, ULONG &ulSysPropCount);
  559. INSTANCELISTTYPE GetObjListType() { return m_objListType; }
  560. WCHAR *GetObjectPath() { return m_pstrPath; }
  561. };
  562. class CWbemCollectionManager
  563. {
  564. public:
  565. CWbemCollectionManager();
  566. ~CWbemCollectionManager();
  567. void Init(CWbemCollectionInstanceList * InstanceList,
  568. CWbemCollectionParameters * pParms,
  569. CWbemCollectionClassDefinitionWrapper * pDef);
  570. INSTANCELISTTYPE GetObjListType() { return m_pClassDefinition->GetObjListType(); }
  571. WCHAR *GetObjectPath() { return m_pClassDefinition->GetObjectPath(); }
  572. private:
  573. CWbemCollectionClassDefinitionWrapper * m_pClassDefinition;
  574. CWbemCollectionInstanceList * m_pInstanceList;
  575. CWbemCollectionInstanceWrapper * m_pInstance;
  576. CWbemCollectionParameters * m_pParms;
  577. };
  578. class CWbemCollectionInstanceWrapper : public CWbemClassInstanceWrapper
  579. {
  580. private:
  581. CWbemCollectionManager * m_pColMgr;
  582. public:
  583. CWbemCollectionInstanceWrapper(CWbemClassParameters * p,CWbemCollectionManager * pWbemColMgr = NULL);
  584. ~CWbemCollectionInstanceWrapper();
  585. virtual WCHAR * GetClassName();
  586. virtual HRESULT GetKey(CBSTR & Key);
  587. virtual HRESULT RefreshInstance();
  588. };
  589. // Class to represent instance list for scope/collection
  590. class CWbemCollectionInstanceList: public CWbemInstanceList
  591. {
  592. private:
  593. CWbemCollectionManager *m_pColMgr;
  594. public:
  595. CWbemCollectionInstanceList(CWbemClassParameters * p,CWbemCollectionManager * pCollectionMgr);
  596. ~CWbemCollectionInstanceList();
  597. virtual HRESULT Reset();
  598. };
  599. #endif