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.

141 lines
4.4 KiB

  1. /******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1999
  4. *
  5. * TITLE: LockMgr.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ByronC
  10. *
  11. * DATE: 15 November, 1999
  12. *
  13. * DESCRIPTION:
  14. * Definition of Lock Manager Class.
  15. *
  16. ******************************************************************************/
  17. #pragma once
  18. #ifndef _LOCKMGR_H_
  19. #define _LOCKMGR_H_
  20. #define WIA_LOCK_WAIT_TIME 60000
  21. class StiLockMgr; // defined later in this file
  22. //
  23. // Lock information stored per device
  24. //
  25. typedef struct _LockInfo {
  26. HANDLE hDeviceIsFree; // Auto-Reset event object used to signal
  27. // when device is free.
  28. BOOL bDeviceIsLocked; // Indicates whether device is currently
  29. // locked.
  30. LONG lInUse; // Indicates whether the device is actually
  31. // in use i.e. we are in the middle of a
  32. // request (e.g. a data transfer).
  33. DWORD dwThreadId; // The Id of the Thread which has device
  34. // locked.
  35. LONG lHoldingTime; // The amount of idle time (milliseconds)
  36. // to keep hold of lock.
  37. LONG lTimeLeft; // The amount of idle time remaining.
  38. } LockInfo, *PLockInfo;
  39. //
  40. // Info struct used during enumeration callbacks
  41. //
  42. typedef struct _EnumContext {
  43. StiLockMgr *This; // Pointer to the Lock Manager that
  44. // requested the enumeration
  45. LONG lShortestWaitTime; // Value indicating the shortest wait time
  46. // till next unlock.
  47. BOOL bMustSchedule; // Indicates whether the unlock callback
  48. // must be scheduled.
  49. } EnumContext, *PEnumContext;
  50. //
  51. // Class definition for the lock manager. It is used by both STI and WIA.
  52. //
  53. class StiLockMgr : IUnknown {
  54. public:
  55. //
  56. // Constructor, Initialize, Destructor
  57. //
  58. StiLockMgr();
  59. HRESULT Initialize();
  60. ~StiLockMgr();
  61. //
  62. // IUnknown methods
  63. //
  64. HRESULT _stdcall QueryInterface(const IID& iid, void** ppv);
  65. ULONG _stdcall AddRef(void);
  66. ULONG _stdcall Release(void);
  67. //
  68. // Lock/Unlock Request methods
  69. //
  70. HRESULT _stdcall RequestLock(BSTR pszDeviceName, ULONG ulTimeout, BOOL bInServerProcess, DWORD dwClientThreadId);
  71. HRESULT _stdcall RequestLock(ACTIVE_DEVICE *pDevice, ULONG ulTimeOut, BOOL bOpenPort = TRUE);
  72. HRESULT _stdcall RequestUnlock(BSTR pszDeviceName, BOOL bInServerProcess, DWORD dwClientThreadId);
  73. HRESULT _stdcall RequestUnlock(ACTIVE_DEVICE *pDevice, BOOL bClosePort = TRUE);
  74. HRESULT _stdcall LockDevice(ACTIVE_DEVICE *pDevice);
  75. HRESULT _stdcall UnlockDevice(ACTIVE_DEVICE *pDevice);
  76. VOID AutoUnlock();
  77. VOID UpdateLockInfoStatus(ACTIVE_DEVICE *pDevice, LONG *pWaitTime, BOOL *pbMustSchedule);
  78. HRESULT ClearLockInfo(LockInfo *pLockInfo);
  79. private:
  80. //
  81. // Private helpers
  82. //
  83. HRESULT RequestLockHelper(ACTIVE_DEVICE *pDevice, ULONG ulTimeOut, BOOL bInServerProcess, DWORD dwClientThreadId);
  84. HRESULT RequestUnlockHelper(ACTIVE_DEVICE *pDevice, BOOL bInServerProcess, DWORD dwClientThreadId);
  85. HRESULT CreateLockInfo(ACTIVE_DEVICE *pDevice);
  86. HRESULT CheckDeviceInfo(ACTIVE_DEVICE *pDevice);
  87. #ifdef USE_ROT
  88. HRESULT WriteCookieNameToRegistry(CHAR *szCookieName);
  89. VOID DeleteCookieFromRegistry();
  90. #endif
  91. //
  92. // Private Data
  93. //
  94. LONG m_cRef; // Ref count
  95. DWORD m_dwCookie; // Cookie identifying location in ROT
  96. BOOL m_bSched; // Indicates whether the UnlockCallback has
  97. // been scheduled
  98. LONG m_lSchedWaitTime; // Amount of time we told Scheduler to wait
  99. // before calling us back
  100. };
  101. #ifdef DECLARE_LOCKMGR
  102. StiLockMgr *g_pStiLockMgr;
  103. #else
  104. extern StiLockMgr *g_pStiLockMgr;
  105. #endif
  106. //
  107. // Callback functions
  108. //
  109. VOID WINAPI UnlockTimedCallback(VOID *pCallbackInfo);
  110. VOID WINAPI EnumDeviceCallback(ACTIVE_DEVICE *pDevice, VOID *pContext);
  111. #endif