MQTTTime.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*******************************************************************************
  2. * Copyright (c) 2020 IBM Corp.
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v2.0
  6. * and Eclipse Distribution License v1.0 which accompany this distribution.
  7. *
  8. * The Eclipse Public License is available at
  9. * https://www.eclipse.org/legal/epl-2.0/
  10. * and the Eclipse Distribution License is available at
  11. * http://www.eclipse.org/org/documents/edl-v10.php.
  12. *
  13. * Contributors:
  14. * Ian Craggs - initial implementation
  15. *******************************************************************************/
  16. #if !defined(MQTTTIME_H)
  17. #define MQTTTIME_H
  18. #include <stdint.h>
  19. #if defined(_WIN32) || defined(_WIN64)
  20. #include <windows.h>
  21. #if WINVER >= _WIN32_WINNT_VISTA
  22. #define START_TIME_TYPE ULONGLONG
  23. #define START_TIME_ZERO 0
  24. #else
  25. #define START_TIME_TYPE DWORD
  26. #define START_TIME_ZERO 0
  27. #endif
  28. #elif defined(AIX)
  29. #define START_TIME_TYPE struct timespec
  30. #define START_TIME_ZERO {0, 0}
  31. #else
  32. #include <sys/time.h>
  33. #define START_TIME_TYPE struct timeval
  34. #define START_TIME_ZERO {0, 0}
  35. #endif
  36. #define ELAPSED_TIME_TYPE uint64_t
  37. #define DIFF_TIME_TYPE int64_t
  38. void MQTTTime_sleep(ELAPSED_TIME_TYPE milliseconds);
  39. START_TIME_TYPE MQTTTime_start_clock(void);
  40. START_TIME_TYPE MQTTTime_now(void);
  41. ELAPSED_TIME_TYPE MQTTTime_elapsed(START_TIME_TYPE milliseconds);
  42. DIFF_TIME_TYPE MQTTTime_difftime(START_TIME_TYPE t_new, START_TIME_TYPE t_old);
  43. #endif