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 17 #if !defined(MQTTTIME_H) 18 #define MQTTTIME_H 19 20 #include <stdint.h> 21 22 #if defined(_WIN32) || defined(_WIN64) 23 #include <windows.h> 24 #if WINVER >= _WIN32_WINNT_VISTA 25 #define START_TIME_TYPE ULONGLONG 26 #define START_TIME_ZERO 0 27 #else 28 #define START_TIME_TYPE DWORD 29 #define START_TIME_ZERO 0 30 #endif 31 #elif defined(AIX) 32 #define START_TIME_TYPE struct timespec 33 #define START_TIME_ZERO {0, 0} 34 #else 35 #include <sys/time.h> 36 #define START_TIME_TYPE struct timeval 37 #define START_TIME_ZERO {0, 0} 38 #endif 39 40 #define ELAPSED_TIME_TYPE uint64_t 41 #define DIFF_TIME_TYPE int64_t 42 43 void MQTTTime_sleep(ELAPSED_TIME_TYPE milliseconds); 44 START_TIME_TYPE MQTTTime_start_clock(void); 45 START_TIME_TYPE MQTTTime_now(void); 46 ELAPSED_TIME_TYPE MQTTTime_elapsed(START_TIME_TYPE milliseconds); 47 DIFF_TIME_TYPE MQTTTime_difftime(START_TIME_TYPE t_new, START_TIME_TYPE t_old); 48 49 #endif 50