ReactOS 0.4.15-dev-8422-g6219a1a
schedsvc.c File Reference
#include "precomp.h"
Include dependency graph for schedsvc.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (schedsvc)
 
static VOID UpdateServiceStatus (DWORD dwState)
 
static DWORD WINAPI ServiceControlHandler (DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
 
static DWORD ServiceInit (VOID)
 
VOID WINAPI SchedServiceMain (DWORD argc, LPTSTR *argv)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 

Variables

static WCHAR ServiceName [] = L"Schedule"
 
static SERVICE_STATUS_HANDLE ServiceStatusHandle
 
static SERVICE_STATUS ServiceStatus
 
HANDLE Events [3] = {NULL, NULL, NULL}
 

Function Documentation

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 270 of file schedsvc.c.

273{
274 switch (fdwReason)
275 {
278 break;
279
281 break;
282 }
283
284 return TRUE;
285}
#define TRUE
Definition: types.h:120
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85

◆ SchedServiceMain()

VOID WINAPI SchedServiceMain ( DWORD  argc,
LPTSTR argv 
)

Definition at line 198 of file schedsvc.c.

199{
200 DWORD dwWait, dwError;
201
204
205 TRACE("SchedServiceMain()\n");
206
209 NULL);
211 {
212 ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
213 return;
214 }
215
217
218 dwError = ServiceInit();
219 if (dwError != ERROR_SUCCESS)
220 {
221 ERR("Service stopped (dwError: %lu\n", dwError);
223 return;
224 }
225
227
229
230 for (;;)
231 {
232 /* Wait for the next event */
233 TRACE("Wait for next event!\n");
235 if (dwWait == WAIT_OBJECT_0)
236 {
237 TRACE("Stop event signaled!\n");
238 break;
239 }
240 else if (dwWait == WAIT_OBJECT_0 + 1)
241 {
242 TRACE("Update event signaled!\n");
243
247 }
248 else if (dwWait == WAIT_OBJECT_0 + 2)
249 {
250 TRACE("Timeout: Start the next job!\n");
251
256 }
257 }
258
259 /* Close the start and update event handles */
263
264 /* Stop the service */
266}
static int argc
Definition: ServiceArgs.c:12
RTL_RESOURCE JobListLock
Definition: job.c:30
VOID GetNextJobTimeout(HANDLE hTimer)
Definition: job.c:44
VOID RunCurrentJobs(VOID)
Definition: job.c:122
static WCHAR ServiceName[]
Definition: schedsvc.c:35
HANDLE Events[3]
Definition: schedsvc.c:40
static DWORD ServiceInit(VOID)
Definition: schedsvc.c:130
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: schedsvc.c:76
static VOID UpdateServiceStatus(DWORD dwState)
Definition: schedsvc.c:46
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: schedsvc.c:37
#define ERR(fmt,...)
Definition: precomp.h:57
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INFINITE
Definition: serial.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
#define argv
Definition: mplay32.c:18
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceShared(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceExclusive(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)
NTSYSAPI VOID NTAPI RtlReleaseResource(_In_ PRTL_RESOURCE Resource)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:812
#define TRACE(s)
Definition: solgame.cpp:4
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24

◆ ServiceControlHandler()

static DWORD WINAPI ServiceControlHandler ( DWORD  dwControl,
DWORD  dwEventType,
LPVOID  lpEventData,
LPVOID  lpContext 
)
static

Definition at line 76 of file schedsvc.c.

80{
81 TRACE("ServiceControlHandler()\n");
82
83 switch (dwControl)
84 {
87 TRACE(" SERVICE_CONTROL_STOP/SERVICE_CONTROL_SHUTDOWN received\n");
89 /* Stop listening to incoming RPC messages */
91 if (Events[0] != NULL)
92 SetEvent(Events[0]);
93 return ERROR_SUCCESS;
94
96 TRACE(" SERVICE_CONTROL_PAUSE received\n");
98 return ERROR_SUCCESS;
99
101 TRACE(" SERVICE_CONTROL_CONTINUE received\n");
103 return ERROR_SUCCESS;
104
106 TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
109 return ERROR_SUCCESS;
110
111#if 0
112 case 128:
113 TRACE(" Start Shell control received\n");
114 return ERROR_SUCCESS;
115
116 case 129:
117 TRACE(" Logoff control received\n");
118 return ERROR_SUCCESS;
119#endif
120
121 default:
122 TRACE(" Control %lu received\n", dwControl);
124 }
125}
static SERVICE_STATUS ServiceStatus
Definition: schedsvc.c:38
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1596
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:997
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40
#define SERVICE_PAUSED
Definition: winsvc.h:27
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39

Referenced by SchedServiceMain().

◆ ServiceInit()

static DWORD ServiceInit ( VOID  )
static

Definition at line 130 of file schedsvc.c.

131{
133 DWORD dwError;
134
135 /* Initialize the job list */
137
138 /* Initialize the job list lock */
140
141 /* Initialize the start list */
143
144 /* Initialize the start list lock */
146
147 /* Load stored jobs from the registry */
148 dwError = LoadJobs();
149 if (dwError != ERROR_SUCCESS)
150 return dwError;
151
152 /* Start the RPC thread */
154 0,
156 NULL,
157 0,
158 NULL);
159 if (!hThread)
160 {
161 ERR("Could not create the RPC thread\n");
162 return GetLastError();
163 }
164
166
167 /* Create the stop event */
169 if (Events[0] == NULL)
170 {
171 ERR("Could not create the stop event\n");
172 return GetLastError();
173 }
174
175 /* Create the update event */
177 if (Events[1] == NULL)
178 {
179 ERR("Could not create the update event\n");
181 return GetLastError();
182 }
183
185 if (Events[2] == NULL)
186 {
187 ERR("Could not create the timer\n");
190 return GetLastError();
191 }
192
193 return ERROR_SUCCESS;
194}
DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
Definition: rpcserver.c:20
LIST_ENTRY JobListHead
Definition: job.c:29
LONG LoadJobs(VOID)
Definition: job.c:318
RTL_RESOURCE StartListLock
Definition: job.c:33
LIST_ENTRY StartListHead
Definition: job.c:32
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSYSAPI VOID NTAPI RtlInitializeResource(_In_ PRTL_RESOURCE Resource)
HANDLE hThread
Definition: wizard.c:28
HANDLE WINAPI CreateWaitableTimerW(IN LPSECURITY_ATTRIBUTES lpTimerAttributes OPTIONAL, IN BOOL bManualReset, IN LPCWSTR lpTimerName OPTIONAL)
Definition: synch.c:331
#define CreateEvent
Definition: winbase.h:3748
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:729

