Author: ekohl
Date: Fri Apr 14 21:16:37 2017
New Revision: 74315
URL:
http://svn.reactos.org/svn/reactos?rev=74315&view=rev
Log:
[SCHEDSVC]
Calculate the next start time of a job and store it in the job object. DaysOfMonth and
DaysOfWeek are not taken into account yet.
Modified:
trunk/reactos/base/services/schedsvc/job.c
trunk/reactos/base/services/schedsvc/precomp.h
trunk/reactos/base/services/schedsvc/rpcserver.c
Modified: trunk/reactos/base/services/schedsvc/job.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/schedsvc/job…
==============================================================================
--- trunk/reactos/base/services/schedsvc/job.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/schedsvc/job.c [iso-8859-1] Fri Apr 14 21:16:37 2017
@@ -282,7 +282,8 @@
/* 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 @@
}
-#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;
-
- GetLocalTime(&Time);
-
- Now = (DWORD_PTR)Time.wHour * 3600000 +
- (DWORD_PTR)Time.wMinute * 60000;
- if (pJob->JobTime > Now)
- bToday = TRUE;
-
- if (pJob->DaysOfMonth != 0)
+ SYSTEMTIME StartTime;
+ DWORD_PTR Now;
+
+ GetLocalTime(&StartTime);
+
+ Now = (DWORD_PTR)StartTime.wHour * 3600000 +
+ (DWORD_PTR)StartTime.wMinute * 60000;
+
+ StartTime.wMilliseconds = 0;
+ StartTime.wSecond = 0;
+ StartTime.wHour = (WORD)(pJob->JobTime / 3600000);
+ StartTime.wMinute = (WORD)((pJob->JobTime % 3600000) / 60000);
+
+ /* Start the job tomorrow */
+ if (Now > pJob->JobTime)
{
- wDay = 0;
- for (i = Time.wDay - 1; i < 32; i++)
- {
- if (pJob->DaysOfMonth && (1 << i))
+ if (StartTime.wDay + 1 > DaysOfMonth(StartTime.wMonth, StartTime.wYear))
+ {
+ if (StartTime.wMonth == 12)
{
- wDay = i;
- break;
+ StartTime.wDay = 1;
+ StartTime.wMonth = 1;
+ StartTime.wYear++;
}
- }
- ERR("Next day this month: %hu\n", wDay);
+ else
+ {
+ StartTime.wDay = 1;
+ StartTime.wMonth++;
+ }
+ }
+ else
+ {
+ StartTime.wDay++;
+ }
}
- else if (pJob->DaysOfWeek != 0)
- {
-
- }
-}
-#endif
+
+ ERR("Next start: %02hu:%02hu %02hu.%02hu.%hu\n", StartTime.wHour,
+ StartTime.wMinute, StartTime.wDay, StartTime.wMonth, StartTime.wYear);
+
+ SystemTimeToFileTime(&StartTime, &pJob->StartTime);
+}
Modified: trunk/reactos/base/services/schedsvc/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/schedsvc/pre…
==============================================================================
--- trunk/reactos/base/services/schedsvc/precomp.h [iso-8859-1] (original)
+++ trunk/reactos/base/services/schedsvc/precomp.h [iso-8859-1] Fri Apr 14 21:16:37 2017
@@ -28,7 +28,7 @@
LIST_ENTRY JobEntry;
LIST_ENTRY StartEntry;
- LARGE_INTEGER StartTime;
+ FILETIME StartTime;
WCHAR Name[9];
DWORD JobId;
@@ -64,6 +64,9 @@
LONG
LoadJobs(VOID);
+VOID
+CalculateNextStartTime(
+ PJOB pJob);
/* rpcserver.c */
Modified: trunk/reactos/base/services/schedsvc/rpcserver.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/schedsvc/rpc…
==============================================================================
--- trunk/reactos/base/services/schedsvc/rpcserver.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/schedsvc/rpcserver.c [iso-8859-1] Fri Apr 14 21:16:37
2017
@@ -121,11 +121,12 @@
/* Save the job in the registry */
SaveJob(pJob);
- // Calculate start time
-
- // Insert job into start list
-
- // Update start timer
+ /* Calculate the next start time */
+ CalculateNextStartTime(pJob);
+
+ // Insert job into the start list
+
+ // Update the start timer
/* Return the new job ID */
*pJobId = pJob->JobId;
@@ -162,9 +163,9 @@
if ((CurrentJob->JobId >= MinJobId) && (CurrentJob->JobId <=
MaxJobId))
{
- // Remove job from start list
-
- // Update start timer
+ // Remove job from the start list
+
+ // Update the start timer
/* Remove the job from the registry */
DeleteJob(CurrentJob);