[BOOTDATA]
[reactos.git] / reactos / base / services / telnetd / serviceentry.c
1 /*
2 * Copyright 2007 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include <stdarg.h>
20 #include <windef.h>
21 #include <winbase.h>
22 #include <winsvc.h>
23 #include <wine/debug.h>
24
25 int kickoff_telnetd(void);
26
27 WINE_DEFAULT_DEBUG_CHANNEL(telnetd);
28
29 static WCHAR telnetdW[] = {'t','e','l','n','e','t','d',0};
30
31 static SERVICE_STATUS_HANDLE service_handle;
32 static HANDLE stop_event;
33
34 static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context )
35 {
36 SERVICE_STATUS status;
37
38 status.dwServiceType = SERVICE_WIN32;
39 status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
40 status.dwWin32ExitCode = 0;
41 status.dwServiceSpecificExitCode = 0;
42 status.dwCheckPoint = 0;
43 status.dwWaitHint = 0;
44
45 switch(ctrl)
46 {
47 case SERVICE_CONTROL_STOP:
48 case SERVICE_CONTROL_SHUTDOWN:
49 WINE_TRACE( "shutting down\n" );
50 status.dwCurrentState = SERVICE_STOP_PENDING;
51 status.dwControlsAccepted = 0;
52 SetServiceStatus( service_handle, &status );
53 SetEvent( stop_event );
54 return NO_ERROR;
55 default:
56 WINE_FIXME( "got service ctrl %x\n", ctrl );
57 status.dwCurrentState = SERVICE_RUNNING;
58 SetServiceStatus( service_handle, &status );
59 return NO_ERROR;
60 }
61 }
62
63 static void WINAPI serv_main(DWORD argc, LPWSTR *argv)
64 {
65 SERVICE_STATUS status;
66
67 WINE_TRACE( "starting service\n" );
68
69 stop_event = CreateEventW( NULL, TRUE, FALSE, NULL );
70
71 service_handle = RegisterServiceCtrlHandlerExW( telnetdW, service_handler, NULL );
72 if (!service_handle)
73 return;
74
75 status.dwServiceType = SERVICE_WIN32;
76 status.dwCurrentState = SERVICE_RUNNING;
77 status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
78 status.dwWin32ExitCode = 0;
79 status.dwServiceSpecificExitCode = 0;
80 status.dwCheckPoint = 0;
81 status.dwWaitHint = 10000;
82 SetServiceStatus( service_handle, &status );
83
84 /* Argument Ignored for now */
85 kickoff_telnetd();
86
87 WaitForSingleObject( stop_event, INFINITE );
88
89 status.dwCurrentState = SERVICE_STOPPED;
90 status.dwControlsAccepted = 0;
91 SetServiceStatus( service_handle, &status );
92 WINE_TRACE( "service stopped\n" );
93 }
94
95 int main(int argc, char **argv)
96 {
97 static const SERVICE_TABLE_ENTRYW servtbl[] = {
98 {telnetdW, serv_main},
99 {NULL, NULL}
100 };
101
102 WINE_TRACE("(%d %p)\n", argc, argv);
103
104 StartServiceCtrlDispatcherW(servtbl);
105 return 0;
106 }
107 /* EOF */
108