Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / problems.cpp
blobb988bba4bef045dc865f1603ab5d18583c8ba0c9
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include "svrmgr.h"
19 #include "problems.h"
20 #include "alert.h"
21 #include "svc_viewlog.h"
22 #include "set_prop.h"
23 #include "agg_prop.h"
24 #include "creds.h"
28 * PROTOTYPES _________________________________________________________________
32 void Problems_OnInitDialog (HWND hDlg, LPIDENT lpi);
33 void Problems_OnRefresh (HWND hDlg, LPIDENT lpi);
34 void Problems_OnRedraw (HWND hDlg, LPIDENT lpi);
35 void Problems_OnRemedy (HWND hDlg, LPIDENT lpi);
39 * ROUTINES ___________________________________________________________________
43 BOOL CALLBACK Problems_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
45 if (AfsAppLib_HandleHelp (IDD_SVR_PROBLEMS, hDlg, msg, wp, lp))
46 return TRUE;
48 if (msg == WM_INITDIALOG)
49 SetWindowLongPtr (hDlg, DWLP_USER, ((LPPROPSHEETPAGE)lp)->lParam);
51 LPIDENT lpi = (LPIDENT)GetWindowLongPtr (hDlg, DWLP_USER);
53 switch (msg)
55 case WM_INITDIALOG:
56 NotifyMe (WHEN_OBJECT_CHANGES, lpi, hDlg, 0);
57 Problems_OnInitDialog (hDlg, lpi);
58 Problems_OnRefresh (hDlg, lpi);
59 break;
61 case WM_NOTIFY_FROM_DISPATCH:
62 Problems_OnRefresh (hDlg, lpi);
63 Delete ((LPNOTIFYSTRUCT)lp);
64 break;
66 case WM_DESTROY:
67 DontNotifyMeEver (hDlg);
68 break;
70 case WM_COMMAND:
71 switch (LOWORD(wp))
73 case IDC_PROBLEM_REMEDY:
74 Problems_OnRemedy (hDlg, lpi);
75 break;
77 break;
79 case WM_CTLCOLORSTATIC:
80 if ((HWND)lp == GetDlgItem (hDlg, IDC_PROBLEM_TEXT))
82 SetBkColor ((HDC)wp, GetSysColor (COLOR_WINDOW));
83 return CreateSolidBrush (GetSysColor (COLOR_WINDOW))?TRUE:FALSE;
85 break;
87 case WM_VSCROLL:
88 int posOld;
89 int posNew;
90 posOld = GetScrollPos (GetDlgItem (hDlg, IDC_PROBLEM_SCROLL), SB_CTL);
91 posNew = posOld;
93 switch (LOWORD(wp))
95 case SB_LINEUP:
96 --posNew;
97 break;
98 case SB_LINEDOWN:
99 ++posNew;
100 break;
101 case SB_PAGEUP:
102 --posNew;
103 break;
104 case SB_PAGEDOWN:
105 ++posNew;
106 break;
107 case SB_THUMBTRACK:
108 posNew = HIWORD(wp);
109 break;
110 case SB_TOP:
111 posNew = 0;
112 break;
113 case SB_BOTTOM:
114 posNew = nAlertsMAX;
115 break;
118 SCROLLINFO si;
119 memset (&si, 0x00, sizeof(si));
120 si.cbSize = sizeof(si);
121 si.fMask = SIF_RANGE;
122 GetScrollInfo (GetDlgItem (hDlg, IDC_PROBLEM_SCROLL), SB_CTL, &si);
123 posNew = limit (0, posNew, si.nMax);
125 if (posNew != posOld)
127 SetScrollPos (GetDlgItem (hDlg, IDC_PROBLEM_SCROLL), SB_CTL, posNew, (LOWORD(wp) == SB_THUMBTRACK) ? FALSE : TRUE);
128 Problems_OnRedraw (hDlg, lpi);
130 break;
133 return FALSE;
137 void Problems_OnInitDialog (HWND hDlg, LPIDENT lpi)
139 TCHAR szText[ cchRESOURCE ];
140 GetDlgItemText (hDlg, IDC_PROBLEM_TITLE, szText, cchRESOURCE);
142 LPTSTR pszTitle = NULL;
144 if (lpi->fIsServer())
146 TCHAR szServer[ cchNAME ];
147 lpi->GetServerName (szServer);
148 pszTitle = FormatString (szText, TEXT("%s"), szServer);
150 else if (lpi->fIsService())
152 TCHAR szServer[ cchNAME ];
153 TCHAR szService[ cchNAME ];
154 lpi->GetServerName (szServer);
155 lpi->GetServiceName (szService);
156 pszTitle = FormatString (szText, TEXT("%s%s"), szServer, szService);
158 else if (lpi->fIsAggregate())
160 TCHAR szServer[ cchNAME ];
161 TCHAR szAggregate[ cchNAME ];
162 lpi->GetServerName (szServer);
163 lpi->GetAggregateName (szAggregate);
164 pszTitle = FormatString (szText, TEXT("%s%s"), szServer, szAggregate);
166 else if (lpi->fIsFileset())
168 TCHAR szServer[ cchNAME ];
169 TCHAR szAggregate[ cchNAME ];
170 TCHAR szFileset[ cchNAME ];
171 lpi->GetServerName (szServer);
172 lpi->GetAggregateName (szAggregate);
173 lpi->GetFilesetName (szFileset);
174 pszTitle = FormatString (szText, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
177 if (pszTitle == NULL)
178 SetDlgItemText (hDlg, IDC_PROBLEM_TITLE, TEXT(""));
179 else
181 SetDlgItemText (hDlg, IDC_PROBLEM_TITLE, pszTitle);
182 FreeString (pszTitle);
185 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_SCROLL), SW_HIDE);
186 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_HEADER), SW_HIDE);
187 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_REMEDY), SW_HIDE);
188 SetDlgItemText (hDlg, IDC_PROBLEM_TEXT, TEXT(""));
192 void Problems_OnRefresh (HWND hDlg, LPIDENT lpi)
194 size_t nAlerts = Alert_GetCount (lpi);
196 LPTSTR pszText = FormatString (IDS_PROBLEM_BOX, TEXT("%lu"), nAlerts);
197 SetDlgItemText (hDlg, IDC_PROBLEM_BOX, pszText);
198 FreeString (pszText);
200 switch (nAlerts)
202 case 0:
203 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_SCROLL), SW_HIDE);
204 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_HEADER), SW_HIDE);
205 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_REMEDY), SW_HIDE);
207 TCHAR szText[ cchRESOURCE ];
208 if (lpi->fIsServer())
209 GetString (szText, IDS_SERVER_NO_PROBLEMS);
210 else if (lpi->fIsService())
211 GetString (szText, IDS_SERVICE_NO_PROBLEMS);
212 else if (lpi->fIsAggregate())
213 GetString (szText, IDS_AGGREGATE_NO_PROBLEMS);
214 else if (lpi->fIsFileset())
215 GetString (szText, IDS_FILESET_NO_PROBLEMS);
216 else
217 wsprintf (szText, TEXT("UNEXPECTED CONDITION in problems.cpp"));
219 SetDlgItemText (hDlg, IDC_PROBLEM_TEXT, szText);
220 break;
222 case 1:
223 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_SCROLL), SW_HIDE);
224 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_HEADER), SW_HIDE);
225 Problems_OnRedraw (hDlg, lpi);
226 break;
228 default: // two or more
229 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_SCROLL), SW_SHOW);
230 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_HEADER), SW_SHOW);
232 SCROLLINFO si;
233 si.cbSize = sizeof(si);
234 si.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
235 si.nMin = 0;
236 si.nMax = (int)(nAlerts-1);
237 si.nPage = 1;
238 si.nPos = 0;
239 si.nTrackPos = 0;
241 SetScrollInfo (GetDlgItem (hDlg, IDC_PROBLEM_SCROLL), SB_CTL, &si, TRUE);
242 Problems_OnRedraw (hDlg, lpi);
243 break;
248 void Problems_OnRedraw (HWND hDlg, LPIDENT lpi)
250 int iAlert = 0;
252 if (IsWindowVisible (GetDlgItem (hDlg, IDC_PROBLEM_SCROLL)))
254 iAlert = GetScrollPos (GetDlgItem (hDlg, IDC_PROBLEM_SCROLL), SB_CTL);
257 TCHAR szText[ cchRESOURCE ];
258 wsprintf (szText, TEXT("%lu:"), 1+iAlert);
259 SetWindowText (GetDlgItem (hDlg, IDC_PROBLEM_HEADER), szText);
261 LPTSTR pszText1 = Alert_GetDescription (lpi, iAlert, TRUE);
262 LPTSTR pszText2 = Alert_GetRemedy (lpi, iAlert);
263 LPTSTR pszText3 = Alert_GetButton (lpi, iAlert);
265 LPTSTR pszProblem = FormatString (TEXT("%1\n\n%2"), TEXT("%s%s"),
266 (pszText1) ? pszText1 : TEXT(""),
267 (pszText2) ? pszText2 : TEXT(""));
268 SetWindowText (GetDlgItem (hDlg, IDC_PROBLEM_TEXT), pszProblem);
269 FreeString (pszProblem);
271 if (pszText3 == NULL)
272 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_REMEDY), SW_HIDE);
273 else
275 SetWindowText (GetDlgItem (hDlg, IDC_PROBLEM_REMEDY), pszText3);
276 ShowWindow (GetDlgItem (hDlg, IDC_PROBLEM_REMEDY), SW_SHOW);
279 FreeString (pszText3);
280 FreeString (pszText2);
281 FreeString (pszText1);
285 void Problems_OnRemedy (HWND hDlg, LPIDENT lpi)
287 int iAlert = GetScrollPos (GetDlgItem (hDlg, IDC_PROBLEM_SCROLL), SB_CTL);
289 LPIDENT lpiTarget = Alert_GetIdent (lpi, iAlert);
290 ALERT alert = Alert_GetAlert (lpi, iAlert);
292 switch (alert)
294 case alertTIMEOUT:
295 if (lpiTarget && lpiTarget->fIsCell())
297 StartTask (taskREFRESH, NULL, lpiTarget);
299 else if (lpiTarget)
301 StartTask (taskREFRESH, NULL, lpiTarget->GetServer());
303 break;
305 case alertFULL:
306 if (lpiTarget && lpiTarget->fIsFileset())
308 size_t nAlerts = Alert_GetCount (lpiTarget);
309 Filesets_ShowProperties (lpiTarget, nAlerts, TRUE);
311 else if (lpiTarget && lpiTarget->fIsAggregate())
313 size_t nAlerts = Alert_GetCount (lpiTarget);
314 Aggregates_ShowProperties (lpiTarget, nAlerts, TRUE);
316 break;
318 case alertNO_VLDBENT:
319 // No button in this case
320 break;
322 case alertNO_SVRENT:
323 // No button in this case
324 break;
326 case alertSTOPPED:
327 Services_ShowServiceLog (lpiTarget);
328 break;
330 case alertBADCREDS:
331 NewCredsDialog();
332 break;
334 case alertOVERALLOC:
335 // No button in this case
336 break;
338 case alertSTATE_NO_VNODE:
339 case alertSTATE_NO_SERVICE:
340 case alertSTATE_OFFLINE:
341 // No button in these cases
342 break;
348 * ParseFilesetName
352 void ParseFilesetName (LPIDENT lpiSearch, LPTSTR pszBase, LPTSTR pszEnding)
354 TCHAR szFileset[ cchNAME ];
355 lpiSearch->GetFilesetName (szFileset);
357 LPTSTR pszDot;
358 if ((pszDot = (LPTSTR)lstrrchr (szFileset, TEXT('.'))) != NULL)
360 if ( lstrcmpi (pszDot, cszENDING_CLONE) &&
361 lstrcmpi (pszDot, cszENDING_REPLICA) )
363 pszDot = NULL;
367 if (pszDot == NULL)
369 lstrcpy (pszBase, szFileset);
370 *pszEnding = NULL;
372 else // (pszDot != NULL)
374 lstrcpy (pszBase, szFileset);
375 lstrcpy (pszEnding, pszDot);
376 pszBase[ pszEnding - szFileset ] = TEXT('\0');