diff --git a/src/backend-device-factory.cpp b/src/backend-device-factory.cpp index 857b2bb34a..c05d928df2 100644 --- a/src/backend-device-factory.cpp +++ b/src/backend-device-factory.cpp @@ -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() ) { @@ -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! diff --git a/src/platform/backend-device-group.h b/src/platform/backend-device-group.h index c992f2210b..24a535cf35 100644 --- a/src/platform/backend-device-group.h +++ b/src/platform/backend-device-group.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace librealsense { @@ -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; + } }; diff --git a/src/platform/platform-device-info.h b/src/platform/platform-device-info.h index b22e6e47eb..74254cce5c 100644 --- a/src/platform/platform-device-info.h +++ b/src/platform/platform-device-info.h @@ -7,6 +7,7 @@ #include #include +#include namespace librealsense { @@ -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