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.

97 lines
2.1 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // TimeOfDay.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines the class TimeOfDay.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/04/1998 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <ias.h>
  19. #include <TimeOfDay.h>
  20. #include <textmap.h>
  21. //////////
  22. // Global evaluator used by all TimeOfDay objects.
  23. //////////
  24. TimeOfDayEvaluator theTimeOfDayEvaluator;
  25. BOOL TimeOfDayEvaluator::isCurrentHourSet(PBYTE hourMap) const throw ()
  26. {
  27. _ASSERT(hourMap != NULL);
  28. //////////
  29. // Determine the system time as a 64-bit integer.
  30. //////////
  31. ULARGE_INTEGER now;
  32. GetSystemTimeAsFileTime((LPFILETIME)&now);
  33. _serialize
  34. //////////
  35. // The call to GetLocalTime is very expensive, so we'll cache the results
  36. // and only update every 6.7 seconds.
  37. //////////
  38. if ((now.QuadPart - lastUpdate) >> 26)
  39. {
  40. // Reset the cache time.
  41. lastUpdate = now.QuadPart;
  42. // Get the time in local SYSTEMTIME format.
  43. SYSTEMTIME st;
  44. GetLocalTime(&st);
  45. //////////
  46. // Compute the offset and mask.
  47. //////////
  48. DWORD hour = st.wDayOfWeek * 24 + st.wHour;
  49. offset = hour >> 3;
  50. mask = 0x80 >> (hour & 0x7);
  51. }
  52. // Check the appropriate bit in the hour map.
  53. return (hourMap[offset] & mask) != 0;
  54. }
  55. STDMETHODIMP TimeOfDay::IsTrue(IRequest*, VARIANT_BOOL *pVal)
  56. {
  57. _ASSERT(pVal != NULL);
  58. *pVal = theTimeOfDayEvaluator.isCurrentHourSet(hourMap) ? VARIANT_TRUE
  59. : VARIANT_FALSE;
  60. return S_OK;
  61. }
  62. STDMETHODIMP TimeOfDay::put_ConditionText(BSTR newVal)
  63. {
  64. // Convert the string to an hour map.
  65. BYTE tempMap[IAS_HOUR_MAP_LENGTH];
  66. DWORD dw = IASHourMapFromText(newVal, tempMap);
  67. if (dw != NO_ERROR) { return HRESULT_FROM_WIN32(dw); }
  68. // Save the text.
  69. HRESULT hr = Condition::put_ConditionText(newVal);
  70. // Save the hour map.
  71. if (SUCCEEDED(hr))
  72. {
  73. memcpy(hourMap, tempMap, sizeof(hourMap));
  74. }
  75. return hr;
  76. }