[USB-BRINGUP-TRUNK]
[reactos.git] / 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 #define WIN32_LEAN_AND_MEAN
20
21 #include <windows.h>
22 #include "wine/debug.h"
23
24 int kickoff_telnetd(void);
25
26 WINE_DEFAULT_DEBUG_CHANNEL(telnetd);
27
28 static WCHAR telnetdW[] = {'t','e','l','n','e','t','d',0};
29
30 static SERVICE_STATUS_HANDLE service_handle;
31 static HANDLE stop_event;
32
33 static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context )
34 {
35 SERVICE_STATUS status;
36
37 status.dwServiceType = SERVICE_WIN32;
38 status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
39 status.dwWin32ExitCode = 0;
40 status.dwServiceSpecificExitCode = 0;
41 status.dwCheckPoint = 0;
42 status.dwWaitHint = 0;
43
44 switch(ctrl)
45 {
46 case SERVICE_CONTROL_STOP:
47 case SERVICE_CONTROL_SHUTDOWN:
48 WINE_TRACE( "shutting down\n" );
49 status.dwCurrentState = SERVICE_STOP_PENDING;
50 status.dwControlsAccepted = 0;
51 SetServiceStatus( service_handle, &status );
52 SetEvent( stop_event );
53 return NO_ERROR;
54 default:
55 WINE_FIXME( "got service ctrl %x\n", ctrl );
56 status.dwCurrentState = SERVICE_RUNNING;
57 SetServiceStatus( service_handle, &status );
58 return NO_ERROR;
59 }
60 }
61
62 static void WINAPI serv_main(DWORD argc, LPWSTR *argv)
63 {
64 SERVICE_STATUS status;
65
66 WINE_TRACE( "starting service\n" );
67
68 stop_event = CreateEventW( NULL, TRUE, FALSE, NULL );
69
70 service_handle = RegisterServiceCtrlHandlerExW( telnetdW, service_handler, NULL );
71 if (!service_handle)
72 return;
73
74 status.dwServiceType = SERVICE_WIN32;
75 status.dwCurrentState = SERVICE_RUNNING;
76 status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
77 status.dwWin32ExitCode = 0;
78 status.dwServiceSpecificExitCode = 0;
79 status.dwCheckPoint = 0;
80 status.dwWaitHint = 10000;
81 SetServiceStatus( service_handle, &status );
82
83 /* Argument Ignored for now */
84 kickoff_telnetd();
85
86 WaitForSingleObject( stop_event, INFINITE );
87
88 status.dwCurrentState = SERVICE_STOPPED;
89 status.dwControlsAccepted = 0;
90 SetServiceStatus( service_handle, &status );
91 WINE_TRACE( "service stopped\n" );
92 }
93
94 int main(int argc, char **argv)
95 {
96 static const SERVICE_TABLE_ENTRYW servtbl[] = {
97 {telnetdW, serv_main},
98 {NULL, NULL}
99 };
100
101 WINE_TRACE("(%d %p)\n", argc, argv);
102
103 StartServiceCtrlDispatcherW(servtbl);
104 return 0;
105 }
106 /* EOF */
107