Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ matrix:
- ./live-test.exe -d yes -i [software-device]
- for i in ../records/single_cam/*; do ./live-test -d yes -i ~[multicam] from "$i"; done
- for i in ../records/multi_cam/*; do ./live-test -d yes -i [multicam] from "$i"; done
- unset LRS_LOG_LEVEL
- C:/Python38/python.exe ../../unit-tests/run-unit-tests.py --verbose .

- name: "Windows - cpp"
os: windows
Expand Down Expand Up @@ -48,16 +50,16 @@ matrix:
- for i in ./records/single_cam/*; do ./unit-tests/live-test -d yes -i ~[multicam] from "$i"; done
- for i in ./records/multi_cam/*; do ./unit-tests/live-test -d yes -i [multicam] from "$i"; done

- name: "Linux - cpp"
- name: "Linux - cpp - static"
os: linux
language: cpp
sudo: required
dist: xenial
script:
- cd ../scripts && ./pr_check.sh && cd ../build
- cmake .. -DBUILD_EXAMPLES=true -DBUILD_WITH_TM2=true
- cmake .. -DBUILD_UNIT_TESTS=true -DBUILD_EXAMPLES=true -DBUILD_WITH_TM2=true -DBUILD_SHARED_LIBS=false
- cmake --build . --config $LRS_BUILD_CONFIG -- -j4
- ls
- python3 ../unit-tests/run-unit-tests.py --verbose .

- name: "Linux - python & nodejs"
os: linux
Expand Down Expand Up @@ -137,9 +139,10 @@ install:
fi

- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
choco install -y python3 --version 3.8.1;
if [[ "$VS15" == "true" ]]; then
choco install -y vcbuildtools --version 2015.4 --force;
fi
fi;
fi

- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
Expand Down
4 changes: 4 additions & 0 deletions CMake/global_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ macro(global_set_flags)
add_definitions(-DRS2_USE_CUDA)
endif()

if (BUILD_SHARED_LIBS)
add_definitions(-DBUILD_SHARED_LIBS)
endif()

if (BUILD_INTERNAL_UNIT_TESTS)
add_definitions(-DBUILD_INTERNAL_UNIT_TESTS)
endif()
Expand Down
7 changes: 5 additions & 2 deletions include/librealsense2/h/rs_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ typedef enum rs2_log_severity {
RS2_LOG_SEVERITY_ERROR, /**< Indication of definite failure */
RS2_LOG_SEVERITY_FATAL, /**< Indication of unrecoverable failure */
RS2_LOG_SEVERITY_NONE , /**< No logging will occur */
RS2_LOG_SEVERITY_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
} rs2_log_severity;
RS2_LOG_SEVERITY_COUNT, /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
RS2_LOG_SEVERITY_ALL = RS2_LOG_SEVERITY_DEBUG /**< Include any/all log messages */
} rs2_log_severity;
const char* rs2_log_severity_to_string(rs2_log_severity info);

/** \brief Specifies advanced interfaces (capabilities) objects may implement. */
Expand Down Expand Up @@ -213,6 +214,7 @@ typedef enum rs2_matchers
typedef struct rs2_device_info rs2_device_info;
typedef struct rs2_device rs2_device;
typedef struct rs2_error rs2_error;
typedef struct rs2_log_message rs2_log_message;
typedef struct rs2_raw_data_buffer rs2_raw_data_buffer;
typedef struct rs2_frame rs2_frame;
typedef struct rs2_frame_queue rs2_frame_queue;
Expand Down Expand Up @@ -241,6 +243,7 @@ typedef struct rs2_options_list rs2_options_list;
typedef struct rs2_devices_changed_callback rs2_devices_changed_callback;
typedef struct rs2_notification rs2_notification;
typedef struct rs2_notifications_callback rs2_notifications_callback;
typedef void (*rs2_log_callback_ptr)(rs2_log_severity, rs2_log_message const *, void * arg);
typedef void (*rs2_notification_callback_ptr)(rs2_notification*, void*);
typedef void (*rs2_devices_changed_callback_ptr)(rs2_device_list*, rs2_device_list*, void*);
typedef void (*rs2_frame_callback_ptr)(rs2_frame*, void*);
Expand Down
6 changes: 3 additions & 3 deletions include/librealsense2/hpp/rs_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ return results;

