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.

380 lines
9.2 KiB

  1. // FrcOwn.h : Declaration of the CForceOwnership
  2. #ifndef __FRCOWN_H_
  3. #define __FRCOWN_H_
  4. #include "resource.h" // main symbols
  5. #include <trkwks.hxx>
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CForceOwnership
  8. class ATL_NO_VTABLE CTrkForceOwnership :
  9. public CComObjectRootEx<CComSingleThreadModel>,
  10. public CComCoClass<CTrkForceOwnership, &CLSID_TrkForceOwnership>,
  11. public IDispatchImpl<ITrkForceOwnership, &IID_ITrkForceOwnership, &LIBID_ITRKADMNLib>
  12. {
  13. public:
  14. CTrkForceOwnership() :
  15. _idt(_dbc, &_refreshSequenceStorage),
  16. _voltab(_dbc, &_refreshSequenceStorage),
  17. _refreshSequenceStorage( &_voltab )
  18. {
  19. __try
  20. {
  21. _dbc.Initialize(NULL);
  22. _voltab.Initialize(NULL,0,0);
  23. _idt.Initialize();
  24. }
  25. __except( BreakOnDebuggableException() )
  26. {
  27. }
  28. }
  29. DECLARE_REGISTRY_RESOURCEID(IDR_FRCOWN)
  30. BEGIN_COM_MAP(CTrkForceOwnership)
  31. COM_INTERFACE_ENTRY(ITrkForceOwnership)
  32. COM_INTERFACE_ENTRY(IDispatch)
  33. END_COM_MAP()
  34. // ITrkForceOwnership
  35. public:
  36. STDMETHOD(FileStatus)(BSTR bstrUncPath, long lScope, VARIANT *pvarrgbstrFileName, VARIANT* pvarrgbstrFileId, VARIANT* pvarrglongStatus);
  37. STDMETHOD(VolumeStatus)(BSTR bstrUncPath, long lScope, VARIANT *pvarlongVolIndex,
  38. VARIANT *pvarbstrVolId, VARIANT *pvarlongStatus);
  39. STDMETHOD(Files)(BSTR bstrUncPath, long lScope);
  40. STDMETHOD(Volumes)(BSTR bstrUncPath, long lScope );
  41. private:
  42. CDbConnection _dbc;
  43. CVolumeTable _voltab;
  44. CIntraDomainTable _idt;
  45. CRefreshSequenceStorage _refreshSequenceStorage;
  46. };
  47. //
  48. // This class is used on the client side of an RPC pipe parameter that passes
  49. // volume tracking information. The client provides a derived class which
  50. // overrides the push/pull methods as appropriate.
  51. //
  52. class PVolInfoPipeCallback : public TPRpcPipeCallback<TRK_VOLUME_TRACKING_INFORMATION>
  53. {
  54. public:
  55. virtual void Pull( TRK_VOLUME_TRACKING_INFORMATION *pVolInfo, unsigned long cbBuffer, unsigned long * pcElems ) = 0;
  56. virtual void Push( TRK_VOLUME_TRACKING_INFORMATION *pVolInfo, unsigned long cElems ) = 0;
  57. virtual void Alloc( unsigned long cbRequested, TRK_VOLUME_TRACKING_INFORMATION **ppVolInfo, unsigned long * pcbActual )
  58. {
  59. if( cbRequested > sizeof(_rgVolInfo) )
  60. *pcbActual = sizeof(_rgVolInfo);
  61. else
  62. *pcbActual = cbRequested;
  63. *ppVolInfo = _rgVolInfo;
  64. return;
  65. }
  66. private:
  67. TRK_VOLUME_TRACKING_INFORMATION _rgVolInfo[ 26 ];
  68. };
  69. //
  70. // This class is used on the client side of an RPC pipe parameter that passes
  71. // file tracking information. The client provides a derived class which
  72. // overrides the push/pull methods as appropriate.
  73. //
  74. class PFileInfoPipeCallback : public TPRpcPipeCallback<TRK_FILE_TRACKING_INFORMATION>
  75. {
  76. public:
  77. virtual void Pull( TRK_FILE_TRACKING_INFORMATION *pVolInfo, unsigned long cbBuffer, unsigned long * pcElems ) = 0;
  78. virtual void Push( TRK_FILE_TRACKING_INFORMATION *pFileInfo, unsigned long cElems ) = 0;
  79. virtual void Alloc( unsigned long cbRequested, TRK_FILE_TRACKING_INFORMATION **ppFileInfo, unsigned long * pcbActual )
  80. {
  81. if( cbRequested > sizeof(_rgFileInfo) )
  82. *pcbActual = sizeof(_rgFileInfo);
  83. else
  84. *pcbActual = cbRequested;
  85. *ppFileInfo = _rgFileInfo;
  86. return;
  87. }
  88. protected:
  89. TRK_FILE_TRACKING_INFORMATION _rgFileInfo[ 32 ];
  90. };
  91. //
  92. // This class is used on the client side of an RPC pipe parameter that passes
  93. // a path from the client to the server.
  94. //
  95. class CPCPath : public TPRpcPipeCallback<TCHAR>
  96. {
  97. public:
  98. CPCPath( TCHAR *ptszPath )
  99. {
  100. _iPath = 0;
  101. _tcscpy( _tszPath, ptszPath );
  102. _cchPath = _tcslen(_tszPath) + 1;
  103. }
  104. public:
  105. void Pull( TCHAR *ptszPath, unsigned long cbBuffer, unsigned long * pcElems )
  106. {
  107. if( 0 > _iPath )
  108. {
  109. *pcElems = 0;
  110. return;
  111. }
  112. else
  113. {
  114. if( sizeof(TCHAR) * (_cchPath - _iPath) > cbBuffer )
  115. *pcElems = cbBuffer / sizeof(TCHAR);
  116. else
  117. *pcElems = _cchPath - _iPath;
  118. memcpy( ptszPath, &_tszPath[ _iPath ], *pcElems * sizeof(TCHAR) );
  119. if( _iPath + *pcElems >= _cchPath )
  120. _iPath = -1;
  121. else
  122. _iPath += *pcElems;
  123. return;
  124. }
  125. }
  126. void Push( TCHAR *ptszPath, unsigned long cElems )
  127. {
  128. TrkAssert( !TEXT("CGetPathPipeCallback::push shouldn't be called") );
  129. return;
  130. }
  131. void Alloc( unsigned long cbRequested, TCHAR **pptszPath, unsigned long * pcbActual )
  132. {
  133. if( cbRequested > sizeof(_tszBuffer) )
  134. *pcbActual = sizeof(_tszBuffer);
  135. else
  136. *pcbActual = cbRequested;
  137. *pptszPath = _tszBuffer;
  138. return;
  139. }
  140. private:
  141. TCHAR _tszPath[ MAX_PATH + 1 ]; // BUGBUG P2: Path
  142. TCHAR _tszBuffer[ MAX_PATH + 1 ];
  143. LONG _iPath;
  144. ULONG _cchPath;
  145. };
  146. class CPCVolumeStatus : public PVolInfoPipeCallback
  147. {
  148. public:
  149. CPCVolumeStatus( CVolumeTable *pvoltab ) : _fInitialized(FALSE), _pvoltab(pvoltab) {};
  150. public:
  151. void Initialize( CMachineId *pmcid, VARIANT *pvarlongVolIndex, VARIANT *pvarbstrVolId, VARIANT *pvarlongStatus );
  152. void UnInitialize();
  153. void Pull( TRK_VOLUME_TRACKING_INFORMATION *pVolInfo, unsigned long cbBuffer, unsigned long * pcElems )
  154. {
  155. TrkAssert( !TEXT("CPCVolumeStatus should not be pulled") );
  156. *pcElems = 0;
  157. return;
  158. }
  159. void Push( TRK_VOLUME_TRACKING_INFORMATION *pVolInfo, unsigned long cElems );
  160. public:
  161. HRESULT GetHResult()
  162. {
  163. return( _hr );
  164. }
  165. void Compact();
  166. private:
  167. HRESULT _hr;
  168. BOOL _fInitialized;
  169. CMachineId *_pmcid;
  170. CVolumeTable *_pvoltab;
  171. VARIANT *_pvarlongVolIndex;
  172. VARIANT *_pvarbstrVolId;
  173. VARIANT *_pvarlongStatus;
  174. SAFEARRAYBOUND _sabound;
  175. LONG _iArrays;
  176. };
  177. class CPCVolumes : public PVolInfoPipeCallback
  178. {
  179. public:
  180. CPCVolumes( CMachineId *pmcid,
  181. CVolumeTable *pvoltab,
  182. CRefreshSequenceStorage *pRefreshSequenceStorage ) :
  183. _pmcid(pmcid),
  184. _pvoltab(pvoltab),
  185. _pRefreshSequenceStorage(pRefreshSequenceStorage)
  186. {
  187. _cVolIds = 0;
  188. _hr = S_OK;
  189. };
  190. public:
  191. void Pull( TRK_VOLUME_TRACKING_INFORMATION *pVolInfo, unsigned long cbBuffer, unsigned long * pcElems )
  192. {
  193. TrkAssert( !TEXT("CPCVolumes should not be pulled") );
  194. *pcElems = 0;
  195. return;
  196. }
  197. void Push( TRK_VOLUME_TRACKING_INFORMATION *pVolInfo, unsigned long cElems );
  198. public:
  199. HRESULT GetHResult()
  200. {
  201. return( _hr );
  202. }
  203. ULONG Count()
  204. {
  205. return( _cVolIds );
  206. }
  207. CVolumeId * GetVolIds()
  208. {
  209. return( _rgvolid );
  210. }
  211. private:
  212. HRESULT _hr;
  213. CMachineId *_pmcid;
  214. CVolumeTable *_pvoltab;
  215. CRefreshSequenceStorage *_pRefreshSequenceStorage;
  216. ULONG _cVolIds;
  217. CVolumeId _rgvolid[ NUM_VOLUMES ]; // BUGBUG: Fixed # volumes
  218. };
  219. class CPCFileStatus : public PFileInfoPipeCallback
  220. {
  221. public:
  222. CPCFileStatus( CIntraDomainTable *pidt ) : _fInitialized(FALSE), _pidt(pidt) {};
  223. public:
  224. void Initialize( CMachineId *pmcid, VARIANT *pvarrgbstrFileName, VARIANT *pvarrgbstrFileId, VARIANT *pvarrglongStatus );
  225. void UnInitialize()
  226. {
  227. // Nothing to do, the Variants are cleaned by the caller
  228. return;
  229. }
  230. void Pull( TRK_FILE_TRACKING_INFORMATION *pFileInfo, unsigned long cbBuffer, unsigned long * pcElems )
  231. {
  232. TrkAssert( !TEXT("CPCFileStatus should not be pulled") );
  233. *pcElems = 0;
  234. return;
  235. }
  236. void Push( TRK_FILE_TRACKING_INFORMATION *pFileInfo, unsigned long cElems );
  237. public:
  238. HRESULT GetHResult()
  239. {
  240. return( _hr );
  241. }
  242. void Compact();
  243. private:
  244. HRESULT _hr;
  245. BOOL _fInitialized;
  246. CMachineId *_pmcid;
  247. CIntraDomainTable
  248. *_pidt;
  249. VARIANT *_pvarrgbstrFileName;
  250. VARIANT *_pvarrgbstrFileId;
  251. VARIANT *_pvarrglongStatus;
  252. SAFEARRAYBOUND _sabound;
  253. long _iArrays;
  254. };
  255. class CPCFiles : public PFileInfoPipeCallback
  256. {
  257. public:
  258. CPCFiles( CIntraDomainTable *pidt )
  259. {
  260. _pidt = pidt;
  261. }
  262. public:
  263. void Pull( TRK_FILE_TRACKING_INFORMATION *pVolInfo, unsigned long cbBuffer, unsigned long * pcElems )
  264. {
  265. TrkAssert( !TEXT("CPCFiles should not be pulled") );
  266. *pcElems = 0;
  267. return;
  268. }
  269. void Push( TRK_FILE_TRACKING_INFORMATION *pFileInfo, unsigned long cElems );
  270. private:
  271. CIntraDomainTable *_pidt;
  272. };
  273. #endif //__FRCOWN_H_