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.

352 lines
8.4 KiB

  1. #ifndef DOCUMENT_H
  2. #define DOCUMENT_H
  3. #pragma once
  4. #include "private.h"
  5. #define MAXFILEPATHLEN 256
  6. #define MAXSTRINGLEN 256
  7. #define NLBMGR_AUTOREFRESH_MIN_INTERVAL 15
  8. #define NLBMGR_AUTOREFRESH_DEF_INTERVAL 60
  9. //
  10. // A single instance of this class, gCmdLineInfo, is initialized
  11. // by the Application object.
  12. //
  13. class CNlbMgrCommandLineInfo : public CCommandLineInfo
  14. {
  15. public:
  16. CNlbMgrCommandLineInfo(VOID)
  17. : m_bDemo(FALSE), m_bNoPing(FALSE), m_bHostList(FALSE),
  18. m_bUsage(FALSE), m_bAutoRefresh(FALSE),
  19. m_refreshInterval(NLBMGR_AUTOREFRESH_DEF_INTERVAL)
  20. {
  21. }
  22. BOOL m_bAutoRefresh;
  23. UINT m_refreshInterval;
  24. BOOL m_bDemo;
  25. BOOL m_bNoPing;
  26. BOOL m_bHostList;
  27. BOOL m_bUsage;
  28. _bstr_t m_bstrHostListFile;
  29. virtual
  30. void
  31. ParseParam( LPCTSTR lpszParam, BOOL bFlag, BOOL bLast );
  32. };
  33. extern CNlbMgrCommandLineInfo gCmdLineInfo;
  34. class CUIWorkItem
  35. {
  36. public:
  37. //
  38. // Use this constructor to create a work item for a log request
  39. //
  40. CUIWorkItem(
  41. IN const IUICallbacks::LogEntryHeader *pHeader,
  42. IN const wchar_t *szText
  43. )
  44. {
  45. workItemType = ITEM_LOG;
  46. try
  47. {
  48. type = pHeader->type;
  49. bstrCluster = pHeader->szCluster;
  50. bstrHost = pHeader->szHost;
  51. bstrInterface = pHeader->szInterface;
  52. bstrText = szText;
  53. bstrDetails = pHeader->szDetails;
  54. }
  55. catch(...)
  56. {
  57. //
  58. // in case there's an bstr alloc failure.
  59. //
  60. workItemType = ITEM_INVALID;
  61. }
  62. }
  63. //
  64. // Use this constructor to create a work item for a "HandleEngineEvent"
  65. // notification.
  66. //
  67. CUIWorkItem(
  68. IN IUICallbacks::ObjectType objtypeX,
  69. IN ENGINEHANDLE ehClusterIdX, // could be NULL
  70. IN ENGINEHANDLE ehObjIdX,
  71. IN IUICallbacks::EventCode evtX
  72. )
  73. {
  74. workItemType = ITEM_ENGINE_EVENT;
  75. objtype = objtypeX;
  76. ehClusterId = ehClusterIdX;
  77. ehObjId = ehObjIdX;
  78. evt = evtX;
  79. }
  80. ~CUIWorkItem()
  81. {
  82. }
  83. enum
  84. {
  85. ITEM_INVALID=0,
  86. ITEM_LOG,
  87. ITEM_ENGINE_EVENT
  88. } workItemType;
  89. //
  90. // Log function related
  91. //
  92. IUICallbacks::LogEntryType type;
  93. _bstr_t bstrCluster;
  94. _bstr_t bstrHost;
  95. _bstr_t bstrInterface;
  96. _bstr_t bstrText;
  97. _bstr_t bstrDetails;
  98. //
  99. // Handle engine event related...
  100. //
  101. IUICallbacks::ObjectType objtype;
  102. ENGINEHANDLE ehClusterId;
  103. ENGINEHANDLE ehObjId;
  104. IUICallbacks::EventCode evt;
  105. };
  106. class Document : public CDocument, public IUICallbacks
  107. {
  108. DECLARE_DYNCREATE( Document )
  109. public:
  110. enum IconNames
  111. {
  112. //
  113. // This order must exactly the order in which Icons are loaded
  114. // in Document::Document.
  115. //
  116. ICON_WORLD = 0,
  117. ICON_CLUSTER,
  118. ICON_HOST_STARTED,
  119. ICON_HOST_STOPPED,
  120. ICON_HOST_CONVERGING,
  121. ICON_HOST_SUSPENDED,
  122. ICON_HOST_DRAINING,
  123. ICON_HOST_DISCONNECTED,
  124. ICON_PORTRULE,
  125. ICON_PENDING,
  126. ICON_INFORMATIONAL,
  127. ICON_WARNING,
  128. ICON_ERROR,
  129. ICON_CLUSTER_OK,
  130. ICON_CLUSTER_PENDING,
  131. ICON_CLUSTER_BROKEN,
  132. ICON_HOST_OK,
  133. ICON_HOST_PENDING,
  134. ICON_HOST_MISCONFIGURED,
  135. ICON_HOST_UNREACHABLE,
  136. ICON_HOST_UNKNOWN
  137. };
  138. enum ListViewColumnSize
  139. {
  140. LV_COLUMN_MINSCULE = 20,
  141. LV_COLUMN_TINY = 60,
  142. LV_COLUMN_SMALL = 70,
  143. LV_COLUMN_SMALLMEDIUM = 75,
  144. LV_COLUMN_MEDIUM = 80,
  145. LV_COLUMN_LARGE = 90,
  146. LV_COLUMN_LARGE2 = 160,
  147. LV_COLUMN_VERYLARGE = 200,
  148. LV_COLUMN_GIGANTIC = 500
  149. };
  150. // constructor
  151. Document();
  152. // destructor
  153. virtual ~Document();
  154. //
  155. // ------------------------------- overrides for IUICallbacks ----------
  156. //
  157. //
  158. // Asks the user to update user-supplied info about a host.
  159. //
  160. BOOL
  161. virtual
  162. Document::UpdateHostInformation(
  163. IN BOOL fNeedCredentials,
  164. IN BOOL fNeedConnectionString,
  165. IN OUT CHostSpec& host
  166. );
  167. //
  168. // Log a message in human-readable form.
  169. //
  170. virtual
  171. void
  172. Log(
  173. IN LogEntryType Type,
  174. IN const wchar_t *szCluster, OPTIONAL
  175. IN const wchar_t *szHost, OPTIONAL
  176. IN UINT ResourceID,
  177. ...
  178. );
  179. virtual
  180. void
  181. LogEx(
  182. IN const LogEntryHeader *pHeader,
  183. IN UINT ResourceID,
  184. ...
  185. );
  186. //
  187. // Handle an event relating to a specific instance of a specific
  188. // object type.
  189. //
  190. virtual
  191. void
  192. HandleEngineEvent(
  193. IN ObjectType objtype,
  194. IN ENGINEHANDLE ehClusterId, // could be NULL
  195. IN ENGINEHANDLE ehObjId,
  196. IN EventCode evt
  197. );
  198. //
  199. // Handle a selection change notification from the left (tree) view
  200. //
  201. void
  202. HandleLeftViewSelChange(
  203. IN IUICallbacks::ObjectType objtype,
  204. IN ENGINEHANDLE ehObjId
  205. );
  206. // ------------------------------- END overrides for IUICallbacks ----------
  207. void
  208. registerLeftView(LeftView *pLeftView);
  209. void
  210. registerLogView(LogView *pLogView);
  211. void
  212. registerDetailsView(DetailsView *pDetailsView);
  213. void
  214. LoadHostsFromFile(_bstr_t &FileName);
  215. VOID
  216. getDefaultCredentials(
  217. OUT _bstr_t &bstrUserName,
  218. OUT _bstr_t &bstrPassword
  219. )
  220. {
  221. bstrUserName = m_bstrDefaultUserName;
  222. bstrPassword = m_bstrDefaultPassword;
  223. }
  224. VOID
  225. setDefaultCredentials(
  226. IN LPCWSTR szUserName,
  227. IN LPCWSTR szPassword
  228. )
  229. {
  230. m_bstrDefaultUserName = _bstr_t(szUserName);
  231. m_bstrDefaultPassword = _bstr_t(szPassword);
  232. }
  233. void
  234. HandleDeferedUIWorkItem(CUIWorkItem *pWorkItem);
  235. CImageList* m_images48x48;
  236. //
  237. // Logging support
  238. //
  239. enum LOG_RESULT {
  240. STARTED=0, ALREADY, NOT_ENABLED, NO_FILE_NAME, FILE_NAME_TOO_LONG,
  241. IO_ERROR, REG_IO_ERROR, FILE_PATH_INVALID, FILE_TOO_LARGE
  242. };
  243. inline bool isLoggingEnabled() { return (m_dwLoggingEnabled != 0); }
  244. inline bool isCurrentlyLogging() { return (NULL != m_hStatusLog); }
  245. Document::LOG_RESULT initLogging();
  246. LONG enableLogging();
  247. LONG disableLogging();
  248. Document::LOG_RESULT startLogging();
  249. bool stopLogging();
  250. void getLogfileName(WCHAR* pszFileName, DWORD dwBufLen);
  251. LONG setLogfileName(WCHAR* pszFileName);
  252. void logStatus(WCHAR* pszStatus);
  253. bool isDirectoryValid(WCHAR* pszFileName);
  254. // End logging support
  255. void SetFocusNextView(CWnd* pWnd, UINT nChar);
  256. void SetFocusPrevView(CWnd* pWnd, UINT nChar);
  257. virtual void OnCloseDocument();
  258. VOID
  259. PrepareToClose(BOOL fBlock);
  260. private:
  261. //
  262. // Attempts to defer the specified operation by posting the operation
  263. // to the application's message queue where it will be picked up and
  264. // processed later. Returns TRUE IFF the operation has been posted
  265. // successfully. The caller should delete pWorkItem IFF the function
  266. // returns FALSE.
  267. //
  268. BOOL
  269. mfn_DeferUIOperation(CUIWorkItem *pWorkItem);
  270. LeftView *m_pLeftView;
  271. DetailsView *m_pDetailsView;
  272. LogView *m_pLogView;
  273. CNlbEngine *m_pNlbEngine;
  274. DWORD m_dwLoggingEnabled;
  275. WCHAR m_szLogFileName[MAXFILEPATHLEN];
  276. FILE *m_hStatusLog;
  277. BOOL m_fPrepareToDeinitialize;
  278. enum VIEWTYPE { NO_VIEW = 0, LEFTVIEW, DETAILSVIEW, LOGVIEW };
  279. VIEWTYPE
  280. GetViewType(CWnd* pWnd); // Matches the CWnd* to that of the defined views
  281. #if OBSOLETE
  282. void LoadHost(WMI_CONNECTION_INFO *pConnInfo);
  283. #endif // OBSOLETE
  284. _bstr_t m_bstrDefaultUserName;
  285. _bstr_t m_bstrDefaultPassword; // TODO Security audit of this practise!!!!!
  286. };
  287. #endif