more-rx-updates-20060504
[openafs.git] / src / WINNT / afssvrmgr / svr_syncvldb.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 #include <winsock2.h>
11 #include <ws2tcpip.h>
12
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
16 }
17
18 #include "svrmgr.h"
19 #include "svr_syncvldb.h"
20 #include "propcache.h"
21
22
23 /*
24  * DEFINITIONS ________________________________________________________________
25  *
26  */
27
28
29 /*
30  * PROTOTYPES _________________________________________________________________
31  *
32  */
33
34 BOOL CALLBACK Server_SyncVLDB_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
35 void Server_SyncVLDB_OnInitDialog (HWND hDlg, LPIDENT lpi);
36 void Server_SyncVLDB_OnOK (HWND hDlg, LPIDENT lpi);
37 void Server_SyncVLDB_OnEndTask_Init (HWND hDlg, LPTASKPACKET ptp);
38
39
40 /*
41  * ROUTINES ___________________________________________________________________
42  *
43  */
44
45 void Server_SyncVLDB (LPIDENT lpi)
46 {
47    HWND hCurrent;
48    if ((hCurrent = PropCache_Search (pcSVR_SYNCVLDB, lpi)) != NULL)
49       {
50       SetFocus (hCurrent);
51       }
52    else
53       {
54       ModelessDialogParam (IDD_SVR_SYNCVLDB, NULL, (DLGPROC)Server_SyncVLDB_DlgProc, (LPARAM)lpi);
55       }
56 }
57
58
59 BOOL CALLBACK Server_SyncVLDB_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
60 {
61    if (AfsAppLib_HandleHelp (IDD_SVR_SYNCVLDB, hDlg, msg, wp, lp))
62       return TRUE;
63
64    if (msg == WM_INITDIALOG)
65       SetWindowLongPtr (hDlg, DWLP_USER, lp);
66
67    LPIDENT lpi;
68    if ((lpi = (LPIDENT)GetWindowLongPtr (hDlg, DWLP_USER)) != NULL)
69       {
70       switch (msg)
71          {
72          case WM_INITDIALOG:
73             PropCache_Add (pcSVR_SYNCVLDB, lpi, hDlg);
74             Server_SyncVLDB_OnInitDialog (hDlg, lpi);
75             break;
76
77          case WM_ENDTASK:
78             LPTASKPACKET ptp;
79             if ((ptp = (LPTASKPACKET)lp) != NULL)
80                {
81                if (ptp->idTask == taskAGG_FIND_GHOST)
82                   Server_SyncVLDB_OnEndTask_Init (hDlg, ptp);
83                FreeTaskPacket (ptp);
84                }
85             break;
86
87          case WM_COMMAND:
88             switch (LOWORD(wp))
89                {
90                case IDOK:
91                   Server_SyncVLDB_OnOK (hDlg, lpi);
92                   DestroyWindow (hDlg);
93                   break;
94
95                case IDCANCEL:
96                   DestroyWindow (hDlg);
97                   break;
98                }
99             break;
100
101          case WM_DESTROY:
102             PropCache_Delete (pcSVR_SYNCVLDB, lpi);
103             break;
104          }
105       }
106
107    return FALSE;
108 }
109
110
111 void Server_SyncVLDB_OnInitDialog (HWND hDlg, LPIDENT lpi)
112 {
113    if (lpi->fIsServer())
114       {
115       TCHAR szServer[ cchNAME ];
116       lpi->GetServerName (szServer);
117
118       LPTSTR pszText = FormatString (IDS_SYNCVLDB_SVR_DESC, TEXT("%s"), szServer);
119       SetDlgItemText (hDlg, IDC_SYNC_DESC, pszText);
120       FreeString (pszText);
121       pszText = FormatString (IDS_SYNCVLDB_SVR_DESC2, TEXT("%s"), szServer);
122       SetDlgItemText (hDlg, IDC_SYNC_DESC2, pszText);
123       FreeString (pszText);
124
125       ShowWindow (hDlg, SW_SHOW);
126       }
127    else // (lpi->fIsAggregate())
128       {
129       TCHAR szServer[ cchNAME ];
130       lpi->GetServerName (szServer);
131       TCHAR szAggregate[ cchNAME ];
132       lpi->GetAggregateName (szAggregate);
133
134       LPTSTR pszText = FormatString (IDS_SYNCVLDB_AGG_DESC, TEXT("%s%s"), szServer, szAggregate);
135       SetDlgItemText (hDlg, IDC_SYNC_DESC, pszText);
136       FreeString (pszText);
137       pszText = FormatString (IDS_SYNCVLDB_AGG_DESC2, TEXT("%s%s"), szServer, szAggregate);
138       SetDlgItemText (hDlg, IDC_SYNC_DESC2, pszText);
139       FreeString (pszText);
140
141       StartTask (taskAGG_FIND_GHOST, hDlg, lpi);
142       }
143 }
144
145
146 void Server_SyncVLDB_OnEndTask_Init (HWND hDlg, LPTASKPACKET ptp)
147 {
148    if (ptp->rc && (!(TASKDATA(ptp)->wGhost & GHOST_HAS_SERVER_ENTRY)))
149       {
150       LPIDENT lpi = (LPIDENT)( ptp->lpUser );
151
152       TCHAR szServer[ cchNAME ];
153       lpi->GetServerName (szServer);
154       TCHAR szAggregate[ cchNAME ];
155       lpi->GetAggregateName (szAggregate);
156
157       ErrorDialog (0, IDS_ERROR_CANT_SYNC_GHOST_AGGREGATE, TEXT("%s%s"), szServer, szAggregate);
158       DestroyWindow (hDlg);
159       return;
160       }
161
162    ShowWindow (hDlg, SW_SHOW);
163 }
164
165
166 void Server_SyncVLDB_OnOK (HWND hDlg, LPIDENT lpi)
167 {
168    LPSVR_SYNCVLDB_PARAMS lpp = New (SVR_SYNCVLDB_PARAMS);
169    lpp->lpi = (LPIDENT)GetWindowLongPtr (hDlg, DWLP_USER);
170    lpp->fForce = TRUE;
171    StartTask (taskSVR_SYNCVLDB, NULL, lpp);
172 }
173