]> sigrok.org Git - pulseview.git/blobdiff - pv/devicemanager.cpp
Trace View: Move ruler time conversion from View to Ruler
[pulseview.git] / pv / devicemanager.cpp
index 35efa12786bb524003bbdbe0ff4eecf54d59927e..5090b480e3d49adc41bc4e861102ce9a6e6bbb8b 100644 (file)
@@ -30,6 +30,7 @@
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
 #include <QApplication>
+#include <QDebug>
 #include <QObject>
 #include <QProgressDialog>
 
@@ -48,8 +49,6 @@ using std::string;
 using std::unique_ptr;
 using std::vector;
 
-using Glib::ustring;
-using Glib::Variant;
 using Glib::VariantBase;
 
 using sigrok::ConfigKey;
@@ -58,7 +57,8 @@ using sigrok::Driver;
 
 namespace pv {
 
-DeviceManager::DeviceManager(shared_ptr<Context> context, std::string driver) :
+DeviceManager::DeviceManager(shared_ptr<Context> context,
+       std::string driver, bool do_scan) :
        context_(context)
 {
        unique_ptr<QProgressDialog> progress(new QProgressDialog("",
@@ -85,7 +85,14 @@ DeviceManager::DeviceManager(shared_ptr<Context> context, std::string driver) :
         * Scan for devices. No specific options apply here, this is
         * best effort auto detection.
         */
-       for (auto entry : context->drivers()) {
+       for (auto& entry : context->drivers()) {
+               if (!do_scan)
+                       break;
+
+               // Skip drivers we won't scan anyway
+               if (!driver_supported(entry.second))
+                       continue;
+
                progress->setLabelText(QObject::tr("Scanning for %1...")
                        .arg(QString::fromStdString(entry.first)));
 
@@ -181,7 +188,7 @@ DeviceManager::drive_scan_options(vector<string> user_spec,
 {
        map<const ConfigKey *, Glib::VariantBase> result;
 
-       for (auto entry : user_spec) {
+       for (auto& entry : user_spec) {
                /*
                 * Split key=value specs. Accept entries without separator
                 * (for simplified boolean specifications).
@@ -217,14 +224,8 @@ DeviceManager::drive_scan_options(vector<string> user_spec,
        return result;
 }
 
-list< shared_ptr<devices::HardwareDevice> >
-DeviceManager::driver_scan(
-       shared_ptr<Driver> driver, map<const ConfigKey *, VariantBase> drvopts)
+bool DeviceManager::driver_supported(shared_ptr<Driver> driver) const
 {
-       list< shared_ptr<devices::HardwareDevice> > driver_devices;
-
-       assert(driver);
-
        /*
         * We currently only support devices that can deliver samples at
         * a fixed samplerate (i.e. oscilloscopes and logic analysers).
@@ -232,9 +233,19 @@ DeviceManager::driver_scan(
         * @todo Add support for non-monotonic devices (DMMs, sensors, etc).
         */
        const auto keys = driver->config_keys();
-       bool supported_device = keys.count(ConfigKey::LOGIC_ANALYZER) |
-               keys.count(ConfigKey::OSCILLOSCOPE);
-       if (!supported_device)
+
+       return keys.count(ConfigKey::LOGIC_ANALYZER) | keys.count(ConfigKey::OSCILLOSCOPE);
+}
+
+list< shared_ptr<devices::HardwareDevice> >
+DeviceManager::driver_scan(
+       shared_ptr<Driver> driver, map<const ConfigKey *, VariantBase> drvopts)
+{
+       list< shared_ptr<devices::HardwareDevice> > driver_devices;
+
+       assert(driver);
+
+       if (!driver_supported(driver))
                return driver_devices;
 
        // Remove any device instances from this driver from the device
@@ -242,21 +253,27 @@ DeviceManager::driver_scan(
        devices_.remove_if([&](shared_ptr<devices::HardwareDevice> device) {
                return device->hardware_device()->driver() == driver; });
 
-       // Do the scan
-       auto devices = driver->scan(drvopts);
+       try {
+               // Do the scan
+               auto devices = driver->scan(drvopts);
 
-       // Add the scanned devices to the main list, set display names and sort.
-       for (shared_ptr<sigrok::HardwareDevice> device : devices) {
-               const shared_ptr<devices::HardwareDevice> d(
-                       new devices::HardwareDevice(context_, device));
-               driver_devices.push_back(d);
-       }
+               // Add the scanned devices to the main list, set display names and sort.
+               for (shared_ptr<sigrok::HardwareDevice>& device : devices) {
+                       const shared_ptr<devices::HardwareDevice> d(
+                               new devices::HardwareDevice(context_, device));
+                       driver_devices.push_back(d);
+               }
+
+               devices_.insert(devices_.end(), driver_devices.begin(),
+                       driver_devices.end());
+               devices_.sort(bind(&DeviceManager::compare_devices, this, _1, _2));
+               driver_devices.sort(bind(
+                       &DeviceManager::compare_devices, this, _1, _2));
 
-       devices_.insert(devices_.end(), driver_devices.begin(),
-               driver_devices.end());
-       devices_.sort(bind(&DeviceManager::compare_devices, this, _1, _2));
-       driver_devices.sort(bind(
-               &DeviceManager::compare_devices, this, _1, _2));
+       } catch (const sigrok::Error &e) {
+               qWarning() << QApplication::tr("Error when scanning device driver '%1': %2").
+                       arg(QString::fromStdString(driver->name()), e.what());
+       }
 
        return driver_devices;
 }