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.

377 lines
13 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // @module baseRowobj.h Header file of abstract base class of CRow and CRowset
  7. //
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////////
  10. #ifndef _ROWSETBASE_H_
  11. #define _ROWSETBASE_H_
  12. #include "headers.h"
  13. #include "bitarray.h"
  14. #include "extbuff.h"
  15. #include "hashtbl.h"
  16. #define NUMBER_OF_COLUMNS_IN_QUALIFERROWSET 4
  17. #define COLNAMESIZE 255
  18. #define QUALIFERNAMECOL 0
  19. #define ONE_ROW 1
  20. #define QUALIFIERNAMECOL 1
  21. #define QUALIFIERTYPECOL 2
  22. #define QUALIFIERVALCOL 3
  23. #define QUALIFIERFLAVOR 4
  24. class CImpIRowsetLocate;
  25. class CImpIRowsetChange;
  26. class CImpIColumnsInfo;
  27. class CImpIAccessor;
  28. class CImpIRowsetInfo;
  29. class CImpIRowsetIdentity;
  30. class CImpIConvertType;
  31. class CImpIChapteredRowset;
  32. class CRowFetchObj;
  33. class CInstanceRowFetchObj;
  34. class CQualifierRowFetchObj;
  35. class CRowset;
  36. class CChapterMgr;
  37. class CInstance;
  38. class CWMIInstanceMgr;
  39. typedef CImpIRowsetLocate* PIMPIROWSET;
  40. typedef CImpIRowsetLocate* PIMPIROWSETLOCATE;
  41. typedef CImpIRowsetChange* PIMPIROWSETCHANGE;
  42. typedef CImpIColumnsInfo* PIMPICOLUMNSINFO;
  43. typedef CImpIAccessor * PIMPIACCESSOR;
  44. typedef CImpIRowsetIdentity*PIMPIROWSETIDENTITY;
  45. typedef CImpIRowsetInfo* PIMPIROWSETINFO;
  46. typedef CImpIConvertType* PIMPICONVERTTYPE;
  47. typedef CImpIChapteredRowset* PICHAPTEREDROWSET;
  48. typedef CRowFetchObj* PROWFETCHOBJ;
  49. //=====================================================
  50. // Struct to hold column information for Rowsets/row
  51. // showing qualifiers
  52. //=====================================================
  53. struct _qualifierColInfo
  54. {
  55. PWSTR pwszName;
  56. DBTYPE wType;
  57. DBLENGTH ulSize;
  58. DBSTATUS dwStatus;
  59. };
  60. typedef _qualifierColInfo QUALIFIERCOLINFO;
  61. /////////////////////////////////////////////////////////////////////////////////////////////////////
  62. // Class to manage Row Data
  63. /////////////////////////////////////////////////////////////////////////////////////////////////////
  64. class CRowDataMemMgr
  65. {
  66. public:
  67. CRowDataMemMgr();
  68. ~CRowDataMemMgr();
  69. HRESULT SetColumnBind( DBORDINAL dwCol, PCOLUMNDATA pColumn );
  70. HRESULT ReAllocRowData();
  71. HRESULT AllocRowData(ULONG_PTR);
  72. HRESULT ResetColumns();
  73. HRESULT CommitColumnToRowData(CVARIANT & vVar,DBTYPE lType);
  74. HRESULT CommitColumnToRowData(CVARIANT & vVar, DBORDINAL nIndex,DBTYPE lType);
  75. void ReleaseRowData();
  76. void ReleaseBookMarkColumn();
  77. private:
  78. PCOLUMNDATA *m_prgpColumnData;
  79. DBCOUNTITEM m_cbTotalCols;
  80. DBORDINAL m_nCurrentIndex;
  81. };
  82. /////////////////////////////////////////////////////////////////////////////////////////////////////
  83. // Class to manage column information
  84. /////////////////////////////////////////////////////////////////////////////////////////////////////
  85. class cRowColumnInfoMemMgr
  86. {
  87. public:
  88. cRowColumnInfoMemMgr(cRowColumnInfoMemMgr *pSrcRsColInfo = NULL);
  89. ~cRowColumnInfoMemMgr();
  90. DBTYPE ColumnType(DBORDINAL icol);
  91. WCHAR * ColumnName(DBORDINAL icol);
  92. DBCOLUMNFLAGS ColumnFlags(DBORDINAL icol);
  93. DBORDINAL GetColOrdinal(WCHAR *pColName);
  94. LONG GetCIMType(DBORDINAL icol);
  95. ULONG_PTR SetRowSize();
  96. DBBYTEOFFSET GetDataOffset(DBORDINAL icol);
  97. WCHAR * ColumnNameListStartingPoint();
  98. DBORDINAL GetCurrentIndex();
  99. HRESULT CopyColumnInfoList(DBCOLUMNINFO *& pNew,BOOL bBookMark = TRUE);
  100. HRESULT CopyColumnNamesList(WCHAR *& pNew);
  101. DBCOLUMNINFO ** CurrentColInfo();
  102. DBCOLUMNINFO * GetColInfo(DBORDINAL icol);
  103. WCHAR * ColumnNameListStartingPointOfSrcRs();
  104. DBLENGTH GetCountOfBytesCopiedForSrcRs();
  105. HRESULT AddColumnNameToList(WCHAR * pColumnName, DBCOLUMNINFO ** pCol);
  106. // NTRaid:111762
  107. // 06/13/00
  108. HRESULT CommitColumnInfo();
  109. HRESULT ResetColumns();
  110. HRESULT ReAllocColumnInfoList();
  111. HRESULT AllocColumnInfoList(DBCOUNTITEM cCols);
  112. HRESULT AllocColumnNameList(DBCOUNTITEM nCols);
  113. HRESULT FreeUnusedMemory();
  114. HRESULT FreeColumnNameList();
  115. HRESULT FreeColumnInfoList();
  116. HRESULT InitializeBookMarkColumn();
  117. DBCOUNTITEM GetTotalNumberOfColumns(); // This includes all the columns including the sources rowsets
  118. DBCOUNTITEM GetNumberOfColumnsInSourceRowset();
  119. void SetCIMType(ULONG dwCIMType,DBORDINAL lIndex = -1); // IF index is -1 then set the CIMTYPE of the current col
  120. protected:
  121. WCHAR * m_pbColumnNames; //Pointer to Info Array Heap (heap of column name strings)
  122. WCHAR * m_lpCurrentName; //Pointer to Info Array Heap (heap of column name strings)
  123. DBCOUNTITEM m_cbFreeColumnNameBytes; // how many bytes of the column names heap is in use
  124. DBCOUNTITEM m_cbColumnInfoBytesUsed; // count of bytes used for column information
  125. DBCOLUMNINFO* m_DBColInfoList; // ColumnInfo array
  126. DBBYTEOFFSET* m_rgdwDataOffsets; // column offsets in buffer
  127. DBORDINAL m_cbCurrentIndex; // The current index of column information
  128. DBCOUNTITEM m_cbTotalCols; // number of columns
  129. DBCOLUMNINFO * m_pCurrentColInfo; // Pointer to the current column information
  130. DBBYTEOFFSET m_dwOffset;
  131. cRowColumnInfoMemMgr * m_pSrcRsColInfo; // pointer to the the rowset that created this
  132. // Mainly used with row objects. If there are any
  133. // new rows apart from the source rowset
  134. DBORDINAL m_nFirstIndex; // Index of the first column if there is any source
  135. // rowset for the row
  136. ULONG * m_rgCIMType; // array to store the base CIMTYP of the property
  137. };
  138. /////////////////////////////////////////////////////////////////////////////////////////////////////
  139. // Abstract Base class for CRow and CRowset class
  140. /////////////////////////////////////////////////////////////////////////////////////////////////////
  141. class CBaseRowObj:public CBaseObj
  142. {
  143. friend class CImpIColumnsInfo;
  144. friend class CImpIConvertType;
  145. friend class CRowFetchObj;
  146. friend class CInstanceRowFetchObj;
  147. friend class CQualifierRowFetchObj;
  148. friend class CRowset;
  149. protected:
  150. CWmiOleDBMap * m_pMap; // CWmiOleDBMap class pointer to interact with WMI
  151. cRowColumnInfoMemMgr m_Columns; // Column information class
  152. CRowDataMemMgr * m_pRowData; // pointer to Row data manager to manage row data
  153. CChapterMgr * m_pChapterMgr; // chapter manager of the rowset to manage chapters
  154. DBCOUNTITEM m_cTotalCols; // Total number of columns
  155. DBCOUNTITEM m_cCols; // Count of Parent Columns in Result Set
  156. DBCOUNTITEM m_cNestedCols; // Number of child rowsets ( chaptered columns)
  157. BYTE * m_rgbRowData; // Pointer to row data of the current row that rowset/row is dealing
  158. PCUTILPROP m_pUtilProp; // Utility object to manage properties
  159. PIMPICOLUMNSINFO m_pIColumnsInfo; // Contained IColumnsInfo
  160. PIMPICONVERTTYPE m_pIConvertType; // Contained IConvertType
  161. PLSTSLOT m_pIBuffer; // internal buffer structure
  162. PIMPISUPPORTERRORINFO m_pISupportErrorInfo; // contained ISupportErrorInfo
  163. DBLENGTH m_cbRowSize; // size of row data in the buffer
  164. unsigned int m_uRsType; // Type of the rowset/row
  165. ULONG m_ulProps; // member variable storing value of some commonly used rowset properties
  166. HROW m_hRow; // member variable that stores the last HROW given out
  167. //Back pointer to a creator object. Used in IRowssetInfo::GetSpecification
  168. PCDBSESSION m_pCreator;
  169. CWbemConnectionWrapper* m_pCon; // This used for remote/cross namespace objects to
  170. // to store their IWbemServicesPointer
  171. BOOL m_bNewConAllocated; // variable which indicates whether m_pCon was allocated or not
  172. BOOL m_IsZoombie; // flag which indicates whether the object is in Zoombie state
  173. HRESULT GatherColumnInfo(void); //Builds DBCOLINFO structures
  174. HROW GetNextHRow() { return ++ m_hRow; };
  175. HRESULT GetRowsetProperty(DBPROPID propId , VARIANT & varValue);
  176. void GetCommonRowsetProperties();
  177. HRESULT GetColumnInfo();
  178. DBORDINAL GetOrdinalFromColName(WCHAR *pColName);
  179. HRESULT SetRowsetProperty(DBPROPID propId , VARIANT varValue);
  180. HRESULT RefreshInstance(CWbemClassWrapper *pInstance);
  181. HRESULT SynchronizeDataSourceMode();
  182. HRESULT GatherColumnInfoForQualifierRowset();
  183. ULONG GetQualifierFlags();
  184. DBLENGTH GetRowSize() { return m_cbRowSize;}
  185. HRESULT SetProperties(const ULONG cPropertySets, const DBPROPSET rgPropertySets[] );
  186. HRESULT SetSearchPreferences();
  187. BOOL IsZoombie() { return m_IsZoombie; }
  188. INSTANCELISTTYPE GetObjectTypeProp(const ULONG cPropertySets, const DBPROPSET rgPropertySets[]);
  189. HRESULT InitializePropertiesForSchemaRowset();
  190. HRESULT InitializePropertiesForCommandRowset();
  191. HRESULT InitializePropertiesForMethodRowset();
  192. // This function is to be overridden by derived classes
  193. virtual HRESULT GetColumnInfo(DBORDINAL* pcColumns, DBCOLUMNINFO** prgInfo,WCHAR** ppStringsBuffer) = 0;
  194. virtual HRESULT AddInterfacesForISupportErrorInfo() = 0;
  195. public:
  196. CBaseRowObj(LPUNKNOWN pUnkOuter);
  197. ~CBaseRowObj();
  198. // IUnknown methods
  199. STDMETHODIMP QueryInterface(REFIID, LPVOID *) = 0;
  200. STDMETHODIMP_(ULONG) AddRef(void) = 0;
  201. STDMETHODIMP_(ULONG) Release(void) = 0;
  202. void SetStatusToZoombie() { m_IsZoombie = TRUE; }
  203. };
  204. /////////////////////////////////////////////////////////////////////////////////////////////////////
  205. // A linked list class to store list of HROWS for a particular chapter
  206. /////////////////////////////////////////////////////////////////////////////////////////////////////
  207. class CHRowsForChapter
  208. {
  209. friend class CChapter;
  210. friend class CChapterMgr;
  211. HROW m_hRow;
  212. CHRowsForChapter * m_pNext;
  213. HSLOT m_hSlot;
  214. CWbemClassWrapper * m_pInstance;
  215. BSTR m_strKey;
  216. DBSTATUS m_dwStatus;
  217. CHRowsForChapter()
  218. {
  219. m_hRow = 0;
  220. m_pNext = NULL;
  221. m_hSlot = -1;
  222. m_pInstance = NULL;
  223. m_strKey = NULL;
  224. m_dwStatus = DBROWSTATUS_S_OK;
  225. }
  226. ~CHRowsForChapter()
  227. {
  228. if(m_strKey != NULL)
  229. {
  230. SysFreeString(m_strKey);
  231. }
  232. }
  233. void SetRowStatus(DWORD dwStatus) { m_dwStatus = dwStatus ; };
  234. DBSTATUS GetRowStatus() { return m_dwStatus; };
  235. };
  236. /////////////////////////////////////////////////////////////////////////////////////////////////////
  237. // class to maintain HCHAPTER to Rowset mapping
  238. /////////////////////////////////////////////////////////////////////////////////////////////////////
  239. class CChapter
  240. {
  241. friend class CChapterMgr;
  242. CChapter();
  243. ~CChapter();
  244. HRESULT AddHRow(HROW hRow = 0, CWbemClassWrapper *pInstance = NULL, HSLOT hSlot = -1);
  245. HRESULT DeleteHRow(HROW hRow);
  246. HRESULT IsHRowOfThisChapter(HROW hRow);
  247. HRESULT GetAllHRowsInList(HROW *pHRows);
  248. HRESULT SetSlot(HROW hRow , HSLOT hSolt);
  249. HSLOT GetSlot(HROW hRow);
  250. HRESULT SetInstance(HROW hRow ,BSTR strInstKey , CWbemClassWrapper *pInstance); // This method is for chapter representing child rows of type Embeded classes
  251. HRESULT GetInstanceKey(HROW hRow , BSTR *pstrKey);
  252. void SetRowStatus(HROW hRow, DBSTATUS dwStatus);
  253. DBSTATUS GetRowStatus(HROW hRow);
  254. HROW GetHRow(BSTR strInstKey);
  255. CWbemClassWrapper * GetInstance(HROW hRow); // This method is for chapter representing child rows of type Embeded classes
  256. private:
  257. CHRowsForChapter * m_pFirstRow;
  258. HCHAPTER m_hChapter;
  259. ULONG m_cRefChapter;
  260. CWbemClassWrapper * m_pInstance;
  261. BSTR m_strKey;
  262. CChapter * m_pNext;
  263. ULONG_PTR m_lCount; // count of HROWS in the list
  264. DBSTATUS m_dwStatus;
  265. };
  266. /////////////////////////////////////////////////////////////////////////////////////////////////////
  267. // class to maintain Chapters for a rowset
  268. /////////////////////////////////////////////////////////////////////////////////////////////////////
  269. class CChapterMgr
  270. {
  271. CChapter * m_pHead;
  272. ULONG_PTR m_lCount; // count of Chapters in the list
  273. public:
  274. CChapterMgr();
  275. ~CChapterMgr();
  276. HRESULT AddChapter(HCHAPTER hChapter);
  277. HRESULT DeleteChapter(HCHAPTER hChapter);
  278. void SetInstance(HCHAPTER hChapter , CWbemClassWrapper *pInstance,BSTR strKey,HROW hRow = 0);
  279. CWbemClassWrapper * GetInstance(HCHAPTER hChapter , HROW hRow = 0);
  280. HRESULT GetInstanceKey(HCHAPTER hChapter, BSTR *pstrKey , HROW hRow = 0);
  281. HRESULT AddHRowForChapter(HCHAPTER hChapter , HROW hRow, CWbemClassWrapper *pInstance = NULL, HSLOT hSlot = -1);
  282. HRESULT SetSlot(HROW hRow , HSLOT hSlot);
  283. HRESULT DeleteHRow(HROW hRow);
  284. HCHAPTER GetChapterForHRow(HROW hRow);
  285. HSLOT GetSlot(HROW hRow);
  286. BOOL IsRowExists(HROW hRow);
  287. BOOL IsExists(HCHAPTER hChapter);
  288. BOOL IsInstanceExist(BSTR strKey);
  289. BOOL IsInstanceExist(CWbemClassWrapper *pInstance);
  290. ULONG AddRefChapter(HCHAPTER hChapter);
  291. ULONG ReleaseRefChapter(HCHAPTER hChapter);
  292. HRESULT GetAllHROWs(HROW *&prghRows , DBCOUNTITEM &cRows);
  293. HRESULT IsRowExistsForChapter(HCHAPTER hChapter);
  294. void SetRowStatus(HROW hRow , DWORD dwStatus);
  295. DBSTATUS GetRowStatus(HROW hRow);
  296. void SetChapterStatus(HCHAPTER hChapter , DBSTATUS dwStatus);
  297. DBSTATUS GetChapterStatus(HCHAPTER hChapter);
  298. HROW GetHRow(HCHAPTER hChapter ,BSTR strKey = Wmioledb_SysAllocString(NULL));
  299. };
  300. #endif