[SCHEDSVC]
[reactos.git] / reactos / base / services / schedsvc / rpcserver.c
index f351802..1ca2b35 100644 (file)
 
 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 *****************************************************************/
 
@@ -131,8 +112,24 @@ NetrJobAdd(
     pJob->JobId = dwNextJobId++;
     dwJobCount++;
 
+    // Cancel the start timer
+
     /* Append the new job to the job list */
-    InsertTailList(&JobListHead, &pJob->Entry);
+    InsertTailList(&JobListHead, &pJob->JobEntry);
+
+    /* Save the job in the registry */
+    SaveJob(pJob);
+
+    /* Calculate the next start time */
+    CalculateNextStartTime(pJob);
+
+    /* Insert the job into the start list */
+    InsertJobIntoStartList(&StartListHead, pJob);
+#if 0
+    DumpStartList(&StartListHead);
+#endif
+
+    // Update the start timer
 
     /* Release the job list lock */
     RtlReleaseResource(&JobListLock);
@@ -158,16 +155,31 @@ 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);
 
+    // Cancel the start timer
+
     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 the job from the start list */
+            RemoveEntryList(&CurrentJob->StartEntry);
+#if 0
+            DumpStartList(&StartListHead);
+#endif
+
+            /* Remove the job from the registry */
+            DeleteJob(CurrentJob);
+
             NextEntry = JobEntry->Flink;
             if (RemoveEntryList(JobEntry))
             {
@@ -181,6 +193,8 @@ NetrJobDel(
         JobEntry = JobEntry->Flink;
     }
 
+    // Update the start timer
+
     /* Release the job list lock */
     RtlReleaseResource(&JobListLock);
 
@@ -234,7 +248,7 @@ NetrJobEnum(
     JobEntry = JobListHead.Flink;
     while (JobEntry != &JobListHead)
     {
-        CurrentJob = CONTAINING_RECORD(JobEntry, JOB, Entry);
+        CurrentJob = CONTAINING_RECORD(JobEntry, JOB, JobEntry);
 
         if (dwIndex >= dwStartIndex)
         {
@@ -243,7 +257,7 @@ NetrJobEnum(
                           (wcslen(CurrentJob->Command) + 1) * sizeof(WCHAR);
             TRACE("dwEntrySize: %lu\n", dwEntrySize);
 
-            if ((PreferedMaximumLength != DWORD_MAX) &&
+            if ((PreferedMaximumLength != ULONG_MAX) &&
                 (dwRequiredSize + dwEntrySize > PreferedMaximumLength))
                 break;
 
@@ -257,7 +271,7 @@ NetrJobEnum(
     TRACE("dwEntriesToRead: %lu\n", dwEntriesToRead);
     TRACE("dwRequiredSize: %lu\n", dwRequiredSize);
 
-    if (PreferedMaximumLength != DWORD_MAX)
+    if (PreferedMaximumLength != ULONG_MAX)
         dwRequiredSize = PreferedMaximumLength;
 
     TRACE("Allocating dwRequiredSize: %lu\n", dwRequiredSize);
@@ -275,7 +289,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 +356,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)