Skip to content

Commit

Permalink
add rs2_device_is_connected, rs2::device::is_connected
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Sep 30, 2023
1 parent e6acbee commit f67dbc4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/librealsense2/h/rs_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ rs2_device* rs2_create_device(const rs2_device_list* info_list, int index, rs2_e
*/
void rs2_delete_device(rs2_device* device);

/**
* \param[in] device Realsense device to query
* \return True if device is still present in the system
*/
int rs2_device_is_connected( const rs2_device * device, rs2_error ** error );

/**
* Retrieve camera specific information, like versions of various internal components.
* \param[in] device The RealSense device
Expand Down
11 changes: 10 additions & 1 deletion include/librealsense2/hpp/rs_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ namespace rs2
void hardware_reset()
{
rs2_error* e = nullptr;

rs2_hardware_reset(_dev.get(), &e);
error::handle(e);
}
Expand All @@ -110,6 +109,8 @@ namespace rs2
}
device() : _dev(nullptr) {}

// Note: this checks the validity of rs2::device (i.e., if it's connected to a realsense device), and does
// NOT reflect the current condition (connected/disconnected). Use is_connected() for that.
operator bool() const
{
return _dev != nullptr;
Expand All @@ -125,6 +126,14 @@ namespace rs2
< 0 );
}

bool is_connected() const
{
rs2_error * e = nullptr;
bool connected = rs2_device_is_connected( _dev.get(), &e );
error::handle( e );
return connected;
}

template<class T>
bool is() const
{
Expand Down
1 change: 1 addition & 0 deletions src/realsense.def
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EXPORTS
rs2_delete_device_list
rs2_create_device
rs2_delete_device
rs2_device_is_connected

rs2_query_sensors
rs2_get_sensors_count
Expand Down
7 changes: 7 additions & 0 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ void rs2_delete_device(rs2_device* device) BEGIN_API_CALL
}
NOEXCEPT_RETURN(, device)

int rs2_device_is_connected( const rs2_device * device, rs2_error ** error ) BEGIN_API_CALL
{
VALIDATE_NOT_NULL( device );
return device->device->is_valid();
}
HANDLE_EXCEPTIONS_AND_RETURN( 0, device )

rs2_sensor* rs2_create_sensor(const rs2_sensor_list* list, int index, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(list);
Expand Down

0 comments on commit f67dbc4

Please sign in to comment.