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
9 /* AFSIFS Portions copyright (c) 2005
10 * the regents of the university of michigan
13 * permission is granted to use, copy, create derivative works and
14 * redistribute this software and such derivative works for any purpose,
15 * so long as the name of the university of michigan is not used in
16 * any advertising or publicity pertaining to the use or distribution
17 * of this software without specific, written prior authorization. if
18 * the above copyright notice or any other identification of the
19 * university of michigan is included in any copy of any portion of
20 * this software, then the disclaimer below must also be included.
22 * this software is provided as is, without representation from the
23 * university of michigan as to its fitness for any purpose, and without
24 * warranty by the university of michigan of any kind, either express
25 * or implied, including without limitation the implied warranties of
26 * merchantability and fitness for a particular purpose. the regents
27 * of the university of michigan shall not be liable for any damages,
28 * including special, indirect, incidental, or consequential damages,
29 * with respect to any claim arising out or in connection with the use
30 * of the software, even if it has been or is hereafter advised of the
31 * possibility of such damages.
34 #include <afs/param.h>
43 #include "afsd_init.h"
56 char main_statusText[100];
60 HANDLE hAFSDWorkerThread[WORKER_THREADS], DoTerminate;
62 extern int traceOnPanic;
64 extern void afsd_DbgBreakAllocInit();
65 extern void afsd_DbgBreakAdd(DWORD requestNumber);
67 HANDLE WaitToTerminate = NULL;
70 * Notifier function for use by osi_panic
72 void afsd_notifier(char *msgp, char *filep, long line)
76 sprintf(tbuffer, "Error at file %s, line %d", filep, line);
78 strcpy(tbuffer, "Error at unknown location");
81 msgp = "Assertion failure";
83 MessageBox(NULL, tbuffer, msgp, MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
85 afsd_ForceTrace(TRUE);
95 /* Init function called when window application starts. Inits instance and
96 * application together, since in Win32 they're essentially the same.
98 * Function then goes into a loop handling user interface messages. Most are
99 * used to handle redrawing the icon.
103 HINSTANCE hPrevInstance,
110 afsd_SetUnhandledExceptionFilter();
113 afsd_DbgBreakAllocInit();
114 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF /* | _CRTDBG_CHECK_ALWAYS_DF */ | _CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF );
117 char *allocRequest = strtok(lpCmdLine, " \t");
120 afsd_DbgBreakAdd(atoi(allocRequest));
121 allocRequest = strtok(NULL, " \t");
126 if (!InitClass(hInstance))
129 if (!InitInstance(hInstance, nCmdShow))
132 while (GetMessage(&msg, NULL, 0, 0)) {
133 TranslateMessage(&msg);
134 DispatchMessage(&msg);
138 WaitForMultipleObjects(WORKER_THREADS, hAFSDWorkerThread, TRUE, INFINITE);
139 for (i = 0; i < WORKER_THREADS; i++)
140 CloseHandle(hAFSDWorkerThread[i]);
141 //CloseHandle(hAFSDMainThread);
142 RpcMgmtStopServerListening(NULL);
149 /* create the window type for our main window */
150 BOOL InitClass(HANDLE hInstance)
154 wc.style = CS_DBLCLKS; /* double-click messages */
155 wc.lpfnWndProc = (WNDPROC) MainWndProc;
158 wc.hInstance = hInstance;
159 wc.hIcon = LoadIcon(hInstance, "AFSDIcon");
160 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
161 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
162 wc.lpszMenuName = "AFSDMenu";
163 wc.lpszClassName = "AFSDWinClass";
165 return (RegisterClass(&wc));
168 /* initialize the process. Reads the init files to get the appropriate
176 TEXTMETRIC textmetric;
181 /* remember this, since it is a useful thing for some of the Windows
183 main_inst = hInstance;
185 /* create our window */
189 WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
203 /* lookup text dimensions */
205 GetTextMetrics(hDC, &textmetric);
206 nLineHeight = textmetric.tmExternalLeading + textmetric.tmHeight;
208 main_rect.left = GetDeviceCaps(hDC, LOGPIXELSX) / 4; /* 1/4 inch */
209 main_rect.right = GetDeviceCaps(hDC, HORZRES);
210 main_rect.top = GetDeviceCaps(hDC, LOGPIXELSY) / 4; /* 1/4 inch */
211 ReleaseDC(hWnd, hDC);
212 main_rect.bottom = main_rect.top + nLineHeight;
214 osi_InitPanic(afsd_notifier);
218 code = afsd_InitCM(&reason);
220 osi_panic(reason, __FILE__, __LINE__);
222 code = afsd_InitDaemons(&reason);
224 osi_panic(reason, __FILE__, __LINE__);
227 code = afsd_InitSMB(&reason, MessageBox);
229 code = ifs_Init(&reason);
233 osi_panic(reason, __FILE__, __LINE__);
236 DoTerminate = CreateEvent(NULL, TRUE, FALSE, TEXT("afsd_service_DoTerminate"));
237 if ( GetLastError() == ERROR_ALREADY_EXISTS )
238 afsi_log("Event Object Already Exists: %s", TEXT("afsd_service_DoTerminate"));
239 for (cnt = 0; cnt < WORKER_THREADS; cnt++)
240 hAFSDWorkerThread[cnt] = CreateThread(NULL, 0, ifs_MainLoop, 0, 0, NULL);
243 ShowWindow(hWnd, SW_SHOWMINNOACTIVE);
248 /* called with no locks with translated messages */
249 LONG APIENTRY MainWndProc(
251 unsigned int message,
255 HDC hDC; /* display-context variable */
256 PAINTSTRUCT ps; /* paint structure */
262 /* block attempts to open the window */
266 /* LOWORD(wParam) is command */
267 return (DefWindowProc(hWnd, message, wParam, lParam));
273 hDC = BeginPaint (hWnd, &ps);
274 /* nothing to print, but this clears invalidated rectangle flag */
280 SetEvent(DoTerminate);
282 RpcMgmtStopServerListening(NULL);
287 return (DefWindowProc(hWnd, message, wParam, lParam));