]> sigrok.org Git - pulseview.git/blobdiff - pv/dialogs/connect.cpp
Rename 'probe' to 'channel' (libsigrokdecode change).
[pulseview.git] / pv / dialogs / connect.cpp
index 02941f2f6785e02efcff07a80a6520c16d8e36d2..d5ab9c4789f6dd9d79b4e601518bc9c4cd27bc44 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <boost/foreach.hpp>
+
+#include <libsigrok/libsigrok.h>
+
 #include "connect.h"
 
+#include "pv/devicemanager.h"
+#include "pv/device/device.h"
+
 extern "C" {
 /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
 #define __STDC_FORMAT_MACROS
@@ -27,13 +34,18 @@ extern "C" {
 #include <libsigrok/libsigrok.h>
 }
 
+using boost::shared_ptr;
+using std::list;
+using std::string;
+
 extern sr_context *sr_ctx;
 
 namespace pv {
 namespace dialogs {
 
-Connect::Connect(QWidget *parent) :
+Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
        QDialog(parent),
+       _device_manager(device_manager),
        _layout(this),
        _form(this),
        _form_layout(&_form),
@@ -70,13 +82,21 @@ Connect::Connect(QWidget *parent) :
        _layout.addWidget(&_button_box);
 }
 
-struct sr_dev_inst* Connect::get_selected_device() const
+shared_ptr<device::Device> Connect::get_selected_device() const
 {
        const QListWidgetItem *const item = _device_list.currentItem();
        if (!item)
-               return NULL;
+               return shared_ptr<device::Device>();
+
+       const sr_dev_inst *const sdi = (sr_dev_inst*)item->data(
+               Qt::UserRole).value<void*>();
+       assert(sdi);
 
-       return (sr_dev_inst*)item->data(Qt::UserRole).value<void*>();
+       std::map<const sr_dev_inst*, boost::shared_ptr<pv::device::Device> >::
+               const_iterator iter = _device_map.find(sdi);
+       assert(iter != _device_map.end());
+
+       return (*iter).second;
 }
 
 void Connect::populate_drivers()
@@ -95,8 +115,8 @@ void Connect::populate_drivers()
                 * and sensors.
                 */
                bool supported_device = false;
-               if ((sr_config_list(drivers[i], SR_CONF_DEVICE_OPTIONS,
-                               &gvar_opts, NULL) == SR_OK)) {
+               if ((sr_config_list(drivers[i], NULL, NULL,
+                               SR_CONF_DEVICE_OPTIONS, &gvar_opts) == SR_OK)) {
                        hwopts = (const int32_t *)g_variant_get_fixed_array(gvar_opts,
                                        &num_opts, sizeof(int32_t));
                        for (unsigned int j = 0; j < num_opts; j++)
@@ -116,6 +136,7 @@ void Connect::populate_drivers()
 void Connect::unset_connection()
 {
        _device_list.clear();
+       _device_map.clear();
        _serial_device.hide();
        _form_layout.labelForField(&_serial_device)->hide();
        _button_box.button(QDialogButtonBox::Ok)->setDisabled(true);
@@ -130,6 +151,7 @@ void Connect::set_serial_connection()
 void Connect::scan_pressed()
 {
        _device_list.clear();
+       _device_map.clear();
 
        const int index = _drivers.currentIndex();
        if (index == -1)
@@ -148,35 +170,34 @@ void Connect::scan_pressed()
                drvopts = g_slist_append(drvopts, src);
        }
 
-       GSList *const devices = sr_driver_scan(driver, drvopts);
+       const list< shared_ptr<device::Device> > devices =
+               _device_manager.driver_scan(driver, drvopts);
+
+       g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
 
-       for (GSList *l = devices; l; l = l->next) {
+       BOOST_FOREACH(shared_ptr<device::Device> dev_inst, devices)
+       {
+               assert(dev_inst);
+               const sr_dev_inst *const sdi = dev_inst->dev_inst();
+               assert(sdi);
 
-               sr_dev_inst *const sdi = (sr_dev_inst*)l->data;
+               const string title = dev_inst->format_device_title();
+               QString text = QString::fromUtf8(title.c_str());
 
-               QString text;
-               if (sdi->vendor && sdi->vendor[0])
-                       text += QString("%1 ").arg(sdi->vendor);
-               if (sdi->model && sdi->model[0])
-                       text += QString("%1 ").arg(sdi->model);
-               if (sdi->version && sdi->version[0])
-                       text += QString("%1 ").arg(sdi->version);
-               if (sdi->probes) {
-                       text += QString("with %1 probes").arg(
-                               g_slist_length(sdi->probes));
+               if (sdi->channels) {
+                       text += QString(" with %1 channels").arg(
+                               g_slist_length(sdi->channels));
                }
 
                QListWidgetItem *const item = new QListWidgetItem(text,
                        &_device_list);
                item->setData(Qt::UserRole, qVariantFromValue((void*)sdi));
                _device_list.addItem(item);
+               _device_map[sdi] = dev_inst;
        }
 
-       g_slist_free(devices);
-       g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
-
        _device_list.setCurrentRow(0);
-       _button_box.button(QDialogButtonBox::Ok)->setDisabled(false);
+       _button_box.button(QDialogButtonBox::Ok)->setDisabled(_device_list.count() == 0);
 }
 
 void Connect::device_selected(int index)
@@ -189,8 +210,8 @@ void Connect::device_selected(int index)
 
        unset_connection();
 
-       if ((sr_config_list(driver, SR_CONF_SCAN_OPTIONS,
-                               &gvar_list, NULL) == SR_OK)) {
+       if ((sr_config_list(driver, NULL, NULL,
+                               SR_CONF_SCAN_OPTIONS, &gvar_list) == SR_OK)) {
                hwopts = (const int32_t *)g_variant_get_fixed_array(gvar_list,
                                &num_opts, sizeof(int32_t));