[SNDVOL32] Advanced controls dialog: Remove the TBS_AUTOTICKS style from the trackbar...
[reactos.git] / base / services / srvsvc / srvsvc.c
1 /*
2 * ReactOS Services
3 * Copyright (C) 2015 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS Services
22 * FILE: base/services/srvsvc/srvsvc.c
23 * PURPOSE: Server service
24 * PROGRAMMER: Eric Kohl
25 */
26
27 /* INCLUDES *****************************************************************/
28
29 #include "precomp.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(srvsvc);
32
33 /* GLOBALS ******************************************************************/
34
35 static WCHAR ServiceName[] = L"Lanmanserver";
36
37 static SERVICE_STATUS_HANDLE ServiceStatusHandle;
38 static SERVICE_STATUS ServiceStatus;
39
40 DWORD dwServiceBits = 0;
41
42
43 /* FUNCTIONS *****************************************************************/
44
45 static VOID
46 UpdateServiceStatus(DWORD dwState)
47 {
48 ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
49 ServiceStatus.dwCurrentState = dwState;
50 ServiceStatus.dwControlsAccepted = 0;
51 ServiceStatus.dwWin32ExitCode = 0;
52 ServiceStatus.dwServiceSpecificExitCode = 0;
53 ServiceStatus.dwCheckPoint = 0;
54
55 if (dwState == SERVICE_START_PENDING ||
56 dwState == SERVICE_STOP_PENDING ||
57 dwState == SERVICE_PAUSE_PENDING ||
58 dwState == SERVICE_CONTINUE_PENDING)
59 ServiceStatus.dwWaitHint = 10000;
60 else
61 ServiceStatus.dwWaitHint = 0;
62
63 SetServiceStatus(ServiceStatusHandle,
64 &ServiceStatus);
65 }
66
67 static DWORD WINAPI
68 ServiceControlHandler(DWORD dwControl,
69 DWORD dwEventType,
70 LPVOID lpEventData,
71 LPVOID lpContext)
72 {
73 TRACE("ServiceControlHandler() called\n");
74
75 switch (dwControl)
76 {
77 case SERVICE_CONTROL_STOP:
78 TRACE(" SERVICE_CONTROL_STOP received\n");
79 /* Stop listening to incoming RPC messages */
80 RpcMgmtStopServerListening(NULL);
81 UpdateServiceStatus(SERVICE_STOPPED);
82 return ERROR_SUCCESS;
83
84 case SERVICE_CONTROL_PAUSE:
85 TRACE(" SERVICE_CONTROL_PAUSE received\n");
86 UpdateServiceStatus(SERVICE_PAUSED);
87 return ERROR_SUCCESS;
88
89 case SERVICE_CONTROL_CONTINUE:
90 TRACE(" SERVICE_CONTROL_CONTINUE received\n");
91 UpdateServiceStatus(SERVICE_RUNNING);
92 return ERROR_SUCCESS;
93
94 case SERVICE_CONTROL_INTERROGATE:
95 TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
96 SetServiceStatus(ServiceStatusHandle,
97 &ServiceStatus);
98 return ERROR_SUCCESS;
99
100 case SERVICE_CONTROL_SHUTDOWN:
101 TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
102 UpdateServiceStatus(SERVICE_STOPPED);
103 return ERROR_SUCCESS;
104
105 default :
106 TRACE(" Control %lu received\n", dwControl);
107 return ERROR_CALL_NOT_IMPLEMENTED;
108 }
109 }
110
111
112 static
113 DWORD
114 ServiceInit(VOID)
115 {
116 HANDLE hThread;
117
118 hThread = CreateThread(NULL,
119 0,
120 (LPTHREAD_START_ROUTINE)RpcThreadRoutine,
121 NULL,
122 0,
123 NULL);
124
125 if (!hThread)
126 {
127 ERR("Can't create PortThread\n");
128 return GetLastError();
129 }
130 else
131 CloseHandle(hThread);
132
133 /* Report a running server service */
134 SetServiceBits(ServiceStatusHandle,
135 SV_TYPE_SERVER,
136 TRUE,
137 TRUE);
138
139 return ERROR_SUCCESS;
140 }
141
142
143 VOID
144 WINAPI
145 ServiceMain(DWORD argc, LPTSTR *argv)
146 {
147 DWORD dwError;
148
149 UNREFERENCED_PARAMETER(argc);
150 UNREFERENCED_PARAMETER(argv);
151
152 TRACE("ServiceMain() called\n");
153
154 ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
155 ServiceControlHandler,
156 NULL);
157 if (!ServiceStatusHandle)
158 {
159 ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
160 return;
161 }
162
163 UpdateServiceStatus(SERVICE_START_PENDING);
164
165 dwError = ServiceInit();
166 if (dwError != ERROR_SUCCESS)
167 {
168 ERR("Service stopped (dwError: %lu\n", dwError);
169 UpdateServiceStatus(SERVICE_STOPPED);
170 return;
171 }
172
173 UpdateServiceStatus(SERVICE_RUNNING);
174 }
175
176
177 BOOL WINAPI
178 DllMain(HINSTANCE hinstDLL,
179 DWORD fdwReason,
180 LPVOID lpvReserved)
181 {
182 switch (fdwReason)
183 {
184 case DLL_PROCESS_ATTACH:
185 DisableThreadLibraryCalls(hinstDLL);
186 break;
187
188 case DLL_PROCESS_DETACH:
189 break;
190 }
191
192 return TRUE;
193 }