Added --version command.
[nssm.git] / hook.h
1 #ifndef HOOK_H\r
2 #define HOOK_H\r
3 \r
4 #define NSSM_HOOK_EVENT_START _T("Start")\r
5 #define NSSM_HOOK_EVENT_STOP _T("Stop")\r
6 #define NSSM_HOOK_EVENT_EXIT _T("Exit")\r
7 #define NSSM_HOOK_EVENT_POWER _T("Power")\r
8 #define NSSM_HOOK_EVENT_ROTATE _T("Rotate")\r
9 \r
10 #define NSSM_HOOK_ACTION_PRE _T("Pre")\r
11 #define NSSM_HOOK_ACTION_POST _T("Post")\r
12 #define NSSM_HOOK_ACTION_CHANGE _T("Change")\r
13 #define NSSM_HOOK_ACTION_RESUME _T("Resume")\r
14 \r
15 /* Hook name will be "<service> (<event>/<action>)" */\r
16 #define HOOK_NAME_LENGTH SERVICE_NAME_LENGTH * 2\r
17 \r
18 #define NSSM_HOOK_VERSION 1\r
19 \r
20 /* Hook ran successfully. */\r
21 #define NSSM_HOOK_STATUS_SUCCESS 0\r
22 /* No hook configured. */\r
23 #define NSSM_HOOK_STATUS_NOTFOUND 1\r
24 /* Hook requested abort. */\r
25 #define NSSM_HOOK_STATUS_ABORT 99\r
26 /* Internal error launching hook. */\r
27 #define NSSM_HOOK_STATUS_ERROR 100\r
28 /* Hook was not run. */\r
29 #define NSSM_HOOK_STATUS_NOTRUN 101\r
30 /* Hook timed out. */\r
31 #define NSSM_HOOK_STATUS_TIMEOUT 102\r
32 /* Hook returned non-zero. */\r
33 #define NSSM_HOOK_STATUS_FAILED 111\r
34 \r
35 /* Version 1. */\r
36 #define NSSM_HOOK_ENV_VERSION _T("NSSM_HOOK_VERSION")\r
37 #define NSSM_HOOK_ENV_IMAGE_PATH _T("NSSM_EXE")\r
38 #define NSSM_HOOK_ENV_NSSM_CONFIGURATION _T("NSSM_CONFIGURATION")\r
39 #define NSSM_HOOK_ENV_NSSM_VERSION _T("NSSM_VERSION")\r
40 #define NSSM_HOOK_ENV_BUILD_DATE _T("NSSM_BUILD_DATE")\r
41 #define NSSM_HOOK_ENV_PID _T("NSSM_PID")\r
42 #define NSSM_HOOK_ENV_DEADLINE _T("NSSM_DEADLINE")\r
43 #define NSSM_HOOK_ENV_SERVICE_NAME _T("NSSM_SERVICE_NAME")\r
44 #define NSSM_HOOK_ENV_SERVICE_DISPLAYNAME _T("NSSM_SERVICE_DISPLAYNAME")\r
45 #define NSSM_HOOK_ENV_COMMAND_LINE _T("NSSM_COMMAND_LINE")\r
46 #define NSSM_HOOK_ENV_APPLICATION_PID _T("NSSM_APPLICATION_PID")\r
47 #define NSSM_HOOK_ENV_EVENT _T("NSSM_EVENT")\r
48 #define NSSM_HOOK_ENV_ACTION _T("NSSM_ACTION")\r
49 #define NSSM_HOOK_ENV_TRIGGER _T("NSSM_TRIGGER")\r
50 #define NSSM_HOOK_ENV_LAST_CONTROL _T("NSSM_LAST_CONTROL")\r
51 #define NSSM_HOOK_ENV_START_REQUESTED_COUNT _T("NSSM_START_REQUESTED_COUNT")\r
52 #define NSSM_HOOK_ENV_START_COUNT _T("NSSM_START_COUNT")\r
53 #define NSSM_HOOK_ENV_THROTTLE_COUNT _T("NSSM_THROTTLE_COUNT")\r
54 #define NSSM_HOOK_ENV_EXIT_COUNT _T("NSSM_EXIT_COUNT")\r
55 #define NSSM_HOOK_ENV_EXITCODE _T("NSSM_EXITCODE")\r
56 #define NSSM_HOOK_ENV_RUNTIME _T("NSSM_RUNTIME")\r
57 #define NSSM_HOOK_ENV_APPLICATION_RUNTIME _T("NSSM_APPLICATION_RUNTIME")\r
58 \r
59 typedef struct {\r
60   TCHAR name[HOOK_NAME_LENGTH];\r
61   HANDLE thread_handle;\r
62 } hook_thread_data_t;\r
63 \r
64 typedef struct {\r
65   hook_thread_data_t *data;\r
66   int num_threads;\r
67 } hook_thread_t;\r
68 \r
69 bool valid_hook_name(const TCHAR *, const TCHAR *, bool);\r
70 void await_hook_threads(hook_thread_t *, SERVICE_STATUS_HANDLE, SERVICE_STATUS *, unsigned long);\r
71 int nssm_hook(hook_thread_t *, nssm_service_t *, TCHAR *, TCHAR *, unsigned long *, unsigned long, bool);\r
72 int nssm_hook(hook_thread_t *, nssm_service_t *, TCHAR *, TCHAR *, unsigned long *, unsigned long);\r
73 int nssm_hook(hook_thread_t *, nssm_service_t *, TCHAR *, TCHAR *, unsigned long *);\r
74 \r
75 #endif\r