2 * Copyright 2000, International Business Machines Corporation and others.
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
14 #include <afs/param.h>
20 #include "svc_general.h"
21 #include "svc_startstop.h"
22 #include "svc_viewlog.h"
23 #include "propcache.h"
29 * PROTOTYPES _________________________________________________________________
33 BOOL CALLBACK
Services_General_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
35 void Services_General_OnInitDialog (HWND hDlg
, LPIDENT lpi
);
36 void Services_General_OnApply (HWND hDlg
, LPIDENT lpi
);
37 void Services_General_OnEndTask_InitDialog (HWND hDlg
, LPTASKPACKET ptp
);
38 void Services_General_OnEndTask_Apply (HWND hDlg
, LPTASKPACKET ptp
);
40 BOOL CALLBACK
Services_BOS_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
41 void Services_BOS_OnInitDialog (HWND hDlg
, LPIDENT lpi
);
42 void Services_BOS_OnEnable (HWND hDlg
, LPIDENT lpi
);
43 void Services_BOS_OnApply (HWND hDlg
, LPIDENT lpi
);
44 void Services_BOS_OnEndTask_InitDialog (HWND hDlg
, LPTASKPACKET ptp
, LPIDENT lpi
);
48 * ROUTINES ___________________________________________________________________
52 BOOL
PropSheet_AddBOSTab (LPPROPSHEET psh
, LPIDENT lpiService
)
54 TCHAR szSvcName
[ cchNAME
];
55 lpiService
->GetServiceName (szSvcName
);
57 if (lstrcmp (szSvcName
, TEXT("BOS")))
60 return PropSheet_AddTab (psh
, IDS_SVC_BOS_TAB
, IDD_SVC_BOS
, (DLGPROC
)Services_BOS_DlgProc
, (LPARAM
)lpiService
, TRUE
);
64 void Services_ShowProperties (LPIDENT lpiService
, size_t nAlerts
)
68 if ((hCurrent
= PropCache_Search (pcSVC_PROP
, lpiService
)) != NULL
)
74 TCHAR szSvrName
[ cchNAME
];
75 TCHAR szSvcName
[ cchNAME
];
76 lpiService
->GetServerName (szSvrName
);
77 lpiService
->GetServiceName (szSvcName
);
78 LPTSTR pszTitle
= FormatString (IDS_SVC_PROP_TITLE
, TEXT("%s%s"), szSvrName
, szSvcName
);
80 LPPROPSHEET psh
= PropSheet_Create (pszTitle
, FALSE
);
81 psh
->fMadeCaption
= TRUE
;
83 if (PropSheet_AddProblemsTab (psh
, IDD_SVC_PROBLEMS
, lpiService
, nAlerts
) &&
84 PropSheet_AddTab (psh
, IDS_SVC_GENERAL_TAB
, IDD_SVC_GENERAL
, (DLGPROC
)Services_General_DlgProc
, (LPARAM
)lpiService
, TRUE
) &&
85 PropSheet_AddBOSTab (psh
, lpiService
))
87 PropSheet_ShowModeless (psh
);
93 BOOL CALLBACK
Services_General_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
95 if (AfsAppLib_HandleHelp (IDD_SVC_GENERAL
, hDlg
, msg
, wp
, lp
))
98 if (msg
== WM_INITDIALOG
)
99 SetWindowLongPtr (hDlg
, DWLP_USER
, ((LPPROPSHEETPAGE
)lp
)->lParam
);
101 LPIDENT lpi
= (LPIDENT
)GetWindowLongPtr (hDlg
, DWLP_USER
);
105 case WM_INITDIALOG_SHEET
:
106 PropCache_Add (pcSVC_PROP
, (LPIDENT
)lp
, hDlg
);
109 case WM_DESTROY_SHEET
:
110 PropCache_Delete (hDlg
);
114 NotifyMe (WHEN_OBJECT_CHANGES
, lpi
, hDlg
, 0);
115 Services_General_OnInitDialog (hDlg
, lpi
);
116 StartTask (taskSVC_PROP_INIT
, hDlg
, lpi
);
120 DontNotifyMeEver (hDlg
);
123 case WM_NOTIFY_FROM_DISPATCH
:
124 if (((LPNOTIFYSTRUCT
)lp
)->evt
== evtRefreshStatusEnd
)
126 if (((LPNOTIFYSTRUCT
)lp
)->Params
.lpi1
== lpi
)
128 StartTask (taskSVC_PROP_INIT
, hDlg
, lpi
);
131 Delete ((LPNOTIFYSTRUCT
)lp
);
136 if ((ptp
= (LPTASKPACKET
)lp
) != NULL
)
138 if (ptp
->idTask
== taskSVC_PROP_INIT
)
139 Services_General_OnEndTask_InitDialog (hDlg
, ptp
);
140 else if (ptp
->idTask
== taskSVC_PROP_APPLY
)
141 Services_General_OnEndTask_Apply (hDlg
, ptp
);
142 FreeTaskPacket (ptp
);
154 Services_General_OnApply (hDlg
, lpi
);
157 case IDC_SVC_WARNSTOP
:
158 PropSheetChanged (hDlg
);
162 TCHAR szSvcName
[ cchNAME
];
163 lpi
->GetServiceName (szSvcName
);
164 if (!lstrcmpi (szSvcName
, TEXT("BOS")))
165 Services_Restart (lpi
);
167 Services_Start (lpi
);
174 case IDC_SVC_VIEWLOG
:
175 Services_ShowServiceLog (lpi
);
185 void Services_General_OnInitDialog (HWND hDlg
, LPIDENT lpi
)
187 TCHAR szText
[ cchRESOURCE
];
190 TCHAR szSvrName
[ cchNAME
];
191 TCHAR szSvcName
[ cchNAME
];
192 lpi
->GetServerName (szSvrName
);
193 lpi
->GetServiceName (szSvcName
);
195 GetDlgItemText (hDlg
, IDC_SVC_NAME
, szText
, cchRESOURCE
);
196 pszText
= FormatString (szText
, TEXT("%s%s"), szSvrName
, szSvcName
);
197 SetDlgItemText (hDlg
, IDC_SVC_NAME
, pszText
);
198 FreeString (pszText
);
200 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_WARNSTOP
), FALSE
);
201 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_VIEWLOG
), FALSE
);
202 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_STOP
), FALSE
);
203 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_START
), FALSE
);
205 if (!lstrcmpi (szSvcName
, TEXT("BOS")))
209 GetRectInParent (GetDlgItem (hDlg
, IDC_SVC_START
), &rStart
);
210 GetRectInParent (GetDlgItem (hDlg
, IDC_SVC_STOP
), &rStop
);
211 DestroyWindow (GetDlgItem (hDlg
, IDC_SVC_STOP
));
212 SetWindowPos (GetDlgItem (hDlg
, IDC_SVC_START
), NULL
,
213 0, 0, rStop
.right
-rStart
.left
, rStart
.bottom
-rStart
.top
,
214 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
215 GetString (szText
, IDS_SVC_RESTART_BUTTON
);
216 SetDlgItemText (hDlg
, IDC_SVC_START
, szText
);
221 void Services_General_OnEndTask_InitDialog (HWND hDlg
, LPTASKPACKET ptp
)
223 LPIDENT lpi
= (LPIDENT
)GetWindowLongPtr (hDlg
, DWLP_USER
);
225 TCHAR szUnknown
[ cchRESOURCE
];
226 GetString (szUnknown
, IDS_UNKNOWN
);
230 SetDlgItemText (hDlg
, IDC_SVC_STARTDATE
, szUnknown
);
231 SetDlgItemText (hDlg
, IDC_SVC_STOPDATE
, szUnknown
);
232 SetDlgItemText (hDlg
, IDC_SVC_LASTERROR
, szUnknown
);
233 GetString (szUnknown
, IDS_SERVICESTATUS_UNKNOWN
);
234 SetDlgItemText (hDlg
, IDC_SVC_STATUS
, szUnknown
);
235 SetDlgItemText (hDlg
, IDC_SVC_PARAMS
, szUnknown
);
236 SetDlgItemText (hDlg
, IDC_SVC_NOTIFIER
, szUnknown
);
238 TCHAR szSvrName
[ cchNAME
];
239 TCHAR szSvcName
[ cchNAME
];
240 lpi
->GetServerName (szSvrName
);
241 lpi
->GetServiceName (szSvcName
);
242 ErrorDialog (ptp
->status
, IDS_ERROR_REFRESH_SERVICE_STATUS
, TEXT("%s%s"), szSvrName
, szSvcName
);
246 TCHAR szText
[ cchRESOURCE
];
248 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_WARNSTOP
), TRUE
);
249 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_VIEWLOG
), TRUE
);
250 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_STOP
), TRUE
);
251 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_START
), TRUE
);
253 if (TASKDATA(ptp
)->cs
.type
== SERVICETYPE_FS
)
254 GetString (szText
, IDS_SERVICETYPE_FS_LONG
);
255 else if (TASKDATA(ptp
)->cs
.type
== SERVICETYPE_CRON
)
256 GetString (szText
, IDS_SERVICETYPE_CRON_LONG
);
257 else // (TASKDATA(ptp)->cs.type == SERVICETYPE_SIMPLE)
258 GetString (szText
, IDS_SERVICETYPE_SIMPLE_LONG
);
259 SetDlgItemText (hDlg
, IDC_SVC_TYPE
, szText
);
261 LPTSTR pszParams
= CloneString (TASKDATA(ptp
)->cs
.szParams
);
263 for (pch
= pszParams
; pch
&& *pch
; ++pch
)
265 if (*pch
== TEXT('\r') || *pch
== TEXT('\t') || *pch
== TEXT('\n'))
268 SetDlgItemText (hDlg
, IDC_SVC_PARAMS
, pszParams
? pszParams
: TEXT(""));
269 FreeString (pszParams
);
271 LPTSTR pszNotifier
= CloneString (TASKDATA(ptp
)->cs
.szNotifier
);
272 for (pch
= pszNotifier
; pch
&& *pch
; ++pch
)
274 if (*pch
== TEXT('\r') || *pch
== TEXT('\t') || *pch
== TEXT('\n'))
277 GetString (szText
, IDS_SVC_NONOTIFIER
);
278 SetDlgItemText (hDlg
, IDC_SVC_NOTIFIER
, (pszNotifier
&& *pszNotifier
) ? pszNotifier
: szText
);
279 FreeString (pszNotifier
);
281 if (!FormatTime (szText
, TEXT("%s"), &TASKDATA(ptp
)->cs
.timeLastStart
))
282 SetDlgItemText (hDlg
, IDC_SVC_STARTDATE
, szUnknown
);
284 SetDlgItemText (hDlg
, IDC_SVC_STARTDATE
, szText
);
286 if (!FormatTime (szText
, TEXT("%s"), &TASKDATA(ptp
)->cs
.timeLastStop
))
287 SetDlgItemText (hDlg
, IDC_SVC_STOPDATE
, szUnknown
);
289 SetDlgItemText (hDlg
, IDC_SVC_STOPDATE
, szText
);
291 if (!FormatTime (szText
, TEXT("%s"), &TASKDATA(ptp
)->cs
.timeLastFail
))
292 SetDlgItemText (hDlg
, IDC_SVC_LASTERROR
, szUnknown
);
295 LPTSTR pszText
= FormatString (IDS_SERVICE_LASTERRORDATE
, TEXT("%s%ld"), szText
, TASKDATA(ptp
)->cs
.dwErrLast
);
296 SetDlgItemText (hDlg
, IDC_SVC_LASTERROR
, pszText
);
297 FreeString (pszText
);
300 if (TASKDATA(ptp
)->cs
.state
== SERVICESTATE_RUNNING
)
302 GetString (szText
, IDS_SERVICESTATUS_RUNNING
);
304 else if (TASKDATA(ptp
)->cs
.state
== SERVICESTATE_STARTING
)
306 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_STOP
), FALSE
);
307 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_START
), FALSE
);
308 GetString (szText
, IDS_SERVICESTATUS_STARTING
);
310 else if (TASKDATA(ptp
)->cs
.state
== SERVICESTATE_STOPPING
)
312 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_STOP
), FALSE
);
313 EnableWindow (GetDlgItem (hDlg
, IDC_SVC_START
), FALSE
);
314 GetString (szText
, IDS_SERVICESTATUS_STOPPING
);
316 else // (TASKDATA(ptp)->cs.state == SERVICESTATE_STOPPED)
318 GetString (szText
, IDS_SERVICESTATUS_STOPPED
);
320 SetDlgItemText (hDlg
, IDC_SVC_STATUS
, szText
);
322 CheckDlgButton (hDlg
, IDC_SVC_WARNSTOP
, (TASKDATA(ptp
)->lpsp
->fWarnSvcStop
&& TASKDATA(ptp
)->lpcp
->fWarnSvcStop
));
327 void Services_General_OnApply (HWND hDlg
, LPIDENT lpi
)
329 LPSVC_PROP_APPLY_PACKET lpp
;
330 if ((lpp
= New (SVC_PROP_APPLY_PACKET
)) != NULL
)
333 lpp
->fIDC_SVC_WARNSTOP
= IsDlgButtonChecked (hDlg
, IDC_SVC_WARNSTOP
);
335 StartTask (taskSVC_PROP_APPLY
, hDlg
, lpp
);
340 void Services_General_OnEndTask_Apply (HWND hDlg
, LPTASKPACKET ptp
)
344 LPIDENT lpi
= (LPIDENT
)GetWindowLongPtr (hDlg
, DWLP_USER
);
346 TCHAR szSvrName
[ cchNAME
];
347 TCHAR szSvcName
[ cchNAME
];
348 lpi
->GetServerName (szSvrName
);
349 lpi
->GetServiceName (szSvcName
);
350 ErrorDialog (ptp
->status
, IDS_ERROR_CHANGE_SERVICE_STATUS
, TEXT("%s%s"), szSvrName
, szSvcName
);
355 BOOL CALLBACK
Services_BOS_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
357 if (AfsAppLib_HandleHelp (IDD_SVC_BOS
, hDlg
, msg
, wp
, lp
))
360 if (msg
== WM_INITDIALOG
)
361 SetWindowLongPtr (hDlg
, DWLP_USER
, ((LPPROPSHEETPAGE
)lp
)->lParam
);
363 LPIDENT lpi
= (LPIDENT
)GetWindowLongPtr (hDlg
, DWLP_USER
);
368 Services_BOS_OnInitDialog (hDlg
, lpi
);
373 if ((ptp
= (LPTASKPACKET
)lp
) != NULL
)
375 if (ptp
->idTask
== taskSVC_GETRESTARTTIMES
)
376 Services_BOS_OnEndTask_InitDialog (hDlg
, ptp
, lpi
);
377 FreeTaskPacket (ptp
);
389 Services_BOS_OnApply (hDlg
, lpi
);
394 Services_BOS_OnEnable (hDlg
, lpi
);
395 PropSheetChanged (hDlg
);
398 case IDC_BOS_GENRES_DATE
:
399 case IDC_BOS_GENRES_TIME
:
400 case IDC_BOS_BINRES_DATE
:
401 case IDC_BOS_BINRES_TIME
:
402 PropSheetChanged (hDlg
);
412 void Services_BOS_OnInitDialog (HWND hDlg
, LPIDENT lpi
)
414 TCHAR szText
[ cchRESOURCE
];
417 TCHAR szSvrName
[ cchNAME
];
418 TCHAR szSvcName
[ cchNAME
];
419 lpi
->GetServerName (szSvrName
);
420 lpi
->GetServiceName (szSvcName
);
422 GetDlgItemText (hDlg
, IDC_SVC_NAME
, szText
, cchRESOURCE
);
423 pszText
= FormatString (szText
, TEXT("%s%s"), szSvrName
, szSvcName
);
424 SetDlgItemText (hDlg
, IDC_SVC_NAME
, pszText
);
425 FreeString (pszText
);
427 HWND hDay
= GetDlgItem (hDlg
, IDC_BOS_GENRES_DATE
);
428 CB_StartChange (hDay
, TRUE
);
429 CB_AddItem (hDay
, IDS_RECUR_DAILY
, (WORD
)-1);
430 CB_AddItem (hDay
, IDS_RECUR_SUNDAY
, 0);
431 CB_AddItem (hDay
, IDS_RECUR_MONDAY
, 1);
432 CB_AddItem (hDay
, IDS_RECUR_TUESDAY
, 2);
433 CB_AddItem (hDay
, IDS_RECUR_WEDNESDAY
, 3);
434 CB_AddItem (hDay
, IDS_RECUR_THURSDAY
, 4);
435 CB_AddItem (hDay
, IDS_RECUR_FRIDAY
, 5);
436 CB_AddItem (hDay
, IDS_RECUR_SATURDAY
, 6);
437 CB_EndChange (hDay
, (WORD
)-1);
439 hDay
= GetDlgItem (hDlg
, IDC_BOS_BINRES_DATE
);
440 CB_StartChange (hDay
, TRUE
);
441 CB_AddItem (hDay
, IDS_RECUR_DAILY
, (WORD
)-1);
442 CB_AddItem (hDay
, IDS_RECUR_SUNDAY
, 0);
443 CB_AddItem (hDay
, IDS_RECUR_MONDAY
, 1);
444 CB_AddItem (hDay
, IDS_RECUR_TUESDAY
, 2);
445 CB_AddItem (hDay
, IDS_RECUR_WEDNESDAY
, 3);
446 CB_AddItem (hDay
, IDS_RECUR_THURSDAY
, 4);
447 CB_AddItem (hDay
, IDS_RECUR_FRIDAY
, 5);
448 CB_AddItem (hDay
, IDS_RECUR_SATURDAY
, 6);
449 CB_EndChange (hDay
, (WORD
)-1);
451 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_GENRES
), FALSE
);
452 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_BINRES
), FALSE
);
453 Services_BOS_OnEnable (hDlg
, lpi
);
455 LPSVC_RESTARTTIMES_PARAMS lpp
= New (SVC_RESTARTTIMES_PARAMS
);
456 memset (lpp
, 0x00, sizeof(SVC_RESTARTTIMES_PARAMS
));
458 StartTask (taskSVC_GETRESTARTTIMES
, hDlg
, lpp
);
462 void Services_BOS_OnEnable (HWND hDlg
, LPIDENT lpi
)
467 if (!IsWindowEnabled (GetDlgItem (hDlg
, IDC_BOS_GENRES
)))
469 else if (!IsDlgButtonChecked (hDlg
, IDC_BOS_GENRES
))
472 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_GENRES_DESC1
), fEnable
);
473 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_GENRES_DATE
), fEnable
);
474 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_GENRES_DESC2
), fEnable
);
475 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_GENRES_TIME
), fEnable
);
478 if (!IsWindowEnabled (GetDlgItem (hDlg
, IDC_BOS_BINRES
)))
480 else if (!IsDlgButtonChecked (hDlg
, IDC_BOS_BINRES
))
483 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_BINRES_DESC1
), fEnable
);
484 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_BINRES_DATE
), fEnable
);
485 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_BINRES_DESC2
), fEnable
);
486 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_BINRES_TIME
), fEnable
);
490 void Services_BOS_OnApply (HWND hDlg
, LPIDENT lpi
)
492 LPSVC_RESTARTTIMES_PARAMS lpp
= New (SVC_RESTARTTIMES_PARAMS
);
495 lpp
->fGeneral
= IsDlgButtonChecked (hDlg
, IDC_BOS_GENRES
);
496 TI_GetTime (GetDlgItem (hDlg
, IDC_BOS_GENRES_TIME
), &lpp
->stGeneral
);
497 lpp
->stGeneral
.wDayOfWeek
= (WORD
)CB_GetSelectedData (GetDlgItem (hDlg
, IDC_BOS_GENRES_DATE
));
499 lpp
->fNewBinary
= IsDlgButtonChecked (hDlg
, IDC_BOS_BINRES
);
500 TI_GetTime (GetDlgItem (hDlg
, IDC_BOS_BINRES_TIME
), &lpp
->stNewBinary
);
501 lpp
->stNewBinary
.wDayOfWeek
= (WORD
)CB_GetSelectedData (GetDlgItem (hDlg
, IDC_BOS_BINRES_DATE
));
503 StartTask (taskSVC_SETRESTARTTIMES
, NULL
, lpp
);
507 void Services_BOS_OnEndTask_InitDialog (HWND hDlg
, LPTASKPACKET ptp
, LPIDENT lpi
)
509 LPSVC_RESTARTTIMES_PARAMS lpp
= (LPSVC_RESTARTTIMES_PARAMS
)(ptp
->lpUser
);
513 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_GENRES
), TRUE
);
514 EnableWindow (GetDlgItem (hDlg
, IDC_BOS_BINRES
), TRUE
);
516 CheckDlgButton (hDlg
, IDC_BOS_GENRES
, lpp
->fGeneral
);
519 lpp
->stGeneral
.wDay
= 0;
520 lpp
->stGeneral
.wHour
= 5;
521 lpp
->stGeneral
.wMinute
= 0;
524 TI_SetTime (GetDlgItem (hDlg
, IDC_BOS_GENRES_TIME
), &lpp
->stGeneral
);
525 CB_SetSelectedByData (GetDlgItem (hDlg
, IDC_BOS_GENRES_DATE
), (LPARAM
)lpp
->stGeneral
.wDayOfWeek
);
527 CheckDlgButton (hDlg
, IDC_BOS_BINRES
, lpp
->fNewBinary
);
528 if (!lpp
->fNewBinary
)
530 lpp
->stNewBinary
.wDay
= 0;
531 lpp
->stNewBinary
.wHour
= 5;
532 lpp
->stNewBinary
.wMinute
= 0;
535 TI_SetTime (GetDlgItem (hDlg
, IDC_BOS_BINRES_TIME
), &lpp
->stNewBinary
);
536 CB_SetSelectedByData (GetDlgItem (hDlg
, IDC_BOS_BINRES_DATE
), (LPARAM
)lpp
->stNewBinary
.wDayOfWeek
);
538 Services_BOS_OnEnable (hDlg
, lpi
);