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.

369 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: C O N N L I S T . H
  7. //
  8. // Contents: Connection list class -- subclass of the stl list<> code.
  9. //
  10. // Notes:
  11. //
  12. // Author: jeffspr 19 Feb 1998
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #ifndef _CONNLIST_H_
  17. #define _CONNLIST_H_
  18. // Icon ID to use for a connection that doesn't have a tray entry
  19. //
  20. #define BOGUS_TRAY_ICON_ID (UINT) -1
  21. // #define VERYSTRICTCOMPILE
  22. #ifdef VERYSTRICTCOMPILE
  23. #define CONST_IFSTRICT const
  24. #else
  25. #define CONST_IFSTRICT
  26. #endif
  27. typedef HRESULT FNBALLOONCLICK(IN const GUID * pGUIDConn,
  28. IN const BSTR pszConnectionName,
  29. IN const BSTR szCookie);
  30. typedef enum tagConnListEntryStateFlags
  31. {
  32. CLEF_NONE = 0x0000, // No special characteristics
  33. CLEF_ACTIVATING = 0x0001, // In the process of connecting
  34. CLEF_TRAY_ICON_LOCKED = 0x0002 // Tray icon state is being updated
  35. } CONNLISTENTRYFLAGS;
  36. // Define our structure that will be stored in the list<>
  37. //
  38. class CTrayIconData
  39. {
  40. private:
  41. CTrayIconData* operator &() throw();
  42. CTrayIconData& operator =(IN const CTrayIconData&) throw();
  43. public:
  44. explicit CTrayIconData(IN const CTrayIconData &) throw();
  45. CTrayIconData(IN UINT uiTrayIconId,
  46. IN NETCON_STATUS ncs,
  47. IN IConnectionPoint * pcpStat,
  48. IN INetStatisticsEngine * pnseStats,
  49. IN CConnectionTrayStats * pccts) throw();
  50. //private:
  51. ~CTrayIconData() throw();
  52. public:
  53. inline const UINT GetTrayIconId() const throw(){ return m_uiTrayIconId; }
  54. inline const NETCON_STATUS GetConnected() const throw() { return m_ncs; }
  55. inline CONST_IFSTRICT INetStatisticsEngine * GetNetStatisticsEngine() throw() { return m_pnseStats; }
  56. inline CONST_IFSTRICT CConnectionTrayStats * GetConnectionTrayStats() throw() { return m_pccts; }
  57. inline CONST_IFSTRICT IConnectionPoint * GetConnectionPoint() throw() { return m_pcpStat; }
  58. inline const DWORD GetLastBalloonMessage() throw() { return m_dwLastBalloonMessage; }
  59. inline FNBALLOONCLICK* GetLastBalloonFunction() throw() { return m_pfnBalloonFunction; }
  60. inline const BSTR GetLastBalloonCookie() throw() { return m_szCookie; }
  61. HRESULT SetBalloonInfo(DWORD dwLastBalloonMessage, BSTR szCookie, FNBALLOONCLICK* pfnBalloonFunction);
  62. private:
  63. UINT m_uiTrayIconId;
  64. NETCON_STATUS m_ncs;
  65. IConnectionPoint * m_pcpStat;
  66. INetStatisticsEngine * m_pnseStats;
  67. CONST_IFSTRICT CConnectionTrayStats * m_pccts;
  68. DWORD m_dwLastBalloonMessage;
  69. BSTR m_szCookie;
  70. FNBALLOONCLICK * m_pfnBalloonFunction;
  71. };
  72. // typedef TRAYICONDATA * PTRAYICONDATA;
  73. // typedef const TRAYICONDATA * PCTRAYICONDATA;
  74. class ConnListEntry
  75. {
  76. public:
  77. ConnListEntry& operator =(IN const ConnListEntry& ConnectionListEntry) throw();
  78. explicit ConnListEntry(IN const ConnListEntry& ConnectionListEntry) throw();
  79. ConnListEntry() throw();
  80. ~ConnListEntry() throw();
  81. DWORD dwState; // bitmask of CONNLISTENTRYFLAGS
  82. CONFOLDENTRY ccfe;
  83. CONST_IFSTRICT CON_TRAY_MENU_DATA * pctmd;
  84. CONST_IFSTRICT CON_BRANDING_INFO * pcbi;
  85. inline CONST_IFSTRICT CTrayIconData* GetTrayIconData() const throw();
  86. inline BOOL HasTrayIconData() const throw();
  87. inline const BOOL GetCreationTime() const throw() { return m_CreationTime; };
  88. inline void UpdateCreationTime() throw() { m_CreationTime = GetTickCount(); };
  89. HRESULT SetTrayIconData(const CTrayIconData& TrayIconData);
  90. HRESULT DeleteTrayIconData();
  91. #ifdef DBG
  92. DWORD dwLockingThreadId;
  93. #endif
  94. private:
  95. CONST_IFSTRICT CTrayIconData * m_pTrayIconData;
  96. DWORD m_CreationTime;
  97. #ifdef VERYSTRICTCOMPILE
  98. private:
  99. const ConnListEntry* operator& ();
  100. #endif
  101. public:
  102. BOOL empty() const;
  103. void clear();
  104. };
  105. // This is the callback definition. Each find routine will be a separate
  106. // callback function
  107. //
  108. // typedef HRESULT (CALLBACK *PFNCONNLISTICONREMOVALCB)(UINT);
  109. // We are creating a list of Connection entries
  110. //
  111. typedef map<GUID, ConnListEntry> ConnListCore;
  112. // Our find callbacks
  113. //
  114. // For ALGO find
  115. bool operator==(IN const ConnListEntry& val, IN PCWSTR pszName) throw(); // HrFindCallbackConnName
  116. bool operator==(IN const ConnListEntry& cle, IN const CONFOLDENTRY& cfe) throw(); // HrFindCallbackConFoldEntry
  117. bool operator==(IN const ConnListEntry& cle, IN const UINT& uiIcon) throw(); // HrFindCallbackTrayIconId
  118. // For map::find
  119. bool operator < (IN const GUID& rguid1, IN const GUID& rguid2) throw(); // HrFindCallbackGuid
  120. // Global connection list wrapper
  121. //
  122. #ifdef DBG
  123. #define AcquireLock() if (FIsDebugFlagSet(dfidTraceFileFunc)) {TraceTag(ttidShellFolder, "Acquiring LOCK: %s, %s, %d", __FUNCTION__, __FILE__, __LINE__);} InternalAcquireLock();
  124. #define ReleaseLock() if (FIsDebugFlagSet(dfidTraceFileFunc)) {TraceTag(ttidShellFolder, "Releasing LOCK: %s, %s, %d", __FUNCTION__, __FILE__, __LINE__);} InternalReleaseLock();
  125. #else
  126. #define AcquireLock() InternalAcquireLock();
  127. #define ReleaseLock() InternalReleaseLock();
  128. #endif
  129. class CConnectionList : CNetCfgDebug<CConnectionList>
  130. {
  131. public:
  132. // No constructor/destructor because we have a global instance of this
  133. // object. Use manual Initialize/Uninitialize instead.
  134. //
  135. VOID Initialize(IN BOOL fTieToTray, IN BOOL fAdviseOnThis) throw();
  136. VOID Uninitialize(IN BOOL fFinalUninitialize = FALSE) throw();
  137. private:
  138. template <class T>
  139. HRESULT HrFindConnectionByType (IN const T& findbyType, IN ConnListEntry& cle)
  140. {
  141. HRESULT hr = S_FALSE;
  142. if (m_pcclc)
  143. {
  144. AcquireLock();
  145. // Try to find the connection
  146. //
  147. ConnListCore::const_iterator iter;
  148. iter = find(m_pcclc->begin(), m_pcclc->end(), findbyType);
  149. if (iter == m_pcclc->end())
  150. {
  151. hr = S_FALSE;
  152. }
  153. else
  154. {
  155. cle = iter->second;
  156. Assert(!cle.ccfe.empty() );
  157. if (!cle.ccfe.empty())
  158. {
  159. cle.UpdateCreationTime();
  160. hr = S_OK;
  161. }
  162. else
  163. {
  164. hr = E_OUTOFMEMORY;
  165. }
  166. }
  167. ReleaseLock();
  168. }
  169. else
  170. {
  171. return S_FALSE;
  172. }
  173. return hr;
  174. }
  175. ConnListCore* m_pcclc;
  176. bool m_fPopulated;
  177. CRITICAL_SECTION m_csMain;
  178. DWORD m_dwAdviseCookie;
  179. BOOL m_fTiedToTray;
  180. BOOL m_fAdviseOnThis;
  181. static DWORD NotifyThread(IN OUT LPVOID pConnectionList) throw();
  182. static DWORD m_dwNotifyThread;
  183. static HANDLE m_hNotifyThread;
  184. // This is for debugging only -- can check the refcount while in the debugger.
  185. #if DBG
  186. DWORD m_dwCritSecRef;
  187. DWORD m_dwWriteLockRef;
  188. #endif
  189. public:
  190. CRITICAL_SECTION m_csWriteLock;
  191. void AcquireWriteLock() throw();
  192. void ReleaseWriteLock() throw();
  193. private:
  194. VOID InternalAcquireLock() throw();
  195. VOID InternalReleaseLock() throw();
  196. public:
  197. HRESULT HrFindConnectionByGuid(
  198. IN const GUID UNALIGNED *pguid,
  199. OUT ConnListEntry& cle);
  200. inline HRESULT HrFindConnectionByName(
  201. IN PCWSTR pszName,
  202. OUT ConnListEntry& cle);
  203. inline HRESULT HrFindConnectionByConFoldEntry(
  204. IN const CONFOLDENTRY& ccfe,
  205. OUT ConnListEntry& cle);
  206. inline HRESULT HrFindConnectionByTrayIconId(
  207. IN UINT uiIcon,
  208. OUT ConnListEntry& cle);
  209. HRESULT HrFindRasServerConnection(
  210. OUT ConnListEntry& cle);
  211. inline BOOL IsInitialized() const throw() { return(m_pcclc != NULL); }
  212. VOID FlushConnectionList() throw();
  213. VOID FlushTrayIcons() throw(); // Flush just the tray icons
  214. VOID EnsureIconsPresent() throw();
  215. HRESULT HrRetrieveConManEntries(
  216. OUT PCONFOLDPIDLVEC& apidlOut) throw();
  217. HRESULT HrRefreshConManEntries();
  218. HRESULT HrSuggestNameForDuplicate(
  219. IN PCWSTR pszOriginal,
  220. OUT PWSTR * ppszNew);
  221. HRESULT HrInsert(
  222. IN const CONFOLDENTRY& pccfe);
  223. HRESULT HrRemoveByIter(
  224. IN OUT ConnListCore::iterator clcIter,
  225. OUT BOOL * pfFlushPosts);
  226. HRESULT HrRemove(
  227. IN OUT const CONFOLDENTRY& ccfe,
  228. OUT BOOL * pfFlushPosts);
  229. HRESULT HrInsertFromNetCon(
  230. IN INetConnection * pNetCon,
  231. OUT PCONFOLDPIDL & ppcfp);
  232. HRESULT HrInsertFromNetConPropertiesEx(
  233. IN const NETCON_PROPERTIES_EX& PropsEx,
  234. OUT PCONFOLDPIDL & ppcfp);
  235. HRESULT HrFindPidlByGuid(
  236. IN const GUID * pguid,
  237. OUT PCONFOLDPIDL& pidl);
  238. HRESULT HrGetCurrentStatsForTrayIconId(
  239. IN UINT uiIcon,
  240. OUT STATMON_ENGINEDATA** ppData,
  241. OUT tstring* pstrName);
  242. HRESULT HrUpdateTrayIconDataByGuid(
  243. IN const GUID * pguid,
  244. IN CConnectionTrayStats * pccts,
  245. IN IConnectionPoint * pcpStat,
  246. IN INetStatisticsEngine * pnseStats,
  247. IN UINT uiIcon);
  248. HRESULT HrUpdateTrayBalloonInfoByGuid(
  249. IN const GUID * pguid,
  250. IN DWORD dwLastBalloonMessage,
  251. IN BSTR szCookie,
  252. IN FNBALLOONCLICK* pfnBalloonFunction);
  253. HRESULT HrUpdateNameByGuid(
  254. IN const GUID * pguid,
  255. IN PCWSTR pszNewName,
  256. OUT PCONFOLDPIDL & pidlOut,
  257. IN BOOL fForce);
  258. HRESULT HrUpdateConnectionByGuid(
  259. IN const GUID * pguid,
  260. IN const ConnListEntry& cle );
  261. HRESULT HrUpdateTrayIconByGuid(
  262. IN const GUID * pguid,
  263. IN BOOL fBrieflyShowBalloon);
  264. HRESULT HrGetBrandingInfo(
  265. IN OUT ConnListEntry& cle);
  266. HRESULT HrGetCachedPidlCopyFromPidl(
  267. IN const PCONFOLDPIDL& pidl,
  268. OUT PCONFOLDPIDL & pcfp);
  269. HRESULT HrMapCMHiddenConnectionToOwner(
  270. IN REFGUID guidHidden,
  271. OUT GUID * pguidOwner);
  272. HRESULT HrUnsetCurrentDefault(OUT PCONFOLDPIDL& cfpPreviousDefault);
  273. HRESULT HasActiveIncomingConnections(OUT LPDWORD pdwCount);
  274. // BOOL FExists(PWSTR pszName);
  275. VOID EnsureConPointNotifyAdded() throw();
  276. VOID EnsureConPointNotifyRemoved() throw();
  277. #ifdef NCDBGEXT
  278. IMPORT_NCDBG_FRIENDS
  279. #endif
  280. };
  281. // Helper routines
  282. //
  283. HRESULT HrCheckForActivation(
  284. IN const PCONFOLDPIDL& cfp,
  285. IN const CONFOLDENTRY& ccfe,
  286. OUT BOOL * pfActivating);
  287. HRESULT HrSetActivationFlag(
  288. IN const PCONFOLDPIDL& cfp,
  289. IN const CONFOLDENTRY& ccfe,
  290. IN BOOL fActivating);
  291. HRESULT HrGetTrayIconLock(
  292. IN const GUID * pguid,
  293. OUT UINT * puiIcon,
  294. OUT LPDWORD pdwLockingThreadId);
  295. VOID ReleaseTrayIconLock(IN const GUID * pguid) throw();
  296. #endif // _CONNLIST_H_