source: trunk/include/service_ew.h @ 5054

Revision 1861, 6.5 KB checked in by mark, 13 years ago (diff)

Added wait_for_dependencies

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 *   THIS FILE IS UNDER CVS - DO NOT MODIFY UNLESS YOU HAVE
3 *   CHECKED IT OUT USING THE COMMAND CHECKOUT.
4 *
5 *    $Id$
6 *
7 *    Revision history:
8 *     $Log$
9 *     Revision 1.6  2005/06/08 17:39:31  mark
10 *     Added wait_for_dependencies
11 *
12 *     Revision 1.5  2004/12/06 22:13:55  mark
13 *     Added get_service_status
14 *
15 *     Revision 1.4  2004/08/03 18:47:20  mark
16 *     Added dependencies param to install_service
17 *
18 *     Revision 1.3  2004/07/27 20:05:15  mark
19 *     Fixed compile errors/warnings
20 *
21 *     Revision 1.2  2004/07/20 16:48:34  mark
22 *     Added #include <winsvc.h> for Win32 projects
23 *
24 *     Revision 1.1  2004/07/13 16:21:27  mark
25 *     Initial checkin
26 *
27 */
28
29#ifndef _SERVICE_EW_H_
30#define _SERVICE_EW_H_
31
32#ifndef WIN32
33/*******
34 * Windows constants used for services.  These were taken from winsvc.h
35 ******/
36
37#define SERVICE_STOPPED                0x00000001
38#define SERVICE_START_PENDING          0x00000002
39#define SERVICE_STOP_PENDING           0x00000003
40#define SERVICE_RUNNING                0x00000004
41#define SERVICE_CONTINUE_PENDING       0x00000005
42#define SERVICE_PAUSE_PENDING          0x00000006
43#define SERVICE_PAUSED                 0x00000007
44
45#define SERVICE_CONTROL_STOP           0x00000001
46#define SERVICE_CONTROL_PAUSE          0x00000002
47#define SERVICE_CONTROL_CONTINUE       0x00000003
48#define SERVICE_CONTROL_INTERROGATE    0x00000004
49#define SERVICE_CONTROL_SHUTDOWN       0x00000005
50#define SERVICE_CONTROL_PARAMCHANGE    0x00000006
51#define SERVICE_CONTROL_NETBINDADD     0x00000007
52#define SERVICE_CONTROL_NETBINDREMOVE  0x00000008
53#define SERVICE_CONTROL_NETBINDENABLE  0x00000009
54#define SERVICE_CONTROL_NETBINDDISABLE 0x0000000A
55
56typedef void (*LPSERVICE_MAIN_FUNCTION)(
57    int   dwNumServicesArgs,
58    char   *lpServiceArgVectors[]
59    );
60
61typedef void (*LPHANDLER_FUNCTION)(
62    int    dwControl
63    );
64
65#else
66#include <winsvc.h>
67#endif
68
69/*******************
70 * install_service
71 *
72 * Installs this app as a service.  This only needs to be called once, period;
73 * not once per time you run.  After this is called, the service will be set
74 * to start automatically at every reboot.
75 *
76 * Params:
77 *  szServiceName - internal name given to this service
78 *  szDisplayName - name displayed in the Service Manager
79 *  szDependencies - double-NULL terminated array of NULL-terminated names of other services
80 *                   that this service depends on, or NULL for no dependencies.
81 ******************/
82void install_service(const char *szServiceName, const char *szDisplayName, const char *szDependencies);
83
84/*******************
85 * uninstall_service
86 *
87 * Uninstalls this app as a service.
88 *
89 * Params:
90 *      szServiceName - internal name given to this service, used during install_service
91 ******************/
92void uninstall_service(const char *szServiceName);
93
94/******************
95 * start_service
96 *
97 * Starts running the service.  This function should be called within the main() function.
98 * Its purpose it to register this app as running with the Windows Service Manager, then
99 * call another function which will act as a second main() function.
100 *
101 * Params;
102 *      szServiceName - internal name given to this service, used during install_service
103 *      mainfunc - new "main" function.
104 * Returns:
105 *      0 if all is well, otherwise an error value.  This function will not return until the
106 *      "mainfunc" function has completed and returned.
107 *****************/
108int start_service(char *szServiceName, LPSERVICE_MAIN_FUNCTION mainfunc);
109
110/******************
111 * init_service
112 *
113 * Initializes the service.  This function should be called towards the beginning of
114 * the mainfunc() function passed to start_service.
115 *
116 * Params:
117 *      szServiceName - internal name given to this service, used during install_service
118 *                                      and start_service
119 *      allow_pause - non-zero if this service can pause/continue; zero if it can't
120 *      handler - function that is called when the Windows Service Manager needs to issue
121 *                              STOP, PAUSE, or INTERROGATE commands
122 * Returns:
123 *      0 if all is well, otherwise an error value.
124 ******************/
125int init_service(char *szServiceName, int allow_pause, LPHANDLER_FUNCTION handler);
126
127/******************
128 * set_service_status
129 *
130 * Informs the Windows Service Manager (and anybody else who's listening via the WSM)
131 * the current state of the service.  See the Win32 SetServiceStatus() function for
132 * more details.
133 *
134 * Params:
135 *      state - current state of the service (e.g. SERVICE_RUNNING), or 0 to re-send the
136 *                      last known state.
137 *      error - Win32 error to report, or 0 if everything is fine
138 *      checkpoint - current checkpoint for _PENDING states.  Start with a 0 value when you
139 *                              enter one of these states, then increment by 1 with subsequent set_service_status
140 *                              calls until you're no longer pending.
141 *      hint - how long the Service Manager can expect to wait until you're no longer pending,
142 *                      or until the next "checkpoint" status is sent (in ms).
143 * Returns:
144 *      0 if all is well, otherwise an error value.
145 ******************/
146int set_service_status(int state, int error, int checkpoint, int hint);
147
148/******************
149 * get_service_status
150 *
151 * Determines the status of a given service.  This can be used to determine if all service
152 * dependencies are running.
153 *
154 * Params:
155 *      szServiceName - internal name given to this service, used during install_service
156 *                                      and start_service (does not have to have registered as an earthworm/hydra
157 *                                      service, but can refer to any service)
158 *  pState - return value referring to current service state (e.g. SERVICE_RUNNING)
159 *  pError - return value referring to current service error value, or 0 if all is well.
160 *
161 * Returns:
162 *      0 if all is well, otherwise an error value.
163 ******************/
164int get_service_status(char *szServiceName, int *pState, int *pError);
165
166/******************
167 * wait_for_dependencies
168 *
169 * Waits for all of the given dependencies to start running.  This is used when a service has
170 * more than one dependency, since Windows only waits for one service to start running rather
171 * than all of them.
172 *
173 * Params:
174 *      szDependencyList - List of dependant services given to install_service; each service name
175 *                      is NULL terminated, and the entire array is double-NULL terminated.
176 *  pCheckpoint -       On entry, the next checkpoint to pass to set_service_status.
177 *                                      On exit, the next checkpoint for the calling function to pass to
178 *                                              set_service_status.
179 *
180 * Returns:
181 *      0 if all is well, otherwise an error value.
182 ******************/
183int wait_for_dependencies(char *szDependencyList, int *pCheckpoint);
184
185#endif /* _SERVICE_EW_H_ */
Note: See TracBrowser for help on using the repository browser.