rmw_dds_common  master
Define a common interface between DDS implementations of ROS middleware.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
time_utils.hpp
1 // Copyright 2020 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RMW_DDS_COMMON__TIME_UTILS_HPP_
16 #define RMW_DDS_COMMON__TIME_UTILS_HPP_
17 
18 #include "rmw/types.h"
19 
20 #include "rmw_dds_common/visibility_control.h"
21 
22 namespace rmw_dds_common
23 {
24 
27 /*
28  * The DDS standard specifies the Time_t and Duration_t types with
29  * "long sec" and "unsigned long nanosec", and the IDL to C++11 mapping
30  * states that the C++ types for long and unsigned long are mapped
31  * to int32_t and uint32_t, respectively. So, the 64-bit seconds and
32  * nanoseconds values will be truncated to 32-bits when converted
33  * from rmw_time_t to either a DDS Duration_t or Time_t. This function
34  * limits the seconds value to the signed 32-bit maximum and attempts
35  * to move the excess seconds to the nanoseconds field. If the resulting
36  * nanoseconds value is too large for unsigned 32-bits it saturates
37  * and issues a warning.
38  *
39  * \param[in] time to convert
40  * \return converted time value
41  */
42 RMW_DDS_COMMON_PUBLIC
44 clamp_rmw_time_to_dds_time(const rmw_time_t & time);
45 
46 } // namespace rmw_dds_common
47 
48 #endif // RMW_DDS_COMMON__TIME_UTILS_HPP_
rmw_time_t
types.h