Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.1 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. SCHED.CPP
  5. Abstract:
  6. Implements the CSched class which is a crude schedualer.
  7. History:
  8. --*/
  9. #include "precomp.h"
  10. #include <persistcfg.h>
  11. #include "sched.h"
  12. CSched::CSched()
  13. {
  14. for(DWORD dwCnt = 0; dwCnt < EOL; dwCnt++)
  15. m_dwDue[dwCnt] = 0xffffffff;
  16. }
  17. void CSched::SetWorkItem(JobType jt, DWORD dwMsFromNow)
  18. {
  19. m_dwDue[jt] = GetTickCount() + dwMsFromNow;
  20. }
  21. DWORD CSched::GetWaitPeriod()
  22. {
  23. DWORD dwCurr = GetTickCount();
  24. DWORD dwRet = INFINITE;
  25. for(DWORD dwCnt = 0; dwCnt < EOL; dwCnt++)
  26. {
  27. if(m_dwDue[dwCnt] == 0xffffffff)
  28. continue;
  29. if(m_dwDue[dwCnt] < dwCurr)
  30. dwRet = 10;
  31. else
  32. {
  33. DWORD dwGap = m_dwDue[dwCnt] - dwCurr;
  34. if(dwGap < dwRet)
  35. dwRet = dwGap;
  36. }
  37. }
  38. return dwRet;
  39. }
  40. bool CSched::IsWorkItemDue(JobType jt)
  41. {
  42. DWORD dwCurr = GetTickCount();
  43. if(m_dwDue[jt] == 0xffffffff)
  44. return FALSE;
  45. return (m_dwDue[jt] <= dwCurr);
  46. }
  47. void CSched::ClearWorkItem(JobType jt)
  48. {
  49. m_dwDue[jt] = INFINITE;
  50. }
  51. void CSched::StartCoreIfEssNeeded()
  52. {
  53. DWORD dwEssNeedsLoading = 0;
  54. DWORD dwBackupNeeded = 0;
  55. // Get the values from the configuration time
  56. CPersistentConfig per;
  57. per.GetPersistentCfgValue(PERSIST_CFGVAL_CORE_ESS_NEEDS_LOADING, dwEssNeedsLoading);
  58. per.GetPersistentCfgValue(PERSIST_CFGVAL_CORE_NEEDSBACKUPCHECK, dwBackupNeeded);
  59. if(dwEssNeedsLoading || dwBackupNeeded)
  60. {
  61. IWbemLevel1Login * pCore = NULL;
  62. SCODE sc = CoCreateInstance(CLSID_InProcWbemLevel1Login,
  63. NULL,
  64. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  65. IID_IUnknown,
  66. (void**)&pCore);
  67. if(sc == S_OK)
  68. {
  69. IWbemServices * pServ = NULL;
  70. sc = pCore->NTLMLogin(L"Root", NULL, 0, NULL, &pServ);
  71. if(SUCCEEDED(sc))
  72. pServ->Release();
  73. pCore->Release();
  74. }
  75. }
  76. }