Skip to content

Commit

Permalink
software-device, -sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Nov 3, 2023
1 parent 47edb8b commit ab391c9
Show file tree
Hide file tree
Showing 13 changed files with 614 additions and 493 deletions.
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ target_sources(${LRS_TARGET}
"${CMAKE_CURRENT_LIST_DIR}/hid-sensor.cpp"
"${CMAKE_CURRENT_LIST_DIR}/uvc-sensor.cpp"
"${CMAKE_CURRENT_LIST_DIR}/software-device.cpp"
"${CMAKE_CURRENT_LIST_DIR}/software-device-info.cpp"
"${CMAKE_CURRENT_LIST_DIR}/software-sensor.cpp"
"${CMAKE_CURRENT_LIST_DIR}/source.cpp"
"${CMAKE_CURRENT_LIST_DIR}/stream.cpp"
"${CMAKE_CURRENT_LIST_DIR}/sync.cpp"
Expand Down Expand Up @@ -140,6 +142,8 @@ target_sources(${LRS_TARGET}
"${CMAKE_CURRENT_LIST_DIR}/hid-sensor.h"
"${CMAKE_CURRENT_LIST_DIR}/uvc-sensor.h"
"${CMAKE_CURRENT_LIST_DIR}/software-device.h"
"${CMAKE_CURRENT_LIST_DIR}/software-device-info.h"
"${CMAKE_CURRENT_LIST_DIR}/software-sensor.h"
"${CMAKE_CURRENT_LIST_DIR}/source.h"
"${CMAKE_CURRENT_LIST_DIR}/stream.h"
"${CMAKE_CURRENT_LIST_DIR}/sync.h"
Expand Down
2 changes: 2 additions & 0 deletions src/dds/rs-dds-device-info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <realdds/dds-device.h>
#include <realdds/topics/device-info-msg.h>

#include <rsutils/string/from.h>


namespace librealsense {

Expand Down
2 changes: 2 additions & 0 deletions src/dds/rs-dds-sensor-proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "rs-dds-sensor-proxy.h"
#include "rs-dds-option.h"

#include <src/device.h>

#include <realdds/dds-device.h>
#include <realdds/dds-time.h>

Expand Down
2 changes: 1 addition & 1 deletion src/dds/rs-dds-sensor-proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


#include "sid_index.h"
#include <src/software-device.h>
#include <src/software-sensor.h>
#include <src/proc/formats-converter.h>

#include <realdds/dds-metadata-syncer.h>
Expand Down
7 changes: 4 additions & 3 deletions src/proc/spatial-filter.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.

#include <librealsense2/hpp/rs_sensor.hpp>
#include <librealsense2/hpp/rs_processing.hpp>
#include "option.h"
#include "environment.h"
#include "software-device.h"
#include "software-sensor.h"
#include "proc/synthetic-stream.h"
#include "proc/hole-filling-filter.h"
#include "proc/spatial-filter.h"

#include <librealsense2/hpp/rs_sensor.hpp>
#include <librealsense2/hpp/rs_processing.hpp>

#include <rsutils/string/from.h>


Expand Down
13 changes: 8 additions & 5 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include "environment.h"
#include "proc/temporal-filter.h"
#include "software-device.h"
#include "software-device-info.h"
#include "software-sensor.h"
#include "global_timestamp_reader.h"
#include "auto-calibrated-device.h"
#include "terminal-parser.h"
Expand Down Expand Up @@ -804,7 +806,7 @@ void rs2_software_device_set_destruction_callback(const rs2_device* dev, rs2_sof
VALIDATE_NOT_NULL(dev);
auto swdev = VALIDATE_INTERFACE(dev->device, librealsense::software_device);
VALIDATE_NOT_NULL(on_destruction);
librealsense::software_device_destruction_callback_ptr callback(
librealsense::software_device::destruction_callback_ptr callback(
new librealsense::software_device_destruction_callback(on_destruction, user),
[](rs2_software_device_destruction_callback* p) { delete p; });
swdev->register_destruction_callback(std::move(callback));
Expand Down Expand Up @@ -868,10 +870,11 @@ void rs2_software_device_set_destruction_callback_cpp(const rs2_device* dev, rs2
// Take ownership of the callback ASAP or else memory leaks could result if we throw! (the caller usually does a
// 'new' when calling us)
VALIDATE_NOT_NULL( callback );
software_device_destruction_callback_ptr callback_ptr{ callback,
[]( rs2_software_device_destruction_callback * p ) {
p->release();
} };
software_device::destruction_callback_ptr callback_ptr{ callback,
[]( rs2_software_device_destruction_callback * p )
{
p->release();
} };

VALIDATE_NOT_NULL(dev);
auto swdev = VALIDATE_INTERFACE(dev->device, librealsense::software_device);
Expand Down
44 changes: 44 additions & 0 deletions src/software-device-info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.

#include "software-device-info.h"
#include "software-device.h"
#include "librealsense-exception.h"

#include <rsutils/string/from.h>


namespace librealsense {


software_device_info::software_device_info( std::shared_ptr< context > const & ctx )
: device_info( ctx )
, _address() // leave empty until set_device()
{
}


void software_device_info::set_device( std::shared_ptr< software_device > const & dev )
{
if( ! _address.empty() )
throw wrong_api_call_sequence_exception( "software_device_info already initialized" );
_dev = dev;
_address = rsutils::string::from() << "software-device://" << (unsigned long long)dev.get();
}


bool software_device_info::is_same_as( std::shared_ptr< const device_info > const & other ) const
{
if( auto rhs = std::dynamic_pointer_cast< const software_device_info >( other ) )
return _address == rhs->_address;
return false;
}


std::shared_ptr< device_interface > software_device_info::create_device()
{
return _dev.lock();
}


} // namespace librealsense
35 changes: 35 additions & 0 deletions src/software-device-info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.
#pragma once

#include "device-info.h"


namespace librealsense {


class software_device;


class software_device_info : public device_info
{
std::weak_ptr< software_device > _dev;
std::string _address;

public:
explicit software_device_info( std::shared_ptr< context > const & ctx );

// The usage is dictated by the rs2 APIs: rather than creating the info and then using create_device() to create the
// device, it's the other way around (see rs2_context_add_software_device).
//
void set_device( std::shared_ptr< software_device > const & dev );

std::string get_address() const override { return _address; }

bool is_same_as( std::shared_ptr< const device_info > const & other ) const override;

std::shared_ptr< device_interface > create_device() override;
};


} // namespace librealsense
Loading

0 comments on commit ab391c9

Please sign in to comment.