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
,
65 ServiceControlHandler(DWORD dwControl
,
70 TRACE("ServiceControlHandler() called\n");
74 case SERVICE_CONTROL_STOP
:
75 TRACE(" SERVICE_CONTROL_STOP received\n");
76 UpdateServiceStatus(SERVICE_STOP_PENDING
);
77 /* Stop listening to incoming RPC messages */
78 RpcMgmtStopServerListening(NULL
);
79 UpdateServiceStatus(SERVICE_STOPPED
);
82 case SERVICE_CONTROL_PAUSE
:
83 TRACE(" SERVICE_CONTROL_PAUSE received\n");
84 UpdateServiceStatus(SERVICE_PAUSED
);
87 case SERVICE_CONTROL_CONTINUE
:
88 TRACE(" SERVICE_CONTROL_CONTINUE received\n");
89 UpdateServiceStatus(SERVICE_RUNNING
);
92 case SERVICE_CONTROL_INTERROGATE
:
93 TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
94 SetServiceStatus(ServiceStatusHandle
,
98 case SERVICE_CONTROL_SHUTDOWN
:
99 TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
100 UpdateServiceStatus(SERVICE_STOP_PENDING
);
101 UpdateServiceStatus(SERVICE_STOPPED
);
102 return ERROR_SUCCESS
;
105 TRACE(" Control %lu received\n", dwControl
);
106 return ERROR_CALL_NOT_IMPLEMENTED
;
117 hThread
= CreateThread(NULL
,
119 (LPTHREAD_START_ROUTINE
)RpcThreadRoutine
,
126 ERR("Can't create PortThread\n");
127 return GetLastError();
130 CloseHandle(hThread
);
132 return ERROR_SUCCESS
;
137 SchedServiceMain(DWORD argc
, LPTSTR
*argv
)
141 UNREFERENCED_PARAMETER(argc
);
142 UNREFERENCED_PARAMETER(argv
);
144 TRACE("SchedServiceMain() called\n");
146 ServiceStatusHandle
= RegisterServiceCtrlHandlerExW(ServiceName
,
147 ServiceControlHandler
,
149 if (!ServiceStatusHandle
)
151 ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
155 UpdateServiceStatus(SERVICE_START_PENDING
);
157 dwError
= ServiceInit();
158 if (dwError
!= ERROR_SUCCESS
)
160 ERR("Service stopped (dwError: %lu\n", dwError
);
161 UpdateServiceStatus(SERVICE_STOPPED
);
165 UpdateServiceStatus(SERVICE_RUNNING
);
170 DllMain(HINSTANCE hinstDLL
,
176 case DLL_PROCESS_ATTACH
:
177 DisableThreadLibraryCalls(hinstDLL
);
180 case DLL_PROCESS_DETACH
: