backend-device-group.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2023 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
6 #include "../usb/usb-types.h"
7 #include "../hid/hid-types.h"
8 
9 #include "hid-device-info.h"
10 #include "uvc-device-info.h"
11 
12 #include <memory>
13 #include <functional>
14 #include <vector>
15 #include <string>
16 #include <algorithm>
17 
18 
19 namespace librealsense {
20 
21 
22 template< class T >
24  const std::vector< T > & list1,
25  const std::vector< T > & list2,
26  std::function< bool( T const &, T const & ) > equal = []( T const & first, T const & second ) { return first == second; } )
27 {
28  if( list1.size() != list2.size() )
29  return true;
30 
31  for( auto dev1 : list1 )
32  {
33  bool found = false;
34  for( auto dev2 : list2 )
35  {
36  if( equal( dev1, dev2 ) )
37  found = true;
38  }
39 
40  if( ! found )
41  return true;
42  }
43  return false;
44 }
45 
46 
47 namespace platform {
48 
49 
51 {
53 
54  backend_device_group( const std::vector< uvc_device_info > & uvc_devices,
55  const std::vector< usb_device_info > & usb_devices,
56  const std::vector< hid_device_info > & hid_devices )
60  {
61  }
62 
63  backend_device_group( const std::vector< usb_device_info > & usb_devices )
65  {
66  }
67 
68  backend_device_group( const std::vector< uvc_device_info > & uvc_devices,
69  const std::vector< usb_device_info > & usb_devices )
72  {
73  }
74 
75  std::vector< uvc_device_info > uvc_devices;
76  std::vector< usb_device_info > usb_devices;
77  std::vector< hid_device_info > hid_devices;
78 
79  bool operator==( const backend_device_group & other ) const
80  {
81  return ! list_changed( uvc_devices, other.uvc_devices ) && ! list_changed( hid_devices, other.hid_devices );
82  }
83 
84  operator std::string() const
85  {
86  std::string s;
87  s = uvc_devices.size() > 0 ? "uvc devices:\n" : "";
88  for( auto uvc : uvc_devices )
89  {
90  s += uvc;
91  s += "\n\n";
92  }
93 
94  s += usb_devices.size() > 0 ? "usb devices:\n" : "";
95  for( auto usb : usb_devices )
96  {
97  s += usb;
98  s += "\n\n";
99  }
100 
101  s += hid_devices.size() > 0 ? "hid devices: \n" : "";
102  for( auto hid : hid_devices )
103  {
104  s += hid;
105  s += "\n\n";
106  }
107 
108  return s;
109  }
110 
111 
112  // Returns true if this group is completely accounted for in the right group
113  //
114  bool is_contained_in( backend_device_group const & second_data ) const
115  {
116  for( auto & uvc : uvc_devices )
117  {
118  if( std::find( second_data.uvc_devices.begin(), second_data.uvc_devices.end(), uvc )
119  == second_data.uvc_devices.end() )
120  return false;
121  }
122  for( auto & usb : usb_devices )
123  {
124  if( std::find( second_data.usb_devices.begin(), second_data.usb_devices.end(), usb )
125  == second_data.usb_devices.end() )
126  return false;
127  }
128  for( auto & hid : hid_devices )
129  {
130  if( std::find( second_data.hid_devices.begin(), second_data.hid_devices.end(), hid )
131  == second_data.hid_devices.end() )
132  return false;
133  }
134  return true;
135  }
136 };
137 
138 
139 } // namespace platform
140 } // namespace librealsense
librealsense
Definition: algo.h:18
rspy.file.find
def find(dir, mask)
Definition: file.py:45
hid-device-info.h
string
GLsizei const GLchar *const * string
Definition: glad/glad/glad.h:2861
librealsense::list_changed
bool list_changed(const std::vector< T > &list1, const std::vector< T > &list2, std::function< bool(T const &, T const &) > equal=[](T const &first, T const &second) { return first==second;})
Definition: backend-device-group.h:23
librealsense::platform::backend_device_group
Definition: backend-device-group.h:50
librealsense::platform::backend_device_group::backend_device_group
backend_device_group(const std::vector< uvc_device_info > &uvc_devices, const std::vector< usb_device_info > &usb_devices, const std::vector< hid_device_info > &hid_devices)
Definition: backend-device-group.h:54
librealsense::platform::backend_device_group::usb_devices
std::vector< usb_device_info > usb_devices
Definition: backend-device-group.h:76
uvc-device-info.h
librealsense::platform::backend_device_group::backend_device_group
backend_device_group()
Definition: backend-device-group.h:52
librealsense::platform::backend_device_group::backend_device_group
backend_device_group(const std::vector< uvc_device_info > &uvc_devices, const std::vector< usb_device_info > &usb_devices)
Definition: backend-device-group.h:68
librealsense::platform::backend_device_group::hid_devices
std::vector< hid_device_info > hid_devices
Definition: backend-device-group.h:77
librealsense::platform::backend_device_group::uvc_devices
std::vector< uvc_device_info > uvc_devices
Definition: backend-device-group.h:75
first
GLint first
Definition: glad/glad/glad.h:2301
librealsense::platform::backend_device_group::backend_device_group
backend_device_group(const std::vector< usb_device_info > &usb_devices)
Definition: backend-device-group.h:63
librealsense::platform::backend_device_group::is_contained_in
bool is_contained_in(backend_device_group const &second_data) const
Definition: backend-device-group.h:114
librealsense::platform::backend_device_group::operator==
bool operator==(const backend_device_group &other) const
Definition: backend-device-group.h:79
s
GLdouble s
Definition: glad/glad/glad.h:2441


librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Fri Aug 2 2024 08:30:01