OmniEvents
daemon_windows.h
Go to the documentation of this file.
1 // Package : omniEvents
2 // daemon_windows.h Created : 2004/07/30
3 // Author : Alex Tingle
4 //
5 // Copyright (C) 2004 Alex Tingle.
6 //
7 // This file is part of the omniEvents application.
8 //
9 // omniEvents is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // omniEvents is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 
24 #ifndef OMNIEVENTS__DAEMON_WINDOWS_H
25 #define OMNIEVENTS__DAEMON_WINDOWS_H
26 
27 #ifndef __WIN32__
28 # error("This file is only intended for Windows.")
29 #endif
30 
31 #include <windows.h>
32 #include <winsvc.h>
33 #include <iostream>
34 
35 namespace OmniEvents {
36 
40 class Service
41 {
42 public:
43  Service();
44  ~Service();
45 
46  void start(int& argc,char**& argv);
47 
48  void tracefile(const char* val);
49  void pidfile(const char* val);
50  void foreground(bool val);
51 
53  void daemonize();
54 
56  void runningOk();
57 
59  void shutdown();
60 
61  // Callbacks.
62 
64  static void log(const char* message);
65 
67  static void ctrlHandler(DWORD controlCode);
68 
69 private:
70  char* _tracefile;
71  const char* _regSubKey;
74  char* _parameters;
75  char** _argv;
76  std::ostream* _logstream;
77  SERVICE_STATUS_HANDLE _serviceStatusHandle;
78 
79  void Service::setArgcArgv(int& argc,char**& argv);
80  void install(int argc,char** argv) const;
81  void uninstall() const;
82 
84  void readParameters();
86  void writeParameters(int argc, char** argv) const;
87 
89  DWORD currentState,
90  DWORD win32ExitCode,
91  DWORD serviceSpecificExitCode,
92  DWORD checkPoint,
93  DWORD waitHint
94  );
95 
96 }; // class Service
97 
98 } // end namespace OmniEvents
99 
100 #endif // OMNIEVENTS__DAEMON_WINDOWS_H
101 
OmniEvents::Service::~Service
~Service()
Definition: daemon_windows.cc:192
OmniEvents::Service::foreground
void foreground(bool val)
Set _foreground.
Definition: daemon_windows.cc:216
OmniEvents::Service::install
void install(int argc, char **argv) const
Definition: daemon_windows.cc:383
OmniEvents::Service::_serviceRunning
bool _serviceRunning
Definition: daemon_windows.h:72
OmniEvents::Service::uninstall
void uninstall() const
Definition: daemon_windows.cc:448
OmniEvents::Service::Service
Service()
Definition: daemon_windows.cc:180
OmniEvents::Service::daemonize
void daemonize()
Redirects output streams to tracefile.
Definition: daemon_windows.cc:292
OmniEvents::Service::_logstream
std::ostream * _logstream
Definition: daemon_windows.h:76
OmniEvents::Service::readParameters
void readParameters()
Populates _parameters from the Registry.
Definition: daemon_windows.cc:485
OmniEvents::Service::start
void start(int &argc, char **&argv)
Definition: daemon_windows.cc:223
OmniEvents::Service::tracefile
void tracefile(const char *val)
Set _tracefile.
Definition: daemon_windows.cc:202
OmniEvents::Service::writeParameters
void writeParameters(int argc, char **argv) const
Writes args 2+ to the Registry.
Definition: daemon_windows.cc:502
OmniEvents::Service::_callCount
int _callCount
Definition: daemon_windows.h:73
OmniEvents::Service::_parameters
char * _parameters
Stores parameters read from the registry.
Definition: daemon_windows.h:74
OmniEvents::Service::shutdown
void shutdown()
Exit handler set with ::on_exit() - shuts down the service.
Definition: daemon_windows.cc:319
OmniEvents::Service
Singleton class that contains various methods for running a Windows service.
Definition: daemon_windows.h:40
OmniEvents::Service::setServiceStatus
bool Service::setServiceStatus(DWORD currentState, DWORD win32ExitCode, DWORD serviceSpecificExitCode, DWORD checkPoint, DWORD waitHint)
OmniEvents::Service::_regSubKey
const char * _regSubKey
Definition: daemon_windows.h:71
OmniEvents
Definition: Callback.h:39
OmniEvents::Service::ctrlHandler
static void ctrlHandler(DWORD controlCode)
Handles control codes from the Service Control Manager.
Definition: daemon_windows.cc:340
OmniEvents::Service::_argv
char ** _argv
Replacement argv array, read from registry.
Definition: daemon_windows.h:75
OmniEvents::Service::pidfile
void pidfile(const char *val)
Set _pidfile.
Definition: daemon_windows.cc:209
OmniEvents::Service::setArgcArgv
void Service::setArgcArgv(int &argc, char **&argv)
OmniEvents::Service::runningOk
void runningOk()
Called to signal that all startup operations have completed OK.
Definition: daemon_windows.cc:309
OmniEvents::Service::_tracefile
char * _tracefile
The tracefile name (if any).
Definition: daemon_windows.h:70
OmniEvents::Service::_serviceStatusHandle
SERVICE_STATUS_HANDLE _serviceStatusHandle
Windows thing.
Definition: daemon_windows.h:77
OmniEvents::Service::log
static void log(const char *message)
Callback, used as a parameter to omniORB::setLogFunction().
Definition: daemon_windows.cc:334