Skip to content

Commit

Permalink
PR #11160 from Eran: ELPP and utilities changes
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Dec 6, 2022
2 parents 5f3a36f + 103b7b4 commit a98d805
Show file tree
Hide file tree
Showing 30 changed files with 177 additions and 102 deletions.
2 changes: 1 addition & 1 deletion CMake/opengl_config.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
find_package(OpenGL REQUIRED)
set(DEPENDENCIES realsense2 utilities glfw ${OPENGL_LIBRARIES})
set(DEPENDENCIES realsense2 glfw ${OPENGL_LIBRARIES})
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ include(src/CMakeLists.txt)
include(third-party/CMakeLists.txt)
include(common/utilities/CMakeLists.txt)

target_link_libraries( ${LRS_TARGET} PRIVATE utilities )
target_link_libraries( ${LRS_TARGET} PUBLIC utilities )

# configure the project according to OS specific requirments
# macro definition located at "CMake/<OS>_config.cmake"
Expand Down
2 changes: 1 addition & 1 deletion src/compression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project(realsense2-compression VERSION 1.0.0 LANGUAGES CXX C)
# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

list( APPEND DEPENDENCIES realsense2 utilities )
list( APPEND DEPENDENCIES realsense2 )

file(GLOB COMPRESSION_SOURCES
"*.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ds5/ds5-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ namespace librealsense
virtual float query() const override;
virtual option_range get_range() const override;
virtual bool is_enabled() const override { return true; }
virtual bool is_read_only() const { return _sensor && _sensor->is_opened(); }
virtual bool is_read_only() const override { return _sensor && _sensor->is_opened(); }
const char* get_description() const override;

void enable_recording(std::function<void(const option &)> record_action) override
Expand Down
2 changes: 1 addition & 1 deletion src/ds5/ds5-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

//#define DEBUG_THERMAL_LOOP
#ifdef DEBUG_THERMAL_LOOP
#define LOG_DEBUG_THERMAL_LOOP(...) do { CLOG(WARNING ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_DEBUG_THERMAL_LOOP(...) do { CLOG(WARNING ,LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false)
#else
#define LOG_DEBUG_THERMAL_LOOP(...)
#endif //DEBUG_THERMAL_LOOP
Expand Down
8 changes: 4 additions & 4 deletions src/ethernet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ if(WIN32)
endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")

add_definitions(-DELPP_WINSOCK2)

set(WINLIB Ws2_32.lib)
endif()

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)