rs2_error* e = nullptr;
std::shared_ptr<const rs2_raw_data_buffer> list(
rs2_run_on_chip_calibration_cpp(_dev.get(), json_content.data(), json_content.size(), health, nullptr, timeout_ms, &e),
rs2_run_on_chip_calibration_cpp(_dev.get(), json_content.data(), static_cast< int >( json_content.size() ), health, nullptr, timeout_ms, &e),
rs2_delete_raw_data);
error::handle(e);
auto size = rs2_get_raw_data_size(list.get(), &e);
Expand Down Expand Up @@ -475,7 +475,7 @@ return results;

rs2_error* e = nullptr;
std::shared_ptr<const rs2_raw_data_buffer> list(
rs2_run_tare_calibration_cpp(_dev.get(), ground_truth_mm, json_content.data(), json_content.size(), nullptr, timeout_ms, &e),
rs2_run_tare_calibration_cpp(_dev.get(), ground_truth_mm, json_content.data(), static_cast< int >( json_content.size() ), nullptr, timeout_ms, &e),
rs2_delete_raw_data);
error::handle(e);

Expand Down Expand Up @@ -520,7 +520,7 @@ return results;
void set_calibration_table(const calibration_table& calibration)
{
rs2_error* e = nullptr;
rs2_set_calibration_table(_dev.get(), calibration.data(), calibration.size(), &e);
rs2_set_calibration_table(_dev.get(), calibration.data(), static_cast< int >( calibration.size() ), &e);
error::handle(e);
}

Expand Down
4 changes: 3 additions & 1 deletion include/librealsense2/hpp/rs_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ struct rs2_notifications_callback
virtual ~rs2_notifications_callback() {}
};

typedef void ( *log_callback_function_ptr )(rs2_log_severity severity, rs2_log_message const * msg );

struct rs2_log_callback
{
virtual void on_event(rs2_log_severity severity, const char * message) = 0;
virtual void on_log( rs2_log_severity severity, rs2_log_message const & msg ) noexcept = 0;
virtual void release() = 0;
virtual ~rs2_log_callback() {}
};
Expand Down
10 changes: 10 additions & 0 deletions include/librealsense2/rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ void rs2_log_to_console(rs2_log_severity min_severity, rs2_error ** error);

void rs2_log_to_file(rs2_log_severity min_severity, const char * file_path, rs2_error ** error);

void rs2_log_to_callback_cpp( rs2_log_severity min_severity, rs2_log_callback * callback, rs2_error ** error );

void rs2_log_to_callback( rs2_log_severity min_severity, rs2_log_callback_ptr callback, void * arg, rs2_error** error );


unsigned rs2_get_log_message_line_number( rs2_log_message const * msg, rs2_error** error );
const char * rs2_get_log_message_filename( rs2_log_message const * msg, rs2_error** error );
const char * rs2_get_raw_log_message( rs2_log_message const * msg, rs2_error** error );
const char * rs2_get_full_log_message( rs2_log_message const * msg, rs2_error** error );

/**
* Add custom message into librealsense log
* \param[in] severity The log level for the message to be written under
Expand Down
96 changes: 96 additions & 0 deletions include/librealsense2/rs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,101 @@ namespace rs2
error::handle(e);
}

/*
Interface to the log message data we expose.
*/
class log_message
{
// Only log_callback should be creating us!
template< class T > friend class log_callback;

log_message( rs2_log_message const & msg ) : _msg( msg ) {}

public:
/* Returns the line-number in the file where the LOG() comment was issued */
size_t line_number() const
{
rs2_error* e = nullptr;
size_t ln = rs2_get_log_message_line_number( &_msg, &e );
error::handle( e );
return ln;
}
/* Returns the file in which the LOG() command was issued */
const char * filename() const
{
rs2_error* e = nullptr;
const char * path = rs2_get_log_message_filename( &_msg, &e );
error::handle( e );
return path;
}
/* Returns the raw message, as it was passed to LOG(), before any embelishments like level etc. */
const char* raw() const
{
rs2_error* e = nullptr;
const char* r = rs2_get_raw_log_message( &_msg, &e );
error::handle( e );
return r;
}
/*
Returns a complete log message, as defined by librealsense, with level, timestamp, etc.:
11/12 13:49:40,153 INFO [10604] (rs.cpp:2271) Framebuffer size changed to 1552 x 919
*/
const char* full() const
{
rs2_error* e = nullptr;
const char* str = rs2_get_full_log_message( &_msg, &e );
error::handle( e );
return str;
}

private:
rs2_log_message const & _msg;
};

