win95-initial-port-20010430
[openafs.git] / src / WINNT / afssvrmgr / svc_startstop.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include "svrmgr.h"
16 #include "svc_startstop.h"
17
18
19 /*
20  * PROTOTYPES _________________________________________________________________
21  *
22  */
23
24 typedef struct
25    {
26    LPIDENT lpi;
27    BOOL fStart;
28    BOOL fTemporary;
29    } SERVICE_STARTSTOP_PARAMS, *LPSERVICE_STARTSTOP_PARAMS;
30
31 BOOL CALLBACK Services_StartStop_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
32 void Services_StartStop_OnInitDialog (HWND hDlg, LPSERVICE_STARTSTOP_PARAMS lpp);
33 void Services_StartStop_OnOK (HWND hDlg, LPSERVICE_STARTSTOP_PARAMS lpp);
34
35
36 /*
37  * ROUTINES ___________________________________________________________________
38  *
39  */
40
41 BOOL Services_fRunning (LPSERVICE lpService)
42 {
43    SERVICESTATUS ss;
44    ULONG status;
45    if (!lpService->GetStatus (&ss, FALSE, &status))
46       return FALSE;
47
48    return (ss.state == SERVICESTATE_RUNNING) ? TRUE : FALSE;
49 }
50
51
52
53 void Services_Restart (LPIDENT lpiService)
54 {
55    StartTask (taskSVC_RESTART, NULL, lpiService);
56 }
57
58
59 void Services_Start (LPIDENT lpiService)
60 {
61    SERVICE_STARTSTOP_PARAMS dp;
62    memset (&dp, 0x00, sizeof(dp));
63    dp.lpi = lpiService;
64    dp.fStart = TRUE;
65
66    if (ModalDialogParam (IDD_SVC_STARTSTOP, NULL, (DLGPROC)Services_StartStop_DlgProc, (LPARAM)&dp) == IDOK)
67       {
68       LPSVC_START_PARAMS lpp = New (SVC_START_PARAMS);
69       memset (lpp, 0x00, sizeof(SVC_START_PARAMS));
70       lpp->lpiStart = lpiService;
71       lpp->fTemporary = dp.fTemporary;
72       StartTask (taskSVC_START, NULL, lpp);
73       }
74 }
75
76
77 void Services_Stop (LPIDENT lpiService)
78 {
79    SERVICE_STARTSTOP_PARAMS dp;
80    memset (&dp, 0x00, sizeof(dp));
81    dp.lpi = lpiService;
82    dp.fStart = FALSE;
83
84    if (ModalDialogParam (IDD_SVC_STARTSTOP, NULL, (DLGPROC)Services_StartStop_DlgProc, (LPARAM)&dp) == IDOK)
85       {
86       LPSVC_STOP_PARAMS lpp = New (SVC_STOP_PARAMS);
87       memset (lpp, 0x00, sizeof(SVC_STOP_PARAMS));
88       lpp->lpiStop = lpiService;
89       lpp->fTemporary = dp.fTemporary;
90       StartTask (taskSVC_STOP, NULL, lpp);
91       }
92 }
93
94
95 BOOL CALLBACK Services_StartStop_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
96 {
97    static LPSERVICE_STARTSTOP_PARAMS lpp = NULL;
98
99    if (lpp != NULL)
100       {
101       if (AfsAppLib_HandleHelp ((lpp->fStart) ? IDD_SVC_START : IDD_SVC_STOP, hDlg, msg, wp, lp))
102          return TRUE;
103       }
104
105    switch (msg)
106       {
107       case WM_INITDIALOG:
108          lpp = (LPSERVICE_STARTSTOP_PARAMS)lp;
109          Services_StartStop_OnInitDialog (hDlg, lpp);
110          break;
111
112       case WM_COMMAND:
113          switch (LOWORD(wp))
114             {
115             case IDOK:
116                Services_StartStop_OnOK (hDlg, lpp);
117                EndDialog (hDlg, IDOK);
118                break;
119
120             case IDCANCEL:
121                EndDialog (hDlg, IDCANCEL);
122                break;
123             }
124          break;
125       }
126
127    return FALSE;
128 }
129
130
131 void Services_StartStop_OnInitDialog (HWND hDlg, LPSERVICE_STARTSTOP_PARAMS lpp)
132 {
133    LPTSTR pszString = FormatString ((lpp->fStart) ? IDS_STARTSERVICE_TITLE : IDS_STOPSERVICE_TITLE);
134    SetWindowText (hDlg, pszString);
135    FreeString (pszString);
136
137    TCHAR szServer[ cchNAME ];
138    lpp->lpi->GetServerName (szServer);
139
140    TCHAR szService[ cchNAME ];
141    lpp->lpi->GetServiceName (szService);
142
143    pszString = FormatString ((lpp->fStart) ? IDS_STARTSERVICE_TEXT : IDS_STOPSERVICE_TEXT, TEXT("%s%s"), szServer, szService);
144    SetDlgItemText (hDlg, IDC_STARTSTOP_TEXT, pszString);
145    FreeString (pszString);
146
147    pszString = FormatString ((lpp->fStart) ? IDS_STARTSERVICE_STARTUP : IDS_STOPSERVICE_STARTUP, TEXT("%s%s"), szServer, szService);
148    SetDlgItemText (hDlg, IDC_STARTSTOP_STARTUP, pszString);
149    FreeString (pszString);
150
151    pszString = FormatString ((lpp->fStart) ? IDS_STARTSERVICE_PERMANENT : IDS_STOPSERVICE_PERMANENT, TEXT("%s%s"), szServer, szService);
152    SetDlgItemText (hDlg, IDC_STARTSTOP_PERMANENT, pszString);
153    FreeString (pszString);
154
155    pszString = FormatString ((lpp->fStart) ? IDS_STARTSERVICE_TEMPORARY : IDS_STOPSERVICE_TEMPORARY, TEXT("%s%s"), szServer, szService);
156    SetDlgItemText (hDlg, IDC_STARTSTOP_TEMPORARY, pszString);
157    FreeString (pszString);
158
159    CheckDlgButton (hDlg, IDC_STARTSTOP_PERMANENT, !lpp->fTemporary);
160    CheckDlgButton (hDlg, IDC_STARTSTOP_TEMPORARY,  lpp->fTemporary);
161 }
162
163
164 void Services_StartStop_OnOK (HWND hDlg, LPSERVICE_STARTSTOP_PARAMS lpp)
165 {
166    lpp->fTemporary = IsDlgButtonChecked (hDlg, IDC_STARTSTOP_TEMPORARY);
167 }
168