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