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.

784 lines
25 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. Rms.h
  5. Abstract:
  6. Remote Media Service defines
  7. Author:
  8. Brian Dodd [brian] 15-Nov-1996
  9. Revision History:
  10. --*/
  11. #ifndef _RMS_
  12. #define _RMS_
  13. // Are we defining imports or exports?
  14. #ifdef RMSDLL
  15. #define RMSAPI __declspec(dllexport)
  16. #else
  17. #define RMSAPI __declspec(dllimport)
  18. #endif
  19. #include "Wsb.h"
  20. #include "HsmConn.h"
  21. #include "Mover.h"
  22. #include "RmsLib.h"
  23. ////////////////////////////////////////////////////////////////////////////////////////
  24. //
  25. // Rms enumerations
  26. //
  27. /*++
  28. Enumeration Name:
  29. RmsFindBy
  30. Description:
  31. Specifies a type of find to perform using CompareTo.
  32. --*/
  33. typedef enum RmsFindBy {
  34. RmsFindByUnknown, // Unknown (or default) find
  35. RmsFindByCartridgeId, // Find by Cartridge Id.
  36. RmsFindByClassId, // Find by Class Id.
  37. RmsFindByDescription, // Find by Description.
  38. RmsFindByDeviceAddress, // Find by Device Address.
  39. RmsFindByDeviceInfo, // Find by unique device information.
  40. RmsFindByDeviceName, // Find by Device Name.
  41. RmsFindByDeviceType, // Find by Device Type.
  42. RmsFindByDriveClassId, // Find by Drive Class Id.
  43. RmsFindByElementNumber, // Find by Element Number.
  44. RmsFindByExternalLabel, // Find by External Label.
  45. RmsFindByExternalNumber, // Find by External Number.
  46. RmsFindByLibraryId, // Find by Library Id.
  47. RmsFindByLocation, // Find by Location.
  48. RmsFindByMediaSupported, // Find by Media Supported.
  49. RmsFindByMediaType, // Find by Media Type.
  50. RmsFindByScratchMediaCriteria, // Find by Scratch Media Criteria.
  51. RmsFindByName, // Find by Name.
  52. RmsFindByObjectId, // Find by Object Id.
  53. RmsFindByPartitionNumber, // Find by Partition Number.
  54. RmsFindByMediaSetId, // Find by Media Set Id.
  55. RmsFindByRequestNo, // Find by Request Number.
  56. RmsFindBySerialNumber // Find by Serial Number.
  57. };
  58. /*++
  59. Enumeration Name:
  60. RmsObject
  61. Description:
  62. Specifies a type of Rms object.
  63. --*/
  64. typedef enum RmsObject {
  65. RmsObjectUnknown = 0,
  66. RmsObjectCartridge,
  67. RmsObjectClient,
  68. RmsObjectDrive,
  69. RmsObjectDriveClass,
  70. RmsObjectDevice,
  71. RmsObjectIEPort,
  72. RmsObjectLibrary,
  73. RmsObjectMedia,
  74. RmsObjectMediaSet,
  75. RmsObjectNTMS,
  76. RmsObjectPartition,
  77. RmsObjectRequest,
  78. RmsObjectServer,
  79. RmsObjectCartridgeSide,
  80. RmsObjectStorageSlot,
  81. NumberOfRmsObjectTypes
  82. };
  83. /*++
  84. Enumeration Name:
  85. RmsServerState
  86. Description:
  87. Specifies the state of the Rms server object.
  88. --*/
  89. typedef enum RmsServerState {
  90. RmsServerStateUnknown = 0,
  91. RmsServerStateStarting,
  92. RmsServerStateStarted,
  93. RmsServerStateInitializing,
  94. RmsServerStateReady,
  95. RmsServerStateStopping,
  96. RmsServerStateStopped,
  97. RmsServerStateSuspending,
  98. RmsServerStateSuspended,
  99. RmsServerStateResuming,
  100. NumberOfRmsServerStates
  101. };
  102. /*++
  103. Enumeration Name:
  104. RmsNtmsState
  105. Description:
  106. Specifies the state of the Rms NTMS object.
  107. --*/
  108. typedef enum RmsNtmsState {
  109. RmsNtmsStateUnknown = 0,
  110. RmsNtmsStateStarting,
  111. RmsNtmsStateStarted,
  112. RmsNtmsStateInitializing,
  113. RmsNtmsStateReady,
  114. RmsNtmsStateStopping,
  115. RmsNtmsStateStopped,
  116. RmsNtmsStateSuspending,
  117. RmsNtmsStateSuspended,
  118. RmsNtmsStateResuming,
  119. NumberOfRmsNtmsStates
  120. };
  121. /*++
  122. Enumeration Name:
  123. RmsElement
  124. Description:
  125. Specifies a type of cartridge storage location.
  126. --*/
  127. typedef enum RmsElement {
  128. RmsElementUnknown, // Unknown storage location
  129. RmsElementStage, // A storage slot used for staging media.
  130. RmsElementStorage, // A normal storage slot element within a
  131. // library device.
  132. RmsElementShelf, // A local shelf storage element. Alternate
  133. // position specifiers further delineate
  134. // location.
  135. RmsElementOffSite, // An off-site storage element. Alternate
  136. // position specifiers further delineate
  137. // location.
  138. RmsElementDrive, // A data transport element.
  139. RmsElementChanger, // A medium transport element.
  140. RmsElementIEPort // An import/export element.
  141. };
  142. /*++
  143. Enumeration Name:
  144. RmsChanger
  145. Description:
  146. Specifies a type of medium changer.
  147. --*/
  148. typedef enum RmsChanger {
  149. RmsChangerUnknown, // Unknown medium changer.
  150. RmsChangerAutomatic, // A robotic medium changer device.
  151. RmsChangerManual // A human jukebox.
  152. };
  153. /*++
  154. Enumeration Name:
  155. RmsPort
  156. Description:
  157. Specifies a type of import / export element.
  158. --*/
  159. typedef enum RmsPort {
  160. RmsPortUnknown, // port type unknown
  161. RmsPortImport, // The portal can be used to import media
  162. RmsPortExport, // The portal can be used to export media
  163. RmsPortImportExport // The portal is capable of importing and
  164. // exporting media
  165. };
  166. /*++
  167. Enumeration Name:
  168. RmsSlotSelect
  169. Description:
  170. Specifies the slot selection policy.
  171. --*/
  172. typedef enum RmsSlotSelect {
  173. RmsSlotSelectUnknown, // Selection policy unknown.
  174. RmsSlotSelectMinMount, // Select slot that minimizes mount times.
  175. RmsSlotSelectGroup, // Select slot that groups cartridges by
  176. // application.
  177. RmsSlotSelectSortName, // Select slot by sorting cartridges by
  178. // name.
  179. RmsSlotSelectSortBarCode, // Select slot by sorting cartridges by
  180. // bar code label.
  181. RmsSlotSelectSortLabel // Select slot by sorting cartridges by
  182. // their on-media label.
  183. };
  184. /*++
  185. Enumeration Name:
  186. RmsStatus
  187. Description:
  188. Specifies the status for a cartridge.
  189. --*/
  190. typedef enum RmsStatus {
  191. RmsStatusUnknown, // The cartridge is unknown to Rms.
  192. RmsStatusPrivate, // The Cartridge is labeled and owned by an
  193. // application.
  194. RmsStatusScratch, // The Cartridge is blank, unlabeled, can be
  195. // used for scratch media requests from
  196. // any application.
  197. RmsStatusCleaning // The cartridge is a cleaning cartridge.
  198. };
  199. /*++
  200. Enumeration Name:
  201. RmsAttributes
  202. Description:
  203. Specifies the attributes of a cartridge partition.
  204. --*/
  205. typedef enum RmsAttribute {
  206. RmsAttributesUnknown, // Attributes are unknown.
  207. RmsAttributesRead, // Data on the partition can be read by an
  208. // owning application.
  209. RmsAttributesWrite, // Data can be written to the partition by
  210. // an owning application.
  211. RmsAttributesReadWrite, // The partition can be read from and
  212. // written to.
  213. RmsAttributesVerify // The partition can only be mounted to read
  214. // on-media Id or data verification.
  215. };
  216. /*++
  217. Enumeration Name:
  218. RmsDriveSelect
  219. Description:
  220. Specifies the drive selection policy.
  221. --*/
  222. typedef enum RmsDriveSelect {
  223. RmsDriveSelectUnknown, // Drive selection policy unknown.
  224. RmsDriveSelectRandom, // Select drives randomly.
  225. RmsDriveSelectLRU, // Select the least recently used drive.
  226. RmsDriveSelectRoundRobin // Select drives in round robin order.
  227. };
  228. /*++
  229. Enumeration Name:
  230. RmsState
  231. Description:
  232. Specifies the state of an Rms object.
  233. --*/
  234. typedef enum RmsState {
  235. RmsStateUnknown, // State unknown.
  236. RmsStateEnabled, // Normal access to the object is enabled.
  237. RmsStateDisabled, // Normal access to the object is disabled.
  238. RmsStateError // Normal access disabled due to an error
  239. // condition.
  240. };
  241. /*++
  242. Enumeration Name:
  243. RmsMedia
  244. Description:
  245. Specifies the type of RMS media.
  246. --*/
  247. typedef enum RmsMedia {
  248. RmsMediaUnknown = 0, // Media type unknown.
  249. RmsMedia8mm = 0x0001, // 8mm tape.
  250. RmsMedia4mm = 0x0002, // 4mm tape.
  251. RmsMediaDLT = 0x0004, // DLT tape.
  252. RmsMediaOptical = 0x0008, // All types of read-write (rewriteable) optical disks.
  253. RmsMediaMO35 = 0x0010, // 3 1/2 inch magneto-optical. (not used)
  254. RmsMediaWORM = 0x0020, // 5 1/4 inch two-sided write-once optical.
  255. RmsMediaCDR = 0x0040, // 5 1/4 inch compact-disc, recordable.
  256. RmsMediaDVD = 0x0080, // All types of read-write (rewriteable) DVD.
  257. RmsMediaDisk = 0x0100, // Removable hard disk of various formats.
  258. RmsMediaFixed = 0x0200, // Fixed Hard disk.
  259. RmsMediaTape = 0x0400 // Generic tape
  260. };
  261. #define RMSMAXMEDIATYPES 12 // Number of enum's from RmsMedia
  262. /*++
  263. Enumeration Name:
  264. RmsDevice
  265. Description:
  266. Specifies a type of RMS supported device.
  267. --*/
  268. typedef enum RmsDevice {
  269. RmsDeviceUnknown, // unknown device type.
  270. RmsDeviceFixedDisk, // Direct access fixed disk.
  271. RmsDeviceRemovableDisk, // Direct access removable disk.
  272. RmsDeviceTape, // Sequential access tape.
  273. RmsDeviceCDROM, // Read only, CDROM.
  274. RmsDeviceWORM, // Write once, WORM.
  275. RmsDeviceOptical, // Optical memory/disk.
  276. RmsDeviceChanger // MediumChanger.
  277. };
  278. /*++
  279. Enumeration Name:
  280. RmsMode
  281. Description:
  282. Specifies the access mode supported by a drive or specified when
  283. mounting a Cartridge.
  284. --*/
  285. typedef enum RmsMode {
  286. RmsModeUnknown, // access mode supported unknown.
  287. RmsModeRead, // Read operations.
  288. RmsModeReadWrite, // Read or write operations.
  289. RmsModeWriteOnly // Write only operations.
  290. };
  291. /*++
  292. Enumeration Name:
  293. RmsMediaSet
  294. Description:
  295. Specifies the type of a Media Set.
  296. --*/
  297. typedef enum RmsMediaSet {
  298. RmsMediaSetUnknown = 1300, // Unknown.
  299. RmsMediaSetFolder, // Contains for other media sets.
  300. RmsMediaSetLibrary, // Cartridges in the media set are accessible via
  301. // robotic device.
  302. RmsMediaSetShelf, // Cartridges are shelved locally, and
  303. // accessible via human intervention.
  304. RmsMediaSetOffSite, // Cartridges are stored at an off-site
  305. // location, and are not directly
  306. // accessible for mounting.
  307. RmsMediaSetNTMS, // Cartridges are accessible through NTMS.
  308. RmsMediaSetLAST
  309. };
  310. /*++
  311. Enumeration Name:
  312. RmsMediaManager
  313. Description:
  314. Specifies the media manager that controls a resource.
  315. --*/
  316. typedef enum RmsMediaManager {
  317. RmsMediaManagerUnknown = 1400, // Unknown.
  318. RmsMediaManagerNative, // Resource managed by RMS (native).
  319. RmsMediaManagerNTMS, // Resource managed by NTMS.
  320. RmsMediaManagerLAST
  321. };
  322. /*++
  323. Enumeration Name:
  324. RmsCreate
  325. Description:
  326. Specifies the create disposition for objects.
  327. --*/
  328. typedef enum RmsCreate {
  329. RmsCreateUnknown,
  330. RmsOpenExisting, // Opens an existing object.
  331. RmsOpenAlways, // Opens an existing object, or creates a new one.
  332. RmsCreateNew // Creates a new object if it doesn't exists.
  333. };
  334. /*++
  335. Enumeration Name:
  336. RmsOnMediaIdentifier
  337. Description:
  338. Specifies the type on media identifier.
  339. --*/
  340. typedef enum RmsOnMediaIdentifier {
  341. RmsOnMediaIdentifierUnknown,
  342. RmsOnMediaIdentifierMTF, // MTF Media Identifier
  343. RmsOnMediaIdentifierWIN32 // WIN32 Filesystem Identifier
  344. };
  345. ////////////////////////////////////////////////////////////////////////////////////////
  346. //
  347. // Rms structs
  348. //
  349. /*++
  350. Structure Name:
  351. RMS_FILESYSTEM_INFO
  352. Description:
  353. Structure used to specify on media file system information.
  354. NOTE: This is a dup of the NTMS_FILESYSTEM_INFO struct.
  355. --*/
  356. typedef struct _RMS_FILESYSTEM_INFO {
  357. WCHAR FileSystemType[64];
  358. WCHAR VolumeName[256];
  359. DWORD SerialNumber;
  360. } RMS_FILESYSTEM_INFO, *LP_RMS_FILESYSTEM_INFO;
  361. ////////////////////////////////////////////////////////////////////////////////////////
  362. //
  363. // Rms defines
  364. //
  365. #define RMS_DUPLICATE_RECYCLEONERROR 0x00010000 // DuplicateCartridge option used to
  366. // recyle a new cartridge if an error occurs.
  367. #define RMS_STR_MAX_CARTRIDGE_INFO 128 // Max string len for Cartridge info
  368. #define RMS_STR_MAX_CARTRIDGE_NAME 64 // Max string len for Cartridge Name
  369. #define RMS_STR_MAX_EXTERNAL_LABEL 32 // Max string len for External Label
  370. #define RMS_STR_MAX_MAIL_STOP 64 // Max string len for Mail Stop
  371. #define RMS_STR_MAX_LENGTH 128 // Max string length of any string
  372. //
  373. // Inquiry defines. Used to interpret data returned from target as result
  374. // of inquiry command.
  375. //
  376. // DeviceType field
  377. //
  378. #define DIRECT_ACCESS_DEVICE 0x00 // disks
  379. #define SEQUENTIAL_ACCESS_DEVICE 0x01 // tapes
  380. #define PRINTER_DEVICE 0x02 // printers
  381. #define PROCESSOR_DEVICE 0x03 // scanners, printers, etc
  382. #define WRITE_ONCE_READ_MULTIPLE_DEVICE 0x04 // worms
  383. #define READ_ONLY_DIRECT_ACCESS_DEVICE 0x05 // cdroms
  384. #define SCANNER_DEVICE 0x06 // scanners
  385. #define OPTICAL_DEVICE 0x07 // optical disks
  386. #define MEDIUM_CHANGER 0x08 // jukebox
  387. #define COMMUNICATION_DEVICE 0x09 // network
  388. //
  389. // Default object names
  390. //
  391. #define RMS_DEFAULT_FIXEDDRIVE_LIBRARY_NAME OLESTR("Fixed Drive Library")
  392. #define RMS_DEFAULT_FIXEDDRIVE_MEDIASET_NAME OLESTR("Fixed Drive Media (Testing Only !!)")
  393. #define RMS_DEFAULT_OPTICAL_LIBRARY_NAME OLESTR("Optical Library")
  394. #define RMS_DEFAULT_OPTICAL_MEDIASET_NAME OLESTR("Optical Media")
  395. #define RMS_DEFAULT_TAPE_LIBRARY_NAME OLESTR("Tape Library")
  396. #define RMS_DEFAULT_TAPE_MEDIASET_NAME OLESTR("Tape Media")
  397. #define RMS_UNDEFINED_STRING OLESTR("Uninitialized String")
  398. #define RMS_NULL_STRING OLESTR("")
  399. #define RMS_DIR_LEN 256
  400. #define RMS_TRACE_FILE_NAME OLESTR("rms.trc")
  401. #define RMS_NTMS_REGISTRY_STRING OLESTR("SYSTEM\\CurrentControlSet\\Services\\NtmsSvc")
  402. // Currently, RMS Registry location points to same location of Engine parameters
  403. // keeping this literal enables moving RMS parameters to another key easily.
  404. #define RMS_REGISTRY_STRING OLESTR("SYSTEM\\CurrentControlSet\\Services\\Remote_Storage_Server\\Parameters")
  405. // Registry parameters (all parameters are string values in the registry)
  406. #define RMS_PARAMETER_HARD_DRIVES_TO_USE OLESTR("HardDrivesToUse") // "ABCDEFG", if "" defaults to any volume with "RS", "RemoteStor", "Remote Stor"
  407. #define RMS_PARAMETER_NTMS_SUPPORT OLESTR("NTMSSupport") // 1 | 0
  408. #define RMS_PARAMETER_NEW_STYLE_IO OLESTR("NewStyleIo") // 1 | 0
  409. #define RMS_PARAMETER_BLOCK_SIZE OLESTR("BlockSize") // Must be mod 512
  410. #define RMS_PARAMETER_BUFFER_SIZE OLESTR("BufferSize") // Must be mod 512
  411. #define RMS_PARAMETER_COPY_BUFFER_SIZE OLESTR("MediaCopyBufferSize") // Buffer size for media copy on FS-media like optical
  412. #define RMS_PARAMETER_FORMAT_COMMAND OLESTR("FormatCommand") // Full pathname specifier to format command
  413. #define RMS_PARAMETER_FORMAT_OPTIONS OLESTR("FormatOptions") // Format command options
  414. #define RMS_PARAMETER_FORMAT_OPTIONS_ALT1 OLESTR("FormatOptionsAlt1") // Format command options - alternate
  415. #define RMS_PARAMETER_FORMAT_OPTIONS_ALT2 OLESTR("FormatOptionsAlt2") // Format command options - second alternate
  416. #define RMS_PARAMETER_FORMAT_WAIT_TIME OLESTR("FormatWaitTime") // Format time-out interval, in milliseconds
  417. #define RMS_PARAMETER_TAPE OLESTR("Tape") // 1 | 0
  418. #define RMS_PARAMETER_OPTICAL OLESTR("Optical") // 1 | 0
  419. #define RMS_PARAMETER_FIXED_DRIVE OLESTR("FixedDrive") // 1 | 0
  420. #define RMS_PARAMETER_DVD OLESTR("DVD") // 1 | 0
  421. #define RMS_PARAMETER_ADDITIONAL_TAPE OLESTR("TapeTypesToSupport") // Additional media types to support (REG_MULTI_SZ)
  422. #define RMS_PARAMETER_DEFAULT_MEDIASET OLESTR("DefaultMediaSet") // The name of the media set to use for unspecified scratch media requests.
  423. #define RMS_PARAMETER_MEDIA_TYPES_TO_EXCLUDE OLESTR("MediaTypesToExclude") // A delimited list of media types to exclude. First char is delimiter.
  424. #define RMS_PARAMETER_NOTIFICATION_WAIT_TIME OLESTR("NotificationWaitTime") // Milliseconds to wait for an object notification
  425. #define RMS_PARAMETER_ALLOCATE_WAIT_TIME OLESTR("AllocateWaitTime") // Milliseconds to wait for a media allocation
  426. #define RMS_PARAMETER_MOUNT_WAIT_TIME OLESTR("MountWaitTime") // Milliseconds to wait for a mount
  427. #define RMS_PARAMETER_REQUEST_WAIT_TIME OLESTR("RequestWaitTime") // Milliseconds to wait for a request
  428. #define RMS_PARAMETER_DISMOUNT_WAIT_TIME OLESTR("DismountWaitTime") // Milliseconds to wait before dismount
  429. #define RMS_PARAMETER_AFTER_DISMOUNT_WAIT_TIME OLESTR("AfterDismountWaitTime") // Milliseconds to wait after dismount
  430. #define RMS_PARAMETER_SHORT_WAIT_TIME OLESTR("ShortWaitTime") // Milliseconds when asked to wait for short periods
  431. #define RMS_PARAMETER_MEDIA_COPY_TOLERANCE OLESTR("MediaCopyTolerance") // Percent copy media can be shorter than original
  432. // Default parameter values
  433. #define RMS_DEFAULT_HARD_DRIVES_TO_USE OLESTR("")
  434. #define RMS_DEFAULT_NTMS_SUPPORT TRUE
  435. #define RMS_DEFAULT_NEW_STYLE_IO TRUE
  436. #define RMS_DEFAULT_BLOCK_SIZE 1024
  437. #define RMS_DEFAULT_BUFFER_SIZE (64*1024)
  438. #define RMS_DEFAULT_FORMAT_COMMAND OLESTR("%SystemRoot%\\System32\\format.com")
  439. #define RMS_DEFAULT_FORMAT_OPTIONS OLESTR("/fs:ntfs /force /q /x")
  440. #define RMS_DEFAULT_FORMAT_OPTIONS_ALT1 OLESTR("/fs:ntfs /force /x")
  441. #define RMS_DEFAULT_FORMAT_OPTIONS_ALT2 OLESTR("")
  442. #define RMS_DEFAULT_FORMAT_WAIT_TIME (20*60*1000)
  443. #define RMS_DEFAULT_TAPE TRUE
  444. #define RMS_DEFAULT_OPTICAL TRUE
  445. #define RMS_DEFAULT_FIXED_DRIVE FALSE
  446. #define RMS_DEFAULT_DVD FALSE
  447. #define RMS_DEFAULT_MEDIASET OLESTR("")
  448. #define RMS_DEFAULT_MEDIA_TYPES_TO_EXCLUDE OLESTR("")
  449. #define RMS_DEFAULT_NOTIFICATION_WAIT_TIME (10000)
  450. #define RMS_DEFAULT_ALLOCATE_WAIT_TIME (3600000)
  451. #define RMS_DEFAULT_MOUNT_WAIT_TIME (14400000)
  452. #define RMS_DEFAULT_REQUEST_WAIT_TIME (3600000)
  453. #define RMS_DEFAULT_DISMOUNT_WAIT_TIME (5000)
  454. #define RMS_DEFAULT_AFTER_DISMOUNT_WAIT_TIME (1000)
  455. #define RMS_DEFAULT_SHORT_WAIT_TIME (1800000)
  456. #define RMS_DEFAULT_MEDIA_COPY_TOLERANCE (2) // Percent copy media can be shorter than original
  457. #define RMS_DEFAULT_DATA_BASE_FILE_NAME OLESTR("RsSub.col")
  458. #define RMS_NTMS_ROOT_MEDIA_POOL_NAME OLESTR("Remote Storage")
  459. #define RMS_NTMS_OBJECT_NAME OLESTR("NTMS")
  460. #define RMS_NTMS_OBJECT_DESCRIPTION OLESTR("NT Media Services")
  461. // RMS media status
  462. #define RMS_MEDIA_ENABLED 0x00000001
  463. #define RMS_MEDIA_ONLINE 0x00000002
  464. #define RMS_MEDIA_AVAILABLE 0x00000004
  465. // RMS Options - Flags literal
  466. // Keep the default for each flag value as zero, i.e. RM_NONE should always be the
  467. // default mask for all methods
  468. #define RMS_NONE 0x0
  469. #define RMS_MOUNT_NO_BLOCK 0x00000001
  470. #define RMS_DISMOUNT_IMMEDIATE 0x00000002
  471. #define RMS_SHORT_TIMEOUT 0x00000004
  472. #define RMS_DISMOUNT_DEFERRED_ONLY 0x00000008
  473. #define RMS_ALLOCATE_NO_BLOCK 0x00000010
  474. #define RMS_USE_MOUNT_NO_DEADLOCK 0x00000020
  475. #define RMS_SERIALIZE_MOUNT 0x00000040
  476. //
  477. // CRmsSink helper class
  478. //
  479. class CRmsSink :
  480. public IRmsSinkEveryEvent,
  481. public CComObjectRoot
  482. {
  483. public:
  484. // constructor/destructor
  485. CRmsSink(void) {};
  486. BEGIN_COM_MAP(CRmsSink)
  487. COM_INTERFACE_ENTRY(IRmsSinkEveryEvent)
  488. END_COM_MAP()
  489. HRESULT FinalConstruct( void ) {
  490. HRESULT hr = S_OK;
  491. try {
  492. m_Cookie = 0;
  493. m_hReady = 0;
  494. WsbAffirmHr( CComObjectRoot::FinalConstruct( ) );
  495. } WsbCatch( hr );
  496. return hr;
  497. }
  498. void FinalRelease( void ) {
  499. DoUnadvise( );
  500. CComObjectRoot::FinalRelease( );
  501. }
  502. public:
  503. STDMETHOD( ProcessObjectStatusChange ) ( IN BOOL isEnabled, IN LONG state, IN HRESULT statusCode ) {
  504. HRESULT hr = S_OK;
  505. UNREFERENCED_PARAMETER(statusCode);
  506. if( isEnabled ) {
  507. switch( state ) {
  508. case RmsServerStateStarting:
  509. case RmsServerStateStarted:
  510. case RmsServerStateInitializing:
  511. break;
  512. default:
  513. SetEvent( m_hReady );
  514. }
  515. } else {
  516. SetEvent( m_hReady );
  517. }
  518. return hr;
  519. }
  520. HRESULT Construct( IN IUnknown * pUnk ) {
  521. HRESULT hr = S_OK;
  522. try {
  523. WsbAffirmHr( FinalConstruct( ) );
  524. WsbAffirmHr( DoAdvise( pUnk ) );
  525. } WsbCatch( hr );
  526. return hr;
  527. }
  528. HRESULT DoAdvise( IN IUnknown * pUnk ) {
  529. HRESULT hr = S_OK;
  530. try {
  531. #define RmsQueryInterface( pUnk, interf, pNew ) (pUnk)->QueryInterface( IID_##interf, (void**) static_cast<interf **>( &pNew ) )
  532. WsbAffirmHr( RmsQueryInterface( pUnk, IRmsServer, m_pRms ) );
  533. #if 0
  534. WCHAR buf[100];
  535. static int count = 0;
  536. swprintf( buf, L"CRmsSinkEvent%d", count++ );
  537. #else
  538. WCHAR* buf = 0;
  539. #endif
  540. m_hReady = CreateEvent( 0, TRUE, FALSE, buf );
  541. WsbAffirmStatus( ( 0 != m_hReady ) );
  542. WsbAffirmHr( AtlAdvise( pUnk, (IUnknown*)(IRmsSinkEveryEvent*)this, IID_IRmsSinkEveryEvent, &m_Cookie ) );
  543. } WsbCatch( hr );
  544. return hr;
  545. }
  546. HRESULT DoUnadvise( void ) {
  547. HRESULT hr = S_OK;
  548. if( m_hReady ) {
  549. CloseHandle( m_hReady );
  550. m_hReady = 0;
  551. }
  552. if( m_Cookie ) {
  553. hr = AtlUnadvise( m_pRms, IID_IRmsSinkEveryEvent, m_Cookie );
  554. m_Cookie = 0;
  555. }
  556. return hr;
  557. }
  558. HRESULT WaitForReady( void ) {
  559. HRESULT hr = S_OK;
  560. try {
  561. DWORD waitResult;
  562. HRESULT hrReady = m_pRms->IsReady( );
  563. switch( hrReady ) {
  564. case RMS_E_NOT_READY_SERVER_STARTING:
  565. case RMS_E_NOT_READY_SERVER_STARTED:
  566. case RMS_E_NOT_READY_SERVER_INITIALIZING:
  567. case RMS_E_NOT_READY_SERVER_LOCKED:
  568. //
  569. // We must wait, but the message queue must be pumped so that
  570. // the COM Apartment model calls can be made in (like the
  571. // call into the connection point)
  572. //
  573. while( TRUE ) {
  574. waitResult = MsgWaitForMultipleObjects( 1, &m_hReady, FALSE, INFINITE, QS_ALLINPUT );
  575. if( WAIT_OBJECT_0 == waitResult ) {
  576. break;
  577. } else {
  578. MSG msg;
  579. while( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) ) {
  580. DispatchMessage( &msg );
  581. }
  582. }
  583. };
  584. WsbAffirmHr( m_pRms->IsReady( ) );
  585. break;
  586. case S_OK:
  587. break;
  588. default:
  589. WsbThrow( hrReady );
  590. }
  591. } WsbCatch( hr );
  592. return hr;
  593. }
  594. private:
  595. CComPtr<IRmsServer> m_pRms;
  596. DWORD m_Cookie;
  597. HANDLE m_hReady;
  598. };
  599. #endif // _RMS_