Skip to content

Commit

Permalink
move subtract-sets(), contained-in() to proper headers for reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Oct 5, 2023
1 parent d51008e commit 954033e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
49 changes: 8 additions & 41 deletions src/backend-device-factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,25 @@ std::shared_ptr< backend > create_backend();
} // namespace librealsense


namespace {


// Returns true if the left group is completely accounted for in the right group
//
bool group_contained_in( librealsense::platform::backend_device_group const & first_data,
librealsense::platform::backend_device_group const & second_data )
{
for( auto && uvc : first_data.uvc_devices )
{
if( std::find( second_data.uvc_devices.begin(), second_data.uvc_devices.end(), uvc )
== second_data.uvc_devices.end() )
return false;
}
for( auto && usb : first_data.usb_devices )
{
if( std::find( second_data.usb_devices.begin(), second_data.usb_devices.end(), usb )
== second_data.usb_devices.end() )
return false;
}
for( auto && hid : first_data.hid_devices )
{
if( std::find( second_data.hid_devices.begin(), second_data.hid_devices.end(), hid )
== second_data.hid_devices.end() )
return false;
}
return true;
}
namespace librealsense {


std::vector< std::shared_ptr< librealsense::platform::platform_device_info > >
subtract_sets( const std::vector< std::shared_ptr< librealsense::platform::platform_device_info > > & first,
const std::vector< std::shared_ptr< librealsense::platform::platform_device_info > > & second )
std::vector< std::shared_ptr< platform::platform_device_info > >
subtract_sets( const std::vector< std::shared_ptr< platform::platform_device_info > > & first,
const std::vector< std::shared_ptr< platform::platform_device_info > > & second )
{
std::vector< std::shared_ptr< librealsense::platform::platform_device_info > > results;
std::vector< std::shared_ptr< platform::platform_device_info > > results;
std::for_each(
first.begin(),
first.end(),
[&]( std::shared_ptr< librealsense::platform::platform_device_info > const & data )
[&]( std::shared_ptr< platform::platform_device_info > const & data )
{
if( std::find_if(
second.begin(),
second.end(),
[&]( std::shared_ptr< librealsense::platform::platform_device_info > const & new_dev )
[&]( std::shared_ptr< platform::platform_device_info > const & new_dev )
{
return group_contained_in( data->get_group(), new_dev->get_group() );
return data->get_group().is_contained_in( new_dev->get_group() );
} )
== second.end() )
{
Expand All @@ -81,12 +54,6 @@ subtract_sets( const std::vector< std::shared_ptr< librealsense::platform::platf
}


} // namespace


namespace librealsense {


// This singleton creates the actual backend; as long as someone holds it, the backend will stay alive.
// The instance is held below by the device-watcher. I.e., the device-watcher triggers creation of the
// backend!
Expand Down
27 changes: 27 additions & 0 deletions src/platform/backend-device-group.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <functional>
#include <vector>
#include <string>
#include <algorithm>


namespace librealsense {
Expand Down Expand Up @@ -106,6 +107,32 @@ struct backend_device_group

return s;
}


// Returns true if this group is completely accounted for in the right group
//
bool is_contained_in( backend_device_group const & second_data ) const
{
for( auto & uvc : uvc_devices )
{
if( std::find( second_data.uvc_devices.begin(), second_data.uvc_devices.end(), uvc )
== second_data.uvc_devices.end() )
return false;
}
for( auto & usb : usb_devices )
{
if( std::find( second_data.usb_devices.begin(), second_data.usb_devices.end(), usb )
== second_data.usb_devices.end() )
return false;
}
for( auto & hid : hid_devices )
{
if( std::find( second_data.hid_devices.begin(), second_data.hid_devices.end(), hid )
== second_data.hid_devices.end() )
return false;
}
return true;
}
};


Expand Down
10 changes: 10 additions & 0 deletions src/platform/platform-device-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <src/device-info.h>

#include <memory>
#include <vector>


namespace librealsense {
Expand Down Expand Up @@ -59,4 +60,13 @@ class platform_device_info : public device_info


} // namespace platform


// subtract_sets( left, right ) = what is in left that's not in right
//
std::vector< std::shared_ptr< platform::platform_device_info > >
subtract_sets( const std::vector< std::shared_ptr< platform::platform_device_info > > & left,
const std::vector< std::shared_ptr< platform::platform_device_info > > & right );


} // namespace librealsense

0 comments on commit 954033e

Please sign in to comment.