X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdevicemanager.cpp;h=ebf140fd725c793f340e089cbb49d412a0348297;hp=15e791e128eb8e542ec705459be51d4ec41dd5ba;hb=b571a8e7e0dc3e3b6daa58f27050e76466f006dd;hpb=58d8e4c6c50bb119d405d754a6fb122d932d6510 diff --git a/pv/devicemanager.cpp b/pv/devicemanager.cpp index 15e791e1..ebf140fd 100644 --- a/pv/devicemanager.cpp +++ b/pv/devicemanager.cpp @@ -48,8 +48,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 +56,8 @@ using sigrok::Driver; namespace pv { -DeviceManager::DeviceManager(shared_ptr context, std::string driver) : +DeviceManager::DeviceManager(shared_ptr context, + std::string driver, bool do_scan) : context_(context) { unique_ptr progress(new QProgressDialog("", @@ -85,7 +84,14 @@ DeviceManager::DeviceManager(shared_ptr 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))); @@ -170,10 +176,10 @@ DeviceManager::user_spec_device() const /** * Convert generic options to data types that are specific to Driver::scan(). * - * @param[in] user_spec vector of tokenized words, string format - * @param[in] driver_opts driver's scan options, result of Driver::scan_options() + * @param[in] user_spec Vector of tokenized words, string format. + * @param[in] driver_opts Driver's scan options, result of Driver::scan_options(). * - * @return map of options suitable for Driver::scan() + * @return Map of options suitable for Driver::scan(). */ map DeviceManager::drive_scan_options(vector user_spec, @@ -181,7 +187,7 @@ DeviceManager::drive_scan_options(vector user_spec, { map 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 +223,8 @@ DeviceManager::drive_scan_options(vector user_spec, return result; } -list< shared_ptr > -DeviceManager::driver_scan( - shared_ptr driver, map drvopts) +bool DeviceManager::driver_supported(shared_ptr driver) const { - list< shared_ptr > 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 +232,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 > +DeviceManager::driver_scan( + shared_ptr driver, map drvopts) +{ + list< shared_ptr > driver_devices; + + assert(driver); + + if (!driver_supported(driver)) return driver_devices; // Remove any device instances from this driver from the device @@ -246,7 +256,7 @@ DeviceManager::driver_scan( auto devices = driver->scan(drvopts); // Add the scanned devices to the main list, set display names and sort. - for (shared_ptr device : devices) { + for (shared_ptr& device : devices) { const shared_ptr d( new devices::HardwareDevice(context_, device)); driver_devices.push_back(d);