X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fsigsession.cpp;h=aab5be7d23bcb5b4ba2ed85d777cb40c5f80c2f7;hb=85843b14c48affe67820ec8c9e357cd26e0ed943;hp=b5387877dda0a73a513f7cb5f066e030f3b17539;hpb=6d483b8b51b4efceacf2f48776af33550bf5d29e;p=pulseview.git diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index b538787..aab5be7 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -25,7 +25,7 @@ #include "sigsession.h" #include "devicemanager.h" -#include "devinst.h" +#include "device/device.h" #include "data/analog.h" #include "data/analogsnapshot.h" @@ -73,42 +73,51 @@ 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(dynamic_pointer_cast(_dev_inst)); + if (device) + _device_manager.release_device(device); // TODO: This should not be necessary _session = NULL; } -shared_ptr SigSession::get_device() const +shared_ptr SigSession::get_device() const { return _dev_inst; } -void SigSession::set_device(shared_ptr dev_inst) +void SigSession::set_device(shared_ptr 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 old_device(dynamic_pointer_cast(_dev_inst)); + if (old_device) + _device_manager.release_device(old_device); + + shared_ptr new_device(dynamic_pointer_cast(dev_inst)); + if (new_device) + _device_manager.use_device(new_device, this); + _dev_inst = dev_inst; update_signals(dev_inst); } -void SigSession::release_device(shared_ptr dev_inst) +void SigSession::release_device(shared_ptr dev_inst) { (void)dev_inst; assert(_capture_state == Stopped); - _dev_inst = shared_ptr(); + _dev_inst = shared_ptr(); } void SigSession::load_file(const string &name, @@ -126,8 +135,8 @@ void SigSession::load_file(const string &name, return; } - shared_ptr dev_inst( - new DevInst((sr_dev_inst*)devlist->data)); + shared_ptr dev_inst( + new device::Device((sr_dev_inst*)devlist->data)); g_slist_free(devlist); _decode_traces.clear(); @@ -146,7 +155,8 @@ void SigSession::load_file(const string &name, return; _decode_traces.clear(); - update_signals(shared_ptr(new DevInst(in->sdi))); + update_signals(shared_ptr( + new device::Device(in->sdi))); read_sample_rate(in->sdi); _sampling_thread = boost::thread( @@ -386,7 +396,7 @@ sr_input* SigSession::load_input_file_format(const string &filename, return in; } -void SigSession::update_signals(shared_ptr dev_inst) +void SigSession::update_signals(shared_ptr dev_inst) { assert(dev_inst); assert(_capture_state == Stopped); @@ -568,7 +578,7 @@ void SigSession::load_input_thread_proc(const string name, delete in; } -void SigSession::sample_thread_proc(shared_ptr dev_inst, +void SigSession::sample_thread_proc(shared_ptr dev_inst, function error_handler) { assert(dev_inst);