]> sigrok.org Git - pulseview.git/commitdiff
Made DeviceManager only handle Device objects
authorJoel Holdsworth <redacted>
Sat, 22 Feb 2014 09:01:23 +0000 (09:01 +0000)
committerJoel Holdsworth <redacted>
Sat, 1 Mar 2014 11:02:11 +0000 (11:02 +0000)
pv/devicemanager.cpp
pv/devicemanager.h
pv/dialogs/connect.cpp
pv/dialogs/connect.h
pv/mainwindow.cpp
pv/sigsession.cpp

index b854c05081123516948262249a632ca39372a80c..5844e80e75325ad91d1e9f93d8368e4e7630321e 100644 (file)
@@ -49,12 +49,12 @@ DeviceManager::~DeviceManager()
        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);
@@ -65,12 +65,12 @@ void DeviceManager::use_device(shared_ptr<device::DevInst> 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());
 
@@ -78,16 +78,16 @@ void DeviceManager::release_device(shared_ptr<device::DevInst> dev_inst)
        _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);
@@ -101,7 +101,7 @@ list< shared_ptr<device::DevInst> > DeviceManager::driver_scan(
        // 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);
@@ -130,7 +130,7 @@ void DeviceManager::init_drivers()
 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);
 
@@ -153,7 +153,7 @@ void DeviceManager::scan_all_drivers()
 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)
                {
@@ -171,8 +171,8 @@ void DeviceManager::release_driver(struct sr_dev_driver *const 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);
index 3ed74e078f2baa3234b9807eb6d62e4e2af6f7ac..2ce523dc6251d424921bba5a696a2fbcdcd100bd 100644 (file)
@@ -37,7 +37,7 @@ namespace pv {
 class SigSession;
 
 namespace device {
-class DevInst;
+class Device;
 }
 
 class DeviceManager
@@ -47,15 +47,15 @@ public:
 
        ~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);
 
@@ -68,13 +68,13 @@ private:
 
        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;
 };
 
index 7b31942d974e5ca28e8aab2d33e54a5db7d608af..c9e8d82c9ba832e1e90b6b209860b2f07767d858 100644 (file)
@@ -25,7 +25,7 @@
 #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++). */
@@ -82,17 +82,17 @@ Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
        _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());
 
@@ -170,12 +170,12 @@ void Connect::scan_pressed()
                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();
index 5a8b1cd0baf07d7974535c4db4bb951616f05262..1de0ed8de9adaec3b68787c4261c1dc332d72fa0 100644 (file)
@@ -40,7 +40,7 @@ namespace pv {
 class DeviceManager;
 
 namespace device {
-class DevInst;
+class Device;
 }
 
 namespace dialogs {
@@ -52,7 +52,7 @@ class Connect : public QDialog
 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();
@@ -83,7 +83,7 @@ private:
 
        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;
index f72d1b7056041bd5cb34c563f68c7aed3523917e..9995e50ac2ef42650ba4d904a3d7b70c287336ff 100644 (file)
@@ -25,6 +25,9 @@
 #include <boost/bind.hpp>
 #include <boost/foreach.hpp>
 
+#include <algorithm>
+#include <iterator>
+
 #include <QAction>
 #include <QApplication>
 #include <QButtonGroup>
@@ -39,7 +42,7 @@
 #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"
@@ -289,8 +292,10 @@ void MainWindow::update_device_list(
 {
        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()) {
index 4469a3eef367071c44a545d3c3a1a8ae746742cc..aab5be7d23bcb5b4ba2ed85d777cb40c5f80c2f7 100644 (file)
@@ -73,13 +73,16 @@ SigSession::SigSession(DeviceManager &device_manager) :
 
 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;
@@ -92,13 +95,19 @@ shared_ptr<device::DevInst> SigSession::get_device() const
 
 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);
 }