]> sigrok.org Git - pulseview.git/blobdiff - pv/sigsession.cpp
Made DeviceManager only handle Device objects
[pulseview.git] / pv / sigsession.cpp
index 622bf8d2c5b4dedf18143df7e5824282178c4995..aab5be7d23bcb5b4ba2ed85d777cb40c5f80c2f7 100644 (file)
@@ -25,7 +25,7 @@
 #include "sigsession.h"
 
 #include "devicemanager.h"
-#include "device/devinst.h"
+#include "device/device.h"
 
 #include "data/analog.h"
 #include "data/analogsnapshot.h"
@@ -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);
 }
@@ -127,7 +136,7 @@ void SigSession::load_file(const string &name,
                }
 
                shared_ptr<device::DevInst> dev_inst(
-                       new device::DevInst((sr_dev_inst*)devlist->data));
+                       new device::Device((sr_dev_inst*)devlist->data));
                g_slist_free(devlist);
 
                _decode_traces.clear();
@@ -147,7 +156,7 @@ void SigSession::load_file(const string &name,
 
                _decode_traces.clear();
                update_signals(shared_ptr<device::DevInst>(
-                       new device::DevInst(in->sdi)));
+                       new device::Device(in->sdi)));
                read_sample_rate(in->sdi);
 
                _sampling_thread = boost::thread(