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 extern int traceOnPanic;
36 extern void afsd_DbgBreakAllocInit();
37 extern void afsd_DbgBreakAdd(DWORD requestNumber);
39 HANDLE WaitToTerminate = NULL;
42 * Notifier function for use by osi_panic
44 void afsd_notifier(char *msgp, char *filep, long line)
48 sprintf(tbuffer, "Error at file %s, line %d", filep, line);
50 strcpy(tbuffer, "Error at unknown location");
53 msgp = "Assertion failure";
55 MessageBox(NULL, tbuffer, msgp, MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
57 afsd_ForceTrace(TRUE);
67 /* Init function called when window application starts. Inits instance and
68 * application together, since in Win32 they're essentially the same.
70 * Function then goes into a loop handling user interface messages. Most are
71 * used to handle redrawing the icon.
75 HINSTANCE hPrevInstance,
81 afsd_SetUnhandledExceptionFilter();
84 afsd_DbgBreakAllocInit();
85 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF /* | _CRTDBG_CHECK_ALWAYS_DF */ | _CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF );
88 char *allocRequest = strtok(lpCmdLine, " \t");
91 afsd_DbgBreakAdd(atoi(allocRequest));
92 allocRequest = strtok(NULL, " \t");
97 if (!InitClass(hInstance))
100 if (!InitInstance(hInstance, nCmdShow))
103 while (GetMessage(&msg, NULL, 0, 0)) {
104 TranslateMessage(&msg);
105 DispatchMessage(&msg);
111 /* create the window type for our main window */
112 BOOL InitClass(HANDLE hInstance)
116 wc.style = CS_DBLCLKS; /* double-click messages */
117 wc.lpfnWndProc = (WNDPROC) MainWndProc;
120 wc.hInstance = hInstance;
121 wc.hIcon = LoadIcon(hInstance, "AFSDIcon");
122 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
123 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
124 wc.lpszMenuName = "AFSDMenu";
125 wc.lpszClassName = "AFSDWinClass";
127 return (RegisterClass(&wc));
130 /* initialize the process. Reads the init files to get the appropriate
138 TEXTMETRIC textmetric;
143 /* remember this, since it is a useful thing for some of the Windows
145 main_inst = hInstance;
147 /* create our window */
151 WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
165 /* lookup text dimensions */
167 GetTextMetrics(hDC, &textmetric);
168 nLineHeight = textmetric.tmExternalLeading + textmetric.tmHeight;
170 main_rect.left = GetDeviceCaps(hDC, LOGPIXELSX) / 4; /* 1/4 inch */
171 main_rect.right = GetDeviceCaps(hDC, HORZRES);
172 main_rect.top = GetDeviceCaps(hDC, LOGPIXELSY) / 4; /* 1/4 inch */
173 ReleaseDC(hWnd, hDC);
174 main_rect.bottom = main_rect.top + nLineHeight;
176 osi_InitPanic(afsd_notifier);
180 code = afsd_InitCM(&reason);
182 osi_panic(reason, __FILE__, __LINE__);
184 code = afsd_InitDaemons(&reason);
186 osi_panic(reason, __FILE__, __LINE__);
188 code = afsd_InitSMB(&reason, MessageBox);
190 osi_panic(reason, __FILE__, __LINE__);
192 ShowWindow(hWnd, SW_SHOWMINNOACTIVE);
197 /* called with no locks with translated messages */
198 LONG APIENTRY MainWndProc(
200 unsigned int message,
204 HDC hDC; /* display-context variable */
205 PAINTSTRUCT ps; /* paint structure */
211 /* block attempts to open the window */
215 /* LOWORD(wParam) is command */
216 return (DefWindowProc(hWnd, message, wParam, lParam));
222 hDC = BeginPaint (hWnd, &ps);
223 /* nothing to print, but this clears invalidated rectangle flag */
228 RpcMgmtStopServerListening(NULL);
233 return (DefWindowProc(hWnd, message, wParam, lParam));