mirror of
https://github.com/reactos/reactos.git
synced 2024-06-29 01:12:06 +00:00
[SCHEDSVC]
Implement storing and loading of jobs in the registry. svn path=/trunk/; revision=74288
This commit is contained in:
parent
4e56b66072
commit
a1b2032688
|
@ -4,6 +4,7 @@ add_rpc_files(server ${REACTOS_SOURCE_DIR}/sdk/include/reactos/idl/atsvc.idl)
|
|||
spec2def(schedsvc.dll schedsvc.spec ADD_IMPORTLIB)
|
||||
|
||||
add_library(schedsvc SHARED
|
||||
job.c
|
||||
rpcserver.c
|
||||
schedsvc.c
|
||||
schedsvc.rc
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#define _INC_WINDOWS
|
||||
#define COM_NO_WINDOWS_H
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <windef.h>
|
||||
#include <winbase.h>
|
||||
#include <winreg.h>
|
||||
|
@ -16,9 +17,56 @@
|
|||
|
||||
#include <wine/debug.h>
|
||||
|
||||
NTSYSAPI
|
||||
ULONG
|
||||
NTAPI
|
||||
RtlRandomEx(
|
||||
PULONG Seed);
|
||||
|
||||
typedef struct _JOB
|
||||
{
|
||||
LIST_ENTRY JobEntry;
|
||||
|
||||
LIST_ENTRY StartEntry;
|
||||
LARGE_INTEGER StartTime;
|
||||
WCHAR Name[9];
|
||||
|
||||
DWORD JobId;
|
||||
DWORD_PTR JobTime;
|
||||
DWORD DaysOfMonth;
|
||||
UCHAR DaysOfWeek;
|
||||
UCHAR Flags;
|
||||
WCHAR Command[1];
|
||||
} JOB, *PJOB;
|
||||
|
||||
#define DWORD_MAX 0xffffffffUL
|
||||
|
||||
extern DWORD dwNextJobId;
|
||||
extern DWORD dwJobCount;
|
||||
|
||||
extern LIST_ENTRY JobListHead;
|
||||
extern RTL_RESOURCE JobListLock;
|
||||
|
||||
extern LIST_ENTRY StartListHead;
|
||||
extern RTL_RESOURCE StartListLock;
|
||||
|
||||
|
||||
/* job.c */
|
||||
|
||||
LONG
|
||||
SaveJob(
|
||||
PJOB pJob);
|
||||
|
||||
LONG
|
||||
DeleteJob(
|
||||
PJOB pJob);
|
||||
|
||||
LONG
|
||||
LoadJobs(VOID);
|
||||
|
||||
|
||||
/* rpcserver.c */
|
||||
|
||||
DWORD
|
||||
WINAPI
|
||||
RpcThreadRoutine(
|
||||
|
|
|
@ -32,25 +32,6 @@
|
|||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(schedsvc);
|
||||
|
||||
#define DWORD_MAX 0xffffffffUL
|
||||
|
||||
typedef struct _JOB
|
||||
{
|
||||
LIST_ENTRY Entry;
|
||||
DWORD JobId;
|
||||
|
||||
DWORD_PTR JobTime;
|
||||
DWORD DaysOfMonth;
|
||||
UCHAR DaysOfWeek;
|
||||
UCHAR Flags;
|
||||
WCHAR Command[1];
|
||||
} JOB, *PJOB;
|
||||
|
||||
DWORD dwNextJobId = 0;
|
||||
DWORD dwJobCount = 0;
|
||||
LIST_ENTRY JobListHead;
|
||||
RTL_RESOURCE JobListLock;
|
||||
|
||||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
|
@ -132,11 +113,20 @@ NetrJobAdd(
|
|||
dwJobCount++;
|
||||
|
||||
/* Append the new job to the job list */
|
||||
InsertTailList(&JobListHead, &pJob->Entry);
|
||||
InsertTailList(&JobListHead, &pJob->JobEntry);
|
||||
|
||||
/* Release the job list lock */
|
||||
RtlReleaseResource(&JobListLock);
|
||||
|
||||
/* Save the job in the registry */
|
||||
SaveJob(pJob);
|
||||
|
||||
// Calculate start time
|
||||
|
||||
// Insert job into start list
|
||||
|
||||
// Update start timer
|
||||
|
||||
/* Return the new job ID */
|
||||
*pJobId = pJob->JobId;
|
||||
|
||||
|
@ -158,16 +148,27 @@ NetrJobDel(
|
|||
TRACE("NetrJobDel(%S %lu %lu)\n",
|
||||
ServerName, MinJobId, MaxJobId);
|
||||
|
||||
/* Check the job IDs */
|
||||
if (MinJobId > MaxJobId)
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
|
||||
/* Acquire the job list lock exclusively */
|
||||
RtlAcquireResourceExclusive(&JobListLock, TRUE);
|
||||
|
||||
JobEntry = JobListHead.Flink;
|
||||
while (JobEntry != &JobListHead)
|
||||
{
|
||||
CurrentJob = CONTAINING_RECORD(JobEntry, JOB, Entry);
|
||||
CurrentJob = CONTAINING_RECORD(JobEntry, JOB, JobEntry);
|
||||
|
||||
if ((CurrentJob->JobId >= MinJobId) && (CurrentJob->JobId <= MaxJobId))
|
||||
{
|
||||
// Remove job from start list
|
||||
|
||||
// Update start timer
|
||||
|
||||
/* Remove the job from the registry */
|
||||
DeleteJob(CurrentJob);
|
||||
|
||||
NextEntry = JobEntry->Flink;
|
||||
if (RemoveEntryList(JobEntry))
|
||||
{
|
||||
|
@ -234,7 +235,7 @@ NetrJobEnum(
|
|||
JobEntry = JobListHead.Flink;
|
||||
while (JobEntry != &JobListHead)
|
||||
{
|
||||
CurrentJob = CONTAINING_RECORD(JobEntry, JOB, Entry);
|
||||
CurrentJob = CONTAINING_RECORD(JobEntry, JOB, JobEntry);
|
||||
|
||||
if (dwIndex >= dwStartIndex)
|
||||
{
|
||||
|
@ -275,7 +276,7 @@ NetrJobEnum(
|
|||
JobEntry = JobListHead.Flink;
|
||||
while (JobEntry != &JobListHead)
|
||||
{
|
||||
CurrentJob = CONTAINING_RECORD(JobEntry, JOB, Entry);
|
||||
CurrentJob = CONTAINING_RECORD(JobEntry, JOB, JobEntry);
|
||||
|
||||
if (dwIndex >= dwStartIndex)
|
||||
{
|
||||
|
@ -342,7 +343,7 @@ NetrJobGetInfo(
|
|||
JobEntry = JobListHead.Flink;
|
||||
while (JobEntry != &JobListHead)
|
||||
{
|
||||
CurrentJob = CONTAINING_RECORD(JobEntry, JOB, Entry);
|
||||
CurrentJob = CONTAINING_RECORD(JobEntry, JOB, JobEntry);
|
||||
|
||||
/* Do we have the right job? */
|
||||
if (CurrentJob->JobId == JobId)
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* PROJECT: ReactOS Services
|
||||
* FILE: base/services/schedsvc/schedsvc.c
|
||||
* PURPOSE: Scheduling service
|
||||
* PROGRAMMER: Eric Kohl
|
||||
* PROGRAMMER: Eric Kohl <eric.kohl@reactos.org>
|
||||
*/
|
||||
|
||||
/* INCLUDES *****************************************************************/
|
||||
|
@ -99,6 +99,7 @@ ServiceControlHandler(DWORD dwControl,
|
|||
case SERVICE_CONTROL_SHUTDOWN:
|
||||
TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
|
||||
UpdateServiceStatus(SERVICE_STOP_PENDING);
|
||||
RpcMgmtStopServerListening(NULL);
|
||||
UpdateServiceStatus(SERVICE_STOPPED);
|
||||
return ERROR_SUCCESS;
|
||||
|
||||
|
@ -114,6 +115,7 @@ DWORD
|
|||
ServiceInit(VOID)
|
||||
{
|
||||
HANDLE hThread;
|
||||
DWORD dwError;
|
||||
|
||||
/* Initialize the job list */
|
||||
InitializeListHead(&JobListHead);
|
||||
|
@ -121,6 +123,18 @@ ServiceInit(VOID)
|
|||
/* Initialize the job list lock */
|
||||
RtlInitializeResource(&JobListLock);
|
||||
|
||||
/* Initialize the start list */
|
||||
InitializeListHead(&StartListHead);
|
||||
|
||||
/* Initialize the start list lock */
|
||||
RtlInitializeResource(&StartListLock);
|
||||
|
||||
/* Load stored jobs from the registry */
|
||||
dwError = LoadJobs();
|
||||
if (dwError != ERROR_SUCCESS)
|
||||
return dwError;
|
||||
|
||||
/* Start the RPC thread */
|
||||
hThread = CreateThread(NULL,
|
||||
0,
|
||||
(LPTHREAD_START_ROUTINE)RpcThreadRoutine,
|
||||
|
|
Loading…
Reference in a new issue