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.

402 lines
9.6 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: handle.hxx
  7. //
  8. // Contents: Defines CHandle
  9. //
  10. // Classes: CHandle
  11. // CStgHandle
  12. // CStmHandle
  13. //
  14. //---------------------------------------------------------------
  15. #ifndef __HANDLE_HXX__
  16. #define __HANDLE_HXX__
  17. #include "msf.hxx"
  18. #include "msffunc.hxx"
  19. //+--------------------------------------------------------------
  20. //
  21. // Class: CHandle (h)
  22. //
  23. // Purpose: An opaque handle to a directory entry-based object
  24. //
  25. // Interface: See below
  26. //
  27. //---------------------------------------------------------------
  28. class CStgHandle;
  29. class CStmHandle;
  30. class CHandle
  31. {
  32. public:
  33. inline CHandle(void);
  34. inline void Init(CMStream *pms,
  35. SID sid);
  36. inline BOOL IsRoot(void) const;
  37. inline BOOL IsValid(void) const;
  38. inline SCODE GetTime(WHICHTIME wt, TIME_T *ptm);
  39. inline SCODE SetTime(WHICHTIME wt, TIME_T tm);
  40. inline SCODE DestroyEntry(CDfName const *pdfn);
  41. inline CMStream *GetMS(void) const;
  42. inline SID GetSid(void) const;
  43. private:
  44. friend class CStgHandle;
  45. friend class CStmHandle;
  46. CMStream *_pms;
  47. SID _sid;
  48. };
  49. //+--------------------------------------------------------------
  50. //
  51. // Member: CHandle::CHandle, public
  52. //
  53. // Synopsis: NULL constructor
  54. //
  55. //---------------------------------------------------------------
  56. inline CHandle::CHandle(void)
  57. {
  58. _pms = NULL;
  59. _sid = NOSTREAM;
  60. }
  61. //+--------------------------------------------------------------
  62. //
  63. // Member: CHandle::Init, public
  64. //
  65. // Synopsis: Sets internal data members
  66. //
  67. // Arguments: [pms] - Multistream
  68. // [sid] - SID
  69. //
  70. // Returns: Appropriate status code
  71. //
  72. //---------------------------------------------------------------
  73. inline void CHandle::Init(CMStream *pms,
  74. SID sid)
  75. {
  76. _pms = pms;
  77. _sid = sid;
  78. }
  79. //+--------------------------------------------------------------
  80. //
  81. // Member: CHandle::IsRoot, public
  82. //
  83. // Synopsis: Whether this is a root handle or not
  84. //
  85. //---------------------------------------------------------------
  86. inline BOOL CHandle::IsRoot(void) const
  87. {
  88. return _sid == SIDROOT;
  89. }
  90. //+--------------------------------------------------------------
  91. //
  92. // Member: CHandle::IsValid, public
  93. //
  94. // Synopsis: Whether this handle has been initialized
  95. //
  96. //---------------------------------------------------------------
  97. inline BOOL CHandle::IsValid(void) const
  98. {
  99. return _pms != NULL;
  100. }
  101. //+--------------------------------------------------------------
  102. //
  103. // Member: CHandle::GetTime, public
  104. //
  105. // Synopsis: Returns the time
  106. //
  107. //---------------------------------------------------------------
  108. inline SCODE CHandle::GetTime(WHICHTIME wt, TIME_T *ptm)
  109. {
  110. return _pms->GetTime(_sid, wt, ptm);
  111. }
  112. //+--------------------------------------------------------------
  113. //
  114. // Member: CHandle::SetTime, public
  115. //
  116. // Synopsis: Sets the time
  117. //
  118. //---------------------------------------------------------------
  119. inline SCODE CHandle::SetTime(WHICHTIME wt, TIME_T tm)
  120. {
  121. return _pms->SetTime(_sid, wt, tm);
  122. }
  123. //+--------------------------------------------------------------
  124. //
  125. // Member: CHandle::DestroyEntry, public
  126. //
  127. // Synopsis: Destroys this entry
  128. //
  129. // Returns: Appropriate status code
  130. //
  131. //---------------------------------------------------------------
  132. inline SCODE CHandle::DestroyEntry(CDfName const *pdfn)
  133. {
  134. return _pms->DestroyEntry(_sid, pdfn);
  135. }
  136. //+--------------------------------------------------------------
  137. //
  138. // Member: CHandle::GetMS, public
  139. //
  140. // Synopsis: Returns the multistream
  141. //
  142. //---------------------------------------------------------------
  143. inline CMStream *CHandle::GetMS(void) const
  144. {
  145. return _pms;
  146. }
  147. //+--------------------------------------------------------------
  148. //
  149. // Member: CHandle::GetSid, public
  150. //
  151. // Synopsis: Returns the sid
  152. //
  153. //---------------------------------------------------------------
  154. inline SID CHandle::GetSid(void) const
  155. {
  156. return _sid;
  157. }
  158. //+--------------------------------------------------------------
  159. //
  160. // Class: CStgHandle, (stgh)
  161. //
  162. // Purpose: An opaque handle for Multistream directories
  163. //
  164. // Interface: See below
  165. //
  166. //---------------------------------------------------------------
  167. class CMSFIterator;
  168. class CStgHandle : public CHandle
  169. {
  170. public:
  171. inline SCODE CreateEntry(CDfName const *pdfnName,
  172. MSENTRYFLAGS const mefFlags,
  173. CHandle *ph);
  174. inline SCODE GetEntry(CDfName const *pdfnName,
  175. MSENTRYFLAGS const mefFlags,
  176. CHandle *ph);
  177. inline SCODE RenameEntry(CDfName const *pdfnName,
  178. CDfName const *pdfnNewName);
  179. inline SCODE IsEntry(CDfName const *pdfnName,
  180. SEntryBuffer *peb);
  181. inline SCODE GetIterator(CMSFIterator **ppi);
  182. inline SCODE GetClass(CLSID *pclsid);
  183. inline SCODE SetClass(REFCLSID clsid);
  184. inline SCODE GetStateBits(DWORD *pgrfStateBits);
  185. inline SCODE SetStateBits(DWORD grfStateBits, DWORD grfMask);
  186. };
  187. //+--------------------------------------------------------------
  188. //
  189. // Member: CStgHandle::CreateEntry, public
  190. //
  191. // Synopsis: Creates an entry
  192. //
  193. //---------------------------------------------------------------
  194. inline SCODE CStgHandle::CreateEntry(CDfName const *pdfnName,
  195. MSENTRYFLAGS const mefFlags,
  196. CHandle *ph)
  197. {
  198. ph->_pms = _pms;
  199. return _pms->CreateEntry(_sid, pdfnName, mefFlags, &ph->_sid);
  200. }
  201. //+--------------------------------------------------------------
  202. //
  203. // Member: CStgHandle::GetEntry, public
  204. //
  205. // Synopsis: Gets an entry
  206. //
  207. //---------------------------------------------------------------
  208. inline SCODE CStgHandle::GetEntry(CDfName const *pdfnName,
  209. MSENTRYFLAGS const mefFlags,
  210. CHandle *ph)
  211. {
  212. SCODE sc;
  213. SEntryBuffer eb;
  214. ph->_pms = _pms;
  215. sc = _pms->IsEntry(_sid, pdfnName, &eb);
  216. if (SUCCEEDED(sc))
  217. {
  218. msfAssert(eb.sid != NOSTREAM);
  219. // entry exists but it may be the wrong type
  220. if ((mefFlags != MEF_ANY) && (mefFlags != eb.dwType))
  221. {
  222. sc = STG_E_FILENOTFOUND;
  223. }
  224. else
  225. ph->_sid = eb.sid;
  226. }
  227. return(sc);
  228. }
  229. //+--------------------------------------------------------------
  230. //
  231. // Member: CStgHandle::RenameEntry, public
  232. //
  233. // Synopsis: Renames an entry
  234. //
  235. //---------------------------------------------------------------
  236. inline SCODE CStgHandle::RenameEntry(CDfName const *pdfnName,
  237. CDfName const *pdfnNewName)
  238. {
  239. return _pms->RenameEntry(_sid, pdfnName, pdfnNewName);
  240. }
  241. //+--------------------------------------------------------------
  242. //
  243. // Member: CStgHandle::IsEntry, public
  244. //
  245. // Synopsis: Gets entry info and checks for existence
  246. //
  247. //---------------------------------------------------------------
  248. inline SCODE CStgHandle::IsEntry(CDfName const *pdfnName,
  249. SEntryBuffer *peb)
  250. {
  251. return _pms->IsEntry(_sid, pdfnName, peb);
  252. }
  253. //+--------------------------------------------------------------
  254. //
  255. // Member: CStgHandle::GetIterator, public
  256. //
  257. // Synopsis: Gets an iterator
  258. //
  259. //---------------------------------------------------------------
  260. inline SCODE CStgHandle::GetIterator(CMSFIterator **ppi)
  261. {
  262. return _pms->GetIterator(_sid, ppi);
  263. }
  264. //+---------------------------------------------------------------------------
  265. //
  266. // Member: CStgHandle::GetClass, public
  267. //
  268. // Synopsis: Gets the class ID
  269. //
  270. //----------------------------------------------------------------------------
  271. inline SCODE CStgHandle::GetClass(CLSID *pclsid)
  272. {
  273. return _pms->GetClass(_sid, pclsid);
  274. }
  275. //+---------------------------------------------------------------------------
  276. //
  277. // Member: CStgHandle::SetClass, public
  278. //
  279. // Synopsis: Sets the class ID
  280. //
  281. //----------------------------------------------------------------------------
  282. inline SCODE CStgHandle::SetClass(REFCLSID clsid)
  283. {
  284. return _pms->SetClass(_sid, clsid);
  285. }
  286. //+---------------------------------------------------------------------------
  287. //
  288. // Member: CStgHandle::GetStateBits, public
  289. //
  290. // Synopsis: Gets state bits
  291. //
  292. //----------------------------------------------------------------------------
  293. inline SCODE CStgHandle::GetStateBits(DWORD *pgrfStateBits)
  294. {
  295. return _pms->GetStateBits(_sid, pgrfStateBits);
  296. }
  297. //+---------------------------------------------------------------------------
  298. //
  299. // Member: CStgHandle::SetStateBits, public
  300. //
  301. // Synopsis: Sets state bits
  302. //
  303. //----------------------------------------------------------------------------
  304. inline SCODE CStgHandle::SetStateBits(DWORD grfStateBits, DWORD grfMask)
  305. {
  306. return _pms->SetStateBits(_sid, grfStateBits, grfMask);
  307. }
  308. //+--------------------------------------------------------------
  309. //
  310. // Class: CStmHandle, (stmh)
  311. //
  312. // Purpose: An opaque handle for Multistream streams
  313. //
  314. // Interface: See below
  315. //
  316. //---------------------------------------------------------------
  317. class CDirectStream;
  318. class CStmHandle : public CHandle
  319. {
  320. public:
  321. inline SCODE GetSize(ULONGLONG *pcbSize);
  322. };
  323. //+--------------------------------------------------------------
  324. //
  325. // Member: CStmHandle::GetSize, public
  326. //
  327. // Synopsis: Gets the stream size
  328. //
  329. //---------------------------------------------------------------
  330. inline SCODE CStmHandle::GetSize(ULONGLONG *pcbSize)
  331. {
  332. return _pms->GetEntrySize(_sid, pcbSize);
  333. }
  334. #endif // #ifndef __HANDLE_HXX__