/*
Wrapper around any callback function that is given to log_to_callback.
*/
template<class T>
class log_callback : public rs2_log_callback
{
T on_log_function;
public:
explicit log_callback( T on_log ) : on_log_function( on_log ) {}

void on_log( rs2_log_severity severity, rs2_log_message const & msg ) noexcept override
{
on_log_function( severity, log_message( msg ));
}

void release() override { delete this; }
};

/*
Your callback should look like this, for example:
void callback( rs2_log_severity severity, rs2::log_message const & msg ) noexcept
{
std::cout << msg.build() << std::endl;
}
and, when initializing rs2:
rs2::log_to_callback( callback );
or:
rs2::log_to_callback(
[]( rs2_log_severity severity, rs2::log_message const & msg ) noexcept
{
std::cout << msg.build() << std::endl;
})
*/
template< typename S >
inline void log_to_callback( rs2_log_severity min_severity, S callback )
{
// We wrap the callback with an interface and pass it to librealsense, who will
// now manage its lifetime. Rather than deleting it, though, it will call its
// release() function, where (back in our context) it can be safely deleted:
rs2_error* e = nullptr;
rs2_log_to_callback_cpp( min_severity, new log_callback< S >( std::move( callback )), &e );
error::handle( e );
}

inline void log(rs2_log_severity severity, const char* message)
{
rs2_error* e = nullptr;
Expand All @@ -43,6 +138,7 @@ inline std::ostream & operator << (std::ostream & o, rs2_format format) { return
inline std::ostream & operator << (std::ostream & o, rs2_distortion distortion) { return o << rs2_distortion_to_string(distortion); }
inline std::ostream & operator << (std::ostream & o, rs2_option option) { return o << rs2_option_to_string(option); } // This function is being deprecated. For existing options it will return option name, but for future API additions the user should call rs2_get_option_name instead.
inline std::ostream & operator << (std::ostream & o, rs2_log_severity severity) { return o << rs2_log_severity_to_string(severity); }
inline std::ostream & operator << (std::ostream & o, rs2::log_message const & msg ) { return o << msg.raw(); }
inline std::ostream & operator << (std::ostream & o, rs2_camera_info camera_info) { return o << rs2_camera_info_to_string(camera_info); }
inline std::ostream & operator << (std::ostream & o, rs2_frame_metadata_value metadata) { return o << rs2_frame_metadata_to_string(metadata); }
inline std::ostream & operator << (std::ostream & o, rs2_timestamp_domain domain) { return o << rs2_timestamp_domain_to_string(domain); }
Expand Down
2 changes: 1 addition & 1 deletion src/concurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class dispatcher
: _owner(owner)
{}

bool try_sleep(int ms)
bool try_sleep(std::chrono::milliseconds::rep ms)
{
using namespace std::chrono;

Expand Down
5 changes: 5 additions & 0 deletions src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ void librealsense::log_to_file(rs2_log_severity min_severity, const char * file_
logger.log_to_file(min_severity, file_path);
}

void librealsense::log_to_callback( rs2_log_severity min_severity, log_callback_ptr callback )
{
logger.log_to_callback( min_severity, callback );
}

#else // BUILD_EASYLOGGINGPP

void librealsense::log_to_console(rs2_log_severity min_severity)
Expand Down
Loading