3 * Copyright (C) 2015 ReactOS Team
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.
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.
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.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS Services
22 * FILE: base/services/schedsvc/schedsvc.c
23 * PURPOSE: Scheduling service
24 * PROGRAMMER: Eric Kohl
27 /* INCLUDES *****************************************************************/
31 WINE_DEFAULT_DEBUG_CHANNEL(schedsvc
);
33 /* GLOBALS ******************************************************************/
35 static WCHAR ServiceName
[] = L
"Schedule";
37 static SERVICE_STATUS_HANDLE ServiceStatusHandle
;
38 static SERVICE_STATUS ServiceStatus
;
40 /* FUNCTIONS *****************************************************************/
43 UpdateServiceStatus(DWORD dwState
)
45 ServiceStatus
.dwServiceType
= SERVICE_WIN32_OWN_PROCESS
;
46 ServiceStatus
.dwCurrentState
= dwState
;
47 ServiceStatus
.dwControlsAccepted
= 0;
48 ServiceStatus
.dwWin32ExitCode
= 0;
49 ServiceStatus
.dwServiceSpecificExitCode
= 0;
50 ServiceStatus
.dwCheckPoint
= 0;
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;
58 ServiceStatus
.dwWaitHint
= 0;
60 SetServiceStatus(ServiceStatusHandle
,
66 ServiceControlHandler(DWORD dwControl
,
71 TRACE("ServiceControlHandler() called\n");
75 case SERVICE_CONTROL_STOP
:
76 TRACE(" SERVICE_CONTROL_STOP received\n");
77 UpdateServiceStatus(SERVICE_STOP_PENDING
);
78 /* Stop listening to incoming RPC messages */
79 RpcMgmtStopServerListening(NULL
);
80 UpdateServiceStatus(SERVICE_STOPPED
);
83 case SERVICE_CONTROL_PAUSE
:
84 TRACE(" SERVICE_CONTROL_PAUSE received\n");
85 UpdateServiceStatus(SERVICE_PAUSED
);
88 case SERVICE_CONTROL_CONTINUE
:
89 TRACE(" SERVICE_CONTROL_CONTINUE received\n");
90 UpdateServiceStatus(SERVICE_RUNNING
);
93 case SERVICE_CONTROL_INTERROGATE
:
94 TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
95 SetServiceStatus(ServiceStatusHandle
,
99 case SERVICE_CONTROL_SHUTDOWN
:
100 TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
101 UpdateServiceStatus(SERVICE_STOP_PENDING
);
102 UpdateServiceStatus(SERVICE_STOPPED
);
103 return ERROR_SUCCESS
;
106 TRACE(" Control %lu received\n", dwControl
);
107 return ERROR_CALL_NOT_IMPLEMENTED
;
118 /* Initialize the job list */
119 InitializeListHead(&JobListHead
);
121 /* Initialize the job list lock */
122 RtlInitializeResource(&JobListLock
);
124 hThread
= CreateThread(NULL
,
126 (LPTHREAD_START_ROUTINE
)RpcThreadRoutine
,
132 ERR("Can't create PortThread\n");
133 return GetLastError();
136 CloseHandle(hThread
);
138 return ERROR_SUCCESS
;
143 SchedServiceMain(DWORD argc
, LPTSTR
*argv
)
147 UNREFERENCED_PARAMETER(argc
);
148 UNREFERENCED_PARAMETER(argv
);
150 TRACE("SchedServiceMain() called\n");
152 ServiceStatusHandle
= RegisterServiceCtrlHandlerExW(ServiceName
,
153 ServiceControlHandler
,
155 if (!ServiceStatusHandle
)
157 ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
161 UpdateServiceStatus(SERVICE_START_PENDING
);
163 dwError
= ServiceInit();
164 if (dwError
!= ERROR_SUCCESS
)
166 ERR("Service stopped (dwError: %lu\n", dwError
);
167 UpdateServiceStatus(SERVICE_STOPPED
);
171 UpdateServiceStatus(SERVICE_RUNNING
);
176 DllMain(HINSTANCE hinstDLL
,
182 case DLL_PROCESS_ATTACH
:
183 DisableThreadLibraryCalls(hinstDLL
);
186 case DLL_PROCESS_DETACH
: