timeout_adjust_func.h
Go to the documentation of this file.
1 // Copyright (c) 2020 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #ifndef TIMEOUT_ADJUST_FUNC_H
17 #define TIMEOUT_ADJUST_FUNC_H
18 
19 #include <chrono>
20 
21 namespace psen_scan_utils
22 {
23 constexpr auto DEFAULT_TIMEOUT_INCREASE{ std::chrono::seconds(10) };
24 constexpr auto DEFAULT_MAX_TIMEOUT{ std::chrono::seconds(60) };
25 
30 static std::chrono::steady_clock::duration
31 adjustTimeout(const std::chrono::steady_clock::duration& timeout,
32  const std::chrono::steady_clock::duration timeout_increase = DEFAULT_TIMEOUT_INCREASE,
33  const std::chrono::steady_clock::duration max_timeout = DEFAULT_MAX_TIMEOUT)
34 {
35  const std::chrono::steady_clock::duration new_timeout{ timeout + timeout_increase };
36  const bool timeout_overflow{ new_timeout > max_timeout };
37  return timeout_overflow ? max_timeout : new_timeout;
38 }
39 
40 } // namespace psen_scan_utils
41 
42 #endif // TIMEOUT_ADJUST_FUNC_H
constexpr auto DEFAULT_TIMEOUT_INCREASE
static std::chrono::steady_clock::duration adjustTimeout(const std::chrono::steady_clock::duration &timeout, const std::chrono::steady_clock::duration timeout_increase=DEFAULT_TIMEOUT_INCREASE, const std::chrono::steady_clock::duration max_timeout=DEFAULT_MAX_TIMEOUT)
Increases the given timeout by the specified timeout increase. If the new timeout exceeds the max tim...
constexpr auto DEFAULT_MAX_TIMEOUT


psen_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:16:20