mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 09:25:10 +00:00
[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. svn path=/trunk/; revision=74315
This commit is contained in:
parent
2769768c33
commit
645f25c4dd
3 changed files with 57 additions and 28 deletions
|
@ -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(&Time);
|
||||
GetLocalTime(&StartTime);
|
||||
|
||||
Now = (DWORD_PTR)Time.wHour * 3600000 +
|
||||
(DWORD_PTR)Time.wMinute * 60000;
|
||||
if (pJob->JobTime > Now)
|
||||
bToday = TRUE;
|
||||
Now = (DWORD_PTR)StartTime.wHour * 3600000 +
|
||||
(DWORD_PTR)StartTime.wMinute * 60000;
|
||||
|
||||
if (pJob->DaysOfMonth != 0)
|
||||
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 (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++;
|
||||
}
|
||||
}
|
||||
ERR("Next day this month: %hu\n", wDay);
|
||||
else
|
||||
{
|
||||
StartTime.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
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue