Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / include / net-snmp / library / winservice.h
1 #ifndef WINSERVICE_H\r
2 #define WINSERVICE_H\r
3 \r
4     /*
5      * \r
6      * *Windows Service related functions declaration\r
7      * *By Raju Krishanppa(raju_krishnappa@yahoo.com)\r
8      * *\r
9      */ \r
10     \r
11 #ifdef __cplusplus\r
12 extern          "C" {
13     \r
14 #endif  /* \r */
15     \r
16         /*
17          * \r
18          * * Define Constants for Register, De-register , Run As service or Console mode\r
19          */ \r
20 #define REGISTER_SERVICE 0\r
21 #define UN_REGISTER_SERVICE 1\r
22 #define RUN_AS_SERVICE 2\r
23 #define RUN_AS_CONSOLE 3\r
24     \r
25         /*
26          * \r
27          * * Define Message catalog ID\r
28          * * MessageId: DISPLAY_MSG\r
29          * * MessageText:\r
30          * *  %1.\r
31          */ \r
32 #define DISPLAY_MSG                      0x00000064L\r
33     \r
34         /*
35          * \r
36          * * Hint Value to SCM to wait before sending successive commands to service\r
37          */ \r
38 #define SCM_WAIT_INTERVAL 7000\r
39     \r
40         /*
41          * \r
42          * * Define Generic String Size, to hold Error or Information\r
43          */ \r
44 #define MAX_STR_SIZE  1024\r
45     \r
46         /*
47          * Delcare Global variables, which are visible to other modules 
48          */ \r
49     extern BOOL     g_fRunningAsService;
50                    \r\r
51         /*
52          * Input parameter structure to thread 
53          */            \r
54     typedef struct _InputParams \r {
55         \rDWORD Argc;
56         \rLPTSTR * Argv;
57     \r} InputParams;
58                    \r\r
59         /*
60          * \r
61          * * Define Service Related functions\r
62          */            \r
63                    \r
64         /*
65          * To register application as windows service with SCM 
66          */            \r
67      
68         
69         
70         
71         
72         
73         
74         
75         
76         
77         
78         
79         
80         
81         
82         VOID RegisterService(LPCTSTR lpszServiceName,
83                              LPCTSTR lpszServiceDisplayName,
84                              LPCTSTR lpszServiceDescription,
85                              InputParams * StartUpArg);
86                    \r\r
87         /*
88          * To unregister servcie 
89          */            \r
90                     VOID UnregisterService(LPCSTR lpszServiceName);
91                    \r\r
92         /*
93          * To parse command line for startup option 
94          */            \r
95      
96         
97         
98         
99         
100         
101         
102                 INT ParseCmdLineForServiceOption(INT argc, TCHAR * argv[]);
103                    \r\r
104         /*
105          * To write to windows event log 
106          */            \r
107      
108         
109         
110         
111         
112                   VOID WriteToEventLog(WORD wType, LPCTSTR pszFormat, ...);
113                    \r\r
114         /*
115          * To display generic windows error 
116          */            \r
117                     VOID DisplayError(LPCTSTR pszTitle);
118                    \r\r
119         /*
120          * To update windows service status to SCM 
121          */            \r
122     static BOOL     UpdateServiceStatus(DWORD dwStatus, DWORD dwErrorCode,
123                                         DWORD dwWaitHint);
124                    \r\r
125         /*
126          * To Report current service status to SCM 
127          */            \r
128     static BOOL     ReportCurrentServiceStatus();
129                    \r\r
130         /*
131          * Service Main function,  Which will spawn a thread, and calls the\r
132          * * Service run part\r
133          */            \r
134                     VOID WINAPI ServiceMain(DWORD argc, LPTSTR argv[]);
135                    \r\r
136         /*
137          * To start Service 
138          */            \r
139      
140         
141         
142         
143         
144                   BOOL RunAsService(INT(*ServiceFunction) (INT, LPTSTR *));
145                    \r\r
146         /*
147          * Call back function to process SCM Requests 
148          */            \r
149                     VOID WINAPI ControlHandler(DWORD dwControl);
150                    \r\r
151         /*
152          * To Stop the service 
153          */            \r
154                     VOID ProcessServiceStop(VOID);
155                    \r\r
156         /*
157          * To Pause service 
158          */            \r
159                     VOID ProcessServicePause(VOID);
160                    \r\r
161         /*
162          * To Continue paused service 
163          */            \r
164                     VOID ProcessServiceContinue(VOID);
165                    \r\r
166         /*
167          * To send Current Serivce status to SCM when INTERROGATE command is sent 
168          */            \r
169                     VOID ProcessServiceInterrogate(VOID);
170                    \r\r
171         /*
172          * To allocate and Set security descriptor 
173          */            \r
174      
175         
176         
177         
178         
179         
180         
181         
182         
183         
184         
185         
186         
187         
188         
189         BOOL SetSimpleSecurityAttributes(SECURITY_ATTRIBUTES *
190                                          pSecurityAttr);
191                    \r\r
192         /*
193          * To free Securtiy Descriptor 
194          */            \r
195      
196         
197         
198         
199         
200         
201         
202         
203         
204         
205         
206         
207         
208           VOID FreeSecurityAttributes(SECURITY_ATTRIBUTES * pSecurityAttr);
209                    \r\r
210         /*
211          * TheadFunction - To spawan as thread - Invokes registered service function 
212          */            \r
213                     DWORD WINAPI ThreadFunction(LPVOID lpParam);
214                    \r\r
215         /*
216          * Service STOP function registration with this framewrok\r
217          * * this function must be invoked before calling RunAsService\r
218          */            \r
219                     VOID RegisterStopFunction(VOID(*StopFunc) ());
220                    \r\r
221 #ifdef __cplusplus\r
222 }              \r
223 #endif  /* \r */
224 #endif  /* WINSERVICE_H */\r