Leaked source code of windows server 2003
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.

67 lines
1.7 KiB

  1. #include "precomp.h"
  2. #include <TimeKeeper.h>
  3. #include <wbemutil.h>
  4. //#define DUMP_DEBUG_TREES 1
  5. bool CTimeKeeper::DecorateObject(_IWmiObject* pObj)
  6. {
  7. FILETIME ft;
  8. GetSystemTimeAsFileTime(&ft);
  9. {
  10. CInCritSec ics(&m_cs);
  11. if(ft.dwLowDateTime == m_ftLastEvent.dwLowDateTime &&
  12. ft.dwHighDateTime == m_ftLastEvent.dwHighDateTime)
  13. {
  14. //
  15. // This event has the same timestamp as the previous one ---
  16. // let's add the counter to it.
  17. //
  18. if(0xFFFFFFFF - ft.dwLowDateTime > m_dwEventCount)
  19. {
  20. ft.dwLowDateTime += m_dwEventCount++;
  21. }
  22. else
  23. {
  24. ft.dwLowDateTime += m_dwEventCount++;
  25. ft.dwHighDateTime++;
  26. }
  27. }
  28. else
  29. {
  30. //
  31. // Different timestamp --- reset the counter
  32. //
  33. m_dwEventCount = 1; // 0 has been used by us
  34. m_ftLastEvent = ft;
  35. }
  36. }
  37. __int64 i64Stamp = ft.dwLowDateTime + ((__int64)ft.dwHighDateTime << 32);
  38. if(m_lTimeHandle == 0 && !m_bHandleInit)
  39. {
  40. HRESULT hres =
  41. pObj->GetPropertyHandleEx(L"TIME_CREATED", 0, NULL, &m_lTimeHandle);
  42. if(FAILED(hres))
  43. {
  44. ERRORTRACE((LOG_ESS, "Unable to retrieve TIME_CREATED handle: 0x%X\n",
  45. hres));
  46. m_lTimeHandle=0;
  47. }
  48. m_bHandleInit = true;
  49. }
  50. if(m_lTimeHandle)
  51. {
  52. pObj->SetPropByHandle(m_lTimeHandle, 0, sizeof(__int64),
  53. &i64Stamp);
  54. return true;
  55. }
  56. else
  57. return false;
  58. }