* 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
#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),
_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()
* 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++)
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);
void Connect::scan_pressed()
{
_device_list.clear();
+ _device_map.clear();
const int index = _drivers.currentIndex();
if (index == -1)
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(
+ text += QString(" with %1 probes").arg(
g_slist_length(sdi->probes));
}
&_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)
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));