[CMAKE]
[reactos.git] / 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 #define WIN32_NO_STATUS
12 #include <windows.h>
13
14 #include "wine/debug.h"
15
16 WINE_DEFAULT_DEBUG_CHANNEL(spoolsv);
17
18
19 /* GLOBALS ******************************************************************/
20
21 static VOID CALLBACK ServiceMain(DWORD argc, LPWSTR *argv);
22 static WCHAR ServiceName[] = L"Spooler";
23 static SERVICE_TABLE_ENTRYW ServiceTable[] =
24 {
25 {ServiceName, ServiceMain},
26 {NULL, NULL}
27 };
28
29 SERVICE_STATUS_HANDLE ServiceStatusHandle;
30 SERVICE_STATUS ServiceStatus;
31
32
33 /* FUNCTIONS *****************************************************************/
34
35 static VOID
36 UpdateServiceStatus(DWORD dwState)
37 {
38 ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
39 ServiceStatus.dwCurrentState = dwState;
40
41 if (dwState == SERVICE_RUNNING)
42 ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
43 else if (dwState == SERVICE_PAUSED)
44 ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE;
45 else
46 ServiceStatus.dwControlsAccepted = 0;
47
48 ServiceStatus.dwWin32ExitCode = 0;
49 ServiceStatus.dwServiceSpecificExitCode = 0;
50 ServiceStatus.dwCheckPoint = 0;
51
52 if (dwState == SERVICE_START_PENDING ||
53 dwState == SERVICE_STOP_PENDING ||
54 dwState == SERVICE_PAUSE_PENDING ||
55 dwState == SERVICE_CONTINUE_PENDING)
56 ServiceStatus.dwWaitHint = 10000;
57 else
58 ServiceStatus.dwWaitHint = 0;
59
60 SetServiceStatus(ServiceStatusHandle,
61 &ServiceStatus);
62 }
63
64
65 static DWORD WINAPI
66 ServiceControlHandler(DWORD dwControl,
67 DWORD dwEventType,
68 LPVOID lpEventData,
69 LPVOID lpContext)
70 {
71 TRACE("ServiceControlHandler() called\n");
72
73 switch (dwControl)
74 {
75 case SERVICE_CONTROL_STOP:
76 TRACE(" SERVICE_CONTROL_STOP received\n");
77 UpdateServiceStatus(SERVICE_STOPPED);
78 return ERROR_SUCCESS;
79
80 case SERVICE_CONTROL_PAUSE:
81 TRACE(" SERVICE_CONTROL_PAUSE received\n");
82 UpdateServiceStatus(SERVICE_PAUSED);
83 return ERROR_SUCCESS;
84
85 case SERVICE_CONTROL_CONTINUE:
86 TRACE(" SERVICE_CONTROL_CONTINUE received\n");
87 UpdateServiceStatus(SERVICE_RUNNING);
88 return ERROR_SUCCESS;
89
90 case SERVICE_CONTROL_INTERROGATE:
91 TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
92 SetServiceStatus(ServiceStatusHandle,
93 &ServiceStatus);
94 return ERROR_SUCCESS;
95
96 case SERVICE_CONTROL_SHUTDOWN:
97 TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
98 UpdateServiceStatus(SERVICE_STOPPED);
99 return ERROR_SUCCESS;
100
101 default :
102 TRACE(" Control %lu received\n");
103 return ERROR_CALL_NOT_IMPLEMENTED;
104 }
105 }
106
107
108 static VOID CALLBACK
109 ServiceMain(DWORD argc, LPWSTR *argv)
110 {
111 UNREFERENCED_PARAMETER(argc);
112 UNREFERENCED_PARAMETER(argv);
113
114 TRACE("ServiceMain() called\n");
115
116 ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
117 ServiceControlHandler,
118 NULL);
119
120 TRACE("Calling SetServiceStatus()\n");
121 UpdateServiceStatus(SERVICE_RUNNING);
122 TRACE("SetServiceStatus() called\n");
123
124
125 TRACE("ServiceMain() done\n");
126 }
127
128
129 int
130 wmain(int argc, WCHAR *argv[])
131 {
132 UNREFERENCED_PARAMETER(argc);
133 UNREFERENCED_PARAMETER(argv);
134
135 TRACE("Spoolsv: main() started\n");
136
137 StartServiceCtrlDispatcher(ServiceTable);
138
139 TRACE("Spoolsv: main() done\n");
140
141 return 0;
142 }
143
144 /* EOF */