LINUX: afs_create infinite fetchStatus loop
[pkg-k5-afs_openafs.git] / src / WINNT / client_osi / main.c
blob84bbe5e0602d5fb376a55e51fc1185f7244e9563
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 /* Copyright (C) 1994 Cazamar Systems, Inc. */
12 /****************************************************************************
14 PROGRAM: Main.c
16 PURPOSE: system test code for osi package.
18 ****************************************************************************/
21 #include <afs/param.h>
22 #include <afs/stds.h>
24 #include "windows.h"
25 #include <string.h>
26 #include "main.h"
27 #include "basic.h"
28 #include "trylock.h"
29 #include "perf.h"
30 #include "osi.h"
31 #include <assert.h>
33 /* global state for test program */
34 HANDLE hInst;
36 HWND globalWnd;
38 /* screen image */
39 char main_screenText[HW_NLINES][80];
41 /* screen display image size */
42 RECT screenRect;
44 /* height of a text line */
45 int lineHeight;
47 /****************************************************************************
49 FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
51 PURPOSE: calls initialization function, processes message loop
53 ****************************************************************************/
55 int APIENTRY WinMain(
56 HANDLE hInstance,
57 HANDLE hPrevInstance,
58 LPSTR lpCmdLine,
59 int nCmdShow
62 MSG msg;
65 if (!InitApplication(hInstance))
66 return (FALSE);
68 if (!InitInstance(hInstance, nCmdShow))
69 return (FALSE);
71 while (GetMessage(&msg, NULL, 0, 0)) {
72 TranslateMessage(&msg);
73 DispatchMessage(&msg);
75 return (msg.wParam);
79 /****************************************************************************
81 FUNCTION: InitApplication(HANDLE)
83 PURPOSE: Initializes window data and registers window class
85 ****************************************************************************/
87 BOOL InitApplication(HANDLE hInstance)
89 WNDCLASS wc;
91 /* create window class */
92 wc.style = CS_DBLCLKS; /* double-click messages */
93 wc.lpfnWndProc = (WNDPROC) MainWndProc;
94 wc.cbClsExtra = 0;
95 wc.cbWndExtra = 0;
96 wc.hInstance = hInstance;
97 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
98 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
99 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
100 wc.lpszMenuName = "InputMenu";
101 wc.lpszClassName = "InputWClass";
103 return (RegisterClass(&wc));
107 /****************************************************************************
109 FUNCTION: InitInstance(HANDLE, int)
111 PURPOSE: Saves instance handle and creates main window
113 ****************************************************************************/
115 BOOL InitInstance(
116 HANDLE hInstance,
117 INT nCmdShow)
119 HWND hWnd;
120 HDC hDC;
121 TEXTMETRIC textmetric;
122 RECT rect;
123 UUID debugID;
124 long code;
126 hInst = hInstance;
128 /* create window itself */
129 hWnd = CreateWindow(
130 "InputWClass",
131 "OSI Lock Test Application",
132 WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, /* horz & vert scroll bars */
133 CW_USEDEFAULT,
134 CW_USEDEFAULT,
135 CW_USEDEFAULT,
136 CW_USEDEFAULT,
137 NULL,
138 NULL,
139 hInstance,
140 NULL
143 if (!hWnd)
144 return (FALSE);
146 globalWnd = hWnd;
148 hDC = GetDC(hWnd);
149 GetTextMetrics(hDC, &textmetric);
150 lineHeight = textmetric.tmExternalLeading + textmetric.tmHeight;
152 rect.left = GetDeviceCaps(hDC, LOGPIXELSX) / 4; /* 1/4 inch */
153 rect.right = GetDeviceCaps(hDC, HORZRES);
154 rect.top = GetDeviceCaps(hDC, LOGPIXELSY) / 4; /* 1/4 inch */
155 ReleaseDC(hWnd, hDC);
156 rect.bottom = rect.top + HW_NLINES * lineHeight;
157 screenRect = rect;
159 /* init RPC system */
160 osi_LongToUID(1, &debugID);
161 code = osi_InitDebug(&debugID);
163 if (code == 0) wsprintf(main_screenText[0], "Initialized successfully.");
164 else wsprintf(main_screenText[0], "Failed to init debug system, code %ld", code);
166 ShowWindow(hWnd, nCmdShow);
167 UpdateWindow(hWnd);
168 return (TRUE);
172 /****************************************************************************
174 FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
176 PURPOSE: Processes messages
178 ****************************************************************************/
180 LONG APIENTRY MainWndProc(
181 HWND hWnd,
182 UINT message,
183 UINT wParam,
184 LONG lParam)
186 FARPROC lpProcAbout;
188 HDC hDC; /* display-context variable */
189 HMENU hMenu; /* menu */
190 PAINTSTRUCT ps; /* paint structure */
191 RECT rect;
192 long i;
193 long code;
195 switch (message) {
196 case WM_COMMAND:
197 if (LOWORD(wParam) == IDM_ABOUT) {
198 lpProcAbout = (FARPROC) About;
200 DialogBox(hInst,
201 "AboutBox",
202 hWnd,
203 lpProcAbout);
205 break;
207 if (LOWORD(wParam) == IDM_DEBUGON) {
208 osi_LockTypeSetDefault("stat");
209 hMenu = GetMenu(globalWnd);
210 CheckMenuItem(hMenu, IDM_DEBUGON, MF_CHECKED);
211 CheckMenuItem(hMenu, IDM_DEBUGOFF, MF_UNCHECKED);
213 if (LOWORD(wParam) == IDM_DEBUGOFF) {
214 osi_LockTypeSetDefault((char *) 0);
215 hMenu = GetMenu(globalWnd);
216 CheckMenuItem(hMenu, IDM_DEBUGON, MF_UNCHECKED);
217 CheckMenuItem(hMenu, IDM_DEBUGOFF, MF_CHECKED);
219 if (LOWORD(wParam) == IDM_BASICTEST) {
220 main_ClearDisplay();
221 wsprintf(main_screenText[0], "Starting basic test run...");
222 code = main_BasicTest(hWnd);
223 wsprintf(main_screenText[0], "Basic test returned code %d", code);
224 InvalidateRect(hWnd, &screenRect, TRUE);
226 else if (LOWORD(wParam) == IDM_PERFTEST) {
227 main_ClearDisplay();
228 wsprintf(main_screenText[0], "Starting performance test run...");
229 code = main_PerfTest(hWnd);
230 wsprintf(main_screenText[0], "Performance test returned code %d", code);
231 InvalidateRect(hWnd, &screenRect, TRUE);
233 else if (LOWORD(wParam) == IDM_TRYLOCKTEST) {
234 main_ClearDisplay();
235 wsprintf(main_screenText[0], "Starting TryLock test run...");
236 code = main_TryLockTest(hWnd);
237 wsprintf(main_screenText[0], "TryLock test returned code %d", code);
238 InvalidateRect(hWnd, &screenRect, TRUE);
240 else
241 return (DefWindowProc(hWnd, message, wParam, lParam));
242 break;
244 case WM_CHAR:
245 wsprintf(main_screenText[0], "WM_CHAR: %c, %x, %x",
246 wParam, LOWORD(lParam), HIWORD(lParam));
247 InvalidateRect(hWnd, &screenRect, TRUE);
248 break;
250 case WM_PAINT:
251 hDC = BeginPaint (hWnd, &ps);
253 if (IntersectRect(&rect, &screenRect, &ps.rcPaint)) {
254 for(i=0; i<HW_NLINES; i++) {
255 TextOut(hDC, screenRect.left, screenRect.top + i*lineHeight,
256 main_screenText[i], strlen(main_screenText[i]));
260 EndPaint(hWnd, &ps);
261 break;
263 case WM_DESTROY:
264 PostQuitMessage(0);
265 break;
267 default:
268 return (DefWindowProc(hWnd, message, wParam, lParam));
270 return (0);
274 /****************************************************************************
276 FUNCTION: About(HWND, unsigned, WORD, LONG)
278 PURPOSE: Processes messages for "About" dialog box
280 MESSAGES:
282 WM_INITDIALOG - initialize dialog box
283 WM_COMMAND - Input received
285 ****************************************************************************/
287 BOOL APIENTRY About(
288 HWND hDlg,
289 UINT message,
290 UINT wParam,
291 LONG lParam)
293 switch (message) {
294 case WM_INITDIALOG:
295 return (TRUE);
297 case WM_COMMAND:
298 if (LOWORD(wParam) == IDOK) {
299 EndDialog(hDlg, TRUE);
300 return (TRUE);
302 break;
304 return (FALSE);
305 UNREFERENCED_PARAMETER(lParam);
308 void main_ClearDisplay(void)
310 int i;
311 for(i=0; i<HW_NLINES; i++) {
312 /* make the line an empty line */
313 main_screenText[i][0] = 0;
317 void main_ForceDisplay(HANDLE hWnd)
319 HDC hDC;
320 HGDIOBJ hBrush;
321 int i;
323 hDC = GetDC(hWnd);
324 hBrush = GetStockObject(WHITE_BRUSH);
325 FillRect(hDC, &screenRect, hBrush);
326 DeleteObject(hBrush);
327 for(i=0; i<HW_NLINES; i++) {
328 TextOut(hDC, screenRect.left, screenRect.top + i*lineHeight,
329 main_screenText[i], strlen(main_screenText[i]));
331 ReleaseDC(hWnd, hDC);