diff options
author | nobody <nobody@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-04-10 19:59:37 +0000 |
---|---|---|
committer | nobody <nobody@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-04-10 19:59:37 +0000 |
commit | 3df4acfa816441fc28a95dee6d0191a927145d95 (patch) | |
tree | b5ae7ca44662cfd8e5c95f1826e4406021a606f5 /examples/NT_Service | |
parent | 60a5612b83d856fc0adc52b9f39fac9960ec9818 (diff) | |
download | ATCD-pre-subset.tar.gz |
This commit was manufactured by cvs2svn to create tag 'pre-subset'.pre-subset
Diffstat (limited to 'examples/NT_Service')
-rw-r--r-- | examples/NT_Service/Makefile | 41 | ||||
-rw-r--r-- | examples/NT_Service/Makefile.bor | 19 | ||||
-rw-r--r-- | examples/NT_Service/NT_Service.dsp | 100 | ||||
-rw-r--r-- | examples/NT_Service/NT_Service.dsw | 29 | ||||
-rw-r--r-- | examples/NT_Service/README | 45 | ||||
-rw-r--r-- | examples/NT_Service/main.cpp | 258 | ||||
-rw-r--r-- | examples/NT_Service/ntsvc.cpp | 111 | ||||
-rw-r--r-- | examples/NT_Service/ntsvc.h | 63 |
8 files changed, 0 insertions, 666 deletions
diff --git a/examples/NT_Service/Makefile b/examples/NT_Service/Makefile deleted file mode 100644 index 9a6d67bf8e9..00000000000 --- a/examples/NT_Service/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -#---------------------------------------------------------------------------- -# $Id$ -# -# Makefile for NT_Service -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# Local macros -#---------------------------------------------------------------------------- - -BIN = ntsvc - -SRC = main.cpp ntsvc.cpp - -LDLIBS = - -VLDLIBS = $(LDLIBS:%=%$(VAR)) - -BUILD = $(VBIN) - -INSTALL = - -#---------------------------------------------------------------------------- -# Include macros and targets -#---------------------------------------------------------------------------- - -include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU -include $(ACE_ROOT)/include/makeinclude/macros.GNU -include $(ACE_ROOT)/include/makeinclude/rules.common.GNU -include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU -include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU -include $(ACE_ROOT)/include/makeinclude/rules.local.GNU - -#---------------------------------------------------------------------------- -# Local targets -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# Dependencies -#---------------------------------------------------------------------------- -# DO NOT DELETE THIS LINE -- g++dep uses it. diff --git a/examples/NT_Service/Makefile.bor b/examples/NT_Service/Makefile.bor deleted file mode 100644 index a754d2cfac7..00000000000 --- a/examples/NT_Service/Makefile.bor +++ /dev/null @@ -1,19 +0,0 @@ -# -# Makefile for building the NT_Service ace examples -# - -NAME = NT_Service - -OBJFILES = \ - $(OBJDIR)\main.obj \ - $(OBJDIR)\ntsvc.obj - -CFLAGS = \ - $(ACE_CFLAGS) - -LIBFILES = \ - $(ACE_LIB) - -CPPDIR = . - -!include <$(ACE_ROOT)\include\makeinclude\build_exe.bor> diff --git a/examples/NT_Service/NT_Service.dsp b/examples/NT_Service/NT_Service.dsp deleted file mode 100644 index 87e39617333..00000000000 --- a/examples/NT_Service/NT_Service.dsp +++ /dev/null @@ -1,100 +0,0 @@ -# Microsoft Developer Studio Project File - Name="NT_Service" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=NT_Service - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "NT_Service.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "NT_Service.mak" CFG="NT_Service - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "NT_Service - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "NT_Service - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "NT_Service - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 ace.lib user32.lib advapi32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\ace"
-
-!ELSEIF "$(CFG)" == "NT_Service - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 aced.lib user32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\ace"
-
-!ENDIF
-
-# Begin Target
-
-# Name "NT_Service - Win32 Release"
-# Name "NT_Service - Win32 Debug"
-# Begin Source File
-
-SOURCE=.\main.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\ntsvc.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\ntsvc.h
-# End Source File
-# End Target
-# End Project
diff --git a/examples/NT_Service/NT_Service.dsw b/examples/NT_Service/NT_Service.dsw deleted file mode 100644 index 62b238d990d..00000000000 --- a/examples/NT_Service/NT_Service.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "NT_Service"=.\NT_Service.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/examples/NT_Service/README b/examples/NT_Service/README deleted file mode 100644 index a1d4175e126..00000000000 --- a/examples/NT_Service/README +++ /dev/null @@ -1,45 +0,0 @@ -$Id$ - -How to use the NT_Service example. - -The NT_Service program has the following usage: -in -r -s -k -tn -d - -i: Install this program as an NT service, with specified startup - -r: Remove this program from the Service Manager - -s: Start the service - -k: Kill the service - -t: Set startup for an existing service - -d: Debug; run as a regular application - -In order to see different stages of an NT service application, -you have to run the program several times, with different options. -Please note: run with only one option at a time. - -1. Make executable NT_Service. - -2. First, you must initialize the service in the NT SCM database. - Run NT_Service with -in, where n is one of the following startup options: - - // - // Start Type (from WinNT.h) - // - #define SERVICE_SYSTEM_START 0x00000001 - #define SERVICE_AUTO_START 0x00000002 - #define SERVICE_DEMAND_START 0x00000003 - #define SERVICE_DISABLED 0x00000004 - - If only -i is specified, SERVICE_AUTO_START is default option. - -3. Now you are ready to run the actual service. Run NT_Service again, - this time with -s option. If the service starts successfully, it will - ring the system bell every second or so until the service is stopped. - -4. To stop service execution, run NT_Service with the -k option. - -5. To remove the service from the Service Control Manager database, run - NT_Service with -r. - -In addition, once you have initialized this service (by using the -i option) -you can change its startup type to one of the other values above. To do -this, run NT_Service with -tn option. n is as explained above for -i. - -In order to debug the service's execution itself, use the -d option. diff --git a/examples/NT_Service/main.cpp b/examples/NT_Service/main.cpp deleted file mode 100644 index 6c8d51fea73..00000000000 --- a/examples/NT_Service/main.cpp +++ /dev/null @@ -1,258 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// examples/NT_Service -// -// = FILENAME -// main.cpp -// -// = DESCRIPTION -// This is the main program - it just hands control off to the -// process instance to figure out what to do. This program only -// runs on Win32. -// -// = AUTHOR -// Gonzalo Diethelm <gonzo@cs.wustl.edu> -// and Steve Huston <shuston@riverace.com> -// -// ============================================================================ - -#include "ace/Get_Opt.h" -#include "ntsvc.h" - -// Default for the -i (install) option -#define DEFAULT_SERVICE_INIT_STARTUP SERVICE_AUTO_START - -class Process -{ -public: - Process (void); - ~Process (void); - - int run(int argc, ACE_TCHAR* argv[]); - -private: - void parse_args (int argc, - ACE_TCHAR* argv[]); - void print_usage_and_die (void); - -private: - char progname[128]; - - int opt_install; - int opt_remove; - int opt_start; - int opt_kill; - int opt_type; - int opt_debug; - - int opt_startup; -}; - -typedef ACE_Singleton<Process, ACE_Mutex> PROCESS; - -Process::Process (void) - : opt_install (0), - opt_remove (0), - opt_start (0), - opt_kill (0), - opt_type (0), - opt_debug (0), - opt_startup (0) -{ - ACE_OS::strcpy (progname, - "service"); - ACE::init (); -} - -Process::~Process (void) -{ - ACE::fini (); -} - -void -Process::print_usage_and_die (void) -{ - ACE_DEBUG ((LM_INFO, - "Usage: %s" - " -in -r -s -k -tn -d\n" - " -i: Install this program as an NT service, with specified startup\n" - " -r: Remove this program from the Service Manager\n" - " -s: Start the service\n" - " -k: Kill the service\n" - " -t: Set startup for an existing service\n" - " -d: Debug; run as a regular application\n", - progname, - 0)); - ACE_OS::exit(1); -} - -void -Process::parse_args (int argc, ACE_TCHAR* argv[]) -{ - ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("i:rskt:d")); - int c; - - while ((c = get_opt ()) != -1) - switch (c) - { - case 'i': - opt_install = 1; - opt_startup = ACE_OS::atoi (get_opt.opt_arg ()); - if (opt_startup <= 0) - print_usage_and_die (); - break; - case 'r': - opt_remove = 1; - break; - case 's': - opt_start = 1; - break; - case 'k': - opt_kill = 1; - break; - case 't': - opt_type = 1; - opt_startup = ACE_OS::atoi (get_opt.opt_arg ()); - if (opt_startup <= 0) - print_usage_and_die (); - break; - case 'd': - opt_debug = 1; - break; - default: - // -i can also be given without a value - if so, it defaults - // to defined value. - if (ACE_OS::strcmp (get_opt.argv ()[get_opt.opt_ind () - 1], ACE_TEXT ("-i")) == 0) - { - opt_install = 1; - opt_startup = DEFAULT_SERVICE_INIT_STARTUP; - } - else - { - print_usage_and_die (); - } - break; - } -} - -// Define a function to handle Ctrl+C to cleanly shut this down. - -static BOOL __stdcall -ConsoleHandler (DWORD ctrlType) -{ - ACE_UNUSED_ARG (ctrlType); - SERVICE::instance ()->handle_control (SERVICE_CONTROL_STOP); - return TRUE; -} - -ACE_NT_SERVICE_DEFINE (Beeper, - Service, - ACE_TEXT ("Annoying Beeper Service")); - -int -Process::run (int argc, ACE_TCHAR* argv[]) -{ - SERVICE::instance ()->name (ACE_TEXT ("Beeper"), - ACE_TEXT ("Annoying Beeper Service")); - - parse_args (argc, argv); - - if (opt_install && !opt_remove) - { - if (-1 == SERVICE::instance ()->insert (opt_startup)) - { - ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("insert"))); - return -1; - } - return 0; - } - - if (opt_remove && !opt_install) - { - if (-1 == SERVICE::instance ()->remove ()) - { - ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("remove"))); - return -1; - } - return 0; - } - - if (opt_start && opt_kill) - print_usage_and_die (); - - if (opt_start) - { - if (-1 == SERVICE::instance ()->start_svc ()) - { - ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("start"))); - return -1; - } - return 0; - } - - if (opt_kill) - { - if (-1 == SERVICE::instance ()->stop_svc ()) - { - ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("stop"))); - return -1; - } - return 0; - } - - if (opt_type) - { - if (-1 == SERVICE::instance ()->startup (opt_startup)) - { - ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("set startup"))); - return -1; - } - return 0; - } - - // If we get here, we either run the app in debug mode (-d) or are - // being called from the service manager to start the service. - - if (opt_debug) - { - SetConsoleCtrlHandler (&ConsoleHandler, 1); - SERVICE::instance ()->svc (); - } - else - { - ofstream *output_file = new ofstream("ntsvc.log", ios::out); - if (output_file && output_file->rdstate() == ios::goodbit) - ACE_LOG_MSG->msg_ostream(output_file, 1); - ACE_LOG_MSG->open(argv[0], - ACE_Log_Msg::STDERR | ACE_Log_Msg::OSTREAM, - 0); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%T (%t): Starting service.\n"))); - - ACE_NT_SERVICE_RUN (Beeper, - SERVICE::instance (), - ret); - if (ret == 0) - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("%p\n"), - ACE_TEXT ("Couldn't start service"))); - else - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%T (%t): Service stopped.\n"))); - } - - return 0; -} - -int -ACE_TMAIN (int argc, ACE_TCHAR* argv[]) -{ - return PROCESS::instance ()->run (argc, argv); -} - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Singleton<Process, ACE_Mutex>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Singleton<Process, ACE_Mutex> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/examples/NT_Service/ntsvc.cpp b/examples/NT_Service/ntsvc.cpp deleted file mode 100644 index d872769bc46..00000000000 --- a/examples/NT_Service/ntsvc.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// examples/NT_Service -// -// = FILENAME -// ntsvc.cpp -// -// = DESCRIPTION -// This is the implementation of the NT service. It beeps every 2 -// seconds until the service is stopped. -// -// = AUTHOR -// Gonzalo Diethelm <gonzo@cs.wustl.edu> -// and Steve Huston <shuston@riverace.com> -// -// ============================================================================ - -#include "ace/OS.h" -#include "ace/Reactor.h" -#include "ntsvc.h" - -Service::Service (void) -{ - // Remember the Reactor instance. - reactor (ACE_Reactor::instance ()); - - // Schedule a timer every two seconds. - ACE_Time_Value tv (2, 0); - ACE_Reactor::instance ()->schedule_timer (this, 0, tv, tv); -} - -// This method is called when the service gets a control request. It -// handles requests for stop and shutdown by calling terminate (). -// All others get handled by calling up to inherited::handle_control. - -void -Service::handle_control (DWORD control_code) -{ - if (control_code == SERVICE_CONTROL_SHUTDOWN - || control_code == SERVICE_CONTROL_STOP) - { - report_status (SERVICE_STOP_PENDING); - - ACE_DEBUG ((LM_INFO, - "Service control stop requested\n")); - stop_ = 1; - reactor ()->notify (this, - ACE_Event_Handler::EXCEPT_MASK); - } - else - inherited::handle_control (control_code); -} - -// This is just here to be the target of the notify from above... it -// doesn't do anything except aid on popping the reactor off its wait -// and causing a drop out of handle_events. - -int -Service::handle_exception (ACE_HANDLE) -{ - return 0; -} - -// Beep every two seconds. This is what this NT service does... - -int -Service::handle_timeout (const ACE_Time_Value &tv, - const void *) -{ - ACE_UNUSED_ARG (tv); - MessageBeep (MB_OK); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%T (%t): Beep...\n"))); - return 0; -} - -// This is the main processing function for the Service. It sets up -// the initial configuration and runs the event loop until a shutdown -// request is received. - -int -Service::svc (void) -{ - ACE_DEBUG ((LM_DEBUG, - "Service::svc\n")); - - // As an NT service, we come in here in a different thread than the - // one which created the reactor. So in order to do anything, we - // need to own the reactor. If we are not a service, report_status - // will return -1. - if (report_status (SERVICE_RUNNING) == 0) - reactor ()->owner (ACE_Thread::self ()); - - stop_ = 0; - - while (!stop_) - reactor ()->handle_events (); - - // Cleanly terminate connections, terminate threads. - ACE_DEBUG ((LM_DEBUG, - "Shutting down\n")); - return 0; -} - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Singleton<Service, ACE_Mutex>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Singleton<Service, ACE_Mutex> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/examples/NT_Service/ntsvc.h b/examples/NT_Service/ntsvc.h deleted file mode 100644 index 28b7ede02bf..00000000000 --- a/examples/NT_Service/ntsvc.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// examples/NT_Service -// -// = FILENAME -// ntsvc.h -// -// = DESCRIPTION -// This is the definition of the sample NT Service class. This example -// only runs on Win32 platforms. -// -// = AUTHOR -// Gonzalo Diethelm and Steve Huston -// -// ============================================================================ - -#ifndef NTSVC_H_ -#define NTSVC_H_ - -#include "ace/Event_Handler.h" -#include "ace/NT_Service.h" -#include "ace/Singleton.h" -#include "ace/Synch.h" - -class Service : public ACE_NT_Service -{ -public: - Service (void); - - virtual void handle_control (DWORD control_code); - // We override <handle_control> because it handles stop requests - // privately. - - virtual int handle_exception (ACE_HANDLE h); - // We override <handle_exception> so a 'stop' control code can pop - // the reactor off of its wait. - - virtual int svc (void); - // This is a virtual method inherited from ACE_NT_Service. - - virtual int handle_timeout (const ACE_Time_Value& tv, - const void *arg = 0); - // Where the real work is done: - -private: - typedef ACE_NT_Service inherited; - -private: - int stop_; -}; - -// Define a singleton class as a way to insure that there's only one -// Service instance in the program, and to protect against access from -// multiple threads. The first reference to it at runtime creates it, -// and the ACE_Object_Manager deletes it at run-down. - -typedef ACE_Singleton<Service, ACE_Mutex> SERVICE; - -#endif /* #ifndef NTSVC_H_ */ |