blob: 3f09eb7913464e84143c9c91bc843ddbb4fda3fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
Copyright (C) 2008 Andreas Baumann <abaumann@yahoo.com>
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 3 of the License, 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WOLF_SERVICE_H
#define WOLF_SERVICE_H
/**
* @addtogroup wolf_win32 Windows-specific
* @{
*/
/**
* @addtogroup wolf_service Windows Service
* @{
*/
/**
* @file service.h
* @brief helper to write a Windows service
* @author Andreas Baumann <abaumann@yahoo.com>
*/
#define WIND32_LEAN_AND_MEAN
#include <windows.h>
#include "errors.h"
#ifdef __cplusplus
extern "C" {
#endif
extern SERVICE_STATUS_HANDLE service_status_handle;
extern SERVICE_STATUS service_status;
extern HANDLE service_stop_event;
/**
* @brief structure to fill out when creating a Windows service.
*/
typedef struct wolf_service_params_t {
LPCTSTR service_name; /**< internal name of the service (for instance for
'net start <service_name>') */
LPCTSTR service_name_descr; /**< the descriptive name of the service (for instance
shown in the event log viewer application) */
} wolf_service_params_t;
/**
* Installs the current binary as a Windows service.
*
* @param params steers how the service should be created
*
* @return WOLF_OK if the service was created, or an WOLF_ERR_INTERNAL
* (which also gets logged with wolf_log)
*/
wolf_error_t wolf_service_install( wolf_service_params_t params );
typedef enum wolf_service_event_t {
WOLF_SERVICE_EVENT_TERMINATE /**< terminate the service now */
} wolf_service_event_t;
/**
* Suspend the current thread till an event happens. At the moment
* we only get the SERVICE_EVENT_TERMINATE event.
*
* @param timeout wait at most timeout seconds, then return also
* without an event happening
* @param error WOLF_OK if an event occured, WOLF_ERR_TIMEOUT if
* no signal happened after timeout seconds
* @return the event which happened
*/
wolf_service_event_t wolf_service_events_suspend( int timeout, wolf_error_t *error );
/**
* The main service function.
*
* @param argc number of arguments as in main()
* @param argv arguments as in main()
*
* Note: Must be exported as it gets called from the SCM in a service thread/process.
*/
void WINAPI wolf_service_main( DWORD argc, LPTSTR *argv );
wolf_error_t wolf_service_start( LPTSTR service_name,
LPSERVICE_MAIN_FUNCTION service_main );
#ifdef __cplusplus
}
#endif
/** @} */ /* @addtogroup wolf_service */
/** @} */ /* @addtogroup wolf_win32 */
#endif /* ifndef WOLF_SERVICE_H */
|