[TFTPD] Fix compilation, and use the #define MAX_SERVERS where needed instead of...
[reactos.git] / base / services / wlansvc / wlansvc.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: base/services/wlansvc/wlansvc.c
5 * PURPOSE: WLAN Service
6 * PROGRAMMER: Christoph von Wittich
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include "precomp.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* GLOBALS ******************************************************************/
17
18 #define SERVICE_NAME L"WLAN Service"
19
20 SERVICE_STATUS_HANDLE ServiceStatusHandle;
21 SERVICE_STATUS SvcStatus;
22 static WCHAR ServiceName[] = L"WlanSvc";
23
24 DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter);
25
26 /* FUNCTIONS *****************************************************************/
27
28 static void UpdateServiceStatus(HANDLE hServiceStatus, DWORD NewStatus, DWORD Increment)
29 {
30 if (Increment > 0)
31 SvcStatus.dwCheckPoint += Increment;
32 else
33 SvcStatus.dwCheckPoint = 0;
34
35 SvcStatus.dwCurrentState = NewStatus;
36 SetServiceStatus(hServiceStatus, &SvcStatus);
37 }
38
39 static DWORD WINAPI
40 ServiceControlHandler(DWORD dwControl,
41 DWORD dwEventType,
42 LPVOID lpEventData,
43 LPVOID lpContext)
44 {
45 switch (dwControl)
46 {
47 case SERVICE_CONTROL_SHUTDOWN:
48 case SERVICE_CONTROL_STOP:
49 UpdateServiceStatus(ServiceStatusHandle, SERVICE_STOP_PENDING, 1);
50 RpcMgmtStopServerListening(NULL);
51 UpdateServiceStatus(ServiceStatusHandle, SERVICE_STOPPED, 0);
52 break;
53 case SERVICE_CONTROL_INTERROGATE:
54 return NO_ERROR;
55 default:
56 return ERROR_CALL_NOT_IMPLEMENTED;
57 }
58 return NO_ERROR;
59 }
60
61 static VOID CALLBACK
62 ServiceMain(DWORD argc, LPWSTR *argv)
63 {
64 HANDLE hThread;
65
66 UNREFERENCED_PARAMETER(argc);
67 UNREFERENCED_PARAMETER(argv);
68
69 DPRINT("ServiceMain() called\n");
70
71 SvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
72 SvcStatus.dwCurrentState = SERVICE_START_PENDING;
73 SvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
74 SvcStatus.dwCheckPoint = 0;
75 SvcStatus.dwWin32ExitCode = NO_ERROR;
76 SvcStatus.dwServiceSpecificExitCode = 0;
77 SvcStatus.dwWaitHint = 4000;
78
79 ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
80 ServiceControlHandler,
81 NULL);
82
83 UpdateServiceStatus(ServiceStatusHandle, SERVICE_RUNNING, 0);
84
85 hThread = CreateThread(NULL,
86 0,
87 (LPTHREAD_START_ROUTINE)
88 RpcThreadRoutine,
89 NULL,
90 0,
91 NULL);
92
93 if (!hThread)
94 {
95 DPRINT("Can't create RpcThread\n");
96 UpdateServiceStatus(ServiceStatusHandle, SERVICE_STOPPED, 0);
97 }
98 else
99 {
100 CloseHandle(hThread);
101 }
102
103 DPRINT("ServiceMain() done\n");
104 }
105
106 int
107 wmain(int argc, WCHAR *argv[])
108 {
109 SERVICE_TABLE_ENTRYW ServiceTable[2] =
110 {
111 {ServiceName, ServiceMain},
112 {NULL, NULL}
113 };
114
115 UNREFERENCED_PARAMETER(argc);
116 UNREFERENCED_PARAMETER(argv);
117
118 DPRINT("wlansvc: main() started\n");
119
120 StartServiceCtrlDispatcherW(ServiceTable);
121
122 DPRINT("wlansvc: main() done\n");
123
124 ExitThread(0);
125
126 return 0;
127 }
128
129 /* EOF */