diff --git a/DSView/pv/dialogs/storeprogress.cpp b/DSView/pv/dialogs/storeprogress.cpp index ac84b808..cc63a095 100755 --- a/DSView/pv/dialogs/storeprogress.cpp +++ b/DSView/pv/dialogs/storeprogress.cpp @@ -21,6 +21,7 @@ #include "storeprogress.h" #include "dsmessagebox.h" +#include "pv/sigsession.h" #include "QVBoxLayout" @@ -59,15 +60,19 @@ void StoreProgress::reject() { using namespace Qt; _store_session.cancel(); + save_done(); QDialog::reject(); } void StoreProgress::timeout() { - if (_done) + if (_done) { + _store_session.session().set_saving(false); + save_done(); close(); - else + } else { QTimer::singleShot(100, this, SLOT(timeout())); + } } void StoreProgress::save_run(QString session_file) @@ -76,7 +81,7 @@ void StoreProgress::save_run(QString session_file) if (_store_session.save_start(session_file)) show(); else - show_error(); + show_error(); QTimer::singleShot(100, this, SLOT(timeout())); } diff --git a/DSView/pv/dialogs/storeprogress.h b/DSView/pv/dialogs/storeprogress.h index 28cf5cb3..93c61ef4 100755 --- a/DSView/pv/dialogs/storeprogress.h +++ b/DSView/pv/dialogs/storeprogress.h @@ -60,6 +60,9 @@ private: void show_error(); void closeEvent(QCloseEvent* e); +signals: + void save_done(); + public slots: void save_run(QString session_file); void export_run(); diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index b306584f..1bf0d1dc 100755 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -54,6 +54,10 @@ #include "device/device.h" #include "device/file.h" +#include "data/logicsnapshot.h" +#include "data/dsosnapshot.h" +#include "data/analogsnapshot.h" + #include "dialogs/about.h" #include "dialogs/deviceoptions.h" #include "dialogs/storeprogress.h" @@ -100,6 +104,7 @@ MainWindow::MainWindow(DeviceManager &device_manager, QMainWindow(parent), _device_manager(device_manager), _session(device_manager), + _hot_detach(false), _msg(NULL) { setup_ui(); @@ -460,9 +465,9 @@ void MainWindow::update_device_list() "Please replug it into a USB 3.0 port.")); } } - } + void MainWindow::reload() { _trigger_widget->device_updated(); @@ -534,7 +539,38 @@ void MainWindow::device_detach() session_save(); _view->hide_calibration(); + if (_session.get_device()->dev_inst()->mode != DSO && + strncmp(_session.get_device()->name().toLocal8Bit(), "virtual", 7)) { + const boost::shared_ptr logic_snapshot(_session.get_snapshot(SR_CHANNEL_LOGIC)); + assert(logic_snapshot); + const boost::shared_ptr analog_snapshot(_session.get_snapshot(SR_CHANNEL_ANALOG)); + assert(analog_snapshot); + if (!logic_snapshot->empty() || !analog_snapshot->empty()) { + dialogs::DSMessageBox msg(this); + _msg = &msg; + msg.mBox()->setText(tr("Hardware Detached")); + msg.mBox()->setInformativeText(tr("Save captured data?")); + msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole); + msg.mBox()->addButton(tr("Cancel"), QMessageBox::RejectRole); + msg.mBox()->setIcon(QMessageBox::Warning); + if (msg.exec()) + on_save(); + _msg = NULL; + } + } + + _hot_detach = true; + if (!_session.get_saving()) + device_detach_post(); +} + +void MainWindow::device_detach_post() +{ + if (!_hot_detach) + return; + + _hot_detach = false; struct sr_dev_driver **const drivers = sr_driver_list(); struct sr_dev_driver **driver; for (driver = drivers; *driver; driver++) @@ -839,6 +875,7 @@ void MainWindow::on_save() // dialogs::RegionOptions *regionDlg = new dialogs::RegionOptions(_view, _session, this); // regionDlg->exec(); + _session.set_saving(true); QString session_file; QDir dir; #if QT_VERSION >= 0x050400 @@ -854,6 +891,7 @@ void MainWindow::on_save() } StoreProgress *dlg = new StoreProgress(_session, this); + connect(dlg, SIGNAL(save_done()), this, SLOT(device_detach_post())); dlg->save_run(session_file); } diff --git a/DSView/pv/mainwindow.h b/DSView/pv/mainwindow.h index 14c96fdb..0af21189 100755 --- a/DSView/pv/mainwindow.h +++ b/DSView/pv/mainwindow.h @@ -146,6 +146,7 @@ private slots: */ void device_attach(); void device_detach(); + void device_detach_post(); void device_changed(bool close); /* @@ -160,6 +161,7 @@ private: DeviceManager &_device_manager; SigSession _session; + bool _hot_detach; pv::view::View *_view; dialogs::DSMessageBox *_msg; diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index 65f1e6f7..354a1c62 100755 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -114,6 +114,7 @@ SigSession::SigSession(DeviceManager &device_manager) : #endif _lissajous_trace = NULL; _math_trace = NULL; + _saving = false; _dso_feed = false; // Create snapshots & data containers @@ -1749,4 +1750,14 @@ uint64_t SigSession::get_save_end() const return _save_end; } +bool SigSession::get_saving() const +{ + return _saving; +} + +void SigSession::set_saving(bool saving) +{ + _saving = saving; +} + } // namespace pv diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index d95ab415..25fe1300 100755 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -253,6 +253,8 @@ public: void set_save_end(uint64_t end); uint64_t get_save_start() const; uint64_t get_save_end() const; + bool get_saving() const; + void set_saving(bool saving); private: void set_capture_state(capture_state state); @@ -360,6 +362,7 @@ private: uint64_t _save_start; uint64_t _save_end; + bool _saving; bool _dso_feed; diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index 765f290c..377dfef2 100755 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -65,7 +65,8 @@ StoreSession::StoreSession(SigSession &session) : _outModule(NULL), _units_stored(0), _unit_count(0), - _has_error(false) + _has_error(false), + _canceled(false) { } @@ -74,6 +75,11 @@ StoreSession::~StoreSession() wait(); } +SigSession& StoreSession::session() +{ + return _session; +} + pair StoreSession::progress() const { //lock_guard lock(_mutex); @@ -94,6 +100,7 @@ void StoreSession::wait() void StoreSession::cancel() { + _canceled = true; _thread.interrupt(); } @@ -174,7 +181,6 @@ bool StoreSession::save_start(QString session_file) #endif if (meta_file == NULL) { _error = tr("Generate temp file failed."); - return false; } else { int ret = sr_session_save_init(_file_name.toLocal8Bit().data(), meta_file.toLocal8Bit().data(), @@ -182,7 +188,6 @@ bool StoreSession::save_start(QString session_file) session_file.toLocal8Bit().data()); if (ret != SR_OK) { _error = tr("Failed to create zip file. Please check write permission of this path."); - return false; } else { _thread = boost::thread(&StoreSession::save_proc, this, snapshot); return !_has_error; @@ -190,6 +195,7 @@ bool StoreSession::save_start(QString session_file) } } + QFile::remove(_file_name); _error.clear(); return false; } @@ -199,6 +205,7 @@ void StoreSession::save_proc(shared_ptr snapshot) assert(snapshot); int ret = SR_ERR; + int num = 0; shared_ptr logic_snapshot; shared_ptr analog_snapshot; shared_ptr dso_snapshot; @@ -210,7 +217,7 @@ void StoreSession::save_proc(shared_ptr snapshot) to_save_probes++; } _unit_count = logic_snapshot->get_sample_count() / 8 * to_save_probes; - int num = logic_snapshot->get_block_num(); + num = logic_snapshot->get_block_num(); bool sample; BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { @@ -240,6 +247,8 @@ void StoreSession::save_proc(shared_ptr snapshot) _error = tr("Failed to create zip file. Please check write permission of this path."); } progress_updated(); + if (_has_error) + QFile::remove(_file_name); return; } _units_stored += size; @@ -256,7 +265,7 @@ void StoreSession::save_proc(shared_ptr snapshot) break; } if (ch_type != -1) { - const int num = snapshot->get_block_num(); + num = snapshot->get_block_num(); _unit_count = snapshot->get_sample_count() * snapshot->get_unit_bytes() * snapshot->get_channel_num(); @@ -292,6 +301,8 @@ void StoreSession::save_proc(shared_ptr snapshot) _error = tr("Failed to create zip file. Please check write permission of this path."); } progress_updated(); + if (_has_error) + QFile::remove(_file_name); return; } _units_stored += size; @@ -300,6 +311,9 @@ void StoreSession::save_proc(shared_ptr snapshot) } } progress_updated(); + + if (_canceled || num == 0) + QFile::remove(_file_name); } QString StoreSession::meta_gen(boost::shared_ptr snapshot) diff --git a/DSView/pv/storesession.h b/DSView/pv/storesession.h index 6c568794..2f369385 100755 --- a/DSView/pv/storesession.h +++ b/DSView/pv/storesession.h @@ -56,6 +56,8 @@ public: ~StoreSession(); + SigSession& session(); + std::pair progress() const; const QString& error() const; @@ -103,6 +105,7 @@ private: uint64_t _unit_count; bool _has_error; QString _error; + bool _canceled; }; } // pv