pax_global_header00006660000000000000000000000064135454754640014533gustar00rootroot0000000000000052 comment=e8848380bc3fbf1b5a8dd11a551b38a3d55cec46 roscpp_core-0.6.13/000077500000000000000000000000001354547546400141405ustar00rootroot00000000000000roscpp_core-0.6.13/.gitignore000066400000000000000000000000071354547546400161250ustar00rootroot00000000000000._* *~ roscpp_core-0.6.13/cpp_common/000077500000000000000000000000001354547546400162725ustar00rootroot00000000000000roscpp_core-0.6.13/cpp_common/CHANGELOG.rst000066400000000000000000000051451354547546400203200ustar00rootroot00000000000000^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Changelog for package cpp_common ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0.6.13 (2019-10-03) ------------------- 0.6.12 (2019-03-04) ------------------- * update the use of macros in platform.h (`#99 `_) * avoid unnecessary memory allocation (std::string) (`#95 `_) * fix bug in HAVE_CXXABI_H compiler check (`#89 `_) 0.6.11 (2018-06-06) ------------------- 0.6.10 (2018-05-01) ------------------- 0.6.9 (2018-02-02) ------------------ 0.6.8 (2018-01-26) ------------------ * define console_bridge macro with API call rather than relying on short macro being defined (`#71 `_) 0.6.7 (2017-11-03) ------------------ * fix support for console_bridge < 0.3.0 (`#70 `_, regression of 0.6.6) 0.6.6 (2017-10-25) ------------------ * replace usage of deprecated logError macros (`#69 `_) 0.6.5 (2017-07-27) ------------------ 0.6.4 (2017-06-06) ------------------ 0.6.3 (2017-05-15) ------------------ 0.6.2 (2017-02-14) ------------------ 0.6.1 (2016-09-02) ------------------ 0.6.0 (2016-03-17) ------------------ 0.5.7 (2016-03-09) ------------------ * export symbols for Header (`#46 `_) 0.5.6 (2015-05-20) ------------------ 0.5.5 (2014-12-22) ------------------ 0.5.4 (2014-07-23) ------------------ 0.5.3 (2014-06-28) ------------------ * add missing boost dependency (`#24 `_) 0.5.2 (2014-06-27) ------------------ * find_package console_bridge with REQUIRED (`#23 `_) 0.5.1 (2014-06-24) ------------------ * convert to use console bridge from upstream debian package (`ros/rosdistro#4633 `_) 0.5.0 (2014-02-19) ------------------ 0.4.2 (2014-02-11) ------------------ 0.4.1 (2014-02-11) ------------------ 0.4.0 (2014-01-29) ------------------ 0.3.17 (2014-01-07) ------------------- * move several client library independent parts from ros_comm into roscpp_core (`#12 `_) 0.3.16 (2013-07-14) ------------------- 0.3.15 (2013-06-06) ------------------- * fix install destination for dll's under Windows 0.3.14 (2013-03-21) ------------------- 0.3.13 (2013-03-08) ------------------- 0.3.12 (2013-01-13) ------------------- 0.3.11 (2012-12-21) ------------------- * first public release for Groovy roscpp_core-0.6.13/cpp_common/CMakeLists.txt000066400000000000000000000027201354547546400210330ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8.3) project(cpp_common) find_package(Boost REQUIRED COMPONENTS system thread) find_package(console_bridge REQUIRED) find_package(catkin REQUIRED) catkin_package( DEPENDS Boost console_bridge INCLUDE_DIRS include LIBRARIES ${PROJECT_NAME}) include(CheckIncludeFile) include(CheckFunctionExists) include(CheckCXXSourceCompiles) include_directories(include ${Boost_INCLUDE_DIRS} ${console_bridge_INCLUDE_DIRS}) # execinfo.h is needed for backtrace on glibc systems CHECK_INCLUDE_FILE(execinfo.h HAVE_EXECINFO_H) if(HAVE_EXECINFO_H) add_definitions(-DHAVE_EXECINFO_H=1) endif(HAVE_EXECINFO_H) # do we have demangle capability? # CHECK_INCLUDE_FILE doesn't work here for some reason CHECK_CXX_SOURCE_COMPILES("#include\nint main(int argc,char**argv){}" HAVE_CXXABI_H) if(HAVE_CXXABI_H) add_definitions(-DHAVE_CXXABI_H=1) endif() CHECK_FUNCTION_EXISTS(backtrace HAVE_GLIBC_BACKTRACE) if(HAVE_GLIBC_BACKTRACE) add_definitions(-DHAVE_GLIBC_BACKTRACE) endif(HAVE_GLIBC_BACKTRACE) add_library(${PROJECT_NAME} src/debug.cpp src/header.cpp) target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES} ${console_bridge_LIBRARIES}) install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) install(DIRECTORY include/ DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.h") roscpp_core-0.6.13/cpp_common/include/000077500000000000000000000000001354547546400177155ustar00rootroot00000000000000roscpp_core-0.6.13/cpp_common/include/ros/000077500000000000000000000000001354547546400205205ustar00rootroot00000000000000roscpp_core-0.6.13/cpp_common/include/ros/cpp_common_decl.h000066400000000000000000000040211354547546400240070ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROS_CPP_COMMON_DECL_H_INCLUDED #define ROS_CPP_COMMON_DECL_H_INCLUDED #include #ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries #ifdef cpp_common_EXPORTS // we are building a shared lib/dll #define CPP_COMMON_DECL ROS_HELPER_EXPORT #else // we are using shared lib/dll #define CPP_COMMON_DECL ROS_HELPER_IMPORT #endif #else // ros is being built around static libraries #define CPP_COMMON_DECL #endif #endif roscpp_core-0.6.13/cpp_common/include/ros/datatypes.h000066400000000000000000000041301354547546400226650ustar00rootroot00000000000000/* * Copyright (C) 2008, Morgan Quigley and Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef CPP_CORE_TYPES_H #define CPP_CORE_TYPES_H #include #include #include #include #include #include namespace ros { typedef std::vector > VP_string; typedef std::vector V_string; typedef std::set S_string; typedef std::map M_string; typedef std::pair StringPair; typedef boost::shared_ptr M_stringPtr; } #endif // CPP_CORE_TYPES_H roscpp_core-0.6.13/cpp_common/include/ros/debug.h000066400000000000000000000043771354547546400217720ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSLIB_DEBUG_H #define ROSLIB_DEBUG_H #include #include #include "cpp_common_decl.h" namespace ros { namespace debug { typedef std::vector V_void; typedef std::vector V_string; CPP_COMMON_DECL std::string getBacktrace(); CPP_COMMON_DECL std::string backtraceToString(const V_void& addresses); CPP_COMMON_DECL void getBacktrace(V_void& addresses); CPP_COMMON_DECL void translateAddresses(const V_void& addresses, V_string& lines); CPP_COMMON_DECL void demangleBacktrace(const V_string& names, V_string& demangled); CPP_COMMON_DECL std::string demangleBacktrace(const V_string& names); CPP_COMMON_DECL std::string demangleName(const std::string& name); } } #endif roscpp_core-0.6.13/cpp_common/include/ros/exception.h000066400000000000000000000035561354547546400227000ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSLIB_EXCEPTION_H #define ROSLIB_EXCEPTION_H #include namespace ros { /** * \brief Base class for all exceptions thrown by ROS */ class Exception : public std::runtime_error { public: Exception(const std::string& what) : std::runtime_error(what) {} }; } // namespace ros #endif roscpp_core-0.6.13/cpp_common/include/ros/header.h000066400000000000000000000056051354547546400221270ustar00rootroot00000000000000/* * Software License Agreement (BSD License) * * Copyright (c) 2008, Willow Garage, Inc. * Copyright (c) 2013, Open Source Robotics Foundation * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef CPP_CORE_HEADER_H #define CPP_CORE_HEADER_H #include #include #include "ros/datatypes.h" #include "cpp_common_decl.h" namespace ros { /** * \brief Provides functionality to parse a connection header and retrieve values from it */ class CPP_COMMON_DECL Header { public: Header(); ~Header(); /** * \brief Get a value from a parsed header * \param key Key value * \param value OUT -- value corresponding to the key if there is one * \return Returns true if the header had the specified key in it */ bool getValue(const std::string& key, std::string& value) const; /** * \brief Returns a shared pointer to the internal map used */ M_stringPtr getValues() { return read_map_; } /** * \brief Parse a header out of a buffer of data */ bool parse(const boost::shared_array& buffer, uint32_t size, std::string& error_msg); /** * \brief Parse a header out of a buffer of data */ bool parse(uint8_t* buffer, uint32_t size, std::string& error_msg); static void write(const M_string& key_vals, boost::shared_array& buffer, uint32_t& size); private: M_stringPtr read_map_; }; } #endif // ROSCPP_HEADER_H roscpp_core-0.6.13/cpp_common/include/ros/macros.h000066400000000000000000000051421354547546400221570ustar00rootroot00000000000000/* * Copyright (C) 2010, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSLIB_MACROS_H_INCLUDED #define ROSLIB_MACROS_H_INCLUDED #if defined(__GNUC__) #define ROS_DEPRECATED __attribute__((deprecated)) #define ROS_FORCE_INLINE __attribute__((always_inline)) #elif defined(_MSC_VER) #define ROS_DEPRECATED #define ROS_FORCE_INLINE __forceinline #else #define ROS_DEPRECATED #define ROS_FORCE_INLINE inline #endif /* Windows import/export and gnu http://gcc.gnu.org/wiki/Visibility macros. */ #if defined(_MSC_VER) #define ROS_HELPER_IMPORT __declspec(dllimport) #define ROS_HELPER_EXPORT __declspec(dllexport) #define ROS_HELPER_LOCAL #elif __GNUC__ >= 4 #define ROS_HELPER_IMPORT __attribute__ ((visibility("default"))) #define ROS_HELPER_EXPORT __attribute__ ((visibility("default"))) #define ROS_HELPER_LOCAL __attribute__ ((visibility("hidden"))) #else #define ROS_HELPER_IMPORT #define ROS_HELPER_EXPORT #define ROS_HELPER_LOCAL #endif // Ignore warnings about import/exports when deriving from std classes. #ifdef _MSC_VER #pragma warning(disable: 4251) #pragma warning(disable: 4275) #endif #endif roscpp_core-0.6.13/cpp_common/include/ros/platform.h000066400000000000000000000050711354547546400225200ustar00rootroot00000000000000/* * Copyright (C) 2010, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* * Some common cross platform utilities. */ #ifndef CPP_COMMON_PLATFORM_H_ #define CPP_COMMON_PLATFORM_H_ /****************************************************************************** * Cross Platform Functions ******************************************************************************/ #include // getenv, _dupenv_s #include namespace ros { /** * Convenient cross platform function for returning a std::string of an * environment variable. */ inline bool get_environment_variable(std::string &str, const char* environment_variable) { char* env_var_cstr = NULL; #ifdef _MSC_VER _dupenv_s(&env_var_cstr, NULL,environment_variable); #else env_var_cstr = getenv(environment_variable); #endif if ( env_var_cstr ) { str = std::string(env_var_cstr); #ifdef _MSC_VER free(env_var_cstr); #endif return true; } else { str = std::string(""); return false; } } } // namespace ros #endif /* CPP_COMMON_PLATFORM_H_ */ roscpp_core-0.6.13/cpp_common/include/ros/types.h000066400000000000000000000042361354547546400220420ustar00rootroot00000000000000/* * Copyright (C) 2008, Morgan Quigley and Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSCPP_TYPES_H #define ROSCPP_TYPES_H // this is just for interoperability with visual studio, where the standard // integer types are not defined. #if defined(_MSC_VER) && (_MSC_VER < 1600 ) // MS express/studio 2008 or earlier typedef __int64 int64_t; typedef unsigned __int64 uint64_t; typedef __int32 int32_t; typedef unsigned __int32 uint32_t; typedef __int16 int16_t; typedef unsigned __int16 uint16_t; typedef __int8 int8_t; typedef unsigned __int8 uint8_t; #else #include #endif #endif // ROSCPP_TYPES_H roscpp_core-0.6.13/cpp_common/package.xml000066400000000000000000000015171354547546400204130ustar00rootroot00000000000000 cpp_common 0.6.13 cpp_common contains C++ code for doing things that are not necessarily ROS related, but are useful for multiple packages. This includes things like the ROS_DEPRECATED and ROS_FORCE_INLINE macros, as well as code for getting backtraces. This package is a component of roscpp. Dirk Thomas BSD http://www.ros.org/wiki/cpp_common John Faust catkin boost libconsole-bridge-dev boost libconsole-bridge-dev roscpp_core-0.6.13/cpp_common/src/000077500000000000000000000000001354547546400170615ustar00rootroot00000000000000roscpp_core-0.6.13/cpp_common/src/debug.cpp000066400000000000000000000076141354547546400206630ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include "ros/debug.h" #if defined(HAVE_EXECINFO_H) #include #endif #if defined(HAVE_CXXABI_H) #include #endif #include #include #include namespace ros { namespace debug { void getBacktrace(V_void& addresses) { #if HAVE_GLIBC_BACKTRACE void *array[64]; size_t size = backtrace(array, 64); for (size_t i = 1; i < size; i++) { addresses.push_back(array[i]); } #endif } void translateAddresses(const V_void& addresses, V_string& lines) { #if HAVE_GLIBC_BACKTRACE if (addresses.empty()) { return; } size_t size = addresses.size(); char **strings = backtrace_symbols(&addresses.front(), size); for (size_t i = 0; i < size; ++i) { lines.push_back(strings[i]); } free(strings); #endif } std::string demangleName(const std::string& name) { #if HAVE_CXXABI_H int status; char* demangled = abi::__cxa_demangle(name.c_str(), 0, 0, &status); std::string out; if (demangled) { out = demangled; free(demangled); } else { out = name; } return out; #else return name; #endif } std::string demangleBacktraceLine(const std::string& line) { // backtrace_symbols outputs in the form: // executable(function+offset) [address] // We want everything between ( and + to send to demangleName() size_t paren_pos = line.find('('); size_t plus_pos = line.find('+'); if (paren_pos == std::string::npos || plus_pos == std::string::npos) { return line; } std::string name(line, paren_pos + 1, plus_pos - paren_pos - 1); return line.substr(0, paren_pos + 1) + demangleName(name) + line.substr(plus_pos); } void demangleBacktrace(const V_string& lines, V_string& demangled) { V_string::const_iterator it = lines.begin(); V_string::const_iterator end = lines.end(); for (; it != end; ++it) { demangled.push_back(demangleBacktraceLine(*it)); } } std::string backtraceToString(const V_void& addresses) { V_string lines, demangled; translateAddresses(addresses, lines); demangleBacktrace(lines, demangled); std::stringstream ss; V_string::const_iterator it = demangled.begin(); V_string::const_iterator end = demangled.end(); for (; it != end; ++it) { ss << *it << std::endl; } return ss.str(); } std::string getBacktrace() { V_void addresses; getBacktrace(addresses); return backtraceToString(addresses); } } } roscpp_core-0.6.13/cpp_common/src/header.cpp000066400000000000000000000124731354547546400210240ustar00rootroot00000000000000/* * Software License Agreement (BSD License) * * Copyright (c) 2008, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include "ros/header.h" #include "console_bridge/console.h" #include #include #include #include #define SROS_SERIALIZE_PRIMITIVE(ptr, data) { memcpy(ptr, &data, sizeof(data)); ptr += sizeof(data); } #define SROS_SERIALIZE_BUFFER(ptr, data, data_size) { if (data_size > 0) { memcpy(ptr, data, data_size); ptr += data_size; } } #define SROS_DESERIALIZE_PRIMITIVE(ptr, data) { memcpy(&data, ptr, sizeof(data)); ptr += sizeof(data); } #define SROS_DESERIALIZE_BUFFER(ptr, data, data_size) { if (data_size > 0) { memcpy(data, ptr, data_size); ptr += data_size; } } // Remove this when no longer supporting platforms with libconsole-bridge-dev < 0.3.0, // in particular Debian Jessie: https://packages.debian.org/jessie/libconsole-bridge-dev #ifndef CONSOLE_BRIDGE_logError # define CONSOLE_BRIDGE_logError(fmt, ...) \ console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_ERROR, fmt, ##__VA_ARGS__) #endif using namespace std; namespace ros { Header::Header() : read_map_(new M_string()) { } Header::~Header() { } bool Header::parse(const boost::shared_array& buffer, uint32_t size, std::string& error_msg) { return parse(buffer.get(), size, error_msg); } bool Header::parse(uint8_t* buffer, uint32_t size, std::string& error_msg) { std::string key_; uint8_t* buf = buffer; while (buf < buffer + size) { uint32_t len; SROS_DESERIALIZE_PRIMITIVE(buf, len); if (len > 1000000) { error_msg = "Received an invalid TCPROS header. Each element must be prepended by a 4-byte length."; CONSOLE_BRIDGE_logError("%s", error_msg.c_str()); return false; } boost::string_ref line((char*)buf, len); buf += len; //printf(":%s:\n", line.c_str()); size_t eqpos = line.find_first_of("="); if (eqpos == string::npos) { error_msg = "Received an invalid TCPROS header. Each line must have an equals sign."; CONSOLE_BRIDGE_logError("%s", error_msg.c_str()); return false; } boost::string_ref key_ref = line.substr(0, eqpos); boost::string_ref value_ref = line.substr(eqpos+1); key_.assign(key_ref.data(), key_ref.length()); (*read_map_)[key_].assign(value_ref.data(), value_ref.length()); } return true; } bool Header::getValue(const std::string& key, std::string& value) const { M_string::const_iterator it = read_map_->find(key); if (it == read_map_->end()) { return false; } value = it->second; return true; } void Header::write(const M_string& key_vals, boost::shared_array& buffer, uint32_t& size) { // Calculate the necessary size size = 0; { M_string::const_iterator it = key_vals.begin(); M_string::const_iterator end = key_vals.end(); for (; it != end; ++it) { const std::string& key = it->first; const std::string& value = it->second; size += key.length(); size += value.length(); size += 1; // = sign size += 4; // 4-byte length } } if (size == 0) { return; } buffer.reset(new uint8_t[size]); char* ptr = (char*)buffer.get(); // Write the data { M_string::const_iterator it = key_vals.begin(); M_string::const_iterator end = key_vals.end(); for (; it != end; ++it) { const std::string& key = it->first; const std::string& value = it->second; uint32_t len = key.length() + value.length() + 1; SROS_SERIALIZE_PRIMITIVE(ptr, len); SROS_SERIALIZE_BUFFER(ptr, key.data(), key.length()); static const char equals = '='; SROS_SERIALIZE_PRIMITIVE(ptr, equals); SROS_SERIALIZE_BUFFER(ptr, value.data(), value.length()); } } assert(ptr == (char*)buffer.get() + size); } } roscpp_core-0.6.13/doc/000077500000000000000000000000001354547546400147055ustar00rootroot00000000000000roscpp_core-0.6.13/doc/roscpp.rst000066400000000000000000000151721354547546400167530ustar00rootroot00000000000000.. roscpp core prototype documentation master file, created by sphinx-quickstart on Fri Nov 11 11:12:23 2011. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. A roscpp_core prototype ======================= The goal of this prototype is to discover ways to make it easy to use ROS message types in ways that are completely familar to the average Linux developer. The current prototype allows one to compile against and serialize the most common C++ ROS messages via only a 200k debian package. The build dependencies are cmake, boost, and a single path. Special thanks to Morten Kjaergaard who has been indispensible in getting this together. How to try it out ----------------- Find an amd64 ubuntu machine with either ``lucid``, ``natty`` or ``oneiric`` installed. You need root permissions. Download the appopriate ``.deb`` file from `here `_, e.g. on ``lucid``:: wget http://people.willowgarage.com/straszheim/files/ros-fuerte-roscpp-core-prototype_lucid_amd64.deb Install it:: dpkg -i ros-fuerte-roscpp-core-prototype_lucid_amd64.deb At this point you will see that ``/opt/ros/fuerte`` has had a bunch of stuff dropped in to it. To try it, create a directory src and pull down two example files:: % cd /tmp % mkdir src % cd src % wget -nv http://people.willowgarage.com/straszheim/files/CMakeLists.txt 2011-11-11 11:52:36 URL:http://people.willowgarage.com/straszheim/files/CMakeLists.txt [268/268] -> "CMakeLists.txt" [1] % wget -nv http://people.willowgarage.com/straszheim/files/main.cpp 2011-11-11 11:52:42 URL:http://people.willowgarage.com/straszheim/files/main.cpp [581/581] -> "main.cpp" [1] the main.cpp does a very simple (de)serialization of a ``sensor_msgs/PointCloud2``:: #include namespace rs = ros::serialization; int main() { sensor_msgs::PointCloud2 pc_1; pc_1.width = 10; pc_1.height = 20; // todo set other stuff std::cout << "PointCloud2 message: " << std::endl << pc_1 << std::endl; uint8_t buf[1024]; rs::OStream out(buf, sizeof(buf) ); rs::serialize(out, pc_1); std::cout << "Message Was Serialized" << std::endl; sensor_msgs::PointCloud2 pc_2; rs::IStream in(buf, sizeof(buf) ); rs::deserialize(in, pc_2); std::cout << "Its a message again: " << std::endl << pc_2 << std::endl; } and the ``CMakeLists.txt`` demonstrates the CMake incantations required to find and use the code:: cmake_minimum_required(VERSION 2.8.3) find_package(ROS 12.04 COMPONENTS cpp_common rostime roscpp_traits roscpp_serialization sensor_msgs) include_directories(${ROS_INCLUDE_DIRS}) add_executable(something main.cpp) target_link_libraries(something ${ROS_LIBRARIES}) The important line is the ``find_package``. This usage is very standard CMake practice. Unfortunately it is not possible to pass ``fuerte`` as the version, as cmake insists that the version be numeric. Indeed, four dependencies (cpp_common, rostime, roscpp_traits, roscpp_serialization) does seem like a lot, but each is very tiny; roscpp_traits has no library, roscpp_serialization contains only one function. We'll be cleaning this up. The important bit is that the user's workflow is decoupled from upstream. Now build in the usual way, with the caveat that ``CMAKE_PREFIX_PATH`` must be specified for the ``find_package`` to work. We believe that we can remove this requirement in the future:: % cmake . -DCMAKE_PREFIX_PATH=/opt/ros/fuerte -- The C compiler identification is GNU -- The CXX compiler identification is GNU -- Check for working C compiler: /usr/bin/gcc -- Check for working C compiler: /usr/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Configuring done -- Generating done -- Build files have been written to: /tmp/src Make and run as usual:: % make Scanning dependencies of target something [100%] Building CXX object CMakeFiles/something.dir/main.cpp.o Linking CXX executable something [100%] Built target something % ./something PointCloud2 message: header: [ etc ] Contents of /opt/ros/fuerte --------------------------- .. rubric:: bin/gen*.py these are message generator binaries. CMake macros provided in the package make it easy to generate your own message types. .. rubric:: lib/ this is currently the smallest set of libraries that you need to serialize ROS messages. There are three. We will be making this smaller, and may be able to go header-only. Anyhow the dependencies are fairly light:: % ldd /opt/ros/fuerte/lib/*.so /opt/ros/fuerte/lib/libcpp_common.so: linux-vdso.so.1 => (0x00007fff0adc3000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fbdd1bad000) libm.so.6 => /lib/libm.so.6 (0x00007fbdd192a000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fbdd1712000) libc.so.6 => /lib/libc.so.6 (0x00007fbdd138f000) /lib64/ld-linux-x86-64.so.2 (0x00007fbdd20f5000) /opt/ros/fuerte/lib/libroscpp_serialization.so: linux-vdso.so.1 => (0x00007fff62ff6000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f7c21ae9000) libm.so.6 => /lib/libm.so.6 (0x00007f7c21866000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f7c2164e000) libc.so.6 => /lib/libc.so.6 (0x00007f7c212cb000) /lib64/ld-linux-x86-64.so.2 (0x00007f7c2202a000) /opt/ros/fuerte/lib/librostime.so: linux-vdso.so.1 => (0x00007fffddb60000) libboost_date_time.so.1.40.0 => /usr/lib/libboost_date_time.so.1.40.0 (0x00007f0af8ffa000) libboost_thread.so.1.40.0 => /usr/lib/libboost_thread.so.1.40.0 (0x00007f0af8de4000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f0af8acf000) libm.so.6 => /lib/libm.so.6 (0x00007f0af884c000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f0af8635000) libc.so.6 => /lib/libc.so.6 (0x00007f0af82b1000) librt.so.1 => /lib/librt.so.1 (0x00007f0af80a9000) libpthread.so.0 => /lib/libpthread.so.0 (0x00007f0af7e8c000) /lib64/ld-linux-x86-64.so.2 (0x00007f0af9481000) i.e. the only additional dependencies are ``boost::thread`` and ``boost::date_time``. This is due to the fact that ros time classes are considered "primtives" by ros messages. .. rubric:: include/ the ``ROS`` headers associated with the libraries above, and generated ROS message headers. .. rubric:: share/msg The original message definition (``.msg``) files. .. rubric:: share/cmake CMake infrastructure for straightforward finding/use of these headers. roscpp_core-0.6.13/roscpp_core/000077500000000000000000000000001354547546400164565ustar00rootroot00000000000000roscpp_core-0.6.13/roscpp_core/CMakeLists.txt000066400000000000000000000001561354547546400212200ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8.3) project(roscpp_core) find_package(catkin REQUIRED) catkin_metapackage() roscpp_core-0.6.13/roscpp_core/package.xml000066400000000000000000000011361354547546400205740ustar00rootroot00000000000000 roscpp_core 0.6.13 Underlying data libraries for roscpp messages. Dirk Thomas BSD http://www.ros.org/wiki/roscpp_core Josh Faust catkin cpp_common roscpp_serialization roscpp_traits rostime roscpp_core-0.6.13/roscpp_serialization/000077500000000000000000000000001354547546400204035ustar00rootroot00000000000000roscpp_core-0.6.13/roscpp_serialization/CHANGELOG.rst000066400000000000000000000052541354547546400224320ustar00rootroot00000000000000^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Changelog for package roscpp_serialization ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0.6.13 (2019-10-03) ------------------- * added cast to uint32_t in roscpp_serialization to fix -Wconversion warning (`#113 `_) * roscpp_serialization: replace c-style-casts with static/reinterpret casts (`#107 `_) 0.6.12 (2019-03-04) ------------------- * fix GCC8 class-memaccess in VectorSerializer (`#102 `_) 0.6.11 (2018-06-06) ------------------- * replace reinterpret_cast with memcpy to avoid undefined behaviour/alignment issues (`#83 `_) 0.6.10 (2018-05-01) ------------------- 0.6.9 (2018-02-02) ------------------ 0.6.8 (2018-01-26) ------------------ 0.6.7 (2017-11-03) ------------------ 0.6.6 (2017-10-25) ------------------ 0.6.5 (2017-07-27) ------------------ 0.6.4 (2017-06-06) ------------------ 0.6.3 (2017-05-15) ------------------ 0.6.2 (2017-02-14) ------------------ * fix warning when compiling with -Wpedantic (`#53 `_) 0.6.1 (2016-09-02) ------------------ * fix warning about unused parameter (`#51 `_) 0.6.0 (2016-03-17) ------------------ 0.5.7 (2016-03-09) ------------------ * fix serializer bool on ARM (`#44 `_) 0.5.6 (2015-05-20) ------------------ 0.5.5 (2014-12-22) ------------------ 0.5.4 (2014-07-23) ------------------ 0.5.3 (2014-06-28) ------------------ 0.5.2 (2014-06-27) ------------------ 0.5.1 (2014-06-24) ------------------ 0.5.0 (2014-02-19) ------------------ 0.4.2 (2014-02-11) ------------------ 0.4.1 (2014-02-11) ------------------ 0.4.0 (2014-01-29) ------------------ * remove assignSubscriptionConnectionHeader (`#19 `_) 0.3.17 (2014-01-07) ------------------- * move several client library independent parts from ros_comm into roscpp_core (`#12 `_) 0.3.16 (2013-07-14) ------------------- * fix alignment in serialization on ARM (`#14 `_) 0.3.15 (2013-06-06) ------------------- * fix compiler warning about unused variable (`#11 `_) * fix install destination for dll's under Windows 0.3.14 (2013-03-21) ------------------- 0.3.13 (2013-03-08) ------------------- * fix serialization on ARM 0.3.12 (2013-01-13) ------------------- 0.3.11 (2012-12-21) ------------------- * first public release for Groovy roscpp_core-0.6.13/roscpp_serialization/CMakeLists.txt000066400000000000000000000013361354547546400231460ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8.3) project(roscpp_serialization) find_package(catkin REQUIRED COMPONENTS cpp_common roscpp_traits rostime) catkin_package( INCLUDE_DIRS include LIBRARIES roscpp_serialization CATKIN_DEPENDS cpp_common roscpp_traits rostime ) include_directories(include ${catkin_INCLUDE_DIRS}) link_directories(${catkin_LIBRARY_DIRS}) add_library(roscpp_serialization src/serialization.cpp) install(TARGETS roscpp_serialization ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) install(DIRECTORY include/ DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.h") roscpp_core-0.6.13/roscpp_serialization/include/000077500000000000000000000000001354547546400220265ustar00rootroot00000000000000roscpp_core-0.6.13/roscpp_serialization/include/ros/000077500000000000000000000000001354547546400226315ustar00rootroot00000000000000roscpp_core-0.6.13/roscpp_serialization/include/ros/roscpp_serialization_macros.h000066400000000000000000000045701354547546400306170ustar00rootroot00000000000000/********************************************************************* * * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * *********************************************************************/ /* * Cross platform macros. * */ #ifndef ROSCPP_SERIALIZATION_MACROS_HPP_ #define ROSCPP_SERIALIZATION_MACROS_HPP_ #include #ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries #ifdef roscpp_serialization_EXPORTS // we are building a shared lib/dll #define ROSCPP_SERIALIZATION_DECL ROS_HELPER_EXPORT #else // we are using shared lib/dll #define ROSCPP_SERIALIZATION_DECL ROS_HELPER_IMPORT #endif #else // ros is being built around static libraries #define ROSCPP_SERIALIZATION_DECL #endif #endif /* ROSCPP_SERIALIZATION_MACROS_HPP_ */ roscpp_core-0.6.13/roscpp_serialization/include/ros/serialization.h000066400000000000000000000532131354547546400256630ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSCPP_SERIALIZATION_H #define ROSCPP_SERIALIZATION_H #include "roscpp_serialization_macros.h" #include #include #include "serialized_message.h" #include "ros/message_traits.h" #include "ros/builtin_message_traits.h" #include "ros/exception.h" #include "ros/datatypes.h" #include #include #include #include #include #include #include #include #include #define ROS_NEW_SERIALIZATION_API 1 /** * \brief Declare your serializer to use an allInOne member instead of requiring 3 different serialization * functions. * * The allinone method has the form: \verbatim template inline static void allInOne(Stream& stream, T t) { stream.next(t.a); stream.next(t.b); ... } \endverbatim * * The only guarantee given is that Stream::next(T) is defined. */ #define ROS_DECLARE_ALLINONE_SERIALIZER \ template \ inline static void write(Stream& stream, const T& t) \ { \ allInOne(stream, t); \ } \ \ template \ inline static void read(Stream& stream, T& t) \ { \ allInOne(stream, t); \ } \ \ template \ inline static uint32_t serializedLength(const T& t) \ { \ LStream stream; \ allInOne(stream, t); \ return stream.getLength(); \ } namespace ros { namespace serialization { namespace mt = message_traits; namespace mpl = boost::mpl; class ROSCPP_SERIALIZATION_DECL StreamOverrunException : public ros::Exception { public: StreamOverrunException(const std::string& what) : Exception(what) {} }; ROSCPP_SERIALIZATION_DECL void throwStreamOverrun(); /** * \brief Templated serialization class. Default implementation provides backwards compatibility with * old message types. * * Specializing the Serializer class is the only thing you need to do to get the ROS serialization system * to work with a type. */ template struct Serializer { /** * \brief Write an object to the stream. Normally the stream passed in here will be a ros::serialization::OStream */ template inline static void write(Stream& stream, typename boost::call_traits::param_type t) { t.serialize(stream.getData(), 0); } /** * \brief Read an object from the stream. Normally the stream passed in here will be a ros::serialization::IStream */ template inline static void read(Stream& stream, typename boost::call_traits::reference t) { t.deserialize(stream.getData()); } /** * \brief Determine the serialized length of an object. */ inline static uint32_t serializedLength(typename boost::call_traits::param_type t) { return t.serializationLength(); } }; /** * \brief Serialize an object. Stream here should normally be a ros::serialization::OStream */ template inline void serialize(Stream& stream, const T& t) { Serializer::write(stream, t); } /** * \brief Deserialize an object. Stream here should normally be a ros::serialization::IStream */ template inline void deserialize(Stream& stream, T& t) { Serializer::read(stream, t); } /** * \brief Determine the serialized length of an object */ template inline uint32_t serializationLength(const T& t) { return Serializer::serializedLength(t); } #define ROS_CREATE_SIMPLE_SERIALIZER(Type) \ template<> struct Serializer \ { \ template inline static void write(Stream& stream, const Type v) \ { \ memcpy(stream.advance(sizeof(v)), &v, sizeof(v) ); \ } \ \ template inline static void read(Stream& stream, Type& v) \ { \ memcpy(&v, stream.advance(sizeof(v)), sizeof(v) ); \ } \ \ inline static uint32_t serializedLength(const Type&) \ { \ return sizeof(Type); \ } \ }; ROS_CREATE_SIMPLE_SERIALIZER(uint8_t) ROS_CREATE_SIMPLE_SERIALIZER(int8_t) ROS_CREATE_SIMPLE_SERIALIZER(uint16_t) ROS_CREATE_SIMPLE_SERIALIZER(int16_t) ROS_CREATE_SIMPLE_SERIALIZER(uint32_t) ROS_CREATE_SIMPLE_SERIALIZER(int32_t) ROS_CREATE_SIMPLE_SERIALIZER(uint64_t) ROS_CREATE_SIMPLE_SERIALIZER(int64_t) ROS_CREATE_SIMPLE_SERIALIZER(float) ROS_CREATE_SIMPLE_SERIALIZER(double) /** * \brief Serializer specialized for bool (serialized as uint8) */ template<> struct Serializer { template inline static void write(Stream& stream, const bool v) { uint8_t b = static_cast(v); memcpy(stream.advance(1), &b, 1 ); } template inline static void read(Stream& stream, bool& v) { uint8_t b; memcpy(&b, stream.advance(1), 1 ); v = static_cast(b); } inline static uint32_t serializedLength(bool) { return 1; } }; /** * \brief Serializer specialized for std::string */ template struct Serializer, ContainerAllocator> > { typedef std::basic_string, ContainerAllocator> StringType; template inline static void write(Stream& stream, const StringType& str) { size_t len = str.size(); stream.next(static_cast(len)); if (len > 0) { memcpy(stream.advance(static_cast(len)), str.data(), len); } } template inline static void read(Stream& stream, StringType& str) { uint32_t len; stream.next(len); if (len > 0) { str = StringType(reinterpret_cast(stream.advance(len)), len); } else { str.clear(); } } inline static uint32_t serializedLength(const StringType& str) { return 4 + static_cast(str.size()); } }; /** * \brief Serializer specialized for ros::Time */ template<> struct Serializer { template inline static void write(Stream& stream, const ros::Time& v) { stream.next(v.sec); stream.next(v.nsec); } template inline static void read(Stream& stream, ros::Time& v) { stream.next(v.sec); stream.next(v.nsec); } inline static uint32_t serializedLength(const ros::Time&) { return 8; } }; /** * \brief Serializer specialized for ros::Duration */ template<> struct Serializer { template inline static void write(Stream& stream, const ros::Duration& v) { stream.next(v.sec); stream.next(v.nsec); } template inline static void read(Stream& stream, ros::Duration& v) { stream.next(v.sec); stream.next(v.nsec); } inline static uint32_t serializedLength(const ros::Duration&) { return 8; } }; /** * \brief Vector serializer. Default implementation does nothing */ template struct VectorSerializer {}; /** * \brief Vector serializer, specialized for non-fixed-size, non-simple types */ template struct VectorSerializer >::type > { typedef std::vector::other> VecType; typedef typename VecType::iterator IteratorType; typedef typename VecType::const_iterator ConstIteratorType; template inline static void write(Stream& stream, const VecType& v) { stream.next(static_cast(v.size())); ConstIteratorType it = v.begin(); ConstIteratorType end = v.end(); for (; it != end; ++it) { stream.next(*it); } } template inline static void read(Stream& stream, VecType& v) { uint32_t len; stream.next(len); v.resize(len); IteratorType it = v.begin(); IteratorType end = v.end(); for (; it != end; ++it) { stream.next(*it); } } inline static uint32_t serializedLength(const VecType& v) { uint32_t size = 4; ConstIteratorType it = v.begin(); ConstIteratorType end = v.end(); for (; it != end; ++it) { size += serializationLength(*it); } return size; } }; /** * \brief Vector serializer, specialized for fixed-size simple types */ template struct VectorSerializer >::type > { typedef std::vector::other> VecType; typedef typename VecType::iterator IteratorType; typedef typename VecType::const_iterator ConstIteratorType; template inline static void write(Stream& stream, const VecType& v) { uint32_t len = static_cast(v.size()); stream.next(len); if (!v.empty()) { const uint32_t data_len = len * static_cast(sizeof(T)); memcpy(stream.advance(data_len), &v.front(), data_len); } } template inline static void read(Stream& stream, VecType& v) { uint32_t len; stream.next(len); v.resize(len); if (len > 0) { const uint32_t data_len = static_cast(sizeof(T)) * len; memcpy(static_cast(&v.front()), stream.advance(data_len), data_len); } } inline static uint32_t serializedLength(const VecType& v) { return 4 + v.size() * static_cast(sizeof(T)); } }; /** * \brief Vector serializer, specialized for fixed-size non-simple types */ template struct VectorSerializer, mpl::not_ > > >::type > { typedef std::vector::other> VecType; typedef typename VecType::iterator IteratorType; typedef typename VecType::const_iterator ConstIteratorType; template inline static void write(Stream& stream, const VecType& v) { stream.next(static_cast(v.size())); ConstIteratorType it = v.begin(); ConstIteratorType end = v.end(); for (; it != end; ++it) { stream.next(*it); } } template inline static void read(Stream& stream, VecType& v) { uint32_t len; stream.next(len); v.resize(len); IteratorType it = v.begin(); IteratorType end = v.end(); for (; it != end; ++it) { stream.next(*it); } } inline static uint32_t serializedLength(const VecType& v) { uint32_t size = 4; if (!v.empty()) { uint32_t len_each = serializationLength(v.front()); size += len_each * static_cast(v.size()); } return size; } }; /** * \brief serialize version for std::vector */ template inline void serialize(Stream& stream, const std::vector& t) { VectorSerializer::write(stream, t); } /** * \brief deserialize version for std::vector */ template inline void deserialize(Stream& stream, std::vector& t) { VectorSerializer::read(stream, t); } /** * \brief serializationLength version for std::vector */ template inline uint32_t serializationLength(const std::vector& t) { return VectorSerializer::serializedLength(t); } /** * \brief Array serializer, default implementation does nothing */ template struct ArraySerializer {}; /** * \brief Array serializer, specialized for non-fixed-size, non-simple types */ template struct ArraySerializer >::type> { typedef boost::array ArrayType; typedef typename ArrayType::iterator IteratorType; typedef typename ArrayType::const_iterator ConstIteratorType; template inline static void write(Stream& stream, const ArrayType& v) { ConstIteratorType it = v.begin(); ConstIteratorType end = v.end(); for (; it != end; ++it) { stream.next(*it); } } template inline static void read(Stream& stream, ArrayType& v) { IteratorType it = v.begin(); IteratorType end = v.end(); for (; it != end; ++it) { stream.next(*it); } } inline static uint32_t serializedLength(const ArrayType& v) { uint32_t size = 0; ConstIteratorType it = v.begin(); ConstIteratorType end = v.end(); for (; it != end; ++it) { size += serializationLength(*it); } return size; } }; /** * \brief Array serializer, specialized for fixed-size, simple types */ template struct ArraySerializer >::type> { typedef boost::array ArrayType; typedef typename ArrayType::iterator IteratorType; typedef typename ArrayType::const_iterator ConstIteratorType; template inline static void write(Stream& stream, const ArrayType& v) { const uint32_t data_len = N * sizeof(T); memcpy(stream.advance(data_len), &v.front(), data_len); } template inline static void read(Stream& stream, ArrayType& v) { const uint32_t data_len = N * sizeof(T); memcpy(&v.front(), stream.advance(data_len), data_len); } inline static uint32_t serializedLength(const ArrayType&) { return N * sizeof(T); } }; /** * \brief Array serializer, specialized for fixed-size, non-simple types */ template struct ArraySerializer, mpl::not_ > > >::type> { typedef boost::array ArrayType; typedef typename ArrayType::iterator IteratorType; typedef typename ArrayType::const_iterator ConstIteratorType; template inline static void write(Stream& stream, const ArrayType& v) { ConstIteratorType it = v.begin(); ConstIteratorType end = v.end(); for (; it != end; ++it) { stream.next(*it); } } template inline static void read(Stream& stream, ArrayType& v) { IteratorType it = v.begin(); IteratorType end = v.end(); for (; it != end; ++it) { stream.next(*it); } } inline static uint32_t serializedLength(const ArrayType& v) { return serializationLength(v.front()) * N; } }; /** * \brief serialize version for boost::array */ template inline void serialize(Stream& stream, const boost::array& t) { ArraySerializer::write(stream, t); } /** * \brief deserialize version for boost::array */ template inline void deserialize(Stream& stream, boost::array& t) { ArraySerializer::read(stream, t); } /** * \brief serializationLength version for boost::array */ template inline uint32_t serializationLength(const boost::array& t) { return ArraySerializer::serializedLength(t); } /** * \brief Enum */ namespace stream_types { enum StreamType { Input, Output, Length }; } typedef stream_types::StreamType StreamType; /** * \brief Stream base-class, provides common functionality for IStream and OStream */ struct ROSCPP_SERIALIZATION_DECL Stream { /* * \brief Returns a pointer to the current position of the stream */ inline uint8_t* getData() { return data_; } /** * \brief Advances the stream, checking bounds, and returns a pointer to the position before it * was advanced. * \throws StreamOverrunException if len would take this stream past the end of its buffer */ ROS_FORCE_INLINE uint8_t* advance(uint32_t len) { uint8_t* old_data = data_; data_ += len; if (data_ > end_) { // Throwing directly here causes a significant speed hit due to the extra code generated // for the throw statement throwStreamOverrun(); } return old_data; } /** * \brief Returns the amount of space left in the stream */ inline uint32_t getLength() { return static_cast(end_ - data_); } protected: Stream(uint8_t* _data, uint32_t _count) : data_(_data) , end_(_data + _count) {} private: uint8_t* data_; uint8_t* end_; }; /** * \brief Input stream */ struct ROSCPP_SERIALIZATION_DECL IStream : public Stream { static const StreamType stream_type = stream_types::Input; IStream(uint8_t* data, uint32_t count) : Stream(data, count) {} /** * \brief Deserialize an item from this input stream */ template ROS_FORCE_INLINE void next(T& t) { deserialize(*this, t); } template ROS_FORCE_INLINE IStream& operator>>(T& t) { deserialize(*this, t); return *this; } }; /** * \brief Output stream */ struct ROSCPP_SERIALIZATION_DECL OStream : public Stream { static const StreamType stream_type = stream_types::Output; OStream(uint8_t* data, uint32_t count) : Stream(data, count) {} /** * \brief Serialize an item to this output stream */ template ROS_FORCE_INLINE void next(const T& t) { serialize(*this, t); } template ROS_FORCE_INLINE OStream& operator<<(const T& t) { serialize(*this, t); return *this; } }; /** * \brief Length stream * * LStream is not what you would normally think of as a stream, but it is used in order to support * allinone serializers. */ struct ROSCPP_SERIALIZATION_DECL LStream { static const StreamType stream_type = stream_types::Length; LStream() : count_(0) {} /** * \brief Add the length of an item to this length stream */ template ROS_FORCE_INLINE void next(const T& t) { count_ += serializationLength(t); } /** * \brief increment the length by len */ ROS_FORCE_INLINE uint32_t advance(uint32_t len) { uint32_t old = count_; count_ += len; return old; } /** * \brief Get the total length of this tream */ inline uint32_t getLength() { return count_; } private: uint32_t count_; }; /** * \brief Serialize a message */ template inline SerializedMessage serializeMessage(const M& message) { SerializedMessage m; uint32_t len = serializationLength(message); m.num_bytes = len + 4; m.buf.reset(new uint8_t[m.num_bytes]); OStream s(m.buf.get(), static_cast(m.num_bytes)); serialize(s, static_cast(m.num_bytes) - 4); m.message_start = s.getData(); serialize(s, message); return m; } /** * \brief Serialize a service response */ template inline SerializedMessage serializeServiceResponse(bool ok, const M& message) { SerializedMessage m; if (ok) { uint32_t len = serializationLength(message); m.num_bytes = len + 5; m.buf.reset(new uint8_t[m.num_bytes]); OStream s(m.buf.get(), static_cast(m.num_bytes)); serialize(s, static_cast(ok)); serialize(s, static_cast(m.num_bytes) - 5); serialize(s, message); } else { uint32_t len = serializationLength(message); m.num_bytes = len + 1; m.buf.reset(new uint8_t[m.num_bytes]); OStream s(m.buf.get(), static_cast(m.num_bytes)); serialize(s, static_cast(ok)); serialize(s, message); } return m; } /** * \brief Deserialize a message. If includes_length is true, skips the first 4 bytes */ template inline void deserializeMessage(const SerializedMessage& m, M& message) { IStream s(m.message_start, static_cast(m.num_bytes - (m.message_start - m.buf.get()))); deserialize(s, message); } // Additional serialization traits template struct PreDeserializeParams { boost::shared_ptr message; boost::shared_ptr > connection_header; }; /** * \brief called by the SubscriptionCallbackHelper after a message is * instantiated but before that message is deserialized */ template struct PreDeserialize { static void notify(const PreDeserializeParams&) { } }; } // namespace serialization } // namespace ros #endif // ROSCPP_SERIALIZATION_H roscpp_core-0.6.13/roscpp_serialization/include/ros/serialized_message.h000066400000000000000000000044461354547546400266510ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSLIB_SERIALIZED_MESSAGE_H #define ROSLIB_SERIALIZED_MESSAGE_H #include "roscpp_serialization_macros.h" #include #include namespace ros { class ROSCPP_SERIALIZATION_DECL SerializedMessage { public: boost::shared_array buf; size_t num_bytes; uint8_t* message_start; boost::shared_ptr message; const std::type_info* type_info; SerializedMessage() : buf(boost::shared_array()) , num_bytes(0) , message_start(0) , type_info(0) {} SerializedMessage(boost::shared_array buf, size_t num_bytes) : buf(buf) , num_bytes(num_bytes) , message_start(buf ? buf.get() : 0) , type_info(0) { } }; } // namespace ros #endif // ROSLIB_SERIALIZED_MESSAGE_H roscpp_core-0.6.13/roscpp_serialization/package.xml000066400000000000000000000015731354547546400225260ustar00rootroot00000000000000 roscpp_serialization 0.6.13 roscpp_serialization contains the code for serialization as described in MessagesSerializationAndAdaptingTypes. This package is a component of roscpp. Dirk Thomas BSD http://ros.org/wiki/roscpp_serialization Josh Faust catkin cpp_common roscpp_traits rostime cpp_common roscpp_traits rostime roscpp_core-0.6.13/roscpp_serialization/src/000077500000000000000000000000001354547546400211725ustar00rootroot00000000000000roscpp_core-0.6.13/roscpp_serialization/src/serialization.cpp000066400000000000000000000033231354547546400245540ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include namespace ros { namespace serialization { void throwStreamOverrun() { throw StreamOverrunException("Buffer Overrun"); } } } roscpp_core-0.6.13/roscpp_traits/000077500000000000000000000000001354547546400170345ustar00rootroot00000000000000roscpp_core-0.6.13/roscpp_traits/CHANGELOG.rst000066400000000000000000000046151354547546400210630ustar00rootroot00000000000000^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Changelog for package roscpp_traits ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0.6.13 (2019-10-03) ------------------- 0.6.12 (2019-03-04) ------------------- 0.6.11 (2018-06-06) ------------------- 0.6.10 (2018-05-01) ------------------- 0.6.9 (2018-02-02) ------------------ 0.6.8 (2018-01-26) ------------------ 0.6.7 (2017-11-03) ------------------ 0.6.6 (2017-10-25) ------------------ * fix assignment operator of MessageEvent (`#66 `_) * fix docblock of ROS_DECLARE_MESSAGE_WITH_ALLOCATOR (`#67 `_) 0.6.5 (2017-07-27) ------------------ 0.6.4 (2017-06-06) ------------------ 0.6.3 (2017-05-15) ------------------ 0.6.2 (2017-02-14) ------------------ * fix warning when compiling with -Wpedantic (`#53 `_) * fix warning about unused parameters (`#52 `_) 0.6.1 (2016-09-02) ------------------ 0.6.0 (2016-03-17) ------------------ 0.5.7 (2016-03-09) ------------------ 0.5.6 (2015-05-20) ------------------ * fix for compile issue on OS X 10.10 (`#34 `_) 0.5.5 (2014-12-22) ------------------ 0.5.4 (2014-07-23) ------------------ 0.5.3 (2014-06-28) ------------------ 0.5.2 (2014-06-27) ------------------ 0.5.1 (2014-06-24) ------------------ 0.5.0 (2014-02-19) ------------------ 0.4.2 (2014-02-11) ------------------ * Revert "remove MessageEvent constructors from Message" (revert changes from 0.4.1) 0.4.1 (2014-02-11) ------------------ * remove MessageEvent constructors from Message (`#21 `_) 0.4.0 (2014-01-29) ------------------ * ros::MessageEvent no longer reads __connection_header from ROS message (`#19 `_) 0.3.17 (2014-01-07) ------------------- * move several client library independent parts from ros_comm into roscpp_core (`#12 `_) * fix compilation with libc++ (`#15 `_) 0.3.16 (2013-07-14) ------------------- 0.3.15 (2013-06-06) ------------------- 0.3.14 (2013-03-21) ------------------- 0.3.13 (2013-03-08) ------------------- 0.3.12 (2013-01-13) ------------------- 0.3.11 (2012-12-21) ------------------- * first public release for Groovy roscpp_core-0.6.13/roscpp_traits/CMakeLists.txt000066400000000000000000000004261354547546400215760ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8.3) project(roscpp_traits) find_package(catkin REQUIRED) catkin_package( INCLUDE_DIRS include CATKIN_DEPENDS cpp_common rostime) install(DIRECTORY include/ DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.h") roscpp_core-0.6.13/roscpp_traits/include/000077500000000000000000000000001354547546400204575ustar00rootroot00000000000000roscpp_core-0.6.13/roscpp_traits/include/ros/000077500000000000000000000000001354547546400212625ustar00rootroot00000000000000roscpp_core-0.6.13/roscpp_traits/include/ros/builtin_message_traits.h000066400000000000000000000050251354547546400261750ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSLIB_BUILTIN_MESSAGE_TRAITS_H #define ROSLIB_BUILTIN_MESSAGE_TRAITS_H #include "message_traits.h" #include "ros/time.h" namespace ros { namespace message_traits { #define ROSLIB_CREATE_SIMPLE_TRAITS(Type) \ template<> struct IsSimple : public TrueType {}; \ template<> struct IsFixedSize : public TrueType {}; ROSLIB_CREATE_SIMPLE_TRAITS(uint8_t) ROSLIB_CREATE_SIMPLE_TRAITS(int8_t) ROSLIB_CREATE_SIMPLE_TRAITS(uint16_t) ROSLIB_CREATE_SIMPLE_TRAITS(int16_t) ROSLIB_CREATE_SIMPLE_TRAITS(uint32_t) ROSLIB_CREATE_SIMPLE_TRAITS(int32_t) ROSLIB_CREATE_SIMPLE_TRAITS(uint64_t) ROSLIB_CREATE_SIMPLE_TRAITS(int64_t) ROSLIB_CREATE_SIMPLE_TRAITS(float) ROSLIB_CREATE_SIMPLE_TRAITS(double) ROSLIB_CREATE_SIMPLE_TRAITS(Time) ROSLIB_CREATE_SIMPLE_TRAITS(Duration) // because std::vector is not a true vector, bool is not a simple type template<> struct IsFixedSize : public TrueType {}; } // namespace message_traits } // namespace ros #endif // ROSLIB_BUILTIN_MESSAGE_TRAITS_H roscpp_core-0.6.13/roscpp_traits/include/ros/message_event.h000066400000000000000000000210661354547546400242650ustar00rootroot00000000000000 /* * Copyright (C) 2010, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSCPP_MESSAGE_EVENT_H #define ROSCPP_MESSAGE_EVENT_H #include "ros/time.h" #include #include #include #include #include #include #include #include #include #include namespace ros { template struct DefaultMessageCreator { boost::shared_ptr operator()() { return boost::make_shared(); } }; template ROS_DEPRECATED inline boost::shared_ptr defaultMessageCreateFunction() { return DefaultMessageCreator()(); } /** * \brief Event type for subscriptions, const ros::MessageEvent& can be used in your callback instead of const boost::shared_ptr& * * Useful if you need to retrieve meta-data about the message, such as the full connection header, or the publisher's node name */ template class MessageEvent { public: typedef typename boost::add_const::type ConstMessage; typedef typename boost::remove_const::type Message; typedef boost::shared_ptr MessagePtr; typedef boost::shared_ptr ConstMessagePtr; typedef boost::function CreateFunction; MessageEvent() : nonconst_need_copy_(true) {} MessageEvent(const MessageEvent& rhs) { *this = rhs; } MessageEvent(const MessageEvent& rhs) { *this = rhs; } MessageEvent(const MessageEvent& rhs, bool nonconst_need_copy) { *this = rhs; nonconst_need_copy_ = nonconst_need_copy; } MessageEvent(const MessageEvent& rhs, bool nonconst_need_copy) { *this = rhs; nonconst_need_copy_ = nonconst_need_copy; } MessageEvent(const MessageEvent& rhs, const CreateFunction& create) { init(boost::const_pointer_cast(boost::static_pointer_cast(rhs.getMessage())), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), create); } /** * \todo Make this explicit in ROS 2.0. Keep as auto-converting for now to maintain backwards compatibility in some places (message_filters) */ MessageEvent(const ConstMessagePtr& message) { init(message, boost::shared_ptr(), ros::Time::now(), true, ros::DefaultMessageCreator()); } MessageEvent(const ConstMessagePtr& message, const boost::shared_ptr& connection_header, ros::Time receipt_time) { init(message, connection_header, receipt_time, true, ros::DefaultMessageCreator()); } MessageEvent(const ConstMessagePtr& message, ros::Time receipt_time) { init(message, boost::shared_ptr(), receipt_time, true, ros::DefaultMessageCreator()); } MessageEvent(const ConstMessagePtr& message, const boost::shared_ptr& connection_header, ros::Time receipt_time, bool nonconst_need_copy, const CreateFunction& create) { init(message, connection_header, receipt_time, nonconst_need_copy, create); } void init(const ConstMessagePtr& message, const boost::shared_ptr& connection_header, ros::Time receipt_time, bool nonconst_need_copy, const CreateFunction& create) { message_ = message; connection_header_ = connection_header; receipt_time_ = receipt_time; nonconst_need_copy_ = nonconst_need_copy; create_ = create; } void operator=(const MessageEvent& rhs) { init(boost::static_pointer_cast(rhs.getMessage()), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), rhs.getMessageFactory()); message_copy_.reset(); } void operator=(const MessageEvent& rhs) { init(boost::const_pointer_cast(boost::static_pointer_cast(rhs.getMessage())), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), rhs.getMessageFactory()); message_copy_.reset(); } /** * \brief Retrieve the message. If M is const, this returns a reference to it. If M is non const * and this event requires it, returns a copy. Note that it caches this copy for later use, so it will * only every make the copy once */ boost::shared_ptr getMessage() const { return copyMessageIfNecessary(); } /** * \brief Retrieve a const version of the message */ const boost::shared_ptr& getConstMessage() const { return message_; } /** * \brief Retrieve the connection header */ M_string& getConnectionHeader() const { return *connection_header_; } const boost::shared_ptr& getConnectionHeaderPtr() const { return connection_header_; } /** * \brief Returns the name of the node which published this message */ const std::string& getPublisherName() const { return connection_header_ ? (*connection_header_)["callerid"] : s_unknown_publisher_string_; } /** * \brief Returns the time at which this message was received */ ros::Time getReceiptTime() const { return receipt_time_; } bool nonConstWillCopy() const { return nonconst_need_copy_; } bool getMessageWillCopy() const { return !boost::is_const::value && nonconst_need_copy_; } bool operator<(const MessageEvent& rhs) { if (message_ != rhs.message_) { return message_ < rhs.message_; } if (receipt_time_ != rhs.receipt_time_) { return receipt_time_ < rhs.receipt_time_; } return nonconst_need_copy_ < rhs.nonconst_need_copy_; } bool operator==(const MessageEvent& rhs) { return message_ == rhs.message_ && receipt_time_ == rhs.receipt_time_ && nonconst_need_copy_ == rhs.nonconst_need_copy_; } bool operator!=(const MessageEvent& rhs) { return !(*this == rhs); } const CreateFunction& getMessageFactory() const { return create_; } private: template typename boost::disable_if, boost::shared_ptr >::type copyMessageIfNecessary() const { if (boost::is_const::value || !nonconst_need_copy_) { return boost::const_pointer_cast(message_); } if (message_copy_) { return message_copy_; } assert(create_); message_copy_ = create_(); *message_copy_ = *message_; return message_copy_; } template typename boost::enable_if, boost::shared_ptr >::type copyMessageIfNecessary() const { return boost::const_pointer_cast(message_); } ConstMessagePtr message_; // Kind of ugly to make this mutable, but it means we can pass a const MessageEvent to a callback and not worry about other things being modified mutable MessagePtr message_copy_; boost::shared_ptr connection_header_; ros::Time receipt_time_; bool nonconst_need_copy_; CreateFunction create_; static const std::string s_unknown_publisher_string_; }; template const std::string MessageEvent::s_unknown_publisher_string_("unknown_publisher"); } #endif // ROSCPP_MESSAGE_EVENT_H roscpp_core-0.6.13/roscpp_traits/include/ros/message_forward.h000066400000000000000000000056701354547546400246130ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSLIB_MESSAGE_FORWARD_H #define ROSLIB_MESSAGE_FORWARD_H // Make sure that either __GLIBCXX__ or _LIBCPP_VERSION is defined. #include // C++ standard section 17.4.3.1/1 states that forward declarations of STL types // that aren't specializations involving user defined types results in undefined // behavior. Apparently only libc++ has a problem with this and won't compile it. #ifndef _LIBCPP_VERSION namespace std { template class allocator; } #else #include #endif namespace boost { template class shared_ptr; } /** * \brief Forward-declare a message, including Ptr and ConstPtr types, with an allocator * * \param msg The "base" message type, i.e., the name of the .msg file * \param new_name The name you'd like the message to have * \param alloc The allocator to use, e.g. std::allocator */ #define ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(msg, new_name, alloc) \ template struct msg##_; \ typedef msg##_ > new_name; \ typedef boost::shared_ptr new_name##Ptr; \ typedef boost::shared_ptr new_name##ConstPtr; /** * \brief Forward-declare a message, including Ptr and ConstPtr types, using std::allocator * \param msg The "base" message type, i.e. the name of the .msg file */ #define ROS_DECLARE_MESSAGE(msg) ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(msg, msg, std::allocator) #endif // ROSLIB_MESSAGE_FORWARD_H roscpp_core-0.6.13/roscpp_traits/include/ros/message_operations.h000066400000000000000000000047711354547546400253330ustar00rootroot00000000000000/* * Copyright (C) 2010, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSLIB_MESSAGE_OPERATIONS_H #define ROSLIB_MESSAGE_OPERATIONS_H #include namespace ros { namespace message_operations { template struct Printer { template static void stream(Stream& s, const std::string& indent, const M& value) { (void)indent; s << value << "\n"; } }; // Explicitly specialize for uint8_t/int8_t because otherwise it thinks it's a char, and treats // the value as a character code template<> struct Printer { template static void stream(Stream& s, const std::string& indent, int8_t value) { (void)indent; s << static_cast(value) << "\n"; } }; template<> struct Printer { template static void stream(Stream& s, const std::string& indent, uint8_t value) { (void)indent; s << static_cast(value) << "\n"; } }; } // namespace message_operations } // namespace ros #endif // ROSLIB_MESSAGE_OPERATIONS_H roscpp_core-0.6.13/roscpp_traits/include/ros/message_traits.h000066400000000000000000000234101354547546400244450ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSLIB_MESSAGE_TRAITS_H #define ROSLIB_MESSAGE_TRAITS_H #include "message_forward.h" #include #include #include #include #include namespace std_msgs { ROS_DECLARE_MESSAGE(Header) } #define ROS_IMPLEMENT_SIMPLE_TOPIC_TRAITS(msg, md5sum, datatype, definition) \ namespace ros \ { \ namespace message_traits \ { \ template<> struct MD5Sum \ { \ static const char* value() { return md5sum; } \ static const char* value(const msg&) { return value(); } \ }; \ template<> struct DataType \ { \ static const char* value() { return datatype; } \ static const char* value(const msg&) { return value(); } \ }; \ template<> struct Definition \ { \ static const char* value() { return definition; } \ static const char* value(const msg&) { return value(); } \ }; \ } \ } namespace ros { namespace message_traits { /** * \brief Base type for compile-type true/false tests. Compatible with Boost.MPL. classes inheriting from this type * are \b true values. */ struct TrueType { static const bool value = true; typedef TrueType type; }; /** * \brief Base type for compile-type true/false tests. Compatible with Boost.MPL. classes inheriting from this type * are \b false values. */ struct FalseType { static const bool value = false; typedef FalseType type; }; /** * \brief A simple datatype is one that can be memcpy'd directly in array form, i.e. it's a POD, fixed-size type and * sizeof(M) == sum(serializationLength(M:a...)) */ template struct IsSimple : public FalseType {}; /** * \brief A fixed-size datatype is one whose size is constant, i.e. it has no variable-length arrays or strings */ template struct IsFixedSize : public FalseType {}; /** * \brief HasHeader informs whether or not there is a header that gets serialized as the first thing in the message */ template struct HasHeader : public FalseType {}; /** * \brief Am I message or not */ template struct IsMessage : public FalseType {}; /** * \brief Specialize to provide the md5sum for a message */ template struct MD5Sum { static const char* value() { return M::__s_getMD5Sum().c_str(); } static const char* value(const M& m) { return m.__getMD5Sum().c_str(); } }; /** * \brief Specialize to provide the datatype for a message */ template struct DataType { static const char* value() { return M::__s_getDataType().c_str(); } static const char* value(const M& m) { return m.__getDataType().c_str(); } }; /** * \brief Specialize to provide the definition for a message */ template struct Definition { static const char* value() { return M::__s_getMessageDefinition().c_str(); } static const char* value(const M& m) { return m.__getMessageDefinition().c_str(); } }; /** * \brief Header trait. In the default implementation pointer() * returns &m.header if HasHeader::value is true, otherwise returns NULL */ template struct Header { static std_msgs::Header* pointer(M& m) { (void)m; return 0; } static std_msgs::Header const* pointer(const M& m) { (void)m; return 0; } }; template struct Header >::type > { static std_msgs::Header* pointer(M& m) { return &m.header; } static std_msgs::Header const* pointer(const M& m) { return &m.header; } }; /** * \brief FrameId trait. In the default implementation pointer() * returns &m.header.frame_id if HasHeader::value is true, otherwise returns NULL. value() * does not exist, and causes a compile error */ template struct FrameId { static std::string* pointer(M& m) { (void)m; return 0; } static std::string const* pointer(const M& m) { (void)m; return 0; } }; template struct FrameId >::type > { static std::string* pointer(M& m) { return &m.header.frame_id; } static std::string const* pointer(const M& m) { return &m.header.frame_id; } static std::string value(const M& m) { return m.header.frame_id; } }; /** * \brief TimeStamp trait. In the default implementation pointer() * returns &m.header.stamp if HasHeader::value is true, otherwise returns NULL. value() * does not exist, and causes a compile error */ template struct TimeStamp { static ros::Time* pointer(M& m) { (void)m; return 0; } static ros::Time const* pointer(const M& m) { (void)m; return 0; } }; template struct TimeStamp >::type > { static ros::Time* pointer(typename boost::remove_const::type &m) { return &m.header.stamp; } static ros::Time const* pointer(const M& m) { return &m.header.stamp; } static ros::Time value(const M& m) { return m.header.stamp; } }; /** * \brief returns MD5Sum::value(); */ template inline const char* md5sum() { return MD5Sum::type>::type>::value(); } /** * \brief returns DataType::value(); */ template inline const char* datatype() { return DataType::type>::type>::value(); } /** * \brief returns Definition::value(); */ template inline const char* definition() { return Definition::type>::type>::value(); } /** * \brief returns MD5Sum::value(m); */ template inline const char* md5sum(const M& m) { return MD5Sum::type>::type>::value(m); } /** * \brief returns DataType::value(m); */ template inline const char* datatype(const M& m) { return DataType::type>::type>::value(m); } /** * \brief returns Definition::value(m); */ template inline const char* definition(const M& m) { return Definition::type>::type>::value(m); } /** * \brief returns Header::pointer(m); */ template inline std_msgs::Header* header(M& m) { return Header::type>::type>::pointer(m); } /** * \brief returns Header::pointer(m); */ template inline std_msgs::Header const* header(const M& m) { return Header::type>::type>::pointer(m); } /** * \brief returns FrameId::pointer(m); */ template inline std::string* frameId(M& m) { return FrameId::type>::type>::pointer(m); } /** * \brief returns FrameId::pointer(m); */ template inline std::string const* frameId(const M& m) { return FrameId::type>::type>::pointer(m); } /** * \brief returns TimeStamp::pointer(m); */ template inline ros::Time* timeStamp(M& m) { return TimeStamp::type>::type>::pointer(m); } /** * \brief returns TimeStamp::pointer(m); */ template inline ros::Time const* timeStamp(const M& m) { return TimeStamp::type>::type>::pointer(m); } /** * \brief returns IsSimple::value; */ template inline bool isSimple() { return IsSimple::type>::type>::value; } /** * \brief returns IsFixedSize::value; */ template inline bool isFixedSize() { return IsFixedSize::type>::type>::value; } /** * \brief returns HasHeader::value; */ template inline bool hasHeader() { return HasHeader::type>::type>::value; } } // namespace message_traits } // namespace ros #endif // ROSLIB_MESSAGE_TRAITS_H roscpp_core-0.6.13/roscpp_traits/include/ros/service_traits.h000066400000000000000000000063111354547546400244620ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef ROSCPP_SERVICE_TRAITS_H #define ROSCPP_SERVICE_TRAITS_H #include #include namespace ros { namespace service_traits { /** * \brief Specialize to provide the md5sum for a service */ template struct MD5Sum { static const char* value() { return M::__s_getServerMD5Sum().c_str(); } static const char* value(const M& m) { return m.__getServerMD5Sum().c_str(); } }; /** * \brief Specialize to provide the datatype for a service */ template struct DataType { static const char* value() { return M::__s_getServiceDataType().c_str(); } static const char* value(const M& m) { return m.__getServiceDataType().c_str(); } }; /** * \brief return MD5Sum::value(); */ template inline const char* md5sum() { return MD5Sum::type>::type>::value(); } /** * \brief return DataType::value(); */ template inline const char* datatype() { return DataType::type>::type>::value(); } /** * \brief return MD5Sum::value(m); */ template inline const char* md5sum(const M& m) { return MD5Sum::type>::type>::value(m); } /** * \brief return DataType::value(); */ template inline const char* datatype(const M& m) { return DataType::type>::type>::value(m); } } // namespace service_traits } // namespace ros #endif // ROSCPP_SERVICE_TRAITS_H roscpp_core-0.6.13/roscpp_traits/package.xml000066400000000000000000000012341354547546400211510ustar00rootroot00000000000000 roscpp_traits 0.6.13 roscpp_traits contains the message traits code as described in MessagesTraits. This package is a component of roscpp. Dirk Thomas BSD http://ros.org/wiki/roscpp_traits Josh Faust catkin cpp_common rostime roscpp_core-0.6.13/rostime/000077500000000000000000000000001354547546400156225ustar00rootroot00000000000000roscpp_core-0.6.13/rostime/CHANGELOG.rst000066400000000000000000000106051354547546400176450ustar00rootroot00000000000000^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Changelog for package rostime ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0.6.13 (2019-10-03) ------------------- * use _WIN32 for platform detection (`#110 `_) * Clarified documentation for time validity (`#109 `_) * rostime: replace c-style casts with static_casts (`#106 `_) 0.6.12 (2019-03-04) ------------------- * use std::numeric_limits instead of * _MAX macros for range checking (`#103 `_) * use std::this_thread::sleep_for instead of WaitableTimer (`#101 `_) * include windows.h in time.cpp (`#100 `_) * fix duration bug and add tests. (`#98 `_) * fix for Duration::fromSec() which had rounding issues (`#93 `_) * fix bug in HAVE_CXXABI_H compiler check (`#89 `_) * add ROSTIME_DECL storage-class attribute (`#90 `_) 0.6.11 (2018-06-06) ------------------- * argument to boost microseconds must be integral for Boost 1.67 and newer compatibility (`#79 `_) * remove empty destructor of TimeBase (which makes TimeBase, Time and WallTime trivially copyable) (`#82 `_) 0.6.10 (2018-05-01) ------------------- * fix conversion of Duration on macOS (`#78 `_) 0.6.9 (2018-02-02) ------------------ * expose ros_walltime and ros_steadytime (`#73 `_) 0.6.8 (2018-01-26) ------------------ 0.6.7 (2017-11-03) ------------------ 0.6.6 (2017-10-25) ------------------ * only use Apple features on Apple (`#68 `_) * remove exception specification (`#64 `_) 0.6.5 (2017-07-27) ------------------ * add additional checks for valid time values (`#62 `_) * fix overflow bugs in Time and Duration (`#61 `_, `#63 `_) 0.6.4 (2017-06-06) ------------------ * add logic to support steady time on macOS (regression of 0.6.3) (`#59 `_) 0.6.3 (2017-05-15) ------------------ * add SteadyTime (`#57 `_) 0.6.2 (2017-02-14) ------------------ 0.6.1 (2016-09-02) ------------------ * fix rounding errors leading to invalid stored data in ros::TimeBase (`#48 `_) 0.6.0 (2016-03-17) ------------------ * change Duration:sleep return semantic (`#47 `_) 0.5.7 (2016-03-09) ------------------ * Adjust return value of sleep() function (`#45 `_) * fix WallRate(Duration) constructor (`#40 `_) 0.5.6 (2015-05-20) ------------------ 0.5.5 (2014-12-22) ------------------ * move implementation of Duration(Rate) constructor (`#30 `_) * fix Duration initialization from seconds for negative values (`#29 `_) 0.5.4 (2014-07-23) ------------------ * fix Rate initialized by Duration (`#26 `_) 0.5.3 (2014-06-28) ------------------ 0.5.2 (2014-06-27) ------------------ 0.5.1 (2014-06-24) ------------------ 0.5.0 (2014-02-19) ------------------ 0.4.2 (2014-02-11) ------------------ 0.4.1 (2014-02-11) ------------------ 0.4.0 (2014-01-29) ------------------ 0.3.17 (2014-01-07) ------------------- * fix boost include dir 0.3.16 (2013-07-14) ------------------- * support for CATKIN_ENABLE_TESTING 0.3.15 (2013-06-06) ------------------- * fix install destination for dll's under Windows 0.3.14 (2013-03-21) ------------------- 0.3.13 (2013-03-08) ------------------- 0.3.12 (2013-01-13) ------------------- * improve string output of negative durations (`#3309 `_) 0.3.11 (2012-12-21) ------------------- * first public release for Groovy roscpp_core-0.6.13/rostime/CMakeLists.txt000066400000000000000000000025541354547546400203700ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8.3) project(rostime) find_package(catkin REQUIRED COMPONENTS cpp_common) find_package(Boost REQUIRED COMPONENTS date_time system thread) catkin_package( INCLUDE_DIRS include LIBRARIES ${PROJECT_NAME} CATKIN_DEPENDS cpp_common DEPENDS Boost ) include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) add_library(rostime src/duration.cpp src/rate.cpp src/time.cpp) target_link_libraries(rostime ${Boost_LIBRARIES}) if(NOT APPLE) target_link_libraries(rostime ${RT_LIBRARY}) endif() install(TARGETS rostime ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) install(DIRECTORY include/ DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.h") if(CATKIN_ENABLE_TESTING) catkin_add_gtest(${PROJECT_NAME}-test_duration test/duration.cpp) if(TARGET ${PROJECT_NAME}-test_duration) target_link_libraries(${PROJECT_NAME}-test_duration ${catkin_LIBRARIES} rostime) endif() catkin_add_gtest(${PROJECT_NAME}-test_time test/time.cpp) if(TARGET ${PROJECT_NAME}-test_time) set_property(TARGET ${PROJECT_NAME}-test_time APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++11") target_link_libraries(${PROJECT_NAME}-test_time ${catkin_LIBRARIES} rostime) endif() endif() roscpp_core-0.6.13/rostime/include/000077500000000000000000000000001354547546400172455ustar00rootroot00000000000000roscpp_core-0.6.13/rostime/include/ros/000077500000000000000000000000001354547546400200505ustar00rootroot00000000000000roscpp_core-0.6.13/rostime/include/ros/duration.h000066400000000000000000000125121354547546400220470ustar00rootroot00000000000000/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2008, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef ROS_DURATION_H #define ROS_DURATION_H /********************************************************************* ** Pragmas *********************************************************************/ #ifdef _MSC_VER // Rostime has some magic interface that doesn't directly include // its implementation, this just disbales those warnings. #pragma warning(disable: 4244) #pragma warning(disable: 4661) #endif #include #include #include #include #include #include "rostime_decl.h" namespace boost { namespace posix_time { class time_duration; } } namespace ros { ROSTIME_DECL void normalizeSecNSecSigned(int64_t& sec, int64_t& nsec); ROSTIME_DECL void normalizeSecNSecSigned(int32_t& sec, int32_t& nsec); /** * \brief Base class for Duration implementations. Provides storage, common functions and operator overloads. * This should not need to be used directly. */ template class DurationBase { public: int32_t sec, nsec; DurationBase() : sec(0), nsec(0) { } DurationBase(int32_t _sec, int32_t _nsec); explicit DurationBase(double t){fromSec(t);}; ~DurationBase() {} T operator+(const T &rhs) const; T operator-(const T &rhs) const; T operator-() const; T operator*(double scale) const; T& operator+=(const T &rhs); T& operator-=(const T &rhs); T& operator*=(double scale); bool operator==(const T &rhs) const; inline bool operator!=(const T &rhs) const { return !(*static_cast(this) == rhs); } bool operator>(const T &rhs) const; bool operator<(const T &rhs) const; bool operator>=(const T &rhs) const; bool operator<=(const T &rhs) const; double toSec() const { return static_cast(sec) + 1e-9*static_cast(nsec); }; int64_t toNSec() const {return static_cast(sec)*1000000000ll + static_cast(nsec); }; T& fromSec(double t); T& fromNSec(int64_t t); bool isZero() const; boost::posix_time::time_duration toBoost() const; }; class Rate; /** * \brief Duration representation for use with the Time class. * * ros::DurationBase provides most of its functionality. */ class ROSTIME_DECL Duration : public DurationBase { public: Duration() : DurationBase() { } Duration(int32_t _sec, int32_t _nsec) : DurationBase(_sec, _nsec) {} explicit Duration(double t) { fromSec(t); } explicit Duration(const Rate&); /** * \brief sleep for the amount of time specified by this Duration. If a signal interrupts the sleep, resleeps for the time remaining. * @return True if the desired sleep duration was met, false otherwise. */ bool sleep() const; }; extern ROSTIME_DECL const Duration DURATION_MAX; extern ROSTIME_DECL const Duration DURATION_MIN; /** * \brief Duration representation for use with the WallTime class. * * ros::DurationBase provides most of its functionality. */ class ROSTIME_DECL WallDuration : public DurationBase { public: WallDuration() : DurationBase() { } WallDuration(int32_t _sec, int32_t _nsec) : DurationBase(_sec, _nsec) {} explicit WallDuration(double t) { fromSec(t); } explicit WallDuration(const Rate&); /** * \brief sleep for the amount of time specified by this Duration. If a signal interrupts the sleep, resleeps for the time remaining. * @return True if the desired sleep duration was met, false otherwise. */ bool sleep() const; }; ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const Duration &rhs); ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const WallDuration &rhs); } #endif // ROS_DURATION_H roscpp_core-0.6.13/rostime/include/ros/impl/000077500000000000000000000000001354547546400210115ustar00rootroot00000000000000roscpp_core-0.6.13/rostime/include/ros/impl/duration.h000066400000000000000000000126661354547546400230220ustar00rootroot00000000000000/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2010, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef ROSTIME_IMPL_DURATION_H_INCLUDED #define ROSTIME_IMPL_DURATION_H_INCLUDED #include #include #include #include namespace ros { // // DurationBase template member function implementation // template DurationBase::DurationBase(int32_t _sec, int32_t _nsec) : sec(_sec), nsec(_nsec) { normalizeSecNSecSigned(sec, nsec); } template T& DurationBase::fromSec(double d) { int64_t sec64 = static_cast(floor(d)); if (sec64 < std::numeric_limits::min() || sec64 > std::numeric_limits::max()) throw std::runtime_error("Duration is out of dual 32-bit range"); sec = static_cast(sec64); nsec = static_cast(boost::math::round((d - sec) * 1e9)); int32_t rollover = nsec / 1000000000ul; sec += rollover; nsec %= 1000000000ul; return *static_cast(this); } template T& DurationBase::fromNSec(int64_t t) { int64_t sec64 = t / 1000000000LL; if (sec64 < std::numeric_limits::min() || sec64 > std::numeric_limits::max()) throw std::runtime_error("Duration is out of dual 32-bit range"); sec = static_cast(sec64); nsec = static_cast(t % 1000000000LL); normalizeSecNSecSigned(sec, nsec); return *static_cast(this); } template T DurationBase::operator+(const T &rhs) const { T t; return t.fromNSec(toNSec() + rhs.toNSec()); } template T DurationBase::operator*(double scale) const { return T(toSec() * scale); } template T DurationBase::operator-(const T &rhs) const { T t; return t.fromNSec(toNSec() - rhs.toNSec()); } template T DurationBase::operator-() const { T t; return t.fromNSec(-toNSec()); } template T& DurationBase::operator+=(const T &rhs) { *this = *this + rhs; return *static_cast(this); } template T& DurationBase::operator-=(const T &rhs) { *this += (-rhs); return *static_cast(this); } template T& DurationBase::operator*=(double scale) { fromSec(toSec() * scale); return *static_cast(this); } template bool DurationBase::operator<(const T &rhs) const { if (sec < rhs.sec) return true; else if (sec == rhs.sec && nsec < rhs.nsec) return true; return false; } template bool DurationBase::operator>(const T &rhs) const { if (sec > rhs.sec) return true; else if (sec == rhs.sec && nsec > rhs.nsec) return true; return false; } template bool DurationBase::operator<=(const T &rhs) const { if (sec < rhs.sec) return true; else if (sec == rhs.sec && nsec <= rhs.nsec) return true; return false; } template bool DurationBase::operator>=(const T &rhs) const { if (sec > rhs.sec) return true; else if (sec == rhs.sec && nsec >= rhs.nsec) return true; return false; } template bool DurationBase::operator==(const T &rhs) const { return sec == rhs.sec && nsec == rhs.nsec; } template bool DurationBase::isZero() const { return sec == 0 && nsec == 0; } template boost::posix_time::time_duration DurationBase::toBoost() const { namespace bt = boost::posix_time; #if defined(BOOST_DATE_TIME_HAS_NANOSECONDS) return bt::seconds(sec) + bt::nanoseconds(nsec); #else return bt::seconds(sec) + bt::microseconds(nsec/1000); #endif } } #endif roscpp_core-0.6.13/rostime/include/ros/impl/time.h000066400000000000000000000130401354547546400221160ustar00rootroot00000000000000/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2008, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef ROS_TIME_IMPL_H_INCLUDED #define ROS_TIME_IMPL_H_INCLUDED /********************************************************************* ** Headers *********************************************************************/ #include #include #include #include #include #include /********************************************************************* ** Cross Platform Headers *********************************************************************/ #if defined(_WIN32) #include #else #include #endif namespace ros { template T& TimeBase::fromNSec(uint64_t t) { uint64_t sec64 = 0; uint64_t nsec64 = t; normalizeSecNSec(sec64, nsec64); sec = static_cast(sec64); nsec = static_cast(nsec64); return *static_cast(this); } template T& TimeBase::fromSec(double t) { int64_t sec64 = static_cast(floor(t)); if (sec64 < 0 || sec64 > std::numeric_limits::max()) throw std::runtime_error("Time is out of dual 32-bit range"); sec = static_cast(sec64); nsec = static_cast(boost::math::round((t-sec) * 1e9)); // avoid rounding errors sec += (nsec / 1000000000ul); nsec %= 1000000000ul; return *static_cast(this); } template D TimeBase::operator-(const T &rhs) const { D d; return d.fromNSec(toNSec() - rhs.toNSec()); } template T TimeBase::operator-(const D &rhs) const { return *static_cast(this) + ( -rhs); } template T TimeBase::operator+(const D &rhs) const { int64_t sec_sum = static_cast(sec) + static_cast(rhs.sec); int64_t nsec_sum = static_cast(nsec) + static_cast(rhs.nsec); // Throws an exception if we go out of 32-bit range normalizeSecNSecUnsigned(sec_sum, nsec_sum); // now, it's safe to downcast back to uint32 bits return T(static_cast(sec_sum), static_cast(nsec_sum)); } template T& TimeBase::operator+=(const D &rhs) { *this = *this + rhs; return *static_cast(this); } template T& TimeBase::operator-=(const D &rhs) { *this += (-rhs); return *static_cast(this); } template bool TimeBase::operator==(const T &rhs) const { return sec == rhs.sec && nsec == rhs.nsec; } template bool TimeBase::operator<(const T &rhs) const { if (sec < rhs.sec) return true; else if (sec == rhs.sec && nsec < rhs.nsec) return true; return false; } template bool TimeBase::operator>(const T &rhs) const { if (sec > rhs.sec) return true; else if (sec == rhs.sec && nsec > rhs.nsec) return true; return false; } template bool TimeBase::operator<=(const T &rhs) const { if (sec < rhs.sec) return true; else if (sec == rhs.sec && nsec <= rhs.nsec) return true; return false; } template bool TimeBase::operator>=(const T &rhs) const { if (sec > rhs.sec) return true; else if (sec == rhs.sec && nsec >= rhs.nsec) return true; return false; } template boost::posix_time::ptime TimeBase::toBoost() const { namespace pt = boost::posix_time; #if defined(BOOST_DATE_TIME_HAS_NANOSECONDS) return pt::from_time_t(sec) + pt::nanoseconds(nsec); #else return pt::from_time_t(sec) + pt::microseconds(nsec/1000); #endif } } #endif // ROS_IMPL_TIME_H_INCLUDED roscpp_core-0.6.13/rostime/include/ros/rate.h000066400000000000000000000077371354547546400211720ustar00rootroot00000000000000/********************************************************************* * * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * Author: Eitan Marder-Eppstein *********************************************************************/ #ifndef ROSLIB_RATE_H #define ROSLIB_RATE_H #include "ros/time.h" #include "rostime_decl.h" namespace ros { class Duration; /** * @class Rate * @brief Class to help run loops at a desired frequency */ class ROSTIME_DECL Rate { public: /** * @brief Constructor, creates a Rate * @param frequency The desired rate to run at in Hz */ Rate(double frequency); explicit Rate(const Duration&); /** * @brief Sleeps for any leftover time in a cycle. Calculated from the last time sleep, reset, or the constructor was called. * @return True if the desired rate was met for the cycle, false otherwise. */ bool sleep(); /** * @brief Sets the start time for the rate to now */ void reset(); /** * @brief Get the actual run time of a cycle from start to sleep * @return The runtime of the cycle */ Duration cycleTime() const; /** * @brief Get the expected cycle time -- one over the frequency passed in to the constructor */ Duration expectedCycleTime() const { return expected_cycle_time_; } private: Time start_; Duration expected_cycle_time_, actual_cycle_time_; }; /** * @class WallRate * @brief Class to help run loops at a desired frequency. This version always uses wall-clock time. */ class ROSTIME_DECL WallRate { public: /** * @brief Constructor, creates a Rate * @param frequency The desired rate to run at in Hz */ WallRate(double frequency); explicit WallRate(const Duration&); /** * @brief Sleeps for any leftover time in a cycle. Calculated from the last time sleep, reset, or the constructor was called. * @return Passes through the return value from WallDuration::sleep() if it slept, false otherwise. */ bool sleep(); /** * @brief Sets the start time for the rate to now */ void reset(); /** * @brief Get the actual run time of a cycle from start to sleep * @return The runtime of the cycle */ WallDuration cycleTime() const; /** * @brief Get the expected cycle time -- one over the frequency passed in to the constructor */ WallDuration expectedCycleTime() const { return expected_cycle_time_; } private: WallTime start_; WallDuration expected_cycle_time_, actual_cycle_time_; }; } #endif roscpp_core-0.6.13/rostime/include/ros/rostime_decl.h000066400000000000000000000043701354547546400226760ustar00rootroot00000000000000/********************************************************************* * * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * *********************************************************************/ /* * Cross platform macros. * */ #ifndef ROSTIME_DECL_HPP_INCLUDED #define ROSTIME_DECL_HPP_INCLUDED #include #ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries #ifdef rostime_EXPORTS // we are building a shared lib/dll #define ROSTIME_DECL ROS_HELPER_EXPORT #else // we are using shared lib/dll #define ROSTIME_DECL ROS_HELPER_IMPORT #endif #else // ros is being built around static libraries #define ROSTIME_DECL #endif #endif /* ROSTIME_DECL_HPP_INCLUDED */ roscpp_core-0.6.13/rostime/include/ros/time.h000066400000000000000000000226141354547546400211640ustar00rootroot00000000000000/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2010, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef ROS_TIME_H_INCLUDED #define ROS_TIME_H_INCLUDED /********************************************************************* ** Pragmas *********************************************************************/ #ifdef _MSC_VER // Rostime has some magic interface that doesn't directly include // its implementation, this just disables those warnings. #pragma warning(disable: 4244) #pragma warning(disable: 4661) #endif /********************************************************************* ** Headers *********************************************************************/ #include #include #include #include #include "duration.h" #include #include "rostime_decl.h" /********************************************************************* ** Cross Platform Headers *********************************************************************/ #if defined(_WIN32) #include #else #include #endif namespace boost { namespace posix_time { class ptime; class time_duration; } } namespace ros { /********************************************************************* ** Exceptions *********************************************************************/ /** * @brief Thrown if the ros subsystem hasn't been initialised before use. */ class ROSTIME_DECL TimeNotInitializedException : public Exception { public: TimeNotInitializedException() : Exception("Cannot use ros::Time::now() before the first NodeHandle has been created or ros::start() has been called. " "If this is a standalone app or test that just uses ros::Time and does not communicate over ROS, you may also call ros::Time::init()") {} }; /** * @brief Thrown if windows high perf. timestamping is unavailable. * * @sa getWallTime */ class ROSTIME_DECL NoHighPerformanceTimersException : public Exception { public: NoHighPerformanceTimersException() : Exception("This windows platform does not " "support the high-performance timing api.") {} }; /********************************************************************* ** Functions *********************************************************************/ ROSTIME_DECL void normalizeSecNSec(uint64_t& sec, uint64_t& nsec); ROSTIME_DECL void normalizeSecNSec(uint32_t& sec, uint32_t& nsec); ROSTIME_DECL void normalizeSecNSecUnsigned(int64_t& sec, int64_t& nsec); ROSTIME_DECL void ros_walltime(uint32_t& sec, uint32_t& nsec); ROSTIME_DECL void ros_steadytime(uint32_t& sec, uint32_t& nsec); /********************************************************************* ** Time Classes *********************************************************************/ /** * \brief Base class for Time implementations. Provides storage, common functions and operator overloads. * This should not need to be used directly. */ template class TimeBase { public: uint32_t sec, nsec; TimeBase() : sec(0), nsec(0) { } TimeBase(uint32_t _sec, uint32_t _nsec) : sec(_sec), nsec(_nsec) { normalizeSecNSec(sec, nsec); } explicit TimeBase(double t) { fromSec(t); } D operator-(const T &rhs) const; T operator+(const D &rhs) const; T operator-(const D &rhs) const; T& operator+=(const D &rhs); T& operator-=(const D &rhs); bool operator==(const T &rhs) const; inline bool operator!=(const T &rhs) const { return !(*static_cast(this) == rhs); } bool operator>(const T &rhs) const; bool operator<(const T &rhs) const; bool operator>=(const T &rhs) const; bool operator<=(const T &rhs) const; double toSec() const { return static_cast(sec) + 1e-9*static_cast(nsec); }; T& fromSec(double t); uint64_t toNSec() const {return static_cast(sec)*1000000000ull + static_cast(nsec); } T& fromNSec(uint64_t t); inline bool isZero() const { return sec == 0 && nsec == 0; } inline bool is_zero() const { return isZero(); } boost::posix_time::ptime toBoost() const; }; /** * \brief Time representation. May either represent wall clock time or ROS clock time. * * ros::TimeBase provides most of its functionality. */ class ROSTIME_DECL Time : public TimeBase { public: Time() : TimeBase() {} Time(uint32_t _sec, uint32_t _nsec) : TimeBase(_sec, _nsec) {} explicit Time(double t) { fromSec(t); } /** * \brief Retrieve the current time. If ROS clock time is in use, this returns the time according to the * ROS clock. Otherwise returns the current wall clock time. */ static Time now(); /** * \brief Sleep until a specific time has been reached. * @return True if the desired sleep time was met, false otherwise. */ static bool sleepUntil(const Time& end); static void init(); static void shutdown(); static void setNow(const Time& new_now); static bool useSystemTime(); static bool isSimTime(); static bool isSystemTime(); /** * \brief Returns whether or not the current time source is valid. Simulation time is valid if it is non-zero. */ static bool isValid(); /** * \brief Wait for time source to become valid */ static bool waitForValid(); /** * \brief Wait for time source to become valid, with timeout */ static bool waitForValid(const ros::WallDuration& timeout); static Time fromBoost(const boost::posix_time::ptime& t); static Time fromBoost(const boost::posix_time::time_duration& d); }; extern ROSTIME_DECL const Time TIME_MAX; extern ROSTIME_DECL const Time TIME_MIN; /** * \brief Time representation. Always wall-clock time. * * ros::TimeBase provides most of its functionality. */ class ROSTIME_DECL WallTime : public TimeBase { public: WallTime() : TimeBase() {} WallTime(uint32_t _sec, uint32_t _nsec) : TimeBase(_sec, _nsec) {} explicit WallTime(double t) { fromSec(t); } /** * \brief Returns the current wall clock time. */ static WallTime now(); /** * \brief Sleep until a specific time has been reached. * @return True if the desired sleep time was met, false otherwise. */ static bool sleepUntil(const WallTime& end); static bool isSystemTime() { return true; } }; /** * \brief Time representation. Always steady-clock time. * * Not affected by ROS time. * * ros::TimeBase provides most of its functionality. */ class ROSTIME_DECL SteadyTime : public TimeBase { public: SteadyTime() : TimeBase() {} SteadyTime(uint32_t _sec, uint32_t _nsec) : TimeBase(_sec, _nsec) {} explicit SteadyTime(double t) { fromSec(t); } /** * \brief Returns the current steady (monotonic) clock time. */ static SteadyTime now(); /** * \brief Sleep until a specific time has been reached. * @return True if the desired sleep time was met, false otherwise. */ static bool sleepUntil(const SteadyTime& end); static bool isSystemTime() { return true; } }; ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const Time &rhs); ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const WallTime &rhs); ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const SteadyTime &rhs); } #endif // ROS_TIME_H roscpp_core-0.6.13/rostime/package.xml000066400000000000000000000010721354547546400177370ustar00rootroot00000000000000 rostime 0.6.13 Time and Duration implementations for C++ libraries, including roscpp. Dirk Thomas BSD http://ros.org/wiki/rostime Josh Faust catkin boost cpp_common boost cpp_common roscpp_core-0.6.13/rostime/src/000077500000000000000000000000001354547546400164115ustar00rootroot00000000000000roscpp_core-0.6.13/rostime/src/duration.cpp000066400000000000000000000056041354547546400207470ustar00rootroot00000000000000/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2010, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include #include namespace ros { Duration::Duration(const Rate& rate) : DurationBase(rate.expectedCycleTime().sec, rate.expectedCycleTime().nsec) { } WallDuration::WallDuration(const Rate& rate) : DurationBase(rate.expectedCycleTime().sec, rate.expectedCycleTime().nsec) { } void normalizeSecNSecSigned(int64_t& sec, int64_t& nsec) { int64_t nsec_part = nsec % 1000000000L; int64_t sec_part = sec + nsec / 1000000000L; if (nsec_part < 0) { nsec_part += 1000000000L; --sec_part; } if (sec_part < std::numeric_limits::min() || sec_part > std::numeric_limits::max()) throw std::runtime_error("Duration is out of dual 32-bit range"); sec = sec_part; nsec = nsec_part; } void normalizeSecNSecSigned(int32_t& sec, int32_t& nsec) { int64_t sec64 = sec; int64_t nsec64 = nsec; normalizeSecNSecSigned(sec64, nsec64); sec = (int32_t)sec64; nsec = (int32_t)nsec64; } template class DurationBase; template class DurationBase; } roscpp_core-0.6.13/rostime/src/rate.cpp000066400000000000000000000105601354547546400200520ustar00rootroot00000000000000/********************************************************************* * * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * Author: Eitan Marder-Eppstein *********************************************************************/ #include namespace ros { Rate::Rate(double frequency) : start_(Time::now()) , expected_cycle_time_(1.0 / frequency) , actual_cycle_time_(0.0) { } Rate::Rate(const Duration& d) : start_(Time::now()) , expected_cycle_time_(d.sec, d.nsec) , actual_cycle_time_(0.0) { } bool Rate::sleep() { Time expected_end = start_ + expected_cycle_time_; Time actual_end = Time::now(); // detect backward jumps in time if (actual_end < start_) { expected_end = actual_end + expected_cycle_time_; } //calculate the time we'll sleep for Duration sleep_time = expected_end - actual_end; //set the actual amount of time the loop took in case the user wants to know actual_cycle_time_ = actual_end - start_; //make sure to reset our start time start_ = expected_end; //if we've taken too much time we won't sleep if(sleep_time <= Duration(0.0)) { // if we've jumped forward in time, or the loop has taken more than a full extra // cycle, reset our cycle if (actual_end > expected_end + expected_cycle_time_) { start_ = actual_end; } // return false to show that the desired rate was not met return false; } return sleep_time.sleep(); } void Rate::reset() { start_ = Time::now(); } Duration Rate::cycleTime() const { return actual_cycle_time_; } WallRate::WallRate(double frequency) : start_(WallTime::now()) , expected_cycle_time_(1.0 / frequency) , actual_cycle_time_(0.0) {} WallRate::WallRate(const Duration& d) : start_(WallTime::now()) , expected_cycle_time_(d.sec, d.nsec) , actual_cycle_time_(0.0) {} bool WallRate::sleep() { WallTime expected_end = start_ + expected_cycle_time_; WallTime actual_end = WallTime::now(); // detect backward jumps in time if (actual_end < start_) { expected_end = actual_end + expected_cycle_time_; } //calculate the time we'll sleep for WallDuration sleep_time = expected_end - actual_end; //set the actual amount of time the loop took in case the user wants to know actual_cycle_time_ = actual_end - start_; //make sure to reset our start time start_ = expected_end; //if we've taken too much time we won't sleep if(sleep_time <= WallDuration(0.0)) { // if we've jumped forward in time, or the loop has taken more than a full extra // cycle, reset our cycle if (actual_end > expected_end + expected_cycle_time_) { start_ = actual_end; } return false; } return sleep_time.sleep(); } void WallRate::reset() { start_ = WallTime::now(); } WallDuration WallRate::cycleTime() const { return actual_cycle_time_; } } roscpp_core-0.6.13/rostime/src/time.cpp000066400000000000000000000410011354547546400200470ustar00rootroot00000000000000/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2010, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifdef _MSC_VER #ifndef NOMINMAX #define NOMINMAX #endif #endif #include "ros/time.h" #include "ros/impl/time.h" #include #include #include #include #include // time related includes for macOS #if defined(__APPLE__) #include #include #endif // defined(__APPLE__) #ifdef _WINDOWS #include #include #include #endif #include #include #include /********************************************************************* ** Preprocessor *********************************************************************/ // Could probably do some better and more elaborate checking // and definition here. #define HAS_CLOCK_GETTIME (_POSIX_C_SOURCE >= 199309L) /********************************************************************* ** Namespaces *********************************************************************/ namespace ros { /********************************************************************* ** Variables *********************************************************************/ const Duration DURATION_MAX(std::numeric_limits::max(), 999999999); const Duration DURATION_MIN(std::numeric_limits::min(), 0); const Time TIME_MAX(std::numeric_limits::max(), 999999999); const Time TIME_MIN(0, 1); // This is declared here because it's set from the Time class but read from // the Duration class, and need not be exported to users of either. static bool g_stopped(false); // I assume that this is declared here, instead of time.h, to keep users // of time.h from including boost/thread/mutex.hpp static boost::mutex g_sim_time_mutex; static bool g_initialized(false); static bool g_use_sim_time(true); static Time g_sim_time(0, 0); /********************************************************************* ** Cross Platform Functions *********************************************************************/ void ros_walltime(uint32_t& sec, uint32_t& nsec) { #if !defined(_WIN32) #if HAS_CLOCK_GETTIME timespec start; clock_gettime(CLOCK_REALTIME, &start); if (start.tv_sec < 0 || start.tv_sec > std::numeric_limits::max()) throw std::runtime_error("Timespec is out of dual 32-bit range"); sec = start.tv_sec; nsec = start.tv_nsec; #else struct timeval timeofday; gettimeofday(&timeofday,NULL); if (timeofday.tv_sec < 0 || timeofday.tv_sec > std::numeric_limits::max()) throw std::runtime_error("Timeofday is out of dual signed 32-bit range"); sec = timeofday.tv_sec; nsec = timeofday.tv_usec * 1000; #endif #else // Win32 implementation // unless I've missed something obvious, the only way to get high-precision // time on Windows is via the QueryPerformanceCounter() call. However, // this is somewhat problematic in Windows XP on some processors, especially // AMD, because the Windows implementation can freak out when the CPU clocks // down to save power. Time can jump or even go backwards. Microsoft has // fixed this bug for most systems now, but it can still show up if you have // not installed the latest CPU drivers (an oxymoron). They fixed all these // problems in Windows Vista, and this API is by far the most accurate that // I know of in Windows, so I'll use it here despite all these caveats static LARGE_INTEGER cpu_freq, init_cpu_time; static uint32_t start_sec = 0; static uint32_t start_nsec = 0; if ( ( start_sec == 0 ) && ( start_nsec == 0 ) ) { QueryPerformanceFrequency(&cpu_freq); if (cpu_freq.QuadPart == 0) { throw NoHighPerformanceTimersException(); } QueryPerformanceCounter(&init_cpu_time); // compute an offset from the Epoch using the lower-performance timer API FILETIME ft; GetSystemTimeAsFileTime(&ft); LARGE_INTEGER start_li; start_li.LowPart = ft.dwLowDateTime; start_li.HighPart = ft.dwHighDateTime; // why did they choose 1601 as the time zero, instead of 1970? // there were no outstanding hard rock bands in 1601. #ifdef _MSC_VER start_li.QuadPart -= 116444736000000000Ui64; #else start_li.QuadPart -= 116444736000000000ULL; #endif int64_t start_sec64 = start_li.QuadPart / 10000000; // 100-ns units if (start_sec64 < 0 || start_sec64 > std::numeric_limits::max()) throw std::runtime_error("SystemTime is out of dual 32-bit range"); start_sec = (uint32_t)start_sec64; start_nsec = (start_li.LowPart % 10000000) * 100; } LARGE_INTEGER cur_time; QueryPerformanceCounter(&cur_time); LARGE_INTEGER delta_cpu_time; delta_cpu_time.QuadPart = cur_time.QuadPart - init_cpu_time.QuadPart; // todo: how to handle cpu clock drift. not sure it's a big deal for us. // also, think about clock wraparound. seems extremely unlikey, but possible double d_delta_cpu_time = delta_cpu_time.QuadPart / (double) cpu_freq.QuadPart; uint32_t delta_sec = (uint32_t) floor(d_delta_cpu_time); uint32_t delta_nsec = (uint32_t) boost::math::round((d_delta_cpu_time-delta_sec) * 1e9); int64_t sec_sum = (int64_t)start_sec + (int64_t)delta_sec; int64_t nsec_sum = (int64_t)start_nsec + (int64_t)delta_nsec; // Throws an exception if we go out of 32-bit range normalizeSecNSecUnsigned(sec_sum, nsec_sum); sec = sec_sum; nsec = nsec_sum; #endif } void ros_steadytime(uint32_t& sec, uint32_t& nsec) { #if !defined(_WIN32) timespec start; #if defined(__APPLE__) // On macOS use clock_get_time. clock_serv_t cclock; mach_timespec_t mts; host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); clock_get_time(cclock, &mts); mach_port_deallocate(mach_task_self(), cclock); start.tv_sec = mts.tv_sec; start.tv_nsec = mts.tv_nsec; #else // defined(__APPLE__) // Otherwise use clock_gettime. clock_gettime(CLOCK_MONOTONIC, &start); #endif // defined(__APPLE__) sec = start.tv_sec; nsec = start.tv_nsec; #else static LARGE_INTEGER cpu_frequency, performance_count; // These should not ever fail since XP is already end of life: // From https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx and // https://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx: // "On systems that run Windows XP or later, the function will always succeed and will // thus never return zero." QueryPerformanceFrequency(&cpu_frequency); if (cpu_frequency.QuadPart == 0) { throw NoHighPerformanceTimersException(); } QueryPerformanceCounter(&performance_count); double steady_time = performance_count.QuadPart / (double) cpu_frequency.QuadPart; int64_t steady_sec = floor(steady_time); int64_t steady_nsec = boost::math::round((steady_time - steady_sec) * 1e9); // Throws an exception if we go out of 32-bit range normalizeSecNSecUnsigned(steady_sec, steady_nsec); sec = steady_sec; nsec = steady_nsec; #endif } /* * These have only internal linkage to this translation unit. * (i.e. not exposed to users of the time classes) */ /** * @brief Simple representation of the rt library nanosleep function. */ int ros_nanosleep(const uint32_t &sec, const uint32_t &nsec) { #if defined(_WIN32) std::this_thread::sleep_for(std::chrono::nanoseconds(static_cast(sec * 1e9 + nsec))); return 0; #else timespec req = { sec, nsec }; return nanosleep(&req, NULL); #endif } /** * @brief Go to the wall! * * @todo Fully implement the win32 parts, currently just like a regular sleep. */ bool ros_wallsleep(uint32_t sec, uint32_t nsec) { #if defined(_WIN32) ros_nanosleep(sec,nsec); #else timespec req = { sec, nsec }; timespec rem = {0, 0}; while (nanosleep(&req, &rem) && !g_stopped) { req = rem; } #endif return !g_stopped; } /********************************************************************* ** Class Methods *********************************************************************/ bool Time::useSystemTime() { return !g_use_sim_time; } bool Time::isSimTime() { return g_use_sim_time; } bool Time::isSystemTime() { return !isSimTime(); } Time Time::now() { if (!g_initialized) { throw TimeNotInitializedException(); } if (g_use_sim_time) { boost::mutex::scoped_lock lock(g_sim_time_mutex); Time t = g_sim_time; return t; } Time t; ros_walltime(t.sec, t.nsec); return t; } void Time::setNow(const Time& new_now) { boost::mutex::scoped_lock lock(g_sim_time_mutex); g_sim_time = new_now; g_use_sim_time = true; } void Time::init() { g_stopped = false; g_use_sim_time = false; g_initialized = true; } void Time::shutdown() { g_stopped = true; } bool Time::isValid() { return (!g_use_sim_time) || !g_sim_time.isZero(); } bool Time::waitForValid() { return waitForValid(ros::WallDuration()); } bool Time::waitForValid(const ros::WallDuration& timeout) { ros::WallTime start = ros::WallTime::now(); while (!isValid() && !g_stopped) { ros::WallDuration(0.01).sleep(); if (timeout > ros::WallDuration(0, 0) && (ros::WallTime::now() - start > timeout)) { return false; } } if (g_stopped) { return false; } return true; } Time Time::fromBoost(const boost::posix_time::ptime& t) { boost::posix_time::time_duration diff = t - boost::posix_time::from_time_t(0); return Time::fromBoost(diff); } Time Time::fromBoost(const boost::posix_time::time_duration& d) { Time t; int64_t sec64 = d.total_seconds(); if (sec64 < 0 || sec64 > std::numeric_limits::max()) throw std::runtime_error("time_duration is out of dual 32-bit range"); t.sec = (uint32_t)sec64; #if defined(BOOST_DATE_TIME_HAS_NANOSECONDS) t.nsec = d.fractional_seconds(); #else t.nsec = d.fractional_seconds()*1000; #endif return t; } std::ostream& operator<<(std::ostream& os, const Time &rhs) { boost::io::ios_all_saver s(os); os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec; return os; } std::ostream& operator<<(std::ostream& os, const Duration& rhs) { boost::io::ios_all_saver s(os); if (rhs.sec >= 0 || rhs.nsec == 0) { os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec; } else { os << (rhs.sec == -1 ? "-" : "") << (rhs.sec + 1) << "." << std::setw(9) << std::setfill('0') << (1000000000 - rhs.nsec); } return os; } bool Time::sleepUntil(const Time& end) { if (Time::useSystemTime()) { Duration d(end - Time::now()); if (d > Duration(0)) { return d.sleep(); } return true; } else { Time start = Time::now(); while (!g_stopped && (Time::now() < end)) { ros_nanosleep(0,1000000); if (Time::now() < start) { return false; } } return true; } } bool WallTime::sleepUntil(const WallTime& end) { WallDuration d(end - WallTime::now()); if (d > WallDuration(0)) { return d.sleep(); } return true; } bool SteadyTime::sleepUntil(const SteadyTime& end) { WallDuration d(end - SteadyTime::now()); if (d > WallDuration(0)) { return d.sleep(); } return true; } bool Duration::sleep() const { if (Time::useSystemTime()) { return ros_wallsleep(sec, nsec); } else { Time start = Time::now(); Time end = start + *this; if (start.isZero()) { end = TIME_MAX; } bool rc = false; while (!g_stopped && (Time::now() < end)) { ros_wallsleep(0, 1000000); rc = true; // If we started at time 0 wait for the first actual time to arrive before starting the timer on // our sleep if (start.isZero()) { start = Time::now(); end = start + *this; } // If time jumped backwards from when we started sleeping, return immediately if (Time::now() < start) { return false; } } return rc && !g_stopped; } } std::ostream &operator<<(std::ostream& os, const WallTime &rhs) { boost::io::ios_all_saver s(os); os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec; return os; } std::ostream &operator<<(std::ostream& os, const SteadyTime &rhs) { boost::io::ios_all_saver s(os); os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec; return os; } WallTime WallTime::now() { WallTime t; ros_walltime(t.sec, t.nsec); return t; } SteadyTime SteadyTime::now() { SteadyTime t; ros_steadytime(t.sec, t.nsec); return t; } std::ostream &operator<<(std::ostream& os, const WallDuration& rhs) { boost::io::ios_all_saver s(os); if (rhs.sec >= 0 || rhs.nsec == 0) { os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec; } else { os << (rhs.sec == -1 ? "-" : "") << (rhs.sec + 1) << "." << std::setw(9) << std::setfill('0') << (1000000000 - rhs.nsec); } return os; } bool WallDuration::sleep() const { return ros_wallsleep(sec, nsec); } void normalizeSecNSec(uint64_t& sec, uint64_t& nsec) { uint64_t nsec_part = nsec % 1000000000UL; uint64_t sec_part = nsec / 1000000000UL; if (sec + sec_part > std::numeric_limits::max()) throw std::runtime_error("Time is out of dual 32-bit range"); sec += sec_part; nsec = nsec_part; } void normalizeSecNSec(uint32_t& sec, uint32_t& nsec) { uint64_t sec64 = sec; uint64_t nsec64 = nsec; normalizeSecNSec(sec64, nsec64); sec = (uint32_t)sec64; nsec = (uint32_t)nsec64; } void normalizeSecNSecUnsigned(int64_t& sec, int64_t& nsec) { int64_t nsec_part = nsec % 1000000000L; int64_t sec_part = sec + nsec / 1000000000L; if (nsec_part < 0) { nsec_part += 1000000000L; --sec_part; } if (sec_part < 0 || sec_part > std::numeric_limits::max()) throw std::runtime_error("Time is out of dual 32-bit range"); sec = sec_part; nsec = nsec_part; } template class TimeBase; template class TimeBase; template class TimeBase; } roscpp_core-0.6.13/rostime/test/000077500000000000000000000000001354547546400166015ustar00rootroot00000000000000roscpp_core-0.6.13/rostime/test/duration.cpp000066400000000000000000000124521354547546400211360ustar00rootroot00000000000000/* * Copyright (c) 2016, Open Source Robotics Foundation, Inc.. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include #include #include using namespace ros; TEST(Duration, sleepWithSimTime) { ros::Time::init(); Time start = Time::now(); start -= Duration(2.0); Time::setNow(start); Time::shutdown(); Duration d(1.0); bool rc = d.sleep(); ASSERT_FALSE(rc); } TEST(Duration, castFromDoubleExceptions) { ros::Time::init(); Duration d1, d2, d3, d4; // Valid values to cast, must not throw exceptions EXPECT_NO_THROW(d1.fromSec(-2147483648.0)); EXPECT_NO_THROW(d2.fromSec(-2147483647.999999)); EXPECT_NO_THROW(d3.fromSec(2147483647.0)); EXPECT_NO_THROW(d4.fromSec(2147483647.999999)); // The next casts all incorrect. EXPECT_THROW(d1.fromSec(2147483648.0), std::runtime_error); EXPECT_THROW(d2.fromSec(6442450943.0), std::runtime_error); // It's 2^31 - 1 + 2^32, and it could pass the test. EXPECT_THROW(d3.fromSec(-2147483648.001), std::runtime_error); EXPECT_THROW(d4.fromSec(-6442450943.0), std::runtime_error); } TEST(Duration, castFromInt64Exceptions) { ros::Time::init(); Duration d1, d2, d3, d4; // Valid values to cast, must not throw exceptions EXPECT_NO_THROW(d1.fromNSec(-2147483648000000000)); EXPECT_NO_THROW(d2.fromNSec(-2147483647999999999)); EXPECT_NO_THROW(d3.fromNSec(2147483647000000000)); EXPECT_NO_THROW(d4.fromNSec(2147483647999999999)); // The next casts all incorrect. EXPECT_THROW(d1.fromSec(2147483648000000000), std::runtime_error); EXPECT_THROW(d2.fromSec(4294967296000000000), std::runtime_error); EXPECT_THROW(d3.fromSec(-2147483648000000001), std::runtime_error); EXPECT_THROW(d4.fromSec(-6442450943000000000), std::runtime_error); } TEST(Duration, arithmeticExceptions) { ros::Time::init(); Duration d1(2147483647, 0); Duration d2(2147483647, 999999999); EXPECT_THROW(d1 + d2, std::runtime_error); Duration d3(-2147483648, 0); Duration d4(2147483647, 0); EXPECT_THROW(d3 - d4, std::runtime_error); EXPECT_THROW(d4 - d3, std::runtime_error); Duration d5(-2147483647, 1); Duration d6(-2, 999999999); Duration d7; EXPECT_NO_THROW(d7 = d5 + d6); EXPECT_EQ(-2147483648000000000, d7.toNSec()); } TEST(Duration, negativeSignExceptions) { ros::Time::init(); Duration d1(2147483647, 0); Duration d2(2147483647, 999999999); Duration d3; EXPECT_NO_THROW(d3 = -d1); EXPECT_EQ(-2147483647000000000, d3.toNSec()); EXPECT_NO_THROW(d3 = -d2); EXPECT_EQ(-2147483647999999999, d3.toNSec()); Duration d4(-2147483647, 0); Duration d5(-2147483648, 999999999); Duration d6(-2147483648, 2); Duration d7; EXPECT_NO_THROW(d7 = -d4); EXPECT_EQ(2147483647000000000, d7.toNSec()); EXPECT_NO_THROW(d7 = -d5); EXPECT_EQ(2147483647000000001, d7.toNSec()); EXPECT_NO_THROW(d7 = -d6); EXPECT_EQ(2147483647999999998, d7.toNSec()); } TEST(Duration, rounding) { ros::Time::init(); Duration d1(49.0000000004); EXPECT_EQ(49, d1.sec); EXPECT_EQ(0, d1.nsec); Duration d2(-49.0000000004); EXPECT_EQ(-49, d2.sec); EXPECT_EQ(0, d2.nsec); Duration d3(49.0000000006); EXPECT_EQ(49, d3.sec); EXPECT_EQ(1, d3.nsec); Duration d4(-49.0000000006); EXPECT_EQ(-50, d4.sec); EXPECT_EQ(999999999, d4.nsec); Duration d5(49.9999999994); EXPECT_EQ(49, d5.sec); EXPECT_EQ(999999999, d5.nsec); Duration d6(-49.9999999994); EXPECT_EQ(-50, d6.sec); EXPECT_EQ(1, d6.nsec); Duration d7(49.9999999996); EXPECT_EQ(50, d7.sec); EXPECT_EQ(0, d7.nsec); Duration d8(-49.9999999996); EXPECT_EQ(-50, d8.sec); EXPECT_EQ(0, d8.nsec); } int main(int argc, char **argv){ testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } roscpp_core-0.6.13/rostime/test/time.cpp000066400000000000000000000370671354547546400202600ustar00rootroot00000000000000/* * Copyright (c) 2008, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #if !defined(_WIN32) #include #endif #include using namespace ros; /// \todo All the tests in here that use randomized values are not unit tests, replace them double epsilon = 1e-9; void seed_rand() { //Seed random number generator with current microseond count #if !defined(_WIN32) timeval temp_time_struct; gettimeofday(&temp_time_struct,NULL); srand(temp_time_struct.tv_usec); #else srand(time(nullptr)); #endif }; void generate_rand_times(uint32_t range, uint64_t runs, std::vector& values1, std::vector& values2) { seed_rand(); values1.clear(); values2.clear(); values1.reserve(runs); values2.reserve(runs); for ( uint32_t i = 0; i < runs ; i++ ) { values1.push_back(ros::Time( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX))); values2.push_back(ros::Time( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX))); } } void generate_rand_durations(uint32_t range, uint64_t runs, std::vector& values1, std::vector& values2) { seed_rand(); values1.clear(); values2.clear(); values1.reserve(runs * 4); values2.reserve(runs * 4); for ( uint32_t i = 0; i < runs ; i++ ) { // positive durations values1.push_back(ros::Duration( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX))); values2.push_back(ros::Duration( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX))); EXPECT_GE(values1.back(), ros::Duration(0,0)); EXPECT_GE(values2.back(), ros::Duration(0,0)); // negative durations values1.push_back(ros::Duration( -(rand() * range / RAND_MAX), -(rand() * 1000000000ULL/RAND_MAX))); values2.push_back(ros::Duration( -(rand() * range / RAND_MAX), -(rand() * 1000000000ULL/RAND_MAX))); EXPECT_LE(values1.back(), ros::Duration(0,0)); EXPECT_LE(values2.back(), ros::Duration(0,0)); // positive and negative durations values1.push_back(ros::Duration( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX))); values2.push_back(ros::Duration( -(rand() * range / RAND_MAX), -(rand() * 1000000000ULL/RAND_MAX))); EXPECT_GE(values1.back(), ros::Duration(0,0)); EXPECT_LE(values2.back(), ros::Duration(0,0)); // negative and positive durations values1.push_back(ros::Duration( -(rand() * range / RAND_MAX), -(rand() * 1000000000ULL/RAND_MAX))); values2.push_back(ros::Duration( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX))); EXPECT_LE(values1.back(), ros::Duration(0,0)); EXPECT_GE(values2.back(), ros::Duration(0,0)); } } TEST(Time, size) { ASSERT_EQ(sizeof(Time), 8); ASSERT_EQ(sizeof(Duration), 8); } TEST(Time, Comparitors) { std::vector v1; std::vector v2; generate_rand_times(100, 1000, v1,v2); for (uint32_t i = 0; i < v1.size(); i++) { if (v1[i].sec * 1000000000ULL + v1[i].nsec < v2[i].sec * 1000000000ULL + v2[i].nsec) { EXPECT_LT(v1[i], v2[i]); // printf("%f %d ", v1[i].toSec(), v1[i].sec * 1000000000ULL + v1[i].nsec); //printf("vs %f %d\n", v2[i].toSec(), v2[i].sec * 1000000000ULL + v2[i].nsec); EXPECT_LE(v1[i], v2[i]); EXPECT_NE(v1[i], v2[i]); } else if (v1[i].sec * 1000000000ULL + v1[i].nsec > v2[i].sec * 1000000000ULL + v2[i].nsec) { EXPECT_GT(v1[i], v2[i]); EXPECT_GE(v1[i], v2[i]); EXPECT_NE(v1[i], v2[i]); } else { EXPECT_EQ(v1[i], v2[i]); EXPECT_LE(v1[i], v2[i]); EXPECT_GE(v1[i], v2[i]); } } } TEST(Time, ToFromDouble) { std::vector v1; std::vector v2; generate_rand_times(100, 1000, v1,v2); for (uint32_t i = 0; i < v1.size(); i++) { EXPECT_EQ(v1[i].toSec(), v1[i].fromSec(v1[i].toSec()).toSec()); } } TEST(Time, RoundingError) { double someInt = 1031.0; // some integer double t = std::nextafter(someInt, 0); // someint - epsilon // t should be 1031.000000 ros::Time exampleTime; exampleTime.fromSec(t); // if rounded incorrectly, sec may be 1030 // and nsec may be 1e9. EXPECT_EQ(exampleTime.sec, 1031); EXPECT_EQ(exampleTime.nsec, 0); } TEST(Time, OperatorPlus) { Time t(100, 0); Duration d(100, 0); Time r = t + d; EXPECT_EQ(r.sec, 200UL); EXPECT_EQ(r.nsec, 0UL); t = Time(0, 100000UL); d = Duration(0, 100UL); r = t + d; EXPECT_EQ(r.sec, 0UL); EXPECT_EQ(r.nsec, 100100UL); t = Time(0, 0); d = Duration(10, 2000003000UL); r = t + d; EXPECT_EQ(r.sec, 12UL); EXPECT_EQ(r.nsec, 3000UL); } TEST(Time, OperatorMinus) { Time t(100, 0); Duration d(100, 0); Time r = t - d; EXPECT_EQ(r.sec, 0UL); EXPECT_EQ(r.nsec, 0UL); t = Time(0, 100000UL); d = Duration(0, 100UL); r = t - d; EXPECT_EQ(r.sec, 0UL); EXPECT_EQ(r.nsec, 99900UL); t = Time(30, 0); d = Duration(10, 2000003000UL); r = t - d; EXPECT_EQ(r.sec, 17UL); EXPECT_EQ(r.nsec, 999997000ULL); } TEST(Time, OperatorPlusEquals) { Time t(100, 0); Duration d(100, 0); t += d; EXPECT_EQ(t.sec, 200UL); EXPECT_EQ(t.nsec, 0UL); t = Time(0, 100000UL); d = Duration(0, 100UL); t += d; EXPECT_EQ(t.sec, 0UL); EXPECT_EQ(t.nsec, 100100UL); t = Time(0, 0); d = Duration(10, 2000003000UL); t += d; EXPECT_EQ(t.sec, 12UL); EXPECT_EQ(t.nsec, 3000UL); } TEST(Time, OperatorMinusEquals) { Time t(100, 0); Duration d(100, 0); t -= d; EXPECT_EQ(t.sec, 0UL); EXPECT_EQ(t.nsec, 0UL); t = Time(0, 100000UL); d = Duration(0, 100UL); t -= d; EXPECT_EQ(t.sec, 0UL); EXPECT_EQ(t.nsec, 99900UL); t = Time(30, 0); d = Duration(10, 2000003000UL); t -= d; EXPECT_EQ(t.sec, 17UL); EXPECT_EQ(t.nsec, 999997000ULL); } TEST(Time, SecNSecConstructor) { Time t(100, 2000003000UL); EXPECT_EQ(t.sec, 102UL); EXPECT_EQ(t.nsec, 3000UL); } TEST(Time, DontMungeStreamState) { std::ostringstream oss; Time t(100, 2000003000UL); oss << std::setfill('N'); oss << std::setw(13); oss << t; EXPECT_EQ(oss.width(), 13); EXPECT_EQ(oss.fill(), 'N'); } TEST(Time, ToFromBoost) { std::vector v1; std::vector v2; generate_rand_times(100, 1000, v1,v2); for (uint32_t i = 0; i < v1.size(); i++) { Time t = v1[i]; // dont assume that nanosecond are available t.nsec = uint32_t(t.nsec / 1000.0) * 1000; boost::posix_time::ptime b = t.toBoost(); Time tt = Time::fromBoost(b); EXPECT_EQ(t, tt); } } TEST(Time, CastFromDoubleExceptions) { ros::Time::init(); Time t1, t2, t3; // Valid values to cast, must not throw exceptions EXPECT_NO_THROW(t1.fromSec(4294967295.0)); EXPECT_NO_THROW(t2.fromSec(4294967295.999)); EXPECT_NO_THROW(t3.fromSec(0.0000001)); // The next casts all incorrect. EXPECT_THROW(t1.fromSec(4294967296.0), std::runtime_error); EXPECT_THROW(t2.fromSec(-0.0001), std::runtime_error); EXPECT_THROW(t3.fromSec(-4294967296.0), std::runtime_error); } TEST(Time, OperatorMinusExceptions) { ros::Time::init(); Time t1(2147483648, 0); Time t2(2147483647, 999999999); Time t3(2147483647, 999999998); Time t4(4294967295, 999999999); Time t5(4294967295, 999999998); Time t6(0, 1); Duration d1(2147483647, 999999999); Duration d2(-2147483648, 0); Duration d3(-2147483648, 1); Duration d4(0, 1); EXPECT_NO_THROW(t1 - t2); EXPECT_NO_THROW(t3 - t2); EXPECT_NO_THROW(t4 - t5); EXPECT_NO_THROW(t1 - d1); EXPECT_NO_THROW(t5 - d1); EXPECT_THROW(t4 - t6, std::runtime_error); EXPECT_THROW(t4 - t3, std::runtime_error); EXPECT_THROW(t1 - d2, std::runtime_error); EXPECT_THROW(t2 - d2, std::runtime_error); EXPECT_THROW(t4 - d3, std::runtime_error); } TEST(Time, OperatorPlusExceptions) { ros::Time::init(); Time t1(2147483648, 0); Time t2(2147483647, 999999999); Time t4(4294967295, 999999999); Time t5(4294967295, 999999998); Duration d1(2147483647, 999999999); Duration d2(-2147483648, 1); Duration d3(0, 2); Duration d4(0, 1); EXPECT_NO_THROW(t2 + d2); EXPECT_NO_THROW(t1 + d1); EXPECT_THROW(t4 + d4, std::runtime_error); EXPECT_THROW(t4 + d1, std::runtime_error); EXPECT_THROW(t5 + d3, std::runtime_error); } /************************************* Duration Tests *****************/ TEST(Duration, Comparitors) { std::vector v1; std::vector v2; generate_rand_durations(100, 1000, v1,v2); for (uint32_t i = 0; i < v1.size(); i++) { if (v1[i].sec * 1000000000LL + v1[i].nsec < v2[i].sec * 1000000000LL + v2[i].nsec) { EXPECT_LT(v1[i], v2[i]); // printf("%f %lld ", v1[i].toSec(), v1[i].sec * 1000000000LL + v1[i].nsec); // printf("vs %f %lld\n", v2[i].toSec(), v2[i].sec * 1000000000LL + v2[i].nsec); EXPECT_LE(v1[i], v2[i]); EXPECT_NE(v1[i], v2[i]); } else if (v1[i].sec * 1000000000LL + v1[i].nsec > v2[i].sec * 1000000000LL + v2[i].nsec) { EXPECT_GT(v1[i], v2[i]); // printf("%f %lld ", v1[i].toSec(), v1[i].sec * 1000000000LL + v1[i].nsec); // printf("vs %f %lld\n", v2[i].toSec(), v2[i].sec * 1000000000LL + v2[i].nsec); EXPECT_GE(v1[i], v2[i]); EXPECT_NE(v1[i], v2[i]); } else { EXPECT_EQ(v1[i], v2[i]); EXPECT_LE(v1[i], v2[i]); EXPECT_GE(v1[i], v2[i]); } } } TEST(Duration, ToFromSec) { std::vector v1; std::vector v2; generate_rand_durations(100, 1000, v1,v2); for (uint32_t i = 0; i < v1.size(); i++) { EXPECT_EQ(v1[i].toSec(), v1[i].fromSec(v1[i].toSec()).toSec()); EXPECT_GE(ros::Duration(v1[i].toSec()).nsec, 0); } EXPECT_EQ(ros::Duration(-0.5), ros::Duration(-1LL, 500000000LL)); EXPECT_EQ(ros::Duration(-0.5), ros::Duration(0, -500000000LL)); } TEST(Duration, FromNSec) { ros::Duration t; t.fromNSec(-500000000LL); EXPECT_EQ(ros::Duration(-0.5), t); t.fromNSec(-1500000000LL); EXPECT_EQ(ros::Duration(-1.5), t); t.fromNSec(500000000LL); EXPECT_EQ(ros::Duration(0.5), t); t.fromNSec(1500000000LL); EXPECT_EQ(ros::Duration(1.5), t); } TEST(Duration, OperatorPlus) { std::vector v1; std::vector v2; generate_rand_durations(100, 1000, v1,v2); for (uint32_t i = 0; i < v1.size(); i++) { EXPECT_NEAR(v1[i].toSec() + v2[i].toSec(), (v1[i] + v2[i]).toSec(), epsilon); ros::Duration temp = v1[i]; EXPECT_NEAR(v1[i].toSec() + v2[i].toSec(), (temp += v2[i]).toSec(), epsilon); } } TEST(Duration, OperatorMinus) { std::vector v1; std::vector v2; generate_rand_durations(100, 1000, v1,v2); for (uint32_t i = 0; i < v1.size(); i++) { EXPECT_NEAR(v1[i].toSec() - v2[i].toSec(), (v1[i] - v2[i]).toSec(), epsilon); ros::Duration temp = v1[i]; EXPECT_NEAR(v1[i].toSec() - v2[i].toSec(), (temp -= v2[i]).toSec(), epsilon); EXPECT_NEAR(- v2[i].toSec(), (-v2[i]).toSec(), epsilon); } ros::Time t1(1.1); ros::Time t2(1.3); ros::Duration time_diff = t1 - t2; //=-0.2 EXPECT_NEAR(time_diff.toSec(), -0.2, epsilon); EXPECT_LE(time_diff, ros::Duration(-0.19)); EXPECT_GE(time_diff, ros::Duration(-0.21)); } TEST(Duration, OperatorTimes) { std::vector v1; std::vector v2; generate_rand_durations(100, 1000, v1,v2); for (uint32_t i = 0; i < v1.size(); i++) { EXPECT_NEAR(v1[i].toSec() * v2[i].toSec(), (v1[i] * v2[i].toSec()).toSec(), epsilon); ros::Duration temp = v1[i]; EXPECT_NEAR(v1[i].toSec() * v2[i].toSec(), (temp *= v2[i].toSec()).toSec(), epsilon); } } TEST(Duration, OperatorPlusEquals) { Duration t(100, 0); Duration d(100, 0); t += d; EXPECT_EQ(t.sec, 200L); EXPECT_EQ(t.nsec, 0L); t = Duration(0, 100000L); d = Duration(0, 100L); t += d; EXPECT_EQ(t.sec, 0L); EXPECT_EQ(t.nsec, 100100L); t = Duration(0, 0); d = Duration(10, 2000003000L); t += d; EXPECT_EQ(t.sec, 12L); EXPECT_EQ(t.nsec, 3000L); } TEST(Duration, OperatorMinusEquals) { Duration t(100, 0); Duration d(100, 0); t -= d; EXPECT_EQ(t.sec, 0L); EXPECT_EQ(t.nsec, 0L); t = Duration(0, 100000L); d = Duration(0, 100L); t -= d; EXPECT_EQ(t.sec, 0L); EXPECT_EQ(t.nsec, 99900L); t = Duration(30, 0); d = Duration(10, 2000003000L); t -= d; EXPECT_EQ(t.sec, 17L); EXPECT_EQ(t.nsec, 999997000L); } void alarmHandler(int sig) { } TEST(Duration, sleepWithSignal) { #if !defined(_WIN32) signal(SIGALRM, alarmHandler); alarm(1); #endif Time start = Time::now(); Duration d(2.0); bool rc = d.sleep(); Time end = Time::now(); ASSERT_GT(end - start, d); ASSERT_TRUE(rc); } TEST(Rate, constructFromDuration){ Duration d(4, 0); Rate r(d); EXPECT_EQ(r.expectedCycleTime(), d); } TEST(Rate, sleep_return_value_true){ Rate r(Duration(0.2)); Duration(r.expectedCycleTime() * 0.5).sleep(); EXPECT_TRUE(r.sleep()); } TEST(Rate, sleep_return_value_false){ Rate r(Duration(0.2)); Duration(r.expectedCycleTime() * 2).sleep(); EXPECT_FALSE(r.sleep()); // requested rate cannot be achieved } TEST(WallRate, constructFromDuration){ Duration d(4, 0); WallRate r(d); WallDuration wd(4, 0); EXPECT_EQ(r.expectedCycleTime(), wd); } /////////////////////////////////////////////////////////////////////////////////// // WallTime/WallDuration /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// // SteadyTime/WallDuration /////////////////////////////////////////////////////////////////////////////////// TEST(SteadyTime, sleep){ SteadyTime start = SteadyTime::now(); WallDuration d(2.0); bool rc = d.sleep(); SteadyTime end = SteadyTime::now(); ASSERT_GT(end - start, d); ASSERT_TRUE(rc); } TEST(SteadyTime, sleepUntil){ SteadyTime start = SteadyTime::now(); SteadyTime end = start + WallDuration(2.0); bool rc = SteadyTime::sleepUntil(end); SteadyTime finished = SteadyTime::now(); ASSERT_GT(finished, end); ASSERT_TRUE(rc); } int main(int argc, char **argv){ testing::InitGoogleTest(&argc, argv); ros::Time::init(); return RUN_ALL_TESTS(); }