set(pulseview_SOURCES
main.cpp
pv/devicemanager.cpp
+ pv/devinst.cpp
pv/mainwindow.cpp
pv/sigsession.cpp
pv/storesession.cpp
*/
#include "devicemanager.h"
+#include "devinst.h"
#include "sigsession.h"
#include <cassert>
-#include <sstream>
#include <stdexcept>
#include <string>
#include <libsigrok/libsigrok.h>
+using boost::shared_ptr;
using std::list;
using std::map;
using std::ostringstream;
release_devices();
}
-const std::list<sr_dev_inst*>& DeviceManager::devices() const
+const list< shared_ptr<pv::DevInst> >& DeviceManager::devices() const
{
return _devices;
}
-void DeviceManager::use_device(sr_dev_inst *sdi, SigSession *owner)
+void DeviceManager::use_device(shared_ptr<DevInst> dev_inst, SigSession *owner)
{
- assert(sdi);
+ assert(dev_inst);
assert(owner);
- _used_devices[sdi] = owner;
+ _used_devices[dev_inst] = owner;
- sr_dev_open(sdi);
+ sr_dev_open(dev_inst->dev_inst());
}
-void DeviceManager::release_device(sr_dev_inst *sdi)
+void DeviceManager::release_device(shared_ptr<DevInst> dev_inst)
{
- assert(sdi);
+ assert(dev_inst);
- // Notify the owner, and removed the device from the used device list
- _used_devices[sdi]->release_device(sdi);
- _used_devices.erase(sdi);
+ // Notify the owner, and remove the device from the used device list
+ map< shared_ptr<DevInst>, pv::SigSession*>::const_iterator iter =
+ _used_devices.find(dev_inst);
+ assert(iter != _used_devices.end());
- sr_dev_close(sdi);
+ (*iter).second->release_device(dev_inst);
+ _used_devices.erase(dev_inst);
}
-list<sr_dev_inst*> DeviceManager::driver_scan(
+list< shared_ptr<DevInst> > DeviceManager::driver_scan(
struct sr_dev_driver *const driver, GSList *const drvopts)
{
- list<sr_dev_inst*> driver_devices;
+ list< shared_ptr<DevInst> > driver_devices;
assert(driver);
// Remove any device instances from this driver from the device
// list. They will not be valid after the scan.
- list<sr_dev_inst*>::iterator i = _devices.begin();
+ list< shared_ptr<DevInst> >::iterator i = _devices.begin();
while (i != _devices.end()) {
- if ((*i)->driver == driver)
+ if ((*i)->dev_inst()->driver == driver)
i = _devices.erase(i);
else
i++;
// Do the scan
GSList *const devices = sr_driver_scan(driver, drvopts);
for (GSList *l = devices; l; l = l->next)
- driver_devices.push_back((sr_dev_inst*)l->data);
+ driver_devices.push_back(shared_ptr<DevInst>(
+ new DevInst((sr_dev_inst*)l->data)));
g_slist_free(devices);
driver_devices.sort(compare_devices);
return driver_devices;
}
-string DeviceManager::format_device_title(const sr_dev_inst *const sdi)
-{
- ostringstream s;
-
- assert(sdi);
-
- if (sdi->vendor && sdi->vendor[0]) {
- s << sdi->vendor;
- if ((sdi->model && sdi->model[0]) ||
- (sdi->version && sdi->version[0]))
- s << ' ';
- }
-
- if (sdi->model && sdi->model[0]) {
- s << sdi->model;
- if (sdi->version && sdi->version[0])
- s << ' ';
- }
-
- if (sdi->version && sdi->version[0])
- s << sdi->version;
-
- return s.str();
-}
-
void DeviceManager::init_drivers()
{
// Initialise all libsigrok drivers
void DeviceManager::release_devices()
{
// Release all the used devices
- for (map<sr_dev_inst*, SigSession*>::iterator i = _used_devices.begin();
- i != _used_devices.end(); i++)
+ for (map<shared_ptr<DevInst>, SigSession*>::iterator i =
+ _used_devices.begin(); i != _used_devices.end(); i++)
release_device((*i).first);
_used_devices.clear();
void DeviceManager::release_driver(struct sr_dev_driver *const driver)
{
assert(driver);
- for (map<sr_dev_inst*, SigSession*>::iterator i = _used_devices.begin();
- i != _used_devices.end(); i++)
- if((*i).first->driver == driver)
+ for (map<shared_ptr<DevInst>, SigSession*>::iterator i =
+ _used_devices.begin(); i != _used_devices.end(); i++)
+ if((*i).first->dev_inst()->driver == driver)
{
// Notify the current owner of the device
(*i).second->release_device((*i).first);
_used_devices.erase(i);
// Close the device instance
- sr_dev_close((*i).first);
+ sr_dev_close((*i).first->dev_inst());
}
// Clear all the old device instances from this driver
sr_dev_clear(driver);
}
-bool DeviceManager::compare_devices(const sr_dev_inst *const a,
- const sr_dev_inst *const b)
+bool DeviceManager::compare_devices(shared_ptr<DevInst> a,
+ shared_ptr<DevInst> b)
{
- return format_device_title(a).compare(format_device_title(b)) < 0;
+ assert(a);
+ assert(b);
+ return a->format_device_title().compare(b->format_device_title()) < 0;
}
} // namespace pv
#include <map>
#include <string>
+#include <boost/shared_ptr.hpp>
+
struct sr_context;
struct sr_dev_driver;
-struct sr_dev_inst;
namespace pv {
+class DevInst;
class SigSession;
class DeviceManager
~DeviceManager();
- const std::list<sr_dev_inst*>& devices() const;
+ const std::list< boost::shared_ptr<pv::DevInst> >& devices() const;
- void use_device(sr_dev_inst *sdi, SigSession *owner);
+ void use_device(boost::shared_ptr<pv::DevInst> dev_inst,
+ SigSession *owner);
- void release_device(sr_dev_inst *sdi);
+ void release_device(boost::shared_ptr<pv::DevInst> dev_inst);
- std::list<sr_dev_inst*> driver_scan(
+ std::list< boost::shared_ptr<DevInst> > driver_scan(
struct sr_dev_driver *const driver,
GSList *const drvopts = NULL);
- static std::string format_device_title(const sr_dev_inst *const sdi);
-
private:
void init_drivers();
void release_driver(struct sr_dev_driver *const driver);
- static bool compare_devices(const sr_dev_inst *const a,
- const sr_dev_inst *const b);
+ static bool compare_devices(boost::shared_ptr<DevInst> a,
+ boost::shared_ptr<DevInst> b);
private:
struct sr_context *const _sr_ctx;
- std::list<sr_dev_inst*> _devices;
- std::map<sr_dev_inst*, pv::SigSession*> _used_devices;
+ std::list< boost::shared_ptr<pv::DevInst> > _devices;
+ std::map< boost::shared_ptr<pv::DevInst>, pv::SigSession*>
+ _used_devices;
};
} // namespace pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * 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
+ */
+
+#include <cassert>
+#include <sstream>
+
+#include <libsigrok/libsigrok.h>
+
+#include "devinst.h"
+
+using std::ostringstream;
+using std::string;
+
+namespace pv {
+
+DevInst::DevInst(sr_dev_inst *sdi) :
+ _sdi(sdi)
+{
+ assert(_sdi);
+}
+
+sr_dev_inst* DevInst::dev_inst() const
+{
+ return _sdi;
+}
+
+string DevInst::format_device_title() const
+{
+ ostringstream s;
+
+ assert(_sdi);
+
+ if (_sdi->vendor && _sdi->vendor[0]) {
+ s << _sdi->vendor;
+ if ((_sdi->model && _sdi->model[0]) ||
+ (_sdi->version && _sdi->version[0]))
+ s << ' ';
+ }
+
+ if (_sdi->model && _sdi->model[0]) {
+ s << _sdi->model;
+ if (_sdi->version && _sdi->version[0])
+ s << ' ';
+ }
+
+ if (_sdi->version && _sdi->version[0])
+ s << _sdi->version;
+
+ return s.str();
+}
+
+} // pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * 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
+ */
+
+#ifndef PULSEVIEW_PV_DEVINST_H
+#define PULSEVIEW_PV_DEVINST_H
+
+#include <string>
+
+#include <boost/shared_ptr.hpp>
+
+struct sr_dev_inst;
+
+namespace pv {
+
+class DevInst
+{
+public:
+ DevInst(sr_dev_inst *sdi);
+
+ sr_dev_inst* dev_inst() const;
+
+ std::string format_device_title() const;
+
+private:
+ sr_dev_inst *const _sdi;
+};
+
+} // pv
+
+#endif // PULSEVIEW_PV_DEVINST_H
#include <boost/foreach.hpp>
+#include <libsigrok/libsigrok.h>
+
#include "connect.h"
#include "pv/devicemanager.h"
+#include "pv/devinst.h"
extern "C" {
/* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
#include <libsigrok/libsigrok.h>
}
+using boost::shared_ptr;
using std::list;
using std::string;
_layout.addWidget(&_button_box);
}
-struct sr_dev_inst* Connect::get_selected_device() const
+shared_ptr<DevInst> Connect::get_selected_device() const
{
const QListWidgetItem *const item = _device_list.currentItem();
if (!item)
- return NULL;
+ return shared_ptr<DevInst>();
+
+ 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::DevInst> >::
+ const_iterator iter = _device_map.find(sdi);
+ assert(iter != _device_map.end());
+
+ return (*iter).second;
}
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);
void Connect::scan_pressed()
{
_device_list.clear();
+ _device_map.clear();
const int index = _drivers.currentIndex();
if (index == -1)
drvopts = g_slist_append(drvopts, src);
}
- const list<sr_dev_inst*> devices = _device_manager.driver_scan(
+ const list< shared_ptr<DevInst> > devices = _device_manager.driver_scan(
driver, drvopts);
g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
- BOOST_FOREACH(sr_dev_inst *const sdi, devices)
+ BOOST_FOREACH(shared_ptr<DevInst> dev_inst, devices)
{
- const string title = DeviceManager::format_device_title(sdi);
+ assert(dev_inst);
+ const sr_dev_inst *const sdi = dev_inst->dev_inst();
+ assert(sdi);
+
+ const string title = dev_inst->format_device_title();
QString text = QString::fromUtf8(title.c_str());
+
if (sdi->probes) {
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;
}
_device_list.setCurrentRow(0);
#ifndef PULSEVIEW_PV_CONNECT_H
#define PULSEVIEW_PV_CONNECT_H
+#include <boost/shared_ptr.hpp>
+
#include <QComboBox>
#include <QDialog>
#include <QDialogButtonBox>
namespace pv {
class DeviceManager;
+class DevInst;
namespace dialogs {
public:
Connect(QWidget *parent, pv::DeviceManager &device_manager);
- struct sr_dev_inst* get_selected_device() const;
+ boost::shared_ptr<DevInst> get_selected_device() const;
private:
void populate_drivers();
QPushButton _scan_button;
QListWidget _device_list;
+ std::map<const sr_dev_inst*, boost::shared_ptr<pv::DevInst> >
+ _device_map;
QDialogButtonBox _button_box;
};
#include "mainwindow.h"
#include "devicemanager.h"
+#include "devinst.h"
#include "dialogs/about.h"
#include "dialogs/connect.h"
#include "dialogs/storeprogress.h"
#include <glib.h>
#include <libsigrok/libsigrok.h>
+using boost::shared_ptr;
using std::list;
namespace pv {
Q_ARG(QString, info_text));
}
-void MainWindow::update_device_list(struct sr_dev_inst *selected_device)
+void MainWindow::update_device_list(shared_ptr<pv::DevInst> selected_device)
{
assert(_sampling_bar);
- const list<sr_dev_inst*> &devices = _device_manager.devices();
+ const list< shared_ptr<DevInst> > &devices = _device_manager.devices();
_sampling_bar->set_device_list(devices);
if (!selected_device && !devices.empty()) {
selected_device = devices.front();
// Try and find the demo device and select that by default
- BOOST_FOREACH (struct sr_dev_inst *sdi, devices)
- if (strcmp(sdi->driver->name, "demo") == 0) {
- selected_device = sdi;
+ BOOST_FOREACH (shared_ptr<pv::DevInst> dev_inst, devices)
+ if (strcmp(dev_inst->dev_inst()->driver->name,
+ "demo") == 0) {
+ selected_device = dev_inst;
}
}
// If the user selected a device, select it in the device list. Select the
// current device otherwise.
- struct sr_dev_inst *const sdi = dlg.exec() ?
+ shared_ptr<DevInst> dev_inst = dlg.exec() ?
dlg.get_selected_device() : _session.get_device();
- update_device_list(sdi);
+ update_device_list(dev_inst);
}
void MainWindow::on_actionQuit_triggered()
namespace pv {
class DeviceManager;
+class DevInst;
namespace toolbars {
class ContextBar;
* first device in the device list should be selected.
*/
void update_device_list(
- struct sr_dev_inst *selected_device = NULL);
+ boost::shared_ptr<pv::DevInst> selected_device =
+ boost::shared_ptr<pv::DevInst>());
private slots:
void load_file(QString file_name);
#include <pv/prop/property.h>
+using boost::shared_ptr;
+
namespace pv {
namespace popups {
-DeviceOptions::DeviceOptions(sr_dev_inst *sdi, QWidget *parent) :
+DeviceOptions::DeviceOptions(shared_ptr<DevInst> dev_inst, QWidget *parent) :
Popup(parent),
- _sdi(sdi),
+ _dev_inst(dev_inst),
_layout(this),
- _binding(sdi)
+ _binding(dev_inst)
{
setLayout(&_layout);
Q_OBJECT
public:
- DeviceOptions(sr_dev_inst *sdi, QWidget *parent);
+ DeviceOptions(boost::shared_ptr<DevInst> dev_inst, QWidget *parent);
pv::prop::binding::DeviceOptions& binding();
private:
- sr_dev_inst *const _sdi;
+ boost::shared_ptr<DevInst> _dev_inst;
QVBoxLayout _layout;
#include "probes.h"
+#include <pv/devinst.h>
#include <pv/prop/binding/deviceoptions.h>
#include <pv/sigsession.h>
#include <pv/view/signal.h>
// Create the layout
setLayout(&_layout);
- sr_dev_inst *const sdi = _session.get_device();
+ shared_ptr<DevInst> dev_inst = _session.get_device();
+ assert(dev_inst);
+ const sr_dev_inst *const sdi = dev_inst->dev_inst();
assert(sdi);
// Collect a set of signals
#include "deviceoptions.h"
+#include <pv/devinst.h>
#include <pv/prop/bool.h>
#include <pv/prop/double.h>
#include <pv/prop/enum.h>
#include <pv/prop/int.h>
+#include <libsigrok/libsigrok.h>
+
using boost::bind;
using boost::function;
using boost::optional;
namespace prop {
namespace binding {
-DeviceOptions::DeviceOptions(const sr_dev_inst *sdi,
+DeviceOptions::DeviceOptions(shared_ptr<pv::DevInst> dev_inst,
const sr_probe_group *group) :
- _sdi(sdi),
+ _dev_inst(dev_inst),
_group(group)
{
+ assert(dev_inst);
+ sr_dev_inst *const sdi = dev_inst->dev_inst();
assert(sdi);
GVariant *gvar_opts, *gvar_list;
const int key = info->key;
- if (sr_config_list(_sdi->driver, _sdi, group,
+ if (sr_config_list(sdi->driver, sdi, group,
key, &gvar_list) != SR_OK)
gvar_list = NULL;
void DeviceOptions::bind_bool(const QString &name, int key)
{
+ sr_dev_inst *const sdi = _dev_inst->dev_inst();
+ assert(sdi);
+
_properties.push_back(shared_ptr<Property>(
- new Bool(name, bind(config_getter, _sdi, _group, key),
- bind(config_setter, _sdi, _group, key, _1))));
+ new Bool(name, bind(config_getter, sdi, _group, key),
+ bind(config_setter, sdi, _group, key, _1))));
}
void DeviceOptions::bind_enum(const QString &name, int key,
assert(gvar_list);
+ sr_dev_inst *const sdi = _dev_inst->dev_inst();
+ assert(sdi);
+
g_variant_iter_init (&iter, gvar_list);
while ((gvar = g_variant_iter_next_value (&iter)))
values.push_back(make_pair(gvar, printer(gvar)));
_properties.push_back(shared_ptr<Property>(
new Enum(name, values,
- bind(config_getter, _sdi, _group, key),
- bind(config_setter, _sdi, _group, key, _1))));
+ bind(config_getter, sdi, _group, key),
+ bind(config_setter, sdi, _group, key, _1))));
}
void DeviceOptions::bind_int(const QString &name, int key, QString suffix,
optional< std::pair<int64_t, int64_t> > range)
{
+ sr_dev_inst *const sdi = _dev_inst->dev_inst();
+ assert(sdi);
+
_properties.push_back(shared_ptr<Property>(
new Int(name, suffix, range,
- bind(config_getter, _sdi, _group, key),
- bind(config_setter, _sdi, _group, key, _1))));
+ bind(config_getter, sdi, _group, key),
+ bind(config_setter, sdi, _group, key, _1))));
}
QString DeviceOptions::print_gvariant(GVariant *const gvar)
#include <QString>
-#include <libsigrok/libsigrok.h>
-
#include "binding.h"
+#include <glib.h>
+
+struct sr_dev_inst;
+struct sr_probe_group;
+
namespace pv {
+
+class DevInst;
+
namespace prop {
namespace binding {
class DeviceOptions : public Binding
{
public:
- DeviceOptions(const sr_dev_inst *sdi,
+ DeviceOptions(boost::shared_ptr<pv::DevInst> dev_inst,
const sr_probe_group *group = NULL);
private:
static QString print_voltage_threshold(GVariant *const gvar);
protected:
- const sr_dev_inst *const _sdi;
+ boost::shared_ptr<DevInst> _dev_inst;
const sr_probe_group *const _group;
};
#include "sigsession.h"
#include "devicemanager.h"
+#include "devinst.h"
#include "data/analog.h"
#include "data/analogsnapshot.h"
SigSession::SigSession(DeviceManager &device_manager) :
_device_manager(device_manager),
- _sdi(NULL),
_capture_state(Stopped)
{
// TODO: This should not be necessary
_sampling_thread.join();
- if (_sdi)
- _device_manager.release_device(_sdi);
- _sdi = NULL;
+ if (_dev_inst)
+ _device_manager.release_device(_dev_inst);
// TODO: This should not be necessary
_session = NULL;
}
-struct sr_dev_inst* SigSession::get_device() const
+shared_ptr<DevInst> SigSession::get_device() const
{
- return _sdi;
+ return _dev_inst;
}
-void SigSession::set_device(struct sr_dev_inst *sdi)
+void SigSession::set_device(shared_ptr<DevInst> dev_inst)
{
// Ensure we are not capturing before setting the device
stop_capture();
- if (_sdi)
- _device_manager.release_device(_sdi);
- if (sdi)
- _device_manager.use_device(sdi, this);
- _sdi = sdi;
- update_signals(sdi);
+ if (_dev_inst)
+ _device_manager.release_device(_dev_inst);
+ if (dev_inst)
+ _device_manager.use_device(dev_inst, this);
+ _dev_inst = dev_inst;
+ update_signals(dev_inst);
}
-void SigSession::release_device(struct sr_dev_inst *sdi)
+void SigSession::release_device(shared_ptr<DevInst> dev_inst)
{
- (void)sdi;
+ (void)dev_inst;
assert(_capture_state == Stopped);
- _sdi = NULL;
- update_signals(NULL);
+ _dev_inst = shared_ptr<DevInst>();
}
void SigSession::load_file(const string &name,
return;
}
- sr_dev_inst *const sdi = (sr_dev_inst*)devlist->data;
+ shared_ptr<DevInst> dev_inst(
+ new DevInst((sr_dev_inst*)devlist->data));
g_slist_free(devlist);
_decode_traces.clear();
- update_signals(sdi);
- read_sample_rate(sdi);
+ update_signals(dev_inst);
+ read_sample_rate(dev_inst->dev_inst());
_sampling_thread = boost::thread(
&SigSession::load_session_thread_proc, this,
return;
_decode_traces.clear();
- update_signals(in->sdi);
+ update_signals(shared_ptr<DevInst>(new DevInst(in->sdi)));
read_sample_rate(in->sdi);
_sampling_thread = boost::thread(
stop_capture();
// Check that a device instance has been selected.
- if (!_sdi) {
+ if (!_dev_inst) {
qDebug() << "No device selected";
return;
}
+ assert(_dev_inst->dev_inst());
+
// Check that at least one probe is enabled
const GSList *l;
- for (l = _sdi->probes; l; l = l->next) {
+ for (l = _dev_inst->dev_inst()->probes; l; l = l->next) {
sr_probe *const probe = (sr_probe*)l->data;
assert(probe);
if (probe->enabled)
// Begin the session
_sampling_thread = boost::thread(
- &SigSession::sample_thread_proc, this, _sdi, error_handler);
+ &SigSession::sample_thread_proc, this, _dev_inst,
+ error_handler);
}
void SigSession::stop_capture()
return in;
}
-void SigSession::update_signals(const sr_dev_inst *const sdi)
+void SigSession::update_signals(shared_ptr<DevInst> dev_inst)
{
+ assert(dev_inst);
assert(_capture_state == Stopped);
unsigned int logic_probe_count = 0;
_decode_traces.clear();
// Detect what data types we will receive
- if(sdi) {
- for (const GSList *l = sdi->probes; l; l = l->next) {
+ if(dev_inst) {
+ assert(dev_inst->dev_inst());
+ for (const GSList *l = dev_inst->dev_inst()->probes;
+ l; l = l->next) {
const sr_probe *const probe = (const sr_probe *)l->data;
if (!probe->enabled)
continue;
_signals.clear();
- if(!sdi)
+ if(!dev_inst)
break;
- for (const GSList *l = sdi->probes; l; l = l->next) {
+ assert(dev_inst->dev_inst());
+ for (const GSList *l = dev_inst->dev_inst()->probes;
+ l; l = l->next) {
shared_ptr<view::Signal> signal;
sr_probe *const probe = (sr_probe *)l->data;
assert(probe);
bool SigSession::is_trigger_enabled() const
{
- assert(_sdi);
- for (const GSList *l = _sdi->probes; l; l = l->next) {
+ assert(_dev_inst);
+ assert(_dev_inst->dev_inst());
+ for (const GSList *l = _dev_inst->dev_inst()->probes; l; l = l->next) {
const sr_probe *const p = (const sr_probe *)l->data;
assert(p);
if (p->trigger && p->trigger[0] != '\0')
delete in;
}
-void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
+void SigSession::sample_thread_proc(shared_ptr<DevInst> dev_inst,
function<void (const QString)> error_handler)
{
- assert(sdi);
+ assert(dev_inst);
+ assert(dev_inst->dev_inst());
assert(error_handler);
sr_session_new();
sr_session_datafeed_callback_add(data_feed_in_proc, NULL);
- if (sr_session_dev_add(sdi) != SR_OK) {
+ if (sr_session_dev_add(dev_inst->dev_inst()) != SR_OK) {
error_handler(tr("Failed to use device."));
sr_session_destroy();
return;
namespace pv {
class DeviceManager;
+class DevInst;
namespace data {
class Analog;
~SigSession();
- struct sr_dev_inst* get_device() const;
+ boost::shared_ptr<DevInst> get_device() const;
/**
* Sets device instance that will be used in the next capture session.
*/
- void set_device(struct sr_dev_inst *sdi);
+ void set_device(boost::shared_ptr<DevInst> dev_inst);
- void release_device(struct sr_dev_inst *sdi);
+ void release_device(boost::shared_ptr<DevInst> dev_inst);
void load_file(const std::string &name,
boost::function<void (const QString)> error_handler);
private:
void set_capture_state(capture_state state);
- void update_signals(const sr_dev_inst *const sdi);
+ void update_signals(boost::shared_ptr<DevInst> dev_inst);
bool is_trigger_enabled() const;
void load_input_thread_proc(const std::string name, sr_input *in,
boost::function<void (const QString)> error_handler);
- void sample_thread_proc(struct sr_dev_inst *sdi,
+ void sample_thread_proc(boost::shared_ptr<DevInst> dev_inst,
boost::function<void (const QString)> error_handler);
void feed_in_header(const sr_dev_inst *sdi);
/**
* The device instance that will be used in the next capture session.
*/
- struct sr_dev_inst *_sdi;
+ boost::shared_ptr<DevInst> _dev_inst;
std::vector< boost::shared_ptr<view::DecodeTrace> > _decode_traces;
#include "samplingbar.h"
#include <pv/devicemanager.h>
+#include <pv/devinst.h>
#include <pv/popups/deviceoptions.h>
#include <pv/popups/probes.h>
+using boost::shared_ptr;
+using std::map;
using std::max;
using std::min;
using std::string;
}
void SamplingBar::set_device_list(
- const std::list<struct sr_dev_inst*> &devices)
+ const std::list< shared_ptr<pv::DevInst> > &devices)
{
_updating_device_selector = true;
_device_selector.clear();
+ _device_selector_map.clear();
- BOOST_FOREACH (sr_dev_inst *sdi, devices) {
- const string title = DeviceManager::format_device_title(sdi);
+ BOOST_FOREACH (shared_ptr<pv::DevInst> dev_inst, devices) {
+ assert(dev_inst);
+ const string title = dev_inst->format_device_title();
+ const sr_dev_inst *sdi = dev_inst->dev_inst();
+ assert(sdi);
+
+ _device_selector_map[sdi] = dev_inst;
_device_selector.addItem(title.c_str(),
qVariantFromValue((void*)sdi));
}
on_device_selected();
}
-struct sr_dev_inst* SamplingBar::get_selected_device() const
+shared_ptr<pv::DevInst> SamplingBar::get_selected_device() const
{
const int index = _device_selector.currentIndex();
if (index < 0)
- return NULL;
+ return shared_ptr<pv::DevInst>();
+
+ const sr_dev_inst *const sdi =
+ (const sr_dev_inst*)_device_selector.itemData(
+ index).value<void*>();
+ assert(sdi);
- return (sr_dev_inst*)_device_selector.itemData(
- index).value<void*>();
+ map<const sr_dev_inst*, boost::weak_ptr<DevInst> >::
+ const_iterator iter = _device_selector_map.find(sdi);
+ if (iter == _device_selector_map.end())
+ return shared_ptr<pv::DevInst>();
+
+ return shared_ptr<pv::DevInst>((*iter).second);
}
-void SamplingBar::set_selected_device(struct sr_dev_inst *const sdi)
+void SamplingBar::set_selected_device(boost::shared_ptr<pv::DevInst> dev_inst)
{
+ assert(dev_inst);
+
for (int i = 0; i < _device_selector.count(); i++)
- if (sdi == _device_selector.itemData(i).value<void*>()) {
+ if (dev_inst->dev_inst() ==
+ _device_selector.itemData(i).value<void*>()) {
_device_selector.setCurrentIndex(i);
return;
}
void SamplingBar::update_sample_rate_selector()
{
- const sr_dev_inst *const sdi = get_selected_device();
GVariant *gvar_dict, *gvar_list;
const uint64_t *elements = NULL;
gsize num_elements;
- if (!sdi)
+ const shared_ptr<DevInst> dev_inst = get_selected_device();
+ if (!dev_inst)
return;
+ const sr_dev_inst *const sdi = dev_inst->dev_inst();
+ assert(sdi);
+
_updating_sample_rate = true;
if (sr_config_list(sdi->driver, sdi, NULL,
void SamplingBar::update_sample_rate_selector_value()
{
- sr_dev_inst *const sdi = get_selected_device();
GVariant *gvar;
uint64_t samplerate;
+ const shared_ptr<DevInst> dev_inst = get_selected_device();
+ if (!dev_inst)
+ return;
+
+ const sr_dev_inst *const sdi = dev_inst->dev_inst();
assert(sdi);
if (sr_config_get(sdi->driver, sdi, NULL,
void SamplingBar::update_sample_count_selector()
{
- sr_dev_inst *const sdi = get_selected_device();
GVariant *gvar;
+ const shared_ptr<DevInst> dev_inst = get_selected_device();
+ if (!dev_inst)
+ return;
+
+ const sr_dev_inst *const sdi = dev_inst->dev_inst();
assert(sdi);
_updating_sample_count = true;
{
uint64_t sample_count = 0;
- sr_dev_inst *const sdi = get_selected_device();
+ const shared_ptr<DevInst> dev_inst = get_selected_device();
+ if (!dev_inst)
+ return;
+
+ const sr_dev_inst *const sdi = dev_inst->dev_inst();
assert(sdi);
sample_count = _sample_count.value();
{
uint64_t sample_rate = 0;
- sr_dev_inst *const sdi = get_selected_device();
+ const shared_ptr<DevInst> dev_inst = get_selected_device();
+ if (!dev_inst)
+ return;
+
+ const sr_dev_inst *const sdi = dev_inst->dev_inst();
assert(sdi);
sample_rate = _sample_rate.value();
if (_updating_device_selector)
return;
- sr_dev_inst *const sdi = get_selected_device();
- _session.set_device(sdi);
+ const shared_ptr<DevInst> dev_inst = get_selected_device();
+ if (!dev_inst)
+ return;
+
+ const sr_dev_inst *const sdi = dev_inst->dev_inst();
+ assert(sdi);
+
+ _session.set_device(dev_inst);
// Update the configure popup
- DeviceOptions *const opts = new DeviceOptions(sdi, this);
+ DeviceOptions *const opts = new DeviceOptions(dev_inst, this);
_configure_button_action->setVisible(
!opts->binding().properties().empty());
_configure_button.set_popup(opts);
#include <stdint.h>
#include <list>
+#include <map>
+
+#include <boost/shared_ptr.hpp>
#include <QComboBox>
#include <QDoubleSpinBox>
#include <pv/widgets/popuptoolbutton.h>
#include <pv/widgets/sweeptimingwidget.h>
-struct st_dev_inst;
class QAction;
namespace pv {
+class DevInst;
class SigSession;
namespace toolbars {
public:
SamplingBar(SigSession &session, QWidget *parent);
- void set_device_list(const std::list<struct sr_dev_inst*> &devices);
+ void set_device_list(
+ const std::list< boost::shared_ptr<pv::DevInst> > &devices);
- struct sr_dev_inst* get_selected_device() const;
- void set_selected_device(struct sr_dev_inst *const sdi);
+ boost::shared_ptr<pv::DevInst> get_selected_device() const;
+ void set_selected_device(boost::shared_ptr<pv::DevInst> dev_inst);
void set_capture_state(pv::SigSession::capture_state state);
SigSession &_session;
QComboBox _device_selector;
+ std::map<const sr_dev_inst*, boost::weak_ptr<DevInst> >
+ _device_selector_map;
bool _updating_device_selector;
pv::widgets::PopupToolButton _configure_button;
#include "logicsignal.h"
#include "view.h"
-#include "pv/sigsession.h"
-#include "pv/data/logic.h"
-#include "pv/data/logicsnapshot.h"
-#include "pv/view/view.h"
+#include <pv/sigsession.h>
+#include <pv/devinst.h>
+#include <pv/data/logic.h>
+#include <pv/data/logicsnapshot.h>
+#include <pv/view/view.h>
using boost::shared_ptr;
using std::deque;
Signal::populate_popup_form(parent, form);
// Add the trigger actions
- const sr_dev_inst *const sdi = _session.get_device();
+ boost::shared_ptr<DevInst> dev_inst = _session.get_device();
+ assert(dev_inst);
+
+ const sr_dev_inst *const sdi = dev_inst->dev_inst();
+ assert(sdi);
+
if (sr_config_list(sdi->driver, sdi, NULL, SR_CONF_TRIGGER_TYPE,
&gvar) == SR_OK)
{
const char *const trigger_string =
(type != 0) ? trigger_type_string : NULL;
- const sr_dev_inst *const sdi = _session.get_device();
+ boost::shared_ptr<DevInst> dev_inst = _session.get_device();
+ assert(dev_inst);
+
+ const sr_dev_inst *const sdi = dev_inst->dev_inst();
+ assert(sdi);
+
const int probe_count = g_slist_length(sdi->probes);
assert(probe_count > 0);