X-Git-Url: http://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdevices%2Fhardwaredevice.cpp;fp=pv%2Fdevices%2Fhardwaredevice.cpp;h=6374dafe6e03aaddb219a05c1fa4c3a21ab71dd5;hp=4fa27f6dd7521e8b8a82433c9b5c940bc4bea435;hb=b485408f20c39ae8d05372a5faffe15653c74705;hpb=da30ecb7e72bd2547e524258efa5ec642988b70b diff --git a/pv/devices/hardwaredevice.cpp b/pv/devices/hardwaredevice.cpp index 4fa27f6d..6374dafe 100644 --- a/pv/devices/hardwaredevice.cpp +++ b/pv/devices/hardwaredevice.cpp @@ -18,14 +18,25 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include #include +#include + #include "hardwaredevice.hpp" +using std::dynamic_pointer_cast; using std::shared_ptr; using std::static_pointer_cast; +using std::string; +using std::vector; + +using boost::algorithm::join; + +using sigrok::HardwareDevice; namespace pv { namespace devices { @@ -42,10 +53,49 @@ HardwareDevice::~HardwareDevice() { session_->remove_devices(); } +string HardwareDevice::full_name() const { + vector parts = {device_->vendor(), device_->model(), + device_->version(), device_->serial_number()}; + if (device_->connection_id().length() > 0) + parts.push_back("(" + device_->connection_id() + ")"); + return join(parts, " "); +} + shared_ptr HardwareDevice::hardware_device() const { return static_pointer_cast(device_); } +string HardwareDevice::display_name( + const DeviceManager &device_manager) const { + const auto hw_dev = hardware_device(); + + // If we can find another device with the same model/vendor then + // we have at least two such devices and need to distinguish them. + const auto &devices = device_manager.devices(); + const bool multiple_dev = hw_dev && any_of( + devices.begin(), devices.end(), + [&](shared_ptr dev) { + return dev->hardware_device()->vendor() == + hw_dev->vendor() && + dev->hardware_device()->model() == + hw_dev->model() && + dev->device_ != device_; + }); + + vector parts = {device_->vendor(), device_->model()}; + + if (multiple_dev) { + parts.push_back(device_->version()); + parts.push_back(device_->serial_number()); + + if ((device_->serial_number().length() == 0) && + (device_->connection_id().length() > 0)) + parts.push_back("(" + device_->connection_id() + ")"); + } + + return join(parts, " "); +} + void HardwareDevice::create() { // Open the device try {