Move PBD::canonical_path to pbd/file_utils.h/cc and reimplement for Windows
[ardour.git] / libs / pbd / pbd / windows_timer_utils.h
1 /*
2  * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #ifndef PBD_WINDOWS_TIMER_UTILS_H
20 #define PBD_WINDOWS_TIMER_UTILS_H
21
22 #include <stdint.h>
23
24 #include "pbd/libpbd_visibility.h"
25
26 namespace PBD {
27
28 namespace MMTIMERS {
29
30 /**
31  * Get the minimum Multimedia Timer resolution as supported by the system
32  * @return true if getting min timer resolution was not successful
33  */
34 bool LIBPBD_API get_min_resolution (uint32_t& timer_resolution_ms);
35
36 /**
37  * Set the minimum Multimedia Timer resolution as supported by the system
38  * @return true if setting min timer resolution was successful
39  */
40 bool LIBPBD_API set_min_resolution ();
41
42 /**
43  * Set current Multimedia Timer resolution. If the timer resolution has already
44  * been set then reset_resolution() must be called before set_resolution will
45  * succeed.
46  * @return true if setting the timer value was successful, false if setting the
47  * timer resolution failed or the resolution has already been set.
48  */
49 bool LIBPBD_API set_resolution(uint32_t timer_resolution_ms);
50
51 /**
52  * Reset Multimedia Timer resolution. In my testing, if the timer resolution is
53  * set below the default, then resetting the resolution will not reset the
54  * timer resolution back to 15ms. At least it does not reset immediately
55  * even after calling Sleep.
56  * @return true if setting the timer value was successful
57  */
58 bool LIBPBD_API reset_resolution();
59
60 } // namespace MMTIMERS
61
62 namespace QPC {
63
64 /**
65  * Initialize the QPC timer, must be called before QPC::get_microseconds will
66  * return a valid value.
67  * @return true if QPC timer is usable, use check_timer_valid to try to check
68  * if it is monotonic.
69  */
70 bool LIBPBD_API initialize ();
71
72 /**
73  * @return true if QueryPerformanceCounter is usable as a timer source
74  * This should always return true for systems > XP as those versions of windows
75  * have there own tests to check timer validity and will select an appropriate
76  * timer source. This check is not conclusive and there are probably conditions
77  * under which this check will return true but the timer is not monotonic.
78  */
79 bool LIBPBD_API check_timer_valid ();
80
81 /**
82  * @return the value of the performance counter converted to microseconds
83  *
84  * If initialize returns true then get_microseconds will always return a
85  * positive value. If QPC is not supported(OS < XP) then -1 is returned but the
86  * MS docs say that this won't occur for systems >= XP.
87  */
88 int64_t LIBPBD_API get_microseconds ();
89
90 } // namespace QPC
91
92 /**
93  * The highest resolution timer source provided by the system. On Vista and
94  * above this is the value returned by QueryPerformanceCounter(QPC). On XP,
95  * this will QPC if supported or otherwise g_get_monotonic_time will be used.
96  *
97  * @return A timer value in microseconds or -1 in the event that the reading
98  * the timer source fails.
99  */
100 int64_t LIBPBD_API get_microseconds ();
101
102 } // namespace PBD
103
104 #endif // PBD_WINDOWS_TIMER_UTILS_H