[SCHEDSVC]
authorEric Kohl <eric.kohl@reactos.org>
Fri, 14 Apr 2017 21:16:37 +0000 (21:16 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Fri, 14 Apr 2017 21:16:37 +0000 (21:16 +0000)
Calculate the next start time of a job and store it in the job object. DaysOfMonth and DaysOfWeek are not taken into account yet.

svn path=/trunk/; revision=74315

reactos/base/services/schedsvc/job.c
reactos/base/services/schedsvc/precomp.h
reactos/base/services/schedsvc/rpcserver.c

index beebc4f..8e7a90c 100644 (file)
@@ -282,7 +282,8 @@ LoadJobs(VOID)
                 /* Release the job list lock */
                 RtlReleaseResource(&JobListLock);
 
-                // Calculate start time
+                /* Calculate the next start time */
+                CalculateNextStartTime(pJob);
 
                 // Insert job into the start list
 
@@ -310,38 +311,62 @@ done:
 }
 
 
-#if 0
+static
+WORD
+DaysOfMonth(
+    WORD wMonth,
+    WORD wYear)
+{
+    WORD wDaysArray[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+
+    if (wMonth == 2 && wYear % 4 == 0 && wYear % 400 != 0)
+        return 29;
+
+    return wDaysArray[wMonth];
+}
+
+
 VOID
 CalculateNextStartTime(PJOB pJob)
 {
-    SYSTEMTIME Time;
-    DWORD_PTR JobTime;
-    WORD wDay;
-    BOOL bToday = FALSE;
+    SYSTEMTIME StartTime;
+    DWORD_PTR Now;
+
+    GetLocalTime(&StartTime);
 
-    GetLocalTime(&Time);
+    Now = (DWORD_PTR)StartTime.wHour * 3600000 +
+          (DWORD_PTR)StartTime.wMinute * 60000;
 
-    Now = (DWORD_PTR)Time.wHour * 3600000 + 
-          (DWORD_PTR)Time.wMinute * 60000;
-    if (pJob->JobTime > Now)
-        bToday = TRUE;
+    StartTime.wMilliseconds = 0;
+    StartTime.wSecond = 0;
+    StartTime.wHour = (WORD)(pJob->JobTime / 3600000);
+    StartTime.wMinute = (WORD)((pJob->JobTime % 3600000) / 60000);
 
-    if (pJob->DaysOfMonth != 0)
+    /* Start the job tomorrow */
+    if (Now > pJob->JobTime)
     {
-        wDay = 0;
-        for (i = Time.wDay - 1; i < 32; i++)
+        if (StartTime.wDay + 1 > DaysOfMonth(StartTime.wMonth, StartTime.wYear))
         {
-            if (pJob->DaysOfMonth && (1 << i))
+            if (StartTime.wMonth == 12)
             {
-                wDay = i;
-                break;
+                StartTime.wDay = 1;
+                StartTime.wMonth = 1;
+                StartTime.wYear++;
             }
+            else
+            {
+                StartTime.wDay = 1;
+                StartTime.wMonth++;
+            }
+        }
+        else
+        {
+            StartTime.wDay++;
         }
-        ERR("Next day this month: %hu\n", wDay);
     }
-    else if (pJob->DaysOfWeek != 0)
-    {
 
-    }
+    ERR("Next start: %02hu:%02hu %02hu.%02hu.%hu\n", StartTime.wHour,
+        StartTime.wMinute, StartTime.wDay, StartTime.wMonth, StartTime.wYear);
+
+    SystemTimeToFileTime(&StartTime, &pJob->StartTime);
 }
-#endif
index d068608..0da85a0 100644 (file)
@@ -28,7 +28,7 @@ typedef struct _JOB
     LIST_ENTRY JobEntry;
 
     LIST_ENTRY StartEntry;
-    LARGE_INTEGER StartTime;
+    FILETIME StartTime;
     WCHAR Name[9];
 
     DWORD JobId;
@@ -64,6 +64,9 @@ DeleteJob(
 LONG
 LoadJobs(VOID);
 
+VOID
+CalculateNextStartTime(
+    PJOB pJob);
 
 /* rpcserver.c */
 
index 8fc5cc8..e23371e 100644 (file)
@@ -121,11 +121,12 @@ NetrJobAdd(
     /* Save the job in the registry */
     SaveJob(pJob);
 
-    // Calculate start time
+    /* Calculate the next start time */
+    CalculateNextStartTime(pJob);
 
-    // Insert job into start list
+    // Insert job into the start list
 
-    // Update start timer
+    // Update the start timer
 
     /* Return the new job ID */
     *pJobId = pJob->JobId;
@@ -162,9 +163,9 @@ NetrJobDel(
 
         if ((CurrentJob->JobId >= MinJobId) && (CurrentJob->JobId <= MaxJobId))
         {
-            // Remove job from start list
+            // Remove job from the start list
 
-            // Update start timer
+            // Update the start timer
 
             /* Remove the job from the registry */
             DeleteJob(CurrentJob);