target_link_libraries(${PROJECT_NAME}
PRIVATE ${WINLIB} realsense2 realsense2-compression utilities
target_link_libraries(${PROJECT_NAME}
PRIVATE ${WINLIB} realsense2 realsense2-compression
)

set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Library)
Expand All @@ -89,7 +89,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${REALSENSE_VERSION_STR
# set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C)

WRITE_BASIC_CONFIG_VERSION_FILE("${CMAKE_CURRENT_BINARY_DIR}/realsense2-netConfigVersion.cmake"
VERSION ${REALSENSE_VERSION_STRING}
VERSION ${REALSENSE_VERSION_STRING}
COMPATIBILITY AnyNewerVersion
)

Expand Down
2 changes: 1 addition & 1 deletion src/fw-update/fw-update-device-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace librealsense
{
auto version_offset = offsetof(platform::dfu_header, bcdDevice);
if (fw_image.size() < (version_offset + sizeof(size_t)))
throw std::runtime_error("Firmware binary image might be corrupted - size is only: " + fw_image.size());
throw std::runtime_error("Firmware binary image might be corrupted - size is only: " + std::to_string( fw_image.size() ));

auto version = fw_image.data() + version_offset;
uint8_t major = *(version + 3);
Expand Down
2 changes: 1 addition & 1 deletion src/gl/rs-gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ HANDLE_EXCEPTIONS_AND_RETURN(nullptr, api_version)
#ifdef SHARED_LIBS
INITIALIZE_EASYLOGGINGPP
#endif
char log_gl_name[] = "librealsense";
char log_gl_name[] = LIBREALSENSE_ELPP_ID;
static logger_type<log_gl_name> logger_gl;
#endif

8 changes: 4 additions & 4 deletions src/ipDeviceCommon/NetdevLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <utilities/easylogging/easyloggingpp.h>

#define DBG CLOG(DEBUG, "librealsense")
#define ERR CLOG(ERROR, "librealsense")
#define WRN CLOG(WARNING, "librealsense")
#define INF CLOG(INFO, "librealsense")
#define DBG CLOG(DEBUG, LIBREALSENSE_ELPP_ID)
#define ERR CLOG(ERROR, LIBREALSENSE_ELPP_ID)
#define WRN CLOG(WARNING, LIBREALSENSE_ELPP_ID)
#define INF CLOG(INFO, LIBREALSENSE_ELPP_ID)
4 changes: 2 additions & 2 deletions src/ipDeviceCommon/RsUsageEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RSUsageEnvironment::~RSUsageEnvironment()
{
CLOG(INFO, "netdev") << "RealSense network logging closed";

el::Loggers::unregisterLogger("librealsense");
el::Loggers::unregisterLogger(LIBREALSENSE_ELPP_ID);
el::Loggers::unregisterLogger("netdev");
}

Expand All @@ -29,7 +29,7 @@ RSUsageEnvironment* RSUsageEnvironment::createNew(TaskScheduler& taskScheduler)
{
env->ptr = env->buffer;
env->netdev_log = el::Loggers::getLogger("netdev");
env->lrs_log = el::Loggers::getLogger("librealsense");
env->lrs_log = el::Loggers::getLogger(LIBREALSENSE_ELPP_ID);

el::Loggers::reconfigureAllLoggers(el::Level::Global, el::ConfigurationType::Format, "%datetime{%y%M%d%H%m%s.%g} [%logger]\t%levshort: %msg");
el::Loggers::reconfigureAllLoggers(el::Level::Debug, el::ConfigurationType::Enabled, "false");
Expand Down
2 changes: 1 addition & 1 deletion src/linux/backend-hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const std::string HID_CUSTOM_PATH("/sys/bus/platform/drivers/hid_sensor_custom")

//#define DEBUG_HID
#ifdef DEBUG_HID
#define LOG_DEBUG_HID(...) do { CLOG(DEBUG ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_DEBUG_HID(...) do { CLOG(DEBUG ,LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false)
#else
#define LOG_DEBUG_HID(...)
#endif //DEBUG_HID
Expand Down
2 changes: 1 addition & 1 deletion src/linux/backend-v4l2.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ constexpr bool metadata_node = false;

#undef DEBUG_V4L
#ifdef DEBUG_V4L
#define LOG_DEBUG_V4L(...) do { CLOG(DEBUG ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_DEBUG_V4L(...) do { CLOG(DEBUG ,LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false)
#else
#define LOG_DEBUG_V4L(...)
#endif //DEBUG_V4L
Expand Down
2 changes: 1 addition & 1 deletion src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ INITIALIZE_EASYLOGGINGPP

namespace librealsense
{
char log_name[] = "librealsense";
char log_name[] = LIBREALSENSE_ELPP_ID;
static logger_type<log_name> logger;
}

Expand Down
56 changes: 49 additions & 7 deletions third-party/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# License: Apache 2.0. See LICENSE file in root directory.
# Copyright(c) 2022 Intel Corporation. All Rights Reserved.

cmake_minimum_required(VERSION 3.8.0) # source_group(TREE)
project( utilities )

add_library( ${PROJECT_NAME} STATIC "" )
Expand All @@ -20,11 +20,14 @@ file(GLOB_RECURSE UTILITIES_HEADER_FILES
"${UTILITIES_INCLUDE_DIR}/*.h"
)
if( BUILD_EASYLOGGINGPP )
list( APPEND UTILITIES_HEADER_FILES
"${REPO_ROOT}/third-party/easyloggingpp/src/easylogging++.h"
)
target_sources( ${PROJECT_NAME}
PRIVATE "${REPO_ROOT}/third-party/easyloggingpp/src/easylogging++.h" )
endif()
target_sources( ${PROJECT_NAME} PRIVATE ${UTILITIES_HEADER_FILES} )
source_group(
TREE ${UTILITIES_INCLUDE_DIR}
PREFIX "Header Files"
FILES ${UTILITIES_HEADER_FILES} )


# Sources -----------------------------------------------------------------------------------
Expand All @@ -36,11 +39,50 @@ file(GLOB_RECURSE UTILITIES_SOURCE_FILES
"${UTILITIES_SRC_DIR}/*"
)
if( BUILD_EASYLOGGINGPP )
list( APPEND UTILITIES_SOURCE_FILES
"${REPO_ROOT}/third-party/easyloggingpp/src/easylogging++.cc"
)
target_sources( ${PROJECT_NAME}
PRIVATE "${REPO_ROOT}/third-party/easyloggingpp/src/easylogging++.cc" )
endif()
target_sources( ${PROJECT_NAME} PRIVATE ${UTILITIES_SOURCE_FILES} )
source_group(
TREE ${UTILITIES_SRC_DIR}
PREFIX "Source Files"
FILES ${UTILITIES_SOURCE_FILES} )


# EasyLogging++ uses global variables that need to be declared somewhere. It therefore
# introduces a macro, INITIALIZE_EASYLOGGINGPP, that needs to be inserted in the code.
# If a client of ours wants to use the easylogging macros, they must do this, or they
# can use this macro in their CMake project file:
#
macro( _using_easyloggingpp include_dir )
#
# using_easyloggingpp( <project-name> [SHARED | STATIC] )
# [SHARED] only initialize when BUILD_SHARED_LIBS is ON
# [STATIC] only initialize when BUILD_SHARED_LIBS is OFF
#
# Projects that depend on realsense2 (and want to use ELPP themselves) need [SHARED]
# because realsense2 always includes the initialization.
#
function( using_easyloggingpp target_name )
set( func_ARGN ARGN ) # otherwise we get the outside macro's ARGN
cmake_parse_arguments( ARG "SHARED;STATIC" "" "" ${${func_ARGN}} )
if( ARG_STATIC AND ARG_SHARED )
message( FATAL_ERROR "Can't be both STATIC and SHARED" )
elseif( ARG_SHARED )
if( NOT BUILD_SHARED_LIBS )
return()
endif()
elseif( ARG_STATIC )
if( BUILD_SHARED_LIBS )
return()
endif()
endif()

target_sources( ${target_name}
PRIVATE "${include_dir}/easylogging/elpp-init.cpp" )
endfunction()
endmacro()
_using_easyloggingpp( ${UTILITIES_INCLUDE_DIR} )


# Install -----------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <third-party/easyloggingpp/src/easylogging++.h>


#define LIBREALSENSE_ELPP_ID "librealsense"


#ifdef __ANDROID__
#include <android/log.h>
#include <sstream>
Expand All @@ -40,11 +43,23 @@

#else //__ANDROID__

#define LOG_DEBUG(...) do { CLOG(DEBUG ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_INFO(...) do { CLOG(INFO ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_WARNING(...) do { CLOG(WARNING ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_ERROR(...) do { CLOG(ERROR ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_FATAL(...) do { CLOG(FATAL ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_DEBUG(...) do { CLOG(DEBUG , LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false)
#define LOG_INFO(...) do { CLOG(INFO , LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false)
#define LOG_WARNING(...) do { CLOG(WARNING , LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false)
#define LOG_ERROR(...) do { CLOG(ERROR , LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false)
#define LOG_FATAL(...) do { CLOG(FATAL , LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false)

namespace utilities {


// Configure the same logger as librealsense (by default), to disable/enable debug output
void configure_elpp_logger( bool enable_debug = false,
std::string const & nested_indent = "",
std::string const & logger_id = LIBREALSENSE_ELPP_ID );


} // namespace utilities


#endif // __ANDROID__

Expand Down
17 changes: 17 additions & 0 deletions third-party/utilities/include/utilities/easylogging/elpp-init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2022 Intel Corporation. All Rights Reserved.

#ifdef BUILD_EASYLOGGINGPP
#ifndef NO_ELPP_INIT
#include <third-party/easyloggingpp/src/easylogging++.h>

// ELPP requires static initialization, otherwise nothing will work:
//
INITIALIZE_EASYLOGGINGPP
//
// The above can be disabled with NO_ELPP_INIT! This is needed in special cases such as librealsense
// where other static initialization is used to automatically set up the logging mechanism based on
// environment variables.

#endif // ! NO_ELPP_INIT
#endif // BUILD_EASYLOGGINGPP

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion third-party/utilities/py/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set_target_properties( ${PROJECT_NAME}
PROJECT_LABEL utilities-py
)

include("../include/utilities/easylogging/shared-init.cmake")
using_easyloggingpp( ${PROJECT_NAME} )

install(
TARGETS ${PROJECT_NAME}
Expand Down
34 changes: 6 additions & 28 deletions third-party/utilities/py/pyrsutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,19 @@
#define SNAME "pyrsutils"


#ifndef BUILD_SHARED_LIBS // shared-init takes care of the else
INITIALIZE_EASYLOGGINGPP
#endif


PYBIND11_MODULE(NAME, m) {
m.doc() = R"pbdoc(
RealSense Utilities Python Bindings
)pbdoc";
m.attr( "__version__" ) = "0.1"; // RS2_API_VERSION_STR;

// Configure the same logger as librealsense, and default to only errors by default...
el::Configurations defaultConf;
defaultConf.setToDefault();
defaultConf.setGlobally( el::ConfigurationType::ToStandardOutput, "false" );
defaultConf.set( el::Level::Error, el::ConfigurationType::ToStandardOutput, "true" );
defaultConf.setGlobally( el::ConfigurationType::Format, "-%levshort- %datetime{%H:%m:%s.%g} %msg (%fbase:%line [%thread])" );
el::Loggers::reconfigureLogger( "librealsense", defaultConf );
utilities::configure_elpp_logger();

m.def(
"debug",
[]( bool enable, std::string const & nested ) {
el::Logger * logger = el::Loggers::getLogger( "librealsense" );
auto configs = logger->configurations();
configs->set( el::Level::Warning, el::ConfigurationType::ToStandardOutput, enable ? "true" : "false" );
configs->set( el::Level::Info, el::ConfigurationType::ToStandardOutput, enable ? "true" : "false" );
configs->set( el::Level::Debug, el::ConfigurationType::ToStandardOutput, enable ? "true" : "false" );
std::string format = "-%levshort- %datetime{%H:%m:%s.%g} %msg (%fbase:%line [%thread])";
if( ! nested.empty() )
format = '[' + nested + "] " + format;
configs->setGlobally( el::ConfigurationType::Format, format );
logger->reconfigure();
},
py::arg( "enable" ),
py::arg( "nested-string" ) = "" );
m.def( "debug",
&utilities::configure_elpp_logger,
py::arg( "enable" ),
py::arg( "nested-string" ) = "",
py::arg( "logger" ) = LIBREALSENSE_ELPP_ID );

m.def( "split", &utilities::string::split );
}
Loading

0 comments on commit a98d805

Please sign in to comment.