]> sigrok.org Git - pulseview.git/blobdiff - pv/devicemanager.cpp
device manager: Move filter for supported devices to the scan routine
[pulseview.git] / pv / devicemanager.cpp
index b11e60c7705a3c89f137047d903b164de08521c1..ac6ce6fb433da3fa29eefa9ba551c043c70f63b5 100644 (file)
@@ -14,8 +14,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "devicemanager.hpp"
 
 #include <cassert>
 #include <functional>
-#include <stdexcept>
+#include <memory>
 #include <sstream>
+#include <stdexcept>
 #include <string>
-#include <vector>
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
-#include <boost/algorithm/string/join.hpp>
+#include <QApplication>
+#include <QObject>
+#include <QProgressDialog>
+
 #include <boost/filesystem.hpp>
 
 #include <pv/devices/hardwaredevice.hpp>
 
-using boost::algorithm::join;
-
 using std::bind;
-using std::dynamic_pointer_cast;
 using std::list;
 using std::map;
 using std::placeholders::_1;
 using std::placeholders::_2;
-using std::remove_if;
-using std::runtime_error;
 using std::shared_ptr;
 using std::string;
-using std::vector;
+using std::unique_ptr;
 
 using Glib::VariantBase;
 
 using sigrok::ConfigKey;
 using sigrok::Context;
 using sigrok::Driver;
-using sigrok::SessionDevice;
 
 namespace pv {
 
 DeviceManager::DeviceManager(shared_ptr<Context> context) :
        context_(context)
 {
-       for (auto entry : context->drivers())
+       unique_ptr<QProgressDialog> progress(new QProgressDialog("",
+               QObject::tr("Cancel"), 0, context->drivers().size()));
+       progress->setWindowModality(Qt::WindowModal);
+       progress->setMinimumDuration(1);  // To show the dialog immediately
+
+       int entry_num = 1;
+
+       for (auto entry : context->drivers()) {
+               progress->setLabelText(QObject::tr("Scanning for %1...")
+                       .arg(QString::fromStdString(entry.first)));
+
                driver_scan(entry.second, map<const ConfigKey *, VariantBase>());
-}
 
-DeviceManager::~DeviceManager()
-{
+               progress->setValue(entry_num++);
+               QApplication::processEvents();
+               if (progress->wasCanceled())
+                       break;
+       }
 }
 
-const std::shared_ptr<sigrok::Context>& DeviceManager::context() const
+const shared_ptr<sigrok::Context>& DeviceManager::context() const
 {
        return context_;
 }
@@ -93,6 +101,18 @@ DeviceManager::driver_scan(
 
        assert(driver);
 
+       /*
+        * We currently only support devices that can deliver samples at
+        * a fixed samplerate (i.e. oscilloscopes and logic analysers).
+        *
+        * @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 driver_devices;
+
        // Remove any device instances from this driver from the device
        // list. They will not be valid after the scan.
        devices_.remove_if([&](shared_ptr<devices::HardwareDevice> device) {