From b3a0de3416e93c43f5acaef8b1670fdb7f07f305 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 15 May 2010 19:31:19 +0000 Subject: [PATCH] 2010-05-15 21:27 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * doc/howtosvn.txt + Made it more clear that 'Chr(36)' should be replaced by '$'. * ChangeLog ! Stripped accented char. Pls keep all files in 7-bit mode. * contrib/hbwin/hbwin.ch * contrib/hbwin/win_srv.c * contrib/hbwin/tests/testsrv.prg ! Cleanup fixes: ! Fixed missing SVN props (pls see howtosvn.txt and my e-mail today about them) ! Fixed SVN header ! Stripped accented char. ! Deleted . ! Tabs converted to spaces. ! Fixed indentation and formatting. % Optimized code to have less redundancy. ! Fixed name of static vars. % Made callbacks static. ! Fixed hbwin.ch constants to have WIN_ prefix. ! Fixed references to unknown functions in test code. % Test code reworked to have user selectable modes via cmdline parameter. ! Fixed to define all functions also in WinCE mode, but with dummy functionality. ! Fixed memory potential leak in WIN_SERVICEDELETE(). ! Added some casts. % Variables declarations moved to inner scopes. ; TOFIX: - UNICODE build problem in hbwin_SrvFunction(). - possible memory corruption in WIN_SERVICESTART()? - 'implicit declaration of function 'Sets_ServiceStatus'' in hbwin_SrvFunction(). ; All the above are shown as mingw warnings. --- harbour/ChangeLog | 42 +- harbour/contrib/hbwin/hbwin.ch | 20 +- harbour/contrib/hbwin/tests/testsrv.prg | 223 +++++---- harbour/contrib/hbwin/win_srv.c | 577 ++++++++++++------------ harbour/doc/howtosvn.txt | 4 +- 5 files changed, 448 insertions(+), 418 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index af177d38a7..d0f1d91ef9 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,40 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-05-15 21:27 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * doc/howtosvn.txt + + Made it more clear that 'Chr(36)' should be replaced by '$'. + + * ChangeLog + ! Stripped accented char. Pls keep all files in 7-bit mode. + + * contrib/hbwin/hbwin.ch + * contrib/hbwin/win_srv.c + * contrib/hbwin/tests/testsrv.prg + ! Cleanup fixes: + ! Fixed missing SVN props (pls see howtosvn.txt and my e-mail today about them) + ! Fixed SVN header + ! Stripped accented char. + ! Deleted . + ! Tabs converted to spaces. + ! Fixed indentation and formatting. + % Optimized code to have less redundancy. + ! Fixed name of static vars. + % Made callbacks static. + ! Fixed hbwin.ch constants to have WIN_ prefix. + ! Fixed references to unknown functions in test code. + % Test code reworked to have user selectable modes via cmdline parameter. + ! Fixed to define all functions also in WinCE mode, but + with dummy functionality. + ! Fixed memory potential leak in WIN_SERVICEDELETE(). + ! Added some casts. + % Variables declarations moved to inner scopes. + ; TOFIX: + - UNICODE build problem in hbwin_SrvFunction(). + - possible memory corruption in WIN_SERVICESTART()? + - 'implicit declaration of function 'Sets_ServiceStatus'' in hbwin_SrvFunction(). + ; All the above are shown as mingw warnings. + 2010-15-15 12:20 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbqt/hbqt_hbqplaintextedit.cpp ! Fixed: selection with Sh+Left was not working ok. @@ -34,18 +68,18 @@ * contrib/hbide/ideeditor.prg ! Fixed: the artifacts reported by Mindaugas and Itamar. ! Optimized: C++ code. - ! Fixed: many other artifacts, i.e., status-bar panel was wrongly + ! Fixed: many other artifacts, i.e., status-bar panel was wrongly reporting selection mode. Mindaugas, can you please test again ? -2010-05-15 20:02 UTC+0200 José Luis Capel (jlcapel at hotmail . com) +2010-05-15 20:02 UTC+0200 Jose Luis Capel (jlcapel at hotmail . com) + contrib/hbwin/win_srv.c + contrib/hbwin/tests/testsrv.prg * contrib/hbwin/hbwin.ch * contrib/hbwin/Makefile - + Basical support for running a harbour application as a windows server. - See tests/testsrv.prg. + + Basical support for running a harbour application as a windows server. + See tests/testsrv.prg. 2010-05-15 20:02 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/hbwin/olecore.c diff --git a/harbour/contrib/hbwin/hbwin.ch b/harbour/contrib/hbwin/hbwin.ch index a0cf347945..f4df3ee207 100644 --- a/harbour/contrib/hbwin/hbwin.ch +++ b/harbour/contrib/hbwin/hbwin.ch @@ -645,17 +645,15 @@ #define WIN_EVENTLOG_AUDIT_SUCCESS 0x0008 #define WIN_EVENTLOG_AUDIT_FAILURE 0x0010 - -/* Windows Service defines */ -#define SERVICE_NO_CHANGE 0xffffffff -#define SERVICE_STOPPED 1 -#define SERVICE_START_PENDING 2 -#define SERVICE_STOP_PENDING 3 -#define SERVICE_RUNNING 4 -#define SERVICE_CONTINUE_PENDING 5 -#define SERVICE_PAUSE_PENDING 6 -#define SERVICE_PAUSED 7 - +/* WIN_SERVICEGETSTATUS() return values */ +#define WIN_SERVICE_NO_CHANGE 0xFFFFFFFF +#define WIN_SERVICE_STOPPED 1 +#define WIN_SERVICE_START_PENDING 2 +#define WIN_SERVICE_STOP_PENDING 3 +#define WIN_SERVICE_RUNNING 4 +#define WIN_SERVICE_CONTINUE_PENDING 5 +#define WIN_SERVICE_PAUSE_PENDING 6 +#define WIN_SERVICE_PAUSED 7 /* ------------------------------- */ /* Deprecated constants and macros */ diff --git a/harbour/contrib/hbwin/tests/testsrv.prg b/harbour/contrib/hbwin/tests/testsrv.prg index a6b737556b..ef8c9f3f7c 100644 --- a/harbour/contrib/hbwin/tests/testsrv.prg +++ b/harbour/contrib/hbwin/tests/testsrv.prg @@ -1,112 +1,111 @@ -/* - * Chr(36) + "Id" + Chr(36) - */ - -/* - * Harbour Project source code: - * Windows Service - * - * Copyright 2010 José Luis Capel - - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - - -#include "hbtrace.ch" -#include "hbwin.ch" - - -/* Uncomment this piece of code to install this service (should be called via consola) */ - -PROCEDURE Main - - IF WIN_SERVICEInstall("HarbourService","Win32 Harbour Service") - Alert("Service has been successfully installed") - ELSE - Alert("Error installing service :" + STR( GETLASTERROR() )) - ENDIf - RETURN - - -/* Uncomment this piece of code to de-install this service (should be called via consola) - -PROCEDURE Main - - IF WIN_SERVICEDelete("HarbourService") - Alert("Service has been deleted") - ELSE - Alert("Error deleting service :" + STR( hb_SrvGetLastError()) ) - ENDIf - RETURN -*/ - -/* Uncomment this piece of code to be called by SCM (not via console) - -PROCEDURE Main - - IF !WIN_SERVICESTART("HarbourService","SRVMAIN") - HB_TRACE(HB_TR_INFO, "Service has worked Ok") - ELSE - HB_TRACE(HB_TR_ERROR, "Service has had som problems : "+ STR( hb_SrvGetLastError()) - ENDIf - - RETURN -*/ - -/* -FUNCTION SrvMain() - - LOCAL n - - n := 1 - DO WHILE WIN_SERVICEGETSTATUS() == SERVICE_RUNNING - HB_TRACE(HB_TR_INFO, "Work in progress " + STR(n)) - n := n + 1 - Inkey(0.1) - ENDDO - - - WIN_SERVICESETEXITCODE( 0 ) - WIN_SERVICESTOP() - - RETURN NIL -*/ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Windows Service + * + * Copyright 2010 Jose Luis Capel - + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbtrace.ch" +#include "hbwin.ch" + +#include "common.ch" + +#define _SERVICE_NAME "HarbourService" + +/* Uncomment this piece of code to install this service (should be called via consola) */ + +PROCEDURE Main( cMode ) + + DEFAULT cMode TO "I" + + SWITCH Upper( cMode ) + CASE "I" + + IF win_serviceInstall( _SERVICE_NAME, "Win32 Harbour Service" ) + Alert( "Service has been successfully installed" ) + ELSE + Alert( "Error installing service:" + hb_ntos( wapi_GetLastError() ) ) + ENDIf + EXIT + + CASE "U" + + IF win_serviceDelete( _SERVICE_NAME ) + Alert( "Service has been deleted" ) + ELSE + Alert( "Error deleting service:" + hb_ntos( wapi_GetLastError() ) ) + ENDIf + EXIT + + CASE "S" + + IF win_serviceStart( _SERVICE_NAME, "SrvMain" ) + HB_TRACE( HB_TR_INFO, "Service has worked Ok" ) + ELSE + HB_TRACE( HB_TR_ERROR, "Service has had som problems : " + hb_ntos( wapi_GetLastError() ) ) + ENDIF + EXIT + + ENDSWITCH + + RETURN + +FUNCTION SrvMain() + LOCAL n + + n := 1 + DO WHILE win_serviceGetStatus() == WIN_SERVICE_RUNNING + HB_TRACE( HB_TR_INFO, "Work in progress " + hb_ntos( n ) ) + n := n + 1 + Inkey( 0.1 ) + ENDDO + + win_serviceSetExitCode( 0 ) + win_serviceStop() + + RETURN NIL diff --git a/harbour/contrib/hbwin/win_srv.c b/harbour/contrib/hbwin/win_srv.c index 27c8fa28b6..fa407099f9 100644 --- a/harbour/contrib/hbwin/win_srv.c +++ b/harbour/contrib/hbwin/win_srv.c @@ -1,288 +1,289 @@ -/* - * Chr(36) + "Id" + Chr(36) - */ - -/* - * Harbour Project source code: - * Windows Service - * - * Copyright 2010 José Luis Capel - - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#include -#include "hbapi.h" -#include "hbvm.h" -#include "hbwinuni.h" -#include "hbwapi.h" - -#if ! defined( HB_OS_WIN_CE ) - - -static SERVICE_STATUS ServiceStatus; -static SERVICE_STATUS_HANDLE hStatus; -static char *sPrgFunction; -static char *sSrvName; - -void hbwin_ControlHandler(DWORD request); -void hbwin_SrvFunction(int argc, char** argv); - - -HB_FUNC( WIN_SERVICEGETSTATUS ) -{ - hb_retnl( ServiceStatus.dwCurrentState ); -} - - -HB_FUNC( WIN_SERVICESETSTATUS ) /* dwStatus */ -{ - ServiceStatus.dwCurrentState = (DWORD) hb_parnl(1); - hb_retl( SetServiceStatus( hStatus, &ServiceStatus ) ); -} - -HB_FUNC( WIN_SERVICESETEXITCODE ) /* dwExitCode */ -{ - ServiceStatus.dwWin32ExitCode = (DWORD) hb_parnl(1); - hb_retl( SetServiceStatus( hStatus, &ServiceStatus ) ); -} - -HB_FUNC( WIN_SERVICESTOP ) -{ - ServiceStatus.dwCurrentState = SERVICE_STOPPED; - SetServiceStatus( hStatus, &ServiceStatus ); -} - - -HB_FUNC( WIN_SERVICEINSTALL ) /* sServiceName, sServiceNameDisplayed */ -{ - SC_HANDLE schSCM; - SC_HANDLE schSrv; - TCHAR szPath[MAX_PATH]; - LPCTSTR lpServiceName,lpDisplayName; - void * hServiceName; - void * hDisplayName; - - - if( !GetModuleFileName( NULL, szPath, MAX_PATH ) ) - { - hbwapi_SetLastError( GetLastError() ) ; - hb_retl( HB_FALSE ); /* Check GetLastError */ - return; - } - - - schSCM = OpenSCManager(NULL, NULL,SC_MANAGER_ALL_ACCESS); - if( schSCM == NULL ) - { - hbwapi_SetLastError( GetLastError() ) ; - hb_retl( HB_FALSE ); /* Check GetLastError */ - return; - } - - - lpServiceName = HB_PARSTR( 1, &hServiceName, NULL ); - lpDisplayName = HB_PARSTR( 2, &hDisplayName, NULL ); - - schSrv = CreateService( schSCM, /* SCM database */ - lpServiceName, /* name of service */ - lpDisplayName, /* service name to display */ - SERVICE_ALL_ACCESS, /* desired access */ - SERVICE_WIN32_OWN_PROCESS, /* service type */ - SERVICE_DEMAND_START, /* start type */ - SERVICE_ERROR_NORMAL, /* error control type */ - szPath, /* path to service's binary */ - NULL, /* no load ordering group */ - NULL, /* no tag identifier */ - NULL, /* no dependencies */ - NULL, /* LocalSystem account */ - NULL ); /* no password */ - - hb_strfree( hServiceName ); - hb_strfree( hDisplayName ); - - if( schSrv == NULL ) - { - CloseServiceHandle( schSCM ); - hbwapi_SetLastError( GetLastError() ) ; - hb_retl( HB_FALSE ); /* Check GetLastError */ - return; - } - - CloseServiceHandle( schSrv ); - CloseServiceHandle( schSCM ); - hb_retl( HB_TRUE ); -} - - -HB_FUNC( WIN_SERVICEDELETE ) /* sServiceName */ -{ - SC_HANDLE schSCM; - SC_HANDLE schSrv; - void * hschSCM; - - schSCM = OpenSCManager( NULL, NULL,SC_MANAGER_ALL_ACCESS ); - if( schSCM == NULL ) - { - hbwapi_SetLastError( GetLastError() ) ; - hb_retl( HB_FALSE ); /* Check GetLastError */ - return; - } - - schSrv = OpenService( schSCM, HB_PARSTR( 1, &hschSCM, NULL ), SERVICE_ALL_ACCESS ); - if( schSrv== NULL ) - { - CloseServiceHandle( schSCM ); - hbwapi_SetLastError( GetLastError() ) ; - hb_retl( HB_FALSE ); /* Check GetLastError */ - return; - } - - /* - TODO: check if service is up and then stop it - */ - - hb_strfree( hschSCM ); - hb_retl( DeleteService( schSrv ) ); - CloseServiceHandle( schSrv ); - CloseServiceHandle( schSCM ); -} - - - -HB_FUNC( WIN_SERVICESTART ) /* sServiceName, sPrgFunction */ -{ - SERVICE_TABLE_ENTRY ServiceTable[2]; - LPTSTR lpServiceName, lpPrgFunction; - void * hServiceName; - void * hPrgFunction; - - lpServiceName = (LPTSTR) HB_PARSTR( 1, &hServiceName, NULL ); - lpPrgFunction = (LPTSTR) HB_PARSTR( 2, &hPrgFunction, NULL ); - - - ServiceTable[0].lpServiceName = lpServiceName; - ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)hbwin_SrvFunction; - - ServiceTable[1].lpServiceName = NULL; - ServiceTable[1].lpServiceProc = NULL; - - sPrgFunction = lpPrgFunction; - sSrvName = lpServiceName; - - hb_strfree( hServiceName ); - hb_strfree( hPrgFunction ); - - hb_retl( StartServiceCtrlDispatcher( ServiceTable ) ); - -} - - -/* Control handler function */ -void hbwin_ControlHandler( DWORD request ) -{ - switch( request ) - { - case SERVICE_CONTROL_STOP: - ServiceStatus.dwWin32ExitCode = 0; - ServiceStatus.dwCurrentState = SERVICE_STOPPED; - return; - - case SERVICE_CONTROL_SHUTDOWN: - ServiceStatus.dwWin32ExitCode = 0; - ServiceStatus.dwCurrentState = SERVICE_STOPPED; - return; - - default: - break; - } - - /* Report current status */ - SetServiceStatus( hStatus, &ServiceStatus ); -} - - -void hbwin_SrvFunction( int argc, char** argv ) -{ - HB_SYMBOL_UNUSED( argc ); - HB_SYMBOL_UNUSED( argv ); - - ServiceStatus.dwServiceType = SERVICE_WIN32; - ServiceStatus.dwCurrentState = SERVICE_START_PENDING; - ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; - ServiceStatus.dwWin32ExitCode = 0; - ServiceStatus.dwServiceSpecificExitCode = 0; - ServiceStatus.dwCheckPoint = 0; - ServiceStatus.dwWaitHint = 0; - - hStatus = RegisterServiceCtrlHandler( sSrvName, (LPHANDLER_FUNCTION) hbwin_ControlHandler ); - - if( hStatus == (SERVICE_STATUS_HANDLE) 0 ) - { - HB_TRACE( HB_TR_DEBUG, ( "Error registering service\n" ) ); - return; - } - - /* We report the running status to SCM. */ - ServiceStatus.dwCurrentState = SERVICE_RUNNING; - SetServiceStatus( hStatus, &ServiceStatus ); - - - PHB_DYNS pDynSym; - pDynSym = hb_dynsymFindName( sPrgFunction ); - if( pDynSym ) - { - if( hb_vmRequestReenter() ) - { - hb_vmPushSymbol( hb_dynsymSymbol( pDynSym ) ); - hb_vmPushNil(); - hb_vmDo(0); - hb_vmRequestRestore(); - } - } - - return; - -} - - -#endif +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Windows Service + * + * Copyright 2010 Jose Luis Capel - + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbvm.h" +#include "hbwinuni.h" + +#include "hbwapi.h" + +#if ! defined( HB_OS_WIN_CE ) + +static SERVICE_STATUS s_ServiceStatus; +static SERVICE_STATUS_HANDLE s_hStatus; +static char * s_pszPrgFunction; +static char * s_pszSrvName; + +static void hbwin_ControlHandler( DWORD request ); +static void hbwin_SrvFunction( int argc, char ** argv ); + +/* Control handler function */ +static void hbwin_ControlHandler( DWORD request ) +{ + switch( request ) + { + case SERVICE_CONTROL_STOP: + s_ServiceStatus.dwWin32ExitCode = 0; + s_ServiceStatus.dwCurrentState = SERVICE_STOPPED; + return; + + case SERVICE_CONTROL_SHUTDOWN: + s_ServiceStatus.dwWin32ExitCode = 0; + s_ServiceStatus.dwCurrentState = SERVICE_STOPPED; + return; + } + + /* Report current status */ + Sets_ServiceStatus( s_hStatus, &s_ServiceStatus ); +} + +static void hbwin_SrvFunction( int argc, char** argv ) +{ + HB_SYMBOL_UNUSED( argc ); + HB_SYMBOL_UNUSED( argv ); + + s_ServiceStatus.dwServiceType = SERVICE_WIN32; + s_ServiceStatus.dwCurrentState = SERVICE_START_PENDING; + s_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; + s_ServiceStatus.dwWin32ExitCode = 0; + s_ServiceStatus.dwServiceSpecificExitCode = 0; + s_ServiceStatus.dwCheckPoint = 0; + s_ServiceStatus.dwWaitHint = 0; + + s_hStatus = RegisterServiceCtrlHandler( s_pszSrvName, ( LPHANDLER_FUNCTION ) hbwin_ControlHandler ); + + if( s_hStatus == ( SERVICE_STATUS_HANDLE ) 0 ) + { + HB_TRACE( HB_TR_DEBUG, ( "Error registering service\n" ) ); + } + else + { + PHB_DYNS pDynSym = hb_dynsymFindName( s_pszPrgFunction ); + + /* We report the running status to SCM. */ + s_ServiceStatus.dwCurrentState = SERVICE_RUNNING; + Sets_ServiceStatus( s_hStatus, &s_ServiceStatus ); + + if( pDynSym ) + { + if( hb_vmRequestReenter() ) + { + hb_vmPushSymbol( hb_dynsymSymbol( pDynSym ) ); + hb_vmPushNil(); + hb_vmDo( 0 ); + hb_vmRequestRestore(); + } + } + } +} + +#endif + +HB_FUNC( WIN_SERVICEGETSTATUS ) +{ +#if ! defined( HB_OS_WIN_CE ) + hb_retnl( s_ServiceStatus.dwCurrentState ); +#else + hb_retnl( 0 ); +#endif +} + +HB_FUNC( WIN_SERVICESETSTATUS ) /* dwStatus */ +{ +#if ! defined( HB_OS_WIN_CE ) + s_ServiceStatus.dwCurrentState = ( DWORD ) hb_parnl( 1 ); + hb_retl( Sets_ServiceStatus( s_hStatus, &s_ServiceStatus ) ); +#else + hb_retl( HB_FALSE ); +#endif +} + +HB_FUNC( WIN_SERVICESETEXITCODE ) /* dwExitCode */ +{ +#if ! defined( HB_OS_WIN_CE ) + s_ServiceStatus.dwWin32ExitCode = ( DWORD ) hb_parnl( 1 ); + hb_retl( Sets_ServiceStatus( s_hStatus, &s_ServiceStatus ) ); +#else + hb_retl( HB_FALSE ); +#endif +} + +HB_FUNC( WIN_SERVICESTOP ) +{ +#if ! defined( HB_OS_WIN_CE ) + s_ServiceStatus.dwCurrentState = SERVICE_STOPPED; + Sets_ServiceStatus( s_hStatus, &s_ServiceStatus ); +#endif +} + +HB_FUNC( WIN_SERVICEINSTALL ) +{ + HB_BOOL bRetVal = HB_FALSE; +#if ! defined( HB_OS_WIN_CE ) + TCHAR szPath[ MAX_PATH ]; + + if( GetModuleFileName( NULL, szPath, MAX_PATH ) ) + { + SC_HANDLE schSCM = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS ); + + if( schSCM ) + { + SC_HANDLE schSrv; + + void * hServiceName; + void * hDisplayName; + + LPCTSTR lpServiceName = HB_PARSTR( 1, &hServiceName, NULL ); + LPCTSTR lpDisplayName = HB_PARSTR( 2, &hDisplayName, NULL ); + + schSrv = CreateService( schSCM, /* SCM database */ + lpServiceName, /* name of service */ + lpDisplayName, /* service name to display */ + SERVICE_ALL_ACCESS, /* desired access */ + SERVICE_WIN32_OWN_PROCESS, /* service type */ + SERVICE_DEMAND_START, /* start type */ + SERVICE_ERROR_NORMAL, /* error control type */ + szPath, /* path to service's binary */ + NULL, /* no load ordering group */ + NULL, /* no tag identifier */ + NULL, /* no dependencies */ + NULL, /* LocalSystem account */ + NULL ); /* no password */ + + hb_strfree( hServiceName ); + hb_strfree( hDisplayName ); + + if( schSrv ) + { + bRetVal = HB_TRUE; + + CloseServiceHandle( schSrv ); + } + else + hbwapi_SetLastError( GetLastError() ); + + CloseServiceHandle( schSCM ); + } + else + hbwapi_SetLastError( GetLastError() ); + } + else + hbwapi_SetLastError( GetLastError() ); + +#endif + hb_retl( bRetVal ); +} + +HB_FUNC( WIN_SERVICEDELETE ) /* sServiceName */ +{ + HB_BOOL bRetVal = HB_FALSE; +#if ! defined( HB_OS_WIN_CE ) + SC_HANDLE schSCM = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS ); + + if( schSCM ) + { + void * hschSCM; + + SC_HANDLE schSrv = OpenService( schSCM, + HB_PARSTR( 1, &hschSCM, NULL ), + SERVICE_ALL_ACCESS ); + + if( schSrv ) + { + /* TODO: check if service is up and then stop it */ + + bRetVal = ( HB_BOOL ) DeleteService( schSrv ); + + CloseServiceHandle( schSrv ); + } + else + hbwapi_SetLastError( GetLastError() ); + + hb_strfree( hschSCM ); + + CloseServiceHandle( schSCM ); + } + else + hbwapi_SetLastError( GetLastError() ); +#endif + hb_retl( bRetVal ); +} + +HB_FUNC( WIN_SERVICESTART ) /* pszServiceName, pszPrgFunction */ +{ +#if ! defined( HB_OS_WIN_CE ) + SERVICE_TABLE_ENTRY ServiceTable[ 2 ]; + LPTSTR lpServiceName; + LPTSTR lpPrgFunction; + void * hServiceName; + void * hPrgFunction; + + lpServiceName = ( LPTSTR ) HB_PARSTR( 1, &hServiceName, NULL ); + lpPrgFunction = ( LPTSTR ) HB_PARSTR( 2, &hPrgFunction, NULL ); + + ServiceTable[ 0 ].lpServiceName = lpServiceName; + ServiceTable[ 0 ].lpServiceProc = ( LPSERVICE_MAIN_FUNCTION ) hbwin_SrvFunction; + + ServiceTable[ 1 ].lpServiceName = NULL; + ServiceTable[ 1 ].lpServiceProc = NULL; + + s_pszPrgFunction = lpPrgFunction; + s_pszSrvName = lpServiceName; + + hb_strfree( hServiceName ); + hb_strfree( hPrgFunction ); + + hb_retl( ( HB_BOOL ) StartServiceCtrlDispatcher( ServiceTable ) ); +#else + hb_retl( HB_FALSE ); +#endif +} diff --git a/harbour/doc/howtosvn.txt b/harbour/doc/howtosvn.txt index ba0b5035ba..e95ba0117c 100644 --- a/harbour/doc/howtosvn.txt +++ b/harbour/doc/howtosvn.txt @@ -183,9 +183,7 @@ To add one to a file lacking it simply put as first lines: * Chr(36) + "Id" + Chr(36) */ -I can't write it here because SVN server would change it as soon as I -commit this file, but second line should not have Chr(36) but $ signs -and no spaces between dollar sign and Id. +IMPORTANT: In real code, replaces 'Chr(36)' with '$' signes. as soon as you commit your file SVN ID string will be expanded by SVN server to full length.