X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdevicemanager.cpp;h=0c6c354fe6f12e14c06a7cfa955464b8049f4088;hp=2f446c45115a8b0ce0d94d5c0b9f344a2e962782;hb=6e2c3c855dff36f6e946e2a54d576bea699f4a61;hpb=8dbbc7f0b9ea59d0f0d62225772f8a56eee125f5 diff --git a/pv/devicemanager.cpp b/pv/devicemanager.cpp index 2f446c45..0c6c354f 100644 --- a/pv/devicemanager.cpp +++ b/pv/devicemanager.cpp @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "devicemanager.h" -#include "sigsession.h" +#include "devicemanager.hpp" +#include "session.hpp" #include #include @@ -29,12 +29,14 @@ #include +#include #include +using boost::algorithm::join; + using std::dynamic_pointer_cast; using std::list; using std::map; -using std::ostringstream; using std::remove_if; using std::runtime_error; using std::shared_ptr; @@ -94,7 +96,7 @@ list< shared_ptr > DeviceManager::driver_scan( driver_devices.end()); for (shared_ptr device : devices_) - display_names_[device] = build_display_name(device); + build_display_name(device); devices_.sort([&](shared_ptr a, shared_ptr b) { return compare_devices(a, b); }); @@ -104,7 +106,7 @@ list< shared_ptr > DeviceManager::driver_scan( // recomute all names of the devices_ list since only the // devices that use the given driver can be affected. for (shared_ptr device : driver_devices) - display_names_[device] = build_display_name(device); + build_display_name(device); driver_devices.sort([&](shared_ptr a, shared_ptr b) { return compare_devices(a, b); }); @@ -184,30 +186,41 @@ const shared_ptr DeviceManager::find_device_from_info( return last_resort_dev; } -const string DeviceManager::build_display_name(shared_ptr device) +void DeviceManager::build_display_name(shared_ptr device) { auto session_device = dynamic_pointer_cast(device); auto hardware_device = dynamic_pointer_cast(device); - if (session_device) - return boost::filesystem::path( + if (session_device) { + full_names_[device] = display_names_[device] = + boost::filesystem::path( session_device->parent()->filename()).filename().string(); + return; + } + + // First, build the device's full name. It always contains all + // possible information. + vector parts = {device->vendor(), device->model(), + device->version(), device->serial_number()}; + + if (device->connection_id().length() > 0) + parts.push_back("("+device->connection_id()+")"); - ostringstream s; + full_names_[device] = join(parts, " "); - bool multiple_dev = false; + // Next, build the display name. It only contains fields as required. // If we can find another device with the same model/vendor then // we have at least two such devices and need to distinguish them. - if (hardware_device) - multiple_dev = any_of(devices_.begin(), devices_.end(), - [&](shared_ptr dev) { + const bool multiple_dev = hardware_device && any_of( + devices_.begin(), devices_.end(), + [&](shared_ptr dev) { return (dev->vendor() == hardware_device->vendor() && - dev->model() == hardware_device->model()) && - dev != hardware_device; - } ); + dev->model() == hardware_device->model()) && + dev != hardware_device; + } ); - vector parts = {device->vendor(), device->model()}; + parts = {device->vendor(), device->model()}; if (multiple_dev) { parts.push_back(device->version()); @@ -218,17 +231,7 @@ const string DeviceManager::build_display_name(shared_ptr device) parts.push_back("("+device->connection_id()+")"); } - for (size_t i = 0; i < parts.size(); i++) - { - if (parts[i].length() > 0) - { - if (i != 0) - s << " "; - s << parts[i]; - } - } - - return s.str(); + display_names_[device] = join(parts, " "); } const std::string DeviceManager::get_display_name(std::shared_ptr dev) @@ -236,9 +239,14 @@ const std::string DeviceManager::get_display_name(std::shared_ptr dev) +{ + return full_names_[dev]; +} + void DeviceManager::update_display_name(std::shared_ptr dev) { - display_names_[dev] = build_display_name(dev); + build_display_name(dev); } bool DeviceManager::compare_devices(shared_ptr a,