release_devices();
}
-const list< shared_ptr<pv::device::DevInst> >& DeviceManager::devices() const
+const list< shared_ptr<pv::device::Device> >& DeviceManager::devices() const
{
return _devices;
}
-void DeviceManager::use_device(shared_ptr<device::DevInst> dev_inst,
+void DeviceManager::use_device(shared_ptr<device::Device> dev_inst,
SigSession *owner)
{
assert(dev_inst);
sr_dev_open(dev_inst->dev_inst());
}
-void DeviceManager::release_device(shared_ptr<device::DevInst> dev_inst)
+void DeviceManager::release_device(shared_ptr<device::Device> dev_inst)
{
assert(dev_inst);
// Notify the owner, and remove the device from the used device list
- map< shared_ptr<device::DevInst>, pv::SigSession*>::const_iterator
+ map< shared_ptr<device::Device>, pv::SigSession*>::const_iterator
iter = _used_devices.find(dev_inst);
assert(iter != _used_devices.end());
_used_devices.erase(dev_inst);
}
-list< shared_ptr<device::DevInst> > DeviceManager::driver_scan(
+list< shared_ptr<device::Device> > DeviceManager::driver_scan(
struct sr_dev_driver *const driver, GSList *const drvopts)
{
- list< shared_ptr<device::DevInst> > driver_devices;
+ list< shared_ptr<device::Device> > driver_devices;
assert(driver);
// Remove any device instances from this driver from the device
// list. They will not be valid after the scan.
- list< shared_ptr<device::DevInst> >::iterator i = _devices.begin();
+ list< shared_ptr<device::Device> >::iterator i = _devices.begin();
while (i != _devices.end()) {
if ((*i)->dev_inst()->driver == driver)
i = _devices.erase(i);
// Do the scan
GSList *const devices = sr_driver_scan(driver, drvopts);
for (GSList *l = devices; l; l = l->next)
- driver_devices.push_back(shared_ptr<device::DevInst>(
+ driver_devices.push_back(shared_ptr<device::Device>(
new device::Device((sr_dev_inst*)l->data)));
g_slist_free(devices);
driver_devices.sort(compare_devices);
void DeviceManager::release_devices()
{
// Release all the used devices
- for (map<shared_ptr<device::DevInst>, SigSession*>::iterator i =
+ for (map<shared_ptr<device::Device>, SigSession*>::iterator i =
_used_devices.begin(); i != _used_devices.end(); i++)
release_device((*i).first);
void DeviceManager::release_driver(struct sr_dev_driver *const driver)
{
assert(driver);
- for (map<shared_ptr<device::DevInst>, SigSession*>::iterator i =
+ for (map<shared_ptr<device::Device>, SigSession*>::iterator i =
_used_devices.begin(); i != _used_devices.end(); i++)
if((*i).first->dev_inst()->driver == driver)
{
sr_dev_clear(driver);
}
-bool DeviceManager::compare_devices(shared_ptr<device::DevInst> a,
- shared_ptr<device::DevInst> b)
+bool DeviceManager::compare_devices(shared_ptr<device::Device> a,
+ shared_ptr<device::Device> b)
{
assert(a);
assert(b);
class SigSession;
namespace device {
-class DevInst;
+class Device;
}
class DeviceManager
~DeviceManager();
- const std::list< boost::shared_ptr<pv::device::DevInst> >&
+ const std::list< boost::shared_ptr<pv::device::Device> >&
devices() const;
- void use_device(boost::shared_ptr<pv::device::DevInst> dev_inst,
+ void use_device(boost::shared_ptr<pv::device::Device> dev_inst,
SigSession *owner);
- void release_device(boost::shared_ptr<pv::device::DevInst> dev_inst);
+ void release_device(boost::shared_ptr<pv::device::Device> dev_inst);
- std::list< boost::shared_ptr<pv::device::DevInst> > driver_scan(
+ std::list< boost::shared_ptr<pv::device::Device> > driver_scan(
struct sr_dev_driver *const driver,
GSList *const drvopts = NULL);
void release_driver(struct sr_dev_driver *const driver);
- static bool compare_devices(boost::shared_ptr<device::DevInst> a,
- boost::shared_ptr<device::DevInst> b);
+ static bool compare_devices(boost::shared_ptr<device::Device> a,
+ boost::shared_ptr<device::Device> b);
private:
struct sr_context *const _sr_ctx;
- std::list< boost::shared_ptr<pv::device::DevInst> > _devices;
- std::map< boost::shared_ptr<pv::device::DevInst>, pv::SigSession*>
+ std::list< boost::shared_ptr<pv::device::Device> > _devices;
+ std::map< boost::shared_ptr<pv::device::Device>, pv::SigSession*>
_used_devices;
};
#include "connect.h"
#include "pv/devicemanager.h"
-#include "pv/device/devinst.h"
+#include "pv/device/device.h"
extern "C" {
/* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
_layout.addWidget(&_button_box);
}
-shared_ptr<device::DevInst> Connect::get_selected_device() const
+shared_ptr<device::Device> Connect::get_selected_device() const
{
const QListWidgetItem *const item = _device_list.currentItem();
if (!item)
- return shared_ptr<device::DevInst>();
+ return shared_ptr<device::Device>();
const sr_dev_inst *const sdi = (sr_dev_inst*)item->data(
Qt::UserRole).value<void*>();
assert(sdi);
- std::map<const sr_dev_inst*, boost::shared_ptr<pv::device::DevInst> >::
+ std::map<const sr_dev_inst*, boost::shared_ptr<pv::device::Device> >::
const_iterator iter = _device_map.find(sdi);
assert(iter != _device_map.end());
drvopts = g_slist_append(drvopts, src);
}
- const list< shared_ptr<device::DevInst> > devices =
+ const list< shared_ptr<device::Device> > devices =
_device_manager.driver_scan(driver, drvopts);
g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
- BOOST_FOREACH(shared_ptr<device::DevInst> dev_inst, devices)
+ BOOST_FOREACH(shared_ptr<device::Device> dev_inst, devices)
{
assert(dev_inst);
const sr_dev_inst *const sdi = dev_inst->dev_inst();
class DeviceManager;
namespace device {
-class DevInst;
+class Device;
}
namespace dialogs {
public:
Connect(QWidget *parent, pv::DeviceManager &device_manager);
- boost::shared_ptr<device::DevInst> get_selected_device() const;
+ boost::shared_ptr<device::Device> get_selected_device() const;
private:
void populate_drivers();
QPushButton _scan_button;
QListWidget _device_list;
- std::map<const sr_dev_inst*, boost::shared_ptr<pv::device::DevInst> >
+ std::map<const sr_dev_inst*, boost::shared_ptr<pv::device::Device> >
_device_map;
QDialogButtonBox _button_box;
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
+#include <algorithm>
+#include <iterator>
+
#include <QAction>
#include <QApplication>
#include <QButtonGroup>
#include "mainwindow.h"
#include "devicemanager.h"
-#include "device/devinst.h"
+#include "device/device.h"
#include "dialogs/about.h"
#include "dialogs/connect.h"
#include "dialogs/storeprogress.h"
{
assert(_sampling_bar);
- const list< shared_ptr<device::DevInst> > &devices =
- _device_manager.devices();
+ list< shared_ptr<device::DevInst> > devices;
+ std::copy(_device_manager.devices().begin(),
+ _device_manager.devices().end(), std::back_inserter(devices));
+
_sampling_bar->set_device_list(devices);
if (!selected_device && !devices.empty()) {
SigSession::~SigSession()
{
+ using pv::device::Device;
+
stop_capture();
if (_sampling_thread.joinable())
_sampling_thread.join();
- if (_dev_inst)
- _device_manager.release_device(_dev_inst);
+ shared_ptr<Device> device(dynamic_pointer_cast<Device>(_dev_inst));
+ if (device)
+ _device_manager.release_device(device);
// TODO: This should not be necessary
_session = NULL;
void SigSession::set_device(shared_ptr<device::DevInst> dev_inst)
{
+ using pv::device::Device;
+
// Ensure we are not capturing before setting the device
stop_capture();
- if (_dev_inst)
- _device_manager.release_device(_dev_inst);
- if (dev_inst)
- _device_manager.use_device(dev_inst, this);
+ shared_ptr<Device> old_device(dynamic_pointer_cast<Device>(_dev_inst));
+ if (old_device)
+ _device_manager.release_device(old_device);
+
+ shared_ptr<Device> new_device(dynamic_pointer_cast<Device>(dev_inst));
+ if (new_device)
+ _device_manager.use_device(new_device, this);
+
_dev_inst = dev_inst;
update_signals(dev_inst);
}