pax_global_header00006660000000000000000000000064122233175550014517gustar00rootroot0000000000000052 comment=2f5e9c683e3b9700ffb1d0ff83174f1015b4b9ff console_bridge-0.2.5/000077500000000000000000000000001222331755500145015ustar00rootroot00000000000000console_bridge-0.2.5/CMakeLists.txt000066400000000000000000000040231222331755500172400ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8) project(console_bridge) include(GNUInstallDirs) 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() find_package(Boost COMPONENTS system thread REQUIRED) if(MSVC OR MSVC90 OR MSVC10) set(MSVC ON) endif (MSVC OR MSVC90 OR MSVC10) if(MSVC) add_definitions(-DBOOST_ALL_NO_LIB) endif(MSVC) include_directories(include) include_directories(${Boost_INCLUDE_DIR}) link_directories(${Boost_LIBRARY_DIRS}) if(NOT DEFINED BUILD_SHARED_LIBS) option(BUILD_SHARED_LIBS "Build dynamically-linked binaries" ON) endif() add_library(${PROJECT_NAME} src/console.cpp) target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES}) set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 0.2) install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h") set(PKG_NAME ${PROJECT_NAME}) set(PKG_LIBRARIES ${PROJECT_NAME}) set(cmake_conf_file "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake") configure_file("${cmake_conf_file}.in" "${CMAKE_BINARY_DIR}/${cmake_conf_file}" @ONLY) install(FILES ${CMAKE_BINARY_DIR}/${cmake_conf_file} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake/ COMPONENT cmake) if (NOT MSVC) set(PKG_DESC "Console Bridge") set(PKG_CB_LIBS "-l${PROJECT_NAME}") set(pkg_conf_file "${CMAKE_CURRENT_SOURCE_DIR}/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) console_bridge-0.2.5/console_bridge-config.cmake.in000066400000000000000000000011751222331755500223350ustar00rootroot00000000000000if (@PKG_NAME@_CONFIG_INCLUDED) return() endif() set(@PKG_NAME@_CONFIG_INCLUDED TRUE) set(@PKG_NAME@_INCLUDE_DIRS @CMAKE_INSTALL_FULL_INCLUDEDIR@) foreach(lib @PKG_LIBRARIES@) set(onelib "${lib}-NOTFOUND") find_library(onelib ${lib}) if(NOT onelib) message(FATAL_ERROR "Library '${lib}' in package @PKG_NAME@ is not installed properly") endif() list(APPEND @PKG_NAME@_LIBRARIES ${onelib}) endforeach() foreach(dep @PKG_DEPENDS@) if(NOT ${dep}_FOUND) find_package(${dep}) endif() list(APPEND @PKG_NAME@_INCLUDE_DIRS ${${dep}_INCLUDE_DIRS}) list(APPEND @PKG_NAME@_LIBRARIES ${${dep}_LIBRARIES}) endforeach() console_bridge-0.2.5/console_bridge.pc.in000066400000000000000000000005041222331755500204070ustar00rootroot00000000000000# This file was generated by CMake for @PROJECT_NAME@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} libdir=@CMAKE_INSTALL_LIBDIR@ includedir=@CMAKE_INSTALL_INCLUDEDIR@ Name: @PKG_NAME@ Description: @PKG_DESC@ Version: @CB_VERSION@ Requires: @PKG_EXTERNAL_DEPS@ Libs: -L${libdir} @PKG_CB_LIBS@ Cflags: -I${includedir} console_bridge-0.2.5/include/000077500000000000000000000000001222331755500161245ustar00rootroot00000000000000console_bridge-0.2.5/include/console_bridge/000077500000000000000000000000001222331755500211025ustar00rootroot00000000000000console_bridge-0.2.5/include/console_bridge/console.h000066400000000000000000000147321222331755500227240ustar00rootroot00000000000000/********************************************************************* * 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 "exportdecl.h" /** \file console.h \defgroup logging Logging Macros \{ \def logError(fmt, ...) \brief Log a formatted error string. \remarks This macro takes the same arguments as printf. \def logWarn(fmt, ...) \brief Log a formatted warning string. \remarks This macro takes the same arguments as printf. \def logInform(fmt, ...) \brief Log a formatted information string. \remarks This macro takes the same arguments as printf. \def logDebug(fmt, ...) \brief Log a formatted debugging string. \remarks This macro takes the same arguments as printf. \} */ #define logError(fmt, ...) console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_ERROR, fmt, ##__VA_ARGS__) #define logWarn(fmt, ...) console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_WARN, fmt, ##__VA_ARGS__) #define logInform(fmt, ...) console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_INFO, fmt, ##__VA_ARGS__) #define 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.2.5/include/console_bridge/exportdecl.h000066400000000000000000000072571222331755500234370ustar00rootroot00000000000000/********************************************************************* * 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: Thomas Moulard */ #ifndef CONSOLE_BRIDGE_EXPORTDECL_H # define CONSOLE_BRIDGE_EXPORTDECL_H // Handle portable symbol export. // Defining manually which symbol should be exported is required // under Windows whether MinGW or MSVC is used. // // The headers then have to be able to work in two different modes: // - dllexport when one is building the library, // - dllimport for clients using the library. // // On Linux, set the visibility accordingly. If C++ symbol visibility // is handled by the compiler, see: http://gcc.gnu.org/wiki/Visibility # if defined _WIN32 || defined __CYGWIN__ // On Microsoft Windows, use dllimport and dllexport to tag symbols. # define CONSOLE_BRIDGE_DLLIMPORT __declspec(dllimport) # define CONSOLE_BRIDGE_DLLEXPORT __declspec(dllexport) # define CONSOLE_BRIDGE_DLLLOCAL # else // On Linux, for GCC >= 4, tag symbols using GCC extension. # if __GNUC__ >= 4 # define CONSOLE_BRIDGE_DLLIMPORT __attribute__ ((visibility("default"))) # define CONSOLE_BRIDGE_DLLEXPORT __attribute__ ((visibility("default"))) # define CONSOLE_BRIDGE_DLLLOCAL __attribute__ ((visibility("hidden"))) # else // Otherwise (GCC < 4 or another compiler is used), export everything. # define CONSOLE_BRIDGE_DLLIMPORT # define CONSOLE_BRIDGE_DLLEXPORT # define CONSOLE_BRIDGE_DLLLOCAL # endif // __GNUC__ >= 4 # endif // defined _WIN32 || defined __CYGWIN__ # ifdef CONSOLE_BRIDGE_STATIC // If one is using the library statically, get rid of // extra information. # define CONSOLE_BRIDGE_DLLAPI # define CONSOLE_BRIDGE_LOCAL # else // Depending on whether one is building or using the // library define DLLAPI to import or export. # ifdef console_bridge_EXPORTS # define CONSOLE_BRIDGE_DLLAPI CONSOLE_BRIDGE_DLLEXPORT # else # define CONSOLE_BRIDGE_DLLAPI CONSOLE_BRIDGE_DLLIMPORT # endif // CONSOLE_BRIDGE_EXPORTS # define CONSOLE_BRIDGE_LOCAL CONSOLE_BRIDGE_DLLLOCAL # endif // CONSOLE_BRIDGE_STATIC #endif //! CONSOLE_BRIDGE_EXPORTDECL_H console_bridge-0.2.5/src/000077500000000000000000000000001222331755500152705ustar00rootroot00000000000000console_bridge-0.2.5/src/console.cpp000066400000000000000000000132021222331755500174340ustar00rootroot00000000000000/********************************************************************* * 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_; boost::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(); \ boost::mutex::scoped_lock slock(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]; vsnprintf(buf, sizeof(buf), m, __ap); 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() { file_ = fopen(filename, "a"); if (!file_) 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_); } }