Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 41013 invoked from network); 30 Jul 2010 06:51:45 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 30 Jul 2010 06:51:45 -0000 Received: (qmail 61483 invoked by uid 500); 30 Jul 2010 06:51:45 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 61421 invoked by uid 500); 30 Jul 2010 06:51:44 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 61414 invoked by uid 99); 30 Jul 2010 06:51:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Jul 2010 06:51:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Jul 2010 06:51:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 255DF2388A40; Fri, 30 Jul 2010 06:50:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r980662 [3/15] - in /commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3: ./ src/ src/assembly/ src/docs/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/commons/ src/java/org/apache/commons/daemon/ src/java/org/apache/comm... Date: Fri, 30 Jul 2010 06:50:16 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100730065019.255DF2388A40@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/lib/moni_inst.h URL: http://svn.apache.org/viewvc/commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/lib/moni_inst.h?rev=980662&view=auto ============================================================================== --- commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/lib/moni_inst.h (added) +++ commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/lib/moni_inst.h Fri Jul 30 06:50:12 2010 @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * include for the service installation + */ +#define SZAPPNAME "JavaService" +#define SZSERVICENAME "jsvc" // name of service +#define SZDEPENDENCIES "" +#define SZSERVICEDISPLAYNAME "Java Service" // name to display +#define SZKEY_ONSERVE "SOFTWARE\\apache\\jakarta\\1.0" +#define SZKEY_ONSERVEARG "SOFTWARE\\apache\\jakarta\\1.0\\arguments" +#define SZKEY_F_DIR "F_DIR" +#define SZDEFMONISVCPATH "\\vdmonisvc.exe" +#define SZCYGWINPATH "c:\\gnu" +#define SZJAKARTA_HOME "c:\\home\\jakarta" +#define SZJAVA_HOME "c:\\jdk1.3.1" Propchange: commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/lib/moni_inst.h ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/Makefile URL: http://svn.apache.org/viewvc/commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/Makefile?rev=980662&view=auto ============================================================================== --- commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/Makefile (added) +++ commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/Makefile Fri Jul 30 06:50:12 2010 @@ -0,0 +1,33 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +INCLUDE=-I../lib +BIN=../../../../dist +all: $(BIN)/vdmoniadm $(BIN)/vdmonisvc + +$(BIN)/vdmoniadm: vdmoniadm.c + gcc $(INCLUDE) -I../executables/vdmoniadm vdmoniadm.c \ + -o $(BIN)/vdmoniadm -lgdi32 +$(BIN)/vdmonisvc: vdmonisvc.c vdenv.o kills.o + gcc -mno-cygwin -I/usr/include $(INCLUDE) -I../executables/vdmonisvc \ + -DCYGWIN vdmonisvc.c \ + -o $(BIN)/vdmonisvc vdenv.o kills.o +vdenv.o: ../supcalls_nt/vdenv.c + gcc $(INCLUDE) -c ../supcalls_nt/vdenv.c +kills.o: ../signals/kills.c + gcc $(INCLUDE) -c ../signals/kills.c +clean: + rm -f vdenv.o kills.o Propchange: commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/Makefile ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/vdmoniadm.c URL: http://svn.apache.org/viewvc/commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/vdmoniadm.c?rev=980662&view=auto ============================================================================== --- commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/vdmoniadm.c (added) +++ commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/vdmoniadm.c Fri Jul 30 06:50:12 2010 @@ -0,0 +1,595 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* @version $Id: vdmoniadm.c 909069 2010-02-11 16:43:36Z mturk $ */ + +#include /* required for all Windows applications */ +#include /* for sprintf */ +#include +#include +#include +#include + +#include "resource.h" +#include "moni_inst.h" + + + +#define WINWIDTH 680 +#define WINHEIGHT 460 + +#define CLASSMAIN +#define VM_ICON_MESS WM_USER+1 +#define VM_ID_TIMER WM_USER+2 +#define VM_START_ICON WM_USER+3 +#define VM_ID_TIMER1 WM_USER+4 +#define VM_ID_TIMER2 WM_USER+5 + +BOOL InitApplication(HANDLE hInstance); + +HANDLE hInst; /* current instance */ +SC_HANDLE hManager=NULL; +SC_HANDLE hService=NULL; +int optmode; /* start, stop or check. */ +int flagdown = 0; + +#define VDMONISTART 0 +#define VDMONISTOP 1 +#define VDMONICHECK 2 + +#define NORMALWINDOW WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX +#define ICONWINDOW WS_CAPTION|WS_POPUPWINDOW|WS_MINIMIZEBOX|WS_MAXIMIZEBOX + + +/* display a message read from resources */ + +static void DisplayMess(HWND hDlg,int item) +{ +char MessBox[256]; + + if (LoadString(hInst,item,MessBox,sizeof(MessBox))) + MessageBox(hDlg, MessBox,"ERROR" , MB_OK); + else { + sprintf(MessBox,"ERROR %d",item); + MessageBox(hDlg, MessBox,"ERROR" , MB_OK); + } +} +/* + * MyTaskBarAddIcon - adds an icon to the taskbar status area. + * Returns TRUE if successful or FALSE otherwise. + * hwnd - handle of the window to receive callback messages + * uID - identifier of the icon + * hicon - handle of the icon to add + * lpszTip - ToolTip text + */ +BOOL MyTaskBarAddIcon(HWND hWnd) +{ + BOOL res; + NOTIFYICONDATA notifyicondata; + HICON hicon; + + notifyicondata.cbSize=sizeof(notifyicondata); + notifyicondata.hWnd=hWnd; + notifyicondata.uID=ID_TASKICON; + notifyicondata.uFlags= NIF_ICON|NIF_MESSAGE|NIF_TIP; + notifyicondata.uCallbackMessage=VM_ICON_MESS; + hicon = LoadIcon(hInst,"OnServe"); + notifyicondata.hIcon = hicon; + strcpy(notifyicondata.szTip,"Jakarta Service"); + + + res = Shell_NotifyIcon(NIM_ADD,¬ifyicondata); + + if (hicon) + DestroyIcon(hicon); + + return res; +} +/* + * MyTaskBarDeleteIcon - deletes an icon from the taskbar + * status area. + * Returns TRUE if successful or FALSE otherwise. + * hwnd - handle of the window that added the icon + * uID - identifier of the icon to delete + */ +BOOL MyTaskBarDeleteIcon(HWND hwnd) +{ + BOOL res; + NOTIFYICONDATA tnid; + + tnid.cbSize = sizeof(NOTIFYICONDATA); + tnid.hWnd = hwnd; + tnid.uID = ID_TASKICON; + + res = Shell_NotifyIcon(NIM_DELETE, &tnid); + return res; +} + +/* start the vdcom process */ +void StartVdcom(HWND hDlg) +{ +STARTUPINFO StartupInfo; +PROCESS_INFORMATION ProcessInformation; + + memset(&StartupInfo,'\0',sizeof(StartupInfo)); + StartupInfo.cb = sizeof(STARTUPINFO); + + if (!CreateProcess(NULL,"vdcom.exe",NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS, + NULL,NULL, &StartupInfo, &ProcessInformation)) { + DisplayMess(hDlg,CANNOT_START_VDCOM); + return; + } + /* the handle to the process */ + CloseHandle(ProcessInformation.hProcess); + CloseHandle(ProcessInformation.hThread); +} +/* start the vdconf process */ +void StartVdconf(HWND hDlg) +{ +STARTUPINFO StartupInfo; +PROCESS_INFORMATION ProcessInformation; + + memset(&StartupInfo,'\0',sizeof(StartupInfo)); + StartupInfo.cb = sizeof(STARTUPINFO); + + if (!CreateProcess(NULL,"vdconf.exe",NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS, + NULL,NULL, &StartupInfo, &ProcessInformation)) { + DisplayMess(hDlg,CANNOT_START_VDCONF); + return; + } + /* the handle to the process */ + CloseHandle(ProcessInformation.hProcess); + CloseHandle(ProcessInformation.hThread); +} + +/* test if service is running */ +BOOL IsRunning(HWND hDlg) +{ + SERVICE_STATUS svcStatus; + + if (!QueryServiceStatus(hService, &svcStatus)) { + DisplayMess(hDlg,ERROR_STATUS); + PostQuitMessage(0); + return(FALSE); + } + else { + if (SERVICE_RUNNING == svcStatus.dwCurrentState) + return(TRUE); + } + return(FALSE); + +} +/* test if service is stoppped */ +BOOL IsStopped(HWND hDlg) +{ + SERVICE_STATUS svcStatus; + + if (!QueryServiceStatus(hService, &svcStatus)) { + DisplayMess(hDlg,ERROR_STATUS); + PostQuitMessage(0); + return(FALSE); + } + else { + if (SERVICE_STOPPED == svcStatus.dwCurrentState) + return(TRUE); + } + return(FALSE); + +} +/* Yes/No dialog box */ +BOOL CALLBACK StopYesNo( + HWND hDlg, /* window handle of the dialog box */ + UINT message, /* type of message */ + WPARAM wParam, /* message-specific information */ + LPARAM lParam) +{ + SERVICE_STATUS svcStatus; + + switch (message) { + case WM_COMMAND: /* message: received a command */ + if (LOWORD(wParam) == IDOK) { /* "OK" box selected */ + if (!IsStopped(hDlg)) { + ControlService(hService, SERVICE_CONTROL_STOP, &svcStatus); + EndDialog(hDlg, TRUE); + } + else + EndDialog(hDlg, FALSE); + } + if (LOWORD(wParam) == IDCANCEL) + EndDialog(hDlg, FALSE); + return(TRUE); + } /* End switch message */ + return (FALSE); /* Didn't process a message */ + UNREFERENCED_PARAMETER(lParam); +} +/* Please wait stopping dialog box */ +BOOL CALLBACK PleaseWait( + HWND hDlg, /* window handle of the dialog box */ + UINT message, /* type of message */ + WPARAM wParam, /* message-specific information */ + LPARAM lParam) +{ + + switch (message) { + case WM_INITDIALOG: + SetTimer(hDlg,VM_ID_TIMER2,5000,NULL); /* wait 5 seconds. */ + case WM_COMMAND: /* message: received a command */ + if (LOWORD(wParam) == IDCANCEL) + EndDialog(hDlg, FALSE); + return(TRUE); + case WM_TIMER: + if(IsStopped(hDlg)) + EndDialog(hDlg, TRUE); + else + SetTimer(hDlg,VM_ID_TIMER2,5000,NULL); /* wait 5 seconds. */ + return(TRUE); + } /* End switch message */ + return (FALSE); /* Didn't process a message */ + UNREFERENCED_PARAMETER(lParam); +} +BOOL CALLBACK StartYesNo( + HWND hDlg, /* window handle of the dialog box */ + UINT message, /* type of message */ + WPARAM wParam, /* message-specific information */ + LPARAM lParam) +{ + + switch (message) { + case WM_INITDIALOG: + if (!StartService(hService,0,NULL)) { + DisplayMess(hDlg,CANNOT_START); + PostQuitMessage(0); + } + /* test if running, if not set a timer. */ + /* wait until service is start */ + if (IsRunning(hDlg)) + EndDialog(hDlg, TRUE); + else + SetTimer(hDlg,VM_ID_TIMER1,5000,NULL); /* wait 5 seconds. */ + return(TRUE); + + case WM_TIMER: + if(IsRunning(hDlg)) + EndDialog(hDlg, TRUE); + else + SetTimer(hDlg,VM_ID_TIMER1,5000,NULL); /* wait 5 seconds. */ + return(TRUE); + + case WM_COMMAND: /* message: received a command */ + if (LOWORD(wParam) == IDCANCEL) { + if (IsRunning(hDlg)) + EndDialog(hDlg, TRUE); + else + PostQuitMessage(0); + } + return(TRUE); + + } /* End switch message */ + return (FALSE); /* Didn't process a message */ + UNREFERENCED_PARAMETER(lParam); +} + +/* Display the menu */ + +void ShowMenu(HWND hWnd) +{ + HMENU hMenu,hMenu1; + POINT point; + + hMenu = LoadMenu(hInst,"MENU"); + SetMenu(hWnd,hMenu); + hMenu1 = GetSubMenu(hMenu,0); + + GetCursorPos(&point); + + SetForegroundWindow(hWnd); /* MS bug. */ + TrackPopupMenuEx(hMenu1,TPM_RIGHTALIGN|TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, + point.x,point.y,hWnd,NULL); + PostMessage(hWnd, WM_USER, 0, 0); /* MS bug. */ + DestroyMenu(hMenu); + +} +/****************************************************************************\ +* +* FUNCTION: InitInstance(HANDLE, int) +* +* PURPOSE: Saves instance handle and creates main window +* +*\***************************************************************************/ + +BOOL InitInstance( + HANDLE hInstance, /* Current instance identifier. */ + int nCmdShow) /* Param for first ShowWindow() call. */ +{ + HWND hWnd; /* Main window handle. */ + DWORD dwStyle,dwExStyle; + + + /* Save the instance handle in static variable, which will be used in */ + /* many subsequence calls from this application to Windows. */ + + hInst = hInstance; + + /* Create a main window for this application instance. */ + + if (optmode == VDMONISTART || optmode == VDMONICHECK) { + dwStyle = ICONWINDOW; + dwExStyle = WS_EX_APPWINDOW; + } + else { + dwStyle = NORMALWINDOW; + dwExStyle = 0; + } + + hWnd = CreateWindowEx( + dwExStyle, + "OnServe", /* See RegisterClass() call. */ + "OnServe Monitor Control", /* Text for window title bar. */ + dwStyle, /* Window style.*/ + CW_USEDEFAULT, /* Default horizontal position. */ + CW_USEDEFAULT, /* Default vertical position. */ + WINWIDTH, /* Windows width. */ + WINHEIGHT, /* Windows height. */ + NULL, /* Overlapped windows have no parent. */ + NULL, /* Use the window class menu. */ + hInstance, /* This instance owns this window. */ + NULL /* Pointer not needed. */ + ); + + + /* If window could not be created, return "failure" */ + + if (!hWnd) { + return (FALSE); + } + + return (TRUE); /* Returns the value from PostQuitMessage */ + +} +/****************************************************************************\ +* +* FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG) +* +* PURPOSE: Processes main window messages +* +*\***************************************************************************/ + +LRESULT CALLBACK MainWndProc( + HWND hWnd, /* window handle */ + UINT message, /* type of message */ + WPARAM wParam, /* additional information */ + LPARAM lParam) /* additional information */ +{ + SERVICE_STATUS svcStatus; + + switch (message) { + case WM_CREATE: + + /* acces to service manager. */ + hManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (hManager==NULL) { + DisplayMess(hWnd,NO_ACCESS); + PostQuitMessage(0); + break; + } + /* access to monitor service. */ + hService = OpenService(hManager, SZSERVICENAME, SERVICE_ALL_ACCESS); + if (hService==NULL) { + DisplayMess(hWnd,NO_ACCESS_MONI); + PostQuitMessage(0); + break; + } + /* check if running. */ + if (QueryServiceStatus(hService, &svcStatus)) { + /* and see if the service is stopped */ + if (SERVICE_STOPPED == svcStatus.dwCurrentState && + optmode == VDMONISTOP) { + DisplayMess(hWnd,ALREADY_STOP); + PostQuitMessage(0); + break; + } + else if (SERVICE_RUNNING == svcStatus.dwCurrentState && + optmode == VDMONISTART) { + DisplayMess(hWnd,ALREADY_START); + PostQuitMessage(0); + break; + } + + } + else { + DisplayMess(hWnd,ERROR_STATUS); + PostQuitMessage(0); + break; + } + + /* DialogBoxes Yes/No */ + if (optmode == VDMONISTART) + DialogBox(hInst, /* current instance */ + "StartYesNo", /* resource to use */ + hWnd, /* parent handle */ + StartYesNo); /* instance address */ + else if (optmode == VDMONISTOP) + if (DialogBox(hInst,"StopYesNo",hWnd,StopYesNo)) + DialogBox(hInst,"PleaseWait",hWnd,PleaseWait); + + + if (optmode == VDMONISTOP) + PostQuitMessage(0); + else { + SetTimer(hWnd,VM_ID_TIMER,5000,NULL); + MyTaskBarAddIcon(hWnd); + } + + break; /* WM_CREATE */ + + case VM_ICON_MESS: + switch ((UINT)lParam) { + case WM_LBUTTONDBLCLK: + StartVdcom(hWnd); + break; + case WM_RBUTTONDOWN: + flagdown = 1; + break; + case WM_RBUTTONUP: + if (flagdown == 1) { + flagdown = 2; + /* show a menu. */ + ShowMenu(hWnd); + } + break; + } + break; + + + case WM_TIMER: + /* check if service is running */ + if (QueryServiceStatus(hService, &svcStatus)) { + /* and see if the service is stopped */ + if (SERVICE_STOPPED == svcStatus.dwCurrentState) { + MyTaskBarDeleteIcon(hWnd); + PostQuitMessage(0); + } + SetTimer(hWnd,VM_ID_TIMER,5000,NULL); + return(0); + } + break; + + case VM_START_ICON: + /* add the icon and timer. */ + MyTaskBarAddIcon(hWnd); + SetTimer(hWnd,VM_ID_TIMER,5000,NULL); + break; + + case WM_COMMAND: + /* command for the popup menu. */ + switch (LOWORD(wParam)) { + case ID_START_VDCOM: + StartVdcom(hWnd); + break; + case ID_STOP_VDMONI: + if (DialogBox(hInst,"StopYesNo",hWnd,StopYesNo)) + DialogBox(hInst,"PleaseWait",hWnd,PleaseWait); + break; + case ID_PROPRETY: + StartVdconf(hWnd); + break; + + } + break; + + /* + * Clean up. + */ + case WM_DESTROY: + if (hService!=NULL) + CloseServiceHandle(hService); + if (hManager!=NULL) + CloseServiceHandle(hManager); + PostQuitMessage(0); + break; + + default: /* Passes it on if unproccessed */ + return (DefWindowProc(hWnd, message, wParam, lParam)); + + } + return (0); + +} + +/**************************************************************************** +* +* FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int) +* +* PURPOSE: calls initialization function, processes message loop +* +*\***************************************************************************/ + +WINAPI WinMain( + HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow + ) +{ + + MSG msg; + + UNREFERENCED_PARAMETER( lpCmdLine ); + if (strcmp(lpCmdLine,"start")==0) + optmode = VDMONISTART; + else if (strcmp(lpCmdLine,"stop")==0) + optmode = VDMONISTOP; + else + optmode = VDMONICHECK; + + if (!hPrevInstance) /* Other instances of app running? */ + if (!InitApplication(hInstance)) /* Initialize shared things */ + return (FALSE); /* Exits if unable to initialize */ + + /* + * Perform initializations that apply to a specific instance + */ + if (!InitInstance(hInstance, nCmdShow)) + return (FALSE); + + /* + * Acquire and dispatch messages until a WM_QUIT message is received. + */ + while (GetMessage(&msg, /* message structure */ + NULL, /* handle of window receiving the message */ + 0, /* lowest message to examine */ + 0)) /* highest message to examine */ + { + TranslateMessage(&msg); /* Translates virtual key codes */ + DispatchMessage(&msg); /* Dispatches message to window */ + } + return (msg.wParam); /* Returns the value from PostQuitMessage */ +} + +/**************************************************************************** +* +* FUNCTION: InitApplication(HANDLE) +* +* PURPOSE: Initializes window data and registers window class +* +*\***************************************************************************/ + +BOOL InitApplication(HANDLE hInstance) /* current instance */ +{ + WNDCLASS wc; + + /* Fill in window class structure with parameters that describe the */ + /* main window. */ + + wc.style = 0; /* Class style(s). */ + wc.lpfnWndProc = MainWndProc; /* Function to retrieve messages for */ + /* windows of this class. */ + wc.cbClsExtra = 0; /* No per-class extra data. */ + wc.cbWndExtra = 0; /* No per-window extra data. */ + wc.hIcon = LoadIcon (hInstance, "onserve"); /* Icon name from .RC */ + wc.hInstance = hInstance; /* Application that owns the class. */ + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = GetStockObject(WHITE_BRUSH); + wc.lpszMenuName = "onservemenu"; /* Name of menu resource in .RC file. */ + wc.lpszClassName = "OnServe"; /* Name used in call to CreateWindow. */ + + /* Register the window class and return success/failure code. */ + + return (RegisterClass(&wc)); + +} + Propchange: commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/vdmoniadm.c ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/vdmonisvc.c URL: http://svn.apache.org/viewvc/commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/vdmonisvc.c?rev=980662&view=auto ============================================================================== --- commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/vdmonisvc.c (added) +++ commons/proper/daemon/tags/COMMONS_DAEMON_1_0_3_RC3/src/native/nt/moni/vdmonisvc.c Fri Jul 30 06:50:12 2010 @@ -0,0 +1,708 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* @version $Id: vdmonisvc.c 909069 2010-02-11 16:43:36Z mturk $ */ + +/* jsvc monitor service module: + * Implements the body of the service. + * It reads the register entry and starts the jsvc. + */ + +#include +#include +#include +#include +#include +#include +#ifdef CYGWIN +#else +#include +#endif +#include "moni_inst.h" + +/* globals */ +SERVICE_STATUS ssStatus; +SERVICE_STATUS_HANDLE sshStatusHandle; +DWORD dwErr; +HANDLE hServerStopEvent = NULL; +HANDLE hMonitorProcess = NULL; + +/* + * NT/other detection + * from src/os/win32/service.c (httpd-1.3!). + */ + +BOOL isWindowsNT(void) +{ + static BOOL once = FALSE; + static BOOL isNT = FALSE; + + if (!once) + { + OSVERSIONINFO osver; + osver.dwOSVersionInfoSize = sizeof(osver); + if (GetVersionEx(&osver)) + if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT) + isNT = TRUE; + once = TRUE; + } + return isNT; +} + +/* Event logger routine */ + +VOID AddToMessageLog(LPTSTR lpszMsg) +{ + TCHAR szMsg[256]; + HANDLE hEventSource; + LPCTSTR lpszStrings[2]; + + + dwErr = GetLastError(); + + /* Use event logging to log the error. */ + + if (isWindowsNT()) + hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME)); + else + hEventSource = NULL; + +#ifdef CYGWIN + sprintf(szMsg, TEXT("%s ERROR: %d"), TEXT(SZSERVICENAME), dwErr); +#else + _stprintf(szMsg, TEXT("%s ERROR: %d"), TEXT(SZSERVICENAME), dwErr); +#endif + lpszStrings[0] = szMsg; + lpszStrings[1] = lpszMsg; + + if (hEventSource != NULL) { + ReportEvent(hEventSource, /* handle of event source */ + EVENTLOG_ERROR_TYPE, /* event type */ + 0, /* event category */ + 0, /* event ID */ + NULL, /* current user's SID */ + 2, /* strings in lpszStrings */ + 0, /* no bytes of raw data */ + lpszStrings, /* array of error strings */ + NULL); /* no raw data */ + + (VOID) DeregisterEventSource(hEventSource); + } else { + /* Default to a trace file */ + FILE *log; + log = fopen("c:/jakarta-service.log","a+"); + if (log != NULL) { + struct tm *newtime; + time_t long_time; + + time( &long_time ); + newtime = localtime( &long_time ); + + if (dwErr) + fprintf(log,"%.24s:%s: %s\n",asctime(newtime),szMsg, lpszMsg); + else + fprintf(log,"%.24s: %s\n",asctime(newtime), lpszMsg); + fclose(log); + } + } +} + +/* + * + * FUNCTION: ServiceStop + * + * PURPOSE: Stops the service + * + * PARAMETERS: + * none + * + * RETURN VALUE: + * none + * + * COMMENTS: + * If a ServiceStop procedure is going to + * take longer than 3 seconds to execute, + * it should spawn a thread to execute the + * stop code, and return. Otherwise, the + * ServiceControlManager will believe that + * the service has stopped responding. + * + */ +VOID ServiceStop() +{ + if ( hServerStopEvent ) + SetEvent(hServerStopEvent); +} + +/* + * Wait for the monitor process to stop + */ +int WaitForMonitor(int num) +{ + DWORD qreturn; + int i; + + for (i=0;i