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
35namespace OmniEvents {
36
41{
42public:
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
69private:
70 char* _tracefile;
71 const char* _regSubKey;
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
Singleton class that contains various methods for running a Windows service.
void tracefile(const char *val)
Set _tracefile.
void Service::setArgcArgv(int &argc, char **&argv)
void install(int argc, char **argv) const
std::ostream * _logstream
void pidfile(const char *val)
Set _pidfile.
void foreground(bool val)
Set _foreground.
bool Service::setServiceStatus(DWORD currentState, DWORD win32ExitCode, DWORD serviceSpecificExitCode, DWORD checkPoint, DWORD waitHint)
char * _tracefile
The tracefile name (if any).
void start(int &argc, char **&argv)
void shutdown()
Exit handler set with ::on_exit() - shuts down the service.
const char * _regSubKey
void writeParameters(int argc, char **argv) const
Writes args 2+ to the Registry.
SERVICE_STATUS_HANDLE _serviceStatusHandle
Windows thing.
char * _parameters
Stores parameters read from the registry.
static void log(const char *message)
Callback, used as a parameter to omniORB::setLogFunction().
void runningOk()
Called to signal that all startup operations have completed OK.
void readParameters()
Populates _parameters from the Registry.
void daemonize()
Redirects output streams to tracefile.
static void ctrlHandler(DWORD controlCode)
Handles control codes from the Service Control Manager.
char ** _argv
Replacement argv array, read from registry.