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
10 #include <afs/param.h>
19 #include "afsd_init.h"
30 char main_statusText[100];
34 HANDLE hAFSDWorkerThread[WORKER_THREADS], DoTerminate;
36 extern int traceOnPanic;
38 extern void afsd_DbgBreakAllocInit();
39 extern void afsd_DbgBreakAdd(DWORD requestNumber);
41 HANDLE WaitToTerminate = NULL;
44 * Notifier function for use by osi_panic
46 void afsd_notifier(char *msgp, char *filep, long line)
50 sprintf(tbuffer, "Error at file %s, line %d", filep, line);
52 strcpy(tbuffer, "Error at unknown location");
55 msgp = "Assertion failure";
57 MessageBox(NULL, tbuffer, msgp, MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
59 afsd_ForceTrace(TRUE);
69 /* Init function called when window application starts. Inits instance and
70 * application together, since in Win32 they're essentially the same.
72 * Function then goes into a loop handling user interface messages. Most are
73 * used to handle redrawing the icon.
77 HINSTANCE hPrevInstance,
84 afsd_SetUnhandledExceptionFilter();
87 afsd_DbgBreakAllocInit();
88 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF /* | _CRTDBG_CHECK_ALWAYS_DF */ | _CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF );
91 char *allocRequest = strtok(lpCmdLine, " \t");
94 afsd_DbgBreakAdd(atoi(allocRequest));
95 allocRequest = strtok(NULL, " \t");
100 if (!InitClass(hInstance))
103 if (!InitInstance(hInstance, nCmdShow))
106 while (GetMessage(&msg, NULL, 0, 0)) {
107 TranslateMessage(&msg);
108 DispatchMessage(&msg);
115 /* create the window type for our main window */
116 BOOL InitClass(HANDLE hInstance)
120 wc.style = CS_DBLCLKS; /* double-click messages */
121 wc.lpfnWndProc = (WNDPROC) MainWndProc;
124 wc.hInstance = hInstance;
125 wc.hIcon = LoadIcon(hInstance, "AFSDIcon");
126 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
127 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
128 wc.lpszMenuName = "AFSDMenu";
129 wc.lpszClassName = "AFSDWinClass";
131 return (RegisterClass(&wc));
134 /* initialize the process. Reads the init files to get the appropriate
142 TEXTMETRIC textmetric;
147 /* remember this, since it is a useful thing for some of the Windows
149 main_inst = hInstance;
151 /* create our window */
155 WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
169 /* lookup text dimensions */
171 GetTextMetrics(hDC, &textmetric);
172 nLineHeight = textmetric.tmExternalLeading + textmetric.tmHeight;
174 main_rect.left = GetDeviceCaps(hDC, LOGPIXELSX) / 4; /* 1/4 inch */
175 main_rect.right = GetDeviceCaps(hDC, HORZRES);
176 main_rect.top = GetDeviceCaps(hDC, LOGPIXELSY) / 4; /* 1/4 inch */
177 ReleaseDC(hWnd, hDC);
178 main_rect.bottom = main_rect.top + nLineHeight;
180 osi_InitPanic(afsd_notifier);
184 code = afsd_InitCM(&reason);
186 osi_panic(reason, __FILE__, __LINE__);
188 code = afsd_InitDaemons(&reason);
190 osi_panic(reason, __FILE__, __LINE__);
192 code = afsd_InitSMB(&reason, MessageBox);
195 osi_panic(reason, __FILE__, __LINE__);
197 ShowWindow(hWnd, SW_SHOWMINNOACTIVE);
202 /* called with no locks with translated messages */
203 LONG APIENTRY MainWndProc(
205 unsigned int message,
209 HDC hDC; /* display-context variable */
210 PAINTSTRUCT ps; /* paint structure */
216 /* block attempts to open the window */
220 /* LOWORD(wParam) is command */
221 return (DefWindowProc(hWnd, message, wParam, lParam));
227 hDC = BeginPaint (hWnd, &ps);
228 /* nothing to print, but this clears invalidated rectangle flag */
233 RpcMgmtStopServerListening(NULL);
238 return (DefWindowProc(hWnd, message, wParam, lParam));