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.

129 lines
4.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: sharecnx.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _WINDOWS_
  11. # include <windows.h>
  12. #endif
  13. #ifndef _INC_COMMCTRL_
  14. # include <commctrl.h>
  15. #endif
  16. #ifndef _INC_COMCTRLP
  17. # include <comctrlp.h>
  18. #endif
  19. class CShareCnxStatusCache
  20. {
  21. public:
  22. CShareCnxStatusCache(void);
  23. ~CShareCnxStatusCache(void);
  24. HRESULT IsOpenConnectionShare(LPCTSTR pszShare, bool bRefresh = false);
  25. HRESULT IsOpenConnectionPathUNC(LPCTSTR pszPathUNC, bool bRefresh = false);
  26. private:
  27. class Entry
  28. {
  29. public:
  30. enum { StatusOpenCnx = 0x00000001 }; // 1 == Open connection.
  31. explicit Entry(LPCTSTR pszShare, DWORD dwStatus = 0);
  32. ~Entry(void);
  33. //
  34. // Refresh cached data in m_dwStatus member.
  35. //
  36. HRESULT Refresh(void);
  37. //
  38. // Returns the status DWORD.
  39. //
  40. DWORD Status(void) const
  41. { return m_dwStatus; }
  42. //
  43. // Returns true if requested status bits are set.
  44. //
  45. bool CheckStatus(DWORD dwMask) const
  46. { return boolify(dwMask == (m_dwStatus & dwMask)); }
  47. //
  48. // Returns error bits from m_dwStatus member.
  49. //
  50. HRESULT LastResult(void) const
  51. { return m_hrLastResult; }
  52. //
  53. // Returns address of share name. Can be NULL.
  54. //
  55. LPCTSTR Share(void) const
  56. { return m_pszShare; }
  57. //
  58. // Returns true if share name ptr is non-null and all error
  59. // bits in m_dwStatus member are clear.
  60. //
  61. bool IsValid(void) const
  62. { return NULL != Share() && SUCCEEDED(m_hrLastResult); }
  63. //
  64. // Static function for obtaining share's system status. Result goes
  65. // in m_dwStatus member. Static so that creator of an Entry object
  66. // can use the status value in the Entry ctor.
  67. //
  68. static HRESULT QueryShareStatus(LPCTSTR pszShare, DWORD *pdwStatus);
  69. private:
  70. LPTSTR m_pszShare; // Name of the share associated with entry.
  71. DWORD m_dwStatus; // Share status and error bits.
  72. DWORD m_hrLastResult; // Last query result.
  73. //
  74. // Prevent copy.
  75. //
  76. Entry(const Entry& rhs);
  77. Entry& operator = (const Entry& rhs);
  78. //
  79. // We don't want folks creating blank entries.
  80. // The error reporting structure assumes that a NULL
  81. // m_pszShare member indicates an allocation failure.
  82. //
  83. Entry(void)
  84. : m_pszShare(NULL),
  85. m_dwStatus(0),
  86. m_hrLastResult(E_FAIL) { }
  87. };
  88. HDPA m_hdpa; // Dynamic array of Entry object ptrs.
  89. //
  90. // Number of entries in cache.
  91. //
  92. int Count(void) const;
  93. //
  94. // Add an entry to the cache.
  95. //
  96. Entry *AddEntry(LPCTSTR pszShare, DWORD dwStatus);
  97. //
  98. // Find an entry in the cache.
  99. //
  100. Entry *FindEntry(LPCTSTR pszShare) const;
  101. //
  102. // Retrieve a given entry at a given DPA index.
  103. //
  104. Entry *GetEntry(int iEntry) const
  105. { return (Entry *)DPA_GetPtr(m_hdpa, iEntry); }
  106. //
  107. // Same as GetEntry but won't AV if m_hdpa is NULL.
  108. //
  109. Entry *SafeGetEntry(int iEntry) const
  110. { return NULL != m_hdpa ? GetEntry(iEntry) : NULL; }
  111. //
  112. // Get the status information for a share.
  113. //
  114. HRESULT GetShareStatus(LPCTSTR pszShare, DWORD *pdwStatus, bool bRefresh);
  115. //
  116. // Prevent copy.
  117. //
  118. CShareCnxStatusCache(const CShareCnxStatusCache& rhs);
  119. CShareCnxStatusCache& operator = (const CShareCnxStatusCache& rhs);
  120. };