Referenced by SchedServiceMain().

◆ UpdateServiceStatus()

static VOID UpdateServiceStatus ( DWORD  dwState)
static

Definition at line 46 of file schedsvc.c.

47{
50
51 if (dwState == SERVICE_PAUSED || dwState == SERVICE_RUNNING)
55 else
57
61
62 if (dwState == SERVICE_START_PENDING ||
63 dwState == SERVICE_STOP_PENDING ||
64 dwState == SERVICE_PAUSE_PENDING ||
65 dwState == SERVICE_CONTINUE_PENDING)
67 else
69
72}
DWORD dwServiceType
Definition: winsvc.h:99
DWORD dwWin32ExitCode
Definition: winsvc.h:102
DWORD dwControlsAccepted
Definition: winsvc.h:101
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwCurrentState
Definition: winsvc.h:100
DWORD dwCheckPoint
Definition: winsvc.h:104
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_ACCEPT_PAUSE_CONTINUE
Definition: winsvc.h:29
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
#define SERVICE_WIN32_SHARE_PROCESS
Definition: cmtypes.h:963

Referenced by SchedServiceMain(), and ServiceControlHandler().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( schedsvc  )

Variable Documentation

◆ Events

◆ ServiceName

WCHAR ServiceName[] = L"Schedule"
static

Definition at line 35 of file schedsvc.c.

Referenced by SchedServiceMain().

◆ ServiceStatus

SERVICE_STATUS ServiceStatus
static

◆ ServiceStatusHandle

SERVICE_STATUS_HANDLE ServiceStatusHandle
static

Definition at line 37 of file schedsvc.c.

Referenced by SchedServiceMain(), ServiceControlHandler(), and UpdateServiceStatus().