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.

359 lines
14 KiB

  1. //=============================================================================
  2. // File: gather.h
  3. // Author: a-jammar
  4. // Covers: CDataGatherer, CDataCategory, CDataListCategory
  5. //
  6. // Copyright (c) 1998-1999 Microsoft Corporation
  7. //
  8. // This header file defines the interface between the data gathering portion
  9. // of MSInfo and the code which implements the user interface and MMC snap-in
  10. // code. The data gathering functionality is broken up into three classes.
  11. // The CDataGatherer object is created first and given a template file
  12. // describing the categories and a string indicating the computer from which
  13. // information should be gathered. A member function (GetRootDataCategory) is
  14. // called to return a pointer to a CDataCategory or CDataListCategory object.
  15. // The CDataCategory class implements basic category behavior like getting
  16. // the category name, refreshing the category, and find child or sibling
  17. // categories. CDataListCategory is derived from CDataCategory, and implement
  18. // behavior specific to a category showing a list view, such as getting a row
  19. // count and returning text for a specific column and row.
  20. //
  21. // This header file also defines error codes returned by the classes.
  22. //=============================================================================
  23. #pragma once
  24. #include <afxcmn.h>
  25. // This enumeration is used to indicate how a column in a CDataListCategory
  26. // should be sorted. NOSORT indicates that sorting by that column should not
  27. // be allowed. LEXICAL means to use a standard string sorting (built into
  28. // the list view). BYVALUE means to sort by the DWORD value returned by
  29. // the CDataListCategory::GetValue member function. Note: this type is
  30. // defined here rather than inside the CDataListCategory class because the
  31. // type is used by multiple classes.
  32. enum MSIColumnSortType { NOSORT, LEXICAL, BYVALUE };
  33. // Another enumeration used by multiple classes, this one specified the
  34. // complexity of data (the level of complexity can be controlled by the user).
  35. enum DataComplexity { BASIC, ADVANCED };
  36. // The following structure is used as a parameter in CDataGatherer::Find().
  37. // The m_strPath parameter identifies a node in the namespace using a
  38. // backslash delimited path (starting at the root node) of category
  39. // names to the specific node.
  40. struct MSI_FIND_STRUCT
  41. {
  42. CString m_strSearch; // [IN] string to search for, Find() may change
  43. CString m_strParentPath; // [IN] if not empty, don't search above this in tree
  44. BOOL m_fCaseSensitive; // [IN] if TRUE, do case sensitive search
  45. BOOL m_fSearchData; // [IN] if TRUE, search data items
  46. BOOL m_fSearchCategories; // [IN] if TRUE, search category names
  47. volatile BOOL *m_pfCancel; // [IN] if not NULL, monitor for TRUE value and cancel
  48. CString m_strPath; // [IN/OUT] path to category to start search
  49. int m_iLine; // [IN/OUT] line # to start search, -1 for cat name
  50. BOOL m_fFound; // [OUT] m_strPath & m_iLine tell where
  51. BOOL m_fNotFound; // [OUT] couldn't find the string
  52. BOOL m_fCancelled; // [OUT] *m_pCancel set to TRUE, find cancelled
  53. };
  54. // Forward declarations.
  55. class CDataCategory;
  56. class CTemplateFile;
  57. class CRefreshFunctions;
  58. class CDataProvider;
  59. struct INTERNAL_CATEGORY;
  60. struct GATH_FIELD;
  61. //-----------------------------------------------------------------------------
  62. // CDataGatherer
  63. //
  64. // This class encapsulates the data gathering used in the MSInfo snap-in.
  65. // Typically one object of this type would be created and passed a template
  66. // file. The template file would specify what information is to be shown,
  67. // This object could then be used to get the root data category.
  68. //-----------------------------------------------------------------------------
  69. extern DWORD WINAPI ThreadRefresh(void * pArg);
  70. class CDataGatherer
  71. {
  72. friend class CDataCategory;
  73. friend class CDataListCategory;
  74. friend class CTemplateFileFunctions;
  75. friend class CRefreshFunctions;
  76. friend class CDataProvider;
  77. friend struct INTERNAL_CATEGORY;
  78. friend DWORD WINAPI ThreadRefresh(void * pArg);
  79. public:
  80. CDataGatherer();
  81. ~CDataGatherer();
  82. // Creation functions, allowing various combinations of specifying a
  83. // template file and a machine on the network to gather info for.
  84. // No machine name means that the local machine is used. No template
  85. // file results in no categories.
  86. BOOL Create(LPCTSTR szMachine = NULL);
  87. // Set a different network machine.
  88. BOOL SetConnect(LPCTSTR szMachine = NULL);
  89. // Method to refresh the gathered information. Also, a method to set the
  90. // complexity of the information displayed to the user.
  91. BOOL Refresh(volatile BOOL *pfCancel = NULL);
  92. BOOL SetDataComplexity(DataComplexity complexity = BASIC);
  93. void ResetCategoryRefresh();
  94. // This function is used to control what data categories are actually
  95. // shown or saved by this gatherer.
  96. BOOL SetCategories(const CString & strCategory) { m_strCategory = strCategory; return TRUE; };
  97. // The following method is used to retrieve the root category. It will
  98. // allocate a new category and return a pointer to it. The caller is
  99. // responsible for deallocating the category.
  100. CDataCategory * GetRootDataCategory();
  101. // The following methods are used to find specific nodes in the
  102. // category tree. GetCategoryPath returns a backslash delimited path
  103. // (starting at the root node) of category names to the node identified
  104. // by strIdentifier. IsChildPath is used to determine if the passed
  105. // category pointer is a child category of the passed category path.
  106. BOOL GetCategoryPath(const CString & strIdentifier, CString & strPath);
  107. BOOL IsChildPath(INTERNAL_CATEGORY * pInternalCat, const CString & strParentPath);
  108. // Find is used to search for a specific string in the category names
  109. // or data. The MSI_FIND_STRUCT contains information about the find,
  110. // including where to start the search. Find may be used as a find
  111. // next by using the last matched location and incrementing the line number.
  112. // If Find returns TRUE, information about the search can be read from the
  113. // struct. If it returns FALSE, and error occurred and the struct is invalid.
  114. BOOL Find(MSI_FIND_STRUCT *pFind);
  115. // This method is used to get more information about the last error
  116. // in a gatherer or category member function call. This will return
  117. // an error code, or zero for OK. Note that a successful method
  118. // call will reset the value returned by this method.
  119. DWORD GetLastError();
  120. DWORD GetLastError(DWORD dwID);
  121. // This is made a public member so that other classes can call it to force
  122. // the connection to another computer.
  123. CDataProvider * GetProvider();
  124. // Include a debug only method to dump the contents of this category.
  125. #ifdef _DEBUG
  126. void Dump();
  127. #endif
  128. private:
  129. BOOL m_fInitialized;
  130. DWORD m_dwNextFreeID;
  131. DWORD m_dwRootID;
  132. DWORD m_dwLastError;
  133. DataComplexity m_complexity;
  134. CMapWordToPtr m_mapCategories; // map of IDs to internal category representations
  135. CDataProvider * m_pProvider; // pointer to class encapsulating WBEM functionality
  136. CString m_strDeferredProvider; // name of machine for deferred provider creation
  137. CStringList m_strlistDeferredTemplates;
  138. BOOL m_fDeferredPending;
  139. DWORD m_dwDeferredError;
  140. BOOL m_fTemplatesLoaded;
  141. CString m_strCategory;
  142. // The relative enumeration is used in conjunction with the GetRelative
  143. // member function to retrieve a category pointer to a relative.
  144. enum Relative { PARENT, CHILD, NEXT_SIBLING, PREV_SIBLING };
  145. CDataCategory * GetRelative(DWORD dwID, Relative relative);
  146. // These private methods are called by CDataCategory (and derived) objects.
  147. // Since the CDataGatherer object stores all of the category information,
  148. // all but the first of these are simply called by similarly named member
  149. // functions of the category classes - see definitions there.
  150. BOOL RefreshCategory(DWORD dwID, BOOL fRecursive, volatile BOOL *pfCancel, BOOL fSoftRefresh = FALSE);
  151. int m_cInRefresh; // used to track how deep in recursion we are
  152. BOOL IsValidDataCategory(DWORD dwID);
  153. BOOL IsCategoryDynamic(DWORD dwID);
  154. BOOL HasDynamicChildren(DWORD dwID, BOOL fRecursive);
  155. BOOL GetName(DWORD dwID, CString & strName);
  156. // These methods return information about columns.
  157. DWORD GetColumnCount(DWORD dwID);
  158. BOOL GetColumnCaption(DWORD dwID, DWORD nColumn, CString &strCaption);
  159. BOOL GetColumnWidth(DWORD dwID, DWORD nColumn, DWORD &cxWidth);
  160. BOOL GetColumnSort(DWORD dwID, DWORD nColumn, MSIColumnSortType &sorttype);
  161. BOOL GetColumnDataComplexity(DWORD dwID, DWORD nColumn, DataComplexity & complexity);
  162. // These methods return information about rows.
  163. DWORD GetRowCount(DWORD dwID);
  164. BOOL GetRowDataComplexity(DWORD dwID, DWORD nRow, DataComplexity & complexity);
  165. // GetValue returns the string and DWORD value for the specified row and column.
  166. BOOL GetValue(DWORD dwID, DWORD nRow, DWORD nColumn, CString &strValue, DWORD &dwValue);
  167. // These private methods are used internally within this class and by the
  168. // CTemplateFile friend class or the CRefreshFunctions friend class.
  169. CDataCategory * BuildDataCategory(DWORD dwID);
  170. INTERNAL_CATEGORY * GetInternalRep(DWORD dwID);
  171. void SetLastError(DWORD dwError);
  172. void SetLastError(DWORD dwError, DWORD dwID);
  173. void SetLastErrorHR(HRESULT hrError);
  174. void SetLastErrorHR(HRESULT hrError, DWORD dwID);
  175. void ResetLastError();
  176. CString GetErrorText();
  177. CString GetErrorText(DWORD dwID);
  178. void RemoveAllCategories();
  179. GATH_FIELD * GetColumnField(DWORD dwID, DWORD nColumn);
  180. BOOL FindCategoryByIdentifer(const CString & strIdentifier, CString & strPath, DWORD dwID);
  181. DWORD FindCategoryByPath(const CString & strPath);
  182. BOOL RecursiveFind(INTERNAL_CATEGORY * pCat, MSI_FIND_STRUCT *pFind, int & iLine, CString & strPath);
  183. void GetCategoryPath(INTERNAL_CATEGORY * pCat, CString & strPath);
  184. void LoadTemplates();
  185. };
  186. //-----------------------------------------------------------------------------
  187. // CDataCategory
  188. //
  189. // This class encapsulates the concept of a category. A category has a one-to-
  190. // one correspondence with a node in the MMC namespace. The root CDataCategory
  191. // object is found through a CDataGatherer object, and can be used to navigate
  192. // though the tree of categories. The CDataCategory object can also be used
  193. // to refresh data and a derived class can be used to return results.
  194. //-----------------------------------------------------------------------------
  195. class CDataCategory
  196. {
  197. friend class CDataGatherer;
  198. public:
  199. CDataCategory();
  200. virtual ~CDataCategory();
  201. // This member function is used to retrieve the CDataGatherer object which
  202. // created this CDataCategory (or derived class) object.
  203. CDataGatherer * GetGatherer();
  204. // Methods to retrieve basic information about this category.
  205. BOOL GetName(CString &strName);
  206. BOOL IsValid();
  207. // The following methods are used to determine if this category is a
  208. // dynamic category or if it has children which are dynamic. A dynamic
  209. // category is one which has been generated during the refresh, and which
  210. // may disappear after another refresh. For instance, there might be a
  211. // category with is repeated for each user attached to a share. Note: the
  212. // bRecursive parameter to HasDynamicChildren is used to search down through
  213. // the tree if it is TRUE. Otherwise only the immediate children are examined.
  214. BOOL IsDynamic();
  215. BOOL HasDynamicChildren(BOOL fRecursive = FALSE);
  216. // Category types. Note: later on we might end up adding { HTML, OCX }.
  217. enum CatType { NONE, LISTVIEW };
  218. // Methods to navigate through the tree of categories. The category
  219. // object is allocated and a pointer to it returned. The caller is
  220. // responsible for deallocating the object.
  221. CDataCategory * GetParent();
  222. CDataCategory * GetChild();
  223. CDataCategory * GetNextSibling();
  224. CDataCategory * GetPrevSibling();
  225. // Refresh the information in this category.
  226. BOOL Refresh(BOOL fRecursive = FALSE, volatile BOOL *pfCancel = NULL, BOOL fSoftRefresh = TRUE);
  227. BOOL HasBeenRefreshed();
  228. // Get information about the results pane for this category.
  229. virtual CatType GetResultType() { return NONE; };
  230. protected:
  231. CDataGatherer * m_pGatherer; // CDataGatherer which created this object
  232. DWORD m_dwID; // internal object ID (passed to CDataGatherer methods)
  233. };
  234. //-----------------------------------------------------------------------------
  235. // CDataListCategory
  236. //
  237. // This class extends CDataCategory for categories which show results in
  238. // a list view.
  239. //-----------------------------------------------------------------------------
  240. class CDataListCategory : private CDataCategory
  241. {
  242. public:
  243. CDataListCategory();
  244. virtual ~CDataListCategory();
  245. // We'll override GetResultType to return CDataCategory::LISTVIEW.
  246. virtual CatType GetResultType() { return LISTVIEW; };
  247. // Here are the methods specific to retrieving data from this category
  248. // for the list view.
  249. DWORD GetColumnCount();
  250. DWORD GetRowCount();
  251. BOOL GetColumnCaption(DWORD nColumn, CString &strCaption);
  252. BOOL GetColumnWidth(DWORD nColumn, DWORD &cxWidth);
  253. BOOL GetColumnDataComplexity(DWORD nColumn, DataComplexity & complexity);
  254. BOOL GetRowDataComplexity(DWORD nRow, DataComplexity & complexity);
  255. // This method returns the sorting type for the column. See comment
  256. // for MSIColumnSortType at the beginning of this file.
  257. BOOL GetColumnSort(DWORD nColumn, MSIColumnSortType & sorttype);
  258. // This method returns the value for the requested row and column. Both
  259. // the string value to display and a DWORD value possibly used for sorting
  260. // are returned.
  261. BOOL GetValue(DWORD nRow, DWORD nColumn, CString &strValue, DWORD &dwValue);
  262. };
  263. //-----------------------------------------------------------------------------
  264. // These error codes are returned by CDataGatherer::GetLastError().
  265. //-----------------------------------------------------------------------------
  266. #define GATH_ERR_NOERROR 0x00000000L
  267. #define GATH_ERR_ALLOCATIONFAILED 0x80000002L
  268. #define GATH_ERR_BADCATEGORYID 0x80000003L
  269. #define GATH_ERR_NOWBEMCONNECT 0x80000004L
  270. #define GATH_ERR_NOWBEMLOCATOR 0x80000005L
  271. #define GATH_ERR_NOTINITIALIZED 0x80000008L
  272. #define GATH_ERR_BADCATIDENTIFIER 0x80000009L
  273. #define GATH_ERR_FINDDATANOTFOUND 0x8000000AL
  274. #define GATH_ERR_NOWBEMOUTOFMEM 0x8000000BL
  275. #define GATH_ERR_NOWBEMACCESSDENIED 0x8000000CL
  276. #define GATH_ERR_NOWBEMBADSERVER 0x8000000DL
  277. #define GATH_ERR_NOWBEMNETWORKFAILURE 0x8000000EL
  278. // Obsolete error messages (template information moved to DLLs).
  279. //
  280. // #define GATH_ERR_BADTEMPLATENAME 0x80000001L
  281. // #define GATH_ERR_TEMPLATEVERSION 0x80000006L
  282. // #define GATH_ERR_TEMPLATEFORMAT 0x80000007L