pax_global_header00006660000000000000000000000064132362467570014531gustar00rootroot0000000000000052 comment=379fc9fcec9501bdd1bac9dd33f1624b58487728 console-bridge-0.4.0+dfsg/000077500000000000000000000000001323624675700153455ustar00rootroot00000000000000console-bridge-0.4.0+dfsg/CMakeLists.txt000066400000000000000000000104221323624675700201040ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8.6) project(console_bridge) set (CONSOLE_BRIDGE_MAJOR_VERSION 0) set (CONSOLE_BRIDGE_MINOR_VERSION 4) set (CONSOLE_BRIDGE_PATCH_VERSION 0) set (CONSOLE_BRIDGE_VERSION ${CONSOLE_BRIDGE_MAJOR_VERSION}.${CONSOLE_BRIDGE_MINOR_VERSION}.${CONSOLE_BRIDGE_PATCH_VERSION}) message (STATUS "${PROJECT_NAME} version ${CONSOLE_BRIDGE_VERSION}") include(GNUInstallDirs) include(GenerateExportHeader) if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() # If compiler support symbol visibility, enable it. include(CheckCCompilerFlag) check_c_compiler_flag(-fvisibility=hidden HAS_VISIBILITY) if (HAS_VISIBILITY) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") endif() if(NOT WIN32) # Use c++11 compiler flag, since it's needed for console.cpp # It isn't in a header file, so it doesn't need to be exported set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CMAKE_CXX_FLAGS}") if(MSVC OR MSVC90 OR MSVC10) set(MSVC ON) endif (MSVC OR MSVC90 OR MSVC10) include_directories(include ${PROJECT_BINARY_DIR}) if(NOT DEFINED BUILD_SHARED_LIBS) option(BUILD_SHARED_LIBS "Build dynamically-linked binaries" ON) endif() # Control where libraries and executables are placed during the build set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") add_library(${PROJECT_NAME} src/console.cpp) set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${CONSOLE_BRIDGE_MAJOR_VERSION}.${CONSOLE_BRIDGE_MINOR_VERSION}) generate_export_header(${PROJECT_NAME} EXPORT_MACRO_NAME CONSOLE_BRIDGE_DLLAPI) install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h") install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) if(WIN32 AND NOT CYGWIN) set(CMAKE_CONFIG_INSTALL_DIR CMake) else() set(CMAKE_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/) endif() include(CMakePackageConfigHelpers) set(PKG_NAME ${PROJECT_NAME}) set(PKG_LIBRARIES ${PROJECT_NAME}) set(cmake_conf_file "${PROJECT_NAME}-config.cmake") configure_package_config_file("${cmake_conf_file}.in" "${CMAKE_BINARY_DIR}/${cmake_conf_file}" INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR} PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO) set(cmake_conf_version_file "${PROJECT_NAME}-config-version.cmake") # Use write_basic_package_version_file to generate a ConfigVersion file that # allow users of gazebo to specify the API or version to depend on # TODO: keep this instruction until deprecate Ubuntu/Precise and update with # https://github.com/Kitware/CMake/blob/v2.8.8/Modules/CMakePackageConfigHelpers.cmake include(WriteBasicConfigVersionFile) write_basic_config_version_file( ${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_version_file} VERSION "${CONSOLE_BRIDGE_VERSION}" COMPATIBILITY SameMajorVersion) install(EXPORT ${PROJECT_NAME}-targets FILE ${PROJECT_NAME}-targets.cmake DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}) install(FILES "${CMAKE_BINARY_DIR}/${cmake_conf_file}" "${CMAKE_BINARY_DIR}/${cmake_conf_version_file}" DESTINATION ${CMAKE_CONFIG_INSTALL_DIR} COMPONENT cmake) if (NOT MSVC) set(PKG_DESC "Console Bridge") set(PKG_CB_LIBS "-l${PROJECT_NAME}") set(pkg_conf_file "console_bridge.pc") configure_file("${pkg_conf_file}.in" "${CMAKE_BINARY_DIR}/${pkg_conf_file}" @ONLY) install(FILES "${CMAKE_BINARY_DIR}/${pkg_conf_file}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ COMPONENT pkgconfig) endif() SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/console_bridge-config.cmake ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/console_bridge.pc) enable_testing() add_subdirectory(test) console-bridge-0.4.0+dfsg/console_bridge-config.cmake.in000066400000000000000000000004241323624675700231750ustar00rootroot00000000000000if (@PKG_NAME@_CONFIG_INCLUDED) return() endif() set(@PKG_NAME@_CONFIG_INCLUDED TRUE) @PACKAGE_INIT@ set(@PKG_NAME@_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@") include("${CMAKE_CURRENT_LIST_DIR}/@PKG_NAME@-targets.cmake") set(@PKG_NAME@_LIBRARIES @PKG_NAME@) console-bridge-0.4.0+dfsg/console_bridge.pc.in000066400000000000000000000005321323624675700212540ustar00rootroot00000000000000# This file was generated by CMake for @PROJECT_NAME@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} libdir=@CMAKE_INSTALL_FULL_LIBDIR@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ Name: @PKG_NAME@ Description: @PKG_DESC@ Version: @CONSOLE_BRIDGE_VERSION@ Requires: @PKG_EXTERNAL_DEPS@ Libs: -L${libdir} @PKG_CB_LIBS@ Cflags: -I${includedir} console-bridge-0.4.0+dfsg/include/000077500000000000000000000000001323624675700167705ustar00rootroot00000000000000console-bridge-0.4.0+dfsg/include/console_bridge/000077500000000000000000000000001323624675700217465ustar00rootroot00000000000000console-bridge-0.4.0+dfsg/include/console_bridge/console.h000066400000000000000000000151551323624675700235700ustar00rootroot00000000000000/********************************************************************* * 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 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: Ryan Luna, Ioan Sucan */ #ifndef CONSOLE_BRIDGE_CONSOLE_ #define CONSOLE_BRIDGE_CONSOLE_ #include #include "console_bridge_export.h" /** \file console.h \defgroup logging Logging Macros \{ \def CONSOLE_BRIDGE_logError(fmt, ...) \brief Log a formatted error string. \remarks This macro takes the same arguments as printf. \def CONSOLE_BRIDGE_logWarn(fmt, ...) \brief Log a formatted warning string. \remarks This macro takes the same arguments as printf. \def CONSOLE_BRIDGE_logInform(fmt, ...) \brief Log a formatted information string. \remarks This macro takes the same arguments as printf. \def CONSOLE_BRIDGE_logDebug(fmt, ...) \brief Log a formatted debugging string. \remarks This macro takes the same arguments as printf. \} */ #define CONSOLE_BRIDGE_logError(fmt, ...) \ console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_ERROR, fmt, ##__VA_ARGS__) #define CONSOLE_BRIDGE_logWarn(fmt, ...) \ console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_WARN, fmt, ##__VA_ARGS__) #define CONSOLE_BRIDGE_logInform(fmt, ...) \ console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_INFO, fmt, ##__VA_ARGS__) #define CONSOLE_BRIDGE_logDebug(fmt, ...) \ console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_DEBUG, fmt, ##__VA_ARGS__) /** \brief Message namespace. This contains classes needed to output error messages (or logging) from within the library. Message logging can be performed with \ref logging "logging macros" */ namespace console_bridge { /** \brief The set of priorities for message logging */ enum CONSOLE_BRIDGE_DLLAPI LogLevel { CONSOLE_BRIDGE_LOG_DEBUG = 0, CONSOLE_BRIDGE_LOG_INFO, CONSOLE_BRIDGE_LOG_WARN, CONSOLE_BRIDGE_LOG_ERROR, CONSOLE_BRIDGE_LOG_NONE }; /** \brief Generic class to handle output from a piece of code. In order to handle output from the library in different ways, an implementation of this class needs to be provided. This instance can be set with the useOutputHandler function. */ class CONSOLE_BRIDGE_DLLAPI OutputHandler { public: OutputHandler(void) { } virtual ~OutputHandler(void) { } /** \brief log a message to the output handler with the given text and logging level from a specific file and line number */ virtual void log(const std::string &text, LogLevel level, const char *filename, int line) = 0; }; /** \brief Default implementation of OutputHandler. This sends the information to the console. */ class CONSOLE_BRIDGE_DLLAPI OutputHandlerSTD : public OutputHandler { public: OutputHandlerSTD(void) : OutputHandler() { } virtual void log(const std::string &text, LogLevel level, const char *filename, int line); }; /** \brief Implementation of OutputHandler that saves messages in a file. */ class CONSOLE_BRIDGE_DLLAPI OutputHandlerFile : public OutputHandler { public: /** \brief The name of the file in which to save the message data */ OutputHandlerFile(const char *filename); virtual ~OutputHandlerFile(void); virtual void log(const std::string &text, LogLevel level, const char *filename, int line); private: /** \brief The file to save to */ FILE *file_; }; /** \brief This function instructs ompl that no messages should be outputted. Equivalent to useOutputHandler(NULL) */ CONSOLE_BRIDGE_DLLAPI void noOutputHandler(void); /** \brief Restore the output handler that was previously in use (if any) */ CONSOLE_BRIDGE_DLLAPI void restorePreviousOutputHandler(void); /** \brief Specify the instance of the OutputHandler to use. By default, this is OutputHandlerSTD */ CONSOLE_BRIDGE_DLLAPI void useOutputHandler(OutputHandler *oh); /** \brief Get the instance of the OutputHandler currently used. This is NULL in case there is no output handler. */ CONSOLE_BRIDGE_DLLAPI OutputHandler* getOutputHandler(void); /** \brief Set the minimum level of logging data to output. Messages with lower logging levels will not be recorded. */ CONSOLE_BRIDGE_DLLAPI void setLogLevel(LogLevel level); /** \brief Retrieve the current level of logging data. Messages with lower logging levels will not be recorded. */ CONSOLE_BRIDGE_DLLAPI LogLevel getLogLevel(void); /** \brief Root level logging function. This should not be invoked directly, but rather used via a \ref logging "logging macro". Formats the message string given the arguments and forwards the string to the output handler */ CONSOLE_BRIDGE_DLLAPI void log(const char *file, int line, LogLevel level, const char* m, ...); } #endif console-bridge-0.4.0+dfsg/src/000077500000000000000000000000001323624675700161345ustar00rootroot00000000000000console-bridge-0.4.0+dfsg/src/console.cpp000066400000000000000000000134751323624675700203140ustar00rootroot00000000000000/********************************************************************* * 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 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: Ryan Luna, Ioan Sucan */ #include "console_bridge/console.h" #include #include #include #include /// @cond IGNORE struct DefaultOutputHandler { DefaultOutputHandler(void) { output_handler_ = static_cast(&std_output_handler_); previous_output_handler_ = output_handler_; logLevel_ = console_bridge::CONSOLE_BRIDGE_LOG_WARN; } console_bridge::OutputHandlerSTD std_output_handler_; console_bridge::OutputHandler *output_handler_; console_bridge::OutputHandler *previous_output_handler_; console_bridge::LogLevel logLevel_; std::mutex lock_; // it is likely the outputhandler does some I/O, so we serialize it }; // we use this function because we want to handle static initialization correctly // however, the first run of this function is not thread safe, due to the use of a static // variable inside the function. For this reason, we ensure the first call happens during // static initialization using a proxy class static DefaultOutputHandler* getDOH(void) { static DefaultOutputHandler DOH; return &DOH; } #define USE_DOH \ DefaultOutputHandler *doh = getDOH(); \ std::lock_guard lock_guard(doh->lock_) #define MAX_BUFFER_SIZE 1024 /// @endcond void console_bridge::noOutputHandler(void) { USE_DOH; doh->previous_output_handler_ = doh->output_handler_; doh->output_handler_ = NULL; } void console_bridge::restorePreviousOutputHandler(void) { USE_DOH; std::swap(doh->previous_output_handler_, doh->output_handler_); } void console_bridge::useOutputHandler(OutputHandler *oh) { USE_DOH; doh->previous_output_handler_ = doh->output_handler_; doh->output_handler_ = oh; } console_bridge::OutputHandler* console_bridge::getOutputHandler(void) { return getDOH()->output_handler_; } void console_bridge::log(const char *file, int line, LogLevel level, const char* m, ...) { USE_DOH; if (doh->output_handler_ && level >= doh->logLevel_) { va_list __ap; va_start(__ap, m); char buf[MAX_BUFFER_SIZE]; #ifdef _MSC_VER vsnprintf_s(buf, sizeof(buf), _TRUNCATE, m, __ap); #else vsnprintf(buf, sizeof(buf), m, __ap); #endif va_end(__ap); buf[MAX_BUFFER_SIZE - 1] = '\0'; doh->output_handler_->log(buf, level, file, line); } } void console_bridge::setLogLevel(LogLevel level) { USE_DOH; doh->logLevel_ = level; } console_bridge::LogLevel console_bridge::getLogLevel(void) { USE_DOH; return doh->logLevel_; } static const char* LogLevelString[4] = {"Debug: ", "Info: ", "Warning: ", "Error: "}; void console_bridge::OutputHandlerSTD::log(const std::string &text, LogLevel level, const char *filename, int line) { if (level >= CONSOLE_BRIDGE_LOG_WARN) { std::cerr << LogLevelString[level] << text << std::endl; std::cerr << " at line " << line << " in " << filename << std::endl; std::cerr.flush(); } else { std::cout << LogLevelString[level] << text << std::endl; std::cout.flush(); } } console_bridge::OutputHandlerFile::OutputHandlerFile(const char *filename) : OutputHandler() { #ifdef _MSC_VER errno_t err = fopen_s(&file_, filename, "a"); if (err != 0 || !file_) #else file_ = fopen(filename, "a"); if (!file_) #endif std::cerr << "Unable to open log file: '" << filename << "'" << std::endl; } console_bridge::OutputHandlerFile::~OutputHandlerFile(void) { if (file_) if (fclose(file_) != 0) std::cerr << "Error closing logfile" << std::endl; } void console_bridge::OutputHandlerFile::log(const std::string &text, LogLevel level, const char *filename, int line) { if (file_) { fprintf(file_, "%s%s\n", LogLevelString[level], text.c_str()); if(level >= CONSOLE_BRIDGE_LOG_WARN) fprintf(file_, " at line %d in %s\n", line, filename); fflush(file_); } } console-bridge-0.4.0+dfsg/test/000077500000000000000000000000001323624675700163245ustar00rootroot00000000000000console-bridge-0.4.0+dfsg/test/CMakeLists.txt000066400000000000000000000024431323624675700210670ustar00rootroot00000000000000include_directories ( ${PROJECT_SOURCE_DIR}/test/gtest/include ${PROJECT_SOURCE_DIR}/test/gtest ${PROJECT_SOURCE_DIR}/test ) link_directories( ${PROJECT_BINARY_DIR}/test ) # Build gtest add_library(gtest STATIC gtest/src/gtest-all.cc) add_library(gtest_main STATIC gtest/src/gtest_main.cc) target_link_libraries(gtest_main gtest) execute_process(COMMAND cmake -E remove_directory ${CMAKE_BINARY_DIR}/test_results) execute_process(COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test_results) include_directories(${GTEST_INCLUDE_DIRS}) set(tests console_TEST.cc) ################################################# # Build all the tests foreach(GTEST_SOURCE_file ${tests}) string(REGEX REPLACE ".cc" "" BINARY_NAME ${GTEST_SOURCE_file}) add_executable(${BINARY_NAME} ${GTEST_SOURCE_file}) add_dependencies(${BINARY_NAME} console_bridge gtest gtest_main) target_link_libraries(${BINARY_NAME} gtest_main gtest console_bridge) if (UNIX AND NOT ANDROID) target_link_libraries(${BINARY_NAME} pthread) endif() add_test(NAME ${BINARY_NAME} COMMAND ${BINARY_NAME} --gtest_output=xml:${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml) set_tests_properties(${BINARY_NAME} PROPERTIES TIMEOUT 240) endforeach() console-bridge-0.4.0+dfsg/test/console_TEST.cc000066400000000000000000000007171323624675700211410ustar00rootroot00000000000000#include #include #include ////////////////////////////////////////////////// TEST(ConsoleTest, MacroExpansionTest_ItShouldCompile) { if (true) CONSOLE_BRIDGE_logDebug("Testing Log"); if (true) CONSOLE_BRIDGE_logDebug("Testing Log"); else { assert(true); } if (true) { CONSOLE_BRIDGE_logDebug("Testing Log"); } else { CONSOLE_BRIDGE_logDebug("Testing Log"); } }