[RTL][NTDLL]
[reactos.git] / reactos / base / services / spoolsv / spoolsv.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: services/spoolsv/spoolsv.c
5 * PURPOSE: Printer spooler
6 * PROGRAMMER: Eric Kohl
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include <windef.h>
12 #include <winsvc.h>
13 #include <wine/debug.h>
14
15 WINE_DEFAULT_DEBUG_CHANNEL(spoolsv);
16
17
18 /* GLOBALS ******************************************************************/
19
20 static VOID CALLBACK ServiceMain(DWORD argc, LPWSTR *argv);
21 static WCHAR ServiceName[] = L"Spooler";
22 static SERVICE_TABLE_ENTRYW ServiceTable[] =
23 {
24 {ServiceName, ServiceMain},
25 {NULL, NULL}
26 };
27
28 SERVICE_STATUS_HANDLE ServiceStatusHandle;
29 SERVICE_STATUS ServiceStatus;
30
31
32 /* FUNCTIONS *****************************************************************/
33
34 static VOID
35 UpdateServiceStatus(DWORD dwState)
36 {
37 ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
38 ServiceStatus.dwCurrentState = dwState;
39
40 if (dwState == SERVICE_RUNNING)
41 ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
42 else
43 ServiceStatus.dwControlsAccepted = 0;
44
45 ServiceStatus.dwWin32ExitCode = 0;
46 ServiceStatus.dwServiceSpecificExitCode = 0;
47 ServiceStatus.dwCheckPoint = 0;
48
49 if (dwState == SERVICE_START_PENDING ||
50 dwState == SERVICE_STOP_PENDING)
51 ServiceStatus.dwWaitHint = 10000;
52 else
53 ServiceStatus.dwWaitHint = 0;
54
55 SetServiceStatus(ServiceStatusHandle,
56 &ServiceStatus);
57 }
58
59
60 static DWORD WINAPI
61 ServiceControlHandler(DWORD dwControl,
62 DWORD dwEventType,
63 LPVOID lpEventData,
64 LPVOID lpContext)
65 {
66 TRACE("ServiceControlHandler() called\n");
67
68 switch (dwControl)
69 {
70 case SERVICE_CONTROL_STOP:
71 TRACE(" SERVICE_CONTROL_STOP received\n");
72 UpdateServiceStatus(SERVICE_STOPPED);
73 return ERROR_SUCCESS;
74
75 case SERVICE_CONTROL_INTERROGATE:
76 TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
77 SetServiceStatus(ServiceStatusHandle,
78 &ServiceStatus);
79 return ERROR_SUCCESS;
80
81 case SERVICE_CONTROL_SHUTDOWN:
82 TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
83 UpdateServiceStatus(SERVICE_STOPPED);
84 return ERROR_SUCCESS;
85
86 default :
87 TRACE(" Control %lu received\n");
88 return ERROR_CALL_NOT_IMPLEMENTED;
89 }
90 }
91
92
93 static VOID CALLBACK
94 ServiceMain(DWORD argc, LPWSTR *argv)
95 {
96 UNREFERENCED_PARAMETER(argc);
97 UNREFERENCED_PARAMETER(argv);
98
99 TRACE("ServiceMain() called\n");
100
101 ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
102 ServiceControlHandler,
103 NULL);
104
105 TRACE("Calling SetServiceStatus()\n");
106 UpdateServiceStatus(SERVICE_RUNNING);
107 TRACE("SetServiceStatus() called\n");
108
109
110 TRACE("ServiceMain() done\n");
111 }
112
113
114 int
115 wmain(int argc, WCHAR *argv[])
116 {
117 UNREFERENCED_PARAMETER(argc);
118 UNREFERENCED_PARAMETER(argv);
119
120 TRACE("Spoolsv: main() started\n");
121
122 StartServiceCtrlDispatcher(ServiceTable);
123
124 TRACE("Spoolsv: main() done\n");
125
126 return 0;
127 }
128
129 /* EOF */