From 602bff3a242a92f74a04ed972082ec740f5cd093 Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Fri, 12 Dec 2014 17:36:02 +0100 Subject: [PATCH 1/1] DeviceManager: Introduce full device names --- pv/devicemanager.cpp | 47 ++++++++++++++++++++++++++++++++++++-------- pv/devicemanager.hpp | 6 +++++- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/pv/devicemanager.cpp b/pv/devicemanager.cpp index 9976d3e6..df0b055c 100644 --- a/pv/devicemanager.cpp +++ b/pv/devicemanager.cpp @@ -94,7 +94,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 +104,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,17 +184,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; + } ostringstream s; + // 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()+")"); + + for (size_t i = 0; i < parts.size(); i++) + { + if (parts[i].length() > 0) + { + if (i != 0) + s << " "; + s << parts[i]; + } + } + + full_names_[device] = s.str(); + + // Next, build the display name. It only contains fields as required. bool multiple_dev = false; // If we can find another device with the same model/vendor then @@ -207,7 +231,9 @@ const string DeviceManager::build_display_name(shared_ptr device) dev != hardware_device; } ); - vector parts = {device->vendor(), device->model()}; + s.str(""); + parts.clear(); + parts = {device->vendor(), device->model()}; if (multiple_dev) { parts.push_back(device->version()); @@ -228,7 +254,7 @@ const string DeviceManager::build_display_name(shared_ptr device) } } - return s.str(); + display_names_[device] = s.str(); } const std::string DeviceManager::get_display_name(std::shared_ptr dev) @@ -236,9 +262,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, diff --git a/pv/devicemanager.hpp b/pv/devicemanager.hpp index fa116223..2ecf54af 100644 --- a/pv/devicemanager.hpp +++ b/pv/devicemanager.hpp @@ -64,10 +64,12 @@ public: const std::shared_ptr find_device_from_info( const std::map search_info); - const std::string build_display_name(std::shared_ptr device); + void build_display_name(std::shared_ptr device); const std::string get_display_name(std::shared_ptr dev); + const std::string get_full_name(std::shared_ptr dev); + void update_display_name(std::shared_ptr dev); private: @@ -77,7 +79,9 @@ private: protected: std::shared_ptr context_; std::list< std::shared_ptr > devices_; + std::map< std::shared_ptr, std::string > display_names_; + std::map< std::shared_ptr, std::string > full_names_; }; } // namespace pv -- 2.30.2